Bug Summary

File:jdk/src/hotspot/share/oops/klass.hpp
Warning:line 437, column 24
The result of the left shift is undefined because the left operand is negative

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name klass.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/libjvm/objs/precompiled -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D _GNU_SOURCE -D _REENTRANT -D LIBC=gnu -D LINUX -D VM_LITTLE_ENDIAN -D _LP64=1 -D ASSERT -D CHECK_UNHANDLED_OOPS -D TARGET_ARCH_x86 -D INCLUDE_SUFFIX_OS=_linux -D INCLUDE_SUFFIX_CPU=_x86 -D INCLUDE_SUFFIX_COMPILER=_gcc -D TARGET_COMPILER_gcc -D AMD64 -D HOTSPOT_LIB_ARCH="amd64" -D COMPILER1 -D COMPILER2 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc/adfiles -I /home/daniel/Projects/java/jdk/src/hotspot/share -I /home/daniel/Projects/java/jdk/src/hotspot/os/linux -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix -I /home/daniel/Projects/java/jdk/src/hotspot/cpu/x86 -I /home/daniel/Projects/java/jdk/src/hotspot/os_cpu/linux_x86 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc -I /home/daniel/Projects/java/jdk/src/hotspot/share/precompiled -I /home/daniel/Projects/java/jdk/src/hotspot/share/include -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix/include -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base/linux -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libjimage -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc/adfiles -I /home/daniel/Projects/java/jdk/src/hotspot/share -I /home/daniel/Projects/java/jdk/src/hotspot/os/linux -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix -I /home/daniel/Projects/java/jdk/src/hotspot/cpu/x86 -I /home/daniel/Projects/java/jdk/src/hotspot/os_cpu/linux_x86 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc -D _FORTIFY_SOURCE=2 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-format-zero-length -Wno-unused-parameter -Wno-unused -Wno-parentheses -Wno-comment -Wno-unknown-pragmas -Wno-address -Wno-delete-non-virtual-dtor -Wno-char-subscripts -Wno-array-bounds -Wno-int-in-bool-context -Wno-ignored-qualifiers -Wno-missing-field-initializers -Wno-implicit-fallthrough -Wno-empty-body -Wno-strict-overflow -Wno-sequence-point -Wno-maybe-uninitialized -Wno-misleading-indentation -Wno-cast-function-type -Wno-shift-negative-value -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /home/daniel/Projects/java/jdk/make/hotspot -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -stack-protector 1 -fno-rtti -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/daniel/Projects/java/scan/2021-12-21-193737-8510-1 -x c++ /home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp

/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp

1/*
2 * Copyright (c) 1997, 2021, 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#include "precompiled.hpp"
26#include "jvm_io.h"
27#include "cds/heapShared.hpp"
28#include "classfile/classLoaderData.inline.hpp"
29#include "classfile/classLoaderDataGraph.inline.hpp"
30#include "classfile/javaClasses.hpp"
31#include "classfile/moduleEntry.hpp"
32#include "classfile/systemDictionary.hpp"
33#include "classfile/systemDictionaryShared.hpp"
34#include "classfile/vmClasses.hpp"
35#include "classfile/vmSymbols.hpp"
36#include "gc/shared/collectedHeap.inline.hpp"
37#include "logging/log.hpp"
38#include "memory/metadataFactory.hpp"
39#include "memory/metaspaceClosure.hpp"
40#include "memory/oopFactory.hpp"
41#include "memory/resourceArea.hpp"
42#include "memory/universe.hpp"
43#include "oops/compressedOops.inline.hpp"
44#include "oops/instanceKlass.hpp"
45#include "oops/klass.inline.hpp"
46#include "oops/oop.inline.hpp"
47#include "oops/oopHandle.inline.hpp"
48#include "prims/jvmtiExport.hpp"
49#include "runtime/arguments.hpp"
50#include "runtime/atomic.hpp"
51#include "runtime/handles.inline.hpp"
52#include "utilities/macros.hpp"
53#include "utilities/powerOfTwo.hpp"
54#include "utilities/stack.inline.hpp"
55
56void Klass::set_java_mirror(Handle m) {
57 assert(!m.is_null(), "New mirror should never be null.")do { if (!(!m.is_null())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 57, "assert(" "!m.is_null()" ") failed", "New mirror should never be null."
); ::breakpoint(); } } while (0)
;
58 assert(_java_mirror.is_empty(), "should only be used to initialize mirror")do { if (!(_java_mirror.is_empty())) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 58, "assert(" "_java_mirror.is_empty()" ") failed", "should only be used to initialize mirror"
); ::breakpoint(); } } while (0)
;
59 _java_mirror = class_loader_data()->add_handle(m);
60}
61
62oop Klass::java_mirror_no_keepalive() const {
63 return _java_mirror.peek();
64}
65
66void Klass::replace_java_mirror(oop mirror) {
67 _java_mirror.replace(mirror);
68}
69
70bool Klass::is_cloneable() const {
71 return _access_flags.is_cloneable_fast() ||
72 is_subtype_of(vmClasses::Cloneable_klass());
73}
74
75void Klass::set_is_cloneable() {
76 if (name() == vmSymbols::java_lang_invoke_MemberName()) {
77 assert(is_final(), "no subclasses allowed")do { if (!(is_final())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 77, "assert(" "is_final()" ") failed", "no subclasses allowed"
); ::breakpoint(); } } while (0)
;
78 // MemberName cloning should not be intrinsified and always happen in JVM_Clone.
79 } else if (is_instance_klass() && InstanceKlass::cast(this)->reference_type() != REF_NONE) {
80 // Reference cloning should not be intrinsified and always happen in JVM_Clone.
81 } else {
82 _access_flags.set_is_cloneable_fast();
83 }
84}
85
86void Klass::set_name(Symbol* n) {
87 _name = n;
88 if (_name != NULL__null) _name->increment_refcount();
89
90 if (Arguments::is_dumping_archive() && is_instance_klass()) {
91 SystemDictionaryShared::init_dumptime_info(InstanceKlass::cast(this));
92 }
93}
94
95bool Klass::is_subclass_of(const Klass* k) const {
96 // Run up the super chain and check
97 if (this == k) return true;
98
99 Klass* t = const_cast<Klass*>(this)->super();
100
101 while (t != NULL__null) {
102 if (t == k) return true;
103 t = t->super();
104 }
105 return false;
106}
107
108void Klass::release_C_heap_structures(bool release_constant_pool) {
109 if (_name != NULL__null) _name->decrement_refcount();
110}
111
112bool Klass::search_secondary_supers(Klass* k) const {
113 // Put some extra logic here out-of-line, before the search proper.
114 // This cuts down the size of the inline method.
115
116 // This is necessary, since I am never in my own secondary_super list.
117 if (this == k)
118 return true;
119 // Scan the array-of-objects for a match
120 int cnt = secondary_supers()->length();
121 for (int i = 0; i < cnt; i++) {
122 if (secondary_supers()->at(i) == k) {
123 ((Klass*)this)->set_secondary_super_cache(k);
124 return true;
125 }
126 }
127 return false;
128}
129
130// Return self, except for abstract classes with exactly 1
131// implementor. Then return the 1 concrete implementation.
132Klass *Klass::up_cast_abstract() {
133 Klass *r = this;
134 while( r->is_abstract() ) { // Receiver is abstract?
135 Klass *s = r->subklass(); // Check for exactly 1 subklass
136 if (s == NULL__null || s->next_sibling() != NULL__null) // Oops; wrong count; give up
137 return this; // Return 'this' as a no-progress flag
138 r = s; // Loop till find concrete class
139 }
140 return r; // Return the 1 concrete class
141}
142
143// Find LCA in class hierarchy
144Klass *Klass::LCA( Klass *k2 ) {
145 Klass *k1 = this;
146 while( 1 ) {
147 if( k1->is_subtype_of(k2) ) return k2;
148 if( k2->is_subtype_of(k1) ) return k1;
149 k1 = k1->super();
150 k2 = k2->super();
151 }
152}
153
154
155void Klass::check_valid_for_instantiation(bool throwError, TRAPSJavaThread* __the_thread__) {
156 ResourceMark rm(THREAD__the_thread__);
157 THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError(){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 158, throwError ? vmSymbols::java_lang_InstantiationError()
: vmSymbols::java_lang_InstantiationException(), external_name
()); return; }
158 : vmSymbols::java_lang_InstantiationException(), external_name()){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 158, throwError ? vmSymbols::java_lang_InstantiationError()
: vmSymbols::java_lang_InstantiationException(), external_name
()); return; }
;
159}
160
161
162void Klass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPSJavaThread* __the_thread__) {
163 ResourceMark rm(THREAD__the_thread__);
164 assert(s != NULL, "Throw NPE!")do { if (!(s != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 164, "assert(" "s != __null" ") failed", "Throw NPE!"); ::breakpoint
(); } } while (0)
;
165 THROW_MSG(vmSymbols::java_lang_ArrayStoreException(),{ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 166, vmSymbols::java_lang_ArrayStoreException(), err_msg("arraycopy: source type %s is not an array"
, s->klass()->external_name())); return; }
166 err_msg("arraycopy: source type %s is not an array", s->klass()->external_name())){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 166, vmSymbols::java_lang_ArrayStoreException(), err_msg("arraycopy: source type %s is not an array"
, s->klass()->external_name())); return; }
;
167}
168
169
170void Klass::initialize(TRAPSJavaThread* __the_thread__) {
171 ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here(
"/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 171); ::breakpoint(); } while (0)
;
172}
173
174Klass* Klass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
175#ifdef ASSERT1
176 tty->print_cr("Error: find_field called on a klass oop."
177 " Likely error: reflection method does not correctly"
178 " wrap return value in a mirror object.");
179#endif
180 ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here(
"/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 180); ::breakpoint(); } while (0)
;
181 return NULL__null;
182}
183
184Method* Klass::uncached_lookup_method(const Symbol* name, const Symbol* signature,
185 OverpassLookupMode overpass_mode,
186 PrivateLookupMode private_mode) const {
187#ifdef ASSERT1
188 tty->print_cr("Error: uncached_lookup_method called on a klass oop."
189 " Likely error: reflection method does not correctly"
190 " wrap return value in a mirror object.");
191#endif
192 ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here(
"/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 192); ::breakpoint(); } while (0)
;
193 return NULL__null;
194}
195
196void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPSJavaThread* __the_thread__) throw() {
197 return Metaspace::allocate(loader_data, word_size, MetaspaceObj::ClassType, THREAD__the_thread__);
198}
199
200// "Normal" instantiation is preceeded by a MetaspaceObj allocation
201// which zeros out memory - calloc equivalent.
202// The constructor is also used from CppVtableCloner,
203// which doesn't zero out the memory before calling the constructor.
204Klass::Klass(KlassID id) : _id(id),
205 _shared_class_path_index(-1) {
206 CDS_ONLY(_shared_class_flags = 0;)_shared_class_flags = 0;
207 CDS_JAVA_HEAP_ONLY(_archived_mirror_index = -1;)_archived_mirror_index = -1;
208 _primary_supers[0] = this;
209 set_super_check_offset(in_bytes(primary_supers_offset()));
210}
211
212jint Klass::array_layout_helper(BasicType etype) {
213 assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype")do { if (!(etype >= T_BOOLEAN && etype <= T_OBJECT
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 213, "assert(" "etype >= T_BOOLEAN && etype <= T_OBJECT"
") failed", "valid etype"); ::breakpoint(); } } while (0)
;
1
Assuming 'etype' is >= T_BOOLEAN
2
Assuming 'etype' is <= T_OBJECT
3
Taking false branch
4
Loop condition is false. Exiting loop
214 // Note that T_ARRAY is not allowed here.
215 int hsize = arrayOopDesc::base_offset_in_bytes(etype);
216 int esize = type2aelembytes(etype);
217 bool isobj = (etype == T_OBJECT);
5
Assuming 'etype' is not equal to T_OBJECT
218 int tag = isobj
5.1
'isobj' is false
5.1
'isobj' is false
? _lh_array_tag_obj_value : _lh_array_tag_type_value;
6
'?' condition is false
7
'tag' initialized to -1
219 int lh = array_layout_helper(tag, hsize, etype, exact_log2(esize));
8
Passing the value -1 via 1st parameter 'tag'
9
Calling 'Klass::array_layout_helper'
220
221 assert(lh < (int)_lh_neutral_value, "must look like an array layout")do { if (!(lh < (int)_lh_neutral_value)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 221, "assert(" "lh < (int)_lh_neutral_value" ") failed",
"must look like an array layout"); ::breakpoint(); } } while
(0)
;
222 assert(layout_helper_is_array(lh), "correct kind")do { if (!(layout_helper_is_array(lh))) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 222, "assert(" "layout_helper_is_array(lh)" ") failed", "correct kind"
); ::breakpoint(); } } while (0)
;
223 assert(layout_helper_is_objArray(lh) == isobj, "correct kind")do { if (!(layout_helper_is_objArray(lh) == isobj)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 223, "assert(" "layout_helper_is_objArray(lh) == isobj" ") failed"
, "correct kind"); ::breakpoint(); } } while (0)
;
224 assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind")do { if (!(layout_helper_is_typeArray(lh) == !isobj)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 224, "assert(" "layout_helper_is_typeArray(lh) == !isobj" ") failed"
, "correct kind"); ::breakpoint(); } } while (0)
;
225 assert(layout_helper_header_size(lh) == hsize, "correct decode")do { if (!(layout_helper_header_size(lh) == hsize)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 225, "assert(" "layout_helper_header_size(lh) == hsize" ") failed"
, "correct decode"); ::breakpoint(); } } while (0)
;
226 assert(layout_helper_element_type(lh) == etype, "correct decode")do { if (!(layout_helper_element_type(lh) == etype)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 226, "assert(" "layout_helper_element_type(lh) == etype" ") failed"
, "correct decode"); ::breakpoint(); } } while (0)
;
227 assert(1 << layout_helper_log2_element_size(lh) == esize, "correct decode")do { if (!(1 << layout_helper_log2_element_size(lh) == esize
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 227, "assert(" "1 << layout_helper_log2_element_size(lh) == esize"
") failed", "correct decode"); ::breakpoint(); } } while (0)
;
228
229 return lh;
230}
231
232bool Klass::can_be_primary_super_slow() const {
233 if (super() == NULL__null)
234 return true;
235 else if (super()->super_depth() >= primary_super_limit()-1)
236 return false;
237 else
238 return true;
239}
240
241void Klass::initialize_supers(Klass* k, Array<InstanceKlass*>* transitive_interfaces, TRAPSJavaThread* __the_thread__) {
242 if (k == NULL__null) {
243 set_super(NULL__null);
244 _primary_supers[0] = this;
245 assert(super_depth() == 0, "Object must already be initialized properly")do { if (!(super_depth() == 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 245, "assert(" "super_depth() == 0" ") failed", "Object must already be initialized properly"
); ::breakpoint(); } } while (0)
;
246 } else if (k != super() || k == vmClasses::Object_klass()) {
247 assert(super() == NULL || super() == vmClasses::Object_klass(),do { if (!(super() == __null || super() == vmClasses::Object_klass
())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 248, "assert(" "super() == __null || super() == vmClasses::Object_klass()"
") failed", "initialize this only once to a non-trivial value"
); ::breakpoint(); } } while (0)
248 "initialize this only once to a non-trivial value")do { if (!(super() == __null || super() == vmClasses::Object_klass
())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 248, "assert(" "super() == __null || super() == vmClasses::Object_klass()"
") failed", "initialize this only once to a non-trivial value"
); ::breakpoint(); } } while (0)
;
249 set_super(k);
250 Klass* sup = k;
251 int sup_depth = sup->super_depth();
252 juint my_depth = MIN2(sup_depth + 1, (int)primary_super_limit());
253 if (!can_be_primary_super_slow())
254 my_depth = primary_super_limit();
255 for (juint i = 0; i < my_depth; i++) {
256 _primary_supers[i] = sup->_primary_supers[i];
257 }
258 Klass* *super_check_cell;
259 if (my_depth < primary_super_limit()) {
260 _primary_supers[my_depth] = this;
261 super_check_cell = &_primary_supers[my_depth];
262 } else {
263 // Overflow of the primary_supers array forces me to be secondary.
264 super_check_cell = &_secondary_super_cache;
265 }
266 set_super_check_offset((address)super_check_cell - (address) this);
267
268#ifdef ASSERT1
269 {
270 juint j = super_depth();
271 assert(j == my_depth, "computed accessor gets right answer")do { if (!(j == my_depth)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 271, "assert(" "j == my_depth" ") failed", "computed accessor gets right answer"
); ::breakpoint(); } } while (0)
;
272 Klass* t = this;
273 while (!t->can_be_primary_super()) {
274 t = t->super();
275 j = t->super_depth();
276 }
277 for (juint j1 = j+1; j1 < primary_super_limit(); j1++) {
278 assert(primary_super_of_depth(j1) == NULL, "super list padding")do { if (!(primary_super_of_depth(j1) == __null)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 278, "assert(" "primary_super_of_depth(j1) == __null" ") failed"
, "super list padding"); ::breakpoint(); } } while (0)
;
279 }
280 while (t != NULL__null) {
281 assert(primary_super_of_depth(j) == t, "super list initialization")do { if (!(primary_super_of_depth(j) == t)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 281, "assert(" "primary_super_of_depth(j) == t" ") failed",
"super list initialization"); ::breakpoint(); } } while (0)
;
282 t = t->super();
283 --j;
284 }
285 assert(j == (juint)-1, "correct depth count")do { if (!(j == (juint)-1)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 285, "assert(" "j == (juint)-1" ") failed", "correct depth count"
); ::breakpoint(); } } while (0)
;
286 }
287#endif
288 }
289
290 if (secondary_supers() == NULL__null) {
291
292 // Now compute the list of secondary supertypes.
293 // Secondaries can occasionally be on the super chain,
294 // if the inline "_primary_supers" array overflows.
295 int extras = 0;
296 Klass* p;
297 for (p = super(); !(p == NULL__null || p->can_be_primary_super()); p = p->super()) {
298 ++extras;
299 }
300
301 ResourceMark rm(THREAD__the_thread__); // need to reclaim GrowableArrays allocated below
302
303 // Compute the "real" non-extra secondaries.
304 GrowableArray<Klass*>* secondaries = compute_secondary_supers(extras, transitive_interfaces);
305 if (secondaries == NULL__null) {
306 // secondary_supers set by compute_secondary_supers
307 return;
308 }
309
310 GrowableArray<Klass*>* primaries = new GrowableArray<Klass*>(extras);
311
312 for (p = super(); !(p == NULL__null || p->can_be_primary_super()); p = p->super()) {
313 int i; // Scan for overflow primaries being duplicates of 2nd'arys
314
315 // This happens frequently for very deeply nested arrays: the
316 // primary superclass chain overflows into the secondary. The
317 // secondary list contains the element_klass's secondaries with
318 // an extra array dimension added. If the element_klass's
319 // secondary list already contains some primary overflows, they
320 // (with the extra level of array-ness) will collide with the
321 // normal primary superclass overflows.
322 for( i = 0; i < secondaries->length(); i++ ) {
323 if( secondaries->at(i) == p )
324 break;
325 }
326 if( i < secondaries->length() )
327 continue; // It's a dup, don't put it in
328 primaries->push(p);
329 }
330 // Combine the two arrays into a metadata object to pack the array.
331 // The primaries are added in the reverse order, then the secondaries.
332 int new_length = primaries->length() + secondaries->length();
333 Array<Klass*>* s2 = MetadataFactory::new_array<Klass*>(
334 class_loader_data(), new_length, CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0
);
335 int fill_p = primaries->length();
336 for (int j = 0; j < fill_p; j++) {
337 s2->at_put(j, primaries->pop()); // add primaries in reverse order.
338 }
339 for( int j = 0; j < secondaries->length(); j++ ) {
340 s2->at_put(j+fill_p, secondaries->at(j)); // add secondaries on the end.
341 }
342
343 #ifdef ASSERT1
344 // We must not copy any NULL placeholders left over from bootstrap.
345 for (int j = 0; j < s2->length(); j++) {
346 assert(s2->at(j) != NULL, "correct bootstrapping order")do { if (!(s2->at(j) != __null)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 346, "assert(" "s2->at(j) != __null" ") failed", "correct bootstrapping order"
); ::breakpoint(); } } while (0)
;
347 }
348 #endif
349
350 set_secondary_supers(s2);
351 }
352}
353
354GrowableArray<Klass*>* Klass::compute_secondary_supers(int num_extra_slots,
355 Array<InstanceKlass*>* transitive_interfaces) {
356 assert(num_extra_slots == 0, "override for complex klasses")do { if (!(num_extra_slots == 0)) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 356, "assert(" "num_extra_slots == 0" ") failed", "override for complex klasses"
); ::breakpoint(); } } while (0)
;
357 assert(transitive_interfaces == NULL, "sanity")do { if (!(transitive_interfaces == __null)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 357, "assert(" "transitive_interfaces == __null" ") failed"
, "sanity"); ::breakpoint(); } } while (0)
;
358 set_secondary_supers(Universe::the_empty_klass_array());
359 return NULL__null;
360}
361
362
363// superklass links
364InstanceKlass* Klass::superklass() const {
365 assert(super() == NULL || super()->is_instance_klass(), "must be instance klass")do { if (!(super() == __null || super()->is_instance_klass
())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 365, "assert(" "super() == __null || super()->is_instance_klass()"
") failed", "must be instance klass"); ::breakpoint(); } } while
(0)
;
366 return _super == NULL__null ? NULL__null : InstanceKlass::cast(_super);
367}
368
369// subklass links. Used by the compiler (and vtable initialization)
370// May be cleaned concurrently, so must use the Compile_lock.
371// The log parameter is for clean_weak_klass_links to report unlinked classes.
372Klass* Klass::subklass(bool log) const {
373 // Need load_acquire on the _subklass, because it races with inserts that
374 // publishes freshly initialized data.
375 for (Klass* chain = Atomic::load_acquire(&_subklass);
376 chain != NULL__null;
377 // Do not need load_acquire on _next_sibling, because inserts never
378 // create _next_sibling edges to dead data.
379 chain = Atomic::load(&chain->_next_sibling))
380 {
381 if (chain->is_loader_alive()) {
382 return chain;
383 } else if (log) {
384 if (log_is_enabled(Trace, class, unload)(LogImpl<(LogTag::_class), (LogTag::_unload), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Trace))
) {
385 ResourceMark rm;
386 log_trace(class, unload)(!(LogImpl<(LogTag::_class), (LogTag::_unload), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag
::_class), (LogTag::_unload), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Trace>
("unlinking class (subclass): %s", chain->external_name());
387 }
388 }
389 }
390 return NULL__null;
391}
392
393Klass* Klass::next_sibling(bool log) const {
394 // Do not need load_acquire on _next_sibling, because inserts never
395 // create _next_sibling edges to dead data.
396 for (Klass* chain = Atomic::load(&_next_sibling);
397 chain != NULL__null;
398 chain = Atomic::load(&chain->_next_sibling)) {
399 // Only return alive klass, there may be stale klass
400 // in this chain if cleaned concurrently.
401 if (chain->is_loader_alive()) {
402 return chain;
403 } else if (log) {
404 if (log_is_enabled(Trace, class, unload)(LogImpl<(LogTag::_class), (LogTag::_unload), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Trace))
) {
405 ResourceMark rm;
406 log_trace(class, unload)(!(LogImpl<(LogTag::_class), (LogTag::_unload), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag
::_class), (LogTag::_unload), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Trace>
("unlinking class (sibling): %s", chain->external_name());
407 }
408 }
409 }
410 return NULL__null;
411}
412
413void Klass::set_subklass(Klass* s) {
414 assert(s != this, "sanity check")do { if (!(s != this)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 414, "assert(" "s != this" ") failed", "sanity check"); ::breakpoint
(); } } while (0)
;
415 Atomic::release_store(&_subklass, s);
416}
417
418void Klass::set_next_sibling(Klass* s) {
419 assert(s != this, "sanity check")do { if (!(s != this)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 419, "assert(" "s != this" ") failed", "sanity check"); ::breakpoint
(); } } while (0)
;
420 // Does not need release semantics. If used by cleanup, it will link to
421 // already safely published data, and if used by inserts, will be published
422 // safely using cmpxchg.
423 Atomic::store(&_next_sibling, s);
424}
425
426void Klass::append_to_sibling_list() {
427 if (Universe::is_fully_initialized()) {
428 assert_locked_or_safepoint(Compile_lock);
429 }
430 debug_only(verify();)verify();
431 // add ourselves to superklass' subklass list
432 InstanceKlass* super = superklass();
433 if (super == NULL__null) return; // special case: class Object
434 assert((!super->is_interface() // interfaces cannot be supersdo { if (!((!super->is_interface() && (super->superklass
() == __null || !is_interface())))) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 436, "assert(" "(!super->is_interface() && (super->superklass() == __null || !is_interface()))"
") failed", "an interface can only be a subklass of Object")
; ::breakpoint(); } } while (0)
435 && (super->superklass() == NULL || !is_interface())),do { if (!((!super->is_interface() && (super->superklass
() == __null || !is_interface())))) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 436, "assert(" "(!super->is_interface() && (super->superklass() == __null || !is_interface()))"
") failed", "an interface can only be a subklass of Object")
; ::breakpoint(); } } while (0)
436 "an interface can only be a subklass of Object")do { if (!((!super->is_interface() && (super->superklass
() == __null || !is_interface())))) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 436, "assert(" "(!super->is_interface() && (super->superklass() == __null || !is_interface()))"
") failed", "an interface can only be a subklass of Object")
; ::breakpoint(); } } while (0)
;
437
438 // Make sure there is no stale subklass head
439 super->clean_subklass();
440
441 for (;;) {
442 Klass* prev_first_subklass = Atomic::load_acquire(&_super->_subklass);
443 if (prev_first_subklass != NULL__null) {
444 // set our sibling to be the superklass' previous first subklass
445 assert(prev_first_subklass->is_loader_alive(), "May not attach not alive klasses")do { if (!(prev_first_subklass->is_loader_alive())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 445, "assert(" "prev_first_subklass->is_loader_alive()" ") failed"
, "May not attach not alive klasses"); ::breakpoint(); } } while
(0)
;
446 set_next_sibling(prev_first_subklass);
447 }
448 // Note that the prev_first_subklass is always alive, meaning no sibling_next links
449 // are ever created to not alive klasses. This is an important invariant of the lock-free
450 // cleaning protocol, that allows us to safely unlink dead klasses from the sibling list.
451 if (Atomic::cmpxchg(&super->_subklass, prev_first_subklass, this) == prev_first_subklass) {
452 return;
453 }
454 }
455 debug_only(verify();)verify();
456}
457
458void Klass::clean_subklass() {
459 for (;;) {
460 // Need load_acquire, due to contending with concurrent inserts
461 Klass* subklass = Atomic::load_acquire(&_subklass);
462 if (subklass == NULL__null || subklass->is_loader_alive()) {
463 return;
464 }
465 // Try to fix _subklass until it points at something not dead.
466 Atomic::cmpxchg(&_subklass, subklass, subklass->next_sibling());
467 }
468}
469
470void Klass::clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses) {
471 if (!ClassUnloading || !unloading_occurred) {
472 return;
473 }
474
475 Klass* root = vmClasses::Object_klass();
476 Stack<Klass*, mtGC> stack;
477
478 stack.push(root);
479 while (!stack.is_empty()) {
480 Klass* current = stack.pop();
481
482 assert(current->is_loader_alive(), "just checking, this should be live")do { if (!(current->is_loader_alive())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 482, "assert(" "current->is_loader_alive()" ") failed", "just checking, this should be live"
); ::breakpoint(); } } while (0)
;
483
484 // Find and set the first alive subklass
485 Klass* sub = current->subklass(true);
486 current->clean_subklass();
487 if (sub != NULL__null) {
488 stack.push(sub);
489 }
490
491 // Find and set the first alive sibling
492 Klass* sibling = current->next_sibling(true);
493 current->set_next_sibling(sibling);
494 if (sibling != NULL__null) {
495 stack.push(sibling);
496 }
497
498 // Clean the implementors list and method data.
499 if (clean_alive_klasses && current->is_instance_klass()) {
500 InstanceKlass* ik = InstanceKlass::cast(current);
501 ik->clean_weak_instanceklass_links();
502
503 // JVMTI RedefineClasses creates previous versions that are not in
504 // the class hierarchy, so process them here.
505 while ((ik = ik->previous_versions()) != NULL__null) {
506 ik->clean_weak_instanceklass_links();
507 }
508 }
509 }
510}
511
512void Klass::metaspace_pointers_do(MetaspaceClosure* it) {
513 if (log_is_enabled(Trace, cds)(LogImpl<(LogTag::_cds), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Trace))
) {
514 ResourceMark rm;
515 log_trace(cds)(!(LogImpl<(LogTag::_cds), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag
::_cds), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Trace>
("Iter(Klass): %p (%s)", this, external_name());
516 }
517
518 it->push(&_name);
519 it->push(&_secondary_super_cache);
520 it->push(&_secondary_supers);
521 for (int i = 0; i < _primary_super_limit; i++) {
522 it->push(&_primary_supers[i]);
523 }
524 it->push(&_super);
525 if (!Arguments::is_dumping_archive()) {
526 // If dumping archive, these may point to excluded classes. There's no need
527 // to follow these pointers anyway, as they will be set to NULL in
528 // remove_unshareable_info().
529 it->push((Klass**)&_subklass);
530 it->push((Klass**)&_next_sibling);
531 it->push(&_next_link);
532 }
533
534 vtableEntry* vt = start_of_vtable();
535 for (int i=0; i<vtable_length(); i++) {
536 it->push(vt[i].method_addr());
537 }
538}
539
540void Klass::remove_unshareable_info() {
541 assert (Arguments::is_dumping_archive(),do { if (!(Arguments::is_dumping_archive())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 542, "assert(" "Arguments::is_dumping_archive()" ") failed"
, "only called during CDS dump time"); ::breakpoint(); } } while
(0)
542 "only called during CDS dump time")do { if (!(Arguments::is_dumping_archive())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 542, "assert(" "Arguments::is_dumping_archive()" ") failed"
, "only called during CDS dump time"); ::breakpoint(); } } while
(0)
;
543 JFR_ONLY(REMOVE_ID(this);)JfrTraceId::remove(this);;
544 if (log_is_enabled(Trace, cds, unshareable)(LogImpl<(LogTag::_cds), (LogTag::_unshareable), (LogTag::
__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG
)>::is_level(LogLevel::Trace))
) {
545 ResourceMark rm;
546 log_trace(cds, unshareable)(!(LogImpl<(LogTag::_cds), (LogTag::_unshareable), (LogTag
::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::
__NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl
<(LogTag::_cds), (LogTag::_unshareable), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::write<LogLevel::Trace>
("remove: %s", external_name());
547 }
548
549 set_subklass(NULL__null);
550 set_next_sibling(NULL__null);
551 set_next_link(NULL__null);
552
553 // Null out class_loader_data because we don't share that yet.
554 set_class_loader_data(NULL__null);
555 set_is_shared();
556}
557
558void Klass::remove_java_mirror() {
559 Arguments::assert_is_dumping_archive();
560 if (log_is_enabled(Trace, cds, unshareable)(LogImpl<(LogTag::_cds), (LogTag::_unshareable), (LogTag::
__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG
)>::is_level(LogLevel::Trace))
) {
561 ResourceMark rm;
562 log_trace(cds, unshareable)(!(LogImpl<(LogTag::_cds), (LogTag::_unshareable), (LogTag
::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::
__NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl
<(LogTag::_cds), (LogTag::_unshareable), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::write<LogLevel::Trace>
("remove java_mirror: %s", external_name());
563 }
564 // Just null out the mirror. The class_loader_data() no longer exists.
565 clear_java_mirror_handle();
566}
567
568void Klass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPSJavaThread* __the_thread__) {
569 assert(is_klass(), "ensure C++ vtable is restored")do { if (!(is_klass())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 569, "assert(" "is_klass()" ") failed", "ensure C++ vtable is restored"
); ::breakpoint(); } } while (0)
;
570 assert(is_shared(), "must be set")do { if (!(is_shared())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 570, "assert(" "is_shared()" ") failed", "must be set"); ::
breakpoint(); } } while (0)
;
571 JFR_ONLY(RESTORE_ID(this);)JfrTraceId::restore(this);;
572 if (log_is_enabled(Trace, cds, unshareable)(LogImpl<(LogTag::_cds), (LogTag::_unshareable), (LogTag::
__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG
)>::is_level(LogLevel::Trace))
) {
573 ResourceMark rm(THREAD__the_thread__);
574 log_trace(cds, unshareable)(!(LogImpl<(LogTag::_cds), (LogTag::_unshareable), (LogTag
::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::
__NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl
<(LogTag::_cds), (LogTag::_unshareable), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::write<LogLevel::Trace>
("restore: %s", external_name());
575 }
576
577 // If an exception happened during CDS restore, some of these fields may already be
578 // set. We leave the class on the CLD list, even if incomplete so that we don't
579 // modify the CLD list outside a safepoint.
580 if (class_loader_data() == NULL__null) {
581 set_class_loader_data(loader_data);
582
583 // Add to class loader list first before creating the mirror
584 // (same order as class file parsing)
585 loader_data->add_class(this);
586 }
587
588 Handle loader(THREAD__the_thread__, loader_data->class_loader());
589 ModuleEntry* module_entry = NULL__null;
590 Klass* k = this;
591 if (k->is_objArray_klass()) {
592 k = ObjArrayKlass::cast(k)->bottom_klass();
593 }
594 // Obtain klass' module.
595 if (k->is_instance_klass()) {
596 InstanceKlass* ik = (InstanceKlass*) k;
597 module_entry = ik->module();
598 } else {
599 module_entry = ModuleEntryTable::javabase_moduleEntry();
600 }
601 // Obtain java.lang.Module, if available
602 Handle module_handle(THREAD__the_thread__, ((module_entry != NULL__null) ? module_entry->module() : (oop)NULL__null));
603
604 if (this->has_archived_mirror_index()) {
605 ResourceMark rm(THREAD__the_thread__);
606 log_debug(cds, mirror)(!(LogImpl<(LogTag::_cds), (LogTag::_mirror), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Debug))) ? (void)0 : LogImpl<(LogTag
::_cds), (LogTag::_mirror), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Debug>
("%s has raw archived mirror", external_name());
607 if (HeapShared::are_archived_mirrors_available()) {
608 bool present = java_lang_Class::restore_archived_mirror(this, loader, module_handle,
609 protection_domain,
610 CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0
);
611 if (present) {
612 return;
613 }
614 }
615
616 // No archived mirror data
617 log_debug(cds, mirror)(!(LogImpl<(LogTag::_cds), (LogTag::_mirror), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Debug))) ? (void)0 : LogImpl<(LogTag
::_cds), (LogTag::_mirror), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Debug>
("No archived mirror data for %s", external_name());
618 clear_java_mirror_handle();
619 this->clear_archived_mirror_index();
620 }
621
622 // Only recreate it if not present. A previous attempt to restore may have
623 // gotten an OOM later but keep the mirror if it was created.
624 if (java_mirror() == NULL__null) {
625 ResourceMark rm(THREAD__the_thread__);
626 log_trace(cds, mirror)(!(LogImpl<(LogTag::_cds), (LogTag::_mirror), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag
::_cds), (LogTag::_mirror), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Trace>
("Recreate mirror for %s", external_name());
627 java_lang_Class::create_mirror(this, loader, module_handle, protection_domain, Handle(), CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0
);
628 }
629}
630
631#if INCLUDE_CDS_JAVA_HEAP1
632oop Klass::archived_java_mirror() {
633 assert(has_archived_mirror_index(), "must have archived mirror")do { if (!(has_archived_mirror_index())) { (*g_assert_poison)
= 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 633, "assert(" "has_archived_mirror_index()" ") failed", "must have archived mirror"
); ::breakpoint(); } } while (0)
;
634 return HeapShared::get_root(_archived_mirror_index);
635}
636
637void Klass::clear_archived_mirror_index() {
638 if (_archived_mirror_index >= 0) {
639 HeapShared::clear_root(_archived_mirror_index);
640 }
641 _archived_mirror_index = -1;
642}
643
644// No GC barrier
645void Klass::set_archived_java_mirror(oop m) {
646 assert(DumpSharedSpaces, "called only during runtime")do { if (!(DumpSharedSpaces)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 646, "assert(" "DumpSharedSpaces" ") failed", "called only during runtime"
); ::breakpoint(); } } while (0)
;
647 _archived_mirror_index = HeapShared::append_root(m);
648}
649#endif // INCLUDE_CDS_JAVA_HEAP
650
651void Klass::check_array_allocation_length(int length, int max_length, TRAPSJavaThread* __the_thread__) {
652 if (length > max_length) {
653 if (!THREAD__the_thread__->in_retryable_allocation()) {
654 report_java_out_of_memory("Requested array size exceeds VM limit");
655 JvmtiExport::post_array_size_exhausted();
656 THROW_OOP(Universe::out_of_memory_error_array_size()){ Exceptions::_throw_oop(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 656, Universe::out_of_memory_error_array_size()); return; }
;
657 } else {
658 THROW_OOP(Universe::out_of_memory_error_retry()){ Exceptions::_throw_oop(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 658, Universe::out_of_memory_error_retry()); return; }
;
659 }
660 } else if (length < 0) {
661 THROW_MSG(vmSymbols::java_lang_NegativeArraySizeException(), err_msg("%d", length)){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 661, vmSymbols::java_lang_NegativeArraySizeException(), err_msg
("%d", length)); return; }
;
662 }
663}
664
665// Replace the last '+' char with '/'.
666static char* convert_hidden_name_to_java(Symbol* name) {
667 size_t name_len = name->utf8_length();
668 char* result = NEW_RESOURCE_ARRAY(char, name_len + 1)(char*) resource_allocate_bytes((name_len + 1) * sizeof(char)
)
;
669 name->as_klass_external_name(result, (int)name_len + 1);
670 for (int index = (int)name_len; index > 0; index--) {
671 if (result[index] == '+') {
672 result[index] = JVM_SIGNATURE_SLASH;
673 break;
674 }
675 }
676 return result;
677}
678
679// In product mode, this function doesn't have virtual function calls so
680// there might be some performance advantage to handling InstanceKlass here.
681const char* Klass::external_name() const {
682 if (is_instance_klass()) {
683 const InstanceKlass* ik = static_cast<const InstanceKlass*>(this);
684 if (ik->is_hidden()) {
685 char* result = convert_hidden_name_to_java(name());
686 return result;
687 }
688 } else if (is_objArray_klass() && ObjArrayKlass::cast(this)->bottom_klass()->is_hidden()) {
689 char* result = convert_hidden_name_to_java(name());
690 return result;
691 }
692 if (name() == NULL__null) return "<unknown>";
693 return name()->as_klass_external_name();
694}
695
696const char* Klass::signature_name() const {
697 if (name() == NULL__null) return "<unknown>";
698 if (is_objArray_klass() && ObjArrayKlass::cast(this)->bottom_klass()->is_hidden()) {
699 size_t name_len = name()->utf8_length();
700 char* result = NEW_RESOURCE_ARRAY(char, name_len + 1)(char*) resource_allocate_bytes((name_len + 1) * sizeof(char)
)
;
701 name()->as_C_string(result, (int)name_len + 1);
702 for (int index = (int)name_len; index > 0; index--) {
703 if (result[index] == '+') {
704 result[index] = JVM_SIGNATURE_DOT;
705 break;
706 }
707 }
708 return result;
709 }
710 return name()->as_C_string();
711}
712
713const char* Klass::external_kind() const {
714 if (is_interface()) return "interface";
715 if (is_abstract()) return "abstract class";
716 return "class";
717}
718
719// Unless overridden, jvmti_class_status has no flags set.
720jint Klass::jvmti_class_status() const {
721 return 0;
722}
723
724
725// Printing
726
727void Klass::print_on(outputStream* st) const {
728 ResourceMark rm;
729 // print title
730 st->print("%s", internal_name());
731 print_address_on(st);
732 st->cr();
733}
734
735#define BULLET" - " " - "
736
737// Caller needs ResourceMark
738void Klass::oop_print_on(oop obj, outputStream* st) {
739 // print title
740 st->print_cr("%s ", internal_name());
741 obj->print_address_on(st);
742
743 if (WizardMode) {
744 // print header
745 obj->mark().print_on(st);
746 st->cr();
747 }
748
749 // print class
750 st->print(BULLET" - ""klass: ");
751 obj->klass()->print_value_on(st);
752 st->cr();
753}
754
755void Klass::oop_print_value_on(oop obj, outputStream* st) {
756 // print title
757 ResourceMark rm; // Cannot print in debug mode without this
758 st->print("%s", internal_name());
759 obj->print_address_on(st);
760}
761
762// Verification
763
764void Klass::verify_on(outputStream* st) {
765
766 // This can be expensive, but it is worth checking that this klass is actually
767 // in the CLD graph but not in production.
768 assert(Metaspace::contains((address)this), "Should be")do { if (!(Metaspace::contains((address)this))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 768, "assert(" "Metaspace::contains((address)this)" ") failed"
, "Should be"); ::breakpoint(); } } while (0)
;
769
770 guarantee(this->is_klass(),"should be klass")do { if (!(this->is_klass())) { (*g_assert_poison) = 'X';;
report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 770, "guarantee(" "this->is_klass()" ") failed", "should be klass"
); ::breakpoint(); } } while (0)
;
771
772 if (super() != NULL__null) {
773 guarantee(super()->is_klass(), "should be klass")do { if (!(super()->is_klass())) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 773, "guarantee(" "super()->is_klass()" ") failed", "should be klass"
); ::breakpoint(); } } while (0)
;
774 }
775 if (secondary_super_cache() != NULL__null) {
776 Klass* ko = secondary_super_cache();
777 guarantee(ko->is_klass(), "should be klass")do { if (!(ko->is_klass())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 777, "guarantee(" "ko->is_klass()" ") failed", "should be klass"
); ::breakpoint(); } } while (0)
;
778 }
779 for ( uint i = 0; i < primary_super_limit(); i++ ) {
780 Klass* ko = _primary_supers[i];
781 if (ko != NULL__null) {
782 guarantee(ko->is_klass(), "should be klass")do { if (!(ko->is_klass())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 782, "guarantee(" "ko->is_klass()" ") failed", "should be klass"
); ::breakpoint(); } } while (0)
;
783 }
784 }
785
786 if (java_mirror_no_keepalive() != NULL__null) {
787 guarantee(oopDesc::is_oop(java_mirror_no_keepalive()), "should be instance")do { if (!(oopDesc::is_oop(java_mirror_no_keepalive()))) { (*
g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 787, "guarantee(" "oopDesc::is_oop(java_mirror_no_keepalive())"
") failed", "should be instance"); ::breakpoint(); } } while
(0)
;
788 }
789}
790
791void Klass::oop_verify_on(oop obj, outputStream* st) {
792 guarantee(oopDesc::is_oop(obj), "should be oop")do { if (!(oopDesc::is_oop(obj))) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 792, "guarantee(" "oopDesc::is_oop(obj)" ") failed", "should be oop"
); ::breakpoint(); } } while (0)
;
793 guarantee(obj->klass()->is_klass(), "klass field is not a klass")do { if (!(obj->klass()->is_klass())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 793, "guarantee(" "obj->klass()->is_klass()" ") failed"
, "klass field is not a klass"); ::breakpoint(); } } while (0
)
;
794}
795
796bool Klass::is_valid(Klass* k) {
797 if (!is_aligned(k, sizeof(MetaWord))) return false;
798 if ((size_t)k < os::min_page_size()) return false;
799
800 if (!os::is_readable_range(k, k + 1)) return false;
801 if (!Metaspace::contains(k)) return false;
802
803 if (!Symbol::is_valid(k->name())) return false;
804 return ClassLoaderDataGraph::is_valid(k->class_loader_data());
805}
806
807Method* Klass::method_at_vtable(int index) {
808#ifndef PRODUCT
809 assert(index >= 0, "valid vtable index")do { if (!(index >= 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 809, "assert(" "index >= 0" ") failed", "valid vtable index"
); ::breakpoint(); } } while (0)
;
810 if (DebugVtables) {
811 verify_vtable_index(index);
812 }
813#endif
814 return start_of_vtable()[index].method();
815}
816
817
818#ifndef PRODUCT
819
820bool Klass::verify_vtable_index(int i) {
821 int limit = vtable_length()/vtableEntry::size();
822 assert(i >= 0 && i < limit, "index %d out of bounds %d", i, limit)do { if (!(i >= 0 && i < limit)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 822, "assert(" "i >= 0 && i < limit" ") failed"
, "index %d out of bounds %d", i, limit); ::breakpoint(); } }
while (0)
;
823 return true;
824}
825
826#endif // PRODUCT
827
828// Caller needs ResourceMark
829// joint_in_module_of_loader provides an optimization if 2 classes are in
830// the same module to succinctly print out relevant information about their
831// module name and class loader's name_and_id for error messages.
832// Format:
833// <fully-qualified-external-class-name1> and <fully-qualified-external-class-name2>
834// are in module <module-name>[@<version>]
835// of loader <loader-name_and_id>[, parent loader <parent-loader-name_and_id>]
836const char* Klass::joint_in_module_of_loader(const Klass* class2, bool include_parent_loader) const {
837 assert(module() == class2->module(), "classes do not have the same module")do { if (!(module() == class2->module())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 837, "assert(" "module() == class2->module()" ") failed"
, "classes do not have the same module"); ::breakpoint(); } }
while (0)
;
838 const char* class1_name = external_name();
839 size_t len = strlen(class1_name) + 1;
840
841 const char* class2_description = class2->class_in_module_of_loader(true, include_parent_loader);
842 len += strlen(class2_description);
843
844 len += strlen(" and ");
845
846 char* joint_description = NEW_RESOURCE_ARRAY_RETURN_NULL(char, len)(char*) resource_allocate_bytes((len) * sizeof(char), AllocFailStrategy
::RETURN_NULL)
;
847
848 // Just return the FQN if error when allocating string
849 if (joint_description == NULL__null) {
850 return class1_name;
851 }
852
853 jio_snprintf(joint_description, len, "%s and %s",
854 class1_name,
855 class2_description);
856
857 return joint_description;
858}
859
860// Caller needs ResourceMark
861// class_in_module_of_loader provides a standard way to include
862// relevant information about a class, such as its module name as
863// well as its class loader's name_and_id, in error messages and logging.
864// Format:
865// <fully-qualified-external-class-name> is in module <module-name>[@<version>]
866// of loader <loader-name_and_id>[, parent loader <parent-loader-name_and_id>]
867const char* Klass::class_in_module_of_loader(bool use_are, bool include_parent_loader) const {
868 // 1. fully qualified external name of class
869 const char* klass_name = external_name();
870 size_t len = strlen(klass_name) + 1;
871
872 // 2. module name + @version
873 const char* module_name = "";
874 const char* version = "";
875 bool has_version = false;
876 bool module_is_named = false;
877 const char* module_name_phrase = "";
878 const Klass* bottom_klass = is_objArray_klass() ?
879 ObjArrayKlass::cast(this)->bottom_klass() : this;
880 if (bottom_klass->is_instance_klass()) {
881 ModuleEntry* module = InstanceKlass::cast(bottom_klass)->module();
882 if (module->is_named()) {
883 module_is_named = true;
884 module_name_phrase = "module ";
885 module_name = module->name()->as_C_string();
886 len += strlen(module_name);
887 // Use version if exists and is not a jdk module
888 if (module->should_show_version()) {
889 has_version = true;
890 version = module->version()->as_C_string();
891 // Include stlen(version) + 1 for the "@"
892 len += strlen(version) + 1;
893 }
894 } else {
895 module_name = UNNAMED_MODULE"unnamed module";
896 len += UNNAMED_MODULE_LEN14;
897 }
898 } else {
899 // klass is an array of primitives, module is java.base
900 module_is_named = true;
901 module_name_phrase = "module ";
902 module_name = JAVA_BASE_NAME"java.base";
903 len += JAVA_BASE_NAME_LEN9;
904 }
905
906 // 3. class loader's name_and_id
907 ClassLoaderData* cld = class_loader_data();
908 assert(cld != NULL, "class_loader_data should not be null")do { if (!(cld != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.cpp"
, 908, "assert(" "cld != __null" ") failed", "class_loader_data should not be null"
); ::breakpoint(); } } while (0)
;
909 const char* loader_name_and_id = cld->loader_name_and_id();
910 len += strlen(loader_name_and_id);
911
912 // 4. include parent loader information
913 const char* parent_loader_phrase = "";
914 const char* parent_loader_name_and_id = "";
915 if (include_parent_loader &&
916 !cld->is_builtin_class_loader_data()) {
917 oop parent_loader = java_lang_ClassLoader::parent(class_loader());
918 ClassLoaderData *parent_cld = ClassLoaderData::class_loader_data_or_null(parent_loader);
919 // The parent loader's ClassLoaderData could be null if it is
920 // a delegating class loader that has never defined a class.
921 // In this case the loader's name must be obtained via the parent loader's oop.
922 if (parent_cld == NULL__null) {
923 oop cl_name_and_id = java_lang_ClassLoader::nameAndId(parent_loader);
924 if (cl_name_and_id != NULL__null) {
925 parent_loader_name_and_id = java_lang_String::as_utf8_string(cl_name_and_id);
926 }
927 } else {
928 parent_loader_name_and_id = parent_cld->loader_name_and_id();
929 }
930 parent_loader_phrase = ", parent loader ";
931 len += strlen(parent_loader_phrase) + strlen(parent_loader_name_and_id);
932 }
933
934 // Start to construct final full class description string
935 len += ((use_are) ? strlen(" are in ") : strlen(" is in "));
936 len += strlen(module_name_phrase) + strlen(" of loader ");
937
938 char* class_description = NEW_RESOURCE_ARRAY_RETURN_NULL(char, len)(char*) resource_allocate_bytes((len) * sizeof(char), AllocFailStrategy
::RETURN_NULL)
;
939
940 // Just return the FQN if error when allocating string
941 if (class_description == NULL__null) {
942 return klass_name;
943 }
944
945 jio_snprintf(class_description, len, "%s %s in %s%s%s%s of loader %s%s%s",
946 klass_name,
947 (use_are) ? "are" : "is",
948 module_name_phrase,
949 module_name,
950 (has_version) ? "@" : "",
951 (has_version) ? version : "",
952 loader_name_and_id,
953 parent_loader_phrase,
954 parent_loader_name_and_id);
955
956 return class_description;
957}

/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp

1/*
2 * Copyright (c) 1997, 2021, 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_OOPS_KLASS_HPP
26#define SHARE_OOPS_KLASS_HPP
27
28#include "memory/iterator.hpp"
29#include "memory/memRegion.hpp"
30#include "oops/markWord.hpp"
31#include "oops/metadata.hpp"
32#include "oops/oop.hpp"
33#include "oops/oopHandle.hpp"
34#include "utilities/accessFlags.hpp"
35#include "utilities/macros.hpp"
36#if INCLUDE_JFR1
37#include "jfr/support/jfrTraceIdExtension.hpp"
38#endif
39
40// Klass IDs for all subclasses of Klass
41enum KlassID {
42 InstanceKlassID,
43 InstanceRefKlassID,
44 InstanceMirrorKlassID,
45 InstanceClassLoaderKlassID,
46 TypeArrayKlassID,
47 ObjArrayKlassID
48};
49
50const uint KLASS_ID_COUNT = 6;
51
52//
53// A Klass provides:
54// 1: language level class object (method dictionary etc.)
55// 2: provide vm dispatch behavior for the object
56// Both functions are combined into one C++ class.
57
58// One reason for the oop/klass dichotomy in the implementation is
59// that we don't want a C++ vtbl pointer in every object. Thus,
60// normal oops don't have any virtual functions. Instead, they
61// forward all "virtual" functions to their klass, which does have
62// a vtbl and does the C++ dispatch depending on the object's
63// actual type. (See oop.inline.hpp for some of the forwarding code.)
64// ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
65
66// Forward declarations.
67template <class T> class Array;
68template <class T> class GrowableArray;
69class ClassLoaderData;
70class fieldDescriptor;
71class klassVtable;
72class ModuleEntry;
73class PackageEntry;
74class ParCompactionManager;
75class PSPromotionManager;
76class vtableEntry;
77
78class Klass : public Metadata {
79 friend class VMStructs;
80 friend class JVMCIVMStructs;
81 protected:
82 // If you add a new field that points to any metaspace object, you
83 // must add this field to Klass::metaspace_pointers_do().
84
85 // note: put frequently-used fields together at start of klass structure
86 // for better cache behavior (may not make much of a difference but sure won't hurt)
87 enum { _primary_super_limit = 8 };
88
89 // The "layout helper" is a combined descriptor of object layout.
90 // For klasses which are neither instance nor array, the value is zero.
91 //
92 // For instances, layout helper is a positive number, the instance size.
93 // This size is already passed through align_object_size and scaled to bytes.
94 // The low order bit is set if instances of this class cannot be
95 // allocated using the fastpath.
96 //
97 // For arrays, layout helper is a negative number, containing four
98 // distinct bytes, as follows:
99 // MSB:[tag, hsz, ebt, log2(esz)]:LSB
100 // where:
101 // tag is 0x80 if the elements are oops, 0xC0 if non-oops
102 // hsz is array header size in bytes (i.e., offset of first element)
103 // ebt is the BasicType of the elements
104 // esz is the element size in bytes
105 // This packed word is arranged so as to be quickly unpacked by the
106 // various fast paths that use the various subfields.
107 //
108 // The esz bits can be used directly by a SLL instruction, without masking.
109 //
110 // Note that the array-kind tag looks like 0x00 for instance klasses,
111 // since their length in bytes is always less than 24Mb.
112 //
113 // Final note: This comes first, immediately after C++ vtable,
114 // because it is frequently queried.
115 jint _layout_helper;
116
117 // Klass identifier used to implement devirtualized oop closure dispatching.
118 const KlassID _id;
119
120 // Processed access flags, for use by Class.getModifiers.
121 jint _modifier_flags;
122
123 // The fields _super_check_offset, _secondary_super_cache, _secondary_supers
124 // and _primary_supers all help make fast subtype checks. See big discussion
125 // in doc/server_compiler/checktype.txt
126 //
127 // Where to look to observe a supertype (it is &_secondary_super_cache for
128 // secondary supers, else is &_primary_supers[depth()].
129 juint _super_check_offset;
130
131 // Class name. Instance classes: java/lang/String, etc. Array classes: [I,
132 // [Ljava/lang/String;, etc. Set to zero for all other kinds of classes.
133 Symbol* _name;
134
135 // Cache of last observed secondary supertype
136 Klass* _secondary_super_cache;
137 // Array of all secondary supertypes
138 Array<Klass*>* _secondary_supers;
139 // Ordered list of all primary supertypes
140 Klass* _primary_supers[_primary_super_limit];
141 // java/lang/Class instance mirroring this class
142 OopHandle _java_mirror;
143 // Superclass
144 Klass* _super;
145 // First subclass (NULL if none); _subklass->next_sibling() is next one
146 Klass* volatile _subklass;
147 // Sibling link (or NULL); links all subklasses of a klass
148 Klass* volatile _next_sibling;
149
150 // All klasses loaded by a class loader are chained through these links
151 Klass* _next_link;
152
153 // The VM's representation of the ClassLoader used to load this class.
154 // Provide access the corresponding instance java.lang.ClassLoader.
155 ClassLoaderData* _class_loader_data;
156
157 int _vtable_len; // vtable length. This field may be read very often when we
158 // have lots of itable dispatches (e.g., lambdas and streams).
159 // Keep it away from the beginning of a Klass to avoid cacheline
160 // contention that may happen when a nearby object is modified.
161 AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
162
163 JFR_ONLY(DEFINE_TRACE_ID_FIELD;)mutable traceid _trace_id;
164
165private:
166 // This is an index into FileMapHeader::_shared_path_table[], to
167 // associate this class with the JAR file where it's loaded from during
168 // dump time. If a class is not loaded from the shared archive, this field is
169 // -1.
170 jshort _shared_class_path_index;
171
172#if INCLUDE_CDS1
173 // Flags of the current shared class.
174 u2 _shared_class_flags;
175 enum {
176 _archived_lambda_proxy_is_available = 2,
177 _has_value_based_class_annotation = 4,
178 _verified_at_dump_time = 8
179 };
180#endif
181
182 CDS_JAVA_HEAP_ONLY(int _archived_mirror_index;)int _archived_mirror_index;
183
184protected:
185
186 // Constructor
187 Klass(KlassID id);
188 Klass() : _id(KlassID(-1)) { assert(DumpSharedSpaces || UseSharedSpaces, "only for cds")do { if (!(DumpSharedSpaces || UseSharedSpaces)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 188, "assert(" "DumpSharedSpaces || UseSharedSpaces" ") failed"
, "only for cds"); ::breakpoint(); } } while (0)
; }
189
190 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPSJavaThread* __the_thread__) throw();
191
192 public:
193 int id() { return _id; }
194
195 enum class DefaultsLookupMode { find, skip };
196 enum class OverpassLookupMode { find, skip };
197 enum class StaticLookupMode { find, skip };
198 enum class PrivateLookupMode { find, skip };
199
200 virtual bool is_klass() const { return true; }
201
202 // super() cannot be InstanceKlass* -- Java arrays are covariant, and _super is used
203 // to implement that. NB: the _super of "[Ljava/lang/Integer;" is "[Ljava/lang/Number;"
204 // If this is not what your code expects, you're probably looking for Klass::java_super().
205 Klass* super() const { return _super; }
206 void set_super(Klass* k) { _super = k; }
207
208 // initializes _super link, _primary_supers & _secondary_supers arrays
209 void initialize_supers(Klass* k, Array<InstanceKlass*>* transitive_interfaces, TRAPSJavaThread* __the_thread__);
210
211 // klass-specific helper for initializing _secondary_supers
212 virtual GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots,
213 Array<InstanceKlass*>* transitive_interfaces);
214
215 // java_super is the Java-level super type as specified by Class.getSuperClass.
216 virtual InstanceKlass* java_super() const { return NULL__null; }
217
218 juint super_check_offset() const { return _super_check_offset; }
219 void set_super_check_offset(juint o) { _super_check_offset = o; }
220
221 Klass* secondary_super_cache() const { return _secondary_super_cache; }
222 void set_secondary_super_cache(Klass* k) { _secondary_super_cache = k; }
223
224 Array<Klass*>* secondary_supers() const { return _secondary_supers; }
225 void set_secondary_supers(Array<Klass*>* k) { _secondary_supers = k; }
226
227 // Return the element of the _super chain of the given depth.
228 // If there is no such element, return either NULL or this.
229 Klass* primary_super_of_depth(juint i) const {
230 assert(i < primary_super_limit(), "oob")do { if (!(i < primary_super_limit())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 230, "assert(" "i < primary_super_limit()" ") failed", "oob"
); ::breakpoint(); } } while (0)
;
231 Klass* super = _primary_supers[i];
232 assert(super == NULL || super->super_depth() == i, "correct display")do { if (!(super == __null || super->super_depth() == i)) {
(*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 232, "assert(" "super == __null || super->super_depth() == i"
") failed", "correct display"); ::breakpoint(); } } while (0
)
;
233 return super;
234 }
235
236 // Can this klass be a primary super? False for interfaces and arrays of
237 // interfaces. False also for arrays or classes with long super chains.
238 bool can_be_primary_super() const {
239 const juint secondary_offset = in_bytes(secondary_super_cache_offset());
240 return super_check_offset() != secondary_offset;
241 }
242 virtual bool can_be_primary_super_slow() const;
243
244 // Returns number of primary supers; may be a number in the inclusive range [0, primary_super_limit].
245 juint super_depth() const {
246 if (!can_be_primary_super()) {
247 return primary_super_limit();
248 } else {
249 juint d = (super_check_offset() - in_bytes(primary_supers_offset())) / sizeof(Klass*);
250 assert(d < primary_super_limit(), "oob")do { if (!(d < primary_super_limit())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 250, "assert(" "d < primary_super_limit()" ") failed", "oob"
); ::breakpoint(); } } while (0)
;
251 assert(_primary_supers[d] == this, "proper init")do { if (!(_primary_supers[d] == this)) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 251, "assert(" "_primary_supers[d] == this" ") failed", "proper init"
); ::breakpoint(); } } while (0)
;
252 return d;
253 }
254 }
255
256 // java mirror
257 oop java_mirror() const;
258 oop java_mirror_no_keepalive() const;
259 void set_java_mirror(Handle m);
260
261 oop archived_java_mirror() NOT_CDS_JAVA_HEAP_RETURN_(NULL);
262 void set_archived_java_mirror(oop m) NOT_CDS_JAVA_HEAP_RETURN;
263
264 // Temporary mirror switch used by RedefineClasses
265 void replace_java_mirror(oop mirror);
266
267 // Set java mirror OopHandle to NULL for CDS
268 // This leaves the OopHandle in the CLD, but that's ok, you can't release them.
269 void clear_java_mirror_handle() { _java_mirror = OopHandle(); }
270
271 // modifier flags
272 jint modifier_flags() const { return _modifier_flags; }
273 void set_modifier_flags(jint flags) { _modifier_flags = flags; }
274
275 // size helper
276 int layout_helper() const { return _layout_helper; }
277 void set_layout_helper(int lh) { _layout_helper = lh; }
278
279 // Note: for instances layout_helper() may include padding.
280 // Use InstanceKlass::contains_field_offset to classify field offsets.
281
282 // sub/superklass links
283 Klass* subklass(bool log = false) const;
284 Klass* next_sibling(bool log = false) const;
285
286 InstanceKlass* superklass() const;
287 void append_to_sibling_list(); // add newly created receiver to superklass' subklass list
288
289 void set_next_link(Klass* k) { _next_link = k; }
290 Klass* next_link() const { return _next_link; } // The next klass defined by the class loader.
291 Klass** next_link_addr() { return &_next_link; }
292
293 // class loader data
294 ClassLoaderData* class_loader_data() const { return _class_loader_data; }
295 void set_class_loader_data(ClassLoaderData* loader_data) { _class_loader_data = loader_data; }
296
297 int shared_classpath_index() const {
298 return _shared_class_path_index;
299 };
300
301 void set_shared_classpath_index(int index) {
302 _shared_class_path_index = index;
303 };
304
305 bool has_archived_mirror_index() const {
306 CDS_JAVA_HEAP_ONLY(return _archived_mirror_index >= 0;)return _archived_mirror_index >= 0;
307 NOT_CDS_JAVA_HEAP(return false);
308 }
309
310 void clear_archived_mirror_index() NOT_CDS_JAVA_HEAP_RETURN;
311
312 void set_lambda_proxy_is_available() {
313 CDS_ONLY(_shared_class_flags |= _archived_lambda_proxy_is_available;)_shared_class_flags |= _archived_lambda_proxy_is_available;
314 }
315 void clear_lambda_proxy_is_available() {
316 CDS_ONLY(_shared_class_flags &= ~_archived_lambda_proxy_is_available;)_shared_class_flags &= ~_archived_lambda_proxy_is_available
;
317 }
318 bool lambda_proxy_is_available() const {
319 CDS_ONLY(return (_shared_class_flags & _archived_lambda_proxy_is_available) != 0;)return (_shared_class_flags & _archived_lambda_proxy_is_available
) != 0;
320 NOT_CDS(return false;)
321 }
322
323 void set_has_value_based_class_annotation() {
324 CDS_ONLY(_shared_class_flags |= _has_value_based_class_annotation;)_shared_class_flags |= _has_value_based_class_annotation;
325 }
326 void clear_has_value_based_class_annotation() {
327 CDS_ONLY(_shared_class_flags &= ~_has_value_based_class_annotation;)_shared_class_flags &= ~_has_value_based_class_annotation
;
328 }
329 bool has_value_based_class_annotation() const {
330 CDS_ONLY(return (_shared_class_flags & _has_value_based_class_annotation) != 0;)return (_shared_class_flags & _has_value_based_class_annotation
) != 0;
331 NOT_CDS(return false;)
332 }
333
334 void set_verified_at_dump_time() {
335 CDS_ONLY(_shared_class_flags |= _verified_at_dump_time;)_shared_class_flags |= _verified_at_dump_time;
336 }
337 bool verified_at_dump_time() const {
338 CDS_ONLY(return (_shared_class_flags & _verified_at_dump_time) != 0;)return (_shared_class_flags & _verified_at_dump_time) != 0
;
339 NOT_CDS(return false;)
340 }
341
342
343 // Obtain the module or package for this class
344 virtual ModuleEntry* module() const = 0;
345 virtual PackageEntry* package() const = 0;
346
347 protected: // internal accessors
348 void set_subklass(Klass* s);
349 void set_next_sibling(Klass* s);
350
351 public:
352
353 // Compiler support
354 static ByteSize super_offset() { return in_ByteSize(offset_of(Klass, _super)(size_t)((intx)&(((Klass*)16)->_super) - 16)); }
355 static ByteSize super_check_offset_offset() { return in_ByteSize(offset_of(Klass, _super_check_offset)(size_t)((intx)&(((Klass*)16)->_super_check_offset) - 16
)
); }
356 static ByteSize primary_supers_offset() { return in_ByteSize(offset_of(Klass, _primary_supers)(size_t)((intx)&(((Klass*)16)->_primary_supers) - 16)); }
357 static ByteSize secondary_super_cache_offset() { return in_ByteSize(offset_of(Klass, _secondary_super_cache)(size_t)((intx)&(((Klass*)16)->_secondary_super_cache)
- 16)
); }
358 static ByteSize secondary_supers_offset() { return in_ByteSize(offset_of(Klass, _secondary_supers)(size_t)((intx)&(((Klass*)16)->_secondary_supers) - 16
)
); }
359 static ByteSize java_mirror_offset() { return in_ByteSize(offset_of(Klass, _java_mirror)(size_t)((intx)&(((Klass*)16)->_java_mirror) - 16)); }
360 static ByteSize class_loader_data_offset() { return in_ByteSize(offset_of(Klass, _class_loader_data)(size_t)((intx)&(((Klass*)16)->_class_loader_data) - 16
)
); }
361 static ByteSize modifier_flags_offset() { return in_ByteSize(offset_of(Klass, _modifier_flags)(size_t)((intx)&(((Klass*)16)->_modifier_flags) - 16)); }
362 static ByteSize layout_helper_offset() { return in_ByteSize(offset_of(Klass, _layout_helper)(size_t)((intx)&(((Klass*)16)->_layout_helper) - 16)); }
363 static ByteSize access_flags_offset() { return in_ByteSize(offset_of(Klass, _access_flags)(size_t)((intx)&(((Klass*)16)->_access_flags) - 16)); }
364
365 // Unpacking layout_helper:
366 static const int _lh_neutral_value = 0; // neutral non-array non-instance value
367 static const int _lh_instance_slow_path_bit = 0x01;
368 static const int _lh_log2_element_size_shift = BitsPerByte*0;
369 static const int _lh_log2_element_size_mask = BitsPerLong-1;
370 static const int _lh_element_type_shift = BitsPerByte*1;
371 static const int _lh_element_type_mask = right_n_bits(BitsPerByte)((((BitsPerByte) >= BitsPerWord) ? 0 : (OneBit << (BitsPerByte
))) - 1)
; // shifted mask
372 static const int _lh_header_size_shift = BitsPerByte*2;
373 static const int _lh_header_size_mask = right_n_bits(BitsPerByte)((((BitsPerByte) >= BitsPerWord) ? 0 : (OneBit << (BitsPerByte
))) - 1)
; // shifted mask
374 static const int _lh_array_tag_bits = 2;
375 static const int _lh_array_tag_shift = BitsPerInt - _lh_array_tag_bits;
376 static const int _lh_array_tag_obj_value = ~0x01; // 0x80000000 >> 30
377
378 static const unsigned int _lh_array_tag_type_value = 0Xffffffff; // ~0x00, // 0xC0000000 >> 30
379
380 static int layout_helper_size_in_bytes(jint lh) {
381 assert(lh > (jint)_lh_neutral_value, "must be instance")do { if (!(lh > (jint)_lh_neutral_value)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 381, "assert(" "lh > (jint)_lh_neutral_value" ") failed"
, "must be instance"); ::breakpoint(); } } while (0)
;
382 return (int) lh & ~_lh_instance_slow_path_bit;
383 }
384 static bool layout_helper_needs_slow_path(jint lh) {
385 assert(lh > (jint)_lh_neutral_value, "must be instance")do { if (!(lh > (jint)_lh_neutral_value)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 385, "assert(" "lh > (jint)_lh_neutral_value" ") failed"
, "must be instance"); ::breakpoint(); } } while (0)
;
386 return (lh & _lh_instance_slow_path_bit) != 0;
387 }
388 static bool layout_helper_is_instance(jint lh) {
389 return (jint)lh > (jint)_lh_neutral_value;
390 }
391 static bool layout_helper_is_array(jint lh) {
392 return (jint)lh < (jint)_lh_neutral_value;
393 }
394 static bool layout_helper_is_typeArray(jint lh) {
395 // _lh_array_tag_type_value == (lh >> _lh_array_tag_shift);
396 return (juint)lh >= (juint)(_lh_array_tag_type_value << _lh_array_tag_shift);
397 }
398 static bool layout_helper_is_objArray(jint lh) {
399 // _lh_array_tag_obj_value == (lh >> _lh_array_tag_shift);
400 return (jint)lh < (jint)(_lh_array_tag_type_value << _lh_array_tag_shift);
401 }
402 static int layout_helper_header_size(jint lh) {
403 assert(lh < (jint)_lh_neutral_value, "must be array")do { if (!(lh < (jint)_lh_neutral_value)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 403, "assert(" "lh < (jint)_lh_neutral_value" ") failed"
, "must be array"); ::breakpoint(); } } while (0)
;
404 int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
405 assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity")do { if (!(hsize > 0 && hsize < (int)sizeof(oopDesc
)*3)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 405, "assert(" "hsize > 0 && hsize < (int)sizeof(oopDesc)*3"
") failed", "sanity"); ::breakpoint(); } } while (0)
;
406 return hsize;
407 }
408 static BasicType layout_helper_element_type(jint lh) {
409 assert(lh < (jint)_lh_neutral_value, "must be array")do { if (!(lh < (jint)_lh_neutral_value)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 409, "assert(" "lh < (jint)_lh_neutral_value" ") failed"
, "must be array"); ::breakpoint(); } } while (0)
;
410 int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
411 assert(btvalue >= T_BOOLEAN && btvalue <= T_OBJECT, "sanity")do { if (!(btvalue >= T_BOOLEAN && btvalue <= T_OBJECT
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 411, "assert(" "btvalue >= T_BOOLEAN && btvalue <= T_OBJECT"
") failed", "sanity"); ::breakpoint(); } } while (0)
;
412 return (BasicType) btvalue;
413 }
414
415 // Want a pattern to quickly diff against layout header in register
416 // find something less clever!
417 static int layout_helper_boolean_diffbit() {
418 jint zlh = array_layout_helper(T_BOOLEAN);
419 jint blh = array_layout_helper(T_BYTE);
420 assert(zlh != blh, "array layout helpers must differ")do { if (!(zlh != blh)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 420, "assert(" "zlh != blh" ") failed", "array layout helpers must differ"
); ::breakpoint(); } } while (0)
;
421 int diffbit = 1;
422 while ((diffbit & (zlh ^ blh)) == 0 && (diffbit & zlh) == 0) {
423 diffbit <<= 1;
424 assert(diffbit != 0, "make sure T_BOOLEAN has a different bit than T_BYTE")do { if (!(diffbit != 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 424, "assert(" "diffbit != 0" ") failed", "make sure T_BOOLEAN has a different bit than T_BYTE"
); ::breakpoint(); } } while (0)
;
425 }
426 return diffbit;
427 }
428
429 static int layout_helper_log2_element_size(jint lh) {
430 assert(lh < (jint)_lh_neutral_value, "must be array")do { if (!(lh < (jint)_lh_neutral_value)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 430, "assert(" "lh < (jint)_lh_neutral_value" ") failed"
, "must be array"); ::breakpoint(); } } while (0)
;
431 int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
432 assert(l2esz <= LogBytesPerLong,do { if (!(l2esz <= LogBytesPerLong)) { (*g_assert_poison)
= 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 433, "assert(" "l2esz <= LogBytesPerLong" ") failed", "sanity. l2esz: 0x%x for lh: 0x%x"
, (uint)l2esz, (uint)lh); ::breakpoint(); } } while (0)
433 "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh)do { if (!(l2esz <= LogBytesPerLong)) { (*g_assert_poison)
= 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 433, "assert(" "l2esz <= LogBytesPerLong" ") failed", "sanity. l2esz: 0x%x for lh: 0x%x"
, (uint)l2esz, (uint)lh); ::breakpoint(); } } while (0)
;
434 return l2esz;
435 }
436 static jint array_layout_helper(jint tag, int hsize, BasicType etype, int log2_esize) {
437 return (tag << _lh_array_tag_shift)
10
The result of the left shift is undefined because the left operand is negative
438 | (hsize << _lh_header_size_shift)
439 | ((int)etype << _lh_element_type_shift)
440 | (log2_esize << _lh_log2_element_size_shift);
441 }
442 static jint instance_layout_helper(jint size, bool slow_path_flag) {
443 return (size << LogBytesPerWord)
444 | (slow_path_flag ? _lh_instance_slow_path_bit : 0);
445 }
446 static int layout_helper_to_size_helper(jint lh) {
447 assert(lh > (jint)_lh_neutral_value, "must be instance")do { if (!(lh > (jint)_lh_neutral_value)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 447, "assert(" "lh > (jint)_lh_neutral_value" ") failed"
, "must be instance"); ::breakpoint(); } } while (0)
;
448 // Note that the following expression discards _lh_instance_slow_path_bit.
449 return lh >> LogBytesPerWord;
450 }
451 // Out-of-line version computes everything based on the etype:
452 static jint array_layout_helper(BasicType etype);
453
454 // What is the maximum number of primary superclasses any klass can have?
455 static juint primary_super_limit() { return _primary_super_limit; }
456
457 // vtables
458 klassVtable vtable() const;
459 int vtable_length() const { return _vtable_len; }
460
461 // subclass check
462 bool is_subclass_of(const Klass* k) const;
463 // subtype check: true if is_subclass_of, or if k is interface and receiver implements it
464 bool is_subtype_of(Klass* k) const {
465 juint off = k->super_check_offset();
466 Klass* sup = *(Klass**)( (address)this + off );
467 const juint secondary_offset = in_bytes(secondary_super_cache_offset());
468 if (sup == k) {
469 return true;
470 } else if (off != secondary_offset) {
471 return false;
472 } else {
473 return search_secondary_supers(k);
474 }
475 }
476
477 bool search_secondary_supers(Klass* k) const;
478
479 // Find LCA in class hierarchy
480 Klass *LCA( Klass *k );
481
482 // Check whether reflection/jni/jvm code is allowed to instantiate this class;
483 // if not, throw either an Error or an Exception.
484 virtual void check_valid_for_instantiation(bool throwError, TRAPSJavaThread* __the_thread__);
485
486 // array copying
487 virtual void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPSJavaThread* __the_thread__);
488
489 // tells if the class should be initialized
490 virtual bool should_be_initialized() const { return false; }
491 // initializes the klass
492 virtual void initialize(TRAPSJavaThread* __the_thread__);
493 virtual Klass* find_field(Symbol* name, Symbol* signature, fieldDescriptor* fd) const;
494 virtual Method* uncached_lookup_method(const Symbol* name, const Symbol* signature,
495 OverpassLookupMode overpass_mode,
496 PrivateLookupMode = PrivateLookupMode::find) const;
497 public:
498 Method* lookup_method(const Symbol* name, const Symbol* signature) const {
499 return uncached_lookup_method(name, signature, OverpassLookupMode::find);
500 }
501
502 // array class with specific rank
503 virtual Klass* array_klass(int rank, TRAPSJavaThread* __the_thread__) = 0;
504
505 // array class with this klass as element type
506 virtual Klass* array_klass(TRAPSJavaThread* __the_thread__) = 0;
507
508 // These will return NULL instead of allocating on the heap:
509 virtual Klass* array_klass_or_null(int rank) = 0;
510 virtual Klass* array_klass_or_null() = 0;
511
512 virtual oop protection_domain() const = 0;
513
514 oop class_loader() const;
515
516 inline oop klass_holder() const;
517
518 protected:
519
520 // Error handling when length > max_length or length < 0
521 static void check_array_allocation_length(int length, int max_length, TRAPSJavaThread* __the_thread__);
522
523 void set_vtable_length(int len) { _vtable_len= len; }
524
525 vtableEntry* start_of_vtable() const;
526 void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPSJavaThread* __the_thread__);
527 public:
528 Method* method_at_vtable(int index);
529
530 static ByteSize vtable_start_offset();
531 static ByteSize vtable_length_offset() {
532 return byte_offset_of(Klass, _vtable_len)in_ByteSize((int)(size_t)((intx)&(((Klass*)16)->_vtable_len
) - 16))
;
533 }
534
535 // CDS support - remove and restore oops from metadata. Oops are not shared.
536 virtual void remove_unshareable_info();
537 virtual void remove_java_mirror();
538
539 bool is_unshareable_info_restored() const {
540 assert(is_shared(), "use this for shared classes only")do { if (!(is_shared())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 540, "assert(" "is_shared()" ") failed", "use this for shared classes only"
); ::breakpoint(); } } while (0)
;
541 if (has_archived_mirror_index()) {
542 // _java_mirror is not a valid OopHandle but rather an encoded reference in the shared heap
543 return false;
544 } else if (_java_mirror.ptr_raw() == NULL__null) {
545 return false;
546 } else {
547 return true;
548 }
549 }
550
551 public:
552 // ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP
553 // These functions describe behavior for the oop not the KLASS.
554
555 // actual oop size of obj in memory in word size.
556 virtual size_t oop_size(oop obj) const = 0;
557
558 // Size of klass in word size.
559 virtual int size() const = 0;
560
561 // Returns the Java name for a class (Resource allocated)
562 // For arrays, this returns the name of the element with a leading '['.
563 // For classes, this returns the name with the package separators
564 // turned into '.'s.
565 const char* external_name() const;
566 // Returns the name for a class (Resource allocated) as the class
567 // would appear in a signature.
568 // For arrays, this returns the name of the element with a leading '['.
569 // For classes, this returns the name with a leading 'L' and a trailing ';'
570 // and the package separators as '/'.
571 virtual const char* signature_name() const;
572
573 const char* joint_in_module_of_loader(const Klass* class2, bool include_parent_loader = false) const;
574 const char* class_in_module_of_loader(bool use_are = false, bool include_parent_loader = false) const;
575
576 // Returns "interface", "abstract class" or "class".
577 const char* external_kind() const;
578
579 // type testing operations
580#ifdef ASSERT1
581 protected:
582 virtual bool is_instance_klass_slow() const { return false; }
583 virtual bool is_array_klass_slow() const { return false; }
584 virtual bool is_objArray_klass_slow() const { return false; }
585 virtual bool is_typeArray_klass_slow() const { return false; }
586#endif // ASSERT
587 public:
588
589 // Fast non-virtual versions
590 #ifndef ASSERT1
591 #define assert_same_query(xval, xcheck) xval
592 #else
593 private:
594 static bool assert_same_query(bool xval, bool xslow) {
595 assert(xval == xslow, "slow and fast queries agree")do { if (!(xval == xslow)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/klass.hpp"
, 595, "assert(" "xval == xslow" ") failed", "slow and fast queries agree"
); ::breakpoint(); } } while (0)
;
596 return xval;
597 }
598 public:
599 #endif
600 inline bool is_instance_klass() const { return assert_same_query(
601 layout_helper_is_instance(layout_helper()),
602 is_instance_klass_slow()); }
603 inline bool is_array_klass() const { return assert_same_query(
604 layout_helper_is_array(layout_helper()),
605 is_array_klass_slow()); }
606 inline bool is_objArray_klass() const { return assert_same_query(
607 layout_helper_is_objArray(layout_helper()),
608 is_objArray_klass_slow()); }
609 inline bool is_typeArray_klass() const { return assert_same_query(
610 layout_helper_is_typeArray(layout_helper()),
611 is_typeArray_klass_slow()); }
612 #undef assert_same_query
613
614 // Access flags
615 AccessFlags access_flags() const { return _access_flags; }
616 void set_access_flags(AccessFlags flags) { _access_flags = flags; }
617
618 bool is_public() const { return _access_flags.is_public(); }
619 bool is_final() const { return _access_flags.is_final(); }
620 bool is_interface() const { return _access_flags.is_interface(); }
621 bool is_abstract() const { return _access_flags.is_abstract(); }
622 bool is_super() const { return _access_flags.is_super(); }
623 bool is_synthetic() const { return _access_flags.is_synthetic(); }
624 void set_is_synthetic() { _access_flags.set_is_synthetic(); }
625 bool has_finalizer() const { return _access_flags.has_finalizer(); }
626 bool has_final_method() const { return _access_flags.has_final_method(); }
627 void set_has_finalizer() { _access_flags.set_has_finalizer(); }
628 void set_has_final_method() { _access_flags.set_has_final_method(); }
629 bool has_vanilla_constructor() const { return _access_flags.has_vanilla_constructor(); }
630 void set_has_vanilla_constructor() { _access_flags.set_has_vanilla_constructor(); }
631 bool has_miranda_methods () const { return access_flags().has_miranda_methods(); }
632 void set_has_miranda_methods() { _access_flags.set_has_miranda_methods(); }
633 bool is_shared() const { return access_flags().is_shared_class(); } // shadows MetaspaceObj::is_shared)()
634 void set_is_shared() { _access_flags.set_is_shared_class(); }
635 bool is_hidden() const { return access_flags().is_hidden_class(); }
636 void set_is_hidden() { _access_flags.set_is_hidden_class(); }
637 bool is_value_based() { return _access_flags.is_value_based_class(); }
638 void set_is_value_based() { _access_flags.set_is_value_based_class(); }
639
640 inline bool is_non_strong_hidden() const;
641
642 bool is_cloneable() const;
643 void set_is_cloneable();
644
645 JFR_ONLY(DEFINE_TRACE_ID_METHODS;)traceid trace_id() const { return _trace_id; } traceid* const
trace_id_addr() const { return &_trace_id; } void set_trace_id
(traceid id) const { _trace_id = id; };
646
647 virtual void metaspace_pointers_do(MetaspaceClosure* iter);
648 virtual MetaspaceObj::Type type() const { return ClassType; }
649
650 inline bool is_loader_alive() const;
651
652 void clean_subklass();
653
654 static void clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses = true);
655 static void clean_subklass_tree() {
656 clean_weak_klass_links(/*unloading_occurred*/ true , /* clean_alive_klasses */ false);
657 }
658
659 // Return self, except for abstract classes with exactly 1
660 // implementor. Then return the 1 concrete implementation.
661 Klass *up_cast_abstract();
662
663 // klass name
664 Symbol* name() const { return _name; }
665 void set_name(Symbol* n);
666
667 virtual void release_C_heap_structures(bool release_constant_pool = true);
668
669 public:
670 virtual jint compute_modifier_flags() const = 0;
671
672 // JVMTI support
673 virtual jint jvmti_class_status() const;
674
675 // Printing
676 virtual void print_on(outputStream* st) const;
677
678 virtual void oop_print_value_on(oop obj, outputStream* st);
679 virtual void oop_print_on (oop obj, outputStream* st);
680
681 virtual const char* internal_name() const = 0;
682
683 // Verification
684 virtual void verify_on(outputStream* st);
685 void verify() { verify_on(tty); }
686
687#ifndef PRODUCT
688 bool verify_vtable_index(int index);
689#endif
690
691 virtual void oop_verify_on(oop obj, outputStream* st);
692
693 // for error reporting
694 static bool is_valid(Klass* k);
695};
696
697#endif // SHARE_OOPS_KLASS_HPP