< prev index next >

src/share/vm/memory/universe.cpp

Print this page
rev 11747 : [mq]: per.hotspot.patch
rev 11748 : imported patch pop_pl
rev 11751 : imported patch suppress_early_stacktrace


 118 LatestMethodCache* Universe::_loader_addClass_cache    = NULL;
 119 LatestMethodCache* Universe::_pd_implies_cache         = NULL;
 120 LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL;
 121 LatestMethodCache* Universe::_do_stack_walk_cache     = NULL;
 122 oop Universe::_out_of_memory_error_java_heap          = NULL;
 123 oop Universe::_out_of_memory_error_metaspace          = NULL;
 124 oop Universe::_out_of_memory_error_class_metaspace    = NULL;
 125 oop Universe::_out_of_memory_error_array_size         = NULL;
 126 oop Universe::_out_of_memory_error_gc_overhead_limit  = NULL;
 127 oop Universe::_out_of_memory_error_realloc_objects    = NULL;
 128 oop Universe::_delayed_stack_overflow_error_message   = NULL;
 129 objArrayOop Universe::_preallocated_out_of_memory_error_array = NULL;
 130 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
 131 bool Universe::_verify_in_progress                    = false;
 132 long Universe::verify_flags                           = Universe::Verify_All;
 133 oop Universe::_null_ptr_exception_instance            = NULL;
 134 oop Universe::_arithmetic_exception_instance          = NULL;
 135 oop Universe::_virtual_machine_error_instance         = NULL;
 136 oop Universe::_vm_exception                           = NULL;
 137 oop Universe::_allocation_context_notification_obj    = NULL;

 138 
 139 Array<int>* Universe::_the_empty_int_array            = NULL;
 140 Array<u2>* Universe::_the_empty_short_array           = NULL;
 141 Array<Klass*>* Universe::_the_empty_klass_array     = NULL;
 142 Array<Method*>* Universe::_the_empty_method_array   = NULL;
 143 
 144 // These variables are guarded by FullGCALot_lock.
 145 debug_only(objArrayOop Universe::_fullgc_alot_dummy_array = NULL;)
 146 debug_only(int Universe::_fullgc_alot_dummy_next      = 0;)
 147 
 148 // Heap
 149 int             Universe::_verify_count = 0;
 150 
 151 // Oop verification (see MacroAssembler::verify_oop)
 152 uintptr_t       Universe::_verify_oop_mask = 0;
 153 uintptr_t       Universe::_verify_oop_bits = (uintptr_t) -1;
 154 
 155 int             Universe::_base_vtable_size = 0;
 156 bool            Universe::_bootstrapping = false;
 157 bool            Universe::_module_initialized = false;


 195   assert(_mirrors[0] == NULL && _mirrors[T_BOOLEAN - 1] == NULL, "checking");
 196 
 197   f->do_oop((oop*)&_the_empty_class_klass_array);
 198   f->do_oop((oop*)&_the_null_string);
 199   f->do_oop((oop*)&_the_min_jint_string);
 200   f->do_oop((oop*)&_out_of_memory_error_java_heap);
 201   f->do_oop((oop*)&_out_of_memory_error_metaspace);
 202   f->do_oop((oop*)&_out_of_memory_error_class_metaspace);
 203   f->do_oop((oop*)&_out_of_memory_error_array_size);
 204   f->do_oop((oop*)&_out_of_memory_error_gc_overhead_limit);
 205   f->do_oop((oop*)&_out_of_memory_error_realloc_objects);
 206   f->do_oop((oop*)&_delayed_stack_overflow_error_message);
 207   f->do_oop((oop*)&_preallocated_out_of_memory_error_array);
 208   f->do_oop((oop*)&_null_ptr_exception_instance);
 209   f->do_oop((oop*)&_arithmetic_exception_instance);
 210   f->do_oop((oop*)&_virtual_machine_error_instance);
 211   f->do_oop((oop*)&_main_thread_group);
 212   f->do_oop((oop*)&_system_thread_group);
 213   f->do_oop((oop*)&_vm_exception);
 214   f->do_oop((oop*)&_allocation_context_notification_obj);

 215   debug_only(f->do_oop((oop*)&_fullgc_alot_dummy_array);)
 216 }
 217 
 218 // Serialize metadata in and out of CDS archive, not oops.
 219 void Universe::serialize(SerializeClosure* f, bool do_all) {
 220 
 221   f->do_ptr((void**)&_boolArrayKlassObj);
 222   f->do_ptr((void**)&_byteArrayKlassObj);
 223   f->do_ptr((void**)&_charArrayKlassObj);
 224   f->do_ptr((void**)&_intArrayKlassObj);
 225   f->do_ptr((void**)&_shortArrayKlassObj);
 226   f->do_ptr((void**)&_longArrayKlassObj);
 227   f->do_ptr((void**)&_singleArrayKlassObj);
 228   f->do_ptr((void**)&_doubleArrayKlassObj);
 229   f->do_ptr((void**)&_objectArrayKlassObj);
 230 
 231   {
 232     for (int i = 0; i < T_VOID+1; i++) {
 233       if (_typeArrayKlassObjs[i] != NULL) {
 234         assert(i >= T_BOOLEAN, "checking");


 471   // walk over permanent objects created so far (mostly classes) and fixup their mirrors. Note
 472   // that the number of objects allocated at this point is very small.
 473   assert(SystemDictionary::Class_klass_loaded(), "java.lang.Class should be loaded");
 474   HandleMark hm(THREAD);
 475   // Cache the start of the static fields
 476   InstanceMirrorKlass::init_offset_of_static_fields();
 477 
 478   GrowableArray <Klass*>* list = java_lang_Class::fixup_mirror_list();
 479   int list_length = list->length();
 480   for (int i = 0; i < list_length; i++) {
 481     Klass* k = list->at(i);
 482     assert(k->is_klass(), "List should only hold classes");
 483     EXCEPTION_MARK;
 484     KlassHandle kh(THREAD, k);
 485     java_lang_Class::fixup_mirror(kh, CATCH);
 486 }
 487   delete java_lang_Class::fixup_mirror_list();
 488   java_lang_Class::set_fixup_mirror_list(NULL);
 489 }
 490 





























 491 static bool has_run_finalizers_on_exit = false;
 492 
 493 void Universe::run_finalizers_on_exit() {
 494   if (has_run_finalizers_on_exit) return;
 495   has_run_finalizers_on_exit = true;
 496 
 497   // Called on VM exit. This ought to be run in a separate thread.
 498   log_trace(ref)("Callback to run finalizers on exit");
 499   {
 500     PRESERVE_EXCEPTION_MARK;
 501     KlassHandle finalizer_klass(THREAD, SystemDictionary::Finalizer_klass());
 502     JavaValue result(T_VOID);
 503     JavaCalls::call_static(
 504       &result,
 505       finalizer_klass,
 506       vmSymbols::run_finalizers_on_exit_name(),
 507       vmSymbols::void_method_signature(),
 508       THREAD
 509     );
 510     // Ignore any pending exceptions


 548 }
 549 
 550 
 551 bool Universe::should_fill_in_stack_trace(Handle throwable) {
 552   // never attempt to fill in the stack trace of preallocated errors that do not have
 553   // backtrace. These errors are kept alive forever and may be "re-used" when all
 554   // preallocated errors with backtrace have been consumed. Also need to avoid
 555   // a potential loop which could happen if an out of memory occurs when attempting
 556   // to allocate the backtrace.
 557   return ((throwable() != Universe::_out_of_memory_error_java_heap) &&
 558           (throwable() != Universe::_out_of_memory_error_metaspace)  &&
 559           (throwable() != Universe::_out_of_memory_error_class_metaspace)  &&
 560           (throwable() != Universe::_out_of_memory_error_array_size) &&
 561           (throwable() != Universe::_out_of_memory_error_gc_overhead_limit) &&
 562           (throwable() != Universe::_out_of_memory_error_realloc_objects));
 563 }
 564 
 565 
 566 oop Universe::gen_out_of_memory_error(oop default_err) {
 567   // generate an out of memory error:
 568   // - if there is a preallocated error with backtrace available then return it wth
 569   //   a filled in stack trace.
 570   // - if there are no preallocated errors with backtrace available then return
 571   //   an error without backtrace.

 572   int next;
 573   if (_preallocated_out_of_memory_error_avail_count > 0) {

 574     next = (int)Atomic::add(-1, &_preallocated_out_of_memory_error_avail_count);
 575     assert(next < (int)PreallocatedOutOfMemoryErrorCount, "avail count is corrupt");
 576   } else {
 577     next = -1;
 578   }
 579   if (next < 0) {
 580     // all preallocated errors have been used.
 581     // return default
 582     return default_err;
 583   } else {
 584     // get the error object at the slot and set set it to NULL so that the
 585     // array isn't keeping it alive anymore.
 586     oop exc = preallocated_out_of_memory_errors()->obj_at(next);
 587     assert(exc != NULL, "slot has been used already");
 588     preallocated_out_of_memory_errors()->obj_at_put(next, NULL);
 589 
 590     // use the message from the default error
 591     oop msg = java_lang_Throwable::message(default_err);
 592     assert(msg != NULL, "no message");
 593     java_lang_Throwable::set_message(exc, msg);




 118 LatestMethodCache* Universe::_loader_addClass_cache    = NULL;
 119 LatestMethodCache* Universe::_pd_implies_cache         = NULL;
 120 LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL;
 121 LatestMethodCache* Universe::_do_stack_walk_cache     = NULL;
 122 oop Universe::_out_of_memory_error_java_heap          = NULL;
 123 oop Universe::_out_of_memory_error_metaspace          = NULL;
 124 oop Universe::_out_of_memory_error_class_metaspace    = NULL;
 125 oop Universe::_out_of_memory_error_array_size         = NULL;
 126 oop Universe::_out_of_memory_error_gc_overhead_limit  = NULL;
 127 oop Universe::_out_of_memory_error_realloc_objects    = NULL;
 128 oop Universe::_delayed_stack_overflow_error_message   = NULL;
 129 objArrayOop Universe::_preallocated_out_of_memory_error_array = NULL;
 130 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
 131 bool Universe::_verify_in_progress                    = false;
 132 long Universe::verify_flags                           = Universe::Verify_All;
 133 oop Universe::_null_ptr_exception_instance            = NULL;
 134 oop Universe::_arithmetic_exception_instance          = NULL;
 135 oop Universe::_virtual_machine_error_instance         = NULL;
 136 oop Universe::_vm_exception                           = NULL;
 137 oop Universe::_allocation_context_notification_obj    = NULL;
 138 oop Universe::_reference_pending_list                 = NULL;
 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<Method*>* Universe::_the_empty_method_array   = NULL;
 144 
 145 // These variables are guarded by FullGCALot_lock.
 146 debug_only(objArrayOop Universe::_fullgc_alot_dummy_array = NULL;)
 147 debug_only(int Universe::_fullgc_alot_dummy_next      = 0;)
 148 
 149 // Heap
 150 int             Universe::_verify_count = 0;
 151 
 152 // Oop verification (see MacroAssembler::verify_oop)
 153 uintptr_t       Universe::_verify_oop_mask = 0;
 154 uintptr_t       Universe::_verify_oop_bits = (uintptr_t) -1;
 155 
 156 int             Universe::_base_vtable_size = 0;
 157 bool            Universe::_bootstrapping = false;
 158 bool            Universe::_module_initialized = false;


 196   assert(_mirrors[0] == NULL && _mirrors[T_BOOLEAN - 1] == NULL, "checking");
 197 
 198   f->do_oop((oop*)&_the_empty_class_klass_array);
 199   f->do_oop((oop*)&_the_null_string);
 200   f->do_oop((oop*)&_the_min_jint_string);
 201   f->do_oop((oop*)&_out_of_memory_error_java_heap);
 202   f->do_oop((oop*)&_out_of_memory_error_metaspace);
 203   f->do_oop((oop*)&_out_of_memory_error_class_metaspace);
 204   f->do_oop((oop*)&_out_of_memory_error_array_size);
 205   f->do_oop((oop*)&_out_of_memory_error_gc_overhead_limit);
 206   f->do_oop((oop*)&_out_of_memory_error_realloc_objects);
 207   f->do_oop((oop*)&_delayed_stack_overflow_error_message);
 208   f->do_oop((oop*)&_preallocated_out_of_memory_error_array);
 209   f->do_oop((oop*)&_null_ptr_exception_instance);
 210   f->do_oop((oop*)&_arithmetic_exception_instance);
 211   f->do_oop((oop*)&_virtual_machine_error_instance);
 212   f->do_oop((oop*)&_main_thread_group);
 213   f->do_oop((oop*)&_system_thread_group);
 214   f->do_oop((oop*)&_vm_exception);
 215   f->do_oop((oop*)&_allocation_context_notification_obj);
 216   f->do_oop((oop*)&_reference_pending_list);
 217   debug_only(f->do_oop((oop*)&_fullgc_alot_dummy_array);)
 218 }
 219 
 220 // Serialize metadata in and out of CDS archive, not oops.
 221 void Universe::serialize(SerializeClosure* f, bool do_all) {
 222 
 223   f->do_ptr((void**)&_boolArrayKlassObj);
 224   f->do_ptr((void**)&_byteArrayKlassObj);
 225   f->do_ptr((void**)&_charArrayKlassObj);
 226   f->do_ptr((void**)&_intArrayKlassObj);
 227   f->do_ptr((void**)&_shortArrayKlassObj);
 228   f->do_ptr((void**)&_longArrayKlassObj);
 229   f->do_ptr((void**)&_singleArrayKlassObj);
 230   f->do_ptr((void**)&_doubleArrayKlassObj);
 231   f->do_ptr((void**)&_objectArrayKlassObj);
 232 
 233   {
 234     for (int i = 0; i < T_VOID+1; i++) {
 235       if (_typeArrayKlassObjs[i] != NULL) {
 236         assert(i >= T_BOOLEAN, "checking");


 473   // walk over permanent objects created so far (mostly classes) and fixup their mirrors. Note
 474   // that the number of objects allocated at this point is very small.
 475   assert(SystemDictionary::Class_klass_loaded(), "java.lang.Class should be loaded");
 476   HandleMark hm(THREAD);
 477   // Cache the start of the static fields
 478   InstanceMirrorKlass::init_offset_of_static_fields();
 479 
 480   GrowableArray <Klass*>* list = java_lang_Class::fixup_mirror_list();
 481   int list_length = list->length();
 482   for (int i = 0; i < list_length; i++) {
 483     Klass* k = list->at(i);
 484     assert(k->is_klass(), "List should only hold classes");
 485     EXCEPTION_MARK;
 486     KlassHandle kh(THREAD, k);
 487     java_lang_Class::fixup_mirror(kh, 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() {
 509   assert_pll_ownership();
 510   return _reference_pending_list != NULL;
 511 }
 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     KlassHandle finalizer_klass(THREAD, 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


 579 }
 580 
 581 
 582 bool Universe::should_fill_in_stack_trace(Handle throwable) {
 583   // never attempt to fill in the stack trace of preallocated errors that do not have
 584   // backtrace. These errors are kept alive forever and may be "re-used" when all
 585   // preallocated errors with backtrace have been consumed. Also need to avoid
 586   // a potential loop which could happen if an out of memory occurs when attempting
 587   // to allocate the backtrace.
 588   return ((throwable() != Universe::_out_of_memory_error_java_heap) &&
 589           (throwable() != Universe::_out_of_memory_error_metaspace)  &&
 590           (throwable() != Universe::_out_of_memory_error_class_metaspace)  &&
 591           (throwable() != Universe::_out_of_memory_error_array_size) &&
 592           (throwable() != Universe::_out_of_memory_error_gc_overhead_limit) &&
 593           (throwable() != Universe::_out_of_memory_error_realloc_objects));
 594 }
 595 
 596 
 597 oop Universe::gen_out_of_memory_error(oop default_err) {
 598   // generate an out of memory error:
 599   // - if there is a preallocated error and stack traces are available
 600   //   (j.l.Throwable is initialized), then return the preallocated
 601   //   error with a filled in stack trace, and with the message
 602   //   provided by the default error.
 603   // - otherwise, return the default error, without a stack trace.
 604   int next;
 605   if ((_preallocated_out_of_memory_error_avail_count > 0) &&
 606       SystemDictionary::Throwable_klass()->is_initialized()) {
 607     next = (int)Atomic::add(-1, &_preallocated_out_of_memory_error_avail_count);
 608     assert(next < (int)PreallocatedOutOfMemoryErrorCount, "avail count is corrupt");
 609   } else {
 610     next = -1;
 611   }
 612   if (next < 0) {
 613     // all preallocated errors have been used.
 614     // return default
 615     return default_err;
 616   } else {
 617     // get the error object at the slot and set set it to NULL so that the
 618     // array isn't keeping it alive anymore.
 619     oop exc = preallocated_out_of_memory_errors()->obj_at(next);
 620     assert(exc != NULL, "slot has been used already");
 621     preallocated_out_of_memory_errors()->obj_at_put(next, NULL);
 622 
 623     // use the message from the default error
 624     oop msg = java_lang_Throwable::message(default_err);
 625     assert(msg != NULL, "no message");
 626     java_lang_Throwable::set_message(exc, msg);


< prev index next >