121 OopHandle Universe::_preallocated_out_of_memory_error_array;
122 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
123
124 // Message details for OOME objects, preallocate these objects since they could be
125 // used when throwing OOME, we should try to avoid further allocation in such case
126 OopHandle Universe::_msg_metaspace;
127 OopHandle Universe::_msg_class_metaspace;
128
129 OopHandle Universe::_null_ptr_exception_instance;
130 OopHandle Universe::_arithmetic_exception_instance;
131 OopHandle Universe::_virtual_machine_error_instance;
132
133 OopHandle Universe::_reference_pending_list;
134
135 Array<Klass*>* Universe::_the_array_interfaces_array = nullptr;
136 LatestMethodCache* Universe::_finalizer_register_cache = nullptr;
137 LatestMethodCache* Universe::_loader_addClass_cache = nullptr;
138 LatestMethodCache* Universe::_throw_illegal_access_error_cache = nullptr;
139 LatestMethodCache* Universe::_throw_no_such_method_error_cache = nullptr;
140 LatestMethodCache* Universe::_do_stack_walk_cache = nullptr;
141
142 long Universe::verify_flags = Universe::Verify_All;
143
144 Array<int>* Universe::_the_empty_int_array = nullptr;
145 Array<u2>* Universe::_the_empty_short_array = nullptr;
146 Array<Klass*>* Universe::_the_empty_klass_array = nullptr;
147 Array<InstanceKlass*>* Universe::_the_empty_instance_klass_array = nullptr;
148 Array<Method*>* Universe::_the_empty_method_array = nullptr;
149
150 // These variables are guarded by FullGCALot_lock.
151 debug_only(OopHandle Universe::_fullgc_alot_dummy_array;)
152 debug_only(int Universe::_fullgc_alot_dummy_next = 0;)
153
154 // Heap
155 int Universe::_verify_count = 0;
156
157 // Oop verification (see MacroAssembler::verify_oop)
158 uintptr_t Universe::_verify_oop_mask = 0;
159 uintptr_t Universe::_verify_oop_bits = (uintptr_t) -1;
160
220
221 void Universe::metaspace_pointers_do(MetaspaceClosure* it) {
222 it->push(&_fillerArrayKlassObj);
223 for (int i = 0; i < T_LONG+1; i++) {
224 it->push(&_typeArrayKlassObjs[i]);
225 }
226 it->push(&_objectArrayKlassObj);
227
228 it->push(&_the_empty_int_array);
229 it->push(&_the_empty_short_array);
230 it->push(&_the_empty_klass_array);
231 it->push(&_the_empty_instance_klass_array);
232 it->push(&_the_empty_method_array);
233 it->push(&_the_array_interfaces_array);
234
235 _finalizer_register_cache->metaspace_pointers_do(it);
236 _loader_addClass_cache->metaspace_pointers_do(it);
237 _throw_illegal_access_error_cache->metaspace_pointers_do(it);
238 _throw_no_such_method_error_cache->metaspace_pointers_do(it);
239 _do_stack_walk_cache->metaspace_pointers_do(it);
240 }
241
242 #if INCLUDE_CDS_JAVA_HEAP
243 void Universe::set_archived_basic_type_mirror_index(BasicType t, int index) {
244 assert(CDSConfig::is_dumping_heap(), "sanity");
245 assert(!is_reference_type(t), "sanity");
246 _archived_basic_type_mirror_indices[t] = index;
247 }
248
249 void Universe::update_archived_basic_type_mirrors() {
250 if (ArchiveHeapLoader::is_in_use()) {
251 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
252 int index = _archived_basic_type_mirror_indices[i];
253 if (!is_reference_type((BasicType)i) && index >= 0) {
254 oop mirror_oop = HeapShared::get_root(index);
255 assert(mirror_oop != nullptr, "must be");
256 _basic_type_mirrors[i] = OopHandle(vm_global(), mirror_oop);
257 }
258 }
259 }
271 }
272 #endif
273
274 f->do_ptr(&_fillerArrayKlassObj);
275 for (int i = 0; i < T_LONG+1; i++) {
276 f->do_ptr(&_typeArrayKlassObjs[i]);
277 }
278
279 f->do_ptr(&_objectArrayKlassObj);
280 f->do_ptr(&_the_array_interfaces_array);
281 f->do_ptr(&_the_empty_int_array);
282 f->do_ptr(&_the_empty_short_array);
283 f->do_ptr(&_the_empty_method_array);
284 f->do_ptr(&_the_empty_klass_array);
285 f->do_ptr(&_the_empty_instance_klass_array);
286 _finalizer_register_cache->serialize(f);
287 _loader_addClass_cache->serialize(f);
288 _throw_illegal_access_error_cache->serialize(f);
289 _throw_no_such_method_error_cache->serialize(f);
290 _do_stack_walk_cache->serialize(f);
291 }
292
293
294 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
295 if (size < alignment || size % alignment != 0) {
296 vm_exit_during_initialization(
297 err_msg("Size of %s (" UINTX_FORMAT " bytes) must be aligned to " UINTX_FORMAT " bytes", name, size, alignment));
298 }
299 }
300
301 void initialize_basic_type_klass(Klass* k, TRAPS) {
302 Klass* ok = vmClasses::Object_klass();
303 #if INCLUDE_CDS
304 if (UseSharedSpaces) {
305 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
306 assert(k->super() == ok, "u3");
307 if (k->is_instance_klass()) {
308 InstanceKlass::cast(k)->restore_unshareable_info(loader_data, Handle(), nullptr, CHECK);
309 } else {
310 ArrayKlass::cast(k)->restore_unshareable_info(loader_data, Handle(), CHECK);
354 }
355
356 vmSymbols::initialize();
357
358 SystemDictionary::initialize(CHECK);
359
360 // Create string constants
361 oop s = StringTable::intern("null", CHECK);
362 _the_null_string = OopHandle(vm_global(), s);
363 s = StringTable::intern("-2147483648", CHECK);
364 _the_min_jint_string = OopHandle(vm_global(), s);
365
366
367 #if INCLUDE_CDS
368 if (UseSharedSpaces) {
369 // Verify shared interfaces array.
370 assert(_the_array_interfaces_array->at(0) ==
371 vmClasses::Cloneable_klass(), "u3");
372 assert(_the_array_interfaces_array->at(1) ==
373 vmClasses::Serializable_klass(), "u3");
374 } else
375 #endif
376 {
377 // Set up shared interfaces array. (Do this before supers are set up.)
378 _the_array_interfaces_array->at_put(0, vmClasses::Cloneable_klass());
379 _the_array_interfaces_array->at_put(1, vmClasses::Serializable_klass());
380 }
381
382 initialize_basic_type_klass(_fillerArrayKlassObj, CHECK);
383
384 initialize_basic_type_klass(boolArrayKlassObj(), CHECK);
385 initialize_basic_type_klass(charArrayKlassObj(), CHECK);
386 initialize_basic_type_klass(floatArrayKlassObj(), CHECK);
387 initialize_basic_type_klass(doubleArrayKlassObj(), CHECK);
388 initialize_basic_type_klass(byteArrayKlassObj(), CHECK);
389 initialize_basic_type_klass(shortArrayKlassObj(), CHECK);
390 initialize_basic_type_klass(intArrayKlassObj(), CHECK);
391 initialize_basic_type_klass(longArrayKlassObj(), CHECK);
392
393 assert(_fillerArrayKlassObj != intArrayKlassObj(),
782
783 GCLogPrecious::initialize();
784
785 // Initialize CPUTimeCounters object, which must be done before creation of the heap.
786 CPUTimeCounters::initialize();
787
788 #ifdef _LP64
789 MetaspaceShared::adjust_heap_sizes_for_dumping();
790 #endif // _LP64
791
792 GCConfig::arguments()->initialize_heap_sizes();
793
794 jint status = Universe::initialize_heap();
795 if (status != JNI_OK) {
796 return status;
797 }
798
799 Universe::initialize_tlab();
800
801 Metaspace::global_initialize();
802
803 // Initialize performance counters for metaspaces
804 MetaspaceCounters::initialize_performance_counters();
805
806 // Checks 'AfterMemoryInit' constraints.
807 if (!JVMFlagLimit::check_all_constraints(JVMFlagConstraintPhase::AfterMemoryInit)) {
808 return JNI_EINVAL;
809 }
810
811 ClassLoaderData::init_null_class_loader_data();
812
813 // We have a heap so create the Method* caches before
814 // Metaspace::initialize_shared_spaces() tries to populate them.
815 Universe::_finalizer_register_cache = new LatestMethodCache();
816 Universe::_loader_addClass_cache = new LatestMethodCache();
817 Universe::_throw_illegal_access_error_cache = new LatestMethodCache();
818 Universe::_throw_no_such_method_error_cache = new LatestMethodCache();
819 Universe::_do_stack_walk_cache = new LatestMethodCache();
820
821 #if INCLUDE_CDS
822 DynamicArchive::check_for_dynamic_dump();
823 if (UseSharedSpaces) {
824 // Read the data structures supporting the shared spaces (shared
825 // system dictionary, symbol table, etc.)
826 MetaspaceShared::initialize_shared_spaces();
827 }
828 if (CDSConfig::is_dumping_archive()) {
829 MetaspaceShared::prepare_for_dumping();
830 }
831 #endif
832
833 SymbolTable::create_table();
834 StringTable::create_table();
835
836 if (strlen(VerifySubSet) > 0) {
837 Universe::initialize_verify_flags();
838 }
839
956 vmClasses::internal_Unsafe_klass(),
957 "throwIllegalAccessError",
958 vmSymbols::void_method_signature(), true, CHECK);
959
960 initialize_known_method(_throw_no_such_method_error_cache,
961 vmClasses::internal_Unsafe_klass(),
962 "throwNoSuchMethodError",
963 vmSymbols::void_method_signature(), true, CHECK);
964
965 // Set up method for registering loaded classes in class loader vector
966 initialize_known_method(_loader_addClass_cache,
967 vmClasses::ClassLoader_klass(),
968 "addClass",
969 vmSymbols::class_void_signature(), false, CHECK);
970
971 // Set up method for stack walking
972 initialize_known_method(_do_stack_walk_cache,
973 vmClasses::AbstractStackWalker_klass(),
974 "doStackWalk",
975 vmSymbols::doStackWalk_signature(), false, CHECK);
976 }
977
978 void universe2_init() {
979 EXCEPTION_MARK;
980 Universe::genesis(CATCH);
981 }
982
983 // Set after initialization of the module runtime, call_initModuleRuntime
984 void universe_post_module_init() {
985 Universe::_module_initialized = true;
986 }
987
988 bool universe_post_init() {
989 assert(!is_init_completed(), "Error: initialization not yet completed!");
990 Universe::_fully_initialized = true;
991 EXCEPTION_MARK;
992 if (!UseSharedSpaces) {
993 reinitialize_vtables();
994 reinitialize_itables();
995 }
|
121 OopHandle Universe::_preallocated_out_of_memory_error_array;
122 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
123
124 // Message details for OOME objects, preallocate these objects since they could be
125 // used when throwing OOME, we should try to avoid further allocation in such case
126 OopHandle Universe::_msg_metaspace;
127 OopHandle Universe::_msg_class_metaspace;
128
129 OopHandle Universe::_null_ptr_exception_instance;
130 OopHandle Universe::_arithmetic_exception_instance;
131 OopHandle Universe::_virtual_machine_error_instance;
132
133 OopHandle Universe::_reference_pending_list;
134
135 Array<Klass*>* Universe::_the_array_interfaces_array = nullptr;
136 LatestMethodCache* Universe::_finalizer_register_cache = nullptr;
137 LatestMethodCache* Universe::_loader_addClass_cache = nullptr;
138 LatestMethodCache* Universe::_throw_illegal_access_error_cache = nullptr;
139 LatestMethodCache* Universe::_throw_no_such_method_error_cache = nullptr;
140 LatestMethodCache* Universe::_do_stack_walk_cache = nullptr;
141 LatestMethodCache* Universe::_is_substitutable_cache = nullptr;
142 LatestMethodCache* Universe::_value_object_hash_code_cache = nullptr;
143
144 long Universe::verify_flags = Universe::Verify_All;
145
146 Array<int>* Universe::_the_empty_int_array = nullptr;
147 Array<u2>* Universe::_the_empty_short_array = nullptr;
148 Array<Klass*>* Universe::_the_empty_klass_array = nullptr;
149 Array<InstanceKlass*>* Universe::_the_empty_instance_klass_array = nullptr;
150 Array<Method*>* Universe::_the_empty_method_array = nullptr;
151
152 // These variables are guarded by FullGCALot_lock.
153 debug_only(OopHandle Universe::_fullgc_alot_dummy_array;)
154 debug_only(int Universe::_fullgc_alot_dummy_next = 0;)
155
156 // Heap
157 int Universe::_verify_count = 0;
158
159 // Oop verification (see MacroAssembler::verify_oop)
160 uintptr_t Universe::_verify_oop_mask = 0;
161 uintptr_t Universe::_verify_oop_bits = (uintptr_t) -1;
162
222
223 void Universe::metaspace_pointers_do(MetaspaceClosure* it) {
224 it->push(&_fillerArrayKlassObj);
225 for (int i = 0; i < T_LONG+1; i++) {
226 it->push(&_typeArrayKlassObjs[i]);
227 }
228 it->push(&_objectArrayKlassObj);
229
230 it->push(&_the_empty_int_array);
231 it->push(&_the_empty_short_array);
232 it->push(&_the_empty_klass_array);
233 it->push(&_the_empty_instance_klass_array);
234 it->push(&_the_empty_method_array);
235 it->push(&_the_array_interfaces_array);
236
237 _finalizer_register_cache->metaspace_pointers_do(it);
238 _loader_addClass_cache->metaspace_pointers_do(it);
239 _throw_illegal_access_error_cache->metaspace_pointers_do(it);
240 _throw_no_such_method_error_cache->metaspace_pointers_do(it);
241 _do_stack_walk_cache->metaspace_pointers_do(it);
242 _is_substitutable_cache->metaspace_pointers_do(it);
243 _value_object_hash_code_cache->metaspace_pointers_do(it);
244 }
245
246 #if INCLUDE_CDS_JAVA_HEAP
247 void Universe::set_archived_basic_type_mirror_index(BasicType t, int index) {
248 assert(CDSConfig::is_dumping_heap(), "sanity");
249 assert(!is_reference_type(t), "sanity");
250 _archived_basic_type_mirror_indices[t] = index;
251 }
252
253 void Universe::update_archived_basic_type_mirrors() {
254 if (ArchiveHeapLoader::is_in_use()) {
255 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
256 int index = _archived_basic_type_mirror_indices[i];
257 if (!is_reference_type((BasicType)i) && index >= 0) {
258 oop mirror_oop = HeapShared::get_root(index);
259 assert(mirror_oop != nullptr, "must be");
260 _basic_type_mirrors[i] = OopHandle(vm_global(), mirror_oop);
261 }
262 }
263 }
275 }
276 #endif
277
278 f->do_ptr(&_fillerArrayKlassObj);
279 for (int i = 0; i < T_LONG+1; i++) {
280 f->do_ptr(&_typeArrayKlassObjs[i]);
281 }
282
283 f->do_ptr(&_objectArrayKlassObj);
284 f->do_ptr(&_the_array_interfaces_array);
285 f->do_ptr(&_the_empty_int_array);
286 f->do_ptr(&_the_empty_short_array);
287 f->do_ptr(&_the_empty_method_array);
288 f->do_ptr(&_the_empty_klass_array);
289 f->do_ptr(&_the_empty_instance_klass_array);
290 _finalizer_register_cache->serialize(f);
291 _loader_addClass_cache->serialize(f);
292 _throw_illegal_access_error_cache->serialize(f);
293 _throw_no_such_method_error_cache->serialize(f);
294 _do_stack_walk_cache->serialize(f);
295 _is_substitutable_cache->serialize(f);
296 _value_object_hash_code_cache->serialize(f);
297 }
298
299
300 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
301 if (size < alignment || size % alignment != 0) {
302 vm_exit_during_initialization(
303 err_msg("Size of %s (" UINTX_FORMAT " bytes) must be aligned to " UINTX_FORMAT " bytes", name, size, alignment));
304 }
305 }
306
307 void initialize_basic_type_klass(Klass* k, TRAPS) {
308 Klass* ok = vmClasses::Object_klass();
309 #if INCLUDE_CDS
310 if (UseSharedSpaces) {
311 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
312 assert(k->super() == ok, "u3");
313 if (k->is_instance_klass()) {
314 InstanceKlass::cast(k)->restore_unshareable_info(loader_data, Handle(), nullptr, CHECK);
315 } else {
316 ArrayKlass::cast(k)->restore_unshareable_info(loader_data, Handle(), CHECK);
360 }
361
362 vmSymbols::initialize();
363
364 SystemDictionary::initialize(CHECK);
365
366 // Create string constants
367 oop s = StringTable::intern("null", CHECK);
368 _the_null_string = OopHandle(vm_global(), s);
369 s = StringTable::intern("-2147483648", CHECK);
370 _the_min_jint_string = OopHandle(vm_global(), s);
371
372
373 #if INCLUDE_CDS
374 if (UseSharedSpaces) {
375 // Verify shared interfaces array.
376 assert(_the_array_interfaces_array->at(0) ==
377 vmClasses::Cloneable_klass(), "u3");
378 assert(_the_array_interfaces_array->at(1) ==
379 vmClasses::Serializable_klass(), "u3");
380
381 } else
382 #endif
383 {
384 // Set up shared interfaces array. (Do this before supers are set up.)
385 _the_array_interfaces_array->at_put(0, vmClasses::Cloneable_klass());
386 _the_array_interfaces_array->at_put(1, vmClasses::Serializable_klass());
387 }
388
389 initialize_basic_type_klass(_fillerArrayKlassObj, CHECK);
390
391 initialize_basic_type_klass(boolArrayKlassObj(), CHECK);
392 initialize_basic_type_klass(charArrayKlassObj(), CHECK);
393 initialize_basic_type_klass(floatArrayKlassObj(), CHECK);
394 initialize_basic_type_klass(doubleArrayKlassObj(), CHECK);
395 initialize_basic_type_klass(byteArrayKlassObj(), CHECK);
396 initialize_basic_type_klass(shortArrayKlassObj(), CHECK);
397 initialize_basic_type_klass(intArrayKlassObj(), CHECK);
398 initialize_basic_type_klass(longArrayKlassObj(), CHECK);
399
400 assert(_fillerArrayKlassObj != intArrayKlassObj(),
789
790 GCLogPrecious::initialize();
791
792 // Initialize CPUTimeCounters object, which must be done before creation of the heap.
793 CPUTimeCounters::initialize();
794
795 #ifdef _LP64
796 MetaspaceShared::adjust_heap_sizes_for_dumping();
797 #endif // _LP64
798
799 GCConfig::arguments()->initialize_heap_sizes();
800
801 jint status = Universe::initialize_heap();
802 if (status != JNI_OK) {
803 return status;
804 }
805
806 Universe::initialize_tlab();
807
808 Metaspace::global_initialize();
809 // Initialize performance counters for metaspaces
810 MetaspaceCounters::initialize_performance_counters();
811
812 // Checks 'AfterMemoryInit' constraints.
813 if (!JVMFlagLimit::check_all_constraints(JVMFlagConstraintPhase::AfterMemoryInit)) {
814 return JNI_EINVAL;
815 }
816
817 ClassLoaderData::init_null_class_loader_data();
818
819 // We have a heap so create the Method* caches before
820 // Metaspace::initialize_shared_spaces() tries to populate them.
821 Universe::_finalizer_register_cache = new LatestMethodCache();
822 Universe::_loader_addClass_cache = new LatestMethodCache();
823 Universe::_throw_illegal_access_error_cache = new LatestMethodCache();
824 Universe::_throw_no_such_method_error_cache = new LatestMethodCache();
825 Universe::_do_stack_walk_cache = new LatestMethodCache();
826 Universe::_is_substitutable_cache = new LatestMethodCache();
827 Universe::_value_object_hash_code_cache = new LatestMethodCache();
828
829 #if INCLUDE_CDS
830 DynamicArchive::check_for_dynamic_dump();
831 if (UseSharedSpaces) {
832 // Read the data structures supporting the shared spaces (shared
833 // system dictionary, symbol table, etc.)
834 MetaspaceShared::initialize_shared_spaces();
835 }
836 if (CDSConfig::is_dumping_archive()) {
837 MetaspaceShared::prepare_for_dumping();
838 }
839 #endif
840
841 SymbolTable::create_table();
842 StringTable::create_table();
843
844 if (strlen(VerifySubSet) > 0) {
845 Universe::initialize_verify_flags();
846 }
847
964 vmClasses::internal_Unsafe_klass(),
965 "throwIllegalAccessError",
966 vmSymbols::void_method_signature(), true, CHECK);
967
968 initialize_known_method(_throw_no_such_method_error_cache,
969 vmClasses::internal_Unsafe_klass(),
970 "throwNoSuchMethodError",
971 vmSymbols::void_method_signature(), true, CHECK);
972
973 // Set up method for registering loaded classes in class loader vector
974 initialize_known_method(_loader_addClass_cache,
975 vmClasses::ClassLoader_klass(),
976 "addClass",
977 vmSymbols::class_void_signature(), false, CHECK);
978
979 // Set up method for stack walking
980 initialize_known_method(_do_stack_walk_cache,
981 vmClasses::AbstractStackWalker_klass(),
982 "doStackWalk",
983 vmSymbols::doStackWalk_signature(), false, CHECK);
984
985 // Set up substitutability testing
986 ResourceMark rm;
987 initialize_known_method(_is_substitutable_cache,
988 vmClasses::ValueObjectMethods_klass(),
989 vmSymbols::isSubstitutable_name()->as_C_string(),
990 vmSymbols::object_object_boolean_signature(), true, CHECK);
991 initialize_known_method(_value_object_hash_code_cache,
992 vmClasses::ValueObjectMethods_klass(),
993 vmSymbols::valueObjectHashCode_name()->as_C_string(),
994 vmSymbols::object_int_signature(), true, CHECK);
995 }
996
997 void universe2_init() {
998 EXCEPTION_MARK;
999 Universe::genesis(CATCH);
1000 }
1001
1002 // Set after initialization of the module runtime, call_initModuleRuntime
1003 void universe_post_module_init() {
1004 Universe::_module_initialized = true;
1005 }
1006
1007 bool universe_post_init() {
1008 assert(!is_init_completed(), "Error: initialization not yet completed!");
1009 Universe::_fully_initialized = true;
1010 EXCEPTION_MARK;
1011 if (!UseSharedSpaces) {
1012 reinitialize_vtables();
1013 reinitialize_itables();
1014 }
|