13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_OOPS_KLASS_HPP
26 #define SHARE_VM_OOPS_KLASS_HPP
27
28 #include "gc/shared/specialized_oop_closures.hpp"
29 #include "memory/iterator.hpp"
30 #include "memory/memRegion.hpp"
31 #include "oops/metadata.hpp"
32 #include "oops/oop.hpp"
33 #include "trace/traceMacros.hpp"
34 #include "utilities/accessFlags.hpp"
35 #include "utilities/macros.hpp"
36
37 //
38 // A Klass provides:
39 // 1: language level class object (method dictionary etc.)
40 // 2: provide vm dispatch behavior for the object
41 // Both functions are combined into one C++ class.
42
43 // One reason for the oop/klass dichotomy in the implementation is
44 // that we don't want a C++ vtbl pointer in every object. Thus,
45 // normal oops don't have any virtual functions. Instead, they
46 // forward all "virtual" functions to their klass, which does have
47 // a vtbl and does the C++ dispatch depending on the object's
48 // actual type. (See oop.inline.hpp for some of the forwarding code.)
49 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
50
51 // Forward declarations.
52 template <class T> class Array;
102
103 // The fields _super_check_offset, _secondary_super_cache, _secondary_supers
104 // and _primary_supers all help make fast subtype checks. See big discussion
105 // in doc/server_compiler/checktype.txt
106 //
107 // Where to look to observe a supertype (it is &_secondary_super_cache for
108 // secondary supers, else is &_primary_supers[depth()].
109 juint _super_check_offset;
110
111 // Class name. Instance classes: java/lang/String, etc. Array classes: [I,
112 // [Ljava/lang/String;, etc. Set to zero for all other kinds of classes.
113 Symbol* _name;
114
115 // Cache of last observed secondary supertype
116 Klass* _secondary_super_cache;
117 // Array of all secondary supertypes
118 Array<Klass*>* _secondary_supers;
119 // Ordered list of all primary supertypes
120 Klass* _primary_supers[_primary_super_limit];
121 // java/lang/Class instance mirroring this class
122 oop _java_mirror;
123 // Superclass
124 Klass* _super;
125 // First subclass (NULL if none); _subklass->next_sibling() is next one
126 Klass* _subklass;
127 // Sibling link (or NULL); links all subklasses of a klass
128 Klass* _next_sibling;
129
130 // All klasses loaded by a class loader are chained through these links
131 Klass* _next_link;
132
133 // The VM's representation of the ClassLoader used to load this class.
134 // Provide access the corresponding instance java.lang.ClassLoader.
135 ClassLoaderData* _class_loader_data;
136
137 jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
138 AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
139
140 TRACE_DEFINE_TRACE_ID_FIELD;
141
142 // Biased locking implementation and statistics
143 // (the 64-bit chunk goes first, to avoid some fragmentation)
144 jlong _last_biased_lock_bulk_revocation_time;
145 markOop _prototype_header; // Used when biased locking is both enabled and disabled for this type
146 jint _biased_lock_revocation_count;
147
148 // vtable length
149 int _vtable_len;
150
151 // Remembered sets support for the oops in the klasses.
152 jbyte _modified_oops; // Card Table Equivalent (YC/CMS support)
153 jbyte _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
154
155 private:
156 // This is an index into FileMapHeader::_classpath_entry_table[], to
157 // associate this class with the JAR file where it's loaded from during
158 // dump time. If a class is not loaded from the shared archive, this field is
159 // -1.
160 jshort _shared_class_path_index;
161
162 friend class SharedClassUtil;
163 protected:
164
165 // Constructor
166 Klass();
167
168 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
169
170 public:
171 enum DefaultsLookupMode { find_defaults, skip_defaults };
172 enum OverpassLookupMode { find_overpass, skip_overpass };
173 enum StaticLookupMode { find_static, skip_static };
174 enum PrivateLookupMode { find_private, skip_private };
211 // Can this klass be a primary super? False for interfaces and arrays of
212 // interfaces. False also for arrays or classes with long super chains.
213 bool can_be_primary_super() const {
214 const juint secondary_offset = in_bytes(secondary_super_cache_offset());
215 return super_check_offset() != secondary_offset;
216 }
217 virtual bool can_be_primary_super_slow() const;
218
219 // Returns number of primary supers; may be a number in the inclusive range [0, primary_super_limit].
220 juint super_depth() const {
221 if (!can_be_primary_super()) {
222 return primary_super_limit();
223 } else {
224 juint d = (super_check_offset() - in_bytes(primary_supers_offset())) / sizeof(Klass*);
225 assert(d < primary_super_limit(), "oob");
226 assert(_primary_supers[d] == this, "proper init");
227 return d;
228 }
229 }
230
231 // store an oop into a field of a Klass
232 void klass_oop_store(oop* p, oop v);
233 void klass_oop_store(volatile oop* p, oop v);
234
235 // java mirror
236 oop java_mirror() const { return _java_mirror; }
237 void set_java_mirror(oop m) { klass_oop_store(&_java_mirror, m); }
238
239 // modifier flags
240 jint modifier_flags() const { return _modifier_flags; }
241 void set_modifier_flags(jint flags) { _modifier_flags = flags; }
242
243 // size helper
244 int layout_helper() const { return _layout_helper; }
245 void set_layout_helper(int lh) { _layout_helper = lh; }
246
247 // Note: for instances layout_helper() may include padding.
248 // Use InstanceKlass::contains_field_offset to classify field offsets.
249
250 // sub/superklass links
251 Klass* subklass() const { return _subklass; }
252 Klass* next_sibling() const { return _next_sibling; }
253 InstanceKlass* superklass() const;
254 void append_to_sibling_list(); // add newly created receiver to superklass' subklass list
255
256 void set_next_link(Klass* k) { _next_link = k; }
257 Klass* next_link() const { return _next_link; } // The next klass defined by the class loader.
258
259 // class loader data
260 ClassLoaderData* class_loader_data() const { return _class_loader_data; }
261 void set_class_loader_data(ClassLoaderData* loader_data) { _class_loader_data = loader_data; }
262
263 // The Klasses are not placed in the Heap, so the Card Table or
264 // the Mod Union Table can't be used to mark when klasses have modified oops.
265 // The CT and MUT bits saves this information for the individual Klasses.
266 void record_modified_oops() { _modified_oops = 1; }
267 void clear_modified_oops() { _modified_oops = 0; }
268 bool has_modified_oops() { return _modified_oops == 1; }
269
270 void accumulate_modified_oops() { if (has_modified_oops()) _accumulated_modified_oops = 1; }
271 void clear_accumulated_modified_oops() { _accumulated_modified_oops = 0; }
272 bool has_accumulated_modified_oops() { return _accumulated_modified_oops == 1; }
273
274 int shared_classpath_index() const {
275 return _shared_class_path_index;
276 };
277
278 void set_shared_classpath_index(int index) {
279 _shared_class_path_index = index;
280 };
281
282 // Obtain the module or package for this class
283 virtual ModuleEntry* module() const = 0;
284 virtual PackageEntry* package() const = 0;
285
286 protected: // internal accessors
287 void set_subklass(Klass* s);
288 void set_next_sibling(Klass* s);
289
290 public:
291
292 // Compiler support
293 static ByteSize super_offset() { return in_ByteSize(offset_of(Klass, _super)); }
581 // NOTE: once instances of this klass are floating around in the
582 // system, this header must only be updated at a safepoint.
583 // NOTE 2: currently we only ever set the prototype header to the
584 // biasable prototype for instanceKlasses. There is no technical
585 // reason why it could not be done for arrayKlasses aside from
586 // wanting to reduce the initial scope of this optimization. There
587 // are potential problems in setting the bias pattern for
588 // JVM-internal oops.
589 inline void set_prototype_header(markOop header);
590 static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
591
592 int biased_lock_revocation_count() const { return (int) _biased_lock_revocation_count; }
593 // Atomically increments biased_lock_revocation_count and returns updated value
594 int atomic_incr_biased_lock_revocation_count();
595 void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; }
596 jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; }
597 void set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
598
599 TRACE_DEFINE_TRACE_ID_METHODS;
600
601 // garbage collection support
602 void oops_do(OopClosure* cl);
603
604 virtual void metaspace_pointers_do(MetaspaceClosure* iter);
605 virtual MetaspaceObj::Type type() const { return ClassType; }
606
607 // Iff the class loader (or mirror for anonymous classes) is alive the
608 // Klass is considered alive.
609 // The is_alive closure passed in depends on the Garbage Collector used.
610 bool is_loader_alive(BoolObjectClosure* is_alive);
611
612 static void clean_weak_klass_links(BoolObjectClosure* is_alive, bool clean_alive_klasses = true);
613 static void clean_subklass_tree(BoolObjectClosure* is_alive) {
614 clean_weak_klass_links(is_alive, false /* clean_alive_klasses */);
615 }
616
617 // GC specific object visitors
618 //
619 #if INCLUDE_ALL_GCS
620 // Parallel Scavenge
621 virtual void oop_ps_push_contents( oop obj, PSPromotionManager* pm) = 0;
622 // Parallel Compact
623 virtual void oop_pc_follow_contents(oop obj, ParCompactionManager* cm) = 0;
670 // Verification
671 virtual void verify_on(outputStream* st);
672 void verify() { verify_on(tty); }
673
674 #ifndef PRODUCT
675 bool verify_vtable_index(int index);
676 bool verify_itable_index(int index);
677 #endif
678
679 virtual void oop_verify_on(oop obj, outputStream* st);
680
681 static bool is_null(narrowKlass obj);
682 static bool is_null(Klass* obj);
683
684 // klass encoding for klass pointer in objects.
685 static narrowKlass encode_klass_not_null(Klass* v);
686 static narrowKlass encode_klass(Klass* v);
687
688 static Klass* decode_klass_not_null(narrowKlass v);
689 static Klass* decode_klass(narrowKlass v);
690
691 private:
692 // barriers used by klass_oop_store
693 void klass_update_barrier_set(oop v);
694 void klass_update_barrier_set_pre(oop* p, oop v);
695 };
696
697 // Helper to convert the oop iterate macro suffixes into bool values that can be used by template functions.
698 #define nvs_nv_to_bool true
699 #define nvs_v_to_bool false
700 #define nvs_to_bool(nv_suffix) nvs##nv_suffix##_to_bool
701
702 // Oop iteration macros for declarations.
703 // Used to generate declarations in the *Klass header files.
704
705 #define OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
706 void oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure); \
707 void oop_oop_iterate_bounded##nv_suffix(oop obj, OopClosureType* closure, MemRegion mr);
708
709 #if INCLUDE_ALL_GCS
710 #define OOP_OOP_ITERATE_DECL_BACKWARDS(OopClosureType, nv_suffix) \
711 void oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure);
712 #endif // INCLUDE_ALL_GCS
713
714
|
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_OOPS_KLASS_HPP
26 #define SHARE_VM_OOPS_KLASS_HPP
27
28 #include "gc/shared/specialized_oop_closures.hpp"
29 #include "memory/iterator.hpp"
30 #include "memory/memRegion.hpp"
31 #include "oops/metadata.hpp"
32 #include "oops/oop.hpp"
33 #include "oops/oopHandle.hpp"
34 #include "trace/traceMacros.hpp"
35 #include "utilities/accessFlags.hpp"
36 #include "utilities/macros.hpp"
37
38 //
39 // A Klass provides:
40 // 1: language level class object (method dictionary etc.)
41 // 2: provide vm dispatch behavior for the object
42 // Both functions are combined into one C++ class.
43
44 // One reason for the oop/klass dichotomy in the implementation is
45 // that we don't want a C++ vtbl pointer in every object. Thus,
46 // normal oops don't have any virtual functions. Instead, they
47 // forward all "virtual" functions to their klass, which does have
48 // a vtbl and does the C++ dispatch depending on the object's
49 // actual type. (See oop.inline.hpp for some of the forwarding code.)
50 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
51
52 // Forward declarations.
53 template <class T> class Array;
103
104 // The fields _super_check_offset, _secondary_super_cache, _secondary_supers
105 // and _primary_supers all help make fast subtype checks. See big discussion
106 // in doc/server_compiler/checktype.txt
107 //
108 // Where to look to observe a supertype (it is &_secondary_super_cache for
109 // secondary supers, else is &_primary_supers[depth()].
110 juint _super_check_offset;
111
112 // Class name. Instance classes: java/lang/String, etc. Array classes: [I,
113 // [Ljava/lang/String;, etc. Set to zero for all other kinds of classes.
114 Symbol* _name;
115
116 // Cache of last observed secondary supertype
117 Klass* _secondary_super_cache;
118 // Array of all secondary supertypes
119 Array<Klass*>* _secondary_supers;
120 // Ordered list of all primary supertypes
121 Klass* _primary_supers[_primary_super_limit];
122 // java/lang/Class instance mirroring this class
123 OopHandle _java_mirror;
124 // Superclass
125 Klass* _super;
126 // First subclass (NULL if none); _subklass->next_sibling() is next one
127 Klass* _subklass;
128 // Sibling link (or NULL); links all subklasses of a klass
129 Klass* _next_sibling;
130
131 // All klasses loaded by a class loader are chained through these links
132 Klass* _next_link;
133
134 // The VM's representation of the ClassLoader used to load this class.
135 // Provide access the corresponding instance java.lang.ClassLoader.
136 ClassLoaderData* _class_loader_data;
137
138 jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
139 AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
140
141 TRACE_DEFINE_TRACE_ID_FIELD;
142
143 // Biased locking implementation and statistics
144 // (the 64-bit chunk goes first, to avoid some fragmentation)
145 jlong _last_biased_lock_bulk_revocation_time;
146 markOop _prototype_header; // Used when biased locking is both enabled and disabled for this type
147 jint _biased_lock_revocation_count;
148
149 // vtable length
150 int _vtable_len;
151
152 private:
153 // This is an index into FileMapHeader::_classpath_entry_table[], to
154 // associate this class with the JAR file where it's loaded from during
155 // dump time. If a class is not loaded from the shared archive, this field is
156 // -1.
157 jshort _shared_class_path_index;
158
159 friend class SharedClassUtil;
160 protected:
161
162 // Constructor
163 Klass();
164
165 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
166
167 public:
168 enum DefaultsLookupMode { find_defaults, skip_defaults };
169 enum OverpassLookupMode { find_overpass, skip_overpass };
170 enum StaticLookupMode { find_static, skip_static };
171 enum PrivateLookupMode { find_private, skip_private };
208 // Can this klass be a primary super? False for interfaces and arrays of
209 // interfaces. False also for arrays or classes with long super chains.
210 bool can_be_primary_super() const {
211 const juint secondary_offset = in_bytes(secondary_super_cache_offset());
212 return super_check_offset() != secondary_offset;
213 }
214 virtual bool can_be_primary_super_slow() const;
215
216 // Returns number of primary supers; may be a number in the inclusive range [0, primary_super_limit].
217 juint super_depth() const {
218 if (!can_be_primary_super()) {
219 return primary_super_limit();
220 } else {
221 juint d = (super_check_offset() - in_bytes(primary_supers_offset())) / sizeof(Klass*);
222 assert(d < primary_super_limit(), "oob");
223 assert(_primary_supers[d] == this, "proper init");
224 return d;
225 }
226 }
227
228 // java mirror
229 oop java_mirror() const;
230 void set_java_mirror(Handle m);
231
232 // modifier flags
233 jint modifier_flags() const { return _modifier_flags; }
234 void set_modifier_flags(jint flags) { _modifier_flags = flags; }
235
236 // size helper
237 int layout_helper() const { return _layout_helper; }
238 void set_layout_helper(int lh) { _layout_helper = lh; }
239
240 // Note: for instances layout_helper() may include padding.
241 // Use InstanceKlass::contains_field_offset to classify field offsets.
242
243 // sub/superklass links
244 Klass* subklass() const { return _subklass; }
245 Klass* next_sibling() const { return _next_sibling; }
246 InstanceKlass* superklass() const;
247 void append_to_sibling_list(); // add newly created receiver to superklass' subklass list
248
249 void set_next_link(Klass* k) { _next_link = k; }
250 Klass* next_link() const { return _next_link; } // The next klass defined by the class loader.
251
252 // class loader data
253 ClassLoaderData* class_loader_data() const { return _class_loader_data; }
254 void set_class_loader_data(ClassLoaderData* loader_data) { _class_loader_data = loader_data; }
255
256 int shared_classpath_index() const {
257 return _shared_class_path_index;
258 };
259
260 void set_shared_classpath_index(int index) {
261 _shared_class_path_index = index;
262 };
263
264 // Obtain the module or package for this class
265 virtual ModuleEntry* module() const = 0;
266 virtual PackageEntry* package() const = 0;
267
268 protected: // internal accessors
269 void set_subklass(Klass* s);
270 void set_next_sibling(Klass* s);
271
272 public:
273
274 // Compiler support
275 static ByteSize super_offset() { return in_ByteSize(offset_of(Klass, _super)); }
563 // NOTE: once instances of this klass are floating around in the
564 // system, this header must only be updated at a safepoint.
565 // NOTE 2: currently we only ever set the prototype header to the
566 // biasable prototype for instanceKlasses. There is no technical
567 // reason why it could not be done for arrayKlasses aside from
568 // wanting to reduce the initial scope of this optimization. There
569 // are potential problems in setting the bias pattern for
570 // JVM-internal oops.
571 inline void set_prototype_header(markOop header);
572 static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
573
574 int biased_lock_revocation_count() const { return (int) _biased_lock_revocation_count; }
575 // Atomically increments biased_lock_revocation_count and returns updated value
576 int atomic_incr_biased_lock_revocation_count();
577 void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; }
578 jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; }
579 void set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
580
581 TRACE_DEFINE_TRACE_ID_METHODS;
582
583 virtual void metaspace_pointers_do(MetaspaceClosure* iter);
584 virtual MetaspaceObj::Type type() const { return ClassType; }
585
586 // Iff the class loader (or mirror for anonymous classes) is alive the
587 // Klass is considered alive.
588 // The is_alive closure passed in depends on the Garbage Collector used.
589 bool is_loader_alive(BoolObjectClosure* is_alive);
590
591 static void clean_weak_klass_links(BoolObjectClosure* is_alive, bool clean_alive_klasses = true);
592 static void clean_subklass_tree(BoolObjectClosure* is_alive) {
593 clean_weak_klass_links(is_alive, false /* clean_alive_klasses */);
594 }
595
596 // GC specific object visitors
597 //
598 #if INCLUDE_ALL_GCS
599 // Parallel Scavenge
600 virtual void oop_ps_push_contents( oop obj, PSPromotionManager* pm) = 0;
601 // Parallel Compact
602 virtual void oop_pc_follow_contents(oop obj, ParCompactionManager* cm) = 0;
649 // Verification
650 virtual void verify_on(outputStream* st);
651 void verify() { verify_on(tty); }
652
653 #ifndef PRODUCT
654 bool verify_vtable_index(int index);
655 bool verify_itable_index(int index);
656 #endif
657
658 virtual void oop_verify_on(oop obj, outputStream* st);
659
660 static bool is_null(narrowKlass obj);
661 static bool is_null(Klass* obj);
662
663 // klass encoding for klass pointer in objects.
664 static narrowKlass encode_klass_not_null(Klass* v);
665 static narrowKlass encode_klass(Klass* v);
666
667 static Klass* decode_klass_not_null(narrowKlass v);
668 static Klass* decode_klass(narrowKlass v);
669 };
670
671 // Helper to convert the oop iterate macro suffixes into bool values that can be used by template functions.
672 #define nvs_nv_to_bool true
673 #define nvs_v_to_bool false
674 #define nvs_to_bool(nv_suffix) nvs##nv_suffix##_to_bool
675
676 // Oop iteration macros for declarations.
677 // Used to generate declarations in the *Klass header files.
678
679 #define OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
680 void oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure); \
681 void oop_oop_iterate_bounded##nv_suffix(oop obj, OopClosureType* closure, MemRegion mr);
682
683 #if INCLUDE_ALL_GCS
684 #define OOP_OOP_ITERATE_DECL_BACKWARDS(OopClosureType, nv_suffix) \
685 void oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure);
686 #endif // INCLUDE_ALL_GCS
687
688
|