Path: blob/master/src/hotspot/share/runtime/init.cpp
40951 views
/*1* Copyright (c) 1997, 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*22*/2324#include "precompiled.hpp"25#include "classfile/stringTable.hpp"26#include "classfile/symbolTable.hpp"27#include "code/icBuffer.hpp"28#include "compiler/compiler_globals.hpp"29#include "gc/shared/collectedHeap.hpp"30#if INCLUDE_JVMCI31#include "jvmci/jvmci.hpp"32#endif33#include "interpreter/bytecodes.hpp"34#include "logging/log.hpp"35#include "logging/logAsyncWriter.hpp"36#include "logging/logTag.hpp"37#include "memory/universe.hpp"38#include "prims/jvmtiExport.hpp"39#include "prims/methodHandles.hpp"40#include "prims/universalNativeInvoker.hpp"41#include "runtime/globals.hpp"42#include "runtime/atomic.hpp"43#include "runtime/flags/jvmFlag.hpp"44#include "runtime/handles.inline.hpp"45#include "runtime/icache.hpp"46#include "runtime/init.hpp"47#include "runtime/safepoint.hpp"48#include "runtime/sharedRuntime.hpp"49#include "services/memTracker.hpp"50#include "utilities/macros.hpp"515253// Initialization done by VM thread in vm_init_globals()54void check_ThreadShadow();55void eventlog_init();56void mutex_init();57void universe_oopstorage_init();58void chunkpool_init();59void perfMemory_init();60void SuspendibleThreadSet_init();6162// Initialization done by Java thread in init_globals()63void management_init();64void bytecodes_init();65void classLoader_init1();66void compilationPolicy_init();67void codeCache_init();68void VM_Version_init();69void stubRoutines_init1();70jint universe_init(); // depends on codeCache_init and stubRoutines_init71// depends on universe_init, must be before interpreter_init (currently only on SPARC)72void gc_barrier_stubs_init();73void interpreter_init_stub(); // before any methods loaded74void interpreter_init_code(); // after methods loaded, but before they are linked75void accessFlags_init();76void InterfaceSupport_init();77void universe2_init(); // dependent on codeCache_init and stubRoutines_init, loads primordial classes78void referenceProcessor_init();79void jni_handles_init();80void vmStructs_init() NOT_DEBUG_RETURN;8182void vtableStubs_init();83void InlineCacheBuffer_init();84void compilerOracle_init();85bool compileBroker_init();86void dependencyContext_init();87void dependencies_init();8889// Initialization after compiler initialization90bool universe_post_init(); // must happen after compiler_init91void javaClasses_init(); // must happen after vtable initialization92void stubRoutines_init2(); // note: StubRoutines need 2-phase init9394// Do not disable thread-local-storage, as it is important for some95// JNI/JVM/JVMTI functions and signal handlers to work properly96// during VM shutdown97void perfMemory_exit();98void ostream_exit();99100void vm_init_globals() {101check_ThreadShadow();102basic_types_init();103eventlog_init();104mutex_init();105universe_oopstorage_init();106chunkpool_init();107perfMemory_init();108SuspendibleThreadSet_init();109}110111112jint init_globals() {113management_init();114JvmtiExport::initialize_oop_storage();115bytecodes_init();116classLoader_init1();117compilationPolicy_init();118codeCache_init();119VM_Version_init(); // depends on codeCache_init for emitting code120stubRoutines_init1();121jint status = universe_init(); // dependent on codeCache_init and122// stubRoutines_init1 and metaspace_init.123if (status != JNI_OK)124return status;125126AsyncLogWriter::initialize();127gc_barrier_stubs_init(); // depends on universe_init, must be before interpreter_init128interpreter_init_stub(); // before methods get loaded129accessFlags_init();130InterfaceSupport_init();131VMRegImpl::set_regName(); // need this before generate_stubs (for printing oop maps).132SharedRuntime::generate_stubs();133universe2_init(); // dependent on codeCache_init and stubRoutines_init1134javaClasses_init();// must happen after vtable initialization, before referenceProcessor_init135interpreter_init_code(); // after javaClasses_init and before any method gets linked136referenceProcessor_init();137jni_handles_init();138#if INCLUDE_VM_STRUCTS139vmStructs_init();140#endif // INCLUDE_VM_STRUCTS141142vtableStubs_init();143InlineCacheBuffer_init();144compilerOracle_init();145dependencyContext_init();146dependencies_init();147148if (!compileBroker_init()) {149return JNI_EINVAL;150}151#if INCLUDE_JVMCI152if (EnableJVMCI) {153JVMCI::initialize_globals();154}155#endif156157if (!universe_post_init()) {158return JNI_ERR;159}160stubRoutines_init2(); // note: StubRoutines need 2-phase init161MethodHandles::generate_adapters();162163// All the flags that get adjusted by VM_Version_init and os::init_2164// have been set so dump the flags now.165if (PrintFlagsFinal || PrintFlagsRanges) {166JVMFlag::printFlags(tty, false, PrintFlagsRanges);167}168169return JNI_OK;170}171172173void exit_globals() {174static bool destructorsCalled = false;175if (!destructorsCalled) {176destructorsCalled = true;177perfMemory_exit();178SafepointTracing::statistics_exit_log();179if (PrintStringTableStatistics) {180SymbolTable::dump(tty);181StringTable::dump(tty);182}183ostream_exit();184}185}186187static volatile bool _init_completed = false;188189bool is_init_completed() {190return Atomic::load_acquire(&_init_completed);191}192193void wait_init_completed() {194MonitorLocker ml(InitCompleted_lock, Monitor::_no_safepoint_check_flag);195while (!_init_completed) {196ml.wait();197}198}199200void set_init_completed() {201assert(Universe::is_fully_initialized(), "Should have completed initialization");202MonitorLocker ml(InitCompleted_lock, Monitor::_no_safepoint_check_flag);203Atomic::release_store(&_init_completed, true);204ml.notify_all();205}206207208