< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page

 776     }
 777   }
 778   st->print("\"");
 779 }
 780 
 781 // java_lang_Class
 782 
 783 int java_lang_Class::_klass_offset;
 784 int java_lang_Class::_array_klass_offset;
 785 int java_lang_Class::_oop_size_offset;
 786 int java_lang_Class::_static_oop_field_count_offset;
 787 int java_lang_Class::_class_loader_offset;
 788 int java_lang_Class::_module_offset;
 789 int java_lang_Class::_protection_domain_offset;
 790 int java_lang_Class::_component_mirror_offset;
 791 int java_lang_Class::_signers_offset;
 792 int java_lang_Class::_name_offset;
 793 int java_lang_Class::_source_file_offset;
 794 int java_lang_Class::_classData_offset;
 795 int java_lang_Class::_classRedefinedCount_offset;

 796 
 797 bool java_lang_Class::_offsets_computed = false;
 798 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = nullptr;
 799 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = nullptr;
 800 
 801 #ifdef ASSERT
 802 inline static void assert_valid_static_string_field(fieldDescriptor* fd) {
 803   assert(fd->has_initial_value(), "caller should have checked this");
 804   assert(fd->field_type() == T_OBJECT, "caller should have checked this");
 805   assert(fd->signature() == vmSymbols::string_signature(), "just checking");
 806 }
 807 #endif
 808 
 809 static void initialize_static_string_field(fieldDescriptor* fd, Handle mirror, TRAPS) {
 810   DEBUG_ONLY(assert_valid_static_string_field(fd);)
 811   oop string = fd->string_initial_value(CHECK);
 812   mirror()->obj_field_put(fd->offset(), string);
 813 }
 814 
 815 static void initialize_static_primitive_field(fieldDescriptor* fd, Handle mirror) {

1197 }
1198 
1199 objArrayOop java_lang_Class::signers(oop java_class) {
1200   assert(_signers_offset != 0, "must be set");
1201   return (objArrayOop)java_class->obj_field(_signers_offset);
1202 }
1203 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1204   assert(_signers_offset != 0, "must be set");
1205   java_class->obj_field_put(_signers_offset, signers);
1206 }
1207 
1208 oop java_lang_Class::class_data(oop java_class) {
1209   assert(_classData_offset != 0, "must be set");
1210   return java_class->obj_field(_classData_offset);
1211 }
1212 void java_lang_Class::set_class_data(oop java_class, oop class_data) {
1213   assert(_classData_offset != 0, "must be set");
1214   java_class->obj_field_put(_classData_offset, class_data);
1215 }
1216 














1217 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1218   assert(_class_loader_offset != 0, "offsets should have been initialized");
1219   java_class->obj_field_put(_class_loader_offset, loader);
1220 }
1221 
1222 oop java_lang_Class::class_loader(oop java_class) {
1223   assert(_class_loader_offset != 0, "must be set");
1224   return java_class->obj_field(_class_loader_offset);
1225 }
1226 
1227 oop java_lang_Class::module(oop java_class) {
1228   assert(_module_offset != 0, "must be set");
1229   return java_class->obj_field(_module_offset);
1230 }
1231 
1232 void java_lang_Class::set_module(oop java_class, oop module) {
1233   assert(_module_offset != 0, "must be set");
1234   java_class->obj_field_put(_module_offset, module);
1235 }
1236 

1386     if (reference_klass != nullptr)
1387       (*reference_klass) = as_Klass(java_class);
1388     return T_OBJECT;
1389   }
1390 }
1391 
1392 
1393 oop java_lang_Class::primitive_mirror(BasicType t) {
1394   oop mirror = Universe::java_mirror(t);
1395   assert(mirror != nullptr && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1396   assert(is_primitive(mirror), "must be primitive");
1397   return mirror;
1398 }
1399 
1400 #define CLASS_FIELDS_DO(macro) \
1401   macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false); \
1402   macro(_class_loader_offset,        k, "classLoader",         classloader_signature, false); \
1403   macro(_component_mirror_offset,    k, "componentType",       class_signature,       false); \
1404   macro(_module_offset,              k, "module",              module_signature,      false); \
1405   macro(_name_offset,                k, "name",                string_signature,      false); \
1406   macro(_classData_offset,           k, "classData",           object_signature,      false);

1407 
1408 void java_lang_Class::compute_offsets() {
1409   if (_offsets_computed) {
1410     return;
1411   }
1412 
1413   _offsets_computed = true;
1414 
1415   InstanceKlass* k = vmClasses::Class_klass();
1416   CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1417 
1418   CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1419 }
1420 
1421 #if INCLUDE_CDS
1422 void java_lang_Class::serialize_offsets(SerializeClosure* f) {
1423   f->do_bool(&_offsets_computed);
1424 
1425   CLASS_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
1426 

2086   oop detailed_message = java_lang_Throwable::message(throwable);
2087   if (detailed_message != nullptr) {
2088     return java_lang_String::as_symbol(detailed_message);
2089   }
2090   return nullptr;
2091 }
2092 
2093 void java_lang_Throwable::set_message(oop throwable, oop value) {
2094   throwable->obj_field_put(_detailMessage_offset, value);
2095 }
2096 
2097 
2098 void java_lang_Throwable::set_stacktrace(oop throwable, oop st_element_array) {
2099   throwable->obj_field_put(_stackTrace_offset, st_element_array);
2100 }
2101 
2102 void java_lang_Throwable::clear_stacktrace(oop throwable) {
2103   set_stacktrace(throwable, nullptr);
2104 }
2105 




2106 
2107 void java_lang_Throwable::print(oop throwable, outputStream* st) {
2108   ResourceMark rm;
2109   Klass* k = throwable->klass();
2110   assert(k != nullptr, "just checking");
2111   st->print("%s", k->external_name());
2112   oop msg = message(throwable);
2113   if (msg != nullptr) {
2114     st->print(": %s", java_lang_String::as_utf8_string(msg));
2115   }
2116 }
2117 
2118 // After this many redefines, the stack trace is unreliable.
2119 const int MAX_VERSION = USHRT_MAX;
2120 
2121 static inline bool version_matches(Method* method, int version) {
2122   assert(version < MAX_VERSION, "version is too big");
2123   return method != nullptr && (method->constants()->version() == version);
2124 }
2125 

5337 
5338   // We have already called the compute_offsets() of the
5339   // BASIC_JAVA_CLASSES_DO_PART1 classes (java_lang_String, java_lang_Class and
5340   // java_lang_ref_Reference) earlier inside vmClasses::resolve_all()
5341   BASIC_JAVA_CLASSES_DO_PART2(DO_COMPUTE_OFFSETS);
5342 }
5343 
5344 #if INCLUDE_CDS
5345 #define DO_SERIALIZE_OFFSETS(k) k::serialize_offsets(soc);
5346 
5347 void JavaClasses::serialize_offsets(SerializeClosure* soc) {
5348   BASIC_JAVA_CLASSES_DO(DO_SERIALIZE_OFFSETS);
5349 }
5350 #endif
5351 
5352 #if INCLUDE_CDS_JAVA_HEAP
5353 bool JavaClasses::is_supported_for_archiving(oop obj) {
5354   Klass* klass = obj->klass();
5355 
5356   if (klass == vmClasses::ClassLoader_klass() ||  // ClassLoader::loader_data is malloc'ed.

5357       // The next 3 classes are used to implement java.lang.invoke, and are not used directly in
5358       // regular Java code. The implementation of java.lang.invoke uses generated hidden classes
5359       // (e.g., as referenced by ResolvedMethodName::vmholder) that are not yet supported by CDS.
5360       // So for now we cannot not support these classes for archiving.
5361       //
5362       // These objects typically are not referenced by static fields, but rather by resolved
5363       // constant pool entries, so excluding them shouldn't affect the archiving of static fields.
5364       klass == vmClasses::ResolvedMethodName_klass() ||
5365       klass == vmClasses::MemberName_klass() ||
5366       klass == vmClasses::Context_klass() ||

5367       // It's problematic to archive Reference objects. One of the reasons is that
5368       // Reference::discovered may pull in unwanted objects (see JDK-8284336)
5369       klass->is_subclass_of(vmClasses::Reference_klass())) {
5370     return false;
5371   }
5372 
5373   return true;
5374 }
5375 #endif
5376 
5377 #ifndef PRODUCT
5378 
5379 // These functions exist to assert the validity of de-serialized offsets in boxing object as a sanity check.
5380 
5381 bool JavaClasses::check_offset(const char *klass_name, int deserialized_offset, const char *field_name,
5382                                const char* field_sig) {
5383   EXCEPTION_MARK;
5384   fieldDescriptor fd;
5385   TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name);
5386   Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);

 776     }
 777   }
 778   st->print("\"");
 779 }
 780 
 781 // java_lang_Class
 782 
 783 int java_lang_Class::_klass_offset;
 784 int java_lang_Class::_array_klass_offset;
 785 int java_lang_Class::_oop_size_offset;
 786 int java_lang_Class::_static_oop_field_count_offset;
 787 int java_lang_Class::_class_loader_offset;
 788 int java_lang_Class::_module_offset;
 789 int java_lang_Class::_protection_domain_offset;
 790 int java_lang_Class::_component_mirror_offset;
 791 int java_lang_Class::_signers_offset;
 792 int java_lang_Class::_name_offset;
 793 int java_lang_Class::_source_file_offset;
 794 int java_lang_Class::_classData_offset;
 795 int java_lang_Class::_classRedefinedCount_offset;
 796 int java_lang_Class::_reflectionData_offset;
 797 
 798 bool java_lang_Class::_offsets_computed = false;
 799 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = nullptr;
 800 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = nullptr;
 801 
 802 #ifdef ASSERT
 803 inline static void assert_valid_static_string_field(fieldDescriptor* fd) {
 804   assert(fd->has_initial_value(), "caller should have checked this");
 805   assert(fd->field_type() == T_OBJECT, "caller should have checked this");
 806   assert(fd->signature() == vmSymbols::string_signature(), "just checking");
 807 }
 808 #endif
 809 
 810 static void initialize_static_string_field(fieldDescriptor* fd, Handle mirror, TRAPS) {
 811   DEBUG_ONLY(assert_valid_static_string_field(fd);)
 812   oop string = fd->string_initial_value(CHECK);
 813   mirror()->obj_field_put(fd->offset(), string);
 814 }
 815 
 816 static void initialize_static_primitive_field(fieldDescriptor* fd, Handle mirror) {

1198 }
1199 
1200 objArrayOop java_lang_Class::signers(oop java_class) {
1201   assert(_signers_offset != 0, "must be set");
1202   return (objArrayOop)java_class->obj_field(_signers_offset);
1203 }
1204 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
1205   assert(_signers_offset != 0, "must be set");
1206   java_class->obj_field_put(_signers_offset, signers);
1207 }
1208 
1209 oop java_lang_Class::class_data(oop java_class) {
1210   assert(_classData_offset != 0, "must be set");
1211   return java_class->obj_field(_classData_offset);
1212 }
1213 void java_lang_Class::set_class_data(oop java_class, oop class_data) {
1214   assert(_classData_offset != 0, "must be set");
1215   java_class->obj_field_put(_classData_offset, class_data);
1216 }
1217 
1218 oop java_lang_Class::reflection_data(oop java_class) {
1219   assert(_reflectionData_offset != 0, "must be set");
1220   return java_class->obj_field(_reflectionData_offset);
1221 }
1222 
1223 bool java_lang_Class::has_reflection_data(oop java_class) {
1224   return (java_lang_Class::reflection_data(java_class) != nullptr);
1225 }
1226 
1227 void java_lang_Class::set_reflection_data(oop java_class, oop reflection_data) {
1228   assert(_reflectionData_offset != 0, "must be set");
1229   java_class->obj_field_put(_reflectionData_offset, reflection_data);
1230 }
1231 
1232 void java_lang_Class::set_class_loader(oop java_class, oop loader) {
1233   assert(_class_loader_offset != 0, "offsets should have been initialized");
1234   java_class->obj_field_put(_class_loader_offset, loader);
1235 }
1236 
1237 oop java_lang_Class::class_loader(oop java_class) {
1238   assert(_class_loader_offset != 0, "must be set");
1239   return java_class->obj_field(_class_loader_offset);
1240 }
1241 
1242 oop java_lang_Class::module(oop java_class) {
1243   assert(_module_offset != 0, "must be set");
1244   return java_class->obj_field(_module_offset);
1245 }
1246 
1247 void java_lang_Class::set_module(oop java_class, oop module) {
1248   assert(_module_offset != 0, "must be set");
1249   java_class->obj_field_put(_module_offset, module);
1250 }
1251 

1401     if (reference_klass != nullptr)
1402       (*reference_klass) = as_Klass(java_class);
1403     return T_OBJECT;
1404   }
1405 }
1406 
1407 
1408 oop java_lang_Class::primitive_mirror(BasicType t) {
1409   oop mirror = Universe::java_mirror(t);
1410   assert(mirror != nullptr && mirror->is_a(vmClasses::Class_klass()), "must be a Class");
1411   assert(is_primitive(mirror), "must be primitive");
1412   return mirror;
1413 }
1414 
1415 #define CLASS_FIELDS_DO(macro) \
1416   macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false); \
1417   macro(_class_loader_offset,        k, "classLoader",         classloader_signature, false); \
1418   macro(_component_mirror_offset,    k, "componentType",       class_signature,       false); \
1419   macro(_module_offset,              k, "module",              module_signature,      false); \
1420   macro(_name_offset,                k, "name",                string_signature,      false); \
1421   macro(_classData_offset,           k, "classData",           object_signature,      false); \
1422   macro(_reflectionData_offset,      k, "reflectionData",      class_ReflectionData_signature, false); \
1423 
1424 void java_lang_Class::compute_offsets() {
1425   if (_offsets_computed) {
1426     return;
1427   }
1428 
1429   _offsets_computed = true;
1430 
1431   InstanceKlass* k = vmClasses::Class_klass();
1432   CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1433 
1434   CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
1435 }
1436 
1437 #if INCLUDE_CDS
1438 void java_lang_Class::serialize_offsets(SerializeClosure* f) {
1439   f->do_bool(&_offsets_computed);
1440 
1441   CLASS_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
1442 

2102   oop detailed_message = java_lang_Throwable::message(throwable);
2103   if (detailed_message != nullptr) {
2104     return java_lang_String::as_symbol(detailed_message);
2105   }
2106   return nullptr;
2107 }
2108 
2109 void java_lang_Throwable::set_message(oop throwable, oop value) {
2110   throwable->obj_field_put(_detailMessage_offset, value);
2111 }
2112 
2113 
2114 void java_lang_Throwable::set_stacktrace(oop throwable, oop st_element_array) {
2115   throwable->obj_field_put(_stackTrace_offset, st_element_array);
2116 }
2117 
2118 void java_lang_Throwable::clear_stacktrace(oop throwable) {
2119   set_stacktrace(throwable, nullptr);
2120 }
2121 
2122 oop java_lang_Throwable::create_exception_instance(Symbol* class_name, TRAPS) {
2123   Klass* k = SystemDictionary::resolve_or_fail(class_name, true, CHECK_NULL);
2124   return InstanceKlass::cast(k)->allocate_instance(CHECK_NULL);
2125 }
2126 
2127 void java_lang_Throwable::print(oop throwable, outputStream* st) {
2128   ResourceMark rm;
2129   Klass* k = throwable->klass();
2130   assert(k != nullptr, "just checking");
2131   st->print("%s", k->external_name());
2132   oop msg = message(throwable);
2133   if (msg != nullptr) {
2134     st->print(": %s", java_lang_String::as_utf8_string(msg));
2135   }
2136 }
2137 
2138 // After this many redefines, the stack trace is unreliable.
2139 const int MAX_VERSION = USHRT_MAX;
2140 
2141 static inline bool version_matches(Method* method, int version) {
2142   assert(version < MAX_VERSION, "version is too big");
2143   return method != nullptr && (method->constants()->version() == version);
2144 }
2145 

5357 
5358   // We have already called the compute_offsets() of the
5359   // BASIC_JAVA_CLASSES_DO_PART1 classes (java_lang_String, java_lang_Class and
5360   // java_lang_ref_Reference) earlier inside vmClasses::resolve_all()
5361   BASIC_JAVA_CLASSES_DO_PART2(DO_COMPUTE_OFFSETS);
5362 }
5363 
5364 #if INCLUDE_CDS
5365 #define DO_SERIALIZE_OFFSETS(k) k::serialize_offsets(soc);
5366 
5367 void JavaClasses::serialize_offsets(SerializeClosure* soc) {
5368   BASIC_JAVA_CLASSES_DO(DO_SERIALIZE_OFFSETS);
5369 }
5370 #endif
5371 
5372 #if INCLUDE_CDS_JAVA_HEAP
5373 bool JavaClasses::is_supported_for_archiving(oop obj) {
5374   Klass* klass = obj->klass();
5375 
5376   if (klass == vmClasses::ClassLoader_klass() ||  // ClassLoader::loader_data is malloc'ed.
5377 #if 0
5378       // The next 3 classes are used to implement java.lang.invoke, and are not used directly in
5379       // regular Java code. The implementation of java.lang.invoke uses generated hidden classes
5380       // (e.g., as referenced by ResolvedMethodName::vmholder) that are not yet supported by CDS.
5381       // So for now we cannot not support these classes for archiving.
5382       //
5383       // These objects typically are not referenced by static fields, but rather by resolved
5384       // constant pool entries, so excluding them shouldn't affect the archiving of static fields.
5385       klass == vmClasses::ResolvedMethodName_klass() ||
5386       klass == vmClasses::MemberName_klass() ||
5387       klass == vmClasses::Context_klass() ||
5388 #endif
5389       // It's problematic to archive Reference objects. One of the reasons is that
5390       // Reference::discovered may pull in unwanted objects (see JDK-8284336)
5391       klass->is_subclass_of(vmClasses::Reference_klass())) {
5392     return false;
5393   }
5394 
5395   return true;
5396 }
5397 #endif
5398 
5399 #ifndef PRODUCT
5400 
5401 // These functions exist to assert the validity of de-serialized offsets in boxing object as a sanity check.
5402 
5403 bool JavaClasses::check_offset(const char *klass_name, int deserialized_offset, const char *field_name,
5404                                const char* field_sig) {
5405   EXCEPTION_MARK;
5406   fieldDescriptor fd;
5407   TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name);
5408   Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
< prev index next >