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