1 /*
2 * Copyright (c) 1997, 2015, 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 *
114 Klass* _primary_supers[_primary_super_limit];
115 // java/lang/Class instance mirroring this class
116 oop _java_mirror;
117 // Superclass
118 Klass* _super;
119 // First subclass (NULL if none); _subklass->next_sibling() is next one
120 Klass* _subklass;
121 // Sibling link (or NULL); links all subklasses of a klass
122 Klass* _next_sibling;
123
124 // All klasses loaded by a class loader are chained through these links
125 Klass* _next_link;
126
127 // The VM's representation of the ClassLoader used to load this class.
128 // Provide access the corresponding instance java.lang.ClassLoader.
129 ClassLoaderData* _class_loader_data;
130
131 jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
132 AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
133
134 // Biased locking implementation and statistics
135 // (the 64-bit chunk goes first, to avoid some fragmentation)
136 jlong _last_biased_lock_bulk_revocation_time;
137 markOop _prototype_header; // Used when biased locking is both enabled and disabled for this type
138 jint _biased_lock_revocation_count;
139
140 TRACE_DEFINE_KLASS_TRACE_ID;
141
142 // Remembered sets support for the oops in the klasses.
143 jbyte _modified_oops; // Card Table Equivalent (YC/CMS support)
144 jbyte _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
145
146 private:
147 // This is an index into FileMapHeader::_classpath_entry_table[], to
148 // associate this class with the JAR file where it's loaded from during
149 // dump time. If a class is not loaded from the shared archive, this field is
150 // -1.
151 jshort _shared_class_path_index;
152
153 friend class SharedClassUtil;
154 protected:
155
156 // Constructor
157 Klass();
158
159 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
160
358 static int layout_helper_to_size_helper(jint lh) {
359 assert(lh > (jint)_lh_neutral_value, "must be instance");
360 // Note that the following expression discards _lh_instance_slow_path_bit.
361 return lh >> LogHeapWordSize;
362 }
363 // Out-of-line version computes everything based on the etype:
364 static jint array_layout_helper(BasicType etype);
365
366 // What is the maximum number of primary superclasses any klass can have?
367 #ifdef PRODUCT
368 static juint primary_super_limit() { return _primary_super_limit; }
369 #else
370 static juint primary_super_limit() {
371 assert(FastSuperclassLimit <= _primary_super_limit, "parameter oob");
372 return FastSuperclassLimit;
373 }
374 #endif
375
376 // vtables
377 virtual klassVtable* vtable() const = 0;
378 virtual int vtable_length() const = 0;
379
380 // subclass check
381 bool is_subclass_of(const Klass* k) const;
382 // subtype check: true if is_subclass_of, or if k is interface and receiver implements it
383 bool is_subtype_of(Klass* k) const {
384 juint off = k->super_check_offset();
385 Klass* sup = *(Klass**)( (address)this + off );
386 const juint secondary_offset = in_bytes(secondary_super_cache_offset());
387 if (sup == k) {
388 return true;
389 } else if (off != secondary_offset) {
390 return false;
391 } else {
392 return search_secondary_supers(k);
393 }
394 }
395 bool search_secondary_supers(Klass* k) const;
396
397 // Find LCA in class hierarchy
398 Klass *LCA( Klass *k );
421 Klass* array_klass(int rank, TRAPS) { return array_klass_impl(false, rank, THREAD); }
422
423 // array class with this klass as element type
424 Klass* array_klass(TRAPS) { return array_klass_impl(false, THREAD); }
425
426 // These will return NULL instead of allocating on the heap:
427 // NB: these can block for a mutex, like other functions with TRAPS arg.
428 Klass* array_klass_or_null(int rank);
429 Klass* array_klass_or_null();
430
431 virtual oop protection_domain() const = 0;
432
433 oop class_loader() const;
434
435 virtual oop klass_holder() const { return class_loader(); }
436
437 protected:
438 virtual Klass* array_klass_impl(bool or_null, int rank, TRAPS);
439 virtual Klass* array_klass_impl(bool or_null, TRAPS);
440
441 public:
442 // CDS support - remove and restore oops from metadata. Oops are not shared.
443 virtual void remove_unshareable_info();
444 virtual void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
445
446 protected:
447 // computes the subtype relationship
448 virtual bool compute_is_subtype_of(Klass* k);
449 public:
450 // subclass accessor (here for convenience; undefined for non-klass objects)
451 virtual bool is_leaf_class() const { fatal("not a class"); return false; }
452 public:
453 // ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP
454 // These functions describe behavior for the oop not the KLASS.
455
456 // actual oop size of obj in memory
457 virtual int oop_size(oop obj) const = 0;
458
459 // Size of klass in word size.
460 virtual int size() const = 0;
461 #if INCLUDE_SERVICES
|
1 /*
2 * Copyright (c) 1997, 2016, 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 *
114 Klass* _primary_supers[_primary_super_limit];
115 // java/lang/Class instance mirroring this class
116 oop _java_mirror;
117 // Superclass
118 Klass* _super;
119 // First subclass (NULL if none); _subklass->next_sibling() is next one
120 Klass* _subklass;
121 // Sibling link (or NULL); links all subklasses of a klass
122 Klass* _next_sibling;
123
124 // All klasses loaded by a class loader are chained through these links
125 Klass* _next_link;
126
127 // The VM's representation of the ClassLoader used to load this class.
128 // Provide access the corresponding instance java.lang.ClassLoader.
129 ClassLoaderData* _class_loader_data;
130
131 jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
132 AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
133
134 TRACE_DEFINE_KLASS_TRACE_ID;
135
136 // Biased locking implementation and statistics
137 // (the 64-bit chunk goes first, to avoid some fragmentation)
138 jlong _last_biased_lock_bulk_revocation_time;
139 markOop _prototype_header; // Used when biased locking is both enabled and disabled for this type
140 jint _biased_lock_revocation_count;
141
142 // vtable length
143 int _vtable_len;
144
145 // Remembered sets support for the oops in the klasses.
146 jbyte _modified_oops; // Card Table Equivalent (YC/CMS support)
147 jbyte _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
148
149 private:
150 // This is an index into FileMapHeader::_classpath_entry_table[], to
151 // associate this class with the JAR file where it's loaded from during
152 // dump time. If a class is not loaded from the shared archive, this field is
153 // -1.
154 jshort _shared_class_path_index;
155
156 friend class SharedClassUtil;
157 protected:
158
159 // Constructor
160 Klass();
161
162 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
163
361 static int layout_helper_to_size_helper(jint lh) {
362 assert(lh > (jint)_lh_neutral_value, "must be instance");
363 // Note that the following expression discards _lh_instance_slow_path_bit.
364 return lh >> LogHeapWordSize;
365 }
366 // Out-of-line version computes everything based on the etype:
367 static jint array_layout_helper(BasicType etype);
368
369 // What is the maximum number of primary superclasses any klass can have?
370 #ifdef PRODUCT
371 static juint primary_super_limit() { return _primary_super_limit; }
372 #else
373 static juint primary_super_limit() {
374 assert(FastSuperclassLimit <= _primary_super_limit, "parameter oob");
375 return FastSuperclassLimit;
376 }
377 #endif
378
379 // vtables
380 virtual klassVtable* vtable() const = 0;
381 int vtable_length() const { return _vtable_len; }
382
383 // subclass check
384 bool is_subclass_of(const Klass* k) const;
385 // subtype check: true if is_subclass_of, or if k is interface and receiver implements it
386 bool is_subtype_of(Klass* k) const {
387 juint off = k->super_check_offset();
388 Klass* sup = *(Klass**)( (address)this + off );
389 const juint secondary_offset = in_bytes(secondary_super_cache_offset());
390 if (sup == k) {
391 return true;
392 } else if (off != secondary_offset) {
393 return false;
394 } else {
395 return search_secondary_supers(k);
396 }
397 }
398 bool search_secondary_supers(Klass* k) const;
399
400 // Find LCA in class hierarchy
401 Klass *LCA( Klass *k );
424 Klass* array_klass(int rank, TRAPS) { return array_klass_impl(false, rank, THREAD); }
425
426 // array class with this klass as element type
427 Klass* array_klass(TRAPS) { return array_klass_impl(false, THREAD); }
428
429 // These will return NULL instead of allocating on the heap:
430 // NB: these can block for a mutex, like other functions with TRAPS arg.
431 Klass* array_klass_or_null(int rank);
432 Klass* array_klass_or_null();
433
434 virtual oop protection_domain() const = 0;
435
436 oop class_loader() const;
437
438 virtual oop klass_holder() const { return class_loader(); }
439
440 protected:
441 virtual Klass* array_klass_impl(bool or_null, int rank, TRAPS);
442 virtual Klass* array_klass_impl(bool or_null, TRAPS);
443
444 void set_vtable_length(int len) { _vtable_len= len; }
445
446 public:
447 static ByteSize vtable_start_offset();
448 static ByteSize vtable_length_offset() {
449 return byte_offset_of(Klass, _vtable_len);
450 }
451
452 // CDS support - remove and restore oops from metadata. Oops are not shared.
453 virtual void remove_unshareable_info();
454 virtual void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
455
456 protected:
457 // computes the subtype relationship
458 virtual bool compute_is_subtype_of(Klass* k);
459 public:
460 // subclass accessor (here for convenience; undefined for non-klass objects)
461 virtual bool is_leaf_class() const { fatal("not a class"); return false; }
462 public:
463 // ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP
464 // These functions describe behavior for the oop not the KLASS.
465
466 // actual oop size of obj in memory
467 virtual int oop_size(oop obj) const = 0;
468
469 // Size of klass in word size.
470 virtual int size() const = 0;
471 #if INCLUDE_SERVICES
|