< prev index next >

src/hotspot/share/memory/universe.cpp

Print this page

  47 #include "gc/shared/oopStorageSet.hpp"
  48 #include "gc/shared/plab.hpp"
  49 #include "gc/shared/stringdedup/stringDedup.hpp"
  50 #include "gc/shared/tlab_globals.hpp"
  51 #include "logging/log.hpp"
  52 #include "logging/logStream.hpp"
  53 #include "memory/metadataFactory.hpp"
  54 #include "memory/metaspaceClosure.hpp"
  55 #include "memory/metaspaceCounters.hpp"
  56 #include "memory/metaspaceUtils.hpp"
  57 #include "memory/oopFactory.hpp"
  58 #include "memory/resourceArea.hpp"
  59 #include "memory/universe.hpp"
  60 #include "oops/compressedOops.hpp"
  61 #include "oops/instanceKlass.hpp"
  62 #include "oops/instanceMirrorKlass.hpp"
  63 #include "oops/klass.inline.hpp"
  64 #include "oops/objArrayOop.inline.hpp"
  65 #include "oops/oop.inline.hpp"
  66 #include "oops/oopHandle.inline.hpp"

  67 #include "oops/typeArrayKlass.hpp"
  68 #include "prims/resolvedMethodTable.hpp"
  69 #include "runtime/arguments.hpp"
  70 #include "runtime/atomic.hpp"
  71 #include "runtime/cpuTimeCounters.hpp"
  72 #include "runtime/flags/jvmFlagLimit.hpp"
  73 #include "runtime/handles.inline.hpp"
  74 #include "runtime/init.hpp"
  75 #include "runtime/java.hpp"
  76 #include "runtime/javaThread.hpp"
  77 #include "runtime/jniHandles.hpp"
  78 #include "runtime/threads.hpp"
  79 #include "runtime/timerTrace.hpp"
  80 #include "sanitizers/leak.hpp"
  81 #include "services/memoryService.hpp"
  82 #include "utilities/align.hpp"
  83 #include "utilities/autoRestore.hpp"
  84 #include "utilities/debug.hpp"
  85 #include "utilities/formatBuffer.hpp"
  86 #include "utilities/macros.hpp"
  87 #include "utilities/ostream.hpp"
  88 #include "utilities/preserveException.hpp"
  89 
  90 // Known objects
  91 Klass* Universe::_typeArrayKlassObjs[T_LONG+1]        = { nullptr /*, nullptr...*/ };
  92 Klass* Universe::_objectArrayKlassObj                 = nullptr;
  93 Klass* Universe::_fillerArrayKlassObj                 = nullptr;
  94 OopHandle Universe::_basic_type_mirrors[T_VOID+1];
  95 #if INCLUDE_CDS_JAVA_HEAP
  96 int Universe::_archived_basic_type_mirror_indices[T_VOID+1];







  97 #endif
  98 
  99 OopHandle Universe::_main_thread_group;
 100 OopHandle Universe::_system_thread_group;
 101 OopHandle Universe::_the_empty_class_array;
 102 OopHandle Universe::_the_null_string;
 103 OopHandle Universe::_the_min_jint_string;
 104 
 105 OopHandle Universe::_the_null_sentinel;
 106 
 107 // _out_of_memory_errors is an objArray
 108 enum OutOfMemoryInstance { _oom_java_heap,
 109                            _oom_c_heap,
 110                            _oom_metaspace,
 111                            _oom_class_metaspace,
 112                            _oom_array_size,
 113                            _oom_gc_overhead_limit,
 114                            _oom_realloc_objects,
 115                            _oom_retry,
 116                            _oom_count };
 117 
 118 OopHandle Universe::_out_of_memory_errors;
 119 OopHandle Universe:: _class_init_stack_overflow_error;
 120 OopHandle Universe::_delayed_stack_overflow_error_message;
 121 OopHandle Universe::_preallocated_out_of_memory_error_array;
 122 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
 123 
 124 // Message details for OOME objects, preallocate these objects since they could be
 125 // used when throwing OOME, we should try to avoid further allocation in such case
 126 OopHandle Universe::_msg_metaspace;
 127 OopHandle Universe::_msg_class_metaspace;
 128 
 129 OopHandle Universe::_null_ptr_exception_instance;
 130 OopHandle Universe::_arithmetic_exception_instance;
 131 OopHandle Universe::_virtual_machine_error_instance;
 132 




 133 OopHandle Universe::_reference_pending_list;
 134 
 135 Array<Klass*>* Universe::_the_array_interfaces_array = nullptr;
 136 LatestMethodCache* Universe::_finalizer_register_cache = nullptr;
 137 LatestMethodCache* Universe::_loader_addClass_cache    = nullptr;
 138 LatestMethodCache* Universe::_throw_illegal_access_error_cache = nullptr;
 139 LatestMethodCache* Universe::_throw_no_such_method_error_cache = nullptr;
 140 LatestMethodCache* Universe::_do_stack_walk_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;)

 168 
 169 CollectedHeap*  Universe::_collectedHeap = nullptr;
 170 
 171 objArrayOop Universe::the_empty_class_array ()  {
 172   return (objArrayOop)_the_empty_class_array.resolve();
 173 }
 174 
 175 oop Universe::main_thread_group()                 { return _main_thread_group.resolve(); }
 176 void Universe::set_main_thread_group(oop group)   { _main_thread_group = OopHandle(vm_global(), group); }
 177 
 178 oop Universe::system_thread_group()               { return _system_thread_group.resolve(); }
 179 void Universe::set_system_thread_group(oop group) { _system_thread_group = OopHandle(vm_global(), group); }
 180 
 181 oop Universe::the_null_string()                   { return _the_null_string.resolve(); }
 182 oop Universe::the_min_jint_string()               { return _the_min_jint_string.resolve(); }
 183 
 184 oop Universe::null_ptr_exception_instance()       { return _null_ptr_exception_instance.resolve(); }
 185 oop Universe::arithmetic_exception_instance()     { return _arithmetic_exception_instance.resolve(); }
 186 oop Universe::virtual_machine_error_instance()    { return _virtual_machine_error_instance.resolve(); }
 187 




 188 oop Universe::the_null_sentinel()                 { return _the_null_sentinel.resolve(); }
 189 
 190 oop Universe::int_mirror()                        { return check_mirror(_basic_type_mirrors[T_INT].resolve()); }
 191 oop Universe::float_mirror()                      { return check_mirror(_basic_type_mirrors[T_FLOAT].resolve()); }
 192 oop Universe::double_mirror()                     { return check_mirror(_basic_type_mirrors[T_DOUBLE].resolve()); }
 193 oop Universe::byte_mirror()                       { return check_mirror(_basic_type_mirrors[T_BYTE].resolve()); }
 194 oop Universe::bool_mirror()                       { return check_mirror(_basic_type_mirrors[T_BOOLEAN].resolve()); }
 195 oop Universe::char_mirror()                       { return check_mirror(_basic_type_mirrors[T_CHAR].resolve()); }
 196 oop Universe::long_mirror()                       { return check_mirror(_basic_type_mirrors[T_LONG].resolve()); }
 197 oop Universe::short_mirror()                      { return check_mirror(_basic_type_mirrors[T_SHORT].resolve()); }
 198 oop Universe::void_mirror()                       { return check_mirror(_basic_type_mirrors[T_VOID].resolve()); }
 199 
 200 oop Universe::java_mirror(BasicType t) {
 201   assert((uint)t < T_VOID+1, "range check");
 202   assert(!is_reference_type(t), "sanity");
 203   return check_mirror(_basic_type_mirrors[t].resolve());
 204 }
 205 
 206 void Universe::basic_type_classes_do(KlassClosure *closure) {
 207   for (int i = T_BOOLEAN; i < T_LONG+1; i++) {

 241 
 242 #if INCLUDE_CDS_JAVA_HEAP
 243 void Universe::set_archived_basic_type_mirror_index(BasicType t, int index) {
 244   assert(CDSConfig::is_dumping_heap(), "sanity");
 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::is_in_use()) {
 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 != nullptr, "must be");
 256         _basic_type_mirrors[i] = OopHandle(vm_global(), mirror_oop);
 257       }
 258     }
 259   }
 260 }



































 261 #endif
 262 
 263 void Universe::serialize(SerializeClosure* f) {
 264 
 265 #if INCLUDE_CDS_JAVA_HEAP
 266   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 267     f->do_int(&_archived_basic_type_mirror_indices[i]);
 268     // if f->reading(): We can't call HeapShared::get_root() yet, as the heap
 269     // contents may need to be relocated. _basic_type_mirrors[i] will be
 270     // updated later in Universe::update_archived_basic_type_mirrors().
 271   }






 272 #endif
 273 
 274   f->do_ptr(&_fillerArrayKlassObj);
 275   for (int i = 0; i < T_LONG+1; i++) {
 276     f->do_ptr(&_typeArrayKlassObjs[i]);
 277   }
 278 
 279   f->do_ptr(&_objectArrayKlassObj);
 280   f->do_ptr(&_the_array_interfaces_array);
 281   f->do_ptr(&_the_empty_int_array);
 282   f->do_ptr(&_the_empty_short_array);
 283   f->do_ptr(&_the_empty_method_array);
 284   f->do_ptr(&_the_empty_klass_array);
 285   f->do_ptr(&_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 }

 439     objArrayOop    naked_array = oopFactory::new_objArray(vmClasses::Object_klass(), size, CHECK);
 440     objArrayHandle dummy_array(THREAD, naked_array);
 441     int i = 0;
 442     while (i < size) {
 443         // Allocate dummy in old generation
 444       oop dummy = vmClasses::Object_klass()->allocate_instance(CHECK);
 445       dummy_array->obj_at_put(i++, dummy);
 446     }
 447     {
 448       // Only modify the global variable inside the mutex.
 449       // If we had a race to here, the other dummy_array instances
 450       // and their elements just get dropped on the floor, which is fine.
 451       MutexLocker ml(THREAD, FullGCALot_lock);
 452       if (_fullgc_alot_dummy_array.is_empty()) {
 453         _fullgc_alot_dummy_array = OopHandle(vm_global(), dummy_array());
 454       }
 455     }
 456     assert(i == ((objArrayOop)_fullgc_alot_dummy_array.resolve())->length(), "just checking");
 457   }
 458   #endif




 459 }
 460 
 461 void Universe::initialize_basic_type_mirrors(TRAPS) {
 462 #if INCLUDE_CDS_JAVA_HEAP
 463     if (UseSharedSpaces &&
 464         ArchiveHeapLoader::is_in_use() &&
 465         _basic_type_mirrors[T_INT].resolve() != nullptr) {
 466       assert(ArchiveHeapLoader::can_use(), "Sanity");
 467 
 468       // check that all basic type mirrors are mapped also
 469       for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 470         if (!is_reference_type((BasicType)i)) {
 471           oop m = _basic_type_mirrors[i].resolve();
 472           assert(m != nullptr, "archived mirrors should not be null");
 473         }
 474       }
 475     } else
 476       // _basic_type_mirrors[T_INT], etc, are null if archived heap is not mapped.
 477 #endif
 478     {

 992   if (!UseSharedSpaces) {
 993     reinitialize_vtables();
 994     reinitialize_itables();
 995   }
 996 
 997   HandleMark hm(THREAD);
 998   // Setup preallocated empty java.lang.Class array for Method reflection.
 999 
1000   objArrayOop the_empty_class_array = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_false);
1001   Universe::_the_empty_class_array = OopHandle(Universe::vm_global(), the_empty_class_array);
1002 
1003   // Setup preallocated OutOfMemoryError errors
1004   Universe::create_preallocated_out_of_memory_errors(CHECK_false);
1005 
1006   oop instance;
1007   // Setup preallocated cause message for delayed StackOverflowError
1008   if (StackReservedPages > 0) {
1009     instance = java_lang_String::create_oop_from_str("Delayed StackOverflowError due to ReservedStackAccess annotated method", CHECK_false);
1010     Universe::_delayed_stack_overflow_error_message = OopHandle(Universe::vm_global(), instance);
1011   }
1012 
1013   // Setup preallocated NullPointerException
1014   // (this is currently used for a cheap & dirty solution in compiler exception handling)
1015   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_NullPointerException(), true, CHECK_false);
1016   instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
1017   Universe::_null_ptr_exception_instance = OopHandle(Universe::vm_global(), instance);
1018 
1019   // Setup preallocated ArithmeticException
1020   // (this is currently used for a cheap & dirty solution in compiler exception handling)
1021   k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ArithmeticException(), true, CHECK_false);
1022   instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
1023   Universe::_arithmetic_exception_instance = OopHandle(Universe::vm_global(), instance);










1024 
1025   // Virtual Machine Error for when we get into a situation we can't resolve
1026   k = vmClasses::VirtualMachineError_klass();
1027   bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false);
1028   if (!linked) {
1029      tty->print_cr("Unable to link/verify VirtualMachineError class");
1030      return false; // initialization failed
1031   }
1032   instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
1033   Universe::_virtual_machine_error_instance = OopHandle(Universe::vm_global(), instance);
1034 

1035   Handle msg = java_lang_String::create_from_str("/ by zero", CHECK_false);
1036   java_lang_Throwable::set_message(Universe::arithmetic_exception_instance(), msg());
1037 
1038   // Setup preallocated StackOverflowError for use with class initialization failure
1039   k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_StackOverflowError(), true, CHECK_false);
1040   instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
1041   Universe::_class_init_stack_overflow_error = OopHandle(Universe::vm_global(), instance);
1042 
1043   Universe::initialize_known_methods(CHECK_false);
1044 
1045   // This needs to be done before the first scavenge/gc, since
1046   // it's an input to soft ref clearing policy.
1047   {
1048     MutexLocker x(THREAD, Heap_lock);
1049     Universe::heap()->update_capacity_and_used_at_gc();
1050   }
1051 
1052   // ("weak") refs processing infrastructure initialization
1053   Universe::heap()->post_initialize();
1054 

  47 #include "gc/shared/oopStorageSet.hpp"
  48 #include "gc/shared/plab.hpp"
  49 #include "gc/shared/stringdedup/stringDedup.hpp"
  50 #include "gc/shared/tlab_globals.hpp"
  51 #include "logging/log.hpp"
  52 #include "logging/logStream.hpp"
  53 #include "memory/metadataFactory.hpp"
  54 #include "memory/metaspaceClosure.hpp"
  55 #include "memory/metaspaceCounters.hpp"
  56 #include "memory/metaspaceUtils.hpp"
  57 #include "memory/oopFactory.hpp"
  58 #include "memory/resourceArea.hpp"
  59 #include "memory/universe.hpp"
  60 #include "oops/compressedOops.hpp"
  61 #include "oops/instanceKlass.hpp"
  62 #include "oops/instanceMirrorKlass.hpp"
  63 #include "oops/klass.inline.hpp"
  64 #include "oops/objArrayOop.inline.hpp"
  65 #include "oops/oop.inline.hpp"
  66 #include "oops/oopHandle.inline.hpp"
  67 #include "oops/trainingData.hpp"
  68 #include "oops/typeArrayKlass.hpp"
  69 #include "prims/resolvedMethodTable.hpp"
  70 #include "runtime/arguments.hpp"
  71 #include "runtime/atomic.hpp"
  72 #include "runtime/cpuTimeCounters.hpp"
  73 #include "runtime/flags/jvmFlagLimit.hpp"
  74 #include "runtime/handles.inline.hpp"
  75 #include "runtime/init.hpp"
  76 #include "runtime/java.hpp"
  77 #include "runtime/javaThread.hpp"
  78 #include "runtime/jniHandles.hpp"
  79 #include "runtime/threads.hpp"
  80 #include "runtime/timerTrace.hpp"
  81 #include "sanitizers/leak.hpp"
  82 #include "services/memoryService.hpp"
  83 #include "utilities/align.hpp"
  84 #include "utilities/autoRestore.hpp"
  85 #include "utilities/debug.hpp"
  86 #include "utilities/formatBuffer.hpp"
  87 #include "utilities/macros.hpp"
  88 #include "utilities/ostream.hpp"
  89 #include "utilities/preserveException.hpp"
  90 
  91 // Known objects
  92 Klass* Universe::_typeArrayKlassObjs[T_LONG+1]        = { nullptr /*, nullptr...*/ };
  93 Klass* Universe::_objectArrayKlassObj                 = nullptr;
  94 Klass* Universe::_fillerArrayKlassObj                 = nullptr;
  95 OopHandle Universe::_basic_type_mirrors[T_VOID+1];
  96 #if INCLUDE_CDS_JAVA_HEAP
  97 int Universe::_archived_basic_type_mirror_indices[T_VOID+1];
  98 
  99 int Universe::_archived_null_ptr_exception_instance_index = -1;
 100 int Universe::_archived_arithmetic_exception_instance_index = -1;
 101 int Universe::_archived_virtual_machine_error_instance_index = -1;
 102 int Universe::_archived_array_index_oob_exception_instance_index = -1;
 103 int Universe::_archived_array_store_exception_instance_index = -1;
 104 int Universe::_archived_class_cast_exception_instance_index = -1;
 105 #endif
 106 
 107 OopHandle Universe::_main_thread_group;
 108 OopHandle Universe::_system_thread_group;
 109 OopHandle Universe::_the_empty_class_array;
 110 OopHandle Universe::_the_null_string;
 111 OopHandle Universe::_the_min_jint_string;
 112 
 113 OopHandle Universe::_the_null_sentinel;
 114 
 115 // _out_of_memory_errors is an objArray
 116 enum OutOfMemoryInstance { _oom_java_heap,
 117                            _oom_c_heap,
 118                            _oom_metaspace,
 119                            _oom_class_metaspace,
 120                            _oom_array_size,
 121                            _oom_gc_overhead_limit,
 122                            _oom_realloc_objects,
 123                            _oom_retry,
 124                            _oom_count };
 125 
 126 OopHandle Universe::_out_of_memory_errors;
 127 OopHandle Universe:: _class_init_stack_overflow_error;
 128 OopHandle Universe::_delayed_stack_overflow_error_message;
 129 OopHandle Universe::_preallocated_out_of_memory_error_array;
 130 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
 131 
 132 // Message details for OOME objects, preallocate these objects since they could be
 133 // used when throwing OOME, we should try to avoid further allocation in such case
 134 OopHandle Universe::_msg_metaspace;
 135 OopHandle Universe::_msg_class_metaspace;
 136 
 137 OopHandle Universe::_null_ptr_exception_instance;
 138 OopHandle Universe::_arithmetic_exception_instance;
 139 OopHandle Universe::_virtual_machine_error_instance;
 140 
 141 OopHandle Universe::_array_index_oob_exception_instance;
 142 OopHandle Universe::_array_store_exception_instance;
 143 OopHandle Universe::_class_cast_exception_instance;
 144 
 145 OopHandle Universe::_reference_pending_list;
 146 
 147 Array<Klass*>* Universe::_the_array_interfaces_array = nullptr;
 148 LatestMethodCache* Universe::_finalizer_register_cache = nullptr;
 149 LatestMethodCache* Universe::_loader_addClass_cache    = nullptr;
 150 LatestMethodCache* Universe::_throw_illegal_access_error_cache = nullptr;
 151 LatestMethodCache* Universe::_throw_no_such_method_error_cache = nullptr;
 152 LatestMethodCache* Universe::_do_stack_walk_cache     = nullptr;
 153 
 154 long Universe::verify_flags                           = Universe::Verify_All;
 155 
 156 Array<int>* Universe::_the_empty_int_array            = nullptr;
 157 Array<u2>* Universe::_the_empty_short_array           = nullptr;
 158 Array<Klass*>* Universe::_the_empty_klass_array     = nullptr;
 159 Array<InstanceKlass*>* Universe::_the_empty_instance_klass_array  = nullptr;
 160 Array<Method*>* Universe::_the_empty_method_array   = nullptr;
 161 
 162 // These variables are guarded by FullGCALot_lock.
 163 debug_only(OopHandle Universe::_fullgc_alot_dummy_array;)
 164 debug_only(int Universe::_fullgc_alot_dummy_next = 0;)

 180 
 181 CollectedHeap*  Universe::_collectedHeap = nullptr;
 182 
 183 objArrayOop Universe::the_empty_class_array ()  {
 184   return (objArrayOop)_the_empty_class_array.resolve();
 185 }
 186 
 187 oop Universe::main_thread_group()                 { return _main_thread_group.resolve(); }
 188 void Universe::set_main_thread_group(oop group)   { _main_thread_group = OopHandle(vm_global(), group); }
 189 
 190 oop Universe::system_thread_group()               { return _system_thread_group.resolve(); }
 191 void Universe::set_system_thread_group(oop group) { _system_thread_group = OopHandle(vm_global(), group); }
 192 
 193 oop Universe::the_null_string()                   { return _the_null_string.resolve(); }
 194 oop Universe::the_min_jint_string()               { return _the_min_jint_string.resolve(); }
 195 
 196 oop Universe::null_ptr_exception_instance()       { return _null_ptr_exception_instance.resolve(); }
 197 oop Universe::arithmetic_exception_instance()     { return _arithmetic_exception_instance.resolve(); }
 198 oop Universe::virtual_machine_error_instance()    { return _virtual_machine_error_instance.resolve(); }
 199 
 200 oop Universe::array_index_oob_exception_instance() { return _array_index_oob_exception_instance.resolve(); }
 201 oop Universe::array_store_exception_instance()     { return _array_store_exception_instance.resolve(); }
 202 oop Universe::class_cast_exception_instance()      { return _class_cast_exception_instance.resolve(); }
 203 
 204 oop Universe::the_null_sentinel()                 { return _the_null_sentinel.resolve(); }
 205 
 206 oop Universe::int_mirror()                        { return check_mirror(_basic_type_mirrors[T_INT].resolve()); }
 207 oop Universe::float_mirror()                      { return check_mirror(_basic_type_mirrors[T_FLOAT].resolve()); }
 208 oop Universe::double_mirror()                     { return check_mirror(_basic_type_mirrors[T_DOUBLE].resolve()); }
 209 oop Universe::byte_mirror()                       { return check_mirror(_basic_type_mirrors[T_BYTE].resolve()); }
 210 oop Universe::bool_mirror()                       { return check_mirror(_basic_type_mirrors[T_BOOLEAN].resolve()); }
 211 oop Universe::char_mirror()                       { return check_mirror(_basic_type_mirrors[T_CHAR].resolve()); }
 212 oop Universe::long_mirror()                       { return check_mirror(_basic_type_mirrors[T_LONG].resolve()); }
 213 oop Universe::short_mirror()                      { return check_mirror(_basic_type_mirrors[T_SHORT].resolve()); }
 214 oop Universe::void_mirror()                       { return check_mirror(_basic_type_mirrors[T_VOID].resolve()); }
 215 
 216 oop Universe::java_mirror(BasicType t) {
 217   assert((uint)t < T_VOID+1, "range check");
 218   assert(!is_reference_type(t), "sanity");
 219   return check_mirror(_basic_type_mirrors[t].resolve());
 220 }
 221 
 222 void Universe::basic_type_classes_do(KlassClosure *closure) {
 223   for (int i = T_BOOLEAN; i < T_LONG+1; i++) {

 257 
 258 #if INCLUDE_CDS_JAVA_HEAP
 259 void Universe::set_archived_basic_type_mirror_index(BasicType t, int index) {
 260   assert(CDSConfig::is_dumping_heap(), "sanity");
 261   assert(!is_reference_type(t), "sanity");
 262   _archived_basic_type_mirror_indices[t] = index;
 263 }
 264 
 265 void Universe::update_archived_basic_type_mirrors() {
 266   if (ArchiveHeapLoader::is_in_use()) {
 267     for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 268       int index = _archived_basic_type_mirror_indices[i];
 269       if (!is_reference_type((BasicType)i) && index >= 0) {
 270         oop mirror_oop = HeapShared::get_root(index);
 271         assert(mirror_oop != nullptr, "must be");
 272         _basic_type_mirrors[i] = OopHandle(vm_global(), mirror_oop);
 273       }
 274     }
 275   }
 276 }
 277 
 278 void Universe::update_exception_instances() {
 279   if (ArchiveHeapLoader::is_in_use()) {
 280     if (_archived_null_ptr_exception_instance_index >= 0) {
 281       oop mirror_oop = HeapShared::get_root(_archived_null_ptr_exception_instance_index);
 282       assert(mirror_oop != nullptr, "must be");
 283       _null_ptr_exception_instance = OopHandle(vm_global(), mirror_oop);
 284     }
 285     if (_archived_arithmetic_exception_instance_index >= 0) {
 286       oop mirror_oop = HeapShared::get_root(_archived_arithmetic_exception_instance_index);
 287       assert(mirror_oop != nullptr, "must be");
 288       _arithmetic_exception_instance = OopHandle(vm_global(), mirror_oop);
 289     }
 290     if (_archived_virtual_machine_error_instance_index >= 0) {
 291       oop mirror_oop = HeapShared::get_root(_archived_virtual_machine_error_instance_index);
 292       assert(mirror_oop != nullptr, "must be");
 293       _virtual_machine_error_instance = OopHandle(vm_global(), mirror_oop);
 294     }
 295     if (_archived_array_index_oob_exception_instance_index >= 0) {
 296       oop mirror_oop = HeapShared::get_root(_archived_array_index_oob_exception_instance_index);
 297       assert(mirror_oop != nullptr, "must be");
 298       _array_index_oob_exception_instance = OopHandle(vm_global(), mirror_oop);
 299     }
 300     if (_archived_array_store_exception_instance_index >= 0) {
 301       oop mirror_oop = HeapShared::get_root(_archived_array_store_exception_instance_index);
 302       assert(mirror_oop != nullptr, "must be");
 303       _array_store_exception_instance = OopHandle(vm_global(), mirror_oop);
 304     }
 305     if (_archived_class_cast_exception_instance_index >= 0) {
 306       oop mirror_oop = HeapShared::get_root(_archived_class_cast_exception_instance_index);
 307       assert(mirror_oop != nullptr, "must be");
 308       _class_cast_exception_instance = OopHandle(vm_global(), mirror_oop);
 309     }
 310   }
 311 }
 312 #endif
 313 
 314 void Universe::serialize(SerializeClosure* f) {
 315 
 316 #if INCLUDE_CDS_JAVA_HEAP
 317   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 318     f->do_int(&_archived_basic_type_mirror_indices[i]);
 319     // if f->reading(): We can't call HeapShared::get_root() yet, as the heap
 320     // contents may need to be relocated. _basic_type_mirrors[i] will be
 321     // updated later in Universe::update_archived_basic_type_mirrors().
 322   }
 323   f->do_int(&_archived_null_ptr_exception_instance_index);
 324   f->do_int(&_archived_arithmetic_exception_instance_index);
 325   f->do_int(&_archived_virtual_machine_error_instance_index);
 326   f->do_int(&_archived_array_index_oob_exception_instance_index);
 327   f->do_int(&_archived_array_store_exception_instance_index);
 328   f->do_int(&_archived_class_cast_exception_instance_index);
 329 #endif
 330 
 331   f->do_ptr(&_fillerArrayKlassObj);
 332   for (int i = 0; i < T_LONG+1; i++) {
 333     f->do_ptr(&_typeArrayKlassObjs[i]);
 334   }
 335 
 336   f->do_ptr(&_objectArrayKlassObj);
 337   f->do_ptr(&_the_array_interfaces_array);
 338   f->do_ptr(&_the_empty_int_array);
 339   f->do_ptr(&_the_empty_short_array);
 340   f->do_ptr(&_the_empty_method_array);
 341   f->do_ptr(&_the_empty_klass_array);
 342   f->do_ptr(&_the_empty_instance_klass_array);
 343   _finalizer_register_cache->serialize(f);
 344   _loader_addClass_cache->serialize(f);
 345   _throw_illegal_access_error_cache->serialize(f);
 346   _throw_no_such_method_error_cache->serialize(f);
 347   _do_stack_walk_cache->serialize(f);
 348 }

 496     objArrayOop    naked_array = oopFactory::new_objArray(vmClasses::Object_klass(), size, CHECK);
 497     objArrayHandle dummy_array(THREAD, naked_array);
 498     int i = 0;
 499     while (i < size) {
 500         // Allocate dummy in old generation
 501       oop dummy = vmClasses::Object_klass()->allocate_instance(CHECK);
 502       dummy_array->obj_at_put(i++, dummy);
 503     }
 504     {
 505       // Only modify the global variable inside the mutex.
 506       // If we had a race to here, the other dummy_array instances
 507       // and their elements just get dropped on the floor, which is fine.
 508       MutexLocker ml(THREAD, FullGCALot_lock);
 509       if (_fullgc_alot_dummy_array.is_empty()) {
 510         _fullgc_alot_dummy_array = OopHandle(vm_global(), dummy_array());
 511       }
 512     }
 513     assert(i == ((objArrayOop)_fullgc_alot_dummy_array.resolve())->length(), "just checking");
 514   }
 515   #endif
 516 
 517 #if INCLUDE_CDS
 518   TrainingData::restore_all_unshareable_info(CHECK);
 519 #endif
 520 }
 521 
 522 void Universe::initialize_basic_type_mirrors(TRAPS) {
 523 #if INCLUDE_CDS_JAVA_HEAP
 524     if (UseSharedSpaces &&
 525         ArchiveHeapLoader::is_in_use() &&
 526         _basic_type_mirrors[T_INT].resolve() != nullptr) {
 527       assert(ArchiveHeapLoader::can_use(), "Sanity");
 528 
 529       // check that all basic type mirrors are mapped also
 530       for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 531         if (!is_reference_type((BasicType)i)) {
 532           oop m = _basic_type_mirrors[i].resolve();
 533           assert(m != nullptr, "archived mirrors should not be null");
 534         }
 535       }
 536     } else
 537       // _basic_type_mirrors[T_INT], etc, are null if archived heap is not mapped.
 538 #endif
 539     {

1053   if (!UseSharedSpaces) {
1054     reinitialize_vtables();
1055     reinitialize_itables();
1056   }
1057 
1058   HandleMark hm(THREAD);
1059   // Setup preallocated empty java.lang.Class array for Method reflection.
1060 
1061   objArrayOop the_empty_class_array = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_false);
1062   Universe::_the_empty_class_array = OopHandle(Universe::vm_global(), the_empty_class_array);
1063 
1064   // Setup preallocated OutOfMemoryError errors
1065   Universe::create_preallocated_out_of_memory_errors(CHECK_false);
1066 
1067   oop instance;
1068   // Setup preallocated cause message for delayed StackOverflowError
1069   if (StackReservedPages > 0) {
1070     instance = java_lang_String::create_oop_from_str("Delayed StackOverflowError due to ReservedStackAccess annotated method", CHECK_false);
1071     Universe::_delayed_stack_overflow_error_message = OopHandle(Universe::vm_global(), instance);
1072   }
1073   if (Universe::_null_ptr_exception_instance.is_empty()) {
1074     instance = java_lang_Throwable::create_exception_instance(vmSymbols::java_lang_NullPointerException(), CHECK_false);
1075     Universe::_null_ptr_exception_instance = OopHandle(Universe::vm_global(), instance);
1076   }
1077   if (Universe::_arithmetic_exception_instance.is_empty()) {
1078     instance = java_lang_Throwable::create_exception_instance(vmSymbols::java_lang_ArithmeticException(), CHECK_false);
1079     Universe::_arithmetic_exception_instance = OopHandle(Universe::vm_global(), instance);
1080   }
1081 //#ifdef COMPILER1_OR_COMPILER2_PRESENT
1082   if (Universe::_array_index_oob_exception_instance.is_empty()) {
1083     instance = java_lang_Throwable::create_exception_instance(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), CHECK_false);
1084     Universe::_array_index_oob_exception_instance = OopHandle(Universe::vm_global(), instance);
1085   }
1086   if (Universe::_array_store_exception_instance.is_empty()) {
1087     instance = java_lang_Throwable::create_exception_instance(vmSymbols::java_lang_ArrayStoreException(), CHECK_false);
1088     Universe::_array_store_exception_instance = OopHandle(Universe::vm_global(), instance);
1089   }
1090   if (Universe::_class_cast_exception_instance.is_empty()) {
1091     instance = java_lang_Throwable::create_exception_instance(vmSymbols::java_lang_ClassCastException(), CHECK_false);
1092     Universe::_class_cast_exception_instance = OopHandle(Universe::vm_global(), instance);
1093   }
1094 //#endif // COMPILER1_OR_COMPILER2_PRESENT
1095 
1096   // Virtual Machine Error for when we get into a situation we can't resolve
1097   Klass* k = vmClasses::VirtualMachineError_klass();
1098   bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false);
1099   if (!linked) {
1100      tty->print_cr("Unable to link/verify VirtualMachineError class");
1101      return false; // initialization failed
1102   }
1103   if (Universe::_virtual_machine_error_instance.is_empty()) {
1104     instance = java_lang_Throwable::create_exception_instance(vmSymbols::java_lang_VirtualMachineError(), CHECK_false);
1105     Universe::_virtual_machine_error_instance = OopHandle(Universe::vm_global(), instance);
1106   }
1107   Handle msg = java_lang_String::create_from_str("/ by zero", CHECK_false);
1108   java_lang_Throwable::set_message(Universe::arithmetic_exception_instance(), msg());
1109 
1110   // Setup preallocated StackOverflowError for use with class initialization failure
1111   k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_StackOverflowError(), true, CHECK_false);
1112   instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
1113   Universe::_class_init_stack_overflow_error = OopHandle(Universe::vm_global(), instance);
1114 
1115   Universe::initialize_known_methods(CHECK_false);
1116 
1117   // This needs to be done before the first scavenge/gc, since
1118   // it's an input to soft ref clearing policy.
1119   {
1120     MutexLocker x(THREAD, Heap_lock);
1121     Universe::heap()->update_capacity_and_used_at_gc();
1122   }
1123 
1124   // ("weak") refs processing infrastructure initialization
1125   Universe::heap()->post_initialize();
1126 
< prev index next >