duke@435: /* zgu@7074: * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" coleenp@3865: #include "classfile/symbolTable.hpp" stefank@2314: #include "code/icBuffer.hpp" stefank@2314: #include "gc_interface/collectedHeap.hpp" stefank@2314: #include "interpreter/bytecodes.hpp" stefank@2314: #include "memory/universe.hpp" stefank@2314: #include "prims/methodHandles.hpp" stefank@2314: #include "runtime/handles.inline.hpp" stefank@2314: #include "runtime/icache.hpp" stefank@2314: #include "runtime/init.hpp" stefank@2314: #include "runtime/safepoint.hpp" stefank@2314: #include "runtime/sharedRuntime.hpp" zgu@7074: #include "services/memTracker.hpp" jprovino@4542: #include "utilities/macros.hpp" duke@435: zgu@7074: duke@435: // Initialization done by VM thread in vm_init_globals() duke@435: void check_ThreadShadow(); duke@435: void eventlog_init(); duke@435: void mutex_init(); duke@435: void chunkpool_init(); duke@435: void perfMemory_init(); duke@435: duke@435: // Initialization done by Java thread in init_globals() duke@435: void management_init(); duke@435: void bytecodes_init(); duke@435: void classLoader_init(); duke@435: void codeCache_init(); duke@435: void VM_Version_init(); phh@3378: void os_init_globals(); // depends on VM_Version_init, before universe_init duke@435: void stubRoutines_init1(); phh@3378: jint universe_init(); // depends on codeCache_init and stubRoutines_init phh@3378: void interpreter_init(); // before any methods loaded phh@3378: void invocationCounter_init(); // before any methods loaded duke@435: void marksweep_init(); duke@435: void accessFlags_init(); duke@435: void templateTable_init(); duke@435: void InterfaceSupport_init(); phh@3378: void universe2_init(); // dependent on codeCache_init and stubRoutines_init, loads primordial classes duke@435: void referenceProcessor_init(); duke@435: void jni_handles_init(); duke@435: void vmStructs_init(); duke@435: duke@435: void vtableStubs_init(); duke@435: void InlineCacheBuffer_init(); duke@435: void compilerOracle_init(); duke@435: void compilationPolicy_init(); never@3499: void compileBroker_init(); duke@435: duke@435: // Initialization after compiler initialization duke@435: bool universe_post_init(); // must happen after compiler_init duke@435: void javaClasses_init(); // must happen after vtable initialization duke@435: void stubRoutines_init2(); // note: StubRoutines need 2-phase init duke@435: duke@435: // Do not disable thread-local-storage, as it is important for some duke@435: // JNI/JVM/JVMTI functions and signal handlers to work properly duke@435: // during VM shutdown duke@435: void perfMemory_exit(); duke@435: void ostream_exit(); duke@435: duke@435: void vm_init_globals() { duke@435: check_ThreadShadow(); coleenp@548: basic_types_init(); duke@435: eventlog_init(); duke@435: mutex_init(); duke@435: chunkpool_init(); duke@435: perfMemory_init(); duke@435: } duke@435: duke@435: duke@435: jint init_globals() { duke@435: HandleMark hm; duke@435: management_init(); duke@435: bytecodes_init(); duke@435: classLoader_init(); duke@435: codeCache_init(); duke@435: VM_Version_init(); phh@3378: os_init_globals(); duke@435: stubRoutines_init1(); phh@3378: jint status = universe_init(); // dependent on codeCache_init and coleenp@4037: // stubRoutines_init1 and metaspace_init. duke@435: if (status != JNI_OK) duke@435: return status; duke@435: duke@435: interpreter_init(); // before any methods loaded duke@435: invocationCounter_init(); // before any methods loaded duke@435: marksweep_init(); duke@435: accessFlags_init(); duke@435: templateTable_init(); duke@435: InterfaceSupport_init(); duke@435: SharedRuntime::generate_stubs(); phh@3378: universe2_init(); // dependent on codeCache_init and stubRoutines_init1 duke@435: referenceProcessor_init(); duke@435: jni_handles_init(); jprovino@4165: #if INCLUDE_VM_STRUCTS duke@435: vmStructs_init(); jprovino@4165: #endif // INCLUDE_VM_STRUCTS duke@435: duke@435: vtableStubs_init(); duke@435: InlineCacheBuffer_init(); duke@435: compilerOracle_init(); duke@435: compilationPolicy_init(); never@3499: compileBroker_init(); duke@435: VMRegImpl::set_regName(); duke@435: duke@435: if (!universe_post_init()) { duke@435: return JNI_ERR; duke@435: } phh@3378: javaClasses_init(); // must happen after vtable initialization duke@435: stubRoutines_init2(); // note: StubRoutines need 2-phase init duke@435: zgu@7074: #if INCLUDE_NMT zgu@7074: // Solaris stack is walkable only after stubRoutines are set up. zgu@7074: // On Other platforms, the stack is always walkable. zgu@7074: NMT_stack_walkable = true; zgu@7074: #endif // INCLUDE_NMT zgu@7074: never@2085: // All the flags that get adjusted by VM_Version_init and os::init_2 never@2085: // have been set so dump the flags now. never@2085: if (PrintFlagsFinal) { fparain@3402: CommandLineFlags::printFlags(tty, false); never@2085: } never@2085: duke@435: return JNI_OK; duke@435: } duke@435: duke@435: duke@435: void exit_globals() { duke@435: static bool destructorsCalled = false; duke@435: if (!destructorsCalled) { duke@435: destructorsCalled = true; duke@435: perfMemory_exit(); duke@435: if (PrintSafepointStatistics) { duke@435: // Print the collected safepoint statistics. duke@435: SafepointSynchronize::print_stat_on_exit(); duke@435: } coleenp@3865: if (PrintStringTableStatistics) { coleenp@3865: SymbolTable::dump(tty); coleenp@3865: StringTable::dump(tty); coleenp@3865: } duke@435: ostream_exit(); duke@435: } duke@435: } duke@435: duke@435: duke@435: static bool _init_completed = false; duke@435: duke@435: bool is_init_completed() { duke@435: return _init_completed; duke@435: } duke@435: duke@435: duke@435: void set_init_completed() { ysr@2301: assert(Universe::is_fully_initialized(), "Should have completed initialization"); duke@435: _init_completed = true; duke@435: }