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