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