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