< prev index next >

src/hotspot/share/memory/universe.cpp

Print this page

 216   void load_from_cds() {
 217     if (_archived_root_index >= 0) {
 218       oop obj = HeapShared::get_root(_archived_root_index);
 219       assert(obj != nullptr, "must be");
 220       _instance = OopHandle(Universe::vm_global(), obj);
 221     }
 222   }
 223 
 224   void serialize(SerializeClosure *f) {
 225     f->do_int(&_archived_root_index);
 226   }
 227 #endif
 228 };
 229 
 230 static BuiltinException _null_ptr_exception;
 231 static BuiltinException _arithmetic_exception;
 232 static BuiltinException _internal_error;
 233 static BuiltinException _array_index_out_of_bounds_exception;
 234 static BuiltinException _array_store_exception;
 235 static BuiltinException _class_cast_exception;

 236 
 237 objArrayOop Universe::the_empty_class_array ()  {
 238   return (objArrayOop)_the_empty_class_array.resolve();
 239 }
 240 
 241 oop Universe::main_thread_group()                 { return _main_thread_group.resolve(); }
 242 void Universe::set_main_thread_group(oop group)   { _main_thread_group = OopHandle(vm_global(), group); }
 243 
 244 oop Universe::system_thread_group()               { return _system_thread_group.resolve(); }
 245 void Universe::set_system_thread_group(oop group) { _system_thread_group = OopHandle(vm_global(), group); }
 246 
 247 oop Universe::the_null_string()                   { return _the_null_string.resolve(); }
 248 oop Universe::the_min_jint_string()               { return _the_min_jint_string.resolve(); }
 249 
 250 oop Universe::null_ptr_exception_instance()       { return _null_ptr_exception.instance(); }
 251 oop Universe::arithmetic_exception_instance()     { return _arithmetic_exception.instance(); }
 252 oop Universe::internal_error_instance()           { return _internal_error.instance(); }
 253 oop Universe::array_index_out_of_bounds_exception_instance() { return _array_index_out_of_bounds_exception.instance(); }
 254 oop Universe::array_store_exception_instance()    { return _array_store_exception.instance(); }
 255 oop Universe::class_cast_exception_instance()     { return _class_cast_exception.instance(); }

 256 
 257 oop Universe::the_null_sentinel()                 { return _the_null_sentinel.resolve(); }
 258 
 259 oop Universe::int_mirror()                        { return check_mirror(_basic_type_mirrors[T_INT].resolve()); }
 260 oop Universe::float_mirror()                      { return check_mirror(_basic_type_mirrors[T_FLOAT].resolve()); }
 261 oop Universe::double_mirror()                     { return check_mirror(_basic_type_mirrors[T_DOUBLE].resolve()); }
 262 oop Universe::byte_mirror()                       { return check_mirror(_basic_type_mirrors[T_BYTE].resolve()); }
 263 oop Universe::bool_mirror()                       { return check_mirror(_basic_type_mirrors[T_BOOLEAN].resolve()); }
 264 oop Universe::char_mirror()                       { return check_mirror(_basic_type_mirrors[T_CHAR].resolve()); }
 265 oop Universe::long_mirror()                       { return check_mirror(_basic_type_mirrors[T_LONG].resolve()); }
 266 oop Universe::short_mirror()                      { return check_mirror(_basic_type_mirrors[T_SHORT].resolve()); }
 267 oop Universe::void_mirror()                       { return check_mirror(_basic_type_mirrors[T_VOID].resolve()); }
 268 
 269 oop Universe::java_mirror(BasicType t) {
 270   assert((uint)t < T_VOID+1, "range check");
 271   assert(!is_reference_type(t), "sanity");
 272   return check_mirror(_basic_type_mirrors[t].resolve());
 273 }
 274 
 275 void Universe::basic_type_classes_do(KlassClosure *closure) {

 295   it->push(&_the_empty_klass_array);
 296   it->push(&_the_empty_instance_klass_array);
 297   it->push(&_the_empty_method_array);
 298   it->push(&_the_array_interfaces_array);
 299 }
 300 
 301 #if INCLUDE_CDS_JAVA_HEAP
 302 void Universe::set_archived_basic_type_mirror_index(BasicType t, int index) {
 303   assert(CDSConfig::is_dumping_heap(), "sanity");
 304   assert(!is_reference_type(t), "sanity");
 305   _archived_basic_type_mirror_indices[t] = index;
 306 }
 307 
 308 void Universe::archive_exception_instances() {
 309   _null_ptr_exception.store_in_cds();
 310   _arithmetic_exception.store_in_cds();
 311   _internal_error.store_in_cds();
 312   _array_index_out_of_bounds_exception.store_in_cds();
 313   _array_store_exception.store_in_cds();
 314   _class_cast_exception.store_in_cds();

 315 }
 316 
 317 void Universe::load_archived_object_instances() {
 318   if (ArchiveHeapLoader::is_in_use()) {
 319     for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 320       int index = _archived_basic_type_mirror_indices[i];
 321       if (!is_reference_type((BasicType)i) && index >= 0) {
 322         oop mirror_oop = HeapShared::get_root(index);
 323         assert(mirror_oop != nullptr, "must be");
 324         _basic_type_mirrors[i] = OopHandle(vm_global(), mirror_oop);
 325       }
 326     }
 327 
 328     _null_ptr_exception.load_from_cds();
 329     _arithmetic_exception.load_from_cds();
 330     _internal_error.load_from_cds();
 331     _array_index_out_of_bounds_exception.load_from_cds();
 332     _array_store_exception.load_from_cds();
 333     _class_cast_exception.load_from_cds();

 334   }
 335 }
 336 #endif
 337 
 338 void Universe::serialize(SerializeClosure* f) {
 339 
 340 #if INCLUDE_CDS_JAVA_HEAP
 341   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 342     f->do_int(&_archived_basic_type_mirror_indices[i]);
 343     // if f->reading(): We can't call HeapShared::get_root() yet, as the heap
 344     // contents may need to be relocated. _basic_type_mirrors[i] will be
 345     // updated later in Universe::load_archived_object_instances().
 346   }
 347   _null_ptr_exception.serialize(f);
 348   _arithmetic_exception.serialize(f);
 349   _internal_error.serialize(f);
 350   _array_index_out_of_bounds_exception.serialize(f);
 351   _array_store_exception.serialize(f);
 352   _class_cast_exception.serialize(f);

 353 #endif
 354 
 355   f->do_ptr(&_fillerArrayKlass);
 356   for (int i = 0; i < T_LONG+1; i++) {
 357     f->do_ptr(&_typeArrayKlasses[i]);
 358   }
 359 
 360   f->do_ptr(&_objectArrayKlass);
 361   f->do_ptr(&_the_array_interfaces_array);
 362   f->do_ptr(&_the_empty_int_array);
 363   f->do_ptr(&_the_empty_short_array);
 364   f->do_ptr(&_the_empty_method_array);
 365   f->do_ptr(&_the_empty_klass_array);
 366   f->do_ptr(&_the_empty_instance_klass_array);
 367 }
 368 
 369 
 370 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
 371   if (size < alignment || size % alignment != 0) {
 372     vm_exit_during_initialization(

1095 
1096   objArrayOop the_empty_class_array = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_false);
1097   Universe::_the_empty_class_array = OopHandle(Universe::vm_global(), the_empty_class_array);
1098 
1099   // Setup preallocated OutOfMemoryError errors
1100   Universe::create_preallocated_out_of_memory_errors(CHECK_false);
1101 
1102   oop instance;
1103   // Setup preallocated cause message for delayed StackOverflowError
1104   if (StackReservedPages > 0) {
1105     instance = java_lang_String::create_oop_from_str("Delayed StackOverflowError due to ReservedStackAccess annotated method", CHECK_false);
1106     Universe::_delayed_stack_overflow_error_message = OopHandle(Universe::vm_global(), instance);
1107   }
1108 
1109   // Setup preallocated exceptions used for a cheap & dirty solution in compiler exception handling
1110   _null_ptr_exception.init_if_empty(vmSymbols::java_lang_NullPointerException(), CHECK_false);
1111   _arithmetic_exception.init_if_empty(vmSymbols::java_lang_ArithmeticException(), CHECK_false);
1112   _array_index_out_of_bounds_exception.init_if_empty(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), CHECK_false);
1113   _array_store_exception.init_if_empty(vmSymbols::java_lang_ArrayStoreException(), CHECK_false);
1114   _class_cast_exception.init_if_empty(vmSymbols::java_lang_ClassCastException(), CHECK_false);

1115 
1116   // Virtual Machine Error for when we get into a situation we can't resolve
1117   Klass* k = vmClasses::InternalError_klass();
1118   bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false);
1119   if (!linked) {
1120      tty->print_cr("Unable to link/verify InternalError class");
1121      return false; // initialization failed
1122   }
1123   _internal_error.init_if_empty(vmSymbols::java_lang_InternalError(), CHECK_false);
1124 
1125   Handle msg = java_lang_String::create_from_str("/ by zero", CHECK_false);
1126   java_lang_Throwable::set_message(Universe::arithmetic_exception_instance(), msg());
1127 
1128   // Setup preallocated StackOverflowError for use with class initialization failure
1129   k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_StackOverflowError(), true, CHECK_false);
1130   instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
1131   Universe::_class_init_stack_overflow_error = OopHandle(Universe::vm_global(), instance);
1132 
1133   Universe::initialize_known_methods(THREAD);
1134 

 216   void load_from_cds() {
 217     if (_archived_root_index >= 0) {
 218       oop obj = HeapShared::get_root(_archived_root_index);
 219       assert(obj != nullptr, "must be");
 220       _instance = OopHandle(Universe::vm_global(), obj);
 221     }
 222   }
 223 
 224   void serialize(SerializeClosure *f) {
 225     f->do_int(&_archived_root_index);
 226   }
 227 #endif
 228 };
 229 
 230 static BuiltinException _null_ptr_exception;
 231 static BuiltinException _arithmetic_exception;
 232 static BuiltinException _internal_error;
 233 static BuiltinException _array_index_out_of_bounds_exception;
 234 static BuiltinException _array_store_exception;
 235 static BuiltinException _class_cast_exception;
 236 static BuiltinException _preempted_exception;
 237 
 238 objArrayOop Universe::the_empty_class_array ()  {
 239   return (objArrayOop)_the_empty_class_array.resolve();
 240 }
 241 
 242 oop Universe::main_thread_group()                 { return _main_thread_group.resolve(); }
 243 void Universe::set_main_thread_group(oop group)   { _main_thread_group = OopHandle(vm_global(), group); }
 244 
 245 oop Universe::system_thread_group()               { return _system_thread_group.resolve(); }
 246 void Universe::set_system_thread_group(oop group) { _system_thread_group = OopHandle(vm_global(), group); }
 247 
 248 oop Universe::the_null_string()                   { return _the_null_string.resolve(); }
 249 oop Universe::the_min_jint_string()               { return _the_min_jint_string.resolve(); }
 250 
 251 oop Universe::null_ptr_exception_instance()       { return _null_ptr_exception.instance(); }
 252 oop Universe::arithmetic_exception_instance()     { return _arithmetic_exception.instance(); }
 253 oop Universe::internal_error_instance()           { return _internal_error.instance(); }
 254 oop Universe::array_index_out_of_bounds_exception_instance() { return _array_index_out_of_bounds_exception.instance(); }
 255 oop Universe::array_store_exception_instance()    { return _array_store_exception.instance(); }
 256 oop Universe::class_cast_exception_instance()     { return _class_cast_exception.instance(); }
 257 oop Universe::preempted_exception_instance()      { return _preempted_exception.instance(); }
 258 
 259 oop Universe::the_null_sentinel()                 { return _the_null_sentinel.resolve(); }
 260 
 261 oop Universe::int_mirror()                        { return check_mirror(_basic_type_mirrors[T_INT].resolve()); }
 262 oop Universe::float_mirror()                      { return check_mirror(_basic_type_mirrors[T_FLOAT].resolve()); }
 263 oop Universe::double_mirror()                     { return check_mirror(_basic_type_mirrors[T_DOUBLE].resolve()); }
 264 oop Universe::byte_mirror()                       { return check_mirror(_basic_type_mirrors[T_BYTE].resolve()); }
 265 oop Universe::bool_mirror()                       { return check_mirror(_basic_type_mirrors[T_BOOLEAN].resolve()); }
 266 oop Universe::char_mirror()                       { return check_mirror(_basic_type_mirrors[T_CHAR].resolve()); }
 267 oop Universe::long_mirror()                       { return check_mirror(_basic_type_mirrors[T_LONG].resolve()); }
 268 oop Universe::short_mirror()                      { return check_mirror(_basic_type_mirrors[T_SHORT].resolve()); }
 269 oop Universe::void_mirror()                       { return check_mirror(_basic_type_mirrors[T_VOID].resolve()); }
 270 
 271 oop Universe::java_mirror(BasicType t) {
 272   assert((uint)t < T_VOID+1, "range check");
 273   assert(!is_reference_type(t), "sanity");
 274   return check_mirror(_basic_type_mirrors[t].resolve());
 275 }
 276 
 277 void Universe::basic_type_classes_do(KlassClosure *closure) {

 297   it->push(&_the_empty_klass_array);
 298   it->push(&_the_empty_instance_klass_array);
 299   it->push(&_the_empty_method_array);
 300   it->push(&_the_array_interfaces_array);
 301 }
 302 
 303 #if INCLUDE_CDS_JAVA_HEAP
 304 void Universe::set_archived_basic_type_mirror_index(BasicType t, int index) {
 305   assert(CDSConfig::is_dumping_heap(), "sanity");
 306   assert(!is_reference_type(t), "sanity");
 307   _archived_basic_type_mirror_indices[t] = index;
 308 }
 309 
 310 void Universe::archive_exception_instances() {
 311   _null_ptr_exception.store_in_cds();
 312   _arithmetic_exception.store_in_cds();
 313   _internal_error.store_in_cds();
 314   _array_index_out_of_bounds_exception.store_in_cds();
 315   _array_store_exception.store_in_cds();
 316   _class_cast_exception.store_in_cds();
 317   _preempted_exception.store_in_cds();
 318 }
 319 
 320 void Universe::load_archived_object_instances() {
 321   if (ArchiveHeapLoader::is_in_use()) {
 322     for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 323       int index = _archived_basic_type_mirror_indices[i];
 324       if (!is_reference_type((BasicType)i) && index >= 0) {
 325         oop mirror_oop = HeapShared::get_root(index);
 326         assert(mirror_oop != nullptr, "must be");
 327         _basic_type_mirrors[i] = OopHandle(vm_global(), mirror_oop);
 328       }
 329     }
 330 
 331     _null_ptr_exception.load_from_cds();
 332     _arithmetic_exception.load_from_cds();
 333     _internal_error.load_from_cds();
 334     _array_index_out_of_bounds_exception.load_from_cds();
 335     _array_store_exception.load_from_cds();
 336     _class_cast_exception.load_from_cds();
 337     _preempted_exception.load_from_cds();
 338   }
 339 }
 340 #endif
 341 
 342 void Universe::serialize(SerializeClosure* f) {
 343 
 344 #if INCLUDE_CDS_JAVA_HEAP
 345   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 346     f->do_int(&_archived_basic_type_mirror_indices[i]);
 347     // if f->reading(): We can't call HeapShared::get_root() yet, as the heap
 348     // contents may need to be relocated. _basic_type_mirrors[i] will be
 349     // updated later in Universe::load_archived_object_instances().
 350   }
 351   _null_ptr_exception.serialize(f);
 352   _arithmetic_exception.serialize(f);
 353   _internal_error.serialize(f);
 354   _array_index_out_of_bounds_exception.serialize(f);
 355   _array_store_exception.serialize(f);
 356   _class_cast_exception.serialize(f);
 357   _preempted_exception.serialize(f);
 358 #endif
 359 
 360   f->do_ptr(&_fillerArrayKlass);
 361   for (int i = 0; i < T_LONG+1; i++) {
 362     f->do_ptr(&_typeArrayKlasses[i]);
 363   }
 364 
 365   f->do_ptr(&_objectArrayKlass);
 366   f->do_ptr(&_the_array_interfaces_array);
 367   f->do_ptr(&_the_empty_int_array);
 368   f->do_ptr(&_the_empty_short_array);
 369   f->do_ptr(&_the_empty_method_array);
 370   f->do_ptr(&_the_empty_klass_array);
 371   f->do_ptr(&_the_empty_instance_klass_array);
 372 }
 373 
 374 
 375 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
 376   if (size < alignment || size % alignment != 0) {
 377     vm_exit_during_initialization(

1100 
1101   objArrayOop the_empty_class_array = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_false);
1102   Universe::_the_empty_class_array = OopHandle(Universe::vm_global(), the_empty_class_array);
1103 
1104   // Setup preallocated OutOfMemoryError errors
1105   Universe::create_preallocated_out_of_memory_errors(CHECK_false);
1106 
1107   oop instance;
1108   // Setup preallocated cause message for delayed StackOverflowError
1109   if (StackReservedPages > 0) {
1110     instance = java_lang_String::create_oop_from_str("Delayed StackOverflowError due to ReservedStackAccess annotated method", CHECK_false);
1111     Universe::_delayed_stack_overflow_error_message = OopHandle(Universe::vm_global(), instance);
1112   }
1113 
1114   // Setup preallocated exceptions used for a cheap & dirty solution in compiler exception handling
1115   _null_ptr_exception.init_if_empty(vmSymbols::java_lang_NullPointerException(), CHECK_false);
1116   _arithmetic_exception.init_if_empty(vmSymbols::java_lang_ArithmeticException(), CHECK_false);
1117   _array_index_out_of_bounds_exception.init_if_empty(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), CHECK_false);
1118   _array_store_exception.init_if_empty(vmSymbols::java_lang_ArrayStoreException(), CHECK_false);
1119   _class_cast_exception.init_if_empty(vmSymbols::java_lang_ClassCastException(), CHECK_false);
1120   _preempted_exception.init_if_empty(vmSymbols::jdk_internal_vm_PreemptedException(), CHECK_false);
1121 
1122   // Virtual Machine Error for when we get into a situation we can't resolve
1123   Klass* k = vmClasses::InternalError_klass();
1124   bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false);
1125   if (!linked) {
1126      tty->print_cr("Unable to link/verify InternalError class");
1127      return false; // initialization failed
1128   }
1129   _internal_error.init_if_empty(vmSymbols::java_lang_InternalError(), CHECK_false);
1130 
1131   Handle msg = java_lang_String::create_from_str("/ by zero", CHECK_false);
1132   java_lang_Throwable::set_message(Universe::arithmetic_exception_instance(), msg());
1133 
1134   // Setup preallocated StackOverflowError for use with class initialization failure
1135   k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_StackOverflowError(), true, CHECK_false);
1136   instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
1137   Universe::_class_init_stack_overflow_error = OopHandle(Universe::vm_global(), instance);
1138 
1139   Universe::initialize_known_methods(THREAD);
1140 
< prev index next >