467 //_mirrors[T_OBJECT] = _object_klass->java_mirror(); 468 //_mirrors[T_ARRAY] = _object_klass->java_mirror(); 469 } 470 471 void Universe::fixup_mirrors(TRAPS) { 472 // Bootstrap problem: all classes gets a mirror (java.lang.Class instance) assigned eagerly, 473 // but we cannot do that for classes created before java.lang.Class is loaded. Here we simply 474 // walk over permanent objects created so far (mostly classes) and fixup their mirrors. Note 475 // that the number of objects allocated at this point is very small. 476 assert(SystemDictionary::Class_klass_loaded(), "java.lang.Class should be loaded"); 477 HandleMark hm(THREAD); 478 // Cache the start of the static fields 479 InstanceMirrorKlass::init_offset_of_static_fields(); 480 481 GrowableArray <Klass*>* list = java_lang_Class::fixup_mirror_list(); 482 int list_length = list->length(); 483 for (int i = 0; i < list_length; i++) { 484 Klass* k = list->at(i); 485 assert(k->is_klass(), "List should only hold classes"); 486 EXCEPTION_MARK; 487 KlassHandle kh(THREAD, k); 488 java_lang_Class::fixup_mirror(kh, CATCH); 489 } 490 delete java_lang_Class::fixup_mirror_list(); 491 java_lang_Class::set_fixup_mirror_list(NULL); 492 } 493 494 #define assert_pll_locked(test) \ 495 assert(Heap_lock->test(), "Reference pending list access requires lock") 496 497 #define assert_pll_ownership() assert_pll_locked(owned_by_self) 498 499 oop Universe::reference_pending_list() { 500 assert_pll_ownership(); 501 return _reference_pending_list; 502 } 503 504 void Universe::set_reference_pending_list(oop list) { 505 assert_pll_ownership(); 506 _reference_pending_list = list; 507 } 508 509 bool Universe::has_reference_pending_list() { 513 514 oop Universe::swap_reference_pending_list(oop list) { 515 assert_pll_locked(is_locked); 516 return (oop)Atomic::xchg_ptr(list, &_reference_pending_list); 517 } 518 519 #undef assert_pll_locked 520 #undef assert_pll_ownership 521 522 523 static bool has_run_finalizers_on_exit = false; 524 525 void Universe::run_finalizers_on_exit() { 526 if (has_run_finalizers_on_exit) return; 527 has_run_finalizers_on_exit = true; 528 529 // Called on VM exit. This ought to be run in a separate thread. 530 log_trace(ref)("Callback to run finalizers on exit"); 531 { 532 PRESERVE_EXCEPTION_MARK; 533 KlassHandle finalizer_klass(THREAD, SystemDictionary::Finalizer_klass()); 534 JavaValue result(T_VOID); 535 JavaCalls::call_static( 536 &result, 537 finalizer_klass, 538 vmSymbols::run_finalizers_on_exit_name(), 539 vmSymbols::void_method_signature(), 540 THREAD 541 ); 542 // Ignore any pending exceptions 543 CLEAR_PENDING_EXCEPTION; 544 } 545 } 546 547 548 // initialize_vtable could cause gc if 549 // 1) we specified true to initialize_vtable and 550 // 2) this ran after gc was enabled 551 // In case those ever change we use handles for oops 552 void Universe::reinitialize_vtable_of(KlassHandle k_h, TRAPS) { 553 // init vtable of k and all subclasses 554 Klass* ko = k_h(); 555 klassVtable* vt = ko->vtable(); 556 if (vt) vt->initialize_vtable(false, CHECK); 557 if (ko->is_instance_klass()) { 558 for (KlassHandle s_h(THREAD, ko->subklass()); 559 s_h() != NULL; 560 s_h = KlassHandle(THREAD, s_h()->next_sibling())) { 561 reinitialize_vtable_of(s_h, CHECK); 562 } 563 } 564 } 565 566 567 void initialize_itable_for_klass(Klass* k, TRAPS) { 568 InstanceKlass::cast(k)->itable()->initialize_itable(false, CHECK); 569 } 570 571 572 void Universe::reinitialize_itables(TRAPS) { 573 SystemDictionary::classes_do(initialize_itable_for_klass, CHECK); 574 575 } 576 577 578 bool Universe::on_page_boundary(void* addr) { 579 return ((uintptr_t) addr) % os::vm_page_size() == 0; 580 } 581 971 } 972 973 void universe2_init() { 974 EXCEPTION_MARK; 975 Universe::genesis(CATCH); 976 } 977 978 // Set after initialization of the module runtime, call_initModuleRuntime 979 void universe_post_module_init() { 980 Universe::_module_initialized = true; 981 } 982 983 bool universe_post_init() { 984 assert(!is_init_completed(), "Error: initialization not yet completed!"); 985 Universe::_fully_initialized = true; 986 EXCEPTION_MARK; 987 { ResourceMark rm; 988 Interpreter::initialize(); // needed for interpreter entry points 989 if (!UseSharedSpaces) { 990 HandleMark hm(THREAD); 991 KlassHandle ok_h(THREAD, SystemDictionary::Object_klass()); 992 Universe::reinitialize_vtable_of(ok_h, CHECK_false); 993 Universe::reinitialize_itables(CHECK_false); 994 } 995 } 996 997 HandleMark hm(THREAD); 998 Klass* k; 999 instanceKlassHandle k_h; 1000 // Setup preallocated empty java.lang.Class array 1001 Universe::_the_empty_class_klass_array = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_false); 1002 1003 // Setup preallocated OutOfMemoryError errors 1004 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_OutOfMemoryError(), true, CHECK_false); 1005 k_h = instanceKlassHandle(THREAD, k); 1006 Universe::_out_of_memory_error_java_heap = k_h->allocate_instance(CHECK_false); 1007 Universe::_out_of_memory_error_metaspace = k_h->allocate_instance(CHECK_false); 1008 Universe::_out_of_memory_error_class_metaspace = k_h->allocate_instance(CHECK_false); 1009 Universe::_out_of_memory_error_array_size = k_h->allocate_instance(CHECK_false); 1010 Universe::_out_of_memory_error_gc_overhead_limit = 1011 k_h->allocate_instance(CHECK_false); 1012 Universe::_out_of_memory_error_realloc_objects = k_h->allocate_instance(CHECK_false); 1013 1014 // Setup preallocated cause message for delayed StackOverflowError 1015 if (StackReservedPages > 0) { 1016 Universe::_delayed_stack_overflow_error_message = 1017 java_lang_String::create_oop_from_str("Delayed StackOverflowError due to ReservedStackAccess annotated method", CHECK_false); 1018 } 1019 1020 // Setup preallocated NullPointerException 1021 // (this is currently used for a cheap & dirty solution in compiler exception handling) 1022 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_NullPointerException(), true, CHECK_false); 1023 Universe::_null_ptr_exception_instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false); 1024 // Setup preallocated ArithmeticException 1025 // (this is currently used for a cheap & dirty solution in compiler exception handling) 1026 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ArithmeticException(), true, CHECK_false); 1027 Universe::_arithmetic_exception_instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false); 1028 // Virtual Machine Error for when we get into a situation we can't resolve 1029 k = SystemDictionary::resolve_or_fail( 1030 vmSymbols::java_lang_VirtualMachineError(), true, CHECK_false); 1031 bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false); 1032 if (!linked) { 1047 msg = java_lang_String::create_from_str("Metaspace", CHECK_false); 1048 java_lang_Throwable::set_message(Universe::_out_of_memory_error_metaspace, msg()); 1049 msg = java_lang_String::create_from_str("Compressed class space", CHECK_false); 1050 java_lang_Throwable::set_message(Universe::_out_of_memory_error_class_metaspace, msg()); 1051 1052 msg = java_lang_String::create_from_str("Requested array size exceeds VM limit", CHECK_false); 1053 java_lang_Throwable::set_message(Universe::_out_of_memory_error_array_size, msg()); 1054 1055 msg = java_lang_String::create_from_str("GC overhead limit exceeded", CHECK_false); 1056 java_lang_Throwable::set_message(Universe::_out_of_memory_error_gc_overhead_limit, msg()); 1057 1058 msg = java_lang_String::create_from_str("Java heap space: failed reallocation of scalar replaced objects", CHECK_false); 1059 java_lang_Throwable::set_message(Universe::_out_of_memory_error_realloc_objects, msg()); 1060 1061 msg = java_lang_String::create_from_str("/ by zero", CHECK_false); 1062 java_lang_Throwable::set_message(Universe::_arithmetic_exception_instance, msg()); 1063 1064 // Setup the array of errors that have preallocated backtrace 1065 k = Universe::_out_of_memory_error_java_heap->klass(); 1066 assert(k->name() == vmSymbols::java_lang_OutOfMemoryError(), "should be out of memory error"); 1067 k_h = instanceKlassHandle(THREAD, k); 1068 1069 int len = (StackTraceInThrowable) ? (int)PreallocatedOutOfMemoryErrorCount : 0; 1070 Universe::_preallocated_out_of_memory_error_array = oopFactory::new_objArray(k_h(), len, CHECK_false); 1071 for (int i=0; i<len; i++) { 1072 oop err = k_h->allocate_instance(CHECK_false); 1073 Handle err_h = Handle(THREAD, err); 1074 java_lang_Throwable::allocate_backtrace(err_h, CHECK_false); 1075 Universe::preallocated_out_of_memory_errors()->obj_at_put(i, err_h()); 1076 } 1077 Universe::_preallocated_out_of_memory_error_avail_count = (jint)len; 1078 } 1079 1080 Universe::initialize_known_methods(CHECK_false); 1081 1082 // This needs to be done before the first scavenge/gc, since 1083 // it's an input to soft ref clearing policy. 1084 { 1085 MutexLocker x(Heap_lock); 1086 Universe::update_heap_info_at_gc(); 1087 } 1088 1089 // ("weak") refs processing infrastructure initialization 1090 Universe::heap()->post_initialize(); 1091 1092 // Initialize performance counters for metaspaces | 467 //_mirrors[T_OBJECT] = _object_klass->java_mirror(); 468 //_mirrors[T_ARRAY] = _object_klass->java_mirror(); 469 } 470 471 void Universe::fixup_mirrors(TRAPS) { 472 // Bootstrap problem: all classes gets a mirror (java.lang.Class instance) assigned eagerly, 473 // but we cannot do that for classes created before java.lang.Class is loaded. Here we simply 474 // walk over permanent objects created so far (mostly classes) and fixup their mirrors. Note 475 // that the number of objects allocated at this point is very small. 476 assert(SystemDictionary::Class_klass_loaded(), "java.lang.Class should be loaded"); 477 HandleMark hm(THREAD); 478 // Cache the start of the static fields 479 InstanceMirrorKlass::init_offset_of_static_fields(); 480 481 GrowableArray <Klass*>* list = java_lang_Class::fixup_mirror_list(); 482 int list_length = list->length(); 483 for (int i = 0; i < list_length; i++) { 484 Klass* k = list->at(i); 485 assert(k->is_klass(), "List should only hold classes"); 486 EXCEPTION_MARK; 487 java_lang_Class::fixup_mirror(k, CATCH); 488 } 489 delete java_lang_Class::fixup_mirror_list(); 490 java_lang_Class::set_fixup_mirror_list(NULL); 491 } 492 493 #define assert_pll_locked(test) \ 494 assert(Heap_lock->test(), "Reference pending list access requires lock") 495 496 #define assert_pll_ownership() assert_pll_locked(owned_by_self) 497 498 oop Universe::reference_pending_list() { 499 assert_pll_ownership(); 500 return _reference_pending_list; 501 } 502 503 void Universe::set_reference_pending_list(oop list) { 504 assert_pll_ownership(); 505 _reference_pending_list = list; 506 } 507 508 bool Universe::has_reference_pending_list() { 512 513 oop Universe::swap_reference_pending_list(oop list) { 514 assert_pll_locked(is_locked); 515 return (oop)Atomic::xchg_ptr(list, &_reference_pending_list); 516 } 517 518 #undef assert_pll_locked 519 #undef assert_pll_ownership 520 521 522 static bool has_run_finalizers_on_exit = false; 523 524 void Universe::run_finalizers_on_exit() { 525 if (has_run_finalizers_on_exit) return; 526 has_run_finalizers_on_exit = true; 527 528 // Called on VM exit. This ought to be run in a separate thread. 529 log_trace(ref)("Callback to run finalizers on exit"); 530 { 531 PRESERVE_EXCEPTION_MARK; 532 Klass* finalizer_klass = SystemDictionary::Finalizer_klass(); 533 JavaValue result(T_VOID); 534 JavaCalls::call_static( 535 &result, 536 finalizer_klass, 537 vmSymbols::run_finalizers_on_exit_name(), 538 vmSymbols::void_method_signature(), 539 THREAD 540 ); 541 // Ignore any pending exceptions 542 CLEAR_PENDING_EXCEPTION; 543 } 544 } 545 546 547 // initialize_vtable could cause gc if 548 // 1) we specified true to initialize_vtable and 549 // 2) this ran after gc was enabled 550 // In case those ever change we use handles for oops 551 void Universe::reinitialize_vtable_of(Klass* ko, TRAPS) { 552 // init vtable of k and all subclasses 553 klassVtable* vt = ko->vtable(); 554 if (vt) vt->initialize_vtable(false, CHECK); 555 if (ko->is_instance_klass()) { 556 for (Klass* sk = ko->subklass(); 557 sk != NULL; 558 sk = sk->next_sibling()) { 559 reinitialize_vtable_of(sk, CHECK); 560 } 561 } 562 } 563 564 565 void initialize_itable_for_klass(Klass* k, TRAPS) { 566 InstanceKlass::cast(k)->itable()->initialize_itable(false, CHECK); 567 } 568 569 570 void Universe::reinitialize_itables(TRAPS) { 571 SystemDictionary::classes_do(initialize_itable_for_klass, CHECK); 572 573 } 574 575 576 bool Universe::on_page_boundary(void* addr) { 577 return ((uintptr_t) addr) % os::vm_page_size() == 0; 578 } 579 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 { ResourceMark rm; 986 Interpreter::initialize(); // needed for interpreter entry points 987 if (!UseSharedSpaces) { 988 HandleMark hm(THREAD); 989 Klass* ok = SystemDictionary::Object_klass(); 990 Universe::reinitialize_vtable_of(ok, CHECK_false); 991 Universe::reinitialize_itables(CHECK_false); 992 } 993 } 994 995 HandleMark hm(THREAD); 996 // Setup preallocated empty java.lang.Class array 997 Universe::_the_empty_class_klass_array = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_false); 998 999 // Setup preallocated OutOfMemoryError errors 1000 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_OutOfMemoryError(), true, CHECK_false); 1001 InstanceKlass* ik = InstanceKlass::cast(k); 1002 Universe::_out_of_memory_error_java_heap = ik->allocate_instance(CHECK_false); 1003 Universe::_out_of_memory_error_metaspace = ik->allocate_instance(CHECK_false); 1004 Universe::_out_of_memory_error_class_metaspace = ik->allocate_instance(CHECK_false); 1005 Universe::_out_of_memory_error_array_size = ik->allocate_instance(CHECK_false); 1006 Universe::_out_of_memory_error_gc_overhead_limit = 1007 ik->allocate_instance(CHECK_false); 1008 Universe::_out_of_memory_error_realloc_objects = ik->allocate_instance(CHECK_false); 1009 1010 // Setup preallocated cause message for delayed StackOverflowError 1011 if (StackReservedPages > 0) { 1012 Universe::_delayed_stack_overflow_error_message = 1013 java_lang_String::create_oop_from_str("Delayed StackOverflowError due to ReservedStackAccess annotated method", CHECK_false); 1014 } 1015 1016 // Setup preallocated NullPointerException 1017 // (this is currently used for a cheap & dirty solution in compiler exception handling) 1018 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_NullPointerException(), true, CHECK_false); 1019 Universe::_null_ptr_exception_instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false); 1020 // Setup preallocated ArithmeticException 1021 // (this is currently used for a cheap & dirty solution in compiler exception handling) 1022 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ArithmeticException(), true, CHECK_false); 1023 Universe::_arithmetic_exception_instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false); 1024 // Virtual Machine Error for when we get into a situation we can't resolve 1025 k = SystemDictionary::resolve_or_fail( 1026 vmSymbols::java_lang_VirtualMachineError(), true, CHECK_false); 1027 bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false); 1028 if (!linked) { 1043 msg = java_lang_String::create_from_str("Metaspace", CHECK_false); 1044 java_lang_Throwable::set_message(Universe::_out_of_memory_error_metaspace, msg()); 1045 msg = java_lang_String::create_from_str("Compressed class space", CHECK_false); 1046 java_lang_Throwable::set_message(Universe::_out_of_memory_error_class_metaspace, msg()); 1047 1048 msg = java_lang_String::create_from_str("Requested array size exceeds VM limit", CHECK_false); 1049 java_lang_Throwable::set_message(Universe::_out_of_memory_error_array_size, msg()); 1050 1051 msg = java_lang_String::create_from_str("GC overhead limit exceeded", CHECK_false); 1052 java_lang_Throwable::set_message(Universe::_out_of_memory_error_gc_overhead_limit, msg()); 1053 1054 msg = java_lang_String::create_from_str("Java heap space: failed reallocation of scalar replaced objects", CHECK_false); 1055 java_lang_Throwable::set_message(Universe::_out_of_memory_error_realloc_objects, msg()); 1056 1057 msg = java_lang_String::create_from_str("/ by zero", CHECK_false); 1058 java_lang_Throwable::set_message(Universe::_arithmetic_exception_instance, msg()); 1059 1060 // Setup the array of errors that have preallocated backtrace 1061 k = Universe::_out_of_memory_error_java_heap->klass(); 1062 assert(k->name() == vmSymbols::java_lang_OutOfMemoryError(), "should be out of memory error"); 1063 ik = InstanceKlass::cast(k); 1064 1065 int len = (StackTraceInThrowable) ? (int)PreallocatedOutOfMemoryErrorCount : 0; 1066 Universe::_preallocated_out_of_memory_error_array = oopFactory::new_objArray(ik, len, CHECK_false); 1067 for (int i=0; i<len; i++) { 1068 oop err = ik->allocate_instance(CHECK_false); 1069 Handle err_h = Handle(THREAD, err); 1070 java_lang_Throwable::allocate_backtrace(err_h, CHECK_false); 1071 Universe::preallocated_out_of_memory_errors()->obj_at_put(i, err_h()); 1072 } 1073 Universe::_preallocated_out_of_memory_error_avail_count = (jint)len; 1074 } 1075 1076 Universe::initialize_known_methods(CHECK_false); 1077 1078 // This needs to be done before the first scavenge/gc, since 1079 // it's an input to soft ref clearing policy. 1080 { 1081 MutexLocker x(Heap_lock); 1082 Universe::update_heap_info_at_gc(); 1083 } 1084 1085 // ("weak") refs processing infrastructure initialization 1086 Universe::heap()->post_initialize(); 1087 1088 // Initialize performance counters for metaspaces |