< prev index next >

src/hotspot/share/runtime/init.cpp

Print this page

  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 "classfile/stringTable.hpp"
 26 #include "classfile/symbolTable.hpp"

 27 #include "code/aotCodeCache.hpp"
 28 #include "compiler/compiler_globals.hpp"
 29 #include "gc/shared/collectedHeap.hpp"
 30 #include "gc/shared/gcHeapSummary.hpp"
 31 #include "interpreter/bytecodes.hpp"
 32 #include "logging/logAsyncWriter.hpp"
 33 #include "memory/universe.hpp"
 34 #include "nmt/memTracker.hpp"
 35 #include "oops/trainingData.hpp"
 36 #include "prims/downcallLinker.hpp"
 37 #include "prims/jvmtiExport.hpp"
 38 #include "prims/methodHandles.hpp"
 39 #include "runtime/atomic.hpp"
 40 #include "runtime/continuation.hpp"
 41 #include "runtime/flags/jvmFlag.hpp"
 42 #include "runtime/globals.hpp"
 43 #include "runtime/handles.inline.hpp"
 44 #include "runtime/icache.hpp"
 45 #include "runtime/init.hpp"
 46 #include "runtime/safepoint.hpp"
 47 #include "runtime/sharedRuntime.hpp"
 48 #include "sanitizers/leak.hpp"
 49 #include "utilities/macros.hpp"

 50 #if INCLUDE_JVMCI
 51 #include "jvmci/jvmci.hpp"
 52 #endif
 53 
 54 // Initialization done by VM thread in vm_init_globals()
 55 void check_ThreadShadow();
 56 void eventlog_init();
 57 void mutex_init();
 58 void universe_oopstorage_init();
 59 void perfMemory_init();
 60 void SuspendibleThreadSet_init();
 61 void ExternalsRecorder_init(); // After mutex_init() and before CodeCache_init
 62 
 63 // Initialization done by Java thread in init_globals()
 64 void management_init();
 65 void bytecodes_init();
 66 void classLoader_init1();
 67 void compilationPolicy_init();
 68 void codeCache_init();
 69 void VM_Version_init();
 70 void icache_init2();

 71 void initial_stubs_init();
 72 
 73 jint universe_init();           // depends on codeCache_init and initial_stubs_init
 74 // depends on universe_init, must be before interpreter_init (currently only on SPARC)
 75 void gc_barrier_stubs_init();
 76 void continuations_init();      // depends on flags (UseCompressedOops) and barrier sets
 77 void continuation_stubs_init(); // depend on continuations_init
 78 void interpreter_init_stub();   // before any methods loaded
 79 void interpreter_init_code();   // after methods loaded, but before they are linked
 80 void accessFlags_init();
 81 void InterfaceSupport_init();
 82 void universe2_init();  // dependent on codeCache_init and initial_stubs_init, loads primordial classes
 83 void referenceProcessor_init();
 84 void jni_handles_init();
 85 void vmStructs_init() NOT_DEBUG_RETURN;
 86 
 87 void vtableStubs_init();
 88 bool compilerOracle_init();
 89 bool compileBroker_init();
 90 void dependencyContext_init();
 91 void dependencies_init();
 92 








 93 // Initialization after compiler initialization
 94 bool universe_post_init();  // must happen after compiler_init
 95 void javaClasses_init();    // must happen after vtable initialization
 96 void compiler_stubs_init(bool in_compiler_thread); // compiler's StubRoutines stubs
 97 void final_stubs_init();    // final StubRoutines stubs
 98 
 99 // Do not disable thread-local-storage, as it is important for some
100 // JNI/JVM/JVMTI functions and signal handlers to work properly
101 // during VM shutdown
102 void perfMemory_exit();
103 void ostream_exit();
104 


105 void vm_init_globals() {
106   check_ThreadShadow();
107   basic_types_init();
108   eventlog_init();
109   mutex_init();
110   universe_oopstorage_init();
111   perfMemory_init();
112   SuspendibleThreadSet_init();
113   ExternalsRecorder_init(); // After mutex_init() and before CodeCache_init
114 }
115 
116 
117 jint init_globals() {



118   management_init();
119   JvmtiExport::initialize_oop_storage();
120 #if INCLUDE_JVMTI
121   if (AlwaysRecordEvolDependencies) {
122     JvmtiExport::set_can_hotswap_or_post_breakpoint(true);
123     JvmtiExport::set_all_dependencies_are_recorded(true);
124   }
125 #endif
126   bytecodes_init();
127   classLoader_init1();
128   compilationPolicy_init();

129   codeCache_init();
130   VM_Version_init();              // depends on codeCache_init for emitting code
131   icache_init2();                 // depends on VM_Version for choosing the mechanism
132   // stub routines in initial blob are referenced by later generated code
133   initial_stubs_init();
134   // stack overflow exception blob is referenced by the interpreter
135   SharedRuntime::generate_initial_stubs();
136   jint status = universe_init();  // dependent on codeCache_init and
137                                   // initial_stubs_init and metaspace_init.
138   if (status != JNI_OK)
139     return status;
140 
141 #ifdef LEAK_SANITIZER
142   {
143     // Register the Java heap with LSan.
144     VirtualSpaceSummary summary = Universe::heap()->create_heap_space_summary();
145     LSAN_REGISTER_ROOT_REGION(summary.start(), summary.reserved_size());
146   }
147 #endif // LEAK_SANITIZER
148   AOTCodeCache::init2();     // depends on universe_init
149   AsyncLogWriter::initialize();





150   gc_barrier_stubs_init();   // depends on universe_init, must be before interpreter_init
151   continuations_init();      // must precede continuation stub generation
152   continuation_stubs_init(); // depends on continuations_init
153 #if INCLUDE_JFR
154   SharedRuntime::generate_jfr_stubs();
155 #endif
156   interpreter_init_stub();   // before methods get loaded
157   accessFlags_init();
158   InterfaceSupport_init();
159   VMRegImpl::set_regName();  // need this before generate_stubs (for printing oop maps).
160   SharedRuntime::generate_stubs();
161   AOTCodeCache::init_shared_blobs_table();  // need this after generate_stubs
162   SharedRuntime::init_adapter_library(); // do this after AOTCodeCache::init_shared_blobs_table
163   return JNI_OK;
164 }
165 
166 jint init_globals2() {
167   universe2_init();          // dependent on codeCache_init and initial_stubs_init













168   javaClasses_init();        // must happen after vtable initialization, before referenceProcessor_init
169   interpreter_init_code();   // after javaClasses_init and before any method gets linked
170   referenceProcessor_init();
171   jni_handles_init();
172 #if INCLUDE_VM_STRUCTS
173   vmStructs_init();
174 #endif // INCLUDE_VM_STRUCTS
175 
176   vtableStubs_init();
177   if (!compilerOracle_init()) {
178     return JNI_EINVAL;
179   }
180   dependencyContext_init();
181   dependencies_init();
182 
183   if (!compileBroker_init()) {
184     return JNI_EINVAL;
185   }
186 #if INCLUDE_JVMCI
187   if (EnableJVMCI) {
188     JVMCI::initialize_globals();
189   }
190 #endif




191 
192   // Initialize TrainingData only we're recording/replaying
193   if (TrainingData::have_data() || TrainingData::need_data()) {
194    TrainingData::initialize();
195   }
196 
197   if (!universe_post_init()) {
198     return JNI_ERR;
199   }
200   compiler_stubs_init(false /* in_compiler_thread */); // compiler's intrinsics stubs
201   final_stubs_init();    // final StubRoutines stubs

202   MethodHandles::generate_adapters();
203 
204   // All the flags that get adjusted by VM_Version_init and os::init_2
205   // have been set so dump the flags now.
206   if (PrintFlagsFinal || PrintFlagsRanges) {
207     JVMFlag::printFlags(tty, false, PrintFlagsRanges);


208   }
209 
210   return JNI_OK;
211 }
212 
213 
214 void exit_globals() {
215   static bool destructorsCalled = false;
216   if (!destructorsCalled) {
217     destructorsCalled = true;
218     perfMemory_exit();
219     SafepointTracing::statistics_exit_log();
220     if (PrintStringTableStatistics) {
221       SymbolTable::dump(tty);
222       StringTable::dump(tty);
223     }
224     ostream_exit();
225 #ifdef LEAK_SANITIZER
226     {
227       // Unregister the Java heap with LSan.

  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 "cds/metaspaceShared.hpp"
 26 #include "classfile/stringTable.hpp"
 27 #include "classfile/symbolTable.hpp"
 28 #include "classfile/systemDictionary.hpp"
 29 #include "code/aotCodeCache.hpp"
 30 #include "compiler/compiler_globals.hpp"
 31 #include "gc/shared/collectedHeap.hpp"
 32 #include "gc/shared/gcHeapSummary.hpp"
 33 #include "interpreter/bytecodes.hpp"
 34 #include "logging/logAsyncWriter.hpp"
 35 #include "memory/universe.hpp"
 36 #include "nmt/memTracker.hpp"
 37 #include "oops/trainingData.hpp"
 38 #include "prims/downcallLinker.hpp"
 39 #include "prims/jvmtiExport.hpp"
 40 #include "prims/methodHandles.hpp"
 41 #include "runtime/atomic.hpp"
 42 #include "runtime/continuation.hpp"
 43 #include "runtime/flags/jvmFlag.hpp"
 44 #include "runtime/globals.hpp"
 45 #include "runtime/handles.inline.hpp"
 46 #include "runtime/icache.hpp"
 47 #include "runtime/init.hpp"
 48 #include "runtime/safepoint.hpp"
 49 #include "runtime/sharedRuntime.hpp"
 50 #include "sanitizers/leak.hpp"
 51 #include "utilities/macros.hpp"
 52 #include "utilities/xmlstream.hpp"
 53 #if INCLUDE_JVMCI
 54 #include "jvmci/jvmci.hpp"
 55 #endif
 56 
 57 // Initialization done by VM thread in vm_init_globals()
 58 void check_ThreadShadow();
 59 void eventlog_init();
 60 void mutex_init();
 61 void universe_oopstorage_init();
 62 void perfMemory_init();
 63 void SuspendibleThreadSet_init();
 64 void ExternalsRecorder_init(); // After mutex_init() and before CodeCache_init
 65 
 66 // Initialization done by Java thread in init_globals()
 67 void management_init();
 68 void bytecodes_init();
 69 void classLoader_init1();
 70 void compilationPolicy_init();
 71 void codeCache_init();
 72 void VM_Version_init();
 73 void icache_init2();
 74 void preuniverse_stubs_init();
 75 void initial_stubs_init();
 76 
 77 jint universe_init();           // depends on codeCache_init and preuniverse_stubs_init
 78 // depends on universe_init, must be before interpreter_init (currently only on SPARC)
 79 void gc_barrier_stubs_init();
 80 void continuations_init();      // depends on flags (UseCompressedOops) and barrier sets
 81 void continuation_stubs_init(); // depend on continuations_init
 82 void interpreter_init_stub();   // before any methods loaded
 83 void interpreter_init_code();   // after methods loaded, but before they are linked
 84 void accessFlags_init();
 85 void InterfaceSupport_init();
 86 void universe2_init();  // dependent on codeCache_init and initial_stubs_init, loads primordial classes
 87 void referenceProcessor_init();
 88 void jni_handles_init();
 89 void vmStructs_init() NOT_DEBUG_RETURN;
 90 
 91 void vtableStubs_init();
 92 bool compilerOracle_init();
 93 bool compileBroker_init();
 94 void dependencyContext_init();
 95 void dependencies_init();
 96 
 97 // initialize upcalls before class loading
 98 bool runtimeUpcalls_open_registration();
 99 bool runtimeUpcallNop_register_upcalls();
100 #if INCLUDE_CDS
101 bool cdsEndTrainingUpcall_register_upcalls();
102 #endif // INCLUDE_CDS
103 void runtimeUpcalls_close_registration();
104 
105 // Initialization after compiler initialization
106 bool universe_post_init();  // must happen after compiler_init
107 void javaClasses_init();    // must happen after vtable initialization
108 void compiler_stubs_init(bool in_compiler_thread); // compiler's StubRoutines stubs
109 void final_stubs_init();    // final StubRoutines stubs
110 
111 // Do not disable thread-local-storage, as it is important for some
112 // JNI/JVM/JVMTI functions and signal handlers to work properly
113 // during VM shutdown
114 void perfMemory_exit();
115 void ostream_exit();
116 
117 void perf_jvm_init();
118 
119 void vm_init_globals() {
120   check_ThreadShadow();
121   basic_types_init();
122   eventlog_init();
123   mutex_init();
124   universe_oopstorage_init();
125   perfMemory_init();
126   SuspendibleThreadSet_init();
127   ExternalsRecorder_init(); // After mutex_init() and before CodeCache_init
128 }
129 
130 
131 jint init_globals() {
132   perf_jvm_init();
133   MethodHandles::init_counters();
134 
135   management_init();
136   JvmtiExport::initialize_oop_storage();
137 #if INCLUDE_JVMTI
138   if (AlwaysRecordEvolDependencies) {
139     JvmtiExport::set_can_hotswap_or_post_breakpoint(true);
140     JvmtiExport::set_all_dependencies_are_recorded(true);
141   }
142 #endif
143   bytecodes_init();
144   classLoader_init1();
145   compilationPolicy_init();
146   MetaspaceShared::open_static_archive();
147   codeCache_init();
148   VM_Version_init();              // depends on codeCache_init for emitting code
149   icache_init2();                 // depends on VM_Version for choosing the mechanism
150   // initialize stubs needed before we can init the universe
151   preuniverse_stubs_init();
152   jint status = universe_init();  // dependent on codeCache_init and preuniverse_stubs_init
153   if (status != JNI_OK) {



154     return status;
155   }
156 #ifdef LEAK_SANITIZER
157   {
158     // Register the Java heap with LSan.
159     VirtualSpaceSummary summary = Universe::heap()->create_heap_space_summary();
160     LSAN_REGISTER_ROOT_REGION(summary.start(), summary.reserved_size());
161   }
162 #endif // LEAK_SANITIZER
163   AOTCodeCache::init2();     // depends on universe_init, must be before initial_stubs_init
164   AsyncLogWriter::initialize();
165 
166   initial_stubs_init();      // initial stub routines
167   // stack overflow exception blob is referenced by the interpreter
168   SharedRuntime::generate_initial_stubs();
169   AOTCodeCache::init_early_stubs_table();  // need this after initial_stubs
170   gc_barrier_stubs_init();   // depends on universe_init, must be before interpreter_init
171   continuations_init();      // must precede continuation stub generation
172   continuation_stubs_init(); // depends on continuations_init
173 #if INCLUDE_JFR
174   SharedRuntime::generate_jfr_stubs();
175 #endif
176   interpreter_init_stub();   // before methods get loaded
177   accessFlags_init();
178   InterfaceSupport_init();
179   VMRegImpl::set_regName();  // need this before generate_stubs (for printing oop maps).
180   SharedRuntime::generate_stubs();
181   AOTCodeCache::init_shared_blobs_table();  // need this after generate_stubs
182   SharedRuntime::init_adapter_library(); // do this after AOTCodeCache::init_shared_blobs_table
183   return JNI_OK;
184 }
185 
186 jint init_globals2() {
187   universe2_init();          // dependent on codeCache_init and initial_stubs_init
188 
189   // initialize upcalls before class loading / initialization
190   runtimeUpcalls_open_registration();
191   if (!runtimeUpcallNop_register_upcalls()) {
192     return JNI_EINVAL;
193   }
194 #if INCLUDE_CDS
195   if (!cdsEndTrainingUpcall_register_upcalls()) {
196     return JNI_EINVAL;
197   }
198 #endif // INCLUDE_CDS
199   runtimeUpcalls_close_registration();
200 
201   javaClasses_init();        // must happen after vtable initialization, before referenceProcessor_init
202   interpreter_init_code();   // after javaClasses_init and before any method gets linked
203   referenceProcessor_init();
204   jni_handles_init();
205 #if INCLUDE_VM_STRUCTS
206   vmStructs_init();
207 #endif // INCLUDE_VM_STRUCTS
208 
209   vtableStubs_init();
210   if (!compilerOracle_init()) {
211     return JNI_EINVAL;
212   }
213   dependencyContext_init();
214   dependencies_init();
215 
216   if (!compileBroker_init()) {
217     return JNI_EINVAL;
218   }
219 #if INCLUDE_JVMCI
220   if (EnableJVMCI) {
221     JVMCI::initialize_globals();
222   }
223 #endif
224   // Initialize TrainingData only we're recording/replaying
225   if (TrainingData::have_data() || TrainingData::need_data()) {
226     TrainingData::initialize();
227   }
228 
229   // Initialize TrainingData only we're recording/replaying
230   if (TrainingData::have_data() || TrainingData::need_data()) {
231    TrainingData::initialize();
232   }
233 
234   if (!universe_post_init()) {
235     return JNI_ERR;
236   }
237   compiler_stubs_init(false /* in_compiler_thread */); // compiler's intrinsics stubs
238   final_stubs_init();    // final StubRoutines stubs
239   AOTCodeCache::init_stubs_table();
240   MethodHandles::generate_adapters();
241 
242   // All the flags that get adjusted by VM_Version_init and os::init_2
243   // have been set so dump the flags now.
244   if (PrintFlagsFinal || PrintFlagsRanges) {
245     JVMFlag::printFlags(tty, false, PrintFlagsRanges);
246   } else if (AOTRecordTraining && xtty != nullptr) {
247     JVMFlag::printFlags(xtty->log_only(), false, PrintFlagsRanges);
248   }
249 
250   return JNI_OK;
251 }
252 
253 
254 void exit_globals() {
255   static bool destructorsCalled = false;
256   if (!destructorsCalled) {
257     destructorsCalled = true;
258     perfMemory_exit();
259     SafepointTracing::statistics_exit_log();
260     if (PrintStringTableStatistics) {
261       SymbolTable::dump(tty);
262       StringTable::dump(tty);
263     }
264     ostream_exit();
265 #ifdef LEAK_SANITIZER
266     {
267       // Unregister the Java heap with LSan.
< prev index next >