comparison src/share/vm/oops/klass.hpp @ 6948:e522a00b91aa

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/ after NPG - C++ build works
author Doug Simon <doug.simon@oracle.com>
date Mon, 12 Nov 2012 23:14:12 +0100
parents dddcdb7ae209 da91efe96a93
children 2cb439954abf
comparison
equal deleted inserted replaced
6711:ae13cc658b80 6948:e522a00b91aa
27 27
28 #include "memory/genOopClosures.hpp" 28 #include "memory/genOopClosures.hpp"
29 #include "memory/iterator.hpp" 29 #include "memory/iterator.hpp"
30 #include "memory/memRegion.hpp" 30 #include "memory/memRegion.hpp"
31 #include "memory/specialized_oop_closures.hpp" 31 #include "memory/specialized_oop_closures.hpp"
32 #include "oops/klassOop.hpp"
33 #include "oops/klassPS.hpp" 32 #include "oops/klassPS.hpp"
33 #include "oops/metadata.hpp"
34 #include "oops/oop.hpp" 34 #include "oops/oop.hpp"
35 #include "runtime/orderAccess.hpp" 35 #include "runtime/orderAccess.hpp"
36 #include "trace/traceMacros.hpp" 36 #include "trace/traceMacros.hpp"
37 #include "utilities/accessFlags.hpp" 37 #include "utilities/accessFlags.hpp"
38 #ifndef SERIALGC 38 #ifndef SERIALGC
39 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.hpp" 39 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.hpp"
40 #include "gc_implementation/g1/g1OopClosures.hpp" 40 #include "gc_implementation/g1/g1OopClosures.hpp"
41 #include "gc_implementation/parNew/parOopClosures.hpp" 41 #include "gc_implementation/parNew/parOopClosures.hpp"
42 #endif 42 #endif
43 43
44 // A Klass is the part of the klassOop that provides: 44 //
45 // A Klass provides:
45 // 1: language level class object (method dictionary etc.) 46 // 1: language level class object (method dictionary etc.)
46 // 2: provide vm dispatch behavior for the object 47 // 2: provide vm dispatch behavior for the object
47 // Both functions are combined into one C++ class. The toplevel class "Klass" 48 // Both functions are combined into one C++ class.
48 // implements purpose 1 whereas all subclasses provide extra virtual functions
49 // for purpose 2.
50 49
51 // One reason for the oop/klass dichotomy in the implementation is 50 // 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, 51 // that we don't want a C++ vtbl pointer in every object. Thus,
53 // normal oops don't have any virtual functions. Instead, they 52 // normal oops don't have any virtual functions. Instead, they
54 // forward all "virtual" functions to their klass, which does have 53 // forward all "virtual" functions to their klass, which does have
55 // a vtbl and does the C++ dispatch depending on the object's 54 // 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.) 55 // actual type. (See oop.inline.hpp for some of the forwarding code.)
57 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"! 56 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
58 57
59 // Klass layout: 58 // Klass layout:
60 // [header ] klassOop 59 // [C++ vtbl ptr ] (contained in Metadata)
61 // [klass pointer ] klassOop
62 // [C++ vtbl ptr ] (contained in Klass_vtbl)
63 // [layout_helper ] 60 // [layout_helper ]
64 // [super_check_offset ] for fast subtype checks 61 // [super_check_offset ] for fast subtype checks
62 // [name ]
65 // [secondary_super_cache] for fast subtype checks 63 // [secondary_super_cache] for fast subtype checks
66 // [secondary_supers ] array of 2ndary supertypes 64 // [secondary_supers ] array of 2ndary supertypes
67 // [primary_supers 0] 65 // [primary_supers 0]
68 // [primary_supers 1] 66 // [primary_supers 1]
69 // [primary_supers 2] 67 // [primary_supers 2]
70 // ... 68 // ...
71 // [primary_supers 7] 69 // [primary_supers 7]
72 // [java_mirror ] 70 // [java_mirror ]
73 // [super ] 71 // [super ]
74 // [name ] 72 // [subklass ] first subclass
75 // [first subklass]
76 // [next_sibling ] link to chain additional subklasses 73 // [next_sibling ] link to chain additional subklasses
74 // [next_link ]
75 // [class_loader_data]
77 // [modifier_flags] 76 // [modifier_flags]
78 // [access_flags ] 77 // [access_flags ]
79 // [verify_count ] - not in product 78 // [verify_count ] - not in product
80 // [alloc_count ] 79 // [alloc_count ]
81 // [last_biased_lock_bulk_revocation_time] (64 bits) 80 // [last_biased_lock_bulk_revocation_time] (64 bits)
82 // [prototype_header] 81 // [prototype_header]
83 // [biased_lock_revocation_count] 82 // [biased_lock_revocation_count]
83 // [_modified_oops]
84 // [_accumulated_modified_oops]
84 // [trace_id] 85 // [trace_id]
85 86
86 87
87 // Forward declarations. 88 // Forward declarations.
89 template <class T> class Array;
90 template <class T> class GrowableArray;
91 class ClassLoaderData;
88 class klassVtable; 92 class klassVtable;
89 class KlassHandle; 93 class ParCompactionManager;
90 class OrderAccess; 94
91 95 class Klass : public Metadata {
92 // Holder (or cage) for the C++ vtable of each kind of Klass.
93 // We want to tightly constrain the location of the C++ vtable in the overall layout.
94 class Klass_vtbl {
95 protected:
96 // The following virtual exists only to force creation of a C++ vtable,
97 // so that this class truly is the location of the vtable of all Klasses.
98 virtual void unused_initial_virtual() { }
99
100 public:
101 // The following virtual makes Klass_vtbl play a second role as a
102 // factory protocol for subclasses of Klass ("sub-Klasses").
103 // Here's how it works....
104 //
105 // This VM uses metaobjects as factories for their instances.
106 //
107 // In order to initialize the C++ vtable of a new instance, its
108 // metaobject is forced to use the C++ placed new operator to
109 // allocate the instance. In a typical C++-based system, each
110 // sub-class would have its own factory routine which
111 // directly uses the placed new operator on the desired class,
112 // and then calls the appropriate chain of C++ constructors.
113 //
114 // However, this system uses shared code to performs the first
115 // allocation and initialization steps for all sub-Klasses.
116 // (See base_create_klass() and base_create_array_klass().)
117 // This does not factor neatly into a hierarchy of C++ constructors.
118 // Each caller of these shared "base_create" routines knows
119 // exactly which sub-Klass it is creating, but the shared routine
120 // does not, even though it must perform the actual allocation.
121 //
122 // Therefore, the caller of the shared "base_create" must wrap
123 // the specific placed new call in a virtual function which
124 // performs the actual allocation and vtable set-up. That
125 // virtual function is here, Klass_vtbl::allocate_permanent.
126 //
127 // The arguments to Universe::allocate_permanent() are passed
128 // straight through the placed new operator, which in turn
129 // obtains them directly from this virtual call.
130 //
131 // This virtual is called on a temporary "example instance" of the
132 // sub-Klass being instantiated, a C++ auto variable. The "real"
133 // instance created by this virtual is on the VM heap, where it is
134 // equipped with a klassOopDesc header.
135 //
136 // It is merely an accident of implementation that we use "example
137 // instances", but that is why the virtual function which implements
138 // each sub-Klass factory happens to be defined by the same sub-Klass
139 // for which it creates instances.
140 //
141 // The vtbl_value() call (see below) is used to strip away the
142 // accidental Klass-ness from an "example instance" and present it as
143 // a factory. Think of each factory object as a mere container of the
144 // C++ vtable for the desired sub-Klass. Since C++ does not allow
145 // direct references to vtables, the factory must also be delegated
146 // the task of allocating the instance, but the essential point is
147 // that the factory knows how to initialize the C++ vtable with the
148 // right pointer value. All other common initializations are handled
149 // by the shared "base_create" subroutines.
150 //
151 virtual void* allocate_permanent(KlassHandle& klass, int size, TRAPS) const = 0;
152 void post_new_init_klass(KlassHandle& klass, klassOop obj) const;
153
154 // Every subclass on which vtbl_value is called must include this macro.
155 // Delay the installation of the klassKlass pointer until after the
156 // the vtable for a new klass has been installed (after the call to new()).
157 #define DEFINE_ALLOCATE_PERMANENT(thisKlass) \
158 void* allocate_permanent(KlassHandle& klass_klass, int size, TRAPS) const { \
159 void* result = new(klass_klass, size, THREAD) thisKlass(); \
160 if (HAS_PENDING_EXCEPTION) return NULL; \
161 klassOop new_klass = ((Klass*) result)->as_klassOop(); \
162 OrderAccess::storestore(); \
163 post_new_init_klass(klass_klass, new_klass); \
164 return result; \
165 }
166
167 bool null_vtbl() { return *(intptr_t*)this == 0; }
168
169 protected:
170 void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
171 };
172
173
174 class Klass : public Klass_vtbl {
175 friend class VMStructs; 96 friend class VMStructs;
176 protected: 97 protected:
177 // note: put frequently-used fields together at start of klass structure 98 // note: put frequently-used fields together at start of klass structure
178 // for better cache behavior (may not make much of a difference but sure won't hurt) 99 // for better cache behavior (may not make much of a difference but sure won't hurt)
179 enum { _primary_super_limit = 8 }; 100 enum { _primary_super_limit = 8 };
200 // The esz bits can be used directly by a SLL instruction, without masking. 121 // The esz bits can be used directly by a SLL instruction, without masking.
201 // 122 //
202 // Note that the array-kind tag looks like 0x00 for instance klasses, 123 // Note that the array-kind tag looks like 0x00 for instance klasses,
203 // since their length in bytes is always less than 24Mb. 124 // since their length in bytes is always less than 24Mb.
204 // 125 //
205 // Final note: This comes first, immediately after Klass_vtbl, 126 // Final note: This comes first, immediately after C++ vtable,
206 // because it is frequently queried. 127 // because it is frequently queried.
207 jint _layout_helper; 128 jint _layout_helper;
208 129
209 // The fields _super_check_offset, _secondary_super_cache, _secondary_supers 130 // The fields _super_check_offset, _secondary_super_cache, _secondary_supers
210 // and _primary_supers all help make fast subtype checks. See big discussion 131 // and _primary_supers all help make fast subtype checks. See big discussion
216 137
217 // Class name. Instance classes: java/lang/String, etc. Array classes: [I, 138 // Class name. Instance classes: java/lang/String, etc. Array classes: [I,
218 // [Ljava/lang/String;, etc. Set to zero for all other kinds of classes. 139 // [Ljava/lang/String;, etc. Set to zero for all other kinds of classes.
219 Symbol* _name; 140 Symbol* _name;
220 141
221 public:
222 oop* oop_block_beg() const { return adr_secondary_super_cache(); }
223 oop* oop_block_end() const { return adr_next_sibling() + 1; }
224
225 protected:
226 //
227 // The oop block. All oop fields must be declared here and only oop fields
228 // may be declared here. In addition, the first and last fields in this block
229 // must remain first and last, unless oop_block_beg() and/or oop_block_end()
230 // are updated. Grouping the oop fields in a single block simplifies oop
231 // iteration.
232 //
233
234 // Cache of last observed secondary supertype 142 // Cache of last observed secondary supertype
235 klassOop _secondary_super_cache; 143 Klass* _secondary_super_cache;
236 // Array of all secondary supertypes 144 // Array of all secondary supertypes
237 objArrayOop _secondary_supers; 145 Array<Klass*>* _secondary_supers;
238 // Ordered list of all primary supertypes 146 // Ordered list of all primary supertypes
239 klassOop _primary_supers[_primary_super_limit]; 147 Klass* _primary_supers[_primary_super_limit];
240 // java/lang/Class instance mirroring this class 148 // java/lang/Class instance mirroring this class
241 oop _java_mirror; 149 oop _java_mirror;
242 // com/oracle/graal/hotspot/HotSpotResolvedJavaType mirroring this class 150 // com/oracle/graal/hotspot/HotSpotResolvedJavaType mirroring this class
243 oop _graal_mirror; 151 oop _graal_mirror;
244 // Superclass 152 // Superclass
245 klassOop _super; 153 Klass* _super;
246 // First subclass (NULL if none); _subklass->next_sibling() is next one 154 // First subclass (NULL if none); _subklass->next_sibling() is next one
247 klassOop _subklass; 155 Klass* _subklass;
248 // Sibling link (or NULL); links all subklasses of a klass 156 // Sibling link (or NULL); links all subklasses of a klass
249 klassOop _next_sibling; 157 Klass* _next_sibling;
250 158
251 // 159 // All klasses loaded by a class loader are chained through these links
252 // End of the oop block. 160 Klass* _next_link;
253 // 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;
254 165
255 jint _modifier_flags; // Processed access flags, for use by Class.getModifiers. 166 jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
256 AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here. 167 AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
257 168
258 #ifndef PRODUCT 169 #ifndef PRODUCT
259 int _verify_count; // to avoid redundant verifies 170 int _verify_count; // to avoid redundant verifies
260 #endif 171 #endif
261 172
262 juint _alloc_count; // allocation profiling support - update klass_size_in_bytes() if moved/deleted 173 juint _alloc_count; // allocation profiling support
263 174
264 // Biased locking implementation and statistics 175 // Biased locking implementation and statistics
265 // (the 64-bit chunk goes first, to avoid some fragmentation) 176 // (the 64-bit chunk goes first, to avoid some fragmentation)
266 jlong _last_biased_lock_bulk_revocation_time; 177 jlong _last_biased_lock_bulk_revocation_time;
267 markOop _prototype_header; // Used when biased locking is both enabled and disabled for this type 178 markOop _prototype_header; // Used when biased locking is both enabled and disabled for this type
268 jint _biased_lock_revocation_count; 179 jint _biased_lock_revocation_count;
269 180
270 TRACE_DEFINE_KLASS_TRACE_ID; 181 TRACE_DEFINE_KLASS_TRACE_ID;
182
183 // Remembered sets support for the oops in the klasses.
184 jbyte _modified_oops; // Card Table Equivalent (YC/CMS support)
185 jbyte _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
186
187 // Constructor
188 Klass();
189
190 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS);
191
271 public: 192 public:
272 193 bool is_klass() const volatile { return true; }
273 // returns the enclosing klassOop
274 klassOop as_klassOop() const {
275 // see klassOop.hpp for layout.
276 return (klassOop) (((char*) this) - sizeof(klassOopDesc));
277 }
278
279 public:
280 // Allocation
281 const Klass_vtbl& vtbl_value() const { return *this; } // used only on "example instances"
282 static KlassHandle base_create_klass(KlassHandle& klass, int size, const Klass_vtbl& vtbl, TRAPS);
283 static klassOop base_create_klass_oop(KlassHandle& klass, int size, const Klass_vtbl& vtbl, TRAPS);
284 194
285 // super 195 // super
286 klassOop super() const { return _super; } 196 Klass* super() const { return _super; }
287 void set_super(klassOop k) { oop_store_without_check((oop*) &_super, (oop) k); } 197 void set_super(Klass* k) { _super = k; }
288 198
289 // initializes _super link, _primary_supers & _secondary_supers arrays 199 // initializes _super link, _primary_supers & _secondary_supers arrays
290 void initialize_supers(klassOop k, TRAPS); 200 void initialize_supers(Klass* k, TRAPS);
291 void initialize_supers_impl1(klassOop k); 201 void initialize_supers_impl1(Klass* k);
292 void initialize_supers_impl2(klassOop k); 202 void initialize_supers_impl2(Klass* k);
293 203
294 // klass-specific helper for initializing _secondary_supers 204 // klass-specific helper for initializing _secondary_supers
295 virtual objArrayOop compute_secondary_supers(int num_extra_slots, TRAPS); 205 virtual GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots);
296 206
297 // java_super is the Java-level super type as specified by Class.getSuperClass. 207 // java_super is the Java-level super type as specified by Class.getSuperClass.
298 virtual klassOop java_super() const { return NULL; } 208 virtual Klass* java_super() const { return NULL; }
299 209
300 juint super_check_offset() const { return _super_check_offset; } 210 juint super_check_offset() const { return _super_check_offset; }
301 void set_super_check_offset(juint o) { _super_check_offset = o; } 211 void set_super_check_offset(juint o) { _super_check_offset = o; }
302 212
303 klassOop secondary_super_cache() const { return _secondary_super_cache; } 213 Klass* secondary_super_cache() const { return _secondary_super_cache; }
304 void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); } 214 void set_secondary_super_cache(Klass* k) { _secondary_super_cache = k; }
305 215
306 objArrayOop secondary_supers() const { return _secondary_supers; } 216 Array<Klass*>* secondary_supers() const { return _secondary_supers; }
307 void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); } 217 void set_secondary_supers(Array<Klass*>* k) { _secondary_supers = k; }
308 218
309 // Return the element of the _super chain of the given depth. 219 // Return the element of the _super chain of the given depth.
310 // If there is no such element, return either NULL or this. 220 // If there is no such element, return either NULL or this.
311 klassOop primary_super_of_depth(juint i) const { 221 Klass* primary_super_of_depth(juint i) const {
312 assert(i < primary_super_limit(), "oob"); 222 assert(i < primary_super_limit(), "oob");
313 klassOop super = _primary_supers[i]; 223 Klass* super = _primary_supers[i];
314 assert(super == NULL || super->klass_part()->super_depth() == i, "correct display"); 224 assert(super == NULL || super->super_depth() == i, "correct display");
315 return super; 225 return super;
316 } 226 }
317 227
318 // Can this klass be a primary super? False for interfaces and arrays of 228 // Can this klass be a primary super? False for interfaces and arrays of
319 // interfaces. False also for arrays or classes with long super chains. 229 // interfaces. False also for arrays or classes with long super chains.
326 // Returns number of primary supers; may be a number in the inclusive range [0, primary_super_limit]. 236 // Returns number of primary supers; may be a number in the inclusive range [0, primary_super_limit].
327 juint super_depth() const { 237 juint super_depth() const {
328 if (!can_be_primary_super()) { 238 if (!can_be_primary_super()) {
329 return primary_super_limit(); 239 return primary_super_limit();
330 } else { 240 } else {
331 juint d = (super_check_offset() - in_bytes(primary_supers_offset())) / sizeof(klassOop); 241 juint d = (super_check_offset() - in_bytes(primary_supers_offset())) / sizeof(Klass*);
332 assert(d < primary_super_limit(), "oob"); 242 assert(d < primary_super_limit(), "oob");
333 assert(_primary_supers[d] == as_klassOop(), "proper init"); 243 assert(_primary_supers[d] == this, "proper init");
334 return d; 244 return d;
335 } 245 }
336 } 246 }
337 247
248 // store an oop into a field of a Klass
249 void klass_oop_store(oop* p, oop v);
250 void klass_oop_store(volatile oop* p, oop v);
251
338 // java mirror 252 // java mirror
339 oop java_mirror() const { return _java_mirror; } 253 oop java_mirror() const { return _java_mirror; }
340 void set_java_mirror(oop m) { oop_store((oop*) &_java_mirror, m); } 254 void set_java_mirror(oop m) { klass_oop_store(&_java_mirror, m); }
341 255
342 // graal mirror 256 // graal mirror
343 oop graal_mirror() const { return _graal_mirror; } 257 oop graal_mirror() const { return _graal_mirror; }
344 void set_graal_mirror(oop m) { oop_store((oop*) &_graal_mirror, m); } 258 void set_graal_mirror(oop m) { oop_store((oop*) &_graal_mirror, m); }
345 259
350 // size helper 264 // size helper
351 int layout_helper() const { return _layout_helper; } 265 int layout_helper() const { return _layout_helper; }
352 void set_layout_helper(int lh) { _layout_helper = lh; } 266 void set_layout_helper(int lh) { _layout_helper = lh; }
353 267
354 // Note: for instances layout_helper() may include padding. 268 // Note: for instances layout_helper() may include padding.
355 // Use instanceKlass::contains_field_offset to classify field offsets. 269 // Use InstanceKlass::contains_field_offset to classify field offsets.
356 270
357 // sub/superklass links 271 // sub/superklass links
358 instanceKlass* superklass() const; 272 InstanceKlass* superklass() const;
359 Klass* subklass() const; 273 Klass* subklass() const;
360 Klass* next_sibling() const; 274 Klass* next_sibling() const;
361 void append_to_sibling_list(); // add newly created receiver to superklass' subklass list 275 void append_to_sibling_list(); // add newly created receiver to superklass' subklass list
362 void remove_from_sibling_list(); // remove receiver from sibling list 276 void remove_from_sibling_list(); // remove receiver from sibling list
277
278 void set_next_link(Klass* k) { _next_link = k; }
279 Klass* next_link() const { return _next_link; } // The next klass defined by the class loader.
280
281 // class loader data
282 ClassLoaderData* class_loader_data() const { return _class_loader_data; }
283 void set_class_loader_data(ClassLoaderData* loader_data) { _class_loader_data = loader_data; }
284
285 // The Klasses are not placed in the Heap, so the Card Table or
286 // the Mod Union Table can't be used to mark when klasses have modified oops.
287 // The CT and MUT bits saves this information for the individual Klasses.
288 void record_modified_oops() { _modified_oops = 1; }
289 void clear_modified_oops() { _modified_oops = 0; }
290 bool has_modified_oops() { return _modified_oops == 1; }
291
292 void accumulate_modified_oops() { if (has_modified_oops()) _accumulated_modified_oops = 1; }
293 void clear_accumulated_modified_oops() { _accumulated_modified_oops = 0; }
294 bool has_accumulated_modified_oops() { return _accumulated_modified_oops == 1; }
295
363 protected: // internal accessors 296 protected: // internal accessors
364 klassOop subklass_oop() const { return _subklass; } 297 Klass* subklass_oop() const { return _subklass; }
365 klassOop next_sibling_oop() const { return _next_sibling; } 298 Klass* next_sibling_oop() const { return _next_sibling; }
366 void set_subklass(klassOop s); 299 void set_subklass(Klass* s);
367 void set_next_sibling(klassOop s); 300 void set_next_sibling(Klass* s);
368
369 oop* adr_super() const { return (oop*)&_super; }
370 oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
371 oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
372 oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
373 oop* adr_java_mirror() const { return (oop*)&_java_mirror; }
374 oop* adr_graal_mirror() const { return (oop*)&_graal_mirror; }
375 oop* adr_subklass() const { return (oop*)&_subklass; }
376 oop* adr_next_sibling() const { return (oop*)&_next_sibling; }
377 301
378 public: 302 public:
379 // Allocation profiling support 303 // Allocation profiling support
380 juint alloc_count() const { return _alloc_count; } 304 juint alloc_count() const { return _alloc_count; }
381 void set_alloc_count(juint n) { _alloc_count = n; } 305 void set_alloc_count(juint n) { _alloc_count = n; }
382 virtual juint alloc_size() const = 0; 306 virtual juint alloc_size() const = 0;
383 virtual void set_alloc_size(juint n) = 0; 307 virtual void set_alloc_size(juint n) = 0;
384 308
385 // Compiler support 309 // Compiler support
386 static ByteSize super_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(Klass, _super)); } 310 static ByteSize super_offset() { return in_ByteSize(offset_of(Klass, _super)); }
387 static ByteSize super_check_offset_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(Klass, _super_check_offset)); } 311 static ByteSize super_check_offset_offset() { return in_ByteSize(offset_of(Klass, _super_check_offset)); }
388 static ByteSize primary_supers_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(Klass, _primary_supers)); } 312 static ByteSize primary_supers_offset() { return in_ByteSize(offset_of(Klass, _primary_supers)); }
389 static ByteSize secondary_super_cache_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(Klass, _secondary_super_cache)); } 313 static ByteSize secondary_super_cache_offset() { return in_ByteSize(offset_of(Klass, _secondary_super_cache)); }
390 static ByteSize secondary_supers_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(Klass, _secondary_supers)); } 314 static ByteSize secondary_supers_offset() { return in_ByteSize(offset_of(Klass, _secondary_supers)); }
391 static ByteSize java_mirror_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(Klass, _java_mirror)); } 315 static ByteSize java_mirror_offset() { return in_ByteSize(offset_of(Klass, _java_mirror)); }
392 static ByteSize modifier_flags_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(Klass, _modifier_flags)); } 316 static ByteSize modifier_flags_offset() { return in_ByteSize(offset_of(Klass, _modifier_flags)); }
393 static ByteSize layout_helper_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(Klass, _layout_helper)); } 317 static ByteSize layout_helper_offset() { return in_ByteSize(offset_of(Klass, _layout_helper)); }
394 static ByteSize access_flags_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(Klass, _access_flags)); } 318 static ByteSize access_flags_offset() { return in_ByteSize(offset_of(Klass, _access_flags)); }
395 static ByteSize graal_mirror_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(Klass, _graal_mirror)); } 319 static ByteSize graal_mirror_offset() { return in_ByteSize(offset_of(Klass, _graal_mirror)); }
396 320
397 // Unpacking layout_helper: 321 // Unpacking layout_helper:
398 enum { 322 enum {
399 _lh_neutral_value = 0, // neutral non-array non-instance value 323 _lh_neutral_value = 0, // neutral non-array non-instance value
400 _lh_instance_slow_path_bit = 0x01, 324 _lh_instance_slow_path_bit = 0x01,
419 return (lh & _lh_instance_slow_path_bit) != 0; 343 return (lh & _lh_instance_slow_path_bit) != 0;
420 } 344 }
421 static bool layout_helper_is_instance(jint lh) { 345 static bool layout_helper_is_instance(jint lh) {
422 return (jint)lh > (jint)_lh_neutral_value; 346 return (jint)lh > (jint)_lh_neutral_value;
423 } 347 }
424 static bool layout_helper_is_javaArray(jint lh) { 348 static bool layout_helper_is_array(jint lh) {
425 return (jint)lh < (jint)_lh_neutral_value; 349 return (jint)lh < (jint)_lh_neutral_value;
426 } 350 }
427 static bool layout_helper_is_typeArray(jint lh) { 351 static bool layout_helper_is_typeArray(jint lh) {
428 // _lh_array_tag_type_value == (lh >> _lh_array_tag_shift); 352 // _lh_array_tag_type_value == (lh >> _lh_array_tag_shift);
429 return (juint)lh >= (juint)(_lh_array_tag_type_value << _lh_array_tag_shift); 353 return (juint)lh >= (juint)(_lh_array_tag_type_value << _lh_array_tag_shift);
479 #endif 403 #endif
480 404
481 // vtables 405 // vtables
482 virtual klassVtable* vtable() const { return NULL; } 406 virtual klassVtable* vtable() const { return NULL; }
483 407
484 static int klass_size_in_bytes() { return offset_of(Klass, _alloc_count) + sizeof(juint); } // all "visible" fields
485
486 // subclass check 408 // subclass check
487 bool is_subclass_of(klassOop k) const; 409 bool is_subclass_of(Klass* k) const;
488 // subtype check: true if is_subclass_of, or if k is interface and receiver implements it 410 // subtype check: true if is_subclass_of, or if k is interface and receiver implements it
489 bool is_subtype_of(klassOop k) const { 411 bool is_subtype_of(Klass* k) const {
490 juint off = k->klass_part()->super_check_offset(); 412 juint off = k->super_check_offset();
491 klassOop sup = *(klassOop*)( (address)as_klassOop() + off ); 413 Klass* sup = *(Klass**)( (address)this + off );
492 const juint secondary_offset = in_bytes(secondary_super_cache_offset()); 414 const juint secondary_offset = in_bytes(secondary_super_cache_offset());
493 if (sup == k) { 415 if (sup == k) {
494 return true; 416 return true;
495 } else if (off != secondary_offset) { 417 } else if (off != secondary_offset) {
496 return false; 418 return false;
497 } else { 419 } else {
498 return search_secondary_supers(k); 420 return search_secondary_supers(k);
499 } 421 }
500 } 422 }
501 bool search_secondary_supers(klassOop k) const; 423 bool search_secondary_supers(Klass* k) const;
502 424
503 // Find LCA in class hierarchy 425 // Find LCA in class hierarchy
504 Klass *LCA( Klass *k ); 426 Klass *LCA( Klass *k );
505 427
506 // Check whether reflection/jni/jvm code is allowed to instantiate this class; 428 // Check whether reflection/jni/jvm code is allowed to instantiate this class;
507 // if not, throw either an Error or an Exception. 429 // if not, throw either an Error or an Exception.
508 virtual void check_valid_for_instantiation(bool throwError, TRAPS); 430 virtual void check_valid_for_instantiation(bool throwError, TRAPS);
509 431
510 // Casting 432 // Casting
511 static Klass* cast(klassOop k) { 433 static Klass* cast(Klass* k) {
512 assert(k->is_klass(), "cast to Klass"); 434 assert(k->is_klass(), "cast to Klass");
513 return k->klass_part(); 435 return k;
514 } 436 }
515 437
516 // array copying 438 // array copying
517 virtual void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS); 439 virtual void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS);
518 440
520 virtual bool should_be_initialized() const { return false; } 442 virtual bool should_be_initialized() const { return false; }
521 // initializes the klass 443 // initializes the klass
522 virtual void initialize(TRAPS); 444 virtual void initialize(TRAPS);
523 // lookup operation for MethodLookupCache 445 // lookup operation for MethodLookupCache
524 friend class MethodLookupCache; 446 friend class MethodLookupCache;
525 virtual methodOop uncached_lookup_method(Symbol* name, Symbol* signature) const; 447 virtual Method* uncached_lookup_method(Symbol* name, Symbol* signature) const;
526 public: 448 public:
527 methodOop lookup_method(Symbol* name, Symbol* signature) const { 449 Method* lookup_method(Symbol* name, Symbol* signature) const {
528 return uncached_lookup_method(name, signature); 450 return uncached_lookup_method(name, signature);
529 } 451 }
530 452
531 // array class with specific rank 453 // array class with specific rank
532 klassOop array_klass(int rank, TRAPS) { return array_klass_impl(false, rank, THREAD); } 454 Klass* array_klass(int rank, TRAPS) { return array_klass_impl(false, rank, THREAD); }
533 455
534 // array class with this klass as element type 456 // array class with this klass as element type
535 klassOop array_klass(TRAPS) { return array_klass_impl(false, THREAD); } 457 Klass* array_klass(TRAPS) { return array_klass_impl(false, THREAD); }
536 458
537 // These will return NULL instead of allocating on the heap: 459 // These will return NULL instead of allocating on the heap:
538 // NB: these can block for a mutex, like other functions with TRAPS arg. 460 // NB: these can block for a mutex, like other functions with TRAPS arg.
539 klassOop array_klass_or_null(int rank); 461 Klass* array_klass_or_null(int rank);
540 klassOop array_klass_or_null(); 462 Klass* array_klass_or_null();
541 463
542 virtual oop protection_domain() { return NULL; } 464 virtual oop protection_domain() { return NULL; }
543 virtual oop class_loader() const { return NULL; } 465
466 oop class_loader() const;
544 467
545 protected: 468 protected:
546 virtual klassOop array_klass_impl(bool or_null, int rank, TRAPS); 469 virtual Klass* array_klass_impl(bool or_null, int rank, TRAPS);
547 virtual klassOop array_klass_impl(bool or_null, TRAPS); 470 virtual Klass* array_klass_impl(bool or_null, TRAPS);
548 471
549 public: 472 public:
473 // CDS support - remove and restore oops from metadata. Oops are not shared.
550 virtual void remove_unshareable_info(); 474 virtual void remove_unshareable_info();
551 virtual void shared_symbols_iterate(SymbolClosure* closure); 475 virtual void restore_unshareable_info(TRAPS);
552 476
553 protected: 477 protected:
554 // computes the subtype relationship 478 // computes the subtype relationship
555 virtual bool compute_is_subtype_of(klassOop k); 479 virtual bool compute_is_subtype_of(Klass* k);
556 public: 480 public:
557 // ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP 481 // ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP
558 // These functions describe behavior for the oop not the KLASS. 482 // These functions describe behavior for the oop not the KLASS.
559 483
560 // actual oop size of obj in memory 484 // actual oop size of obj in memory
561 virtual int oop_size(oop obj) const = 0; 485 virtual int oop_size(oop obj) const = 0;
562 486
563 // actual oop size of this klass in memory 487 // Size of klass in word size.
564 virtual int klass_oop_size() const = 0; 488 virtual int size() const = 0;
565 489
566 // Returns the Java name for a class (Resource allocated) 490 // Returns the Java name for a class (Resource allocated)
567 // For arrays, this returns the name of the element with a leading '['. 491 // For arrays, this returns the name of the element with a leading '['.
568 // For classes, this returns the name with the package separators 492 // For classes, this returns the name with the package separators
569 // turned into '.'s. 493 // turned into '.'s.
580 virtual int oop_adjust_pointers(oop obj) = 0; 504 virtual int oop_adjust_pointers(oop obj) = 0;
581 505
582 // Parallel Scavenge and Parallel Old 506 // Parallel Scavenge and Parallel Old
583 PARALLEL_GC_DECLS_PV 507 PARALLEL_GC_DECLS_PV
584 508
509 // type testing operations
510 protected:
511 virtual bool oop_is_instance_slow() const { return false; }
512 virtual bool oop_is_array_slow() const { return false; }
513 virtual bool oop_is_objArray_slow() const { return false; }
514 virtual bool oop_is_typeArray_slow() const { return false; }
585 public: 515 public:
586 // type testing operations
587 virtual bool oop_is_instance_slow() const { return false; }
588 virtual bool oop_is_instanceMirror() const { return false; } 516 virtual bool oop_is_instanceMirror() const { return false; }
589 virtual bool oop_is_instanceRef() const { return false; } 517 virtual bool oop_is_instanceRef() const { return false; }
590 virtual bool oop_is_array() const { return false; } 518
591 virtual bool oop_is_objArray_slow() const { return false; } 519 // Fast non-virtual versions
592 virtual bool oop_is_klass() const { return false; }
593 virtual bool oop_is_thread() const { return false; }
594 virtual bool oop_is_method() const { return false; }
595 virtual bool oop_is_constMethod() const { return false; }
596 virtual bool oop_is_methodData() const { return false; }
597 virtual bool oop_is_constantPool() const { return false; }
598 virtual bool oop_is_constantPoolCache() const { return false; }
599 virtual bool oop_is_typeArray_slow() const { return false; }
600 virtual bool oop_is_arrayKlass() const { return false; }
601 virtual bool oop_is_objArrayKlass() const { return false; }
602 virtual bool oop_is_typeArrayKlass() const { return false; }
603 virtual bool oop_is_compiledICHolder() const { return false; }
604 virtual bool oop_is_instanceKlass() const { return false; }
605
606 bool oop_is_javaArray_slow() const {
607 return oop_is_objArray_slow() || oop_is_typeArray_slow();
608 }
609
610 // Fast non-virtual versions, used by oop.inline.hpp and elsewhere:
611 #ifndef ASSERT 520 #ifndef ASSERT
612 #define assert_same_query(xval, xcheck) xval 521 #define assert_same_query(xval, xcheck) xval
613 #else 522 #else
614 private: 523 private:
615 static bool assert_same_query(bool xval, bool xslow) { 524 static bool assert_same_query(bool xval, bool xslow) {
619 public: 528 public:
620 #endif 529 #endif
621 inline bool oop_is_instance() const { return assert_same_query( 530 inline bool oop_is_instance() const { return assert_same_query(
622 layout_helper_is_instance(layout_helper()), 531 layout_helper_is_instance(layout_helper()),
623 oop_is_instance_slow()); } 532 oop_is_instance_slow()); }
624 inline bool oop_is_javaArray() const { return assert_same_query( 533 inline bool oop_is_array() const { return assert_same_query(
625 layout_helper_is_javaArray(layout_helper()), 534 layout_helper_is_array(layout_helper()),
626 oop_is_javaArray_slow()); } 535 oop_is_array_slow()); }
627 inline bool oop_is_objArray() const { return assert_same_query( 536 inline bool oop_is_objArray() const { return assert_same_query(
628 layout_helper_is_objArray(layout_helper()), 537 layout_helper_is_objArray(layout_helper()),
629 oop_is_objArray_slow()); } 538 oop_is_objArray_slow()); }
630 inline bool oop_is_typeArray() const { return assert_same_query( 539 inline bool oop_is_typeArray() const { return assert_same_query(
631 layout_helper_is_typeArray(layout_helper()), 540 layout_helper_is_typeArray(layout_helper()),
632 oop_is_typeArray_slow()); } 541 oop_is_typeArray_slow()); }
633 #undef assert_same_query 542 #undef assert_same_query
634
635 // Unless overridden, oop is parsable if it has a klass pointer.
636 // Parsability of an object is object specific.
637 virtual bool oop_is_parsable(oop obj) const { return true; }
638
639 // Unless overridden, oop is safe for concurrent GC processing
640 // after its allocation is complete. The exception to
641 // this is the case where objects are changed after allocation.
642 // Class redefinition is one of the known exceptions. During
643 // class redefinition, an allocated class can changed in order
644 // order to create a merged class (the combiniation of the
645 // old class definition that has to be perserved and the new class
646 // definition which is being created.
647 virtual bool oop_is_conc_safe(oop obj) const { return true; }
648 543
649 // Access flags 544 // Access flags
650 AccessFlags access_flags() const { return _access_flags; } 545 AccessFlags access_flags() const { return _access_flags; }
651 void set_access_flags(AccessFlags flags) { _access_flags = flags; } 546 void set_access_flags(AccessFlags flags) { _access_flags = flags; }
652 547
680 // reason why it could not be done for arrayKlasses aside from 575 // reason why it could not be done for arrayKlasses aside from
681 // wanting to reduce the initial scope of this optimization. There 576 // wanting to reduce the initial scope of this optimization. There
682 // are potential problems in setting the bias pattern for 577 // are potential problems in setting the bias pattern for
683 // JVM-internal oops. 578 // JVM-internal oops.
684 inline void set_prototype_header(markOop header); 579 inline void set_prototype_header(markOop header);
685 static ByteSize prototype_header_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(Klass, _prototype_header)); } 580 static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
686 581
687 int biased_lock_revocation_count() const { return (int) _biased_lock_revocation_count; } 582 int biased_lock_revocation_count() const { return (int) _biased_lock_revocation_count; }
688 // Atomically increments biased_lock_revocation_count and returns updated value 583 // Atomically increments biased_lock_revocation_count and returns updated value
689 int atomic_incr_biased_lock_revocation_count(); 584 int atomic_incr_biased_lock_revocation_count();
690 void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; } 585 void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; }
692 void set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; } 587 void set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
693 588
694 TRACE_DEFINE_KLASS_METHODS; 589 TRACE_DEFINE_KLASS_METHODS;
695 590
696 // garbage collection support 591 // garbage collection support
697 virtual void follow_weak_klass_links( 592 virtual void oops_do(OopClosure* cl);
698 BoolObjectClosure* is_alive, OopClosure* keep_alive); 593
594 // Checks if the class loader is alive.
595 // Iff the class loader is alive the Klass is considered alive.
596 // The is_alive closure passed in depends on the Garbage Collector used.
597 bool is_loader_alive(BoolObjectClosure* is_alive);
598
599 static void clean_weak_klass_links(BoolObjectClosure* is_alive);
699 600
700 // Prefetch within oop iterators. This is a macro because we 601 // Prefetch within oop iterators. This is a macro because we
701 // can't guarantee that the compiler will inline it. In 64-bit 602 // can't guarantee that the compiler will inline it. In 64-bit
702 // it generally doesn't. Signature is 603 // it generally doesn't. Signature is
703 // 604 //
726 } \ 627 } \
727 } \ 628 } \
728 } 629 }
729 630
730 // iterators 631 // iterators
731 virtual int oop_oop_iterate(oop obj, OopClosure* blk) = 0; 632 virtual int oop_oop_iterate(oop obj, ExtendedOopClosure* blk) = 0;
732 virtual int oop_oop_iterate_v(oop obj, OopClosure* blk) { 633 virtual int oop_oop_iterate_v(oop obj, ExtendedOopClosure* blk) {
733 return oop_oop_iterate(obj, blk); 634 return oop_oop_iterate(obj, blk);
734 } 635 }
735 636
736 #ifndef SERIALGC 637 #ifndef SERIALGC
737 // In case we don't have a specialized backward scanner use forward 638 // In case we don't have a specialized backward scanner use forward
738 // iteration. 639 // iteration.
739 virtual int oop_oop_iterate_backwards_v(oop obj, OopClosure* blk) { 640 virtual int oop_oop_iterate_backwards_v(oop obj, ExtendedOopClosure* blk) {
740 return oop_oop_iterate_v(obj, blk); 641 return oop_oop_iterate_v(obj, blk);
741 } 642 }
742 #endif // !SERIALGC 643 #endif // !SERIALGC
743 644
744 // Iterates "blk" over all the oops in "obj" (of type "this") within "mr". 645 // Iterates "blk" over all the oops in "obj" (of type "this") within "mr".
745 // (I don't see why the _m should be required, but without it the Solaris 646 // (I don't see why the _m should be required, but without it the Solaris
746 // C++ gives warning messages about overridings of the "oop_oop_iterate" 647 // C++ gives warning messages about overridings of the "oop_oop_iterate"
747 // defined above "hiding" this virtual function. (DLD, 6/20/00)) */ 648 // defined above "hiding" this virtual function. (DLD, 6/20/00)) */
748 virtual int oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) = 0; 649 virtual int oop_oop_iterate_m(oop obj, ExtendedOopClosure* blk, MemRegion mr) = 0;
749 virtual int oop_oop_iterate_v_m(oop obj, OopClosure* blk, MemRegion mr) { 650 virtual int oop_oop_iterate_v_m(oop obj, ExtendedOopClosure* blk, MemRegion mr) {
750 return oop_oop_iterate_m(obj, blk, mr); 651 return oop_oop_iterate_m(obj, blk, mr);
751 } 652 }
752 653
753 // Versions of the above iterators specialized to particular subtypes 654 // Versions of the above iterators specialized to particular subtypes
754 // of OopClosure, to avoid closure virtual calls. 655 // of OopClosure, to avoid closure virtual calls.
781 682
782 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_BACKWARDS_DECL) 683 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_BACKWARDS_DECL)
783 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_BACKWARDS_DECL) 684 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_BACKWARDS_DECL)
784 #endif // !SERIALGC 685 #endif // !SERIALGC
785 686
786 virtual void array_klasses_do(void f(klassOop k)) {} 687 virtual void array_klasses_do(void f(Klass* k)) {}
787 virtual void with_array_klasses_do(void f(klassOop k)); 688 virtual void with_array_klasses_do(void f(Klass* k));
788 689
789 // Return self, except for abstract classes with exactly 1 690 // Return self, except for abstract classes with exactly 1
790 // implementor. Then return the 1 concrete implementation. 691 // implementor. Then return the 1 concrete implementation.
791 Klass *up_cast_abstract(); 692 Klass *up_cast_abstract();
792 693
793 // klass name 694 // klass name
794 Symbol* name() const { return _name; } 695 Symbol* name() const { return _name; }
795 void set_name(Symbol* n); 696 void set_name(Symbol* n);
796 697
797 friend class klassKlass;
798
799 public: 698 public:
800 // jvm support 699 // jvm support
801 virtual jint compute_modifier_flags(TRAPS) const; 700 virtual jint compute_modifier_flags(TRAPS) const;
802 701
803 // JVMTI support 702 // JVMTI support
804 virtual jint jvmti_class_status() const; 703 virtual jint jvmti_class_status() const;
805 704
806 // Printing 705 // Printing
706 virtual void print_on(outputStream* st) const;
707
807 virtual void oop_print_value_on(oop obj, outputStream* st); 708 virtual void oop_print_value_on(oop obj, outputStream* st);
808 virtual void oop_print_on (oop obj, outputStream* st); 709 virtual void oop_print_on (oop obj, outputStream* st);
809 710
711 virtual const char* internal_name() const = 0;
712
810 // Verification 713 // Verification
811 virtual const char* internal_name() const = 0; 714 virtual void verify_on(outputStream* st);
812 virtual void oop_verify_on(oop obj, outputStream* st); 715 void verify() { verify_on(tty); }
813 // tells whether obj is partially constructed (gc during class loading)
814 virtual bool oop_partially_loaded(oop obj) const { return false; }
815 virtual void oop_set_partially_loaded(oop obj) {};
816 716
817 #ifndef PRODUCT 717 #ifndef PRODUCT
818 void verify_vtable_index(int index); 718 void verify_vtable_index(int index);
819 #endif 719 #endif
720
721 virtual void oop_verify_on(oop obj, outputStream* st);
722
723 private:
724 // barriers used by klass_oop_store
725 void klass_update_barrier_set(oop v);
726 void klass_update_barrier_set_pre(void* p, oop v);
820 }; 727 };
821 728
822
823 inline oop klassOopDesc::java_mirror() const { return klass_part()->java_mirror(); }
824
825
826 #endif // SHARE_VM_OOPS_KLASS_HPP 729 #endif // SHARE_VM_OOPS_KLASS_HPP