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 "memory/genOopClosures.hpp"
29 #include "memory/iterator.hpp"
30 #include "memory/memRegion.hpp"
31 #include "memory/specialized_oop_closures.hpp"
32 #include "oops/klassPS.hpp"
33 #include "oops/metadata.hpp"
34 #include "oops/oop.hpp"
35 #include "trace/traceMacros.hpp"
36 #include "utilities/accessFlags.hpp"
37 #include "utilities/macros.hpp"
38 #if INCLUDE_ALL_GCS
39 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.hpp"
40 #include "gc_implementation/g1/g1OopClosures.hpp"
41 #include "gc_implementation/parNew/parOopClosures.hpp"
42 #endif // INCLUDE_ALL_GCS
43
44 //
45 // A Klass provides:
46 // 1: language level class object (method dictionary etc.)
47 // 2: provide vm dispatch behavior for the object
48 // Both functions are combined into one C++ class.
49
50 // One reason for the oop/klass dichotomy in the implementation is
51 // that we don't want a C++ vtbl pointer in every object. Thus,
52 // normal oops don't have any virtual functions. Instead, they
53 // forward all "virtual" functions to their klass, which does have
54 // a vtbl and does the C++ dispatch depending on the object's
55 // actual type. (See oop.inline.hpp for some of the forwarding code.)
56 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
57
58 // Klass layout:
59 // [C++ vtbl ptr ] (contained in Metadata)
60 // [layout_helper ]
61 // [super_check_offset ] for fast subtype checks
62 // [name ]
153 Klass* _subklass;
154 // Sibling link (or NULL); links all subklasses of a klass
155 Klass* _next_sibling;
156
157 // All klasses loaded by a class loader are chained through these links
158 Klass* _next_link;
159
160 // The VM's representation of the ClassLoader used to load this class.
161 // Provide access the corresponding instance java.lang.ClassLoader.
162 ClassLoaderData* _class_loader_data;
163
164 jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
165 AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
166
167 // Biased locking implementation and statistics
168 // (the 64-bit chunk goes first, to avoid some fragmentation)
169 jlong _last_biased_lock_bulk_revocation_time;
170 markOop _prototype_header; // Used when biased locking is both enabled and disabled for this type
171 jint _biased_lock_revocation_count;
172
173 TRACE_DEFINE_KLASS_TRACE_ID;
174
175 // Remembered sets support for the oops in the klasses.
176 jbyte _modified_oops; // Card Table Equivalent (YC/CMS support)
177 jbyte _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
178
179 private:
180 // This is an index into FileMapHeader::_classpath_entry_table[], to
181 // associate this class with the JAR file where it's loaded from during
182 // dump time. If a class is not loaded from the shared archive, this field is
183 // -1.
184 jshort _shared_class_path_index;
185
186 friend class SharedClassUtil;
187 protected:
188
189 // Constructor
190 Klass();
191
192 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
193
595 // biasable and have an epoch.
596 markOop prototype_header() const { return _prototype_header; }
597 // NOTE: once instances of this klass are floating around in the
598 // system, this header must only be updated at a safepoint.
599 // NOTE 2: currently we only ever set the prototype header to the
600 // biasable prototype for instanceKlasses. There is no technical
601 // reason why it could not be done for arrayKlasses aside from
602 // wanting to reduce the initial scope of this optimization. There
603 // are potential problems in setting the bias pattern for
604 // JVM-internal oops.
605 inline void set_prototype_header(markOop header);
606 static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
607
608 int biased_lock_revocation_count() const { return (int) _biased_lock_revocation_count; }
609 // Atomically increments biased_lock_revocation_count and returns updated value
610 int atomic_incr_biased_lock_revocation_count();
611 void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; }
612 jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; }
613 void set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
614
615 TRACE_DEFINE_KLASS_METHODS;
616
617 // garbage collection support
618 virtual void oops_do(OopClosure* cl);
619
620 // Iff the class loader (or mirror for anonymous classes) is alive the
621 // Klass is considered alive.
622 // The is_alive closure passed in depends on the Garbage Collector used.
623 bool is_loader_alive(BoolObjectClosure* is_alive);
624
625 static void clean_weak_klass_links(BoolObjectClosure* is_alive, bool clean_alive_klasses = true);
626 static void clean_subklass_tree(BoolObjectClosure* is_alive) {
627 clean_weak_klass_links(is_alive, false /* clean_alive_klasses */);
628 }
629
630 // iterators
631 virtual int oop_oop_iterate(oop obj, ExtendedOopClosure* blk) = 0;
632 virtual int oop_oop_iterate_v(oop obj, ExtendedOopClosure* blk) {
633 return oop_oop_iterate(obj, blk);
634 }
635
|
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 "memory/genOopClosures.hpp"
29 #include "memory/iterator.hpp"
30 #include "memory/memRegion.hpp"
31 #include "memory/specialized_oop_closures.hpp"
32 #include "oops/klassPS.hpp"
33 #include "oops/metadata.hpp"
34 #include "oops/oop.hpp"
35 #include "utilities/accessFlags.hpp"
36 #include "utilities/macros.hpp"
37 #if INCLUDE_ALL_GCS
38 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.hpp"
39 #include "gc_implementation/g1/g1OopClosures.hpp"
40 #include "gc_implementation/parNew/parOopClosures.hpp"
41 #endif // INCLUDE_ALL_GCS
42 #if INCLUDE_JFR
43 #include "jfr/support/jfrTraceIdExtension.hpp"
44 #endif
45
46 //
47 // A Klass provides:
48 // 1: language level class object (method dictionary etc.)
49 // 2: provide vm dispatch behavior for the object
50 // Both functions are combined into one C++ class.
51
52 // One reason for the oop/klass dichotomy in the implementation is
53 // that we don't want a C++ vtbl pointer in every object. Thus,
54 // normal oops don't have any virtual functions. Instead, they
55 // forward all "virtual" functions to their klass, which does have
56 // a vtbl and does the C++ dispatch depending on the object's
57 // actual type. (See oop.inline.hpp for some of the forwarding code.)
58 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
59
60 // Klass layout:
61 // [C++ vtbl ptr ] (contained in Metadata)
62 // [layout_helper ]
63 // [super_check_offset ] for fast subtype checks
64 // [name ]
155 Klass* _subklass;
156 // Sibling link (or NULL); links all subklasses of a klass
157 Klass* _next_sibling;
158
159 // All klasses loaded by a class loader are chained through these links
160 Klass* _next_link;
161
162 // The VM's representation of the ClassLoader used to load this class.
163 // Provide access the corresponding instance java.lang.ClassLoader.
164 ClassLoaderData* _class_loader_data;
165
166 jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
167 AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
168
169 // Biased locking implementation and statistics
170 // (the 64-bit chunk goes first, to avoid some fragmentation)
171 jlong _last_biased_lock_bulk_revocation_time;
172 markOop _prototype_header; // Used when biased locking is both enabled and disabled for this type
173 jint _biased_lock_revocation_count;
174
175 JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
176
177 // Remembered sets support for the oops in the klasses.
178 jbyte _modified_oops; // Card Table Equivalent (YC/CMS support)
179 jbyte _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
180
181 private:
182 // This is an index into FileMapHeader::_classpath_entry_table[], to
183 // associate this class with the JAR file where it's loaded from during
184 // dump time. If a class is not loaded from the shared archive, this field is
185 // -1.
186 jshort _shared_class_path_index;
187
188 friend class SharedClassUtil;
189 protected:
190
191 // Constructor
192 Klass();
193
194 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
195
597 // biasable and have an epoch.
598 markOop prototype_header() const { return _prototype_header; }
599 // NOTE: once instances of this klass are floating around in the
600 // system, this header must only be updated at a safepoint.
601 // NOTE 2: currently we only ever set the prototype header to the
602 // biasable prototype for instanceKlasses. There is no technical
603 // reason why it could not be done for arrayKlasses aside from
604 // wanting to reduce the initial scope of this optimization. There
605 // are potential problems in setting the bias pattern for
606 // JVM-internal oops.
607 inline void set_prototype_header(markOop header);
608 static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
609
610 int biased_lock_revocation_count() const { return (int) _biased_lock_revocation_count; }
611 // Atomically increments biased_lock_revocation_count and returns updated value
612 int atomic_incr_biased_lock_revocation_count();
613 void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; }
614 jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; }
615 void set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
616
617 JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
618
619 // garbage collection support
620 virtual void oops_do(OopClosure* cl);
621
622 // Iff the class loader (or mirror for anonymous classes) is alive the
623 // Klass is considered alive.
624 // The is_alive closure passed in depends on the Garbage Collector used.
625 bool is_loader_alive(BoolObjectClosure* is_alive);
626
627 static void clean_weak_klass_links(BoolObjectClosure* is_alive, bool clean_alive_klasses = true);
628 static void clean_subklass_tree(BoolObjectClosure* is_alive) {
629 clean_weak_klass_links(is_alive, false /* clean_alive_klasses */);
630 }
631
632 // iterators
633 virtual int oop_oop_iterate(oop obj, ExtendedOopClosure* blk) = 0;
634 virtual int oop_oop_iterate_v(oop obj, ExtendedOopClosure* blk) {
635 return oop_oop_iterate(obj, blk);
636 }
637
|