96 oop Universe::_void_mirror = NULL;
97 oop Universe::_mirrors[T_VOID+1] = { NULL /*, NULL...*/ };
98 oop Universe::_main_thread_group = NULL;
99 oop Universe::_system_thread_group = NULL;
100 objArrayOop Universe::_the_empty_class_klass_array = NULL;
101 Array<Klass*>* Universe::_the_array_interfaces_array = NULL;
102 oop Universe::_the_null_sentinel = NULL;
103 oop Universe::_the_null_string = NULL;
104 oop Universe::_the_min_jint_string = NULL;
105 LatestMethodCache* Universe::_finalizer_register_cache = NULL;
106 LatestMethodCache* Universe::_loader_addClass_cache = NULL;
107 LatestMethodCache* Universe::_pd_implies_cache = NULL;
108 LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL;
109 LatestMethodCache* Universe::_do_stack_walk_cache = NULL;
110 oop Universe::_out_of_memory_error_java_heap = NULL;
111 oop Universe::_out_of_memory_error_metaspace = NULL;
112 oop Universe::_out_of_memory_error_class_metaspace = NULL;
113 oop Universe::_out_of_memory_error_array_size = NULL;
114 oop Universe::_out_of_memory_error_gc_overhead_limit = NULL;
115 oop Universe::_out_of_memory_error_realloc_objects = NULL;
116 oop Universe::_delayed_stack_overflow_error_message = NULL;
117 objArrayOop Universe::_preallocated_out_of_memory_error_array = NULL;
118 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
119 bool Universe::_verify_in_progress = false;
120 long Universe::verify_flags = Universe::Verify_All;
121 oop Universe::_null_ptr_exception_instance = NULL;
122 oop Universe::_arithmetic_exception_instance = NULL;
123 oop Universe::_virtual_machine_error_instance = NULL;
124 oop Universe::_vm_exception = NULL;
125 oop Universe::_reference_pending_list = NULL;
126
127 Array<int>* Universe::_the_empty_int_array = NULL;
128 Array<u2>* Universe::_the_empty_short_array = NULL;
129 Array<Klass*>* Universe::_the_empty_klass_array = NULL;
130 Array<InstanceKlass*>* Universe::_the_empty_instance_klass_array = NULL;
131 Array<Method*>* Universe::_the_empty_method_array = NULL;
132
133 // These variables are guarded by FullGCALot_lock.
134 debug_only(objArrayOop Universe::_fullgc_alot_dummy_array = NULL;)
135 debug_only(int Universe::_fullgc_alot_dummy_next = 0;)
178 f->do_oop((oop*) &_char_mirror);
179 f->do_oop((oop*) &_long_mirror);
180 f->do_oop((oop*) &_short_mirror);
181 f->do_oop((oop*) &_void_mirror);
182
183 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
184 f->do_oop((oop*) &_mirrors[i]);
185 }
186 assert(_mirrors[0] == NULL && _mirrors[T_BOOLEAN - 1] == NULL, "checking");
187
188 f->do_oop((oop*)&_the_empty_class_klass_array);
189 f->do_oop((oop*)&_the_null_sentinel);
190 f->do_oop((oop*)&_the_null_string);
191 f->do_oop((oop*)&_the_min_jint_string);
192 f->do_oop((oop*)&_out_of_memory_error_java_heap);
193 f->do_oop((oop*)&_out_of_memory_error_metaspace);
194 f->do_oop((oop*)&_out_of_memory_error_class_metaspace);
195 f->do_oop((oop*)&_out_of_memory_error_array_size);
196 f->do_oop((oop*)&_out_of_memory_error_gc_overhead_limit);
197 f->do_oop((oop*)&_out_of_memory_error_realloc_objects);
198 f->do_oop((oop*)&_delayed_stack_overflow_error_message);
199 f->do_oop((oop*)&_preallocated_out_of_memory_error_array);
200 f->do_oop((oop*)&_null_ptr_exception_instance);
201 f->do_oop((oop*)&_arithmetic_exception_instance);
202 f->do_oop((oop*)&_virtual_machine_error_instance);
203 f->do_oop((oop*)&_main_thread_group);
204 f->do_oop((oop*)&_system_thread_group);
205 f->do_oop((oop*)&_vm_exception);
206 f->do_oop((oop*)&_reference_pending_list);
207 debug_only(f->do_oop((oop*)&_fullgc_alot_dummy_array);)
208 }
209
210 void LatestMethodCache::metaspace_pointers_do(MetaspaceClosure* it) {
211 it->push(&_klass);
212 }
213
214 void Universe::metaspace_pointers_do(MetaspaceClosure* it) {
215 for (int i = 0; i < T_LONG+1; i++) {
216 it->push(&_typeArrayKlassObjs[i]);
217 }
548 ClassLoaderDataGraph::dictionary_classes_do(initialize_itable_for_klass, CHECK);
549 }
550
551
552 bool Universe::on_page_boundary(void* addr) {
553 return is_aligned(addr, os::vm_page_size());
554 }
555
556
557 bool Universe::should_fill_in_stack_trace(Handle throwable) {
558 // never attempt to fill in the stack trace of preallocated errors that do not have
559 // backtrace. These errors are kept alive forever and may be "re-used" when all
560 // preallocated errors with backtrace have been consumed. Also need to avoid
561 // a potential loop which could happen if an out of memory occurs when attempting
562 // to allocate the backtrace.
563 return ((!oopDesc::equals(throwable(), Universe::_out_of_memory_error_java_heap)) &&
564 (!oopDesc::equals(throwable(), Universe::_out_of_memory_error_metaspace)) &&
565 (!oopDesc::equals(throwable(), Universe::_out_of_memory_error_class_metaspace)) &&
566 (!oopDesc::equals(throwable(), Universe::_out_of_memory_error_array_size)) &&
567 (!oopDesc::equals(throwable(), Universe::_out_of_memory_error_gc_overhead_limit)) &&
568 (!oopDesc::equals(throwable(), Universe::_out_of_memory_error_realloc_objects)));
569 }
570
571
572 oop Universe::gen_out_of_memory_error(oop default_err) {
573 // generate an out of memory error:
574 // - if there is a preallocated error and stack traces are available
575 // (j.l.Throwable is initialized), then return the preallocated
576 // error with a filled in stack trace, and with the message
577 // provided by the default error.
578 // - otherwise, return the default error, without a stack trace.
579 int next;
580 if ((_preallocated_out_of_memory_error_avail_count > 0) &&
581 SystemDictionary::Throwable_klass()->is_initialized()) {
582 next = (int)Atomic::add(-1, &_preallocated_out_of_memory_error_avail_count);
583 assert(next < (int)PreallocatedOutOfMemoryErrorCount, "avail count is corrupt");
584 } else {
585 next = -1;
586 }
587 if (next < 0) {
588 // all preallocated errors have been used.
957 Klass* ok = SystemDictionary::Object_klass();
958 Universe::reinitialize_vtable_of(ok, CHECK_false);
959 Universe::reinitialize_itables(CHECK_false);
960 }
961 }
962
963 HandleMark hm(THREAD);
964 // Setup preallocated empty java.lang.Class array
965 Universe::_the_empty_class_klass_array = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_false);
966
967 // Setup preallocated OutOfMemoryError errors
968 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_OutOfMemoryError(), true, CHECK_false);
969 InstanceKlass* ik = InstanceKlass::cast(k);
970 Universe::_out_of_memory_error_java_heap = ik->allocate_instance(CHECK_false);
971 Universe::_out_of_memory_error_metaspace = ik->allocate_instance(CHECK_false);
972 Universe::_out_of_memory_error_class_metaspace = ik->allocate_instance(CHECK_false);
973 Universe::_out_of_memory_error_array_size = ik->allocate_instance(CHECK_false);
974 Universe::_out_of_memory_error_gc_overhead_limit =
975 ik->allocate_instance(CHECK_false);
976 Universe::_out_of_memory_error_realloc_objects = ik->allocate_instance(CHECK_false);
977
978 // Setup preallocated cause message for delayed StackOverflowError
979 if (StackReservedPages > 0) {
980 Universe::_delayed_stack_overflow_error_message =
981 java_lang_String::create_oop_from_str("Delayed StackOverflowError due to ReservedStackAccess annotated method", CHECK_false);
982 }
983
984 // Setup preallocated NullPointerException
985 // (this is currently used for a cheap & dirty solution in compiler exception handling)
986 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_NullPointerException(), true, CHECK_false);
987 Universe::_null_ptr_exception_instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
988 // Setup preallocated ArithmeticException
989 // (this is currently used for a cheap & dirty solution in compiler exception handling)
990 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ArithmeticException(), true, CHECK_false);
991 Universe::_arithmetic_exception_instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
992 // Virtual Machine Error for when we get into a situation we can't resolve
993 k = SystemDictionary::resolve_or_fail(
994 vmSymbols::java_lang_VirtualMachineError(), true, CHECK_false);
995 bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false);
996 if (!linked) {
1002
1003 Universe::_vm_exception = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
1004
1005 Handle msg = java_lang_String::create_from_str("Java heap space", CHECK_false);
1006 java_lang_Throwable::set_message(Universe::_out_of_memory_error_java_heap, msg());
1007
1008 msg = java_lang_String::create_from_str("Metaspace", CHECK_false);
1009 java_lang_Throwable::set_message(Universe::_out_of_memory_error_metaspace, msg());
1010 msg = java_lang_String::create_from_str("Compressed class space", CHECK_false);
1011 java_lang_Throwable::set_message(Universe::_out_of_memory_error_class_metaspace, msg());
1012
1013 msg = java_lang_String::create_from_str("Requested array size exceeds VM limit", CHECK_false);
1014 java_lang_Throwable::set_message(Universe::_out_of_memory_error_array_size, msg());
1015
1016 msg = java_lang_String::create_from_str("GC overhead limit exceeded", CHECK_false);
1017 java_lang_Throwable::set_message(Universe::_out_of_memory_error_gc_overhead_limit, msg());
1018
1019 msg = java_lang_String::create_from_str("Java heap space: failed reallocation of scalar replaced objects", CHECK_false);
1020 java_lang_Throwable::set_message(Universe::_out_of_memory_error_realloc_objects, msg());
1021
1022 msg = java_lang_String::create_from_str("/ by zero", CHECK_false);
1023 java_lang_Throwable::set_message(Universe::_arithmetic_exception_instance, msg());
1024
1025 // Setup the array of errors that have preallocated backtrace
1026 k = Universe::_out_of_memory_error_java_heap->klass();
1027 assert(k->name() == vmSymbols::java_lang_OutOfMemoryError(), "should be out of memory error");
1028 ik = InstanceKlass::cast(k);
1029
1030 int len = (StackTraceInThrowable) ? (int)PreallocatedOutOfMemoryErrorCount : 0;
1031 Universe::_preallocated_out_of_memory_error_array = oopFactory::new_objArray(ik, len, CHECK_false);
1032 for (int i=0; i<len; i++) {
1033 oop err = ik->allocate_instance(CHECK_false);
1034 Handle err_h = Handle(THREAD, err);
1035 java_lang_Throwable::allocate_backtrace(err_h, CHECK_false);
1036 Universe::preallocated_out_of_memory_errors()->obj_at_put(i, err_h());
1037 }
1038 Universe::_preallocated_out_of_memory_error_avail_count = (jint)len;
1039
1040 Universe::initialize_known_methods(CHECK_false);
1041
|
96 oop Universe::_void_mirror = NULL;
97 oop Universe::_mirrors[T_VOID+1] = { NULL /*, NULL...*/ };
98 oop Universe::_main_thread_group = NULL;
99 oop Universe::_system_thread_group = NULL;
100 objArrayOop Universe::_the_empty_class_klass_array = NULL;
101 Array<Klass*>* Universe::_the_array_interfaces_array = NULL;
102 oop Universe::_the_null_sentinel = NULL;
103 oop Universe::_the_null_string = NULL;
104 oop Universe::_the_min_jint_string = NULL;
105 LatestMethodCache* Universe::_finalizer_register_cache = NULL;
106 LatestMethodCache* Universe::_loader_addClass_cache = NULL;
107 LatestMethodCache* Universe::_pd_implies_cache = NULL;
108 LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL;
109 LatestMethodCache* Universe::_do_stack_walk_cache = NULL;
110 oop Universe::_out_of_memory_error_java_heap = NULL;
111 oop Universe::_out_of_memory_error_metaspace = NULL;
112 oop Universe::_out_of_memory_error_class_metaspace = NULL;
113 oop Universe::_out_of_memory_error_array_size = NULL;
114 oop Universe::_out_of_memory_error_gc_overhead_limit = NULL;
115 oop Universe::_out_of_memory_error_realloc_objects = NULL;
116 oop Universe::_out_of_memory_error_retry = NULL;
117 oop Universe::_delayed_stack_overflow_error_message = NULL;
118 objArrayOop Universe::_preallocated_out_of_memory_error_array = NULL;
119 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
120 bool Universe::_verify_in_progress = false;
121 long Universe::verify_flags = Universe::Verify_All;
122 oop Universe::_null_ptr_exception_instance = NULL;
123 oop Universe::_arithmetic_exception_instance = NULL;
124 oop Universe::_virtual_machine_error_instance = NULL;
125 oop Universe::_vm_exception = NULL;
126 oop Universe::_reference_pending_list = NULL;
127
128 Array<int>* Universe::_the_empty_int_array = NULL;
129 Array<u2>* Universe::_the_empty_short_array = NULL;
130 Array<Klass*>* Universe::_the_empty_klass_array = NULL;
131 Array<InstanceKlass*>* Universe::_the_empty_instance_klass_array = NULL;
132 Array<Method*>* Universe::_the_empty_method_array = NULL;
133
134 // These variables are guarded by FullGCALot_lock.
135 debug_only(objArrayOop Universe::_fullgc_alot_dummy_array = NULL;)
136 debug_only(int Universe::_fullgc_alot_dummy_next = 0;)
179 f->do_oop((oop*) &_char_mirror);
180 f->do_oop((oop*) &_long_mirror);
181 f->do_oop((oop*) &_short_mirror);
182 f->do_oop((oop*) &_void_mirror);
183
184 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
185 f->do_oop((oop*) &_mirrors[i]);
186 }
187 assert(_mirrors[0] == NULL && _mirrors[T_BOOLEAN - 1] == NULL, "checking");
188
189 f->do_oop((oop*)&_the_empty_class_klass_array);
190 f->do_oop((oop*)&_the_null_sentinel);
191 f->do_oop((oop*)&_the_null_string);
192 f->do_oop((oop*)&_the_min_jint_string);
193 f->do_oop((oop*)&_out_of_memory_error_java_heap);
194 f->do_oop((oop*)&_out_of_memory_error_metaspace);
195 f->do_oop((oop*)&_out_of_memory_error_class_metaspace);
196 f->do_oop((oop*)&_out_of_memory_error_array_size);
197 f->do_oop((oop*)&_out_of_memory_error_gc_overhead_limit);
198 f->do_oop((oop*)&_out_of_memory_error_realloc_objects);
199 f->do_oop((oop*)&_out_of_memory_error_retry);
200 f->do_oop((oop*)&_delayed_stack_overflow_error_message);
201 f->do_oop((oop*)&_preallocated_out_of_memory_error_array);
202 f->do_oop((oop*)&_null_ptr_exception_instance);
203 f->do_oop((oop*)&_arithmetic_exception_instance);
204 f->do_oop((oop*)&_virtual_machine_error_instance);
205 f->do_oop((oop*)&_main_thread_group);
206 f->do_oop((oop*)&_system_thread_group);
207 f->do_oop((oop*)&_vm_exception);
208 f->do_oop((oop*)&_reference_pending_list);
209 debug_only(f->do_oop((oop*)&_fullgc_alot_dummy_array);)
210 }
211
212 void LatestMethodCache::metaspace_pointers_do(MetaspaceClosure* it) {
213 it->push(&_klass);
214 }
215
216 void Universe::metaspace_pointers_do(MetaspaceClosure* it) {
217 for (int i = 0; i < T_LONG+1; i++) {
218 it->push(&_typeArrayKlassObjs[i]);
219 }
550 ClassLoaderDataGraph::dictionary_classes_do(initialize_itable_for_klass, CHECK);
551 }
552
553
554 bool Universe::on_page_boundary(void* addr) {
555 return is_aligned(addr, os::vm_page_size());
556 }
557
558
559 bool Universe::should_fill_in_stack_trace(Handle throwable) {
560 // never attempt to fill in the stack trace of preallocated errors that do not have
561 // backtrace. These errors are kept alive forever and may be "re-used" when all
562 // preallocated errors with backtrace have been consumed. Also need to avoid
563 // a potential loop which could happen if an out of memory occurs when attempting
564 // to allocate the backtrace.
565 return ((!oopDesc::equals(throwable(), Universe::_out_of_memory_error_java_heap)) &&
566 (!oopDesc::equals(throwable(), Universe::_out_of_memory_error_metaspace)) &&
567 (!oopDesc::equals(throwable(), Universe::_out_of_memory_error_class_metaspace)) &&
568 (!oopDesc::equals(throwable(), Universe::_out_of_memory_error_array_size)) &&
569 (!oopDesc::equals(throwable(), Universe::_out_of_memory_error_gc_overhead_limit)) &&
570 (!oopDesc::equals(throwable(), Universe::_out_of_memory_error_realloc_objects)) &&
571 (!oopDesc::equals(throwable(), Universe::_out_of_memory_error_retry)));
572 }
573
574
575 oop Universe::gen_out_of_memory_error(oop default_err) {
576 // generate an out of memory error:
577 // - if there is a preallocated error and stack traces are available
578 // (j.l.Throwable is initialized), then return the preallocated
579 // error with a filled in stack trace, and with the message
580 // provided by the default error.
581 // - otherwise, return the default error, without a stack trace.
582 int next;
583 if ((_preallocated_out_of_memory_error_avail_count > 0) &&
584 SystemDictionary::Throwable_klass()->is_initialized()) {
585 next = (int)Atomic::add(-1, &_preallocated_out_of_memory_error_avail_count);
586 assert(next < (int)PreallocatedOutOfMemoryErrorCount, "avail count is corrupt");
587 } else {
588 next = -1;
589 }
590 if (next < 0) {
591 // all preallocated errors have been used.
960 Klass* ok = SystemDictionary::Object_klass();
961 Universe::reinitialize_vtable_of(ok, CHECK_false);
962 Universe::reinitialize_itables(CHECK_false);
963 }
964 }
965
966 HandleMark hm(THREAD);
967 // Setup preallocated empty java.lang.Class array
968 Universe::_the_empty_class_klass_array = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_false);
969
970 // Setup preallocated OutOfMemoryError errors
971 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_OutOfMemoryError(), true, CHECK_false);
972 InstanceKlass* ik = InstanceKlass::cast(k);
973 Universe::_out_of_memory_error_java_heap = ik->allocate_instance(CHECK_false);
974 Universe::_out_of_memory_error_metaspace = ik->allocate_instance(CHECK_false);
975 Universe::_out_of_memory_error_class_metaspace = ik->allocate_instance(CHECK_false);
976 Universe::_out_of_memory_error_array_size = ik->allocate_instance(CHECK_false);
977 Universe::_out_of_memory_error_gc_overhead_limit =
978 ik->allocate_instance(CHECK_false);
979 Universe::_out_of_memory_error_realloc_objects = ik->allocate_instance(CHECK_false);
980 Universe::_out_of_memory_error_retry = ik->allocate_instance(CHECK_false);
981
982 // Setup preallocated cause message for delayed StackOverflowError
983 if (StackReservedPages > 0) {
984 Universe::_delayed_stack_overflow_error_message =
985 java_lang_String::create_oop_from_str("Delayed StackOverflowError due to ReservedStackAccess annotated method", CHECK_false);
986 }
987
988 // Setup preallocated NullPointerException
989 // (this is currently used for a cheap & dirty solution in compiler exception handling)
990 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_NullPointerException(), true, CHECK_false);
991 Universe::_null_ptr_exception_instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
992 // Setup preallocated ArithmeticException
993 // (this is currently used for a cheap & dirty solution in compiler exception handling)
994 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ArithmeticException(), true, CHECK_false);
995 Universe::_arithmetic_exception_instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
996 // Virtual Machine Error for when we get into a situation we can't resolve
997 k = SystemDictionary::resolve_or_fail(
998 vmSymbols::java_lang_VirtualMachineError(), true, CHECK_false);
999 bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false);
1000 if (!linked) {
1006
1007 Universe::_vm_exception = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
1008
1009 Handle msg = java_lang_String::create_from_str("Java heap space", CHECK_false);
1010 java_lang_Throwable::set_message(Universe::_out_of_memory_error_java_heap, msg());
1011
1012 msg = java_lang_String::create_from_str("Metaspace", CHECK_false);
1013 java_lang_Throwable::set_message(Universe::_out_of_memory_error_metaspace, msg());
1014 msg = java_lang_String::create_from_str("Compressed class space", CHECK_false);
1015 java_lang_Throwable::set_message(Universe::_out_of_memory_error_class_metaspace, msg());
1016
1017 msg = java_lang_String::create_from_str("Requested array size exceeds VM limit", CHECK_false);
1018 java_lang_Throwable::set_message(Universe::_out_of_memory_error_array_size, msg());
1019
1020 msg = java_lang_String::create_from_str("GC overhead limit exceeded", CHECK_false);
1021 java_lang_Throwable::set_message(Universe::_out_of_memory_error_gc_overhead_limit, msg());
1022
1023 msg = java_lang_String::create_from_str("Java heap space: failed reallocation of scalar replaced objects", CHECK_false);
1024 java_lang_Throwable::set_message(Universe::_out_of_memory_error_realloc_objects, msg());
1025
1026 msg = java_lang_String::create_from_str("Java heap space: failed retryable allocation", CHECK_false);
1027 java_lang_Throwable::set_message(Universe::_out_of_memory_error_retry, msg());
1028
1029 msg = java_lang_String::create_from_str("/ by zero", CHECK_false);
1030 java_lang_Throwable::set_message(Universe::_arithmetic_exception_instance, msg());
1031
1032 // Setup the array of errors that have preallocated backtrace
1033 k = Universe::_out_of_memory_error_java_heap->klass();
1034 assert(k->name() == vmSymbols::java_lang_OutOfMemoryError(), "should be out of memory error");
1035 ik = InstanceKlass::cast(k);
1036
1037 int len = (StackTraceInThrowable) ? (int)PreallocatedOutOfMemoryErrorCount : 0;
1038 Universe::_preallocated_out_of_memory_error_array = oopFactory::new_objArray(ik, len, CHECK_false);
1039 for (int i=0; i<len; i++) {
1040 oop err = ik->allocate_instance(CHECK_false);
1041 Handle err_h = Handle(THREAD, err);
1042 java_lang_Throwable::allocate_backtrace(err_h, CHECK_false);
1043 Universe::preallocated_out_of_memory_errors()->obj_at_put(i, err_h());
1044 }
1045 Universe::_preallocated_out_of_memory_error_avail_count = (jint)len;
1046
1047 Universe::initialize_known_methods(CHECK_false);
1048
|