42 // An InstanceKlass is the VM level representation of a Java class.
43 // It contains all information needed for at class at execution runtime.
44
45 // InstanceKlass embedded field layout (after declared fields):
46 // [EMBEDDED Java vtable ] size in words = vtable_len
47 // [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
48 // The embedded nonstatic oop-map blocks are short pairs (offset, length)
49 // indicating where oops are located in instances of this klass.
50 // [EMBEDDED implementor of the interface] only exist for interface
51 // [EMBEDDED host klass ] only exist for an anonymous class (JSR 292 enabled)
52
53
54 // forward declaration for class -- see below for definition
55 class SuperTypeClosure;
56 class JNIid;
57 class jniIdMapBase;
58 class BreakpointInfo;
59 class fieldDescriptor;
60 class DepChange;
61 class nmethodBucket;
62 class PreviousVersionNode;
63 class JvmtiCachedClassFieldMap;
64 class MemberNameTable;
65
66 // This is used in iterators below.
67 class FieldClosure: public StackObj {
68 public:
69 virtual void do_field(fieldDescriptor* fd) = 0;
70 };
71
72 #ifndef PRODUCT
73 // Print fields.
74 // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
75 class FieldPrinter: public FieldClosure {
76 oop _obj;
77 outputStream* _st;
78 public:
79 FieldPrinter(outputStream* st, oop obj = NULL) : _obj(obj), _st(st) {}
80 void do_field(fieldDescriptor* fd);
81 };
82 #endif // !PRODUCT
188 // or 0 if none.
189 u2 _generic_signature_index;
190 // Constant pool index to the utf8 entry for the name of source file
191 // containing this klass, 0 if not specified.
192 u2 _source_file_name_index;
193 u2 _static_oop_field_count;// number of static oop fields in this klass
194 u2 _java_fields_count; // The number of declared Java fields
195 int _nonstatic_oop_map_size;// size in words of nonstatic oop map blocks
196
197 // _is_marked_dependent can be set concurrently, thus cannot be part of the
198 // _misc_flags.
199 bool _is_marked_dependent; // used for marking during flushing and deoptimization
200 bool _has_unloaded_dependent;
201
202 enum {
203 _misc_rewritten = 1 << 0, // methods rewritten.
204 _misc_has_nonstatic_fields = 1 << 1, // for sizing with UseCompressedOops
205 _misc_should_verify_class = 1 << 2, // allow caching of preverification
206 _misc_is_anonymous = 1 << 3, // has embedded _host_klass field
207 _misc_is_contended = 1 << 4, // marked with contended annotation
208 _misc_has_default_methods = 1 << 5 // class/superclass/implemented interfaces has default methods
209 };
210 u2 _misc_flags;
211 u2 _minor_version; // minor version number of class file
212 u2 _major_version; // major version number of class file
213 Thread* _init_thread; // Pointer to current thread doing initialization (to handle recusive initialization)
214 int _vtable_len; // length of Java vtable (in words)
215 int _itable_len; // length of Java itable (in words)
216 OopMapCache* volatile _oop_map_cache; // OopMapCache for all methods in the klass (allocated lazily)
217 MemberNameTable* _member_names; // Member names
218 JNIid* _jni_ids; // First JNI identifier for static fields in this class
219 jmethodID* _methods_jmethod_ids; // jmethodIDs corresponding to method_idnum, or NULL if none
220 nmethodBucket* _dependencies; // list of dependent nmethods
221 nmethod* _osr_nmethods_head; // Head of list of on-stack replacement nmethods for this class
222 BreakpointInfo* _breakpoints; // bpt lists, managed by Method*
223 // Array of interesting part(s) of the previous version(s) of this
224 // InstanceKlass. See PreviousVersionWalker below.
225 GrowableArray<PreviousVersionNode *>* _previous_versions;
226 // JVMTI fields can be moved to their own structure - see 6315920
227 // JVMTI: cached class file, before retransformable agent modified it in CFLH
228 JvmtiCachedClassFileData* _cached_class_file;
229
230 volatile u2 _idnum_allocated_count; // JNI/JVMTI: increments with the addition of methods, old ids don't change
231
232 // Class states are defined as ClassState (see above).
233 // Place the _init_state here to utilize the unused 2-byte after
234 // _idnum_allocated_count.
235 u1 _init_state; // state of class
236 u1 _reference_type; // reference type
237
238 JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map; // JVMTI: used during heap iteration
239
240 NOT_PRODUCT(int _verify_count;) // to avoid redundant verifies
241
242 // Method array.
243 Array<Method*>* _methods;
244 // Default Method Array, concrete methods inherited from interfaces
245 Array<Method*>* _default_methods;
593
594 // symbol unloading support (refcount already added)
595 Symbol* array_name() { return _array_name; }
596 void set_array_name(Symbol* name) { assert(_array_name == NULL || name == NULL, "name already created"); _array_name = name; }
597
598 // nonstatic oop-map blocks
599 static int nonstatic_oop_map_size(unsigned int oop_map_count) {
600 return oop_map_count * OopMapBlock::size_in_words();
601 }
602 unsigned int nonstatic_oop_map_count() const {
603 return _nonstatic_oop_map_size / OopMapBlock::size_in_words();
604 }
605 int nonstatic_oop_map_size() const { return _nonstatic_oop_map_size; }
606 void set_nonstatic_oop_map_size(int words) {
607 _nonstatic_oop_map_size = words;
608 }
609
610 // RedefineClasses() support for previous versions:
611 void add_previous_version(instanceKlassHandle ikh, BitMap *emcp_methods,
612 int emcp_method_count);
613 // If the _previous_versions array is non-NULL, then this klass
614 // has been redefined at least once even if we aren't currently
615 // tracking a previous version.
616 bool has_been_redefined() const { return _previous_versions != NULL; }
617 bool has_previous_version() const;
618 void init_previous_versions() {
619 _previous_versions = NULL;
620 }
621 GrowableArray<PreviousVersionNode *>* previous_versions() const {
622 return _previous_versions;
623 }
624
625 static void purge_previous_versions(InstanceKlass* ik);
626
627 // JVMTI: Support for caching a class file before it is modified by an agent that can do retransformation
628 void set_cached_class_file(JvmtiCachedClassFileData *data) {
629 _cached_class_file = data;
630 }
631 JvmtiCachedClassFileData * get_cached_class_file() { return _cached_class_file; }
632 jint get_cached_class_file_len();
633 unsigned char * get_cached_class_file_bytes();
634
635 // JVMTI: Support for caching of field indices, types, and offsets
636 void set_jvmti_cached_class_field_map(JvmtiCachedClassFieldMap* descriptor) {
637 _jvmti_cached_class_field_map = descriptor;
638 }
639 JvmtiCachedClassFieldMap* jvmti_cached_class_field_map() const {
640 return _jvmti_cached_class_field_map;
641 }
642
643 bool has_default_methods() const {
1025 static void eager_initialize_impl (instanceKlassHandle this_k);
1026 static void set_initialization_state_and_notify_impl (instanceKlassHandle this_k, ClassState state, TRAPS);
1027 static void call_class_initializer_impl (instanceKlassHandle this_k, TRAPS);
1028 static Klass* array_klass_impl (instanceKlassHandle this_k, bool or_null, int n, TRAPS);
1029 static void do_local_static_fields_impl (instanceKlassHandle this_k, void f(fieldDescriptor* fd, Handle, TRAPS), Handle, TRAPS);
1030 /* jni_id_for_impl for jfieldID only */
1031 static JNIid* jni_id_for_impl (instanceKlassHandle this_k, int offset);
1032
1033 // Returns the array class for the n'th dimension
1034 Klass* array_klass_impl(bool or_null, int n, TRAPS);
1035
1036 // Returns the array class with this class as element type
1037 Klass* array_klass_impl(bool or_null, TRAPS);
1038
1039 // find a local method (returns NULL if not found)
1040 Method* find_method_impl(Symbol* name, Symbol* signature, bool skipping_overpass) const;
1041 static Method* find_method_impl(Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass);
1042
1043 // Free CHeap allocated fields.
1044 void release_C_heap_structures();
1045 public:
1046 // CDS support - remove and restore oops from metadata. Oops are not shared.
1047 virtual void remove_unshareable_info();
1048 virtual void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
1049
1050 // jvm support
1051 jint compute_modifier_flags(TRAPS) const;
1052
1053 // JSR-292 support
1054 MemberNameTable* member_names() { return _member_names; }
1055 void set_member_names(MemberNameTable* member_names) { _member_names = member_names; }
1056 void add_member_name(int index, Handle member_name);
1057 oop get_member_name(int index);
1058
1059 public:
1060 // JVMTI support
1061 jint jvmti_class_status() const;
1062
1063 public:
1064 // Printing
1121 // Accessors
1122 Klass* holder() const { return _holder; }
1123 int offset() const { return _offset; }
1124 JNIid* next() { return _next; }
1125 // Constructor
1126 JNIid(Klass* holder, int offset, JNIid* next);
1127 // Identifier lookup
1128 JNIid* find(int offset);
1129
1130 bool find_local_field(fieldDescriptor* fd) {
1131 return InstanceKlass::cast(holder())->find_local_field_from_offset(offset(), true, fd);
1132 }
1133
1134 static void deallocate(JNIid* id);
1135 // Debugging
1136 #ifdef ASSERT
1137 bool is_static_field_id() const { return _is_static_field_id; }
1138 void set_is_static_field_id() { _is_static_field_id = true; }
1139 #endif
1140 void verify(Klass* holder);
1141 };
1142
1143
1144 // If breakpoints are more numerous than just JVMTI breakpoints,
1145 // consider compressing this data structure.
1146 // It is currently a simple linked list defined in method.hpp.
1147
1148 class BreakpointInfo;
1149
1150
1151 // A collection point for interesting information about the previous
1152 // version(s) of an InstanceKlass. A GrowableArray of PreviousVersionNodes
1153 // is attached to the InstanceKlass as needed. See PreviousVersionWalker below.
1154 class PreviousVersionNode : public CHeapObj<mtClass> {
1155 private:
1156 ConstantPool* _prev_constant_pool;
1157
1158 // If the previous version of the InstanceKlass doesn't have any
1159 // EMCP methods, then _prev_EMCP_methods will be NULL. If all the
1160 // EMCP methods have been collected, then _prev_EMCP_methods can
1161 // have a length of zero.
1162 GrowableArray<Method*>* _prev_EMCP_methods;
1163
1164 public:
1165 PreviousVersionNode(ConstantPool* prev_constant_pool,
1166 GrowableArray<Method*>* prev_EMCP_methods);
1167 ~PreviousVersionNode();
1168 ConstantPool* prev_constant_pool() const {
1169 return _prev_constant_pool;
1170 }
1171 GrowableArray<Method*>* prev_EMCP_methods() const {
1172 return _prev_EMCP_methods;
1173 }
1174 };
1175
1176
1177 // Helper object for walking previous versions.
1178 class PreviousVersionWalker : public StackObj {
1179 private:
1180 Thread* _thread;
1181 GrowableArray<PreviousVersionNode *>* _previous_versions;
1182 int _current_index;
1183
1184 // A pointer to the current node object so we can handle the deletes.
1185 PreviousVersionNode* _current_p;
1186
1187 // The constant pool handle keeps all the methods in this class from being
1188 // deallocated from the metaspace during class unloading.
1189 constantPoolHandle _current_constant_pool_handle;
1190
1191 public:
1192 PreviousVersionWalker(Thread* thread, InstanceKlass *ik);
1193
1194 // Return the interesting information for the next previous version
1195 // of the klass. Returns NULL if there are no more previous versions.
1196 PreviousVersionNode* next_previous_version();
1197 };
1198
1199
1200 //
1201 // nmethodBucket is used to record dependent nmethods for
1202 // deoptimization. nmethod dependencies are actually <klass, method>
1203 // pairs but we really only care about the klass part for purposes of
1204 // finding nmethods which might need to be deoptimized. Instead of
1205 // recording the method, a count of how many times a particular nmethod
1206 // was recorded is kept. This ensures that any recording errors are
1207 // noticed since an nmethod should be removed as many times are it's
1208 // added.
1209 //
1210 class nmethodBucket: public CHeapObj<mtClass> {
1211 friend class VMStructs;
1212 private:
1213 nmethod* _nmethod;
1214 int _count;
1215 nmethodBucket* _next;
1216
|
42 // An InstanceKlass is the VM level representation of a Java class.
43 // It contains all information needed for at class at execution runtime.
44
45 // InstanceKlass embedded field layout (after declared fields):
46 // [EMBEDDED Java vtable ] size in words = vtable_len
47 // [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
48 // The embedded nonstatic oop-map blocks are short pairs (offset, length)
49 // indicating where oops are located in instances of this klass.
50 // [EMBEDDED implementor of the interface] only exist for interface
51 // [EMBEDDED host klass ] only exist for an anonymous class (JSR 292 enabled)
52
53
54 // forward declaration for class -- see below for definition
55 class SuperTypeClosure;
56 class JNIid;
57 class jniIdMapBase;
58 class BreakpointInfo;
59 class fieldDescriptor;
60 class DepChange;
61 class nmethodBucket;
62 class JvmtiCachedClassFieldMap;
63 class MemberNameTable;
64
65 // This is used in iterators below.
66 class FieldClosure: public StackObj {
67 public:
68 virtual void do_field(fieldDescriptor* fd) = 0;
69 };
70
71 #ifndef PRODUCT
72 // Print fields.
73 // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
74 class FieldPrinter: public FieldClosure {
75 oop _obj;
76 outputStream* _st;
77 public:
78 FieldPrinter(outputStream* st, oop obj = NULL) : _obj(obj), _st(st) {}
79 void do_field(fieldDescriptor* fd);
80 };
81 #endif // !PRODUCT
187 // or 0 if none.
188 u2 _generic_signature_index;
189 // Constant pool index to the utf8 entry for the name of source file
190 // containing this klass, 0 if not specified.
191 u2 _source_file_name_index;
192 u2 _static_oop_field_count;// number of static oop fields in this klass
193 u2 _java_fields_count; // The number of declared Java fields
194 int _nonstatic_oop_map_size;// size in words of nonstatic oop map blocks
195
196 // _is_marked_dependent can be set concurrently, thus cannot be part of the
197 // _misc_flags.
198 bool _is_marked_dependent; // used for marking during flushing and deoptimization
199 bool _has_unloaded_dependent;
200
201 enum {
202 _misc_rewritten = 1 << 0, // methods rewritten.
203 _misc_has_nonstatic_fields = 1 << 1, // for sizing with UseCompressedOops
204 _misc_should_verify_class = 1 << 2, // allow caching of preverification
205 _misc_is_anonymous = 1 << 3, // has embedded _host_klass field
206 _misc_is_contended = 1 << 4, // marked with contended annotation
207 _misc_has_default_methods = 1 << 5, // class/superclass/implemented interfaces has default methods
208 _misc_has_been_redefined = 1 << 6 // class has been redefined
209 };
210 u2 _misc_flags;
211 u2 _minor_version; // minor version number of class file
212 u2 _major_version; // major version number of class file
213 Thread* _init_thread; // Pointer to current thread doing initialization (to handle recusive initialization)
214 int _vtable_len; // length of Java vtable (in words)
215 int _itable_len; // length of Java itable (in words)
216 OopMapCache* volatile _oop_map_cache; // OopMapCache for all methods in the klass (allocated lazily)
217 MemberNameTable* _member_names; // Member names
218 JNIid* _jni_ids; // First JNI identifier for static fields in this class
219 jmethodID* _methods_jmethod_ids; // jmethodIDs corresponding to method_idnum, or NULL if none
220 nmethodBucket* _dependencies; // list of dependent nmethods
221 nmethod* _osr_nmethods_head; // Head of list of on-stack replacement nmethods for this class
222 BreakpointInfo* _breakpoints; // bpt lists, managed by Method*
223 // Linked instanceKlasses of previous versions
224 InstanceKlass* _previous_versions;
225 // JVMTI fields can be moved to their own structure - see 6315920
226 // JVMTI: cached class file, before retransformable agent modified it in CFLH
227 JvmtiCachedClassFileData* _cached_class_file;
228
229 volatile u2 _idnum_allocated_count; // JNI/JVMTI: increments with the addition of methods, old ids don't change
230
231 // Class states are defined as ClassState (see above).
232 // Place the _init_state here to utilize the unused 2-byte after
233 // _idnum_allocated_count.
234 u1 _init_state; // state of class
235 u1 _reference_type; // reference type
236
237 JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map; // JVMTI: used during heap iteration
238
239 NOT_PRODUCT(int _verify_count;) // to avoid redundant verifies
240
241 // Method array.
242 Array<Method*>* _methods;
243 // Default Method Array, concrete methods inherited from interfaces
244 Array<Method*>* _default_methods;
592
593 // symbol unloading support (refcount already added)
594 Symbol* array_name() { return _array_name; }
595 void set_array_name(Symbol* name) { assert(_array_name == NULL || name == NULL, "name already created"); _array_name = name; }
596
597 // nonstatic oop-map blocks
598 static int nonstatic_oop_map_size(unsigned int oop_map_count) {
599 return oop_map_count * OopMapBlock::size_in_words();
600 }
601 unsigned int nonstatic_oop_map_count() const {
602 return _nonstatic_oop_map_size / OopMapBlock::size_in_words();
603 }
604 int nonstatic_oop_map_size() const { return _nonstatic_oop_map_size; }
605 void set_nonstatic_oop_map_size(int words) {
606 _nonstatic_oop_map_size = words;
607 }
608
609 // RedefineClasses() support for previous versions:
610 void add_previous_version(instanceKlassHandle ikh, BitMap *emcp_methods,
611 int emcp_method_count);
612
613 InstanceKlass* previous_versions() const { return _previous_versions; }
614
615 bool has_been_redefined() const {
616 return (_misc_flags & _misc_has_been_redefined) != 0;
617 }
618 void set_has_been_redefined() {
619 _misc_flags |= _misc_has_been_redefined;
620 }
621
622 void init_previous_versions() {
623 _previous_versions = NULL;
624 }
625
626 static void purge_previous_versions(InstanceKlass* ik);
627
628 // JVMTI: Support for caching a class file before it is modified by an agent that can do retransformation
629 void set_cached_class_file(JvmtiCachedClassFileData *data) {
630 _cached_class_file = data;
631 }
632 JvmtiCachedClassFileData * get_cached_class_file() { return _cached_class_file; }
633 jint get_cached_class_file_len();
634 unsigned char * get_cached_class_file_bytes();
635
636 // JVMTI: Support for caching of field indices, types, and offsets
637 void set_jvmti_cached_class_field_map(JvmtiCachedClassFieldMap* descriptor) {
638 _jvmti_cached_class_field_map = descriptor;
639 }
640 JvmtiCachedClassFieldMap* jvmti_cached_class_field_map() const {
641 return _jvmti_cached_class_field_map;
642 }
643
644 bool has_default_methods() const {
1026 static void eager_initialize_impl (instanceKlassHandle this_k);
1027 static void set_initialization_state_and_notify_impl (instanceKlassHandle this_k, ClassState state, TRAPS);
1028 static void call_class_initializer_impl (instanceKlassHandle this_k, TRAPS);
1029 static Klass* array_klass_impl (instanceKlassHandle this_k, bool or_null, int n, TRAPS);
1030 static void do_local_static_fields_impl (instanceKlassHandle this_k, void f(fieldDescriptor* fd, Handle, TRAPS), Handle, TRAPS);
1031 /* jni_id_for_impl for jfieldID only */
1032 static JNIid* jni_id_for_impl (instanceKlassHandle this_k, int offset);
1033
1034 // Returns the array class for the n'th dimension
1035 Klass* array_klass_impl(bool or_null, int n, TRAPS);
1036
1037 // Returns the array class with this class as element type
1038 Klass* array_klass_impl(bool or_null, TRAPS);
1039
1040 // find a local method (returns NULL if not found)
1041 Method* find_method_impl(Symbol* name, Symbol* signature, bool skipping_overpass) const;
1042 static Method* find_method_impl(Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass);
1043
1044 // Free CHeap allocated fields.
1045 void release_C_heap_structures();
1046
1047 // RedefineClass support
1048 void link_previous_versions(instanceKlassHandle prev) { _previous_versions = prev(); }
1049 void mark_newly_obsolete_methods(Array<Method*>* old_methods, int emcp_method_count);
1050 public:
1051 // CDS support - remove and restore oops from metadata. Oops are not shared.
1052 virtual void remove_unshareable_info();
1053 virtual void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
1054
1055 // jvm support
1056 jint compute_modifier_flags(TRAPS) const;
1057
1058 // JSR-292 support
1059 MemberNameTable* member_names() { return _member_names; }
1060 void set_member_names(MemberNameTable* member_names) { _member_names = member_names; }
1061 void add_member_name(int index, Handle member_name);
1062 oop get_member_name(int index);
1063
1064 public:
1065 // JVMTI support
1066 jint jvmti_class_status() const;
1067
1068 public:
1069 // Printing
1126 // Accessors
1127 Klass* holder() const { return _holder; }
1128 int offset() const { return _offset; }
1129 JNIid* next() { return _next; }
1130 // Constructor
1131 JNIid(Klass* holder, int offset, JNIid* next);
1132 // Identifier lookup
1133 JNIid* find(int offset);
1134
1135 bool find_local_field(fieldDescriptor* fd) {
1136 return InstanceKlass::cast(holder())->find_local_field_from_offset(offset(), true, fd);
1137 }
1138
1139 static void deallocate(JNIid* id);
1140 // Debugging
1141 #ifdef ASSERT
1142 bool is_static_field_id() const { return _is_static_field_id; }
1143 void set_is_static_field_id() { _is_static_field_id = true; }
1144 #endif
1145 void verify(Klass* holder);
1146 };
1147
1148
1149 //
1150 // nmethodBucket is used to record dependent nmethods for
1151 // deoptimization. nmethod dependencies are actually <klass, method>
1152 // pairs but we really only care about the klass part for purposes of
1153 // finding nmethods which might need to be deoptimized. Instead of
1154 // recording the method, a count of how many times a particular nmethod
1155 // was recorded is kept. This ensures that any recording errors are
1156 // noticed since an nmethod should be removed as many times are it's
1157 // added.
1158 //
1159 class nmethodBucket: public CHeapObj<mtClass> {
1160 friend class VMStructs;
1161 private:
1162 nmethod* _nmethod;
1163 int _count;
1164 nmethodBucket* _next;
1165
|