1139 allocate_mirror(k, /*is_scratch=*/false, protection_domain, classData, mirror, comp_mirror, CHECK);
1140
1141 // set the classLoader field in the java_lang_Class instance
1142 assert(class_loader() == k->class_loader(), "should be same");
1143 set_class_loader(mirror(), class_loader());
1144
1145 // Setup indirection from klass->mirror
1146 // after any exceptions can happen during allocations.
1147 k->set_java_mirror(mirror);
1148
1149 // Set the module field in the java_lang_Class instance. This must be done
1150 // after the mirror is set.
1151 set_mirror_module_field(THREAD, k, mirror, module);
1152
1153 if (comp_mirror() != nullptr) {
1154 // Set after k->java_mirror() is published, because compiled code running
1155 // concurrently doesn't expect a k to have a null java_mirror.
1156 release_set_array_klass(comp_mirror(), k);
1157 }
1158 if (CDSConfig::is_dumping_heap()) {
1159 create_scratch_mirror(k, CHECK);
1160 }
1161 } else {
1162 assert(fixup_mirror_list() != nullptr, "fixup_mirror_list not initialized");
1163 fixup_mirror_list()->push(k);
1164 }
1165 }
1166
1167 #if INCLUDE_CDS_JAVA_HEAP
1168 // The "scratch mirror" stores the states of the mirror object that can be
1169 // decided at dump time (such as the initial values of the static fields, the
1170 // component mirror, etc). At runtime, more information is added to it by
1171 // java_lang_Class::restore_archived_mirror().
1172 //
1173 // Essentially, /*dumptime*/create_scratch_mirror() + /*runtime*/restore_archived_mirror()
1174 // produces the same result as /*runtime*/create_mirror().
1175 //
1176 // Note: we archive the "scratch mirror" instead of k->java_mirror(), because the
1177 // latter may contain dumptime-specific information that cannot be archived
1178 // (e.g., ClassLoaderData*, or static fields that are modified by Java code execution).
1179 void java_lang_Class::create_scratch_mirror(Klass* k, TRAPS) {
1180 if (k->class_loader() != nullptr &&
1181 k->class_loader() != SystemDictionary::java_platform_loader() &&
1182 k->class_loader() != SystemDictionary::java_system_loader()) {
1183 // We only archive the mirrors of classes loaded by the built-in loaders
1184 return;
1185 }
1186
1187 Handle protection_domain, classData; // set to null. Will be reinitialized at runtime
1188 Handle mirror;
1189 Handle comp_mirror;
1190 allocate_mirror(k, /*is_scratch=*/true, protection_domain, classData, mirror, comp_mirror, CHECK);
1191
1192 if (comp_mirror() != nullptr) {
1193 release_set_array_klass(comp_mirror(), k);
1194 }
1195
1196 HeapShared::set_scratch_java_mirror(k, mirror());
1197 }
1198
1199 // Returns true if the mirror is updated, false if no archived mirror
1200 // data is present. After the archived mirror object is restored, the
1201 // shared klass' _has_raw_archived_mirror flag is cleared.
1202 bool java_lang_Class::restore_archived_mirror(Klass *k,
1203 Handle class_loader, Handle module,
1204 Handle protection_domain, TRAPS) {
1205 // Postpone restoring archived mirror until java.lang.Class is loaded. Please
1206 // see more details in vmClasses::resolve_all().
1207 if (!vmClasses::Class_klass_loaded()) {
1301 }
1302 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) {
1303 assert(_init_lock_offset != 0, "must be set");
1304 java_class->obj_field_put(_init_lock_offset, init_lock);
1305 }
1306
1307 objArrayOop java_lang_Class::signers(oop java_class) {
1308 assert(_signers_offset != 0, "must be set");
1309 return (objArrayOop)java_class->obj_field(_signers_offset);
1310 }
1311
1312 oop java_lang_Class::class_data(oop java_class) {
1313 assert(_classData_offset != 0, "must be set");
1314 return java_class->obj_field(_classData_offset);
1315 }
1316 void java_lang_Class::set_class_data(oop java_class, oop class_data) {
1317 assert(_classData_offset != 0, "must be set");
1318 java_class->obj_field_put(_classData_offset, class_data);
1319 }
1320
1321 void java_lang_Class::set_reflection_data(oop java_class, oop reflection_data) {
1322 assert(_reflectionData_offset != 0, "must be set");
1323 java_class->obj_field_put(_reflectionData_offset, reflection_data);
1324 }
1325
1326 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1327 assert(_class_loader_offset != 0, "offsets should have been initialized");
1328 java_class->obj_field_put(_class_loader_offset, loader);
1329 }
1330
1331 oop java_lang_Class::class_loader(oop java_class) {
1332 assert(_class_loader_offset != 0, "must be set");
1333 return java_class->obj_field(_class_loader_offset);
1334 }
1335
1336 oop java_lang_Class::module(oop java_class) {
1337 assert(_module_offset != 0, "must be set");
1338 return java_class->obj_field(_module_offset);
1339 }
1340
1505 (*reference_klass) = as_Klass(java_class);
1506 return T_OBJECT;
1507 }
1508 }
1509
1510
1511 oop java_lang_Class::primitive_mirror(BasicType t) {
1512 oop mirror = Universe::java_mirror(t);
1513 assert(mirror != nullptr && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1514 assert(is_primitive(mirror), "must be primitive");
1515 return mirror;
1516 }
1517
1518 #define CLASS_FIELDS_DO(macro) \
1519 macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature, false); \
1520 macro(_class_loader_offset, k, "classLoader", classloader_signature, false); \
1521 macro(_component_mirror_offset, k, "componentType", class_signature, false); \
1522 macro(_module_offset, k, "module", module_signature, false); \
1523 macro(_name_offset, k, "name", string_signature, false); \
1524 macro(_classData_offset, k, "classData", object_signature, false); \
1525 macro(_reflectionData_offset, k, "reflectionData", java_lang_ref_SoftReference_signature, false); \
1526 macro(_signers_offset, k, "signers", object_array_signature, false); \
1527 macro(_modifiers_offset, k, vmSymbols::modifiers_name(), char_signature, false); \
1528 macro(_raw_access_flags_offset, k, "classFileAccessFlags", char_signature, false); \
1529 macro(_protection_domain_offset, k, "protectionDomain", java_security_ProtectionDomain_signature, false); \
1530 macro(_is_primitive_offset, k, "primitive", bool_signature, false);
1531
1532 void java_lang_Class::compute_offsets() {
1533 if (_offsets_computed) {
1534 return;
1535 }
1536
1537 _offsets_computed = true;
1538
1539 InstanceKlass* k = vmClasses::Class_klass();
1540 CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1541 CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1542 }
1543
1544 #if INCLUDE_CDS
1545 void java_lang_Class::serialize_offsets(SerializeClosure* f) {
2323 return msg_utf8;
2324 }
2325
2326 oop java_lang_Throwable::cause(oop throwable) {
2327 return throwable->obj_field(_cause_offset);
2328 }
2329
2330 void java_lang_Throwable::set_message(oop throwable, oop value) {
2331 throwable->obj_field_put(_detailMessage_offset, value);
2332 }
2333
2334
2335 void java_lang_Throwable::set_stacktrace(oop throwable, oop st_element_array) {
2336 throwable->obj_field_put(_stackTrace_offset, st_element_array);
2337 }
2338
2339 void java_lang_Throwable::clear_stacktrace(oop throwable) {
2340 set_stacktrace(throwable, nullptr);
2341 }
2342
2343
2344 void java_lang_Throwable::print(oop throwable, outputStream* st) {
2345 ResourceMark rm;
2346 Klass* k = throwable->klass();
2347 assert(k != nullptr, "just checking");
2348 st->print("%s", k->external_name());
2349 oop msg = message(throwable);
2350 if (msg != nullptr) {
2351 st->print(": %s", java_lang_String::as_utf8_string(msg));
2352 }
2353 }
2354
2355 // After this many redefines, the stack trace is unreliable.
2356 const int MAX_VERSION = USHRT_MAX;
2357
2358 static inline bool version_matches(Method* method, int version) {
2359 assert(version < MAX_VERSION, "version is too big");
2360 return method != nullptr && (method->constants()->version() == version);
2361 }
2362
|
1139 allocate_mirror(k, /*is_scratch=*/false, protection_domain, classData, mirror, comp_mirror, CHECK);
1140
1141 // set the classLoader field in the java_lang_Class instance
1142 assert(class_loader() == k->class_loader(), "should be same");
1143 set_class_loader(mirror(), class_loader());
1144
1145 // Setup indirection from klass->mirror
1146 // after any exceptions can happen during allocations.
1147 k->set_java_mirror(mirror);
1148
1149 // Set the module field in the java_lang_Class instance. This must be done
1150 // after the mirror is set.
1151 set_mirror_module_field(THREAD, k, mirror, module);
1152
1153 if (comp_mirror() != nullptr) {
1154 // Set after k->java_mirror() is published, because compiled code running
1155 // concurrently doesn't expect a k to have a null java_mirror.
1156 release_set_array_klass(comp_mirror(), k);
1157 }
1158 if (CDSConfig::is_dumping_heap()) {
1159 if (CDSConfig::is_dumping_protection_domains()) {
1160 create_scratch_mirror(k, protection_domain, CHECK);
1161 } else {
1162 create_scratch_mirror(k, Handle() /* null protection_domain*/, CHECK);
1163 }
1164 }
1165 } else {
1166 assert(fixup_mirror_list() != nullptr, "fixup_mirror_list not initialized");
1167 fixup_mirror_list()->push(k);
1168 }
1169 }
1170
1171 #if INCLUDE_CDS_JAVA_HEAP
1172 // The "scratch mirror" stores the states of the mirror object that can be
1173 // decided at dump time (such as the initial values of the static fields, the
1174 // component mirror, etc). At runtime, more information is added to it by
1175 // java_lang_Class::restore_archived_mirror().
1176 //
1177 // Essentially, /*dumptime*/create_scratch_mirror() + /*runtime*/restore_archived_mirror()
1178 // produces the same result as /*runtime*/create_mirror().
1179 //
1180 // Note: we archive the "scratch mirror" instead of k->java_mirror(), because the
1181 // latter may contain dumptime-specific information that cannot be archived
1182 // (e.g., ClassLoaderData*, or static fields that are modified by Java code execution).
1183 void java_lang_Class::create_scratch_mirror(Klass* k, Handle protection_domain, TRAPS) {
1184 if (k->class_loader() != nullptr &&
1185 k->class_loader() != SystemDictionary::java_platform_loader() &&
1186 k->class_loader() != SystemDictionary::java_system_loader()) {
1187 // We only archive the mirrors of classes loaded by the built-in loaders
1188 return;
1189 }
1190
1191 Handle classData; // set to null. Will be reinitialized at runtime
1192 Handle mirror;
1193 Handle comp_mirror;
1194 allocate_mirror(k, /*is_scratch=*/true, protection_domain, classData, mirror, comp_mirror, CHECK);
1195
1196 if (comp_mirror() != nullptr) {
1197 release_set_array_klass(comp_mirror(), k);
1198 }
1199
1200 HeapShared::set_scratch_java_mirror(k, mirror());
1201 }
1202
1203 // Returns true if the mirror is updated, false if no archived mirror
1204 // data is present. After the archived mirror object is restored, the
1205 // shared klass' _has_raw_archived_mirror flag is cleared.
1206 bool java_lang_Class::restore_archived_mirror(Klass *k,
1207 Handle class_loader, Handle module,
1208 Handle protection_domain, TRAPS) {
1209 // Postpone restoring archived mirror until java.lang.Class is loaded. Please
1210 // see more details in vmClasses::resolve_all().
1211 if (!vmClasses::Class_klass_loaded()) {
1305 }
1306 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) {
1307 assert(_init_lock_offset != 0, "must be set");
1308 java_class->obj_field_put(_init_lock_offset, init_lock);
1309 }
1310
1311 objArrayOop java_lang_Class::signers(oop java_class) {
1312 assert(_signers_offset != 0, "must be set");
1313 return (objArrayOop)java_class->obj_field(_signers_offset);
1314 }
1315
1316 oop java_lang_Class::class_data(oop java_class) {
1317 assert(_classData_offset != 0, "must be set");
1318 return java_class->obj_field(_classData_offset);
1319 }
1320 void java_lang_Class::set_class_data(oop java_class, oop class_data) {
1321 assert(_classData_offset != 0, "must be set");
1322 java_class->obj_field_put(_classData_offset, class_data);
1323 }
1324
1325 oop java_lang_Class::reflection_data(oop java_class) {
1326 assert(_reflectionData_offset != 0, "must be set");
1327 return java_class->obj_field(_reflectionData_offset);
1328 }
1329
1330 bool java_lang_Class::has_reflection_data(oop java_class) {
1331 return (java_lang_Class::reflection_data(java_class) != nullptr);
1332 }
1333
1334 void java_lang_Class::set_reflection_data(oop java_class, oop reflection_data) {
1335 assert(_reflectionData_offset != 0, "must be set");
1336 java_class->obj_field_put(_reflectionData_offset, reflection_data);
1337 }
1338
1339 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1340 assert(_class_loader_offset != 0, "offsets should have been initialized");
1341 java_class->obj_field_put(_class_loader_offset, loader);
1342 }
1343
1344 oop java_lang_Class::class_loader(oop java_class) {
1345 assert(_class_loader_offset != 0, "must be set");
1346 return java_class->obj_field(_class_loader_offset);
1347 }
1348
1349 oop java_lang_Class::module(oop java_class) {
1350 assert(_module_offset != 0, "must be set");
1351 return java_class->obj_field(_module_offset);
1352 }
1353
1518 (*reference_klass) = as_Klass(java_class);
1519 return T_OBJECT;
1520 }
1521 }
1522
1523
1524 oop java_lang_Class::primitive_mirror(BasicType t) {
1525 oop mirror = Universe::java_mirror(t);
1526 assert(mirror != nullptr && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1527 assert(is_primitive(mirror), "must be primitive");
1528 return mirror;
1529 }
1530
1531 #define CLASS_FIELDS_DO(macro) \
1532 macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature, false); \
1533 macro(_class_loader_offset, k, "classLoader", classloader_signature, false); \
1534 macro(_component_mirror_offset, k, "componentType", class_signature, false); \
1535 macro(_module_offset, k, "module", module_signature, false); \
1536 macro(_name_offset, k, "name", string_signature, false); \
1537 macro(_classData_offset, k, "classData", object_signature, false); \
1538 macro(_reflectionData_offset, k, "reflectionData", class_ReflectionData_signature, false); \
1539 macro(_signers_offset, k, "signers", object_array_signature, false); \
1540 macro(_modifiers_offset, k, vmSymbols::modifiers_name(), char_signature, false); \
1541 macro(_raw_access_flags_offset, k, "classFileAccessFlags", char_signature, false); \
1542 macro(_protection_domain_offset, k, "protectionDomain", java_security_ProtectionDomain_signature, false); \
1543 macro(_is_primitive_offset, k, "primitive", bool_signature, false);
1544
1545 void java_lang_Class::compute_offsets() {
1546 if (_offsets_computed) {
1547 return;
1548 }
1549
1550 _offsets_computed = true;
1551
1552 InstanceKlass* k = vmClasses::Class_klass();
1553 CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1554 CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1555 }
1556
1557 #if INCLUDE_CDS
1558 void java_lang_Class::serialize_offsets(SerializeClosure* f) {
2336 return msg_utf8;
2337 }
2338
2339 oop java_lang_Throwable::cause(oop throwable) {
2340 return throwable->obj_field(_cause_offset);
2341 }
2342
2343 void java_lang_Throwable::set_message(oop throwable, oop value) {
2344 throwable->obj_field_put(_detailMessage_offset, value);
2345 }
2346
2347
2348 void java_lang_Throwable::set_stacktrace(oop throwable, oop st_element_array) {
2349 throwable->obj_field_put(_stackTrace_offset, st_element_array);
2350 }
2351
2352 void java_lang_Throwable::clear_stacktrace(oop throwable) {
2353 set_stacktrace(throwable, nullptr);
2354 }
2355
2356 oop java_lang_Throwable::create_exception_instance(Symbol* class_name, TRAPS) {
2357 Klass* k = SystemDictionary::resolve_or_fail(class_name, true, CHECK_NULL);
2358 return InstanceKlass::cast(k)->allocate_instance(CHECK_NULL);
2359 }
2360
2361 void java_lang_Throwable::print(oop throwable, outputStream* st) {
2362 ResourceMark rm;
2363 Klass* k = throwable->klass();
2364 assert(k != nullptr, "just checking");
2365 st->print("%s", k->external_name());
2366 oop msg = message(throwable);
2367 if (msg != nullptr) {
2368 st->print(": %s", java_lang_String::as_utf8_string(msg));
2369 }
2370 }
2371
2372 // After this many redefines, the stack trace is unreliable.
2373 const int MAX_VERSION = USHRT_MAX;
2374
2375 static inline bool version_matches(Method* method, int version) {
2376 assert(version < MAX_VERSION, "version is too big");
2377 return method != nullptr && (method->constants()->version() == version);
2378 }
2379
|