< 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"

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



 232 
 233 objArrayOop Universe::the_empty_class_array ()  {
 234   return (objArrayOop)_the_empty_class_array.resolve();
 235 }
 236 
 237 oop Universe::main_thread_group()                 { return _main_thread_group.resolve(); }
 238 void Universe::set_main_thread_group(oop group)   { _main_thread_group = OopHandle(vm_global(), group); }
 239 
 240 oop Universe::system_thread_group()               { return _system_thread_group.resolve(); }
 241 void Universe::set_system_thread_group(oop group) { _system_thread_group = OopHandle(vm_global(), group); }
 242 
 243 oop Universe::the_null_string()                   { return _the_null_string.resolve(); }
 244 oop Universe::the_min_jint_string()               { return _the_min_jint_string.resolve(); }
 245 
 246 oop Universe::null_ptr_exception_instance()       { return _null_ptr_exception.instance(); }
 247 oop Universe::arithmetic_exception_instance()     { return _arithmetic_exception.instance(); }
 248 oop Universe::internal_error_instance()           { return _internal_error.instance(); }
 249 




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

 285 
 286   it->push(&_the_empty_int_array);
 287   it->push(&_the_empty_short_array);
 288   it->push(&_the_empty_klass_array);
 289   it->push(&_the_empty_instance_klass_array);
 290   it->push(&_the_empty_method_array);
 291   it->push(&_the_array_interfaces_array);
 292 }
 293 
 294 #if INCLUDE_CDS_JAVA_HEAP
 295 void Universe::set_archived_basic_type_mirror_index(BasicType t, int index) {
 296   assert(CDSConfig::is_dumping_heap(), "sanity");
 297   assert(!is_reference_type(t), "sanity");
 298   _archived_basic_type_mirror_indices[t] = index;
 299 }
 300 
 301 void Universe::archive_exception_instances() {
 302   _null_ptr_exception.store_in_cds();
 303   _arithmetic_exception.store_in_cds();
 304   _internal_error.store_in_cds();



 305 }
 306 
 307 void Universe::load_archived_object_instances() {
 308   if (ArchiveHeapLoader::is_in_use()) {
 309     for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 310       int index = _archived_basic_type_mirror_indices[i];
 311       if (!is_reference_type((BasicType)i) && index >= 0) {
 312         oop mirror_oop = HeapShared::get_root(index);
 313         assert(mirror_oop != nullptr, "must be");
 314         _basic_type_mirrors[i] = OopHandle(vm_global(), mirror_oop);
 315       }
 316     }
 317 
 318     _null_ptr_exception.load_from_cds();
 319     _arithmetic_exception.load_from_cds();
 320     _internal_error.load_from_cds();



 321   }
 322 }
 323 #endif
 324 
 325 void Universe::serialize(SerializeClosure* f) {
 326 
 327 #if INCLUDE_CDS_JAVA_HEAP
 328   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 329     f->do_int(&_archived_basic_type_mirror_indices[i]);
 330     // if f->reading(): We can't call HeapShared::get_root() yet, as the heap
 331     // contents may need to be relocated. _basic_type_mirrors[i] will be
 332     // updated later in Universe::load_archived_object_instances().
 333   }
 334   _null_ptr_exception.serialize(f);
 335   _arithmetic_exception.serialize(f);
 336   _internal_error.serialize(f);



 337 #endif
 338 
 339   f->do_ptr(&_fillerArrayKlass);
 340   for (int i = 0; i < T_LONG+1; i++) {
 341     f->do_ptr(&_typeArrayKlasses[i]);
 342   }
 343 
 344   f->do_ptr(&_objectArrayKlass);
 345   f->do_ptr(&_the_array_interfaces_array);
 346   f->do_ptr(&_the_empty_int_array);
 347   f->do_ptr(&_the_empty_short_array);
 348   f->do_ptr(&_the_empty_method_array);
 349   f->do_ptr(&_the_empty_klass_array);
 350   f->do_ptr(&_the_empty_instance_klass_array);
 351 }
 352 
 353 
 354 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
 355   if (size < alignment || size % alignment != 0) {
 356     vm_exit_during_initialization(

1070   HandleMark hm(THREAD);
1071   // Setup preallocated empty java.lang.Class array for Method reflection.
1072 
1073   objArrayOop the_empty_class_array = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_false);
1074   Universe::_the_empty_class_array = OopHandle(Universe::vm_global(), the_empty_class_array);
1075 
1076   // Setup preallocated OutOfMemoryError errors
1077   Universe::create_preallocated_out_of_memory_errors(CHECK_false);
1078 
1079   oop instance;
1080   // Setup preallocated cause message for delayed StackOverflowError
1081   if (StackReservedPages > 0) {
1082     instance = java_lang_String::create_oop_from_str("Delayed StackOverflowError due to ReservedStackAccess annotated method", CHECK_false);
1083     Universe::_delayed_stack_overflow_error_message = OopHandle(Universe::vm_global(), instance);
1084   }
1085 
1086   // Setup preallocated NullPointerException/ArithmeticException
1087   // (used for a cheap & dirty solution in compiler exception handling)
1088   _null_ptr_exception.init_if_empty(vmSymbols::java_lang_NullPointerException(), CHECK_false);
1089   _arithmetic_exception.init_if_empty(vmSymbols::java_lang_ArithmeticException(), CHECK_false);



1090 
1091   // Virtual Machine Error for when we get into a situation we can't resolve
1092   Klass* k = vmClasses::InternalError_klass();
1093   bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false);
1094   if (!linked) {
1095      tty->print_cr("Unable to link/verify InternalError class");
1096      return false; // initialization failed
1097   }
1098   _internal_error.init_if_empty(vmSymbols::java_lang_InternalError(), CHECK_false);
1099 
1100   Handle msg = java_lang_String::create_from_str("/ by zero", CHECK_false);
1101   java_lang_Throwable::set_message(Universe::arithmetic_exception_instance(), msg());
1102 
1103   // Setup preallocated StackOverflowError for use with class initialization failure
1104   k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_StackOverflowError(), true, CHECK_false);
1105   instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
1106   Universe::_class_init_stack_overflow_error = OopHandle(Universe::vm_global(), instance);
1107 
1108   Universe::initialize_known_methods(THREAD);
1109 

  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"

 213     _archived_root_index = HeapShared::archive_exception_instance(instance());
 214   }
 215 
 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_oob_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 
 254 oop Universe::array_index_oob_exception_instance() { return _array_index_oob_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 
 258 oop Universe::the_null_sentinel()                 { return _the_null_sentinel.resolve(); }
 259 
 260 oop Universe::int_mirror()                        { return check_mirror(_basic_type_mirrors[T_INT].resolve()); }
 261 oop Universe::float_mirror()                      { return check_mirror(_basic_type_mirrors[T_FLOAT].resolve()); }
 262 oop Universe::double_mirror()                     { return check_mirror(_basic_type_mirrors[T_DOUBLE].resolve()); }
 263 oop Universe::byte_mirror()                       { return check_mirror(_basic_type_mirrors[T_BYTE].resolve()); }
 264 oop Universe::bool_mirror()                       { return check_mirror(_basic_type_mirrors[T_BOOLEAN].resolve()); }
 265 oop Universe::char_mirror()                       { return check_mirror(_basic_type_mirrors[T_CHAR].resolve()); }
 266 oop Universe::long_mirror()                       { return check_mirror(_basic_type_mirrors[T_LONG].resolve()); }
 267 oop Universe::short_mirror()                      { return check_mirror(_basic_type_mirrors[T_SHORT].resolve()); }
 268 oop Universe::void_mirror()                       { return check_mirror(_basic_type_mirrors[T_VOID].resolve()); }
 269 
 270 oop Universe::java_mirror(BasicType t) {
 271   assert((uint)t < T_VOID+1, "range check");
 272   assert(!is_reference_type(t), "sanity");
 273   return check_mirror(_basic_type_mirrors[t].resolve());
 274 }
 275 
 276 void Universe::basic_type_classes_do(KlassClosure *closure) {
 277   for (int i = T_BOOLEAN; i < T_LONG+1; i++) {

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

1087   HandleMark hm(THREAD);
1088   // Setup preallocated empty java.lang.Class array for Method reflection.
1089 
1090   objArrayOop the_empty_class_array = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_false);
1091   Universe::_the_empty_class_array = OopHandle(Universe::vm_global(), the_empty_class_array);
1092 
1093   // Setup preallocated OutOfMemoryError errors
1094   Universe::create_preallocated_out_of_memory_errors(CHECK_false);
1095 
1096   oop instance;
1097   // Setup preallocated cause message for delayed StackOverflowError
1098   if (StackReservedPages > 0) {
1099     instance = java_lang_String::create_oop_from_str("Delayed StackOverflowError due to ReservedStackAccess annotated method", CHECK_false);
1100     Universe::_delayed_stack_overflow_error_message = OopHandle(Universe::vm_global(), instance);
1101   }
1102 
1103   // Setup preallocated NullPointerException/ArithmeticException
1104   // (used for a cheap & dirty solution in compiler exception handling)
1105   _null_ptr_exception.init_if_empty(vmSymbols::java_lang_NullPointerException(), CHECK_false);
1106   _arithmetic_exception.init_if_empty(vmSymbols::java_lang_ArithmeticException(), CHECK_false);
1107   _array_index_oob_exception.init_if_empty(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), CHECK_false);
1108   _array_store_exception.init_if_empty(vmSymbols::java_lang_ArrayStoreException(), CHECK_false);
1109   _class_cast_exception.init_if_empty(vmSymbols::java_lang_ClassCastException(), CHECK_false);
1110 
1111   // Virtual Machine Error for when we get into a situation we can't resolve
1112   Klass* k = vmClasses::InternalError_klass();
1113   bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false);
1114   if (!linked) {
1115      tty->print_cr("Unable to link/verify InternalError class");
1116      return false; // initialization failed
1117   }
1118   _internal_error.init_if_empty(vmSymbols::java_lang_InternalError(), CHECK_false);
1119 
1120   Handle msg = java_lang_String::create_from_str("/ by zero", CHECK_false);
1121   java_lang_Throwable::set_message(Universe::arithmetic_exception_instance(), msg());
1122 
1123   // Setup preallocated StackOverflowError for use with class initialization failure
1124   k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_StackOverflowError(), true, CHECK_false);
1125   instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
1126   Universe::_class_init_stack_overflow_error = OopHandle(Universe::vm_global(), instance);
1127 
1128   Universe::initialize_known_methods(THREAD);
1129 
< prev index next >