Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/runtime/init.cpp
40951 views
1
/*
2
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
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 "precompiled.hpp"
26
#include "classfile/stringTable.hpp"
27
#include "classfile/symbolTable.hpp"
28
#include "code/icBuffer.hpp"
29
#include "compiler/compiler_globals.hpp"
30
#include "gc/shared/collectedHeap.hpp"
31
#if INCLUDE_JVMCI
32
#include "jvmci/jvmci.hpp"
33
#endif
34
#include "interpreter/bytecodes.hpp"
35
#include "logging/log.hpp"
36
#include "logging/logAsyncWriter.hpp"
37
#include "logging/logTag.hpp"
38
#include "memory/universe.hpp"
39
#include "prims/jvmtiExport.hpp"
40
#include "prims/methodHandles.hpp"
41
#include "prims/universalNativeInvoker.hpp"
42
#include "runtime/globals.hpp"
43
#include "runtime/atomic.hpp"
44
#include "runtime/flags/jvmFlag.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 "services/memTracker.hpp"
51
#include "utilities/macros.hpp"
52
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 chunkpool_init();
60
void perfMemory_init();
61
void SuspendibleThreadSet_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();
70
void stubRoutines_init1();
71
jint universe_init(); // depends on codeCache_init and stubRoutines_init
72
// depends on universe_init, must be before interpreter_init (currently only on SPARC)
73
void gc_barrier_stubs_init();
74
void interpreter_init_stub(); // before any methods loaded
75
void interpreter_init_code(); // after methods loaded, but before they are linked
76
void accessFlags_init();
77
void InterfaceSupport_init();
78
void universe2_init(); // dependent on codeCache_init and stubRoutines_init, loads primordial classes
79
void referenceProcessor_init();
80
void jni_handles_init();
81
void vmStructs_init() NOT_DEBUG_RETURN;
82
83
void vtableStubs_init();
84
void InlineCacheBuffer_init();
85
void 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 stubRoutines_init2(); // note: StubRoutines need 2-phase init
94
95
// Do not disable thread-local-storage, as it is important for some
96
// JNI/JVM/JVMTI functions and signal handlers to work properly
97
// during VM shutdown
98
void perfMemory_exit();
99
void ostream_exit();
100
101
void vm_init_globals() {
102
check_ThreadShadow();
103
basic_types_init();
104
eventlog_init();
105
mutex_init();
106
universe_oopstorage_init();
107
chunkpool_init();
108
perfMemory_init();
109
SuspendibleThreadSet_init();
110
}
111
112
113
jint init_globals() {
114
management_init();
115
JvmtiExport::initialize_oop_storage();
116
bytecodes_init();
117
classLoader_init1();
118
compilationPolicy_init();
119
codeCache_init();
120
VM_Version_init(); // depends on codeCache_init for emitting code
121
stubRoutines_init1();
122
jint status = universe_init(); // dependent on codeCache_init and
123
// stubRoutines_init1 and metaspace_init.
124
if (status != JNI_OK)
125
return status;
126
127
AsyncLogWriter::initialize();
128
gc_barrier_stubs_init(); // depends on universe_init, must be before interpreter_init
129
interpreter_init_stub(); // before methods get loaded
130
accessFlags_init();
131
InterfaceSupport_init();
132
VMRegImpl::set_regName(); // need this before generate_stubs (for printing oop maps).
133
SharedRuntime::generate_stubs();
134
universe2_init(); // dependent on codeCache_init and stubRoutines_init1
135
javaClasses_init();// must happen after vtable initialization, before referenceProcessor_init
136
interpreter_init_code(); // after javaClasses_init and before any method gets linked
137
referenceProcessor_init();
138
jni_handles_init();
139
#if INCLUDE_VM_STRUCTS
140
vmStructs_init();
141
#endif // INCLUDE_VM_STRUCTS
142
143
vtableStubs_init();
144
InlineCacheBuffer_init();
145
compilerOracle_init();
146
dependencyContext_init();
147
dependencies_init();
148
149
if (!compileBroker_init()) {
150
return JNI_EINVAL;
151
}
152
#if INCLUDE_JVMCI
153
if (EnableJVMCI) {
154
JVMCI::initialize_globals();
155
}
156
#endif
157
158
if (!universe_post_init()) {
159
return JNI_ERR;
160
}
161
stubRoutines_init2(); // note: StubRoutines need 2-phase init
162
MethodHandles::generate_adapters();
163
164
// All the flags that get adjusted by VM_Version_init and os::init_2
165
// have been set so dump the flags now.
166
if (PrintFlagsFinal || PrintFlagsRanges) {
167
JVMFlag::printFlags(tty, false, PrintFlagsRanges);
168
}
169
170
return JNI_OK;
171
}
172
173
174
void exit_globals() {
175
static bool destructorsCalled = false;
176
if (!destructorsCalled) {
177
destructorsCalled = true;
178
perfMemory_exit();
179
SafepointTracing::statistics_exit_log();
180
if (PrintStringTableStatistics) {
181
SymbolTable::dump(tty);
182
StringTable::dump(tty);
183
}
184
ostream_exit();
185
}
186
}
187
188
static volatile bool _init_completed = false;
189
190
bool is_init_completed() {
191
return Atomic::load_acquire(&_init_completed);
192
}
193
194
void wait_init_completed() {
195
MonitorLocker ml(InitCompleted_lock, Monitor::_no_safepoint_check_flag);
196
while (!_init_completed) {
197
ml.wait();
198
}
199
}
200
201
void set_init_completed() {
202
assert(Universe::is_fully_initialized(), "Should have completed initialization");
203
MonitorLocker ml(InitCompleted_lock, Monitor::_no_safepoint_check_flag);
204
Atomic::release_store(&_init_completed, true);
205
ml.notify_all();
206
}
207
208