1 /*
   2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 # include "incls/_precompiled.incl"
  26 # include "incls/_init.cpp.incl"
  27 
  28 // Initialization done by VM thread in vm_init_globals()
  29 void check_ThreadShadow();
  30 void eventlog_init();
  31 void mutex_init();
  32 void chunkpool_init();
  33 void perfMemory_init();
  34 
  35 // Initialization done by Java thread in init_globals()
  36 void management_init();
  37 void bytecodes_init();
  38 void classLoader_init();
  39 void codeCache_init();
  40 void VM_Version_init();
  41 void stubRoutines_init1();
  42 jint universe_init();  // dependent on codeCache_init and stubRoutines_init
  43 void interpreter_init();  // before any methods loaded
  44 void invocationCounter_init();  // before any methods loaded
  45 void marksweep_init();
  46 void accessFlags_init();
  47 void templateTable_init();
  48 void InterfaceSupport_init();
  49 void universe2_init();  // dependent on codeCache_init and stubRoutines_init
  50 void referenceProcessor_init();
  51 void jni_handles_init();
  52 void vmStructs_init();
  53 
  54 void vtableStubs_init();
  55 void InlineCacheBuffer_init();
  56 void compilerOracle_init();
  57 void compilationPolicy_init();
  58 
  59 
  60 // Initialization after compiler initialization
  61 bool universe_post_init();  // must happen after compiler_init
  62 void javaClasses_init();  // must happen after vtable initialization
  63 void stubRoutines_init2(); // note: StubRoutines need 2-phase init
  64 
  65 // Do not disable thread-local-storage, as it is important for some
  66 // JNI/JVM/JVMTI functions and signal handlers to work properly
  67 // during VM shutdown
  68 void perfMemory_exit();
  69 void ostream_exit();
  70 
  71 void vm_init_globals() {
  72   check_ThreadShadow();
  73   basic_types_init();
  74   eventlog_init();
  75   mutex_init();
  76   chunkpool_init();
  77   perfMemory_init();
  78 }
  79 
  80 
  81 jint init_globals() {
  82   HandleMark hm;
  83   management_init();
  84   bytecodes_init();
  85   classLoader_init();
  86   codeCache_init();
  87   VM_Version_init();
  88   stubRoutines_init1();
  89   jint status = universe_init();  // dependent on codeCache_init and stubRoutines_init
  90   if (status != JNI_OK)
  91     return status;
  92 
  93   interpreter_init();  // before any methods loaded
  94   invocationCounter_init();  // before any methods loaded
  95   marksweep_init();
  96   accessFlags_init();
  97   templateTable_init();
  98   InterfaceSupport_init();
  99   SharedRuntime::generate_stubs();
 100   universe2_init();  // dependent on codeCache_init and stubRoutines_init
 101   referenceProcessor_init();
 102   jni_handles_init();
 103 #ifndef VM_STRUCTS_KERNEL
 104   vmStructs_init();
 105 #endif // VM_STRUCTS_KERNEL
 106 
 107   vtableStubs_init();
 108   InlineCacheBuffer_init();
 109   compilerOracle_init();
 110   compilationPolicy_init();
 111   VMRegImpl::set_regName();
 112 
 113   if (!universe_post_init()) {
 114     return JNI_ERR;
 115   }
 116   javaClasses_init();  // must happen after vtable initialization
 117   stubRoutines_init2(); // note: StubRoutines need 2-phase init
 118 
 119   // Generate MethodHandles adapters.
 120   MethodHandles::generate_adapters();
 121 
 122   // Although we'd like to, we can't easily do a heap verify
 123   // here because the main thread isn't yet a JavaThread, so
 124   // its TLAB may not be made parseable from the usual interfaces.
 125   if (VerifyBeforeGC && !UseTLAB &&
 126       Universe::heap()->total_collections() >= VerifyGCStartAt) {
 127     Universe::heap()->prepare_for_verify();
 128     Universe::verify();   // make sure we're starting with a clean slate
 129   }
 130 
 131   // All the flags that get adjusted by VM_Version_init and os::init_2
 132   // have been set so dump the flags now.
 133   if (PrintFlagsFinal) {
 134     CommandLineFlags::printFlags();
 135   }
 136 
 137   return JNI_OK;
 138 }
 139 
 140 
 141 void exit_globals() {
 142   static bool destructorsCalled = false;
 143   if (!destructorsCalled) {
 144     destructorsCalled = true;
 145     perfMemory_exit();
 146     if (PrintSafepointStatistics) {
 147       // Print the collected safepoint statistics.
 148       SafepointSynchronize::print_stat_on_exit();
 149     }
 150     ostream_exit();
 151   }
 152 }
 153 
 154 
 155 static bool _init_completed = false;
 156 
 157 bool is_init_completed() {
 158   return _init_completed;
 159 }
 160 
 161 
 162 void set_init_completed() {
 163   _init_completed = true;
 164 }