1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
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 "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
|
1 /*
2 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
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 "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 #include "jfr/utilities/jfrLog.hpp"
44
45 //
46 // A Klass provides:
47 // 1: language level class object (method dictionary etc.)
48 // 2: provide vm dispatch behavior for the object
49 // Both functions are combined into one C++ class.
50
51 // One reason for the oop/klass dichotomy in the implementation is
52 // that we don't want a C++ vtbl pointer in every object. Thus,
53 // normal oops don't have any virtual functions. Instead, they
54 // forward all "virtual" functions to their klass, which does have
55 // a vtbl and does the C++ dispatch depending on the object's
56 // actual type. (See oop.inline.hpp for some of the forwarding code.)
57 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
58
59 // Klass layout:
60 // [C++ vtbl ptr ] (contained in Metadata)
61 // [layout_helper ]
62 // [super_check_offset ] for fast subtype checks
63 // [name ]
154 Klass* _subklass;
155 // Sibling link (or NULL); links all subklasses of a klass
156 Klass* _next_sibling;
157
158 // All klasses loaded by a class loader are chained through these links
159 Klass* _next_link;
160
161 // The VM's representation of the ClassLoader used to load this class.
162 // Provide access the corresponding instance java.lang.ClassLoader.
163 ClassLoaderData* _class_loader_data;
164
165 jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
166 AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
167
168 // Biased locking implementation and statistics
169 // (the 64-bit chunk goes first, to avoid some fragmentation)
170 jlong _last_biased_lock_bulk_revocation_time;
171 markOop _prototype_header; // Used when biased locking is both enabled and disabled for this type
172 jint _biased_lock_revocation_count;
173
174 TRACE_DEFINE_TRACE_ID_FIELD;
175
176 // Remembered sets support for the oops in the klasses.
177 jbyte _modified_oops; // Card Table Equivalent (YC/CMS support)
178 jbyte _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
179
180 private:
181 // This is an index into FileMapHeader::_classpath_entry_table[], to
182 // associate this class with the JAR file where it's loaded from during
183 // dump time. If a class is not loaded from the shared archive, this field is
184 // -1.
185 jshort _shared_class_path_index;
186
187 friend class SharedClassUtil;
188 protected:
189
190 // Constructor
191 Klass();
192
193 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
194
596 // biasable and have an epoch.
597 markOop prototype_header() const { return _prototype_header; }
598 // NOTE: once instances of this klass are floating around in the
599 // system, this header must only be updated at a safepoint.
600 // NOTE 2: currently we only ever set the prototype header to the
601 // biasable prototype for instanceKlasses. There is no technical
602 // reason why it could not be done for arrayKlasses aside from
603 // wanting to reduce the initial scope of this optimization. There
604 // are potential problems in setting the bias pattern for
605 // JVM-internal oops.
606 inline void set_prototype_header(markOop header);
607 static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
608
609 int biased_lock_revocation_count() const { return (int) _biased_lock_revocation_count; }
610 // Atomically increments biased_lock_revocation_count and returns updated value
611 int atomic_incr_biased_lock_revocation_count();
612 void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; }
613 jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; }
614 void set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
615
616 TRACE_DEFINE_TRACE_ID_METHODS;
617
618 // garbage collection support
619 virtual void oops_do(OopClosure* cl);
620
621 // Iff the class loader (or mirror for anonymous classes) is alive the
622 // Klass is considered alive.
623 // The is_alive closure passed in depends on the Garbage Collector used.
624 bool is_loader_alive(BoolObjectClosure* is_alive);
625
626 static void clean_weak_klass_links(BoolObjectClosure* is_alive, bool clean_alive_klasses = true);
627 static void clean_subklass_tree(BoolObjectClosure* is_alive) {
628 clean_weak_klass_links(is_alive, false /* clean_alive_klasses */);
629 }
630
631 // iterators
632 virtual int oop_oop_iterate(oop obj, ExtendedOopClosure* blk) = 0;
633 virtual int oop_oop_iterate_v(oop obj, ExtendedOopClosure* blk) {
634 return oop_oop_iterate(obj, blk);
635 }
636
|