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();
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 initial_stubs_init();
130 jint status = universe_init(); // dependent on codeCache_init and
131 // initial_stubs_init and metaspace_init.
132 if (status != JNI_OK)
133 return status;
134
135 #ifdef LEAK_SANITIZER
136 {
137 // Register the Java heap with LSan.
138 VirtualSpaceSummary summary = Universe::heap()->create_heap_space_summary();
139 LSAN_REGISTER_ROOT_REGION(summary.start(), summary.reserved_size());
140 }
141 #endif // LEAK_SANITIZER
142
143 AsyncLogWriter::initialize();
144 gc_barrier_stubs_init(); // depends on universe_init, must be before interpreter_init
145 continuations_init(); // must precede continuation stub generation
146 continuation_stubs_init(); // depends on continuations_init
147 interpreter_init_stub(); // before methods get loaded
148 accessFlags_init();
149 InterfaceSupport_init();
150 VMRegImpl::set_regName(); // need this before generate_stubs (for printing oop maps).
151 SharedRuntime::generate_stubs();
152 return JNI_OK;
153 }
154
155 jint init_globals2() {
156 universe2_init(); // dependent on codeCache_init and initial_stubs_init
157 javaClasses_init(); // must happen after vtable initialization, before referenceProcessor_init
158 interpreter_init_code(); // after javaClasses_init and before any method gets linked
159 referenceProcessor_init();
160 jni_handles_init();
161 #if INCLUDE_VM_STRUCTS
162 vmStructs_init();
163 #endif // INCLUDE_VM_STRUCTS
164
165 vtableStubs_init();
166 if (!compilerOracle_init()) {
167 return JNI_EINVAL;
168 }
169 dependencyContext_init();
170 dependencies_init();
171
172 if (!compileBroker_init()) {
173 return JNI_EINVAL;
174 }
175 #if INCLUDE_JVMCI
176 if (EnableJVMCI) {
177 JVMCI::initialize_globals();
178 }
179 #endif
180
181 if (!universe_post_init()) {
182 return JNI_ERR;
183 }
184 compiler_stubs_init(false /* in_compiler_thread */); // compiler's intrinsics stubs
185 final_stubs_init(); // final StubRoutines stubs
186 MethodHandles::generate_adapters();
187
188 // All the flags that get adjusted by VM_Version_init and os::init_2
189 // have been set so dump the flags now.
190 if (PrintFlagsFinal || PrintFlagsRanges) {
191 JVMFlag::printFlags(tty, false, PrintFlagsRanges);
192 }
193
194 return JNI_OK;
195 }
196
197
198 void exit_globals() {
199 static bool destructorsCalled = false;
200 if (!destructorsCalled) {
201 destructorsCalled = true;
202 perfMemory_exit();
203 SafepointTracing::statistics_exit_log();
204 if (PrintStringTableStatistics) {
205 SymbolTable::dump(tty);
206 StringTable::dump(tty);
207 }
208 ostream_exit();
209 #ifdef LEAK_SANITIZER
210 {
211 // 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();
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 // Initialization after compiler initialization
97 bool universe_post_init(); // must happen after compiler_init
98 void javaClasses_init(); // must happen after vtable initialization
99 void compiler_stubs_init(bool in_compiler_thread); // compiler's StubRoutines stubs
100 void final_stubs_init(); // final StubRoutines stubs
101
102 // Do not disable thread-local-storage, as it is important for some
103 // JNI/JVM/JVMTI functions and signal handlers to work properly
104 // during VM shutdown
105 void perfMemory_exit();
106 void ostream_exit();
107
108 void perf_jvm_init();
109
110 void vm_init_globals() {
111 check_ThreadShadow();
112 basic_types_init();
113 eventlog_init();
114 mutex_init();
115 universe_oopstorage_init();
116 perfMemory_init();
117 SuspendibleThreadSet_init();
118 ExternalsRecorder_init(); // After mutex_init() and before CodeCache_init
119 }
120
121
122 jint init_globals() {
123 perf_jvm_init();
124 MethodHandles::init_counters();
125
126 management_init();
127 JvmtiExport::initialize_oop_storage();
128 #if INCLUDE_JVMTI
129 if (AlwaysRecordEvolDependencies) {
130 JvmtiExport::set_can_hotswap_or_post_breakpoint(true);
131 JvmtiExport::set_all_dependencies_are_recorded(true);
132 }
133 #endif
134 bytecodes_init();
135 classLoader_init1();
136 compilationPolicy_init();
137 MetaspaceShared::open_static_archive();
138 codeCache_init();
139 VM_Version_init(); // depends on codeCache_init for emitting code
140 initial_stubs_init();
141 jint status = universe_init(); // dependent on codeCache_init and
142 // initial_stubs_init and metaspace_init.
143 if (status != JNI_OK)
144 return status;
145 SCCache::initialize();
146 #ifdef LEAK_SANITIZER
147 {
148 // Register the Java heap with LSan.
149 VirtualSpaceSummary summary = Universe::heap()->create_heap_space_summary();
150 LSAN_REGISTER_ROOT_REGION(summary.start(), summary.reserved_size());
151 }
152 #endif // LEAK_SANITIZER
153 SCCache::init2(); // depends on universe_init
154 AsyncLogWriter::initialize();
155 gc_barrier_stubs_init(); // depends on universe_init, must be before interpreter_init
156 continuations_init(); // must precede continuation stub generation
157 continuation_stubs_init(); // depends on continuations_init
158 interpreter_init_stub(); // before methods get loaded
159 accessFlags_init();
160 InterfaceSupport_init();
161 VMRegImpl::set_regName(); // need this before generate_stubs (for printing oop maps).
162 SharedRuntime::generate_stubs();
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 if (TrainingData::have_data() || TrainingData::need_data()) {
193 TrainingData::initialize();
194 }
195
196 if (!universe_post_init()) {
197 return JNI_ERR;
198 }
199 compiler_stubs_init(false /* in_compiler_thread */); // compiler's intrinsics stubs
200 final_stubs_init(); // final StubRoutines stubs
201 MethodHandles::generate_adapters();
202 SystemDictionary::restore_archived_method_handle_intrinsics();
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 } else if (RecordTraining && xtty != nullptr) {
209 JVMFlag::printFlags(xtty->log_only(), false, PrintFlagsRanges);
210 }
211
212 return JNI_OK;
213 }
214
215
216 void exit_globals() {
217 static bool destructorsCalled = false;
218 if (!destructorsCalled) {
219 destructorsCalled = true;
220 perfMemory_exit();
221 SafepointTracing::statistics_exit_log();
222 if (PrintStringTableStatistics) {
223 SymbolTable::dump(tty);
224 StringTable::dump(tty);
225 }
226 ostream_exit();
227 #ifdef LEAK_SANITIZER
228 {
229 // Unregister the Java heap with LSan.
|