1122 allocate_mirror(k, /*is_scratch=*/false, protection_domain, classData, mirror, comp_mirror, CHECK);
1123
1124 // set the classLoader field in the java_lang_Class instance
1125 assert(class_loader() == k->class_loader(), "should be same");
1126 set_class_loader(mirror(), class_loader());
1127
1128 // Setup indirection from klass->mirror
1129 // after any exceptions can happen during allocations.
1130 k->set_java_mirror(mirror);
1131
1132 // Set the module field in the java_lang_Class instance. This must be done
1133 // after the mirror is set.
1134 set_mirror_module_field(THREAD, k, mirror, module);
1135
1136 if (comp_mirror() != nullptr) {
1137 // Set after k->java_mirror() is published, because compiled code running
1138 // concurrently doesn't expect a k to have a null java_mirror.
1139 release_set_array_klass(comp_mirror(), k);
1140 }
1141 if (CDSConfig::is_dumping_heap()) {
1142 create_scratch_mirror(k, CHECK);
1143 }
1144 } else {
1145 assert(fixup_mirror_list() != nullptr, "fixup_mirror_list not initialized");
1146 fixup_mirror_list()->push(k);
1147 }
1148 }
1149
1150 #if INCLUDE_CDS_JAVA_HEAP
1151 // The "scratch mirror" stores the states of the mirror object that can be
1152 // decided at dump time (such as the initial values of the static fields, the
1153 // component mirror, etc). At runtime, more information is added to it by
1154 // java_lang_Class::restore_archived_mirror().
1155 //
1156 // Essentially, /*dumptime*/create_scratch_mirror() + /*runtime*/restore_archived_mirror()
1157 // produces the same result as /*runtime*/create_mirror().
1158 //
1159 // Note: we archive the "scratch mirror" instead of k->java_mirror(), because the
1160 // latter may contain dumptime-specific information that cannot be archived
1161 // (e.g., ClassLoaderData*, or static fields that are modified by Java code execution).
1162 void java_lang_Class::create_scratch_mirror(Klass* k, TRAPS) {
1163 if (k->class_loader() != nullptr &&
1164 k->class_loader() != SystemDictionary::java_platform_loader() &&
1165 k->class_loader() != SystemDictionary::java_system_loader()) {
1166 // We only archive the mirrors of classes loaded by the built-in loaders
1167 return;
1168 }
1169
1170 Handle protection_domain, classData; // set to null. Will be reinitialized at runtime
1171 Handle mirror;
1172 Handle comp_mirror;
1173 allocate_mirror(k, /*is_scratch=*/true, protection_domain, classData, mirror, comp_mirror, CHECK);
1174
1175 if (comp_mirror() != nullptr) {
1176 release_set_array_klass(comp_mirror(), k);
1177 }
1178
1179 HeapShared::set_scratch_java_mirror(k, mirror());
1180 }
1181
1182 // Returns true if the mirror is updated, false if no archived mirror
1183 // data is present. After the archived mirror object is restored, the
1184 // shared klass' _has_raw_archived_mirror flag is cleared.
1185 bool java_lang_Class::restore_archived_mirror(Klass *k,
1186 Handle class_loader, Handle module,
1187 Handle protection_domain, TRAPS) {
1188 // Postpone restoring archived mirror until java.lang.Class is loaded. Please
1189 // see more details in vmClasses::resolve_all().
1190 if (!vmClasses::Class_klass_loaded()) {
1281 }
1282 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) {
1283 assert(_init_lock_offset != 0, "must be set");
1284 java_class->obj_field_put(_init_lock_offset, init_lock);
1285 }
1286
1287 objArrayOop java_lang_Class::signers(oop java_class) {
1288 assert(_signers_offset != 0, "must be set");
1289 return (objArrayOop)java_class->obj_field(_signers_offset);
1290 }
1291
1292 oop java_lang_Class::class_data(oop java_class) {
1293 assert(_classData_offset != 0, "must be set");
1294 return java_class->obj_field(_classData_offset);
1295 }
1296 void java_lang_Class::set_class_data(oop java_class, oop class_data) {
1297 assert(_classData_offset != 0, "must be set");
1298 java_class->obj_field_put(_classData_offset, class_data);
1299 }
1300
1301 void java_lang_Class::set_reflection_data(oop java_class, oop reflection_data) {
1302 assert(_reflectionData_offset != 0, "must be set");
1303 java_class->obj_field_put(_reflectionData_offset, reflection_data);
1304 }
1305
1306 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1307 assert(_class_loader_offset != 0, "offsets should have been initialized");
1308 java_class->obj_field_put(_class_loader_offset, loader);
1309 }
1310
1311 oop java_lang_Class::class_loader(oop java_class) {
1312 assert(_class_loader_offset != 0, "must be set");
1313 return java_class->obj_field(_class_loader_offset);
1314 }
1315
1316 oop java_lang_Class::module(oop java_class) {
1317 assert(_module_offset != 0, "must be set");
1318 return java_class->obj_field(_module_offset);
1319 }
1320
1476 (*reference_klass) = as_Klass(java_class);
1477 return T_OBJECT;
1478 }
1479 }
1480
1481
1482 oop java_lang_Class::primitive_mirror(BasicType t) {
1483 oop mirror = Universe::java_mirror(t);
1484 assert(mirror != nullptr && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1485 assert(is_primitive(mirror), "must be primitive");
1486 return mirror;
1487 }
1488
1489 #define CLASS_FIELDS_DO(macro) \
1490 macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature, false); \
1491 macro(_class_loader_offset, k, "classLoader", classloader_signature, false); \
1492 macro(_component_mirror_offset, k, "componentType", class_signature, false); \
1493 macro(_module_offset, k, "module", module_signature, false); \
1494 macro(_name_offset, k, "name", string_signature, false); \
1495 macro(_classData_offset, k, "classData", object_signature, false); \
1496 macro(_reflectionData_offset, k, "reflectionData", java_lang_ref_SoftReference_signature, false); \
1497 macro(_signers_offset, k, "signers", object_array_signature, false);
1498
1499 void java_lang_Class::compute_offsets() {
1500 if (_offsets_computed) {
1501 return;
1502 }
1503
1504 _offsets_computed = true;
1505
1506 InstanceKlass* k = vmClasses::Class_klass();
1507 CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1508 CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1509 }
1510
1511 #if INCLUDE_CDS
1512 void java_lang_Class::serialize_offsets(SerializeClosure* f) {
1513 f->do_bool(&_offsets_computed);
1514
1515 CLASS_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
1516
2272 return msg_utf8;
2273 }
2274
2275 oop java_lang_Throwable::cause(oop throwable) {
2276 return throwable->obj_field(_cause_offset);
2277 }
2278
2279 void java_lang_Throwable::set_message(oop throwable, oop value) {
2280 throwable->obj_field_put(_detailMessage_offset, value);
2281 }
2282
2283
2284 void java_lang_Throwable::set_stacktrace(oop throwable, oop st_element_array) {
2285 throwable->obj_field_put(_stackTrace_offset, st_element_array);
2286 }
2287
2288 void java_lang_Throwable::clear_stacktrace(oop throwable) {
2289 set_stacktrace(throwable, nullptr);
2290 }
2291
2292
2293 void java_lang_Throwable::print(oop throwable, outputStream* st) {
2294 ResourceMark rm;
2295 Klass* k = throwable->klass();
2296 assert(k != nullptr, "just checking");
2297 st->print("%s", k->external_name());
2298 oop msg = message(throwable);
2299 if (msg != nullptr) {
2300 st->print(": %s", java_lang_String::as_utf8_string(msg));
2301 }
2302 }
2303
2304 // After this many redefines, the stack trace is unreliable.
2305 const int MAX_VERSION = USHRT_MAX;
2306
2307 static inline bool version_matches(Method* method, int version) {
2308 assert(version < MAX_VERSION, "version is too big");
2309 return method != nullptr && (method->constants()->version() == version);
2310 }
2311
|
1122 allocate_mirror(k, /*is_scratch=*/false, protection_domain, classData, mirror, comp_mirror, CHECK);
1123
1124 // set the classLoader field in the java_lang_Class instance
1125 assert(class_loader() == k->class_loader(), "should be same");
1126 set_class_loader(mirror(), class_loader());
1127
1128 // Setup indirection from klass->mirror
1129 // after any exceptions can happen during allocations.
1130 k->set_java_mirror(mirror);
1131
1132 // Set the module field in the java_lang_Class instance. This must be done
1133 // after the mirror is set.
1134 set_mirror_module_field(THREAD, k, mirror, module);
1135
1136 if (comp_mirror() != nullptr) {
1137 // Set after k->java_mirror() is published, because compiled code running
1138 // concurrently doesn't expect a k to have a null java_mirror.
1139 release_set_array_klass(comp_mirror(), k);
1140 }
1141 if (CDSConfig::is_dumping_heap()) {
1142 if (CDSConfig::is_dumping_protection_domains()) {
1143 create_scratch_mirror(k, protection_domain, CHECK);
1144 } else {
1145 create_scratch_mirror(k, Handle() /* null protection_domain*/, CHECK);
1146 }
1147 }
1148 } else {
1149 assert(fixup_mirror_list() != nullptr, "fixup_mirror_list not initialized");
1150 fixup_mirror_list()->push(k);
1151 }
1152 }
1153
1154 #if INCLUDE_CDS_JAVA_HEAP
1155 // The "scratch mirror" stores the states of the mirror object that can be
1156 // decided at dump time (such as the initial values of the static fields, the
1157 // component mirror, etc). At runtime, more information is added to it by
1158 // java_lang_Class::restore_archived_mirror().
1159 //
1160 // Essentially, /*dumptime*/create_scratch_mirror() + /*runtime*/restore_archived_mirror()
1161 // produces the same result as /*runtime*/create_mirror().
1162 //
1163 // Note: we archive the "scratch mirror" instead of k->java_mirror(), because the
1164 // latter may contain dumptime-specific information that cannot be archived
1165 // (e.g., ClassLoaderData*, or static fields that are modified by Java code execution).
1166 void java_lang_Class::create_scratch_mirror(Klass* k, Handle protection_domain, TRAPS) {
1167 if (k->class_loader() != nullptr &&
1168 k->class_loader() != SystemDictionary::java_platform_loader() &&
1169 k->class_loader() != SystemDictionary::java_system_loader()) {
1170 // We only archive the mirrors of classes loaded by the built-in loaders
1171 return;
1172 }
1173
1174 Handle classData; // set to null. Will be reinitialized at runtime
1175 Handle mirror;
1176 Handle comp_mirror;
1177 allocate_mirror(k, /*is_scratch=*/true, protection_domain, classData, mirror, comp_mirror, CHECK);
1178
1179 if (comp_mirror() != nullptr) {
1180 release_set_array_klass(comp_mirror(), k);
1181 }
1182
1183 HeapShared::set_scratch_java_mirror(k, mirror());
1184 }
1185
1186 // Returns true if the mirror is updated, false if no archived mirror
1187 // data is present. After the archived mirror object is restored, the
1188 // shared klass' _has_raw_archived_mirror flag is cleared.
1189 bool java_lang_Class::restore_archived_mirror(Klass *k,
1190 Handle class_loader, Handle module,
1191 Handle protection_domain, TRAPS) {
1192 // Postpone restoring archived mirror until java.lang.Class is loaded. Please
1193 // see more details in vmClasses::resolve_all().
1194 if (!vmClasses::Class_klass_loaded()) {
1285 }
1286 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) {
1287 assert(_init_lock_offset != 0, "must be set");
1288 java_class->obj_field_put(_init_lock_offset, init_lock);
1289 }
1290
1291 objArrayOop java_lang_Class::signers(oop java_class) {
1292 assert(_signers_offset != 0, "must be set");
1293 return (objArrayOop)java_class->obj_field(_signers_offset);
1294 }
1295
1296 oop java_lang_Class::class_data(oop java_class) {
1297 assert(_classData_offset != 0, "must be set");
1298 return java_class->obj_field(_classData_offset);
1299 }
1300 void java_lang_Class::set_class_data(oop java_class, oop class_data) {
1301 assert(_classData_offset != 0, "must be set");
1302 java_class->obj_field_put(_classData_offset, class_data);
1303 }
1304
1305 oop java_lang_Class::reflection_data(oop java_class) {
1306 assert(_reflectionData_offset != 0, "must be set");
1307 return java_class->obj_field(_reflectionData_offset);
1308 }
1309
1310 bool java_lang_Class::has_reflection_data(oop java_class) {
1311 return (java_lang_Class::reflection_data(java_class) != nullptr);
1312 }
1313
1314 void java_lang_Class::set_reflection_data(oop java_class, oop reflection_data) {
1315 assert(_reflectionData_offset != 0, "must be set");
1316 java_class->obj_field_put(_reflectionData_offset, reflection_data);
1317 }
1318
1319 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1320 assert(_class_loader_offset != 0, "offsets should have been initialized");
1321 java_class->obj_field_put(_class_loader_offset, loader);
1322 }
1323
1324 oop java_lang_Class::class_loader(oop java_class) {
1325 assert(_class_loader_offset != 0, "must be set");
1326 return java_class->obj_field(_class_loader_offset);
1327 }
1328
1329 oop java_lang_Class::module(oop java_class) {
1330 assert(_module_offset != 0, "must be set");
1331 return java_class->obj_field(_module_offset);
1332 }
1333
1489 (*reference_klass) = as_Klass(java_class);
1490 return T_OBJECT;
1491 }
1492 }
1493
1494
1495 oop java_lang_Class::primitive_mirror(BasicType t) {
1496 oop mirror = Universe::java_mirror(t);
1497 assert(mirror != nullptr && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1498 assert(is_primitive(mirror), "must be primitive");
1499 return mirror;
1500 }
1501
1502 #define CLASS_FIELDS_DO(macro) \
1503 macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature, false); \
1504 macro(_class_loader_offset, k, "classLoader", classloader_signature, false); \
1505 macro(_component_mirror_offset, k, "componentType", class_signature, false); \
1506 macro(_module_offset, k, "module", module_signature, false); \
1507 macro(_name_offset, k, "name", string_signature, false); \
1508 macro(_classData_offset, k, "classData", object_signature, false); \
1509 macro(_reflectionData_offset, k, "reflectionData", class_ReflectionData_signature, false); \
1510 macro(_signers_offset, k, "signers", object_array_signature, false);
1511
1512 void java_lang_Class::compute_offsets() {
1513 if (_offsets_computed) {
1514 return;
1515 }
1516
1517 _offsets_computed = true;
1518
1519 InstanceKlass* k = vmClasses::Class_klass();
1520 CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1521 CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1522 }
1523
1524 #if INCLUDE_CDS
1525 void java_lang_Class::serialize_offsets(SerializeClosure* f) {
1526 f->do_bool(&_offsets_computed);
1527
1528 CLASS_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
1529
2285 return msg_utf8;
2286 }
2287
2288 oop java_lang_Throwable::cause(oop throwable) {
2289 return throwable->obj_field(_cause_offset);
2290 }
2291
2292 void java_lang_Throwable::set_message(oop throwable, oop value) {
2293 throwable->obj_field_put(_detailMessage_offset, value);
2294 }
2295
2296
2297 void java_lang_Throwable::set_stacktrace(oop throwable, oop st_element_array) {
2298 throwable->obj_field_put(_stackTrace_offset, st_element_array);
2299 }
2300
2301 void java_lang_Throwable::clear_stacktrace(oop throwable) {
2302 set_stacktrace(throwable, nullptr);
2303 }
2304
2305 oop java_lang_Throwable::create_exception_instance(Symbol* class_name, TRAPS) {
2306 Klass* k = SystemDictionary::resolve_or_fail(class_name, true, CHECK_NULL);
2307 return InstanceKlass::cast(k)->allocate_instance(CHECK_NULL);
2308 }
2309
2310 void java_lang_Throwable::print(oop throwable, outputStream* st) {
2311 ResourceMark rm;
2312 Klass* k = throwable->klass();
2313 assert(k != nullptr, "just checking");
2314 st->print("%s", k->external_name());
2315 oop msg = message(throwable);
2316 if (msg != nullptr) {
2317 st->print(": %s", java_lang_String::as_utf8_string(msg));
2318 }
2319 }
2320
2321 // After this many redefines, the stack trace is unreliable.
2322 const int MAX_VERSION = USHRT_MAX;
2323
2324 static inline bool version_matches(Method* method, int version) {
2325 assert(version < MAX_VERSION, "version is too big");
2326 return method != nullptr && (method->constants()->version() == version);
2327 }
2328
|