93 // interacts with the RedefineClasses API.
94 class LatestMethodCache {
95 // We save the InstanceKlass* and the idnum of Method* in order to get
96 // the current Method*.
97 InstanceKlass* _klass;
98 int _method_idnum;
99
100 public:
101 LatestMethodCache() { _klass = nullptr; _method_idnum = -1; }
102
103 void init(JavaThread* current, InstanceKlass* ik, const char* method,
104 Symbol* signature, bool is_static);
105 Method* get_method();
106 };
107
108 static LatestMethodCache _finalizer_register_cache; // Finalizer.register()
109 static LatestMethodCache _loader_addClass_cache; // ClassLoader.addClass()
110 static LatestMethodCache _throw_illegal_access_error_cache; // Unsafe.throwIllegalAccessError()
111 static LatestMethodCache _throw_no_such_method_error_cache; // Unsafe.throwNoSuchMethodError()
112 static LatestMethodCache _do_stack_walk_cache; // AbstractStackWalker.doStackWalk()
113
114 // Known objects
115 TypeArrayKlass* Universe::_typeArrayKlasses[T_LONG+1] = { nullptr /*, nullptr...*/ };
116 ObjArrayKlass* Universe::_objectArrayKlass = nullptr;
117 Klass* Universe::_fillerArrayKlass = nullptr;
118 OopHandle Universe::_basic_type_mirrors[T_VOID+1];
119 #if INCLUDE_CDS_JAVA_HEAP
120 int Universe::_archived_basic_type_mirror_indices[T_VOID+1];
121 #endif
122
123 OopHandle Universe::_main_thread_group;
124 OopHandle Universe::_system_thread_group;
125 OopHandle Universe::_the_empty_class_array;
126 OopHandle Universe::_the_null_string;
127 OopHandle Universe::_the_min_jint_string;
128
129 OopHandle Universe::_the_null_sentinel;
130
131 // _out_of_memory_errors is an objArray
132 enum OutOfMemoryInstance { _oom_java_heap,
435 }
436
437 vmSymbols::initialize();
438
439 SystemDictionary::initialize(CHECK);
440
441 // Create string constants
442 oop s = StringTable::intern("null", CHECK);
443 _the_null_string = OopHandle(vm_global(), s);
444 s = StringTable::intern("-2147483648", CHECK);
445 _the_min_jint_string = OopHandle(vm_global(), s);
446
447
448 #if INCLUDE_CDS
449 if (CDSConfig::is_using_archive()) {
450 // Verify shared interfaces array.
451 assert(_the_array_interfaces_array->at(0) ==
452 vmClasses::Cloneable_klass(), "u3");
453 assert(_the_array_interfaces_array->at(1) ==
454 vmClasses::Serializable_klass(), "u3");
455 } else
456 #endif
457 {
458 // Set up shared interfaces array. (Do this before supers are set up.)
459 _the_array_interfaces_array->at_put(0, vmClasses::Cloneable_klass());
460 _the_array_interfaces_array->at_put(1, vmClasses::Serializable_klass());
461 }
462
463 _the_array_interfaces_bitmap = Klass::compute_secondary_supers_bitmap(_the_array_interfaces_array);
464 _the_empty_klass_bitmap = Klass::compute_secondary_supers_bitmap(_the_empty_klass_array);
465
466 initialize_basic_type_klass(_fillerArrayKlass, CHECK);
467
468 initialize_basic_type_klass(boolArrayKlass(), CHECK);
469 initialize_basic_type_klass(charArrayKlass(), CHECK);
470 initialize_basic_type_klass(floatArrayKlass(), CHECK);
471 initialize_basic_type_klass(doubleArrayKlass(), CHECK);
472 initialize_basic_type_klass(byteArrayKlass(), CHECK);
473 initialize_basic_type_klass(shortArrayKlass(), CHECK);
474 initialize_basic_type_klass(intArrayKlass(), CHECK);
868
869 // Initialize CPUTimeCounters object, which must be done before creation of the heap.
870 CPUTimeCounters::initialize();
871
872 ObjLayout::initialize();
873
874 #ifdef _LP64
875 MetaspaceShared::adjust_heap_sizes_for_dumping();
876 #endif // _LP64
877
878 GCConfig::arguments()->initialize_heap_sizes();
879
880 jint status = Universe::initialize_heap();
881 if (status != JNI_OK) {
882 return status;
883 }
884
885 Universe::initialize_tlab();
886
887 Metaspace::global_initialize();
888
889 // Initialize performance counters for metaspaces
890 MetaspaceCounters::initialize_performance_counters();
891
892 // Checks 'AfterMemoryInit' constraints.
893 if (!JVMFlagLimit::check_all_constraints(JVMFlagConstraintPhase::AfterMemoryInit)) {
894 return JNI_EINVAL;
895 }
896
897 ClassLoaderData::init_null_class_loader_data();
898
899 #if INCLUDE_CDS
900 if (CDSConfig::is_using_archive()) {
901 // Read the data structures supporting the shared spaces (shared
902 // system dictionary, symbol table, etc.)
903 MetaspaceShared::initialize_shared_spaces();
904 }
905 if (CDSConfig::is_dumping_archive()) {
906 CDSConfig::prepare_for_dumping();
907 }
908 #endif
1023 _klass = ik;
1024 _method_idnum = m->method_idnum();
1025 assert(_method_idnum >= 0, "sanity check");
1026 }
1027
1028 Method* LatestMethodCache::get_method() {
1029 if (_klass == nullptr) {
1030 return nullptr;
1031 } else {
1032 Method* m = _klass->method_with_idnum(_method_idnum);
1033 assert(m != nullptr, "sanity check");
1034 return m;
1035 }
1036 }
1037
1038 Method* Universe::finalizer_register_method() { return _finalizer_register_cache.get_method(); }
1039 Method* Universe::loader_addClass_method() { return _loader_addClass_cache.get_method(); }
1040 Method* Universe::throw_illegal_access_error() { return _throw_illegal_access_error_cache.get_method(); }
1041 Method* Universe::throw_no_such_method_error() { return _throw_no_such_method_error_cache.get_method(); }
1042 Method* Universe::do_stack_walk_method() { return _do_stack_walk_cache.get_method(); }
1043
1044 void Universe::initialize_known_methods(JavaThread* current) {
1045 // Set up static method for registering finalizers
1046 _finalizer_register_cache.init(current,
1047 vmClasses::Finalizer_klass(),
1048 "register",
1049 vmSymbols::object_void_signature(), true);
1050
1051 _throw_illegal_access_error_cache.init(current,
1052 vmClasses::internal_Unsafe_klass(),
1053 "throwIllegalAccessError",
1054 vmSymbols::void_method_signature(), true);
1055
1056 _throw_no_such_method_error_cache.init(current,
1057 vmClasses::internal_Unsafe_klass(),
1058 "throwNoSuchMethodError",
1059 vmSymbols::void_method_signature(), true);
1060
1061 // Set up method for registering loaded classes in class loader vector
1062 _loader_addClass_cache.init(current,
1063 vmClasses::ClassLoader_klass(),
1064 "addClass",
1065 vmSymbols::class_void_signature(), false);
1066
1067 // Set up method for stack walking
1068 _do_stack_walk_cache.init(current,
1069 vmClasses::AbstractStackWalker_klass(),
1070 "doStackWalk",
1071 vmSymbols::doStackWalk_signature(), false);
1072 }
1073
1074 void universe2_init() {
1075 EXCEPTION_MARK;
1076 Universe::genesis(CATCH);
1077 }
1078
1079 // Set after initialization of the module runtime, call_initModuleRuntime
1080 void universe_post_module_init() {
1081 Universe::_module_initialized = true;
1082 }
1083
1084 bool universe_post_init() {
1085 assert(!is_init_completed(), "Error: initialization not yet completed!");
1086 Universe::_fully_initialized = true;
1087 EXCEPTION_MARK;
1088 if (!CDSConfig::is_using_archive()) {
1089 reinitialize_vtables();
1090 reinitialize_itables();
1091 }
|
93 // interacts with the RedefineClasses API.
94 class LatestMethodCache {
95 // We save the InstanceKlass* and the idnum of Method* in order to get
96 // the current Method*.
97 InstanceKlass* _klass;
98 int _method_idnum;
99
100 public:
101 LatestMethodCache() { _klass = nullptr; _method_idnum = -1; }
102
103 void init(JavaThread* current, InstanceKlass* ik, const char* method,
104 Symbol* signature, bool is_static);
105 Method* get_method();
106 };
107
108 static LatestMethodCache _finalizer_register_cache; // Finalizer.register()
109 static LatestMethodCache _loader_addClass_cache; // ClassLoader.addClass()
110 static LatestMethodCache _throw_illegal_access_error_cache; // Unsafe.throwIllegalAccessError()
111 static LatestMethodCache _throw_no_such_method_error_cache; // Unsafe.throwNoSuchMethodError()
112 static LatestMethodCache _do_stack_walk_cache; // AbstractStackWalker.doStackWalk()
113 static LatestMethodCache _is_substitutable_cache; // ValueObjectMethods.isSubstitutable()
114 static LatestMethodCache _value_object_hash_code_cache; // ValueObjectMethods.valueObjectHashCode()
115
116 // Known objects
117 TypeArrayKlass* Universe::_typeArrayKlasses[T_LONG+1] = { nullptr /*, nullptr...*/ };
118 ObjArrayKlass* Universe::_objectArrayKlass = nullptr;
119 Klass* Universe::_fillerArrayKlass = nullptr;
120 OopHandle Universe::_basic_type_mirrors[T_VOID+1];
121 #if INCLUDE_CDS_JAVA_HEAP
122 int Universe::_archived_basic_type_mirror_indices[T_VOID+1];
123 #endif
124
125 OopHandle Universe::_main_thread_group;
126 OopHandle Universe::_system_thread_group;
127 OopHandle Universe::_the_empty_class_array;
128 OopHandle Universe::_the_null_string;
129 OopHandle Universe::_the_min_jint_string;
130
131 OopHandle Universe::_the_null_sentinel;
132
133 // _out_of_memory_errors is an objArray
134 enum OutOfMemoryInstance { _oom_java_heap,
437 }
438
439 vmSymbols::initialize();
440
441 SystemDictionary::initialize(CHECK);
442
443 // Create string constants
444 oop s = StringTable::intern("null", CHECK);
445 _the_null_string = OopHandle(vm_global(), s);
446 s = StringTable::intern("-2147483648", CHECK);
447 _the_min_jint_string = OopHandle(vm_global(), s);
448
449
450 #if INCLUDE_CDS
451 if (CDSConfig::is_using_archive()) {
452 // Verify shared interfaces array.
453 assert(_the_array_interfaces_array->at(0) ==
454 vmClasses::Cloneable_klass(), "u3");
455 assert(_the_array_interfaces_array->at(1) ==
456 vmClasses::Serializable_klass(), "u3");
457
458 } else
459 #endif
460 {
461 // Set up shared interfaces array. (Do this before supers are set up.)
462 _the_array_interfaces_array->at_put(0, vmClasses::Cloneable_klass());
463 _the_array_interfaces_array->at_put(1, vmClasses::Serializable_klass());
464 }
465
466 _the_array_interfaces_bitmap = Klass::compute_secondary_supers_bitmap(_the_array_interfaces_array);
467 _the_empty_klass_bitmap = Klass::compute_secondary_supers_bitmap(_the_empty_klass_array);
468
469 initialize_basic_type_klass(_fillerArrayKlass, CHECK);
470
471 initialize_basic_type_klass(boolArrayKlass(), CHECK);
472 initialize_basic_type_klass(charArrayKlass(), CHECK);
473 initialize_basic_type_klass(floatArrayKlass(), CHECK);
474 initialize_basic_type_klass(doubleArrayKlass(), CHECK);
475 initialize_basic_type_klass(byteArrayKlass(), CHECK);
476 initialize_basic_type_klass(shortArrayKlass(), CHECK);
477 initialize_basic_type_klass(intArrayKlass(), CHECK);
871
872 // Initialize CPUTimeCounters object, which must be done before creation of the heap.
873 CPUTimeCounters::initialize();
874
875 ObjLayout::initialize();
876
877 #ifdef _LP64
878 MetaspaceShared::adjust_heap_sizes_for_dumping();
879 #endif // _LP64
880
881 GCConfig::arguments()->initialize_heap_sizes();
882
883 jint status = Universe::initialize_heap();
884 if (status != JNI_OK) {
885 return status;
886 }
887
888 Universe::initialize_tlab();
889
890 Metaspace::global_initialize();
891 // Initialize performance counters for metaspaces
892 MetaspaceCounters::initialize_performance_counters();
893
894 // Checks 'AfterMemoryInit' constraints.
895 if (!JVMFlagLimit::check_all_constraints(JVMFlagConstraintPhase::AfterMemoryInit)) {
896 return JNI_EINVAL;
897 }
898
899 ClassLoaderData::init_null_class_loader_data();
900
901 #if INCLUDE_CDS
902 if (CDSConfig::is_using_archive()) {
903 // Read the data structures supporting the shared spaces (shared
904 // system dictionary, symbol table, etc.)
905 MetaspaceShared::initialize_shared_spaces();
906 }
907 if (CDSConfig::is_dumping_archive()) {
908 CDSConfig::prepare_for_dumping();
909 }
910 #endif
1025 _klass = ik;
1026 _method_idnum = m->method_idnum();
1027 assert(_method_idnum >= 0, "sanity check");
1028 }
1029
1030 Method* LatestMethodCache::get_method() {
1031 if (_klass == nullptr) {
1032 return nullptr;
1033 } else {
1034 Method* m = _klass->method_with_idnum(_method_idnum);
1035 assert(m != nullptr, "sanity check");
1036 return m;
1037 }
1038 }
1039
1040 Method* Universe::finalizer_register_method() { return _finalizer_register_cache.get_method(); }
1041 Method* Universe::loader_addClass_method() { return _loader_addClass_cache.get_method(); }
1042 Method* Universe::throw_illegal_access_error() { return _throw_illegal_access_error_cache.get_method(); }
1043 Method* Universe::throw_no_such_method_error() { return _throw_no_such_method_error_cache.get_method(); }
1044 Method* Universe::do_stack_walk_method() { return _do_stack_walk_cache.get_method(); }
1045 Method* Universe::is_substitutable_method() { return _is_substitutable_cache.get_method(); }
1046 Method* Universe::value_object_hash_code_method() { return _value_object_hash_code_cache.get_method(); }
1047
1048 void Universe::initialize_known_methods(JavaThread* current) {
1049 // Set up static method for registering finalizers
1050 _finalizer_register_cache.init(current,
1051 vmClasses::Finalizer_klass(),
1052 "register",
1053 vmSymbols::object_void_signature(), true);
1054
1055 _throw_illegal_access_error_cache.init(current,
1056 vmClasses::internal_Unsafe_klass(),
1057 "throwIllegalAccessError",
1058 vmSymbols::void_method_signature(), true);
1059
1060 _throw_no_such_method_error_cache.init(current,
1061 vmClasses::internal_Unsafe_klass(),
1062 "throwNoSuchMethodError",
1063 vmSymbols::void_method_signature(), true);
1064
1065 // Set up method for registering loaded classes in class loader vector
1066 _loader_addClass_cache.init(current,
1067 vmClasses::ClassLoader_klass(),
1068 "addClass",
1069 vmSymbols::class_void_signature(), false);
1070
1071 // Set up method for stack walking
1072 _do_stack_walk_cache.init(current,
1073 vmClasses::AbstractStackWalker_klass(),
1074 "doStackWalk",
1075 vmSymbols::doStackWalk_signature(), false);
1076
1077 // Set up substitutability testing
1078 ResourceMark rm(current);
1079 _is_substitutable_cache.init(current,
1080 vmClasses::ValueObjectMethods_klass(),
1081 vmSymbols::isSubstitutable_name()->as_C_string(),
1082 vmSymbols::object_object_boolean_signature(), true);
1083 _value_object_hash_code_cache.init(current,
1084 vmClasses::ValueObjectMethods_klass(),
1085 vmSymbols::valueObjectHashCode_name()->as_C_string(),
1086 vmSymbols::object_int_signature(), true);
1087 }
1088
1089 void universe2_init() {
1090 EXCEPTION_MARK;
1091 Universe::genesis(CATCH);
1092 }
1093
1094 // Set after initialization of the module runtime, call_initModuleRuntime
1095 void universe_post_module_init() {
1096 Universe::_module_initialized = true;
1097 }
1098
1099 bool universe_post_init() {
1100 assert(!is_init_completed(), "Error: initialization not yet completed!");
1101 Universe::_fully_initialized = true;
1102 EXCEPTION_MARK;
1103 if (!CDSConfig::is_using_archive()) {
1104 reinitialize_vtables();
1105 reinitialize_itables();
1106 }
|