Path: blob/master/src/hotspot/share/jvmci/jvmciCompiler.cpp
40949 views
/*1* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "classfile/vmClasses.hpp"25#include "compiler/compileBroker.hpp"26#include "classfile/moduleEntry.hpp"27#include "classfile/vmSymbols.hpp"28#include "jvmci/jvmciEnv.hpp"29#include "jvmci/jvmciRuntime.hpp"30#include "oops/objArrayOop.inline.hpp"31#include "runtime/arguments.hpp"32#include "runtime/handles.inline.hpp"3334JVMCICompiler* JVMCICompiler::_instance = NULL;35elapsedTimer JVMCICompiler::_codeInstallTimer;36elapsedTimer JVMCICompiler::_hostedCodeInstallTimer;3738JVMCICompiler::JVMCICompiler() : AbstractCompiler(compiler_jvmci) {39_bootstrapping = false;40_bootstrap_compilation_request_handled = false;41_methods_compiled = 0;42_global_compilation_ticks = 0;43assert(_instance == NULL, "only one instance allowed");44_instance = this;45}4647JVMCICompiler* JVMCICompiler::instance(bool require_non_null, TRAPS) {48if (!EnableJVMCI) {49THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVMCI is not enabled")50}51if (_instance == NULL && require_non_null) {52THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "The JVMCI compiler instance has not been created");53}54return _instance;55}5657// Initialization58void JVMCICompiler::initialize() {59assert(!CompilerConfig::is_c1_or_interpreter_only_no_jvmci(), "JVMCI is launched, it's not c1/interpreter only mode");60if (!UseCompiler || !EnableJVMCI || !UseJVMCICompiler || !should_perform_init()) {61return;62}6364set_state(initialized);65}6667void JVMCICompiler::bootstrap(TRAPS) {68if (Arguments::mode() == Arguments::_int) {69// Nothing to do in -Xint mode70return;71}72_bootstrapping = true;73ResourceMark rm(THREAD);74HandleMark hm(THREAD);75if (PrintBootstrap) {76tty->print("Bootstrapping JVMCI");77}78jlong start = os::javaTimeNanos();7980Array<Method*>* objectMethods = vmClasses::Object_klass()->methods();81// Initialize compile queue with a selected set of methods.82int len = objectMethods->length();83for (int i = 0; i < len; i++) {84methodHandle mh(THREAD, objectMethods->at(i));85if (!mh->is_native() && !mh->is_static() && !mh->is_initializer()) {86ResourceMark rm;87int hot_count = 10; // TODO: what's the appropriate value?88CompileBroker::compile_method(mh, InvocationEntryBci, CompLevel_full_optimization, mh, hot_count, CompileTask::Reason_Bootstrap, CHECK);89}90}9192int qsize;93bool first_round = true;94int z = 0;95do {96// Loop until there is something in the queue.97do {98THREAD->sleep(100);99qsize = CompileBroker::queue_size(CompLevel_full_optimization);100} while (!_bootstrap_compilation_request_handled && first_round && qsize == 0);101first_round = false;102if (PrintBootstrap) {103while (z < (_methods_compiled / 100)) {104++z;105tty->print_raw(".");106}107}108} while (qsize != 0);109110if (PrintBootstrap) {111tty->print_cr(" in " JLONG_FORMAT " ms (compiled %d methods)",112(jlong)nanos_to_millis(os::javaTimeNanos() - start), _methods_compiled);113}114_bootstrapping = false;115JVMCI::java_runtime()->bootstrap_finished(CHECK);116}117118bool JVMCICompiler::force_comp_at_level_simple(const methodHandle& method) {119if (_bootstrapping) {120// When bootstrapping, the JVMCI compiler can compile its own methods.121return false;122}123if (UseJVMCINativeLibrary) {124// This mechanism exists to force compilation of a JVMCI compiler by C1125// to reduce the compilation time spent on the JVMCI compiler itself. In126// +UseJVMCINativeLibrary mode, the JVMCI compiler is AOT compiled.127return false;128} else {129JVMCIRuntime* runtime = JVMCI::java_runtime();130if (runtime != NULL) {131JVMCIObject receiver = runtime->probe_HotSpotJVMCIRuntime();132if (receiver.is_null()) {133return false;134}135JVMCIEnv* ignored_env = NULL;136objArrayHandle excludeModules(JavaThread::current(), HotSpotJVMCI::HotSpotJVMCIRuntime::excludeFromJVMCICompilation(ignored_env, HotSpotJVMCI::resolve(receiver)));137if (excludeModules.not_null()) {138ModuleEntry* moduleEntry = method->method_holder()->module();139for (int i = 0; i < excludeModules->length(); i++) {140if (excludeModules->obj_at(i) == moduleEntry->module()) {141return true;142}143}144}145}146return false;147}148}149150// Compilation entry point for methods151void JVMCICompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci, bool install_code, DirectiveSet* directive) {152ShouldNotReachHere();153}154155// Print CompileBroker compilation timers156void JVMCICompiler::print_timers() {157double code_install_time = _codeInstallTimer.seconds();158tty->print_cr(" JVMCI CompileBroker Time:");159tty->print_cr(" Compile: %7.3f s", stats()->total_time());160tty->print_cr(" Install Code: %7.3f s", code_install_time);161}162163// Print non-CompileBroker compilation timers164void JVMCICompiler::print_hosted_timers() {165double code_install_time = _hostedCodeInstallTimer.seconds();166tty->print_cr(" JVMCI Hosted Time:");167tty->print_cr(" Install Code: %7.3f s", code_install_time);168}169170void JVMCICompiler::inc_methods_compiled() {171Atomic::inc(&_methods_compiled);172Atomic::inc(&_global_compilation_ticks);173}174175void JVMCICompiler::inc_global_compilation_ticks() {176Atomic::inc(&_global_compilation_ticks);177}178179180