comparison src/share/vm/classfile/javaClasses.hpp @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents 1d7922586cf6
children e522a00b91aa bd7a7ce2e264 070d523b96a7
comparison
equal deleted inserted replaced
6724:36d1d483d5d6 6725:da91efe96a93
57 static int count_offset; 57 static int count_offset;
58 static int hash_offset; 58 static int hash_offset;
59 59
60 static bool initialized; 60 static bool initialized;
61 61
62 static Handle basic_create(int length, bool tenured, TRAPS); 62 static Handle basic_create(int length, TRAPS);
63 static Handle basic_create_from_unicode(jchar* unicode, int length, bool tenured, TRAPS);
64 63
65 static void set_value( oop string, typeArrayOop buffer) { 64 static void set_value( oop string, typeArrayOop buffer) {
66 assert(initialized, "Must be initialized"); 65 assert(initialized, "Must be initialized");
67 string->obj_field_put(value_offset, (oop)buffer); 66 string->obj_field_put(value_offset, (oop)buffer);
68 } 67 }
82 public: 81 public:
83 static void compute_offsets(); 82 static void compute_offsets();
84 83
85 // Instance creation 84 // Instance creation
86 static Handle create_from_unicode(jchar* unicode, int len, TRAPS); 85 static Handle create_from_unicode(jchar* unicode, int len, TRAPS);
87 static Handle create_tenured_from_unicode(jchar* unicode, int len, TRAPS);
88 static oop create_oop_from_unicode(jchar* unicode, int len, TRAPS); 86 static oop create_oop_from_unicode(jchar* unicode, int len, TRAPS);
89 static Handle create_from_str(const char* utf8_str, TRAPS); 87 static Handle create_from_str(const char* utf8_str, TRAPS);
90 static oop create_oop_from_str(const char* utf8_str, TRAPS); 88 static oop create_oop_from_str(const char* utf8_str, TRAPS);
91 static Handle create_from_symbol(Symbol* symbol, TRAPS); 89 static Handle create_from_symbol(Symbol* symbol, TRAPS);
92 static Handle create_from_platform_dependent_str(const char* str, TRAPS); 90 static Handle create_from_platform_dependent_str(const char* str, TRAPS);
203 201
204 202
205 // Interface to java.lang.Class objects 203 // Interface to java.lang.Class objects
206 204
207 #define CLASS_INJECTED_FIELDS(macro) \ 205 #define CLASS_INJECTED_FIELDS(macro) \
208 macro(java_lang_Class, klass, object_signature, false) \ 206 macro(java_lang_Class, klass, intptr_signature, false) \
209 macro(java_lang_Class, resolved_constructor, object_signature, false) \ 207 macro(java_lang_Class, resolved_constructor, intptr_signature, false) \
210 macro(java_lang_Class, array_klass, object_signature, false) \ 208 macro(java_lang_Class, array_klass, intptr_signature, false) \
211 macro(java_lang_Class, oop_size, int_signature, false) \ 209 macro(java_lang_Class, oop_size, int_signature, false) \
212 macro(java_lang_Class, static_oop_field_count, int_signature, false) 210 macro(java_lang_Class, static_oop_field_count, int_signature, false)
213 211
214 class java_lang_Class : AllStatic { 212 class java_lang_Class : AllStatic {
215 friend class VMStructs; 213 friend class VMStructs;
224 static int _oop_size_offset; 222 static int _oop_size_offset;
225 static int _static_oop_field_count_offset; 223 static int _static_oop_field_count_offset;
226 224
227 static bool offsets_computed; 225 static bool offsets_computed;
228 static int classRedefinedCount_offset; 226 static int classRedefinedCount_offset;
227 static GrowableArray<Klass*>* _fixup_mirror_list;
229 228
230 public: 229 public:
231 static void compute_offsets(); 230 static void compute_offsets();
232 231
233 // Instance creation 232 // Instance creation
234 static oop create_mirror(KlassHandle k, TRAPS); 233 static oop create_mirror(KlassHandle k, TRAPS);
235 static void fixup_mirror(KlassHandle k, TRAPS); 234 static void fixup_mirror(KlassHandle k, TRAPS);
236 static oop create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS); 235 static oop create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
237 // Conversion 236 // Conversion
238 static klassOop as_klassOop(oop java_class); 237 static Klass* as_Klass(oop java_class);
239 static void set_klass(oop java_class, klassOop klass); 238 static void set_klass(oop java_class, Klass* klass);
240 static BasicType as_BasicType(oop java_class, klassOop* reference_klass = NULL); 239 static BasicType as_BasicType(oop java_class, Klass** reference_klass = NULL);
241 static BasicType as_BasicType(oop java_class, KlassHandle* reference_klass) { 240 static BasicType as_BasicType(oop java_class, KlassHandle* reference_klass) {
242 klassOop refk_oop = NULL; 241 Klass* refk_oop = NULL;
243 BasicType result = as_BasicType(java_class, &refk_oop); 242 BasicType result = as_BasicType(java_class, &refk_oop);
244 (*reference_klass) = KlassHandle(refk_oop); 243 (*reference_klass) = KlassHandle(refk_oop);
245 return result; 244 return result;
246 } 245 }
247 static Symbol* as_signature(oop java_class, bool intern_if_not_found, TRAPS); 246 static Symbol* as_signature(oop java_class, bool intern_if_not_found, TRAPS);
252 } 251 }
253 static bool is_primitive(oop java_class); 252 static bool is_primitive(oop java_class);
254 static BasicType primitive_type(oop java_class); 253 static BasicType primitive_type(oop java_class);
255 static oop primitive_mirror(BasicType t); 254 static oop primitive_mirror(BasicType t);
256 // JVM_NewInstance support 255 // JVM_NewInstance support
257 static methodOop resolved_constructor(oop java_class); 256 static Method* resolved_constructor(oop java_class);
258 static void set_resolved_constructor(oop java_class, methodOop constructor); 257 static void set_resolved_constructor(oop java_class, Method* constructor);
259 // JVM_NewArray support 258 // JVM_NewArray support
260 static klassOop array_klass(oop java_class); 259 static Klass* array_klass(oop java_class);
261 static void set_array_klass(oop java_class, klassOop klass); 260 static void set_array_klass(oop java_class, Klass* klass);
262 // compiler support for class operations 261 // compiler support for class operations
263 static int klass_offset_in_bytes() { return _klass_offset; } 262 static int klass_offset_in_bytes() { return _klass_offset; }
264 static int resolved_constructor_offset_in_bytes() { return _resolved_constructor_offset; } 263 static int resolved_constructor_offset_in_bytes() { return _resolved_constructor_offset; }
265 static int array_klass_offset_in_bytes() { return _array_klass_offset; } 264 static int array_klass_offset_in_bytes() { return _array_klass_offset; }
266 // Support for classRedefinedCount field 265 // Support for classRedefinedCount field
270 static int oop_size(oop java_class); 269 static int oop_size(oop java_class);
271 static void set_oop_size(oop java_class, int size); 270 static void set_oop_size(oop java_class, int size);
272 static int static_oop_field_count(oop java_class); 271 static int static_oop_field_count(oop java_class);
273 static void set_static_oop_field_count(oop java_class, int size); 272 static void set_static_oop_field_count(oop java_class, int size);
274 273
275 // Debugging 274 static GrowableArray<Klass*>* fixup_mirror_list() {
276 friend class JavaClasses; 275 return _fixup_mirror_list;
277 friend class instanceKlass; // verification code accesses offsets 276 }
277 static void set_fixup_mirror_list(GrowableArray<Klass*>* v) {
278 _fixup_mirror_list = v;
279 }
280 // Debugging
281 friend class JavaClasses;
282 friend class InstanceKlass; // verification code accesses offsets
278 friend class ClassFileParser; // access to number_of_fake_fields 283 friend class ClassFileParser; // access to number_of_fake_fields
279 }; 284 };
280 285
281 // Interface to java.lang.Thread objects 286 // Interface to java.lang.Thread objects
282 287
447 }; 452 };
448 // Trace constants 453 // Trace constants
449 enum { 454 enum {
450 trace_methods_offset = 0, 455 trace_methods_offset = 0,
451 trace_bcis_offset = 1, 456 trace_bcis_offset = 1,
452 trace_next_offset = 2, 457 trace_mirrors_offset = 2,
453 trace_size = 3, 458 trace_next_offset = 3,
459 trace_size = 4,
454 trace_chunk_size = 32 460 trace_chunk_size = 32
455 }; 461 };
456 462
457 static int backtrace_offset; 463 static int backtrace_offset;
458 static int detailMessage_offset; 464 static int detailMessage_offset;
459 static int cause_offset; 465 static int cause_offset;
460 static int stackTrace_offset; 466 static int stackTrace_offset;
461 static int static_unassigned_stacktrace_offset; 467 static int static_unassigned_stacktrace_offset;
462 468
463 // Printing 469 // Printing
464 static char* print_stack_element_to_buffer(methodOop method, int bci); 470 static char* print_stack_element_to_buffer(Method* method, int bci);
465 static void print_to_stream(Handle stream, const char* str); 471 static void print_to_stream(Handle stream, const char* str);
466 // StackTrace (programmatic access, new since 1.4) 472 // StackTrace (programmatic access, new since 1.4)
467 static void clear_stacktrace(oop throwable); 473 static void clear_stacktrace(oop throwable);
468 // No stack trace available 474 // No stack trace available
469 static const char* no_stack_trace_message(); 475 static const char* no_stack_trace_message();
484 static void set_message(oop throwable, oop value); 490 static void set_message(oop throwable, oop value);
485 // Print stack trace stored in exception by call-back to Java 491 // Print stack trace stored in exception by call-back to Java
486 // Note: this is no longer used in Merlin, but we still suppport 492 // Note: this is no longer used in Merlin, but we still suppport
487 // it for compatibility. 493 // it for compatibility.
488 static void print_stack_trace(oop throwable, oop print_stream); 494 static void print_stack_trace(oop throwable, oop print_stream);
489 static void print_stack_element(Handle stream, methodOop method, int bci); 495 static void print_stack_element(Handle stream, Method* method, int bci);
490 static void print_stack_element(outputStream *st, methodOop method, int bci); 496 static void print_stack_element(outputStream *st, Method* method, int bci);
491 static void print_stack_usage(Handle stream); 497 static void print_stack_usage(Handle stream);
492 498
493 // Allocate space for backtrace (created but stack trace not filled in) 499 // Allocate space for backtrace (created but stack trace not filled in)
494 static void allocate_backtrace(Handle throwable, TRAPS); 500 static void allocate_backtrace(Handle throwable, TRAPS);
495 // Fill in current stack trace for throwable with preallocated backtrace (no GC) 501 // Fill in current stack trace for throwable with preallocated backtrace (no GC)
709 // Interface to sun.reflect.ConstantPool objects 715 // Interface to sun.reflect.ConstantPool objects
710 class sun_reflect_ConstantPool { 716 class sun_reflect_ConstantPool {
711 private: 717 private:
712 // Note that to reduce dependencies on the JDK we compute these 718 // Note that to reduce dependencies on the JDK we compute these
713 // offsets at run-time. 719 // offsets at run-time.
714 static int _cp_oop_offset; 720 static int _oop_offset;
715 721
716 static void compute_offsets(); 722 static void compute_offsets();
717 723
718 public: 724 public:
719 // Allocation 725 // Allocation
720 static Handle create(TRAPS); 726 static Handle create(TRAPS);
721 727
722 // Accessors 728 // Accessors
723 static oop cp_oop(oop reflect); 729 static void set_cp(oop reflect, ConstantPool* value);
724 static void set_cp_oop(oop reflect, oop value); 730 static int oop_offset() {
725 static int cp_oop_offset() { 731 return _oop_offset;
726 return _cp_oop_offset; 732 }
727 } 733
734 static ConstantPool* get_cp(oop reflect);
728 735
729 // Debugging 736 // Debugging
730 friend class JavaClasses; 737 friend class JavaClasses;
731 }; 738 };
732 739
851 } 858 }
852 // Accessors for statics 859 // Accessors for statics
853 static oop pending_list_lock(); 860 static oop pending_list_lock();
854 static oop pending_list(); 861 static oop pending_list();
855 862
863 static HeapWord* pending_list_lock_addr();
856 static HeapWord* pending_list_addr(); 864 static HeapWord* pending_list_addr();
857 }; 865 };
858 866
859 867
860 // Interface to java.lang.ref.SoftReference objects 868 // Interface to java.lang.ref.SoftReference objects
901 909
902 static oop form(oop mh); 910 static oop form(oop mh);
903 static void set_form(oop mh, oop lform); 911 static void set_form(oop mh, oop lform);
904 912
905 // Testers 913 // Testers
906 static bool is_subclass(klassOop klass) { 914 static bool is_subclass(Klass* klass) {
907 return Klass::cast(klass)->is_subclass_of(SystemDictionary::MethodHandle_klass()); 915 return Klass::cast(klass)->is_subclass_of(SystemDictionary::MethodHandle_klass());
908 } 916 }
909 static bool is_instance(oop obj) { 917 static bool is_instance(oop obj) {
910 return obj != NULL && is_subclass(obj->klass()); 918 return obj != NULL && is_subclass(obj->klass());
911 } 919 }
930 // Accessors 938 // Accessors
931 static oop vmentry(oop lform); 939 static oop vmentry(oop lform);
932 static void set_vmentry(oop lform, oop invoker); 940 static void set_vmentry(oop lform, oop invoker);
933 941
934 // Testers 942 // Testers
935 static bool is_subclass(klassOop klass) { 943 static bool is_subclass(Klass* klass) {
936 return SystemDictionary::LambdaForm_klass() != NULL && 944 return SystemDictionary::LambdaForm_klass() != NULL &&
937 Klass::cast(klass)->is_subclass_of(SystemDictionary::LambdaForm_klass()); 945 Klass::cast(klass)->is_subclass_of(SystemDictionary::LambdaForm_klass());
938 } 946 }
939 static bool is_instance(oop obj) { 947 static bool is_instance(oop obj) {
940 return obj != NULL && is_subclass(obj->klass()); 948 return obj != NULL && is_subclass(obj->klass());
947 955
948 // Interface to java.lang.invoke.MemberName objects 956 // Interface to java.lang.invoke.MemberName objects
949 // (These are a private interface for Java code to query the class hierarchy.) 957 // (These are a private interface for Java code to query the class hierarchy.)
950 958
951 #define MEMBERNAME_INJECTED_FIELDS(macro) \ 959 #define MEMBERNAME_INJECTED_FIELDS(macro) \
960 macro(java_lang_invoke_MemberName, vmloader, object_signature, false) \
952 macro(java_lang_invoke_MemberName, vmindex, intptr_signature, false) \ 961 macro(java_lang_invoke_MemberName, vmindex, intptr_signature, false) \
953 macro(java_lang_invoke_MemberName, vmtarget, object_signature, false) 962 macro(java_lang_invoke_MemberName, vmtarget, intptr_signature, false)
954 963
955 class java_lang_invoke_MemberName: AllStatic { 964 class java_lang_invoke_MemberName: AllStatic {
956 friend class JavaClasses; 965 friend class JavaClasses;
957 966
958 private: 967 private:
959 // From java.lang.invoke.MemberName: 968 // From java.lang.invoke.MemberName:
960 // private Class<?> clazz; // class in which the method is defined 969 // private Class<?> clazz; // class in which the method is defined
961 // private String name; // may be null if not yet materialized 970 // private String name; // may be null if not yet materialized
962 // private Object type; // may be null if not yet materialized 971 // private Object type; // may be null if not yet materialized
963 // private int flags; // modifier bits; see reflect.Modifier 972 // private int flags; // modifier bits; see reflect.Modifier
964 // private Object vmtarget; // VM-specific target value 973 // private intptr vmtarget; // VM-specific target value
965 // private intptr_t vmindex; // member index within class or interface 974 // private intptr_t vmindex; // member index within class or interface
966 static int _clazz_offset; 975 static int _clazz_offset;
967 static int _name_offset; 976 static int _name_offset;
968 static int _type_offset; 977 static int _type_offset;
969 static int _flags_offset; 978 static int _flags_offset;
970 static int _vmtarget_offset; 979 static int _vmtarget_offset;
980 static int _vmloader_offset;
971 static int _vmindex_offset; 981 static int _vmindex_offset;
972 982
973 static void compute_offsets(); 983 static void compute_offsets();
974 984
975 public: 985 public:
984 static void set_name(oop mname, oop name); 994 static void set_name(oop mname, oop name);
985 995
986 static int flags(oop mname); 996 static int flags(oop mname);
987 static void set_flags(oop mname, int flags); 997 static void set_flags(oop mname, int flags);
988 998
989 static oop vmtarget(oop mname); 999 static Metadata* vmtarget(oop mname);
990 static void set_vmtarget(oop mname, oop target); 1000 static void set_vmtarget(oop mname, Metadata* target);
991 1001
992 static intptr_t vmindex(oop mname); 1002 static intptr_t vmindex(oop mname);
993 static void set_vmindex(oop mname, intptr_t index); 1003 static void set_vmindex(oop mname, intptr_t index);
994 1004
995 // Testers 1005 // Testers
996 static bool is_subclass(klassOop klass) { 1006 static bool is_subclass(Klass* klass) {
997 return Klass::cast(klass)->is_subclass_of(SystemDictionary::MemberName_klass()); 1007 return Klass::cast(klass)->is_subclass_of(SystemDictionary::MemberName_klass());
998 } 1008 }
999 static bool is_instance(oop obj) { 1009 static bool is_instance(oop obj) {
1000 return obj != NULL && is_subclass(obj->klass()); 1010 return obj != NULL && is_subclass(obj->klass());
1001 } 1011 }
1077 1087
1078 static volatile oop target_volatile(oop site) { return site->obj_field_volatile( _target_offset); } 1088 static volatile oop target_volatile(oop site) { return site->obj_field_volatile( _target_offset); }
1079 static void set_target_volatile(oop site, oop target) { site->obj_field_put_volatile(_target_offset, target); } 1089 static void set_target_volatile(oop site, oop target) { site->obj_field_put_volatile(_target_offset, target); }
1080 1090
1081 // Testers 1091 // Testers
1082 static bool is_subclass(klassOop klass) { 1092 static bool is_subclass(Klass* klass) {
1083 return Klass::cast(klass)->is_subclass_of(SystemDictionary::CallSite_klass()); 1093 return Klass::cast(klass)->is_subclass_of(SystemDictionary::CallSite_klass());
1084 } 1094 }
1085 static bool is_instance(oop obj) { 1095 static bool is_instance(oop obj) {
1086 return obj != NULL && is_subclass(obj->klass()); 1096 return obj != NULL && is_subclass(obj->klass());
1087 } 1097 }
1110 }; 1120 };
1111 1121
1112 1122
1113 // Interface to java.lang.ClassLoader objects 1123 // Interface to java.lang.ClassLoader objects
1114 1124
1125 #define CLASSLOADER_INJECTED_FIELDS(macro) \
1126 macro(java_lang_ClassLoader, loader_data, intptr_signature, false) \
1127 macro(java_lang_ClassLoader, dependencies, object_signature, false)
1128
1115 class java_lang_ClassLoader : AllStatic { 1129 class java_lang_ClassLoader : AllStatic {
1116 private: 1130 private:
1131 // The fake offsets are added by the class loader when java.lang.Class is loaded
1117 enum { 1132 enum {
1118 hc_parent_offset = 0 1133 hc_parent_offset = 0
1119 }; 1134 };
1120 1135 static int _loader_data_offset;
1136 static int _dependencies_offset;
1121 static bool offsets_computed; 1137 static bool offsets_computed;
1122 static int parent_offset; 1138 static int parent_offset;
1123 static int parallelCapable_offset; 1139 static int parallelCapable_offset;
1124 1140
1125 static void compute_offsets(); 1141 public:
1126 1142 static void compute_offsets();
1127 public: 1143
1144 static ClassLoaderData** loader_data_addr(oop loader);
1145 static ClassLoaderData* loader_data(oop loader);
1146
1147 static oop dependencies(oop loader);
1148 static HeapWord* dependencies_addr(oop loader);
1149
1128 static oop parent(oop loader); 1150 static oop parent(oop loader);
1129 static bool isAncestor(oop loader, oop cl); 1151 static bool isAncestor(oop loader, oop cl);
1130 1152
1131 // Support for parallelCapable field 1153 // Support for parallelCapable field
1132 static bool parallelCapable(oop the_class_mirror); 1154 static bool parallelCapable(oop the_class_mirror);
1135 1157
1136 // Fix for 4474172 1158 // Fix for 4474172
1137 static oop non_reflection_class_loader(oop loader); 1159 static oop non_reflection_class_loader(oop loader);
1138 1160
1139 // Testers 1161 // Testers
1140 static bool is_subclass(klassOop klass) { 1162 static bool is_subclass(Klass* klass) {
1141 return Klass::cast(klass)->is_subclass_of(SystemDictionary::ClassLoader_klass()); 1163 return Klass::cast(klass)->is_subclass_of(SystemDictionary::ClassLoader_klass());
1142 } 1164 }
1143 static bool is_instance(oop obj) { 1165 static bool is_instance(oop obj) {
1144 return obj != NULL && is_subclass(obj->klass()); 1166 return obj != NULL && is_subclass(obj->klass());
1145 } 1167 }
1146 1168
1147 // Debugging 1169 // Debugging
1148 friend class JavaClasses; 1170 friend class JavaClasses;
1171 friend class ClassFileParser; // access to number_of_fake_fields
1149 }; 1172 };
1150 1173
1151 1174
1152 // Interface to java.lang.System objects 1175 // Interface to java.lang.System objects
1153 1176
1266 const vmSymbols::SID name_index; 1289 const vmSymbols::SID name_index;
1267 const vmSymbols::SID signature_index; 1290 const vmSymbols::SID signature_index;
1268 const bool may_be_java; 1291 const bool may_be_java;
1269 1292
1270 1293
1271 klassOop klass() const { return SystemDictionary::well_known_klass(klass_id); } 1294 Klass* klass() const { return SystemDictionary::well_known_klass(klass_id); }
1272 Symbol* name() const { return lookup_symbol(name_index); } 1295 Symbol* name() const { return lookup_symbol(name_index); }
1273 Symbol* signature() const { return lookup_symbol(signature_index); } 1296 Symbol* signature() const { return lookup_symbol(signature_index); }
1274 1297
1275 int compute_offset(); 1298 int compute_offset();
1276 1299
1283 #define DECLARE_INJECTED_FIELD_ENUM(klass, name, signature, may_be_java) \ 1306 #define DECLARE_INJECTED_FIELD_ENUM(klass, name, signature, may_be_java) \
1284 klass##_##name##_enum, 1307 klass##_##name##_enum,
1285 1308
1286 #define ALL_INJECTED_FIELDS(macro) \ 1309 #define ALL_INJECTED_FIELDS(macro) \
1287 CLASS_INJECTED_FIELDS(macro) \ 1310 CLASS_INJECTED_FIELDS(macro) \
1311 CLASSLOADER_INJECTED_FIELDS(macro) \
1288 MEMBERNAME_INJECTED_FIELDS(macro) 1312 MEMBERNAME_INJECTED_FIELDS(macro)
1289 1313
1290 // Interface to hard-coded offset checking 1314 // Interface to hard-coded offset checking
1291 1315
1292 class JavaClasses : AllStatic { 1316 class JavaClasses : AllStatic {