< prev index next >

src/hotspot/share/memory/universe.cpp

Print this page


  68 #include "runtime/handles.inline.hpp"
  69 #include "runtime/init.hpp"
  70 #include "runtime/java.hpp"
  71 #include "runtime/javaCalls.hpp"
  72 #include "runtime/sharedRuntime.hpp"
  73 #include "runtime/synchronizer.hpp"
  74 #include "runtime/thread.inline.hpp"
  75 #include "runtime/timerTrace.hpp"
  76 #include "runtime/vmOperations.hpp"
  77 #include "services/memoryService.hpp"
  78 #include "utilities/align.hpp"
  79 #include "utilities/copy.hpp"
  80 #include "utilities/debug.hpp"
  81 #include "utilities/events.hpp"
  82 #include "utilities/formatBuffer.hpp"
  83 #include "utilities/hashtable.inline.hpp"
  84 #include "utilities/macros.hpp"
  85 #include "utilities/ostream.hpp"
  86 #include "utilities/preserveException.hpp"
  87 














  88 // Known objects

  89 Klass* Universe::_typeArrayKlassObjs[T_LONG+1]        = { NULL /*, NULL...*/ };
  90 Klass* Universe::_objectArrayKlassObj                 = NULL;
  91 oop Universe::_int_mirror                             = NULL;
  92 oop Universe::_float_mirror                           = NULL;
  93 oop Universe::_double_mirror                          = NULL;
  94 oop Universe::_byte_mirror                            = NULL;
  95 oop Universe::_bool_mirror                            = NULL;
  96 oop Universe::_char_mirror                            = NULL;
  97 oop Universe::_long_mirror                            = NULL;
  98 oop Universe::_short_mirror                           = NULL;
  99 oop Universe::_void_mirror                            = NULL;
 100 oop Universe::_mirrors[T_VOID+1]                      = { NULL /*, NULL...*/ };
 101 oop Universe::_main_thread_group                      = NULL;
 102 oop Universe::_system_thread_group                    = NULL;
 103 objArrayOop Universe::_the_empty_class_klass_array    = NULL;
 104 Array<Klass*>* Universe::_the_array_interfaces_array = NULL;
 105 oop Universe::_the_null_sentinel                      = NULL;
 106 oop Universe::_the_null_string                        = NULL;
 107 oop Universe::_the_min_jint_string                   = NULL;
 108 LatestMethodCache* Universe::_finalizer_register_cache = NULL;
 109 LatestMethodCache* Universe::_loader_addClass_cache    = NULL;
 110 LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL;
 111 LatestMethodCache* Universe::_throw_no_such_method_error_cache = NULL;
 112 LatestMethodCache* Universe::_do_stack_walk_cache     = NULL;
 113 oop Universe::_out_of_memory_error_java_heap          = NULL;
 114 oop Universe::_out_of_memory_error_metaspace          = NULL;
 115 oop Universe::_out_of_memory_error_class_metaspace    = NULL;
 116 oop Universe::_out_of_memory_error_array_size         = NULL;
 117 oop Universe::_out_of_memory_error_gc_overhead_limit  = NULL;
 118 oop Universe::_out_of_memory_error_realloc_objects    = NULL;
 119 oop Universe::_out_of_memory_error_retry              = NULL;


 150 bool            Universe::_module_initialized = false;
 151 bool            Universe::_fully_initialized = false;
 152 
 153 size_t          Universe::_heap_capacity_at_last_gc;
 154 size_t          Universe::_heap_used_at_last_gc = 0;
 155 
 156 CollectedHeap*  Universe::_collectedHeap = NULL;
 157 
 158 void Universe::basic_type_classes_do(void f(Klass*)) {
 159   for (int i = T_BOOLEAN; i < T_LONG+1; i++) {
 160     f(_typeArrayKlassObjs[i]);
 161   }
 162 }
 163 
 164 void Universe::basic_type_classes_do(KlassClosure *closure) {
 165   for (int i = T_BOOLEAN; i < T_LONG+1; i++) {
 166     closure->do_klass(_typeArrayKlassObjs[i]);
 167   }
 168 }
 169 
 170 void Universe::oops_do(OopClosure* f) {

 171 
 172   f->do_oop((oop*) &_int_mirror);
 173   f->do_oop((oop*) &_float_mirror);
 174   f->do_oop((oop*) &_double_mirror);
 175   f->do_oop((oop*) &_byte_mirror);
 176   f->do_oop((oop*) &_bool_mirror);
 177   f->do_oop((oop*) &_char_mirror);
 178   f->do_oop((oop*) &_long_mirror);
 179   f->do_oop((oop*) &_short_mirror);
 180   f->do_oop((oop*) &_void_mirror);
 181 
 182   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 183     f->do_oop((oop*) &_mirrors[i]);
 184   }
 185   assert(_mirrors[0] == NULL && _mirrors[T_BOOLEAN - 1] == NULL, "checking");
 186 
 187   f->do_oop((oop*)&_the_empty_class_klass_array);
 188   f->do_oop((oop*)&_the_null_sentinel);
 189   f->do_oop((oop*)&_the_null_string);
 190   f->do_oop((oop*)&_the_min_jint_string);
 191   f->do_oop((oop*)&_out_of_memory_error_java_heap);
 192   f->do_oop((oop*)&_out_of_memory_error_metaspace);
 193   f->do_oop((oop*)&_out_of_memory_error_class_metaspace);
 194   f->do_oop((oop*)&_out_of_memory_error_array_size);
 195   f->do_oop((oop*)&_out_of_memory_error_gc_overhead_limit);
 196   f->do_oop((oop*)&_out_of_memory_error_realloc_objects);
 197   f->do_oop((oop*)&_out_of_memory_error_retry);
 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);


 214 void Universe::metaspace_pointers_do(MetaspaceClosure* it) {
 215   for (int i = 0; i < T_LONG+1; i++) {
 216     it->push(&_typeArrayKlassObjs[i]);
 217   }
 218   it->push(&_objectArrayKlassObj);
 219 
 220   it->push(&_the_empty_int_array);
 221   it->push(&_the_empty_short_array);
 222   it->push(&_the_empty_klass_array);
 223   it->push(&_the_empty_instance_klass_array);
 224   it->push(&_the_empty_method_array);
 225   it->push(&_the_array_interfaces_array);
 226 
 227   _finalizer_register_cache->metaspace_pointers_do(it);
 228   _loader_addClass_cache->metaspace_pointers_do(it);
 229   _throw_illegal_access_error_cache->metaspace_pointers_do(it);
 230   _throw_no_such_method_error_cache->metaspace_pointers_do(it);
 231   _do_stack_walk_cache->metaspace_pointers_do(it);
 232 }
 233 







 234 // Serialize metadata and pointers to primitive type mirrors in and out of CDS archive
 235 void Universe::serialize(SerializeClosure* f) {
 236 
 237   for (int i = 0; i < T_LONG+1; i++) {
 238     f->do_ptr((void**)&_typeArrayKlassObjs[i]);
 239   }
 240 
 241   f->do_ptr((void**)&_objectArrayKlassObj);

 242 #if INCLUDE_CDS_JAVA_HEAP
 243 #ifdef ASSERT
 244   if (DumpSharedSpaces && !HeapShared::is_heap_object_archiving_allowed()) {
 245     assert(_int_mirror == NULL    && _float_mirror == NULL &&
 246            _double_mirror == NULL && _byte_mirror == NULL  &&
 247            _bool_mirror == NULL   && _char_mirror == NULL  &&
 248            _long_mirror == NULL   && _short_mirror == NULL &&
 249            _void_mirror == NULL, "mirrors should be NULL");
 250   }
 251 #endif
 252   f->do_mirror_oop(&_int_mirror);
 253   f->do_mirror_oop(&_float_mirror);
 254   f->do_mirror_oop(&_double_mirror);
 255   f->do_mirror_oop(&_byte_mirror);
 256   f->do_mirror_oop(&_bool_mirror);
 257   f->do_mirror_oop(&_char_mirror);
 258   f->do_mirror_oop(&_long_mirror);
 259   f->do_mirror_oop(&_short_mirror);
 260   f->do_mirror_oop(&_void_mirror);
 261 #endif
 262 
 263   f->do_ptr((void**)&_the_array_interfaces_array);
 264   f->do_ptr((void**)&_the_empty_int_array);
 265   f->do_ptr((void**)&_the_empty_short_array);
 266   f->do_ptr((void**)&_the_empty_method_array);
 267   f->do_ptr((void**)&_the_empty_klass_array);
 268   f->do_ptr((void**)&_the_empty_instance_klass_array);
 269   _finalizer_register_cache->serialize(f);
 270   _loader_addClass_cache->serialize(f);
 271   _throw_illegal_access_error_cache->serialize(f);
 272   _throw_no_such_method_error_cache->serialize(f);
 273   _do_stack_walk_cache->serialize(f);
 274 }
 275 
 276 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
 277   if (size < alignment || size % alignment != 0) {
 278     vm_exit_during_initialization(
 279       err_msg("Size of %s (" UINTX_FORMAT " bytes) must be aligned to " UINTX_FORMAT " bytes", name, size, alignment));
 280   }


 407     int i = 0;
 408     while (i < size) {
 409         // Allocate dummy in old generation
 410       oop dummy = SystemDictionary::Object_klass()->allocate_instance(CHECK);
 411       dummy_array->obj_at_put(i++, dummy);
 412     }
 413     {
 414       // Only modify the global variable inside the mutex.
 415       // If we had a race to here, the other dummy_array instances
 416       // and their elements just get dropped on the floor, which is fine.
 417       MutexLocker ml(FullGCALot_lock);
 418       if (_fullgc_alot_dummy_array == NULL) {
 419         _fullgc_alot_dummy_array = dummy_array();
 420       }
 421     }
 422     assert(i == _fullgc_alot_dummy_array->length(), "just checking");
 423   }
 424   #endif
 425 }
 426 



 427 void Universe::initialize_basic_type_mirrors(TRAPS) {
 428 #if INCLUDE_CDS_JAVA_HEAP
 429     if (UseSharedSpaces &&
 430         HeapShared::open_archive_heap_region_mapped() &&
 431         _int_mirror != NULL) {
 432       assert(HeapShared::is_heap_object_archiving_allowed(), "Sanity");
 433       assert(_float_mirror != NULL && _double_mirror != NULL &&
 434              _byte_mirror  != NULL && _byte_mirror   != NULL &&
 435              _bool_mirror  != NULL && _char_mirror   != NULL &&
 436              _long_mirror  != NULL && _short_mirror  != NULL &&
 437              _void_mirror  != NULL, "Sanity");
 438     } else

 439 #endif
 440     {
 441       _int_mirror     =
 442         java_lang_Class::create_basic_type_mirror("int",    T_INT, CHECK);
 443       _float_mirror   =
 444         java_lang_Class::create_basic_type_mirror("float",  T_FLOAT,   CHECK);
 445       _double_mirror  =
 446         java_lang_Class::create_basic_type_mirror("double", T_DOUBLE,  CHECK);
 447       _byte_mirror    =
 448         java_lang_Class::create_basic_type_mirror("byte",   T_BYTE, CHECK);
 449       _bool_mirror    =
 450         java_lang_Class::create_basic_type_mirror("boolean",T_BOOLEAN, CHECK);
 451       _char_mirror    =
 452         java_lang_Class::create_basic_type_mirror("char",   T_CHAR, CHECK);
 453       _long_mirror    =
 454         java_lang_Class::create_basic_type_mirror("long",   T_LONG, CHECK);
 455       _short_mirror   =
 456         java_lang_Class::create_basic_type_mirror("short",  T_SHORT,   CHECK);
 457       _void_mirror    =
 458         java_lang_Class::create_basic_type_mirror("void",   T_VOID, CHECK);




  68 #include "runtime/handles.inline.hpp"
  69 #include "runtime/init.hpp"
  70 #include "runtime/java.hpp"
  71 #include "runtime/javaCalls.hpp"
  72 #include "runtime/sharedRuntime.hpp"
  73 #include "runtime/synchronizer.hpp"
  74 #include "runtime/thread.inline.hpp"
  75 #include "runtime/timerTrace.hpp"
  76 #include "runtime/vmOperations.hpp"
  77 #include "services/memoryService.hpp"
  78 #include "utilities/align.hpp"
  79 #include "utilities/copy.hpp"
  80 #include "utilities/debug.hpp"
  81 #include "utilities/events.hpp"
  82 #include "utilities/formatBuffer.hpp"
  83 #include "utilities/hashtable.inline.hpp"
  84 #include "utilities/macros.hpp"
  85 #include "utilities/ostream.hpp"
  86 #include "utilities/preserveException.hpp"
  87 
  88 #define PRIMITIVE_MIRRORS_DO(func) \
  89   func(_int_mirror)    \
  90   func(_float_mirror)  \
  91   func(_double_mirror) \
  92   func(_byte_mirror)   \
  93   func(_bool_mirror)   \
  94   func(_char_mirror)   \
  95   func(_long_mirror)   \
  96   func(_short_mirror)  \
  97   func(_void_mirror)
  98 
  99 #define DEFINE_PRIMITIVE_MIRROR(m) \
 100     oop Universe::m  = NULL;
 101 
 102 // Known objects
 103 PRIMITIVE_MIRRORS_DO(DEFINE_PRIMITIVE_MIRROR)
 104 Klass* Universe::_typeArrayKlassObjs[T_LONG+1]        = { NULL /*, NULL...*/ };
 105 Klass* Universe::_objectArrayKlassObj                 = NULL;









 106 oop Universe::_mirrors[T_VOID+1]                      = { NULL /*, NULL...*/ };
 107 oop Universe::_main_thread_group                      = NULL;
 108 oop Universe::_system_thread_group                    = NULL;
 109 objArrayOop Universe::_the_empty_class_klass_array    = NULL;
 110 Array<Klass*>* Universe::_the_array_interfaces_array = NULL;
 111 oop Universe::_the_null_sentinel                      = NULL;
 112 oop Universe::_the_null_string                        = NULL;
 113 oop Universe::_the_min_jint_string                   = NULL;
 114 LatestMethodCache* Universe::_finalizer_register_cache = NULL;
 115 LatestMethodCache* Universe::_loader_addClass_cache    = NULL;
 116 LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL;
 117 LatestMethodCache* Universe::_throw_no_such_method_error_cache = NULL;
 118 LatestMethodCache* Universe::_do_stack_walk_cache     = NULL;
 119 oop Universe::_out_of_memory_error_java_heap          = NULL;
 120 oop Universe::_out_of_memory_error_metaspace          = NULL;
 121 oop Universe::_out_of_memory_error_class_metaspace    = NULL;
 122 oop Universe::_out_of_memory_error_array_size         = NULL;
 123 oop Universe::_out_of_memory_error_gc_overhead_limit  = NULL;
 124 oop Universe::_out_of_memory_error_realloc_objects    = NULL;
 125 oop Universe::_out_of_memory_error_retry              = NULL;


 156 bool            Universe::_module_initialized = false;
 157 bool            Universe::_fully_initialized = false;
 158 
 159 size_t          Universe::_heap_capacity_at_last_gc;
 160 size_t          Universe::_heap_used_at_last_gc = 0;
 161 
 162 CollectedHeap*  Universe::_collectedHeap = NULL;
 163 
 164 void Universe::basic_type_classes_do(void f(Klass*)) {
 165   for (int i = T_BOOLEAN; i < T_LONG+1; i++) {
 166     f(_typeArrayKlassObjs[i]);
 167   }
 168 }
 169 
 170 void Universe::basic_type_classes_do(KlassClosure *closure) {
 171   for (int i = T_BOOLEAN; i < T_LONG+1; i++) {
 172     closure->do_klass(_typeArrayKlassObjs[i]);
 173   }
 174 }
 175 
 176 #define DO_PRIMITIVE_MIRROR(m) \
 177   f->do_oop((oop*) &m);
 178 
 179 void Universe::oops_do(OopClosure* f) {
 180   PRIMITIVE_MIRRORS_DO(DO_PRIMITIVE_MIRROR);







 181 
 182   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 183     f->do_oop((oop*) &_mirrors[i]);
 184   }
 185   assert(_mirrors[0] == NULL && _mirrors[T_BOOLEAN - 1] == NULL, "checking");
 186 
 187   f->do_oop((oop*)&_the_empty_class_klass_array);
 188   f->do_oop((oop*)&_the_null_sentinel);
 189   f->do_oop((oop*)&_the_null_string);
 190   f->do_oop((oop*)&_the_min_jint_string);
 191   f->do_oop((oop*)&_out_of_memory_error_java_heap);
 192   f->do_oop((oop*)&_out_of_memory_error_metaspace);
 193   f->do_oop((oop*)&_out_of_memory_error_class_metaspace);
 194   f->do_oop((oop*)&_out_of_memory_error_array_size);
 195   f->do_oop((oop*)&_out_of_memory_error_gc_overhead_limit);
 196   f->do_oop((oop*)&_out_of_memory_error_realloc_objects);
 197   f->do_oop((oop*)&_out_of_memory_error_retry);
 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);


 214 void Universe::metaspace_pointers_do(MetaspaceClosure* it) {
 215   for (int i = 0; i < T_LONG+1; i++) {
 216     it->push(&_typeArrayKlassObjs[i]);
 217   }
 218   it->push(&_objectArrayKlassObj);
 219 
 220   it->push(&_the_empty_int_array);
 221   it->push(&_the_empty_short_array);
 222   it->push(&_the_empty_klass_array);
 223   it->push(&_the_empty_instance_klass_array);
 224   it->push(&_the_empty_method_array);
 225   it->push(&_the_array_interfaces_array);
 226 
 227   _finalizer_register_cache->metaspace_pointers_do(it);
 228   _loader_addClass_cache->metaspace_pointers_do(it);
 229   _throw_illegal_access_error_cache->metaspace_pointers_do(it);
 230   _throw_no_such_method_error_cache->metaspace_pointers_do(it);
 231   _do_stack_walk_cache->metaspace_pointers_do(it);
 232 }
 233 
 234 #define ASSERT_MIRROR_NULL(m) \
 235   assert(m == NULL, "archived mirrors should be NULL");
 236 
 237 #define SERIALIZE_MIRROR(m) \
 238   f->do_oop(&m); \
 239   if (m != NULL) { java_lang_Class::update_archived_primitive_mirror_native_pointers(m); }
 240 
 241 // Serialize metadata and pointers to primitive type mirrors in and out of CDS archive
 242 void Universe::serialize(SerializeClosure* f) {
 243 
 244   for (int i = 0; i < T_LONG+1; i++) {
 245     f->do_ptr((void**)&_typeArrayKlassObjs[i]);
 246   }
 247 
 248   f->do_ptr((void**)&_objectArrayKlassObj);
 249 
 250 #if INCLUDE_CDS_JAVA_HEAP
 251   DEBUG_ONLY(if (DumpSharedSpaces && !HeapShared::is_heap_object_archiving_allowed()) {
 252       PRIMITIVE_MIRRORS_DO(ASSERT_MIRROR_NULL);
 253     });
 254   PRIMITIVE_MIRRORS_DO(SERIALIZE_MIRROR);














 255 #endif
 256 
 257   f->do_ptr((void**)&_the_array_interfaces_array);
 258   f->do_ptr((void**)&_the_empty_int_array);
 259   f->do_ptr((void**)&_the_empty_short_array);
 260   f->do_ptr((void**)&_the_empty_method_array);
 261   f->do_ptr((void**)&_the_empty_klass_array);
 262   f->do_ptr((void**)&_the_empty_instance_klass_array);
 263   _finalizer_register_cache->serialize(f);
 264   _loader_addClass_cache->serialize(f);
 265   _throw_illegal_access_error_cache->serialize(f);
 266   _throw_no_such_method_error_cache->serialize(f);
 267   _do_stack_walk_cache->serialize(f);
 268 }
 269 
 270 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
 271   if (size < alignment || size % alignment != 0) {
 272     vm_exit_during_initialization(
 273       err_msg("Size of %s (" UINTX_FORMAT " bytes) must be aligned to " UINTX_FORMAT " bytes", name, size, alignment));
 274   }


 401     int i = 0;
 402     while (i < size) {
 403         // Allocate dummy in old generation
 404       oop dummy = SystemDictionary::Object_klass()->allocate_instance(CHECK);
 405       dummy_array->obj_at_put(i++, dummy);
 406     }
 407     {
 408       // Only modify the global variable inside the mutex.
 409       // If we had a race to here, the other dummy_array instances
 410       // and their elements just get dropped on the floor, which is fine.
 411       MutexLocker ml(FullGCALot_lock);
 412       if (_fullgc_alot_dummy_array == NULL) {
 413         _fullgc_alot_dummy_array = dummy_array();
 414       }
 415     }
 416     assert(i == _fullgc_alot_dummy_array->length(), "just checking");
 417   }
 418   #endif
 419 }
 420 
 421 #define ASSERT_MIRROR_NOT_NULL(m) \
 422   assert(m != NULL, "archived mirrors should not be NULL");
 423 
 424 void Universe::initialize_basic_type_mirrors(TRAPS) {
 425 #if INCLUDE_CDS_JAVA_HEAP
 426     if (UseSharedSpaces &&
 427         HeapShared::open_archive_heap_region_mapped() &&
 428         _int_mirror != NULL) {
 429       assert(HeapShared::is_heap_object_archiving_allowed(), "Sanity");
 430       PRIMITIVE_MIRRORS_DO(ASSERT_MIRROR_NOT_NULL);




 431     } else
 432       // _int_mirror could be NULL if archived heap is not mapped.
 433 #endif
 434     {
 435       _int_mirror     =
 436         java_lang_Class::create_basic_type_mirror("int",    T_INT, CHECK);
 437       _float_mirror   =
 438         java_lang_Class::create_basic_type_mirror("float",  T_FLOAT,   CHECK);
 439       _double_mirror  =
 440         java_lang_Class::create_basic_type_mirror("double", T_DOUBLE,  CHECK);
 441       _byte_mirror    =
 442         java_lang_Class::create_basic_type_mirror("byte",   T_BYTE, CHECK);
 443       _bool_mirror    =
 444         java_lang_Class::create_basic_type_mirror("boolean",T_BOOLEAN, CHECK);
 445       _char_mirror    =
 446         java_lang_Class::create_basic_type_mirror("char",   T_CHAR, CHECK);
 447       _long_mirror    =
 448         java_lang_Class::create_basic_type_mirror("long",   T_LONG, CHECK);
 449       _short_mirror   =
 450         java_lang_Class::create_basic_type_mirror("short",  T_SHORT,   CHECK);
 451       _void_mirror    =
 452         java_lang_Class::create_basic_type_mirror("void",   T_VOID, CHECK);


< prev index next >