/*
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "precompiled.hpp"
#include "compiler/compileBroker.hpp"
#include "classfile/moduleEntry.hpp"
#include "jvmci/jvmciEnv.hpp"
#include "jvmci/jvmciRuntime.hpp"
#include "oops/objArrayOop.inline.hpp"
#include "runtime/handles.inline.hpp"
JVMCICompiler* JVMCICompiler::_instance = NULL;
elapsedTimer JVMCICompiler::_codeInstallTimer;
JVMCICompiler::JVMCICompiler() : AbstractCompiler(compiler_jvmci) {
_bootstrapping = false;
_bootstrap_compilation_request_handled = false;
_methods_compiled = 0;
assert(_instance == NULL, "only one instance allowed");
_instance = this;
}
// Initialization
void JVMCICompiler::initialize() {
if (!UseCompiler || !EnableJVMCI || !UseJVMCICompiler || !should_perform_init()) {
return;
}
set_state(initialized);
}
void JVMCICompiler::bootstrap(TRAPS) {
assert(THREAD->is_Java_thread(), "must be");
if (Arguments::mode() == Arguments::_int) {
// Nothing to do in -Xint mode
return;
}
_bootstrapping = true;
ResourceMark rm;
HandleMark hm;
if (PrintBootstrap) {
tty->print("Bootstrapping JVMCI");
}
jlong start = os::javaTimeMillis();
Array<Method*>* objectMethods = SystemDictionary::Object_klass()->methods();
// Initialize compile queue with a selected set of methods.
int len = objectMethods->length();
for (int i = 0; i < len; i++) {
methodHandle mh = objectMethods->at(i);
if (!mh->is_native() && !mh->is_static() && !mh->is_initializer()) {
ResourceMark rm;
int hot_count = 10; // TODO: what's the appropriate value?
CompileBroker::compile_method(mh, InvocationEntryBci, CompLevel_full_optimization, mh, hot_count, CompileTask::Reason_Bootstrap, THREAD);
}
}
int qsize;
bool first_round = true;
int z = 0;
do {
// Loop until there is something in the queue.
do {
((JavaThread*)THREAD)->sleep(100);
qsize = CompileBroker::queue_size(CompLevel_full_optimization);
} while (!_bootstrap_compilation_request_handled && first_round && qsize == 0);
first_round = false;
if (PrintBootstrap) {
while (z < (_methods_compiled / 100)) {
++z;
tty->print_raw(".");
}
}
} while (qsize != 0);
if (PrintBootstrap) {
tty->print_cr(" in " JLONG_FORMAT " ms (compiled %d methods)", os::javaTimeMillis() - start, _methods_compiled);
}
_bootstrapping = false;
JVMCI::compiler_runtime()->bootstrap_finished(CHECK);
}
bool JVMCICompiler::force_comp_at_level_simple(Method *method) {
if (UseJVMCINativeLibrary) {
// This mechanism exists to force compilation of a JVMCI compiler by C1
// to reduces the compilation time spent on the JVMCI compiler itself. In
// +UseJVMCINativeLibrary mode, the JVMCI compiler is AOT compiled.
return false;
}
if (_bootstrapping) {
// When bootstrapping, the JVMCI compiler can compile its own methods.
return false;
}
JVMCIRuntime* runtime = JVMCI::compiler_runtime();
if (runtime != NULL && runtime->is_HotSpotJVMCIRuntime_initialized()) {
JavaThread* thread = JavaThread::current();
HandleMark hm(thread);
THREAD_JVMCIENV(thread);
JVMCIObject receiver = runtime->get_HotSpotJVMCIRuntime(JVMCIENV);
objArrayHandle excludeModules(thread, HotSpotJVMCI::HotSpotJVMCIRuntime::excludeFromJVMCICompilation(JVMCIENV, HotSpotJVMCI::resolve(receiver)));
if (excludeModules.not_null()) {
ModuleEntry* moduleEntry = method->method_holder()->module();
for (int i = 0; i < excludeModules->length(); i++) {
if (oopDesc::equals(excludeModules->obj_at(i), moduleEntry->module())) {
return true;
}
}
}
}
return false;
}
// Compilation entry point for methods
void JVMCICompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci, DirectiveSet* directive) {
ShouldNotReachHere();
}
// Print compilation timers and statistics
void JVMCICompiler::print_timers() {
print_compilation_timers();
}
// Print compilation timers and statistics
void JVMCICompiler::print_compilation_timers() {
TRACE_jvmci_1("JVMCICompiler::print_timers");
tty->print_cr(" JVMCI code install time: %6.3f s", _codeInstallTimer.seconds());
}