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 "compiler/compiler_globals.hpp"
28 #include "gc/shared/collectedHeap.hpp"
29 #include "gc/shared/gcHeapSummary.hpp"
30 #include "interpreter/bytecodes.hpp"
31 #include "logging/logAsyncWriter.hpp"
32 #include "memory/universe.hpp"
33 #include "nmt/memTracker.hpp"
34 #include "prims/downcallLinker.hpp"
35 #include "prims/jvmtiExport.hpp"
36 #include "prims/methodHandles.hpp"
37 #include "runtime/atomic.hpp"
38 #include "runtime/continuation.hpp"
39 #include "runtime/flags/jvmFlag.hpp"
40 #include "runtime/globals.hpp"
41 #include "runtime/handles.inline.hpp"
42 #include "runtime/icache.hpp"
43 #include "runtime/init.hpp"
44 #include "runtime/safepoint.hpp"
45 #include "runtime/sharedRuntime.hpp"
46 #include "sanitizers/leak.hpp"
47 #include "utilities/macros.hpp"
48 #if INCLUDE_JVMCI
49 #include "jvmci/jvmci.hpp"
50 #endif
51
52 // Initialization done by VM thread in vm_init_globals()
53 void check_ThreadShadow();
54 void eventlog_init();
55 void mutex_init();
56 void universe_oopstorage_init();
57 void perfMemory_init();
58 void SuspendibleThreadSet_init();
59 void ExternalsRecorder_init(); // After mutex_init() and before CodeCache_init
60
61 // Initialization done by Java thread in init_globals()
62 void management_init();
63 void bytecodes_init();
64 void classLoader_init1();
65 void compilationPolicy_init();
66 void codeCache_init();
67 void VM_Version_init();
70 jint universe_init(); // depends on codeCache_init and initial_stubs_init
71 // depends on universe_init, must be before interpreter_init (currently only on SPARC)
72 void gc_barrier_stubs_init();
73 void continuations_init(); // depends on flags (UseCompressedOops) and barrier sets
74 void continuation_stubs_init(); // depend on continuations_init
75 void interpreter_init_stub(); // before any methods loaded
76 void interpreter_init_code(); // after methods loaded, but before they are linked
77 void accessFlags_init();
78 void InterfaceSupport_init();
79 void universe2_init(); // dependent on codeCache_init and initial_stubs_init, loads primordial classes
80 void referenceProcessor_init();
81 void jni_handles_init();
82 void vmStructs_init() NOT_DEBUG_RETURN;
83
84 void vtableStubs_init();
85 bool compilerOracle_init();
86 bool compileBroker_init();
87 void dependencyContext_init();
88 void dependencies_init();
89
90 // Initialization after compiler initialization
91 bool universe_post_init(); // must happen after compiler_init
92 void javaClasses_init(); // must happen after vtable initialization
93 void compiler_stubs_init(bool in_compiler_thread); // compiler's StubRoutines stubs
94 void final_stubs_init(); // final StubRoutines stubs
95
96 // Do not disable thread-local-storage, as it is important for some
97 // JNI/JVM/JVMTI functions and signal handlers to work properly
98 // during VM shutdown
99 void perfMemory_exit();
100 void ostream_exit();
101
102 void vm_init_globals() {
103 check_ThreadShadow();
104 basic_types_init();
105 eventlog_init();
106 mutex_init();
107 universe_oopstorage_init();
108 perfMemory_init();
109 SuspendibleThreadSet_init();
110 ExternalsRecorder_init(); // After mutex_init() and before CodeCache_init
111 }
112
113
114 jint init_globals() {
115 management_init();
116 JvmtiExport::initialize_oop_storage();
117 #if INCLUDE_JVMTI
118 if (AlwaysRecordEvolDependencies) {
119 JvmtiExport::set_can_hotswap_or_post_breakpoint(true);
120 JvmtiExport::set_all_dependencies_are_recorded(true);
121 }
122 #endif
123 bytecodes_init();
124 classLoader_init1();
125 compilationPolicy_init();
126 codeCache_init();
127 VM_Version_init(); // depends on codeCache_init for emitting code
128 // stub routines in initial blob are referenced by later generated code
129 initial_stubs_init();
130 // stack overflow exception blob is referenced by the interpreter
131 SharedRuntime::generate_initial_stubs();
132 jint status = universe_init(); // dependent on codeCache_init and
133 // initial_stubs_init and metaspace_init.
134 if (status != JNI_OK)
135 return status;
136
137 #ifdef LEAK_SANITIZER
138 {
139 // Register the Java heap with LSan.
140 VirtualSpaceSummary summary = Universe::heap()->create_heap_space_summary();
141 LSAN_REGISTER_ROOT_REGION(summary.start(), summary.reserved_size());
142 }
143 #endif // LEAK_SANITIZER
144
145 AsyncLogWriter::initialize();
146 gc_barrier_stubs_init(); // depends on universe_init, must be before interpreter_init
147 continuations_init(); // must precede continuation stub generation
148 continuation_stubs_init(); // depends on continuations_init
149 #if INCLUDE_JFR
150 SharedRuntime::generate_jfr_stubs();
151 #endif
152 interpreter_init_stub(); // before methods get loaded
153 accessFlags_init();
154 InterfaceSupport_init();
155 VMRegImpl::set_regName(); // need this before generate_stubs (for printing oop maps).
156 SharedRuntime::generate_stubs();
157 return JNI_OK;
158 }
159
160 jint init_globals2() {
161 universe2_init(); // dependent on codeCache_init and initial_stubs_init
162 javaClasses_init(); // must happen after vtable initialization, before referenceProcessor_init
163 interpreter_init_code(); // after javaClasses_init and before any method gets linked
164 referenceProcessor_init();
165 jni_handles_init();
166 #if INCLUDE_VM_STRUCTS
167 vmStructs_init();
168 #endif // INCLUDE_VM_STRUCTS
169
170 vtableStubs_init();
171 if (!compilerOracle_init()) {
172 return JNI_EINVAL;
173 }
174 dependencyContext_init();
175 dependencies_init();
176
177 if (!compileBroker_init()) {
178 return JNI_EINVAL;
179 }
180 #if INCLUDE_JVMCI
181 if (EnableJVMCI) {
182 JVMCI::initialize_globals();
183 }
184 #endif
185
186 if (!universe_post_init()) {
187 return JNI_ERR;
188 }
189 compiler_stubs_init(false /* in_compiler_thread */); // compiler's intrinsics stubs
190 final_stubs_init(); // final StubRoutines stubs
191 MethodHandles::generate_adapters();
192
193 // All the flags that get adjusted by VM_Version_init and os::init_2
194 // have been set so dump the flags now.
195 if (PrintFlagsFinal || PrintFlagsRanges) {
196 JVMFlag::printFlags(tty, false, PrintFlagsRanges);
197 }
198
199 return JNI_OK;
200 }
201
202
203 void exit_globals() {
204 static bool destructorsCalled = false;
205 if (!destructorsCalled) {
206 destructorsCalled = true;
207 perfMemory_exit();
208 SafepointTracing::statistics_exit_log();
209 if (PrintStringTableStatistics) {
210 SymbolTable::dump(tty);
211 StringTable::dump(tty);
212 }
213 ostream_exit();
214 #ifdef LEAK_SANITIZER
215 {
216 // 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/SCCache.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();
75 jint universe_init(); // depends on codeCache_init and initial_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 // initialize upcalls before class loading
96 bool runtimeUpcalls_open_registration();
97 bool runtimeUpcallNop_register_upcalls();
98 #if INCLUDE_CDS
99 bool cdsEndTrainingUpcall_register_upcalls();
100 #endif // INCLUDE_CDS
101 void runtimeUpcalls_close_registration();
102
103 // Initialization after compiler initialization
104 bool universe_post_init(); // must happen after compiler_init
105 void javaClasses_init(); // must happen after vtable initialization
106 void compiler_stubs_init(bool in_compiler_thread); // compiler's StubRoutines stubs
107 void final_stubs_init(); // final StubRoutines stubs
108
109 // Do not disable thread-local-storage, as it is important for some
110 // JNI/JVM/JVMTI functions and signal handlers to work properly
111 // during VM shutdown
112 void perfMemory_exit();
113 void ostream_exit();
114
115 void perf_jvm_init();
116
117 void vm_init_globals() {
118 check_ThreadShadow();
119 basic_types_init();
120 eventlog_init();
121 mutex_init();
122 universe_oopstorage_init();
123 perfMemory_init();
124 SuspendibleThreadSet_init();
125 ExternalsRecorder_init(); // After mutex_init() and before CodeCache_init
126 }
127
128
129 jint init_globals() {
130 perf_jvm_init();
131 MethodHandles::init_counters();
132
133 management_init();
134 JvmtiExport::initialize_oop_storage();
135 #if INCLUDE_JVMTI
136 if (AlwaysRecordEvolDependencies) {
137 JvmtiExport::set_can_hotswap_or_post_breakpoint(true);
138 JvmtiExport::set_all_dependencies_are_recorded(true);
139 }
140 #endif
141 bytecodes_init();
142 classLoader_init1();
143 compilationPolicy_init();
144 MetaspaceShared::open_static_archive();
145 codeCache_init();
146 VM_Version_init(); // depends on codeCache_init for emitting code
147 // stub routines in initial blob are referenced by later generated code
148 initial_stubs_init();
149 // stack overflow exception blob is referenced by the interpreter
150 SharedRuntime::generate_initial_stubs();
151 jint status = universe_init(); // dependent on codeCache_init and
152 // initial_stubs_init and metaspace_init.
153 if (status != JNI_OK)
154 return status;
155 #ifdef LEAK_SANITIZER
156 {
157 // Register the Java heap with LSan.
158 VirtualSpaceSummary summary = Universe::heap()->create_heap_space_summary();
159 LSAN_REGISTER_ROOT_REGION(summary.start(), summary.reserved_size());
160 }
161 #endif // LEAK_SANITIZER
162 SCCache::init2(); // depends on universe_init
163 AsyncLogWriter::initialize();
164 gc_barrier_stubs_init(); // depends on universe_init, must be before interpreter_init
165 continuations_init(); // must precede continuation stub generation
166 continuation_stubs_init(); // depends on continuations_init
167 #if INCLUDE_JFR
168 SharedRuntime::generate_jfr_stubs();
169 #endif
170 interpreter_init_stub(); // before methods get loaded
171 accessFlags_init();
172 InterfaceSupport_init();
173 VMRegImpl::set_regName(); // need this before generate_stubs (for printing oop maps).
174 SharedRuntime::generate_stubs();
175 SCCache::init_shared_blobs_table(); // need this after generate_stubs
176 SharedRuntime::init_adapter_library(); // do this after SCCache::init_shared_blobs_table
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 SCCache::init_stubs_table();
229 MethodHandles::generate_adapters();
230
231 // All the flags that get adjusted by VM_Version_init and os::init_2
232 // have been set so dump the flags now.
233 if (PrintFlagsFinal || PrintFlagsRanges) {
234 JVMFlag::printFlags(tty, false, PrintFlagsRanges);
235 } else if (RecordTraining && xtty != nullptr) {
236 JVMFlag::printFlags(xtty->log_only(), false, PrintFlagsRanges);
237 }
238
239 return JNI_OK;
240 }
241
242
243 void exit_globals() {
244 static bool destructorsCalled = false;
245 if (!destructorsCalled) {
246 destructorsCalled = true;
247 perfMemory_exit();
248 SafepointTracing::statistics_exit_log();
249 if (PrintStringTableStatistics) {
250 SymbolTable::dump(tty);
251 StringTable::dump(tty);
252 }
253 ostream_exit();
254 #ifdef LEAK_SANITIZER
255 {
256 // Unregister the Java heap with LSan.
|