< prev index next >

src/hotspot/share/runtime/init.cpp

Print this page

  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 "precompiled.hpp"

 26 #include "classfile/stringTable.hpp"
 27 #include "classfile/symbolTable.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 "prims/downcallLinker.hpp"
 36 #include "prims/jvmtiExport.hpp"
 37 #include "prims/methodHandles.hpp"
 38 #include "runtime/atomic.hpp"
 39 #include "runtime/continuation.hpp"
 40 #include "runtime/flags/jvmFlag.hpp"
 41 #include "runtime/globals.hpp"
 42 #include "runtime/handles.inline.hpp"
 43 #include "runtime/icache.hpp"
 44 #include "runtime/init.hpp"
 45 #include "runtime/safepoint.hpp"
 46 #include "runtime/sharedRuntime.hpp"
 47 #include "sanitizers/leak.hpp"
 48 #include "utilities/macros.hpp"

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

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








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


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



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

127   codeCache_init();
128   VM_Version_init();              // depends on codeCache_init for emitting code
129   // stub routines in initial blob are referenced by later generated code
130   initial_stubs_init();
131   // stack overflow exception blob is referenced by the interpreter
132   SharedRuntime::generate_initial_stubs();
133   jint status = universe_init();  // dependent on codeCache_init and
134                                   // initial_stubs_init and metaspace_init.
135   if (status != JNI_OK)
136     return status;
137 
138 #ifdef LEAK_SANITIZER
139   {
140     // Register the Java heap with LSan.
141     VirtualSpaceSummary summary = Universe::heap()->create_heap_space_summary();
142     LSAN_REGISTER_ROOT_REGION(summary.start(), summary.reserved_size());
143   }
144 #endif // LEAK_SANITIZER
145 
146   AsyncLogWriter::initialize();
147   gc_barrier_stubs_init();   // depends on universe_init, must be before interpreter_init
148   continuations_init();      // must precede continuation stub generation
149   continuation_stubs_init(); // depends on continuations_init
150 #if INCLUDE_JFR
151   SharedRuntime::generate_jfr_stubs();
152 #endif
153   interpreter_init_stub();   // before methods get loaded
154   accessFlags_init();
155   InterfaceSupport_init();
156   VMRegImpl::set_regName();  // need this before generate_stubs (for printing oop maps).
157   SharedRuntime::generate_stubs();
158   return JNI_OK;
159 }
160 
161 jint init_globals2() {
162   universe2_init();          // dependent on codeCache_init and initial_stubs_init













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




187   if (!universe_post_init()) {
188     return JNI_ERR;
189   }
190   compiler_stubs_init(false /* in_compiler_thread */); // compiler's intrinsics stubs
191   final_stubs_init();    // final StubRoutines stubs
192   MethodHandles::generate_adapters();
193 
194   // All the flags that get adjusted by VM_Version_init and os::init_2
195   // have been set so dump the flags now.
196   if (PrintFlagsFinal || PrintFlagsRanges) {
197     JVMFlag::printFlags(tty, false, PrintFlagsRanges);


198   }
199 
200   return JNI_OK;
201 }
202 
203 
204 void exit_globals() {
205   static bool destructorsCalled = false;
206   if (!destructorsCalled) {
207     destructorsCalled = true;
208     perfMemory_exit();
209     SafepointTracing::statistics_exit_log();
210     if (PrintStringTableStatistics) {
211       SymbolTable::dump(tty);
212       StringTable::dump(tty);
213     }
214     ostream_exit();
215 #ifdef LEAK_SANITIZER
216     {
217       // Unregister the Java heap with LSan.

  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 "precompiled.hpp"
 26 #include "cds/metaspaceShared.hpp"
 27 #include "classfile/stringTable.hpp"
 28 #include "classfile/symbolTable.hpp"
 29 #include "classfile/systemDictionary.hpp"
 30 #include "code/SCCache.hpp"
 31 #include "compiler/compiler_globals.hpp"
 32 #include "gc/shared/collectedHeap.hpp"
 33 #include "gc/shared/gcHeapSummary.hpp"
 34 #include "interpreter/bytecodes.hpp"
 35 #include "logging/logAsyncWriter.hpp"
 36 #include "memory/universe.hpp"
 37 #include "nmt/memTracker.hpp"
 38 #include "oops/trainingData.hpp"
 39 #include "prims/downcallLinker.hpp"
 40 #include "prims/jvmtiExport.hpp"
 41 #include "prims/methodHandles.hpp"
 42 #include "runtime/atomic.hpp"
 43 #include "runtime/continuation.hpp"
 44 #include "runtime/flags/jvmFlag.hpp"
 45 #include "runtime/globals.hpp"
 46 #include "runtime/handles.inline.hpp"
 47 #include "runtime/icache.hpp"
 48 #include "runtime/init.hpp"
 49 #include "runtime/safepoint.hpp"
 50 #include "runtime/sharedRuntime.hpp"
 51 #include "sanitizers/leak.hpp"
 52 #include "utilities/macros.hpp"
 53 #include "utilities/xmlstream.hpp"
 54 #if INCLUDE_JVMCI
 55 #include "jvmci/jvmci.hpp"
 56 #endif
 57 
 58 // Initialization done by VM thread in vm_init_globals()
 59 void check_ThreadShadow();
 60 void eventlog_init();
 61 void mutex_init();
 62 void universe_oopstorage_init();
 63 void perfMemory_init();
 64 void SuspendibleThreadSet_init();
 65 void ExternalsRecorder_init(); // After mutex_init() and before CodeCache_init
 66 
 67 // Initialization done by Java thread in init_globals()
 68 void management_init();
 69 void bytecodes_init();
 70 void classLoader_init1();
 71 void compilationPolicy_init();
 72 void codeCache_init();
 73 void VM_Version_init();

 76 jint universe_init();           // depends on codeCache_init and initial_stubs_init
 77 // depends on universe_init, must be before interpreter_init (currently only on SPARC)
 78 void gc_barrier_stubs_init();
 79 void continuations_init();      // depends on flags (UseCompressedOops) and barrier sets
 80 void continuation_stubs_init(); // depend on continuations_init
 81 void interpreter_init_stub();   // before any methods loaded
 82 void interpreter_init_code();   // after methods loaded, but before they are linked
 83 void accessFlags_init();
 84 void InterfaceSupport_init();
 85 void universe2_init();  // dependent on codeCache_init and initial_stubs_init, loads primordial classes
 86 void referenceProcessor_init();
 87 void jni_handles_init();
 88 void vmStructs_init() NOT_DEBUG_RETURN;
 89 
 90 void vtableStubs_init();
 91 bool compilerOracle_init();
 92 bool compileBroker_init();
 93 void dependencyContext_init();
 94 void dependencies_init();
 95 
 96 // initialize upcalls before class loading
 97 bool runtimeUpcalls_open_registration();
 98 bool runtimeUpcallNop_register_upcalls();
 99 #if INCLUDE_CDS
100 bool cdsEndTrainingUpcall_register_upcalls();
101 #endif // INCLUDE_CDS
102 bool runtimeUpcalls_close_registration();
103 
104 // Initialization after compiler initialization
105 bool universe_post_init();  // must happen after compiler_init
106 void javaClasses_init();    // must happen after vtable initialization
107 void compiler_stubs_init(bool in_compiler_thread); // compiler's StubRoutines stubs
108 void final_stubs_init();    // final StubRoutines stubs
109 
110 // Do not disable thread-local-storage, as it is important for some
111 // JNI/JVM/JVMTI functions and signal handlers to work properly
112 // during VM shutdown
113 void perfMemory_exit();
114 void ostream_exit();
115 
116 void perf_jvm_init();
117 
118 void vm_init_globals() {
119   check_ThreadShadow();
120   basic_types_init();
121   eventlog_init();
122   mutex_init();
123   universe_oopstorage_init();
124   perfMemory_init();
125   SuspendibleThreadSet_init();
126   ExternalsRecorder_init(); // After mutex_init() and before CodeCache_init
127 }
128 
129 
130 jint init_globals() {
131   perf_jvm_init();
132   MethodHandles::init_counters();
133 
134   management_init();
135   JvmtiExport::initialize_oop_storage();
136 #if INCLUDE_JVMTI
137   if (AlwaysRecordEvolDependencies) {
138     JvmtiExport::set_can_hotswap_or_post_breakpoint(true);
139     JvmtiExport::set_all_dependencies_are_recorded(true);
140   }
141 #endif
142   bytecodes_init();
143   classLoader_init1();
144   compilationPolicy_init();
145   MetaspaceShared::open_static_archive();
146   codeCache_init();
147   VM_Version_init();              // depends on codeCache_init for emitting code
148   // stub routines in initial blob are referenced by later generated code
149   initial_stubs_init();
150   // stack overflow exception blob is referenced by the interpreter
151   SharedRuntime::generate_initial_stubs();
152   jint status = universe_init();  // dependent on codeCache_init and
153                                   // initial_stubs_init and metaspace_init.
154   if (status != JNI_OK)
155     return status;
156   SCCache::initialize();
157 #ifdef LEAK_SANITIZER
158   {
159     // Register the Java heap with LSan.
160     VirtualSpaceSummary summary = Universe::heap()->create_heap_space_summary();
161     LSAN_REGISTER_ROOT_REGION(summary.start(), summary.reserved_size());
162   }
163 #endif // LEAK_SANITIZER
164   SCCache::init2();        // depends on universe_init
165   AsyncLogWriter::initialize();
166   gc_barrier_stubs_init();   // depends on universe_init, must be before interpreter_init
167   continuations_init();      // must precede continuation stub generation
168   continuation_stubs_init(); // depends on continuations_init
169 #if INCLUDE_JFR
170   SharedRuntime::generate_jfr_stubs();
171 #endif
172   interpreter_init_stub();   // before methods get loaded
173   accessFlags_init();
174   InterfaceSupport_init();
175   VMRegImpl::set_regName();  // need this before generate_stubs (for printing oop maps).
176   SharedRuntime::generate_stubs();
177   return JNI_OK;
178 }
179 
180 jint init_globals2() {
181   universe2_init();          // dependent on codeCache_init and initial_stubs_init
182 
183   // initialize upcalls before class loading / initialization
184   runtimeUpcalls_open_registration();
185   if (!runtimeUpcallNop_register_upcalls()) {
186     return JNI_EINVAL;
187   }
188 #if INCLUDE_CDS
189   if (!cdsEndTrainingUpcall_register_upcalls()) {
190     return JNI_EINVAL;
191   }
192 #endif // INCLUDE_CDS
193   runtimeUpcalls_close_registration();
194 
195   javaClasses_init();        // must happen after vtable initialization, before referenceProcessor_init
196   interpreter_init_code();   // after javaClasses_init and before any method gets linked
197   referenceProcessor_init();
198   jni_handles_init();
199 #if INCLUDE_VM_STRUCTS
200   vmStructs_init();
201 #endif // INCLUDE_VM_STRUCTS
202 
203   vtableStubs_init();
204   if (!compilerOracle_init()) {
205     return JNI_EINVAL;
206   }
207   dependencyContext_init();
208   dependencies_init();
209 
210   if (!compileBroker_init()) {
211     return JNI_EINVAL;
212   }
213 #if INCLUDE_JVMCI
214   if (EnableJVMCI) {
215     JVMCI::initialize_globals();
216   }
217 #endif
218 
219   if (TrainingData::have_data() || TrainingData::need_data()) {
220     TrainingData::initialize();
221   }
222 
223   if (!universe_post_init()) {
224     return JNI_ERR;
225   }
226   compiler_stubs_init(false /* in_compiler_thread */); // compiler's intrinsics stubs
227   final_stubs_init();    // final StubRoutines stubs
228   MethodHandles::generate_adapters();
229 
230   // All the flags that get adjusted by VM_Version_init and os::init_2
231   // have been set so dump the flags now.
232   if (PrintFlagsFinal || PrintFlagsRanges) {
233     JVMFlag::printFlags(tty, false, PrintFlagsRanges);
234   } else if (RecordTraining && xtty != nullptr) {
235     JVMFlag::printFlags(xtty->log_only(), false, PrintFlagsRanges);
236   }
237 
238   return JNI_OK;
239 }
240 
241 
242 void exit_globals() {
243   static bool destructorsCalled = false;
244   if (!destructorsCalled) {
245     destructorsCalled = true;
246     perfMemory_exit();
247     SafepointTracing::statistics_exit_log();
248     if (PrintStringTableStatistics) {
249       SymbolTable::dump(tty);
250       StringTable::dump(tty);
251     }
252     ostream_exit();
253 #ifdef LEAK_SANITIZER
254     {
255       // Unregister the Java heap with LSan.
< prev index next >