217 void load_from_cds() {
218 if (_archived_root_index >= 0) {
219 oop obj = HeapShared::get_root(_archived_root_index);
220 assert(obj != nullptr, "must be");
221 _instance = OopHandle(Universe::vm_global(), obj);
222 }
223 }
224
225 void serialize(SerializeClosure *f) {
226 f->do_int(&_archived_root_index);
227 }
228 #endif
229 };
230
231 static BuiltinException _null_ptr_exception;
232 static BuiltinException _arithmetic_exception;
233 static BuiltinException _internal_error;
234 static BuiltinException _array_index_out_of_bounds_exception;
235 static BuiltinException _array_store_exception;
236 static BuiltinException _class_cast_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
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) {
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_out_of_bounds_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_out_of_bounds_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_out_of_bounds_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(
1098
1099 objArrayOop the_empty_class_array = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_false);
1100 Universe::_the_empty_class_array = OopHandle(Universe::vm_global(), the_empty_class_array);
1101
1102 // Setup preallocated OutOfMemoryError errors
1103 Universe::create_preallocated_out_of_memory_errors(CHECK_false);
1104
1105 oop instance;
1106 // Setup preallocated cause message for delayed StackOverflowError
1107 if (StackReservedPages > 0) {
1108 instance = java_lang_String::create_oop_from_str("Delayed StackOverflowError due to ReservedStackAccess annotated method", CHECK_false);
1109 Universe::_delayed_stack_overflow_error_message = OopHandle(Universe::vm_global(), instance);
1110 }
1111
1112 // Setup preallocated exceptions used for a cheap & dirty solution in compiler exception handling
1113 _null_ptr_exception.init_if_empty(vmSymbols::java_lang_NullPointerException(), CHECK_false);
1114 _arithmetic_exception.init_if_empty(vmSymbols::java_lang_ArithmeticException(), CHECK_false);
1115 _array_index_out_of_bounds_exception.init_if_empty(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), CHECK_false);
1116 _array_store_exception.init_if_empty(vmSymbols::java_lang_ArrayStoreException(), CHECK_false);
1117 _class_cast_exception.init_if_empty(vmSymbols::java_lang_ClassCastException(), CHECK_false);
1118
1119 // Virtual Machine Error for when we get into a situation we can't resolve
1120 Klass* k = vmClasses::InternalError_klass();
1121 bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false);
1122 if (!linked) {
1123 tty->print_cr("Unable to link/verify InternalError class");
1124 return false; // initialization failed
1125 }
1126 _internal_error.init_if_empty(vmSymbols::java_lang_InternalError(), CHECK_false);
1127
1128 Handle msg = java_lang_String::create_from_str("/ by zero", CHECK_false);
1129 java_lang_Throwable::set_message(Universe::arithmetic_exception_instance(), msg());
1130
1131 // Setup preallocated StackOverflowError for use with class initialization failure
1132 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_StackOverflowError(), true, CHECK_false);
1133 instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
1134 Universe::_class_init_stack_overflow_error = OopHandle(Universe::vm_global(), instance);
1135
1136 Universe::initialize_known_methods(THREAD);
1137
|
217 void load_from_cds() {
218 if (_archived_root_index >= 0) {
219 oop obj = HeapShared::get_root(_archived_root_index);
220 assert(obj != nullptr, "must be");
221 _instance = OopHandle(Universe::vm_global(), obj);
222 }
223 }
224
225 void serialize(SerializeClosure *f) {
226 f->do_int(&_archived_root_index);
227 }
228 #endif
229 };
230
231 static BuiltinException _null_ptr_exception;
232 static BuiltinException _arithmetic_exception;
233 static BuiltinException _internal_error;
234 static BuiltinException _array_index_out_of_bounds_exception;
235 static BuiltinException _array_store_exception;
236 static BuiltinException _class_cast_exception;
237 static BuiltinException _preempted_exception;
238
239 objArrayOop Universe::the_empty_class_array () {
240 return (objArrayOop)_the_empty_class_array.resolve();
241 }
242
243 oop Universe::main_thread_group() { return _main_thread_group.resolve(); }
244 void Universe::set_main_thread_group(oop group) { _main_thread_group = OopHandle(vm_global(), group); }
245
246 oop Universe::system_thread_group() { return _system_thread_group.resolve(); }
247 void Universe::set_system_thread_group(oop group) { _system_thread_group = OopHandle(vm_global(), group); }
248
249 oop Universe::the_null_string() { return _the_null_string.resolve(); }
250 oop Universe::the_min_jint_string() { return _the_min_jint_string.resolve(); }
251
252 oop Universe::null_ptr_exception_instance() { return _null_ptr_exception.instance(); }
253 oop Universe::arithmetic_exception_instance() { return _arithmetic_exception.instance(); }
254 oop Universe::internal_error_instance() { return _internal_error.instance(); }
255 oop Universe::array_index_out_of_bounds_exception_instance() { return _array_index_out_of_bounds_exception.instance(); }
256 oop Universe::array_store_exception_instance() { return _array_store_exception.instance(); }
257 oop Universe::class_cast_exception_instance() { return _class_cast_exception.instance(); }
258 oop Universe::preempted_exception_instance() { return _preempted_exception.instance(); }
259
260 oop Universe::the_null_sentinel() { return _the_null_sentinel.resolve(); }
261
262 oop Universe::int_mirror() { return check_mirror(_basic_type_mirrors[T_INT].resolve()); }
263 oop Universe::float_mirror() { return check_mirror(_basic_type_mirrors[T_FLOAT].resolve()); }
264 oop Universe::double_mirror() { return check_mirror(_basic_type_mirrors[T_DOUBLE].resolve()); }
265 oop Universe::byte_mirror() { return check_mirror(_basic_type_mirrors[T_BYTE].resolve()); }
266 oop Universe::bool_mirror() { return check_mirror(_basic_type_mirrors[T_BOOLEAN].resolve()); }
267 oop Universe::char_mirror() { return check_mirror(_basic_type_mirrors[T_CHAR].resolve()); }
268 oop Universe::long_mirror() { return check_mirror(_basic_type_mirrors[T_LONG].resolve()); }
269 oop Universe::short_mirror() { return check_mirror(_basic_type_mirrors[T_SHORT].resolve()); }
270 oop Universe::void_mirror() { return check_mirror(_basic_type_mirrors[T_VOID].resolve()); }
271
272 oop Universe::java_mirror(BasicType t) {
273 assert((uint)t < T_VOID+1, "range check");
274 assert(!is_reference_type(t), "sanity");
275 return check_mirror(_basic_type_mirrors[t].resolve());
276 }
277
278 void Universe::basic_type_classes_do(KlassClosure *closure) {
298 it->push(&_the_empty_klass_array);
299 it->push(&_the_empty_instance_klass_array);
300 it->push(&_the_empty_method_array);
301 it->push(&_the_array_interfaces_array);
302 }
303
304 #if INCLUDE_CDS_JAVA_HEAP
305 void Universe::set_archived_basic_type_mirror_index(BasicType t, int index) {
306 assert(CDSConfig::is_dumping_heap(), "sanity");
307 assert(!is_reference_type(t), "sanity");
308 _archived_basic_type_mirror_indices[t] = index;
309 }
310
311 void Universe::archive_exception_instances() {
312 _null_ptr_exception.store_in_cds();
313 _arithmetic_exception.store_in_cds();
314 _internal_error.store_in_cds();
315 _array_index_out_of_bounds_exception.store_in_cds();
316 _array_store_exception.store_in_cds();
317 _class_cast_exception.store_in_cds();
318 _preempted_exception.store_in_cds();
319 }
320
321 void Universe::load_archived_object_instances() {
322 if (ArchiveHeapLoader::is_in_use()) {
323 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
324 int index = _archived_basic_type_mirror_indices[i];
325 if (!is_reference_type((BasicType)i) && index >= 0) {
326 oop mirror_oop = HeapShared::get_root(index);
327 assert(mirror_oop != nullptr, "must be");
328 _basic_type_mirrors[i] = OopHandle(vm_global(), mirror_oop);
329 }
330 }
331
332 _null_ptr_exception.load_from_cds();
333 _arithmetic_exception.load_from_cds();
334 _internal_error.load_from_cds();
335 _array_index_out_of_bounds_exception.load_from_cds();
336 _array_store_exception.load_from_cds();
337 _class_cast_exception.load_from_cds();
338 _preempted_exception.load_from_cds();
339 }
340 }
341 #endif
342
343 void Universe::serialize(SerializeClosure* f) {
344
345 #if INCLUDE_CDS_JAVA_HEAP
346 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
347 f->do_int(&_archived_basic_type_mirror_indices[i]);
348 // if f->reading(): We can't call HeapShared::get_root() yet, as the heap
349 // contents may need to be relocated. _basic_type_mirrors[i] will be
350 // updated later in Universe::load_archived_object_instances().
351 }
352 _null_ptr_exception.serialize(f);
353 _arithmetic_exception.serialize(f);
354 _internal_error.serialize(f);
355 _array_index_out_of_bounds_exception.serialize(f);
356 _array_store_exception.serialize(f);
357 _class_cast_exception.serialize(f);
358 _preempted_exception.serialize(f);
359 #endif
360
361 f->do_ptr(&_fillerArrayKlass);
362 for (int i = 0; i < T_LONG+1; i++) {
363 f->do_ptr(&_typeArrayKlasses[i]);
364 }
365
366 f->do_ptr(&_objectArrayKlass);
367 f->do_ptr(&_the_array_interfaces_array);
368 f->do_ptr(&_the_empty_int_array);
369 f->do_ptr(&_the_empty_short_array);
370 f->do_ptr(&_the_empty_method_array);
371 f->do_ptr(&_the_empty_klass_array);
372 f->do_ptr(&_the_empty_instance_klass_array);
373 }
374
375
376 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
377 if (size < alignment || size % alignment != 0) {
378 vm_exit_during_initialization(
1103
1104 objArrayOop the_empty_class_array = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_false);
1105 Universe::_the_empty_class_array = OopHandle(Universe::vm_global(), the_empty_class_array);
1106
1107 // Setup preallocated OutOfMemoryError errors
1108 Universe::create_preallocated_out_of_memory_errors(CHECK_false);
1109
1110 oop instance;
1111 // Setup preallocated cause message for delayed StackOverflowError
1112 if (StackReservedPages > 0) {
1113 instance = java_lang_String::create_oop_from_str("Delayed StackOverflowError due to ReservedStackAccess annotated method", CHECK_false);
1114 Universe::_delayed_stack_overflow_error_message = OopHandle(Universe::vm_global(), instance);
1115 }
1116
1117 // Setup preallocated exceptions used for a cheap & dirty solution in compiler exception handling
1118 _null_ptr_exception.init_if_empty(vmSymbols::java_lang_NullPointerException(), CHECK_false);
1119 _arithmetic_exception.init_if_empty(vmSymbols::java_lang_ArithmeticException(), CHECK_false);
1120 _array_index_out_of_bounds_exception.init_if_empty(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), CHECK_false);
1121 _array_store_exception.init_if_empty(vmSymbols::java_lang_ArrayStoreException(), CHECK_false);
1122 _class_cast_exception.init_if_empty(vmSymbols::java_lang_ClassCastException(), CHECK_false);
1123 _preempted_exception.init_if_empty(vmSymbols::jdk_internal_vm_PreemptedException(), CHECK_false);
1124
1125 // Virtual Machine Error for when we get into a situation we can't resolve
1126 Klass* k = vmClasses::InternalError_klass();
1127 bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false);
1128 if (!linked) {
1129 tty->print_cr("Unable to link/verify InternalError class");
1130 return false; // initialization failed
1131 }
1132 _internal_error.init_if_empty(vmSymbols::java_lang_InternalError(), CHECK_false);
1133
1134 Handle msg = java_lang_String::create_from_str("/ by zero", CHECK_false);
1135 java_lang_Throwable::set_message(Universe::arithmetic_exception_instance(), msg());
1136
1137 // Setup preallocated StackOverflowError for use with class initialization failure
1138 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_StackOverflowError(), true, CHECK_false);
1139 instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
1140 Universe::_class_init_stack_overflow_error = OopHandle(Universe::vm_global(), instance);
1141
1142 Universe::initialize_known_methods(THREAD);
1143
|