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