@@ -93,6 +93,13 @@ Klass* Universe::_fillerArrayKlassObj = nullptr;
93
93
OopHandle Universe::_basic_type_mirrors[T_VOID+1 ];
94
94
#if INCLUDE_CDS_JAVA_HEAP
95
95
int Universe::_archived_basic_type_mirror_indices[T_VOID+1 ];
96
+
97
+ int Universe::_archived_null_ptr_exception_instance_index;
98
+ int Universe::_archived_arithmetic_exception_instance_index;
99
+ int Universe::_archived_virtual_machine_error_instance_index;
100
+ int Universe::_archived_array_index_oob_exception_instance_index;
101
+ int Universe::_archived_array_store_exception_instance_index;
102
+ int Universe::_archived_class_cast_exception_instance_index;
96
103
#endif
97
104
98
105
OopHandle Universe::_main_thread_group;
@@ -129,6 +136,10 @@ OopHandle Universe::_null_ptr_exception_instance;
129
136
OopHandle Universe::_arithmetic_exception_instance;
130
137
OopHandle Universe::_virtual_machine_error_instance;
131
138
139
+ OopHandle Universe::_array_index_oob_exception_instance;
140
+ OopHandle Universe::_array_store_exception_instance;
141
+ OopHandle Universe::_class_cast_exception_instance;
142
+
132
143
OopHandle Universe::_reference_pending_list;
133
144
134
145
Array<Klass*>* Universe::_the_array_interfaces_array = nullptr ;
@@ -184,6 +195,10 @@ oop Universe::null_ptr_exception_instance() { return _null_ptr_exception_i
184
195
oop Universe::arithmetic_exception_instance () { return _arithmetic_exception_instance.resolve (); }
185
196
oop Universe::virtual_machine_error_instance () { return _virtual_machine_error_instance.resolve (); }
186
197
198
+ oop Universe::array_index_oob_exception_instance () { return _array_index_oob_exception_instance.resolve (); }
199
+ oop Universe::array_store_exception_instance () { return _array_store_exception_instance.resolve (); }
200
+ oop Universe::class_cast_exception_instance () { return _class_cast_exception_instance.resolve (); }
201
+
187
202
oop Universe::the_null_sentinel () { return _the_null_sentinel.resolve (); }
188
203
189
204
oop Universe::int_mirror () { return check_mirror (_basic_type_mirrors[T_INT].resolve ()); }
@@ -257,6 +272,41 @@ void Universe::update_archived_basic_type_mirrors() {
257
272
}
258
273
}
259
274
}
275
+
276
+ void Universe::update_exception_instances () {
277
+ if (ArchiveHeapLoader::is_in_use ()) {
278
+ if (_archived_null_ptr_exception_instance_index >= 0 ) {
279
+ oop mirror_oop = HeapShared::get_root (_archived_null_ptr_exception_instance_index);
280
+ assert (mirror_oop != nullptr , " must be" );
281
+ _null_ptr_exception_instance = OopHandle (vm_global (), mirror_oop);
282
+ }
283
+ if (_archived_arithmetic_exception_instance_index >= 0 ) {
284
+ oop mirror_oop = HeapShared::get_root (_archived_arithmetic_exception_instance_index);
285
+ assert (mirror_oop != nullptr , " must be" );
286
+ _arithmetic_exception_instance = OopHandle (vm_global (), mirror_oop);
287
+ }
288
+ if (_archived_virtual_machine_error_instance_index >= 0 ) {
289
+ oop mirror_oop = HeapShared::get_root (_archived_virtual_machine_error_instance_index);
290
+ assert (mirror_oop != nullptr , " must be" );
291
+ _virtual_machine_error_instance = OopHandle (vm_global (), mirror_oop);
292
+ }
293
+ if (_archived_array_index_oob_exception_instance_index >= 0 ) {
294
+ oop mirror_oop = HeapShared::get_root (_archived_array_index_oob_exception_instance_index);
295
+ assert (mirror_oop != nullptr , " must be" );
296
+ _array_index_oob_exception_instance = OopHandle (vm_global (), mirror_oop);
297
+ }
298
+ if (_archived_array_store_exception_instance_index >= 0 ) {
299
+ oop mirror_oop = HeapShared::get_root (_archived_array_store_exception_instance_index);
300
+ assert (mirror_oop != nullptr , " must be" );
301
+ _array_store_exception_instance = OopHandle (vm_global (), mirror_oop);
302
+ }
303
+ if (_archived_class_cast_exception_instance_index >= 0 ) {
304
+ oop mirror_oop = HeapShared::get_root (_archived_class_cast_exception_instance_index);
305
+ assert (mirror_oop != nullptr , " must be" );
306
+ _class_cast_exception_instance = OopHandle (vm_global (), mirror_oop);
307
+ }
308
+ }
309
+ }
260
310
#endif
261
311
262
312
void Universe::serialize (SerializeClosure* f) {
@@ -268,6 +318,12 @@ void Universe::serialize(SerializeClosure* f) {
268
318
// contents may need to be relocated. _basic_type_mirrors[i] will be
269
319
// updated later in Universe::update_archived_basic_type_mirrors().
270
320
}
321
+ f->do_int (&_archived_null_ptr_exception_instance_index);
322
+ f->do_int (&_archived_arithmetic_exception_instance_index);
323
+ f->do_int (&_archived_virtual_machine_error_instance_index);
324
+ f->do_int (&_archived_array_index_oob_exception_instance_index);
325
+ f->do_int (&_archived_array_store_exception_instance_index);
326
+ f->do_int (&_archived_class_cast_exception_instance_index);
271
327
#endif
272
328
273
329
f->do_ptr (&_fillerArrayKlassObj);
@@ -1011,29 +1067,50 @@ bool universe_post_init() {
1011
1067
instance = java_lang_String::create_oop_from_str (" Delayed StackOverflowError due to ReservedStackAccess annotated method" , CHECK_false);
1012
1068
Universe::_delayed_stack_overflow_error_message = OopHandle (Universe::vm_global (), instance);
1013
1069
}
1070
+ if (Universe::_null_ptr_exception_instance.is_empty ()) {
1071
+ instance = java_lang_Throwable::create_exception_instance (vmSymbols::java_lang_NullPointerException (), CHECK_false);
1072
+ Universe::_null_ptr_exception_instance = OopHandle (Universe::vm_global (), instance);
1073
+ Universe::_archived_null_ptr_exception_instance_index = -1 ;
1074
+ }
1075
+ if (Universe::_arithmetic_exception_instance.is_empty ()) {
1076
+ instance = java_lang_Throwable::create_exception_instance (vmSymbols::java_lang_ArithmeticException (), CHECK_false);
1077
+ Universe::_arithmetic_exception_instance = OopHandle (Universe::vm_global (), instance);
1078
+ Universe::_archived_arithmetic_exception_instance_index = -1 ;
1079
+ }
1080
+ // #ifdef COMPILER1_OR_COMPILER2_PRESENT
1081
+ if (Universe::_array_index_oob_exception_instance.is_empty ()) {
1082
+ instance = java_lang_Throwable::create_exception_instance (vmSymbols::java_lang_ArrayIndexOutOfBoundsException (), CHECK_false);
1083
+ Universe::_array_index_oob_exception_instance = OopHandle (Universe::vm_global (), instance);
1084
+ Universe::_archived_array_index_oob_exception_instance_index = -1 ;
1085
+ }
1086
+ if (Universe::_array_store_exception_instance.is_empty ()) {
1087
+ instance = java_lang_Throwable::create_exception_instance (vmSymbols::java_lang_ArrayStoreException (), CHECK_false);
1088
+ Universe::_array_store_exception_instance = OopHandle (Universe::vm_global (), instance);
1089
+ Universe::_archived_array_store_exception_instance_index = -1 ;
1090
+ }
1091
+ if (Universe::_class_cast_exception_instance.is_empty ()) {
1092
+ instance = java_lang_Throwable::create_exception_instance (vmSymbols::java_lang_ClassCastException (), CHECK_false);
1093
+ Universe::_class_cast_exception_instance = OopHandle (Universe::vm_global (), instance);
1094
+ Universe::_archived_class_cast_exception_instance_index = -1 ;
1095
+ }
1096
+ // #endif // COMPILER1_OR_COMPILER2_PRESENT
1014
1097
1015
- // Setup preallocated NullPointerException
1016
- // (this is currently used for a cheap & dirty solution in compiler exception handling)
1017
- Klass* k = SystemDictionary::resolve_or_fail (vmSymbols::java_lang_NullPointerException (), true , CHECK_false);
1018
- instance = InstanceKlass::cast (k)->allocate_instance (CHECK_false);
1019
- Universe::_null_ptr_exception_instance = OopHandle (Universe::vm_global (), instance);
1020
-
1021
- // Setup preallocated ArithmeticException
1022
- // (this is currently used for a cheap & dirty solution in compiler exception handling)
1023
- k = SystemDictionary::resolve_or_fail (vmSymbols::java_lang_ArithmeticException (), true , CHECK_false);
1024
- instance = InstanceKlass::cast (k)->allocate_instance (CHECK_false);
1025
- Universe::_arithmetic_exception_instance = OopHandle (Universe::vm_global (), instance);
1098
+ if (DumpSharedSpaces) {
1099
+ HeapShared::init_scratch_exceptions (CHECK_false);
1100
+ }
1026
1101
1027
1102
// Virtual Machine Error for when we get into a situation we can't resolve
1028
- k = vmClasses::VirtualMachineError_klass ();
1103
+ Klass* k = vmClasses::VirtualMachineError_klass ();
1029
1104
bool linked = InstanceKlass::cast (k)->link_class_or_fail (CHECK_false);
1030
1105
if (!linked) {
1031
1106
tty->print_cr (" Unable to link/verify VirtualMachineError class" );
1032
1107
return false ; // initialization failed
1033
1108
}
1034
- instance = InstanceKlass::cast (k)->allocate_instance (CHECK_false);
1035
- Universe::_virtual_machine_error_instance = OopHandle (Universe::vm_global (), instance);
1036
-
1109
+ if (Universe::_virtual_machine_error_instance.is_empty ()) {
1110
+ instance = java_lang_Throwable::create_exception_instance (vmSymbols::java_lang_VirtualMachineError (), CHECK_false);
1111
+ Universe::_virtual_machine_error_instance = OopHandle (Universe::vm_global (), instance);
1112
+ Universe::_archived_virtual_machine_error_instance_index = -1 ;
1113
+ }
1037
1114
Handle msg = java_lang_String::create_from_str (" / by zero" , CHECK_false);
1038
1115
java_lang_Throwable::set_message (Universe::arithmetic_exception_instance (), msg ());
1039
1116
0 commit comments