< prev index next >

src/hotspot/share/memory/universe.cpp

Print this page

  49 #include "gc/shared/tlab_globals.hpp"
  50 #include "logging/log.hpp"
  51 #include "logging/logStream.hpp"
  52 #include "memory/memoryReserver.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/jmethodIDTable.hpp"
  64 #include "oops/klass.inline.hpp"
  65 #include "oops/objArrayOop.inline.hpp"
  66 #include "oops/objLayout.hpp"
  67 #include "oops/oop.inline.hpp"
  68 #include "oops/oopHandle.inline.hpp"

  69 #include "oops/typeArrayKlass.hpp"
  70 #include "prims/resolvedMethodTable.hpp"
  71 #include "runtime/arguments.hpp"
  72 #include "runtime/atomicAccess.hpp"
  73 #include "runtime/cpuTimeCounters.hpp"
  74 #include "runtime/flags/jvmFlagLimit.hpp"
  75 #include "runtime/handles.inline.hpp"
  76 #include "runtime/init.hpp"
  77 #include "runtime/java.hpp"
  78 #include "runtime/javaThread.hpp"
  79 #include "runtime/jniHandles.hpp"
  80 #include "runtime/threads.hpp"
  81 #include "runtime/timerTrace.hpp"
  82 #include "sanitizers/leak.hpp"
  83 #include "services/cpuTimeUsage.hpp"
  84 #include "services/memoryService.hpp"
  85 #include "utilities/align.hpp"
  86 #include "utilities/autoRestore.hpp"
  87 #include "utilities/debug.hpp"
  88 #include "utilities/formatBuffer.hpp"

  96 // interacts with the RedefineClasses API.
  97 class LatestMethodCache {
  98   // We save the InstanceKlass* and the idnum of Method* in order to get
  99   // the current Method*.
 100   InstanceKlass*        _klass;
 101   int                   _method_idnum;
 102 
 103  public:
 104   LatestMethodCache()   { _klass = nullptr; _method_idnum = -1; }
 105 
 106   void init(JavaThread* current, InstanceKlass* ik, const char* method,
 107             Symbol* signature, bool is_static);
 108   Method* get_method();
 109 };
 110 
 111 static LatestMethodCache _finalizer_register_cache;         // Finalizer.register()
 112 static LatestMethodCache _loader_addClass_cache;            // ClassLoader.addClass()
 113 static LatestMethodCache _throw_illegal_access_error_cache; // Unsafe.throwIllegalAccessError()
 114 static LatestMethodCache _throw_no_such_method_error_cache; // Unsafe.throwNoSuchMethodError()
 115 static LatestMethodCache _do_stack_walk_cache;              // AbstractStackWalker.doStackWalk()




 116 
 117 // Known objects
 118 TypeArrayKlass* Universe::_typeArrayKlasses[T_LONG+1] = { nullptr /*, nullptr...*/ };
 119 ObjArrayKlass* Universe::_objectArrayKlass            = nullptr;
 120 Klass* Universe::_fillerArrayKlass                    = nullptr;
 121 OopHandle Universe::_basic_type_mirrors[T_VOID+1];
 122 #if INCLUDE_CDS_JAVA_HEAP
 123 int Universe::_archived_basic_type_mirror_indices[T_VOID+1];
 124 #endif
 125 
 126 OopHandle Universe::_main_thread_group;
 127 OopHandle Universe::_system_thread_group;
 128 OopHandle Universe::_the_empty_class_array;
 129 OopHandle Universe::_the_null_string;
 130 OopHandle Universe::_the_min_jint_string;
 131 
 132 OopHandle Universe::_the_null_sentinel;
 133 
 134 // _out_of_memory_errors is an objArray
 135 enum OutOfMemoryInstance { _oom_java_heap,

 492     Handle tns = java_lang_String::create_from_str("<null_sentinel>", CHECK);
 493     _the_null_sentinel = OopHandle(vm_global(), tns());
 494   }
 495 
 496   // Create a handle for reference_pending_list
 497   _reference_pending_list = OopHandle(vm_global(), nullptr);
 498 
 499   // Maybe this could be lifted up now that object array can be initialized
 500   // during the bootstrapping.
 501 
 502   // OLD
 503   // Initialize _objectArrayKlass after core bootstraping to make
 504   // sure the super class is set up properly for _objectArrayKlass.
 505   // ---
 506   // NEW
 507   // Since some of the old system object arrays have been converted to
 508   // ordinary object arrays, _objectArrayKlass will be loaded when
 509   // SystemDictionary::initialize(CHECK); is run. See the extra check
 510   // for Object_klass_is_loaded in ObjArrayKlass::allocate_objArray_klass.
 511   {
 512     Klass* oak = vmClasses::Object_klass()->array_klass(CHECK);
 513     _objectArrayKlass = ObjArrayKlass::cast(oak);




 514   }
 515   // OLD
 516   // Add the class to the class hierarchy manually to make sure that
 517   // its vtable is initialized after core bootstrapping is completed.
 518   // ---
 519   // New
 520   // Have already been initialized.
 521   _objectArrayKlass->append_to_sibling_list();
 522 
 523   #ifdef ASSERT
 524   if (FullGCALot) {
 525     // Allocate an array of dummy objects.
 526     // We'd like these to be at the bottom of the old generation,
 527     // so that when we free one and then collect,
 528     // (almost) the whole heap moves
 529     // and we find out if we actually update all the oops correctly.
 530     // But we can't allocate directly in the old generation,
 531     // so we allocate wherever, and hope that the first collection
 532     // moves these objects to the bottom of the old generation.
 533     int size = FullGCALotDummies * 2;
 534 
 535     objArrayOop    naked_array = oopFactory::new_objArray(vmClasses::Object_klass(), size, CHECK);
 536     objArrayHandle dummy_array(THREAD, naked_array);
 537     int i = 0;
 538     while (i < size) {
 539         // Allocate dummy in old generation
 540       oop dummy = vmClasses::Object_klass()->allocate_instance(CHECK);
 541       dummy_array->obj_at_put(i++, dummy);

 636   assert_pll_ownership();
 637   return _reference_pending_list.peek() != nullptr;
 638 }
 639 
 640 oop Universe::swap_reference_pending_list(oop list) {
 641   assert_pll_locked(is_locked);
 642   return _reference_pending_list.xchg(list);
 643 }
 644 
 645 #undef assert_pll_locked
 646 #undef assert_pll_ownership
 647 
 648 static void reinitialize_vtables() {
 649   // The vtables are initialized by starting at java.lang.Object and
 650   // initializing through the subclass links, so that the super
 651   // classes are always initialized first.
 652   for (ClassHierarchyIterator iter(vmClasses::Object_klass()); !iter.done(); iter.next()) {
 653     Klass* sub = iter.klass();
 654     sub->vtable().initialize_vtable();
 655   }



 656 }
 657 
 658 static void reinitialize_itables() {
 659 
 660   class ReinitTableClosure : public KlassClosure {
 661    public:
 662     void do_klass(Klass* k) {
 663       if (k->is_instance_klass()) {
 664          InstanceKlass::cast(k)->itable().initialize_itable();
 665       }
 666     }
 667   };
 668 
 669   MutexLocker mcld(ClassLoaderDataGraph_lock);
 670   ReinitTableClosure cl;
 671   ClassLoaderDataGraph::classes_do(&cl);
 672 }
 673 
 674 bool Universe::on_page_boundary(void* addr) {
 675   return is_aligned(addr, os::vm_page_size());

1060     // <init> function before java_lang_Class is linked. Print error and exit.
1061     vm_exit_during_initialization(err_msg("Unable to link/verify %s.%s method",
1062                                  ik->name()->as_C_string(), method));
1063   }
1064 
1065   _klass = ik;
1066   _method_idnum = m->method_idnum();
1067   assert(_method_idnum >= 0, "sanity check");
1068 }
1069 
1070 Method* LatestMethodCache::get_method() {
1071   if (_klass == nullptr) {
1072     return nullptr;
1073   } else {
1074     Method* m = _klass->method_with_idnum(_method_idnum);
1075     assert(m != nullptr, "sanity check");
1076     return m;
1077   }
1078 }
1079 
1080 Method* Universe::finalizer_register_method()     { return _finalizer_register_cache.get_method(); }
1081 Method* Universe::loader_addClass_method()        { return _loader_addClass_cache.get_method(); }
1082 Method* Universe::throw_illegal_access_error()    { return _throw_illegal_access_error_cache.get_method(); }
1083 Method* Universe::throw_no_such_method_error()    { return _throw_no_such_method_error_cache.get_method(); }
1084 Method* Universe::do_stack_walk_method()          { return _do_stack_walk_cache.get_method(); }




1085 
1086 void Universe::initialize_known_methods(JavaThread* current) {
1087   // Set up static method for registering finalizers
1088   _finalizer_register_cache.init(current,
1089                           vmClasses::Finalizer_klass(),
1090                           "register",
1091                           vmSymbols::object_void_signature(), true);
1092 
1093   _throw_illegal_access_error_cache.init(current,
1094                           vmClasses::internal_Unsafe_klass(),
1095                           "throwIllegalAccessError",
1096                           vmSymbols::void_method_signature(), true);
1097 
1098   _throw_no_such_method_error_cache.init(current,
1099                           vmClasses::internal_Unsafe_klass(),
1100                           "throwNoSuchMethodError",
1101                           vmSymbols::void_method_signature(), true);
1102 
1103   // Set up method for registering loaded classes in class loader vector
1104   _loader_addClass_cache.init(current,
1105                           vmClasses::ClassLoader_klass(),
1106                           "addClass",
1107                           vmSymbols::class_void_signature(), false);
1108 
1109   // Set up method for stack walking
1110   _do_stack_walk_cache.init(current,
1111                           vmClasses::AbstractStackWalker_klass(),
1112                           "doStackWalk",
1113                           vmSymbols::doStackWalk_signature(), false);



















1114 }
1115 
1116 void universe2_init() {
1117   EXCEPTION_MARK;
1118   Universe::genesis(CATCH);
1119 }
1120 
1121 // Set after initialization of the module runtime, call_initModuleRuntime
1122 void universe_post_module_init() {
1123   Universe::_module_initialized = true;
1124 }
1125 
1126 bool universe_post_init() {
1127   assert(!is_init_completed(), "Error: initialization not yet completed!");
1128   Universe::_fully_initialized = true;
1129   EXCEPTION_MARK;
1130   if (!CDSConfig::is_using_archive()) {
1131     reinitialize_vtables();
1132     reinitialize_itables();
1133   }

  49 #include "gc/shared/tlab_globals.hpp"
  50 #include "logging/log.hpp"
  51 #include "logging/logStream.hpp"
  52 #include "memory/memoryReserver.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/jmethodIDTable.hpp"
  64 #include "oops/klass.inline.hpp"
  65 #include "oops/objArrayOop.inline.hpp"
  66 #include "oops/objLayout.hpp"
  67 #include "oops/oop.inline.hpp"
  68 #include "oops/oopHandle.inline.hpp"
  69 #include "oops/refArrayKlass.hpp"
  70 #include "oops/typeArrayKlass.hpp"
  71 #include "prims/resolvedMethodTable.hpp"
  72 #include "runtime/arguments.hpp"
  73 #include "runtime/atomicAccess.hpp"
  74 #include "runtime/cpuTimeCounters.hpp"
  75 #include "runtime/flags/jvmFlagLimit.hpp"
  76 #include "runtime/handles.inline.hpp"
  77 #include "runtime/init.hpp"
  78 #include "runtime/java.hpp"
  79 #include "runtime/javaThread.hpp"
  80 #include "runtime/jniHandles.hpp"
  81 #include "runtime/threads.hpp"
  82 #include "runtime/timerTrace.hpp"
  83 #include "sanitizers/leak.hpp"
  84 #include "services/cpuTimeUsage.hpp"
  85 #include "services/memoryService.hpp"
  86 #include "utilities/align.hpp"
  87 #include "utilities/autoRestore.hpp"
  88 #include "utilities/debug.hpp"
  89 #include "utilities/formatBuffer.hpp"

  97 // interacts with the RedefineClasses API.
  98 class LatestMethodCache {
  99   // We save the InstanceKlass* and the idnum of Method* in order to get
 100   // the current Method*.
 101   InstanceKlass*        _klass;
 102   int                   _method_idnum;
 103 
 104  public:
 105   LatestMethodCache()   { _klass = nullptr; _method_idnum = -1; }
 106 
 107   void init(JavaThread* current, InstanceKlass* ik, const char* method,
 108             Symbol* signature, bool is_static);
 109   Method* get_method();
 110 };
 111 
 112 static LatestMethodCache _finalizer_register_cache;         // Finalizer.register()
 113 static LatestMethodCache _loader_addClass_cache;            // ClassLoader.addClass()
 114 static LatestMethodCache _throw_illegal_access_error_cache; // Unsafe.throwIllegalAccessError()
 115 static LatestMethodCache _throw_no_such_method_error_cache; // Unsafe.throwNoSuchMethodError()
 116 static LatestMethodCache _do_stack_walk_cache;              // AbstractStackWalker.doStackWalk()
 117 static LatestMethodCache _is_substitutable_cache;           // ValueObjectMethods.isSubstitutable()
 118 static LatestMethodCache _value_object_hash_code_cache;     // ValueObjectMethods.valueObjectHashCode()
 119 static LatestMethodCache _is_substitutable_alt_cache;       // ValueObjectMethods.isSubstitutableAlt()
 120 static LatestMethodCache _value_object_hash_code_alt_cache; // ValueObjectMethods.valueObjectHashCodeAlt()
 121 
 122 // Known objects
 123 TypeArrayKlass* Universe::_typeArrayKlasses[T_LONG+1] = { nullptr /*, nullptr...*/ };
 124 ObjArrayKlass* Universe::_objectArrayKlass            = nullptr;
 125 Klass* Universe::_fillerArrayKlass                    = nullptr;
 126 OopHandle Universe::_basic_type_mirrors[T_VOID+1];
 127 #if INCLUDE_CDS_JAVA_HEAP
 128 int Universe::_archived_basic_type_mirror_indices[T_VOID+1];
 129 #endif
 130 
 131 OopHandle Universe::_main_thread_group;
 132 OopHandle Universe::_system_thread_group;
 133 OopHandle Universe::_the_empty_class_array;
 134 OopHandle Universe::_the_null_string;
 135 OopHandle Universe::_the_min_jint_string;
 136 
 137 OopHandle Universe::_the_null_sentinel;
 138 
 139 // _out_of_memory_errors is an objArray
 140 enum OutOfMemoryInstance { _oom_java_heap,

 497     Handle tns = java_lang_String::create_from_str("<null_sentinel>", CHECK);
 498     _the_null_sentinel = OopHandle(vm_global(), tns());
 499   }
 500 
 501   // Create a handle for reference_pending_list
 502   _reference_pending_list = OopHandle(vm_global(), nullptr);
 503 
 504   // Maybe this could be lifted up now that object array can be initialized
 505   // during the bootstrapping.
 506 
 507   // OLD
 508   // Initialize _objectArrayKlass after core bootstraping to make
 509   // sure the super class is set up properly for _objectArrayKlass.
 510   // ---
 511   // NEW
 512   // Since some of the old system object arrays have been converted to
 513   // ordinary object arrays, _objectArrayKlass will be loaded when
 514   // SystemDictionary::initialize(CHECK); is run. See the extra check
 515   // for Object_klass_is_loaded in ObjArrayKlass::allocate_objArray_klass.
 516   {
 517     ArrayKlass* oak = vmClasses::Object_klass()->array_klass(CHECK);
 518     oak->append_to_sibling_list();
 519 
 520     // Create a RefArrayKlass (which is the default) and initialize.
 521     ObjArrayKlass* rak = ObjArrayKlass::cast(oak)->klass_with_properties(ArrayKlass::ArrayProperties::DEFAULT, THREAD);
 522     _objectArrayKlass = rak;
 523   }







 524 
 525   #ifdef ASSERT
 526   if (FullGCALot) {
 527     // Allocate an array of dummy objects.
 528     // We'd like these to be at the bottom of the old generation,
 529     // so that when we free one and then collect,
 530     // (almost) the whole heap moves
 531     // and we find out if we actually update all the oops correctly.
 532     // But we can't allocate directly in the old generation,
 533     // so we allocate wherever, and hope that the first collection
 534     // moves these objects to the bottom of the old generation.
 535     int size = FullGCALotDummies * 2;
 536 
 537     objArrayOop    naked_array = oopFactory::new_objArray(vmClasses::Object_klass(), size, CHECK);
 538     objArrayHandle dummy_array(THREAD, naked_array);
 539     int i = 0;
 540     while (i < size) {
 541         // Allocate dummy in old generation
 542       oop dummy = vmClasses::Object_klass()->allocate_instance(CHECK);
 543       dummy_array->obj_at_put(i++, dummy);

 638   assert_pll_ownership();
 639   return _reference_pending_list.peek() != nullptr;
 640 }
 641 
 642 oop Universe::swap_reference_pending_list(oop list) {
 643   assert_pll_locked(is_locked);
 644   return _reference_pending_list.xchg(list);
 645 }
 646 
 647 #undef assert_pll_locked
 648 #undef assert_pll_ownership
 649 
 650 static void reinitialize_vtables() {
 651   // The vtables are initialized by starting at java.lang.Object and
 652   // initializing through the subclass links, so that the super
 653   // classes are always initialized first.
 654   for (ClassHierarchyIterator iter(vmClasses::Object_klass()); !iter.done(); iter.next()) {
 655     Klass* sub = iter.klass();
 656     sub->vtable().initialize_vtable();
 657   }
 658 
 659   // This isn't added to the subclass list, so need to reinitialize vtables directly.
 660   Universe::objectArrayKlass()->vtable().initialize_vtable();
 661 }
 662 
 663 static void reinitialize_itables() {
 664 
 665   class ReinitTableClosure : public KlassClosure {
 666    public:
 667     void do_klass(Klass* k) {
 668       if (k->is_instance_klass()) {
 669          InstanceKlass::cast(k)->itable().initialize_itable();
 670       }
 671     }
 672   };
 673 
 674   MutexLocker mcld(ClassLoaderDataGraph_lock);
 675   ReinitTableClosure cl;
 676   ClassLoaderDataGraph::classes_do(&cl);
 677 }
 678 
 679 bool Universe::on_page_boundary(void* addr) {
 680   return is_aligned(addr, os::vm_page_size());

1065     // <init> function before java_lang_Class is linked. Print error and exit.
1066     vm_exit_during_initialization(err_msg("Unable to link/verify %s.%s method",
1067                                  ik->name()->as_C_string(), method));
1068   }
1069 
1070   _klass = ik;
1071   _method_idnum = m->method_idnum();
1072   assert(_method_idnum >= 0, "sanity check");
1073 }
1074 
1075 Method* LatestMethodCache::get_method() {
1076   if (_klass == nullptr) {
1077     return nullptr;
1078   } else {
1079     Method* m = _klass->method_with_idnum(_method_idnum);
1080     assert(m != nullptr, "sanity check");
1081     return m;
1082   }
1083 }
1084 
1085 Method* Universe::finalizer_register_method()        { return _finalizer_register_cache.get_method(); }
1086 Method* Universe::loader_addClass_method()           { return _loader_addClass_cache.get_method(); }
1087 Method* Universe::throw_illegal_access_error()       { return _throw_illegal_access_error_cache.get_method(); }
1088 Method* Universe::throw_no_such_method_error()       { return _throw_no_such_method_error_cache.get_method(); }
1089 Method* Universe::do_stack_walk_method()             { return _do_stack_walk_cache.get_method(); }
1090 Method* Universe::is_substitutable_method()          { return _is_substitutable_cache.get_method(); }
1091 Method* Universe::value_object_hash_code_method()    { return _value_object_hash_code_cache.get_method(); }
1092 Method* Universe::is_substitutableAlt_method()       { return _is_substitutable_alt_cache.get_method(); }
1093 Method* Universe::value_object_hash_codeAlt_method() { return _value_object_hash_code_alt_cache.get_method(); }
1094 
1095 void Universe::initialize_known_methods(JavaThread* current) {
1096   // Set up static method for registering finalizers
1097   _finalizer_register_cache.init(current,
1098                           vmClasses::Finalizer_klass(),
1099                           "register",
1100                           vmSymbols::object_void_signature(), true);
1101 
1102   _throw_illegal_access_error_cache.init(current,
1103                           vmClasses::internal_Unsafe_klass(),
1104                           "throwIllegalAccessError",
1105                           vmSymbols::void_method_signature(), true);
1106 
1107   _throw_no_such_method_error_cache.init(current,
1108                           vmClasses::internal_Unsafe_klass(),
1109                           "throwNoSuchMethodError",
1110                           vmSymbols::void_method_signature(), true);
1111 
1112   // Set up method for registering loaded classes in class loader vector
1113   _loader_addClass_cache.init(current,
1114                           vmClasses::ClassLoader_klass(),
1115                           "addClass",
1116                           vmSymbols::class_void_signature(), false);
1117 
1118   // Set up method for stack walking
1119   _do_stack_walk_cache.init(current,
1120                           vmClasses::AbstractStackWalker_klass(),
1121                           "doStackWalk",
1122                           vmSymbols::doStackWalk_signature(), false);
1123 
1124   // Set up substitutability testing
1125   ResourceMark rm(current);
1126   _is_substitutable_cache.init(current,
1127                           vmClasses::ValueObjectMethods_klass(),
1128                           vmSymbols::isSubstitutable_name()->as_C_string(),
1129                           vmSymbols::object_object_boolean_signature(), true);
1130   _value_object_hash_code_cache.init(current,
1131                           vmClasses::ValueObjectMethods_klass(),
1132                           vmSymbols::valueObjectHashCode_name()->as_C_string(),
1133                           vmSymbols::object_int_signature(), true);
1134   _is_substitutable_alt_cache.init(current,
1135                           vmClasses::ValueObjectMethods_klass(),
1136                           vmSymbols::isSubstitutableAlt_name()->as_C_string(),
1137                           vmSymbols::object_object_boolean_signature(), true);
1138   _value_object_hash_code_alt_cache.init(current,
1139                           vmClasses::ValueObjectMethods_klass(),
1140                           vmSymbols::valueObjectHashCodeAlt_name()->as_C_string(),
1141                           vmSymbols::object_int_signature(), true);
1142 }
1143 
1144 void universe2_init() {
1145   EXCEPTION_MARK;
1146   Universe::genesis(CATCH);
1147 }
1148 
1149 // Set after initialization of the module runtime, call_initModuleRuntime
1150 void universe_post_module_init() {
1151   Universe::_module_initialized = true;
1152 }
1153 
1154 bool universe_post_init() {
1155   assert(!is_init_completed(), "Error: initialization not yet completed!");
1156   Universe::_fully_initialized = true;
1157   EXCEPTION_MARK;
1158   if (!CDSConfig::is_using_archive()) {
1159     reinitialize_vtables();
1160     reinitialize_itables();
1161   }
< prev index next >