159
160 JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
161
162 // Biased locking implementation and statistics
163 // (the 64-bit chunk goes first, to avoid some fragmentation)
164 jlong _last_biased_lock_bulk_revocation_time;
165 markWord _prototype_header; // Used when biased locking is both enabled and disabled for this type
166 jint _biased_lock_revocation_count;
167
168 private:
169 // This is an index into FileMapHeader::_shared_path_table[], to
170 // associate this class with the JAR file where it's loaded from during
171 // dump time. If a class is not loaded from the shared archive, this field is
172 // -1.
173 jshort _shared_class_path_index;
174
175 #if INCLUDE_CDS
176 // Flags of the current shared class.
177 u2 _shared_class_flags;
178 enum {
179 _has_raw_archived_mirror = 1,
180 _archived_lambda_proxy_is_available = 2
181 };
182 #endif
183
184 // The _archived_mirror is set at CDS dump time pointing to the cached mirror
185 // in the open archive heap region when archiving java object is supported.
186 CDS_JAVA_HEAP_ONLY(narrowOop _archived_mirror;)
187
188 protected:
189
190 // Constructor
191 Klass(KlassID id);
192 Klass() : _id(KlassID(-1)) { assert(DumpSharedSpaces || UseSharedSpaces, "only for cds"); }
193
194 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
195
196 public:
197 int id() { return _id; }
198
199 enum class DefaultsLookupMode { find, skip };
200 enum class OverpassLookupMode { find, skip };
201 enum class StaticLookupMode { find, skip };
202 enum class PrivateLookupMode { find, skip };
203
204 virtual bool is_klass() const { return true; }
205
206 // super() cannot be InstanceKlass* -- Java arrays are covariant, and _super is used
245 }
246 virtual bool can_be_primary_super_slow() const;
247
248 // Returns number of primary supers; may be a number in the inclusive range [0, primary_super_limit].
249 juint super_depth() const {
250 if (!can_be_primary_super()) {
251 return primary_super_limit();
252 } else {
253 juint d = (super_check_offset() - in_bytes(primary_supers_offset())) / sizeof(Klass*);
254 assert(d < primary_super_limit(), "oob");
255 assert(_primary_supers[d] == this, "proper init");
256 return d;
257 }
258 }
259
260 // java mirror
261 oop java_mirror() const;
262 oop java_mirror_no_keepalive() const;
263 void set_java_mirror(Handle m);
264
265 oop archived_java_mirror_raw() NOT_CDS_JAVA_HEAP_RETURN_(NULL); // no GC barrier
266 narrowOop archived_java_mirror_raw_narrow() NOT_CDS_JAVA_HEAP_RETURN_(narrowOop::null); // no GC barrier
267 void set_archived_java_mirror_raw(oop m) NOT_CDS_JAVA_HEAP_RETURN; // no GC barrier
268
269 // Temporary mirror switch used by RedefineClasses
270 void replace_java_mirror(oop mirror);
271
272 // Set java mirror OopHandle to NULL for CDS
273 // This leaves the OopHandle in the CLD, but that's ok, you can't release them.
274 void clear_java_mirror_handle() { _java_mirror = OopHandle(); }
275
276 // modifier flags
277 jint modifier_flags() const { return _modifier_flags; }
278 void set_modifier_flags(jint flags) { _modifier_flags = flags; }
279
280 // size helper
281 int layout_helper() const { return _layout_helper; }
282 void set_layout_helper(int lh) { _layout_helper = lh; }
283
284 // Note: for instances layout_helper() may include padding.
285 // Use InstanceKlass::contains_field_offset to classify field offsets.
286
287 // sub/superklass links
290
291 InstanceKlass* superklass() const;
292 void append_to_sibling_list(); // add newly created receiver to superklass' subklass list
293
294 void set_next_link(Klass* k) { _next_link = k; }
295 Klass* next_link() const { return _next_link; } // The next klass defined by the class loader.
296 Klass** next_link_addr() { return &_next_link; }
297
298 // class loader data
299 ClassLoaderData* class_loader_data() const { return _class_loader_data; }
300 void set_class_loader_data(ClassLoaderData* loader_data) { _class_loader_data = loader_data; }
301
302 int shared_classpath_index() const {
303 return _shared_class_path_index;
304 };
305
306 void set_shared_classpath_index(int index) {
307 _shared_class_path_index = index;
308 };
309
310 void set_has_raw_archived_mirror() {
311 CDS_ONLY(_shared_class_flags |= _has_raw_archived_mirror;)
312 }
313 void clear_has_raw_archived_mirror() {
314 CDS_ONLY(_shared_class_flags &= ~_has_raw_archived_mirror;)
315 }
316 bool has_raw_archived_mirror() const {
317 CDS_ONLY(return (_shared_class_flags & _has_raw_archived_mirror) != 0;)
318 NOT_CDS(return false;)
319 }
320
321 void set_lambda_proxy_is_available() {
322 CDS_ONLY(_shared_class_flags |= _archived_lambda_proxy_is_available;)
323 }
324 void clear_lambda_proxy_is_available() {
325 CDS_ONLY(_shared_class_flags &= ~_archived_lambda_proxy_is_available;)
326 }
327 bool lambda_proxy_is_available() const {
328 CDS_ONLY(return (_shared_class_flags & _archived_lambda_proxy_is_available) != 0;)
329 NOT_CDS(return false;)
330 }
331
332 // Obtain the module or package for this class
333 virtual ModuleEntry* module() const = 0;
334 virtual PackageEntry* package() const = 0;
335
336 protected: // internal accessors
337 void set_subklass(Klass* s);
338 void set_next_sibling(Klass* s);
339
340 public:
517 static void check_array_allocation_length(int length, int max_length, TRAPS);
518
519 void set_vtable_length(int len) { _vtable_len= len; }
520
521 vtableEntry* start_of_vtable() const;
522 void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
523 public:
524 Method* method_at_vtable(int index);
525
526 static ByteSize vtable_start_offset();
527 static ByteSize vtable_length_offset() {
528 return byte_offset_of(Klass, _vtable_len);
529 }
530
531 // CDS support - remove and restore oops from metadata. Oops are not shared.
532 virtual void remove_unshareable_info();
533 virtual void remove_java_mirror();
534
535 bool is_unshareable_info_restored() const {
536 assert(is_shared(), "use this for shared classes only");
537 if (has_raw_archived_mirror()) {
538 // _java_mirror is not a valid OopHandle but rather an encoded reference in the shared heap
539 return false;
540 } else if (_java_mirror.ptr_raw() == NULL) {
541 return false;
542 } else {
543 return true;
544 }
545 }
546
547 public:
548 // ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP
549 // These functions describe behavior for the oop not the KLASS.
550
551 // actual oop size of obj in memory
552 virtual int oop_size(oop obj) const = 0;
553
554 // Size of klass in word size.
555 virtual int size() const = 0;
556
557 // Returns the Java name for a class (Resource allocated)
|
159
160 JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
161
162 // Biased locking implementation and statistics
163 // (the 64-bit chunk goes first, to avoid some fragmentation)
164 jlong _last_biased_lock_bulk_revocation_time;
165 markWord _prototype_header; // Used when biased locking is both enabled and disabled for this type
166 jint _biased_lock_revocation_count;
167
168 private:
169 // This is an index into FileMapHeader::_shared_path_table[], to
170 // associate this class with the JAR file where it's loaded from during
171 // dump time. If a class is not loaded from the shared archive, this field is
172 // -1.
173 jshort _shared_class_path_index;
174
175 #if INCLUDE_CDS
176 // Flags of the current shared class.
177 u2 _shared_class_flags;
178 enum {
179 _archived_lambda_proxy_is_available = 2
180 };
181 #endif
182
183 CDS_JAVA_HEAP_ONLY(int _archived_mirror_index;)
184
185 protected:
186
187 // Constructor
188 Klass(KlassID id);
189 Klass() : _id(KlassID(-1)) { assert(DumpSharedSpaces || UseSharedSpaces, "only for cds"); }
190
191 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
192
193 public:
194 int id() { return _id; }
195
196 enum class DefaultsLookupMode { find, skip };
197 enum class OverpassLookupMode { find, skip };
198 enum class StaticLookupMode { find, skip };
199 enum class PrivateLookupMode { find, skip };
200
201 virtual bool is_klass() const { return true; }
202
203 // super() cannot be InstanceKlass* -- Java arrays are covariant, and _super is used
242 }
243 virtual bool can_be_primary_super_slow() const;
244
245 // Returns number of primary supers; may be a number in the inclusive range [0, primary_super_limit].
246 juint super_depth() const {
247 if (!can_be_primary_super()) {
248 return primary_super_limit();
249 } else {
250 juint d = (super_check_offset() - in_bytes(primary_supers_offset())) / sizeof(Klass*);
251 assert(d < primary_super_limit(), "oob");
252 assert(_primary_supers[d] == this, "proper init");
253 return d;
254 }
255 }
256
257 // java mirror
258 oop java_mirror() const;
259 oop java_mirror_no_keepalive() const;
260 void set_java_mirror(Handle m);
261
262 oop archived_java_mirror() NOT_CDS_JAVA_HEAP_RETURN_(NULL);
263 void set_archived_java_mirror(oop m) NOT_CDS_JAVA_HEAP_RETURN;
264
265 // Temporary mirror switch used by RedefineClasses
266 void replace_java_mirror(oop mirror);
267
268 // Set java mirror OopHandle to NULL for CDS
269 // This leaves the OopHandle in the CLD, but that's ok, you can't release them.
270 void clear_java_mirror_handle() { _java_mirror = OopHandle(); }
271
272 // modifier flags
273 jint modifier_flags() const { return _modifier_flags; }
274 void set_modifier_flags(jint flags) { _modifier_flags = flags; }
275
276 // size helper
277 int layout_helper() const { return _layout_helper; }
278 void set_layout_helper(int lh) { _layout_helper = lh; }
279
280 // Note: for instances layout_helper() may include padding.
281 // Use InstanceKlass::contains_field_offset to classify field offsets.
282
283 // sub/superklass links
286
287 InstanceKlass* superklass() const;
288 void append_to_sibling_list(); // add newly created receiver to superklass' subklass list
289
290 void set_next_link(Klass* k) { _next_link = k; }
291 Klass* next_link() const { return _next_link; } // The next klass defined by the class loader.
292 Klass** next_link_addr() { return &_next_link; }
293
294 // class loader data
295 ClassLoaderData* class_loader_data() const { return _class_loader_data; }
296 void set_class_loader_data(ClassLoaderData* loader_data) { _class_loader_data = loader_data; }
297
298 int shared_classpath_index() const {
299 return _shared_class_path_index;
300 };
301
302 void set_shared_classpath_index(int index) {
303 _shared_class_path_index = index;
304 };
305
306 bool has_archived_mirror_index() const {
307 CDS_JAVA_HEAP_ONLY(return _archived_mirror_index >= 0);
308 NOT_CDS_JAVA_HEAP( return false);
309 }
310
311 void clear_archived_mirror_index() NOT_CDS_JAVA_HEAP_RETURN;
312
313 void set_lambda_proxy_is_available() {
314 CDS_ONLY(_shared_class_flags |= _archived_lambda_proxy_is_available;)
315 }
316 void clear_lambda_proxy_is_available() {
317 CDS_ONLY(_shared_class_flags &= ~_archived_lambda_proxy_is_available;)
318 }
319 bool lambda_proxy_is_available() const {
320 CDS_ONLY(return (_shared_class_flags & _archived_lambda_proxy_is_available) != 0;)
321 NOT_CDS(return false;)
322 }
323
324 // Obtain the module or package for this class
325 virtual ModuleEntry* module() const = 0;
326 virtual PackageEntry* package() const = 0;
327
328 protected: // internal accessors
329 void set_subklass(Klass* s);
330 void set_next_sibling(Klass* s);
331
332 public:
509 static void check_array_allocation_length(int length, int max_length, TRAPS);
510
511 void set_vtable_length(int len) { _vtable_len= len; }
512
513 vtableEntry* start_of_vtable() const;
514 void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
515 public:
516 Method* method_at_vtable(int index);
517
518 static ByteSize vtable_start_offset();
519 static ByteSize vtable_length_offset() {
520 return byte_offset_of(Klass, _vtable_len);
521 }
522
523 // CDS support - remove and restore oops from metadata. Oops are not shared.
524 virtual void remove_unshareable_info();
525 virtual void remove_java_mirror();
526
527 bool is_unshareable_info_restored() const {
528 assert(is_shared(), "use this for shared classes only");
529 if (has_archived_mirror_index()) {
530 // _java_mirror is not a valid OopHandle but rather an encoded reference in the shared heap
531 return false;
532 } else if (_java_mirror.ptr_raw() == NULL) {
533 return false;
534 } else {
535 return true;
536 }
537 }
538
539 public:
540 // ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP
541 // These functions describe behavior for the oop not the KLASS.
542
543 // actual oop size of obj in memory
544 virtual int oop_size(oop obj) const = 0;
545
546 // Size of klass in word size.
547 virtual int size() const = 0;
548
549 // Returns the Java name for a class (Resource allocated)
|