Bug Summary

File:jdk/src/hotspot/share/classfile/systemDictionary.cpp
Warning:line 700, column 29
Value stored to 'newprobe' during its initialization is never read

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 systemDictionary.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/classfile/systemDictionary.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.h"
27#include "cds/heapShared.hpp"
28#include "classfile/classFileParser.hpp"
29#include "classfile/classFileStream.hpp"
30#include "classfile/classLoader.hpp"
31#include "classfile/classLoaderData.inline.hpp"
32#include "classfile/classLoaderDataGraph.inline.hpp"
33#include "classfile/classLoaderExt.hpp"
34#include "classfile/classLoadInfo.hpp"
35#include "classfile/dictionary.hpp"
36#include "classfile/javaClasses.inline.hpp"
37#include "classfile/klassFactory.hpp"
38#include "classfile/loaderConstraints.hpp"
39#include "classfile/packageEntry.hpp"
40#include "classfile/placeholders.hpp"
41#include "classfile/protectionDomainCache.hpp"
42#include "classfile/resolutionErrors.hpp"
43#include "classfile/stringTable.hpp"
44#include "classfile/symbolTable.hpp"
45#include "classfile/systemDictionary.hpp"
46#include "classfile/vmClasses.hpp"
47#include "classfile/vmSymbols.hpp"
48#include "code/codeCache.hpp"
49#include "gc/shared/gcTraceTime.inline.hpp"
50#include "interpreter/bootstrapInfo.hpp"
51#include "jfr/jfrEvents.hpp"
52#include "logging/log.hpp"
53#include "logging/logStream.hpp"
54#include "memory/metaspaceClosure.hpp"
55#include "memory/oopFactory.hpp"
56#include "memory/resourceArea.hpp"
57#include "memory/universe.hpp"
58#include "oops/access.inline.hpp"
59#include "oops/instanceKlass.hpp"
60#include "oops/klass.inline.hpp"
61#include "oops/method.inline.hpp"
62#include "oops/objArrayKlass.hpp"
63#include "oops/objArrayOop.inline.hpp"
64#include "oops/oop.inline.hpp"
65#include "oops/oopHandle.inline.hpp"
66#include "oops/symbol.hpp"
67#include "oops/typeArrayKlass.hpp"
68#include "prims/jvmtiExport.hpp"
69#include "prims/methodHandles.hpp"
70#include "runtime/arguments.hpp"
71#include "runtime/handles.inline.hpp"
72#include "runtime/java.hpp"
73#include "runtime/javaCalls.hpp"
74#include "runtime/mutexLocker.hpp"
75#include "runtime/sharedRuntime.hpp"
76#include "runtime/signature.hpp"
77#include "services/classLoadingService.hpp"
78#include "services/diagnosticCommand.hpp"
79#include "services/finalizerService.hpp"
80#include "services/threadService.hpp"
81#include "utilities/macros.hpp"
82#include "utilities/utf8.hpp"
83#if INCLUDE_CDS1
84#include "classfile/systemDictionaryShared.hpp"
85#endif
86#if INCLUDE_JFR1
87#include "jfr/jfr.hpp"
88#endif
89
90ResolutionErrorTable* SystemDictionary::_resolution_errors = NULL__null;
91SymbolPropertyTable* SystemDictionary::_invoke_method_table = NULL__null;
92ProtectionDomainCacheTable* SystemDictionary::_pd_cache_table = NULL__null;
93
94OopHandle SystemDictionary::_java_system_loader;
95OopHandle SystemDictionary::_java_platform_loader;
96
97// Default ProtectionDomainCacheSize value
98const int defaultProtectionDomainCacheSize = 1009;
99
100const int _resolution_error_size = 107; // number of entries in resolution error table
101const int _invoke_method_size = 139; // number of entries in invoke method table
102
103// Hashtable holding placeholders for classes being loaded.
104const int _placeholder_table_size = 1009;
105static PlaceholderTable* _placeholders = NULL__null;
106static PlaceholderTable* placeholders() { return _placeholders; }
107
108// Constraints on class loaders
109const int _loader_constraint_size = 107; // number of entries in constraint table
110static LoaderConstraintTable* _loader_constraints;
111static LoaderConstraintTable* constraints() { return _loader_constraints; }
112
113// ----------------------------------------------------------------------------
114// Java-level SystemLoader and PlatformLoader
115oop SystemDictionary::java_system_loader() {
116 return _java_system_loader.resolve();
117}
118
119oop SystemDictionary::java_platform_loader() {
120 return _java_platform_loader.resolve();
121}
122
123void SystemDictionary::compute_java_loaders(TRAPSJavaThread* __the_thread__) {
124 JavaValue result(T_OBJECT);
125 InstanceKlass* class_loader_klass = vmClasses::ClassLoader_klass();
126 JavaCalls::call_static(&result,
127 class_loader_klass,
128 vmSymbols::getSystemClassLoader_name(),
129 vmSymbols::void_classloader_signature(),
130 CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0
);
131
132 _java_system_loader = OopHandle(Universe::vm_global(), result.get_oop());
133
134 JavaCalls::call_static(&result,
135 class_loader_klass,
136 vmSymbols::getPlatformClassLoader_name(),
137 vmSymbols::void_classloader_signature(),
138 CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0
);
139
140 _java_platform_loader = OopHandle(Universe::vm_global(), result.get_oop());
141}
142
143ClassLoaderData* SystemDictionary::register_loader(Handle class_loader, bool create_mirror_cld) {
144 if (create_mirror_cld) {
145 // Add a new class loader data to the graph.
146 return ClassLoaderDataGraph::add(class_loader, true);
147 } else {
148 return (class_loader() == NULL__null) ? ClassLoaderData::the_null_class_loader_data() :
149 ClassLoaderDataGraph::find_or_create(class_loader);
150 }
151}
152
153// ----------------------------------------------------------------------------
154// Parallel class loading check
155
156bool is_parallelCapable(Handle class_loader) {
157 if (class_loader.is_null()) return true;
158 return java_lang_ClassLoader::parallelCapable(class_loader());
159}
160// ----------------------------------------------------------------------------
161// ParallelDefineClass flag does not apply to bootclass loader
162bool is_parallelDefine(Handle class_loader) {
163 if (class_loader.is_null()) return false;
164 if (AllowParallelDefineClass && java_lang_ClassLoader::parallelCapable(class_loader())) {
165 return true;
166 }
167 return false;
168}
169
170// Returns true if the passed class loader is the builtin application class loader
171// or a custom system class loader. A customer system class loader can be
172// specified via -Djava.system.class.loader.
173bool SystemDictionary::is_system_class_loader(oop class_loader) {
174 if (class_loader == NULL__null) {
175 return false;
176 }
177 return (class_loader->klass() == vmClasses::jdk_internal_loader_ClassLoaders_AppClassLoader_klass() ||
178 class_loader == _java_system_loader.peek());
179}
180
181// Returns true if the passed class loader is the platform class loader.
182bool SystemDictionary::is_platform_class_loader(oop class_loader) {
183 if (class_loader == NULL__null) {
184 return false;
185 }
186 return (class_loader->klass() == vmClasses::jdk_internal_loader_ClassLoaders_PlatformClassLoader_klass());
187}
188
189Handle SystemDictionary::get_loader_lock_or_null(Handle class_loader) {
190 // If class_loader is NULL or parallelCapable, the JVM doesn't acquire a lock while loading.
191 if (is_parallelCapable(class_loader)) {
192 return Handle();
193 } else {
194 return class_loader;
195 }
196}
197
198// ----------------------------------------------------------------------------
199// Resolving of classes
200
201Symbol* SystemDictionary::class_name_symbol(const char* name, Symbol* exception, TRAPSJavaThread* __the_thread__) {
202 if (name == NULL__null) {
203 THROW_MSG_0(exception, "No class name given"){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 203, exception, "No class name given"); return 0; }
;
204 }
205 if ((int)strlen(name) > Symbol::max_length()) {
206 // It's impossible to create this class; the name cannot fit
207 // into the constant pool.
208 Exceptions::fthrow(THREAD_AND_LOCATION__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 208
, exception,
209 "Class name exceeds maximum length of %d: %s",
210 Symbol::max_length(),
211 name);
212 return NULL__null;
213 }
214 // Callers should ensure that the name is never an illegal UTF8 string.
215 assert(UTF8::is_legal_utf8((const unsigned char*)name, (int)strlen(name), false),do { if (!(UTF8::is_legal_utf8((const unsigned char*)name, (int
)strlen(name), false))) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 216, "assert(" "UTF8::is_legal_utf8((const unsigned char*)name, (int)strlen(name), false)"
") failed", "Class name is not a valid utf8 string."); ::breakpoint
(); } } while (0)
216 "Class name is not a valid utf8 string.")do { if (!(UTF8::is_legal_utf8((const unsigned char*)name, (int
)strlen(name), false))) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 216, "assert(" "UTF8::is_legal_utf8((const unsigned char*)name, (int)strlen(name), false)"
") failed", "Class name is not a valid utf8 string."); ::breakpoint
(); } } while (0)
;
217
218 // Make a new symbol for the class name.
219 return SymbolTable::new_symbol(name);
220}
221
222#ifdef ASSERT1
223// Used to verify that class loading succeeded in adding k to the dictionary.
224void verify_dictionary_entry(Symbol* class_name, InstanceKlass* k) {
225 MutexLocker mu(SystemDictionary_lock);
226 ClassLoaderData* loader_data = k->class_loader_data();
227 Dictionary* dictionary = loader_data->dictionary();
228 assert(class_name == k->name(), "Must be the same")do { if (!(class_name == k->name())) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 228, "assert(" "class_name == k->name()" ") failed", "Must be the same"
); ::breakpoint(); } } while (0)
;
229 unsigned int name_hash = dictionary->compute_hash(class_name);
230 InstanceKlass* kk = dictionary->find_class(name_hash, class_name);
231 assert(kk == k, "should be present in dictionary")do { if (!(kk == k)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 231, "assert(" "kk == k" ") failed", "should be present in dictionary"
); ::breakpoint(); } } while (0)
;
232}
233#endif
234
235static void handle_resolution_exception(Symbol* class_name, bool throw_error, TRAPSJavaThread* __the_thread__) {
236 if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) {
237 // If we have a pending exception we forward it to the caller, unless throw_error is true,
238 // in which case we have to check whether the pending exception is a ClassNotFoundException,
239 // and convert it to a NoClassDefFoundError and chain the original ClassNotFoundException.
240 if (throw_error && PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->pending_exception())->is_a(vmClasses::ClassNotFoundException_klass())) {
241 ResourceMark rm(THREAD__the_thread__);
242 Handle e(THREAD__the_thread__, PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->pending_exception()));
243 CLEAR_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->clear_pending_exception(
))
;
244 THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e){ Exceptions::_throw_msg_cause(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 244, vmSymbols::java_lang_NoClassDefFoundError(), class_name
->as_C_string(), e); return; }
;
245 } else {
246 return; // the caller will throw the incoming exception
247 }
248 }
249 // If the class is not found, ie, caller has checked that klass is NULL, throw the appropriate
250 // error or exception depending on the value of throw_error.
251 ResourceMark rm(THREAD__the_thread__);
252 if (throw_error) {
253 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string()){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 253, vmSymbols::java_lang_NoClassDefFoundError(), class_name
->as_C_string()); return; }
;
254 } else {
255 THROW_MSG(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string()){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 255, vmSymbols::java_lang_ClassNotFoundException(), class_name
->as_C_string()); return; }
;
256 }
257}
258
259// Forwards to resolve_or_null
260
261Klass* SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain,
262 bool throw_error, TRAPSJavaThread* __the_thread__) {
263 Klass* klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD__the_thread__);
264 // Check for pending exception or null klass, and throw exception
265 if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception()) || klass == NULL__null) {
266 handle_resolution_exception(class_name, throw_error, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
267 }
268 return klass;
269}
270
271// Forwards to resolve_array_class_or_null or resolve_instance_class_or_null
272
273Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPSJavaThread* __the_thread__) {
274 if (Signature::is_array(class_name)) {
275 return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD__the_thread__);
276 } else {
277 return resolve_instance_class_or_null_helper(class_name, class_loader, protection_domain, THREAD__the_thread__);
278 }
279}
280
281// name may be in the form of "java/lang/Object" or "Ljava/lang/Object;"
282InstanceKlass* SystemDictionary::resolve_instance_class_or_null_helper(Symbol* class_name,
283 Handle class_loader,
284 Handle protection_domain,
285 TRAPSJavaThread* __the_thread__) {
286 assert(class_name != NULL && !Signature::is_array(class_name), "must be")do { if (!(class_name != __null && !Signature::is_array
(class_name))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 286, "assert(" "class_name != __null && !Signature::is_array(class_name)"
") failed", "must be"); ::breakpoint(); } } while (0)
;
287 if (Signature::has_envelope(class_name)) {
288 ResourceMark rm(THREAD__the_thread__);
289 // Ignore wrapping L and ;.
290 TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
291 class_name->utf8_length() - 2);
292 return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD__the_thread__);
293 } else {
294 return resolve_instance_class_or_null(class_name, class_loader, protection_domain, THREAD__the_thread__);
295 }
296}
297
298// Forwards to resolve_instance_class_or_null
299
300Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
301 Handle class_loader,
302 Handle protection_domain,
303 TRAPSJavaThread* __the_thread__) {
304 assert(Signature::is_array(class_name), "must be array")do { if (!(Signature::is_array(class_name))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 304, "assert(" "Signature::is_array(class_name)" ") failed"
, "must be array"); ::breakpoint(); } } while (0)
;
305 ResourceMark rm(THREAD__the_thread__);
306 SignatureStream ss(class_name, false);
307 int ndims = ss.skip_array_prefix(); // skip all '['s
308 Klass* k = NULL__null;
309 BasicType t = ss.type();
310 if (ss.has_envelope()) {
311 Symbol* obj_class = ss.as_symbol();
312 k = SystemDictionary::resolve_instance_class_or_null(obj_class,
313 class_loader,
314 protection_domain,
315 CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
316 if (k != NULL__null) {
317 k = k->array_klass(ndims, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
318 }
319 } else {
320 k = Universe::typeArrayKlassObj(t);
321 k = TypeArrayKlass::cast(k)->array_klass(ndims, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
322 }
323 return k;
324}
325
326static inline void log_circularity_error(Thread* thread, PlaceholderEntry* probe) {
327 LogTarget(Debug, class, load, placeholders)LogTargetImpl<LogLevel::Debug, (LogTag::_class), (LogTag::
_load), (LogTag::_placeholders), (LogTag::__NO_TAG), (LogTag::
__NO_TAG), (LogTag::__NO_TAG)>
lt;
328 if (lt.is_enabled()) {
329 ResourceMark rm(thread);
330 LogStream ls(lt);
331 ls.print("ClassCircularityError detected for placeholder ");
332 probe->print_entry(&ls);
333 ls.cr();
334 }
335}
336
337// Must be called for any superclass or superinterface resolution
338// during class definition to allow class circularity checking
339// superinterface callers:
340// parse_interfaces - from defineClass
341// superclass callers:
342// ClassFileParser - from defineClass
343// load_shared_class - while loading a class from shared archive
344// resolve_instance_class_or_null:
345// via: handle_parallel_super_load
346// when resolving a class that has an existing placeholder with
347// a saved superclass [i.e. a defineClass is currently in progress]
348// If another thread is trying to resolve the class, it must do
349// superclass checks on its own thread to catch class circularity and
350// to avoid deadlock.
351//
352// resolve_super_or_fail adds a LOAD_SUPER placeholder to the placeholder table before calling
353// resolve_instance_class_or_null. ClassCircularityError is detected when a LOAD_SUPER or LOAD_INSTANCE
354// placeholder for the same thread, class, classloader is found.
355// This can be seen with logging option: -Xlog:class+load+placeholders=debug.
356//
357InstanceKlass* SystemDictionary::resolve_super_or_fail(Symbol* class_name,
358 Symbol* super_name,
359 Handle class_loader,
360 Handle protection_domain,
361 bool is_superclass,
362 TRAPSJavaThread* __the_thread__) {
363
364 assert(super_name != NULL, "null superclass for resolving")do { if (!(super_name != __null)) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 364, "assert(" "super_name != __null" ") failed", "null superclass for resolving"
); ::breakpoint(); } } while (0)
;
365 assert(!Signature::is_array(super_name), "invalid superclass name")do { if (!(!Signature::is_array(super_name))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 365, "assert(" "!Signature::is_array(super_name)" ") failed"
, "invalid superclass name"); ::breakpoint(); } } while (0)
;
366#if INCLUDE_CDS1
367 if (DumpSharedSpaces) {
368 // Special processing for handling UNREGISTERED shared classes.
369 InstanceKlass* k = SystemDictionaryShared::lookup_super_for_unregistered_class(class_name,
370 super_name, is_superclass);
371 if (k) {
372 return k;
373 }
374 }
375#endif // INCLUDE_CDS
376
377 // If klass is already loaded, just return the superclass or superinterface.
378 // Make sure there's a placeholder for the class_name before resolving.
379 // This is used as a claim that this thread is currently loading superclass/classloader
380 // and for ClassCircularity checks.
381
382 ClassLoaderData* loader_data = class_loader_data(class_loader);
383 Dictionary* dictionary = loader_data->dictionary();
384 unsigned int name_hash = dictionary->compute_hash(class_name);
385 assert(placeholders()->compute_hash(class_name) == name_hash, "they're the same hashcode")do { if (!(placeholders()->compute_hash(class_name) == name_hash
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 385, "assert(" "placeholders()->compute_hash(class_name) == name_hash"
") failed", "they're the same hashcode"); ::breakpoint(); } }
while (0)
;
386
387 // can't throw error holding a lock
388 bool throw_circularity_error = false;
389 {
390 MutexLocker mu(THREAD__the_thread__, SystemDictionary_lock);
391 InstanceKlass* klassk = dictionary->find_class(name_hash, class_name);
392 InstanceKlass* quicksuperk;
393 // To support parallel loading: if class is done loading, just return the superclass
394 // if the super_name matches class->super()->name() and if the class loaders match.
395 // Otherwise, a LinkageError will be thrown later.
396 if (klassk != NULL__null && is_superclass &&
397 ((quicksuperk = klassk->java_super()) != NULL__null) &&
398 ((quicksuperk->name() == super_name) &&
399 (quicksuperk->class_loader() == class_loader()))) {
400 return quicksuperk;
401 } else {
402 // Must check ClassCircularity before checking if superclass is already loaded.
403 PlaceholderEntry* probe = placeholders()->get_entry(name_hash, class_name, loader_data);
404 if (probe && probe->check_seen_thread(THREAD__the_thread__, PlaceholderTable::LOAD_SUPER)) {
405 log_circularity_error(THREAD__the_thread__, probe);
406 throw_circularity_error = true;
407 }
408 }
409
410 if (!throw_circularity_error) {
411 // Be careful not to exit resolve_super without removing this placeholder.
412 PlaceholderEntry* newprobe = placeholders()->find_and_add(name_hash,
413 class_name,
414 loader_data,
415 PlaceholderTable::LOAD_SUPER,
416 super_name, THREAD__the_thread__);
417 }
418 }
419
420 if (throw_circularity_error) {
421 ResourceMark rm(THREAD__the_thread__);
422 THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), class_name->as_C_string()){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 422, vmSymbols::java_lang_ClassCircularityError(), class_name
->as_C_string()); return __null; }
;
423 }
424
425 // Resolve the superclass or superinterface, check results on return
426 InstanceKlass* superk =
427 SystemDictionary::resolve_instance_class_or_null_helper(super_name,
428 class_loader,
429 protection_domain,
430 THREAD__the_thread__);
431
432 // Clean up placeholder entry.
433 {
434 MutexLocker mu(THREAD__the_thread__, SystemDictionary_lock);
435 placeholders()->find_and_remove(name_hash, class_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD__the_thread__);
436 SystemDictionary_lock->notify_all();
437 }
438
439 // Check for pending exception or null superk, and throw exception
440 if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception()) || superk == NULL__null) {
441 handle_resolution_exception(super_name, true, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
442 }
443
444 return superk;
445}
446
447// We only get here if this thread finds that another thread
448// has already claimed the placeholder token for the current operation,
449// but that other thread either never owned or gave up the
450// object lock
451// Waits on SystemDictionary_lock to indicate placeholder table updated
452// On return, caller must recheck placeholder table state
453//
454// We only get here if
455// 1) custom classLoader, i.e. not bootstrap classloader
456// 2) custom classLoader has broken the class loader objectLock
457// so another thread got here in parallel
458//
459// lockObject must be held.
460// Complicated dance due to lock ordering:
461// Must first release the classloader object lock to
462// allow initial definer to complete the class definition
463// and to avoid deadlock
464// Reclaim classloader lock object with same original recursion count
465// Must release SystemDictionary_lock after notify, since
466// class loader lock must be claimed before SystemDictionary_lock
467// to prevent deadlocks
468//
469// The notify allows applications that did an untimed wait() on
470// the classloader object lock to not hang.
471static void double_lock_wait(JavaThread* thread, Handle lockObject) {
472 assert_lock_strong(SystemDictionary_lock);
473
474 assert(lockObject() != NULL, "lockObject must be non-NULL")do { if (!(lockObject() != __null)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 474, "assert(" "lockObject() != __null" ") failed", "lockObject must be non-NULL"
); ::breakpoint(); } } while (0)
;
475 bool calledholdinglock
476 = ObjectSynchronizer::current_thread_holds_lock(thread, lockObject);
477 assert(calledholdinglock, "must hold lock for notify")do { if (!(calledholdinglock)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 477, "assert(" "calledholdinglock" ") failed", "must hold lock for notify"
); ::breakpoint(); } } while (0)
;
478 assert(!is_parallelCapable(lockObject), "lockObject must not be parallelCapable")do { if (!(!is_parallelCapable(lockObject))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 478, "assert(" "!is_parallelCapable(lockObject)" ") failed"
, "lockObject must not be parallelCapable"); ::breakpoint(); }
} while (0)
;
479 // These don't throw exceptions.
480 ObjectSynchronizer::notifyall(lockObject, thread);
481 intx recursions = ObjectSynchronizer::complete_exit(lockObject, thread);
482 SystemDictionary_lock->wait();
483 SystemDictionary_lock->unlock();
484 ObjectSynchronizer::reenter(lockObject, recursions, thread);
485 SystemDictionary_lock->lock();
486}
487
488// If the class in is in the placeholder table, class loading is in progress.
489// For cases where the application changes threads to load classes, it
490// is critical to ClassCircularity detection that we try loading
491// the superclass on the new thread internally, so we do parallel
492// superclass loading here. This avoids deadlock for ClassCircularity
493// detection for parallelCapable class loaders that lock on a per-class lock.
494static void handle_parallel_super_load(Symbol* name,
495 Symbol* superclassname,
496 Handle class_loader,
497 Handle protection_domain, TRAPSJavaThread* __the_thread__) {
498
499 // superk is not used; resolve_super_or_fail is called for circularity check only.
500 Klass* superk = SystemDictionary::resolve_super_or_fail(name,
501 superclassname,
502 class_loader,
503 protection_domain,
504 true,
505 CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0
);
506}
507
508// parallelCapable class loaders do NOT wait for parallel superclass loads to complete
509// Serial class loaders and bootstrap classloader do wait for superclass loads
510static bool should_wait_for_loading(Handle class_loader) {
511 return class_loader.is_null() || !is_parallelCapable(class_loader);
512}
513
514// For bootstrap and non-parallelCapable class loaders, check and wait for
515// another thread to complete loading this class.
516InstanceKlass* SystemDictionary::handle_parallel_loading(JavaThread* current,
517 unsigned int name_hash,
518 Symbol* name,
519 ClassLoaderData* loader_data,
520 Handle lockObject,
521 bool* throw_circularity_error) {
522 PlaceholderEntry* oldprobe = placeholders()->get_entry(name_hash, name, loader_data);
523 if (oldprobe != NULL__null) {
524 // only need check_seen_thread once, not on each loop
525 // 6341374 java/lang/Instrument with -Xcomp
526 if (oldprobe->check_seen_thread(current, PlaceholderTable::LOAD_INSTANCE)) {
527 log_circularity_error(current, oldprobe);
528 *throw_circularity_error = true;
529 return NULL__null;
530 } else {
531 // Wait until the first thread has finished loading this class. Also wait until all the
532 // threads trying to load its superclass have removed their placeholders.
533 while (oldprobe != NULL__null &&
534 (oldprobe->instance_load_in_progress() || oldprobe->super_load_in_progress())) {
535
536 // We only get here if the application has released the
537 // classloader lock when another thread was in the middle of loading a
538 // superclass/superinterface for this class, and now
539 // this thread is also trying to load this class.
540 // To minimize surprises, the first thread that started to
541 // load a class should be the one to complete the loading
542 // with the classfile it initially expected.
543 // This logic has the current thread wait once it has done
544 // all the superclass/superinterface loading it can, until
545 // the original thread completes the class loading or fails
546 // If it completes we will use the resulting InstanceKlass
547 // which we will find below in the systemDictionary.
548 oldprobe = NULL__null; // Other thread could delete this placeholder entry
549
550 if (lockObject.is_null()) {
551 SystemDictionary_lock->wait();
552 } else {
553 double_lock_wait(current, lockObject);
554 }
555
556 // Check if classloading completed while we were waiting
557 InstanceKlass* check = loader_data->dictionary()->find_class(name_hash, name);
558 if (check != NULL__null) {
559 // Klass is already loaded, so just return it
560 return check;
561 }
562 // check if other thread failed to load and cleaned up
563 oldprobe = placeholders()->get_entry(name_hash, name, loader_data);
564 }
565 }
566 }
567 return NULL__null;
568}
569
570void SystemDictionary::post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld) {
571 assert(event != NULL, "invariant")do { if (!(event != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 571, "assert(" "event != __null" ") failed", "invariant"); ::
breakpoint(); } } while (0)
;
572 assert(k != NULL, "invariant")do { if (!(k != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 572, "assert(" "k != __null" ") failed", "invariant"); ::breakpoint
(); } } while (0)
;
573 assert(event->should_commit(), "invariant")do { if (!(event->should_commit())) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 573, "assert(" "event->should_commit()" ") failed", "invariant"
); ::breakpoint(); } } while (0)
;
574 event->set_loadedClass(k);
575 event->set_definingClassLoader(k->class_loader_data());
576 event->set_initiatingClassLoader(init_cld);
577 event->commit();
578}
579
580// SystemDictionary::resolve_instance_class_or_null is the main function for class name resolution.
581// After checking if the InstanceKlass already exists, it checks for ClassCircularityError and
582// whether the thread must wait for loading in parallel. It eventually calls load_instance_class,
583// which will load the class via the bootstrap loader or call ClassLoader.loadClass().
584// This can return NULL, an exception or an InstanceKlass.
585InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
586 Handle class_loader,
587 Handle protection_domain,
588 TRAPSJavaThread* __the_thread__) {
589 // name must be in the form of "java/lang/Object" -- cannot be "Ljava/lang/Object;"
590 assert(name != NULL && !Signature::is_array(name) &&do { if (!(name != __null && !Signature::is_array(name
) && !Signature::has_envelope(name))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 591, "assert(" "name != __null && !Signature::is_array(name) && !Signature::has_envelope(name)"
") failed", "invalid class name"); ::breakpoint(); } } while
(0)
591 !Signature::has_envelope(name), "invalid class name")do { if (!(name != __null && !Signature::is_array(name
) && !Signature::has_envelope(name))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 591, "assert(" "name != __null && !Signature::is_array(name) && !Signature::has_envelope(name)"
") failed", "invalid class name"); ::breakpoint(); } } while
(0)
;
592
593 EventClassLoad class_load_start_event;
594
595 HandleMark hm(THREAD__the_thread__);
596
597 // Fix for 4474172; see evaluation for more details
598 class_loader = Handle(THREAD__the_thread__, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
599 ClassLoaderData* loader_data = register_loader(class_loader);
600 Dictionary* dictionary = loader_data->dictionary();
601 unsigned int name_hash = dictionary->compute_hash(name);
602
603 // Do lookup to see if class already exists and the protection domain
604 // has the right access.
605 // This call uses find which checks protection domain already matches
606 // All subsequent calls use find_class, and set loaded_class so that
607 // before we return a result, we call out to java to check for valid protection domain.
608 InstanceKlass* probe = dictionary->find(name_hash, name, protection_domain);
609 if (probe != NULL__null) return probe;
610
611 // Non-bootstrap class loaders will call out to class loader and
612 // define via jvm/jni_DefineClass which will acquire the
613 // class loader object lock to protect against multiple threads
614 // defining the class in parallel by accident.
615 // This lock must be acquired here so the waiter will find
616 // any successful result in the SystemDictionary and not attempt
617 // the define.
618 // ParallelCapable class loaders and the bootstrap classloader
619 // do not acquire lock here.
620 Handle lockObject = get_loader_lock_or_null(class_loader);
621 ObjectLocker ol(lockObject, THREAD__the_thread__);
622
623 bool super_load_in_progress = false;
624 InstanceKlass* loaded_class = NULL__null;
625 Symbol* superclassname = NULL__null;
626
627 assert(THREAD->can_call_java(),do { if (!(__the_thread__->can_call_java())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 630, "assert(" "__the_thread__->can_call_java()" ") failed"
, "can not load classes with compiler thread: class=%s, classloader=%s"
, name->as_C_string(), class_loader.is_null() ? "null" : class_loader
->klass()->name()->as_C_string()); ::breakpoint(); }
} while (0)
628 "can not load classes with compiler thread: class=%s, classloader=%s",do { if (!(__the_thread__->can_call_java())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 630, "assert(" "__the_thread__->can_call_java()" ") failed"
, "can not load classes with compiler thread: class=%s, classloader=%s"
, name->as_C_string(), class_loader.is_null() ? "null" : class_loader
->klass()->name()->as_C_string()); ::breakpoint(); }
} while (0)
629 name->as_C_string(),do { if (!(__the_thread__->can_call_java())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 630, "assert(" "__the_thread__->can_call_java()" ") failed"
, "can not load classes with compiler thread: class=%s, classloader=%s"
, name->as_C_string(), class_loader.is_null() ? "null" : class_loader
->klass()->name()->as_C_string()); ::breakpoint(); }
} while (0)
630 class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string())do { if (!(__the_thread__->can_call_java())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 630, "assert(" "__the_thread__->can_call_java()" ") failed"
, "can not load classes with compiler thread: class=%s, classloader=%s"
, name->as_C_string(), class_loader.is_null() ? "null" : class_loader
->klass()->name()->as_C_string()); ::breakpoint(); }
} while (0)
;
631
632 assert(placeholders()->compute_hash(name) == name_hash, "they're the same hashcode")do { if (!(placeholders()->compute_hash(name) == name_hash
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 632, "assert(" "placeholders()->compute_hash(name) == name_hash"
") failed", "they're the same hashcode"); ::breakpoint(); } }
while (0)
;
633
634 // Check again (after locking) if the class already exists in SystemDictionary
635 {
636 MutexLocker mu(THREAD__the_thread__, SystemDictionary_lock);
637 InstanceKlass* check = dictionary->find_class(name_hash, name);
638 if (check != NULL__null) {
639 // InstanceKlass is already loaded, but we still need to check protection domain below.
640 loaded_class = check;
641 } else {
642 PlaceholderEntry* placeholder = placeholders()->get_entry(name_hash, name, loader_data);
643 if (placeholder != NULL__null && placeholder->super_load_in_progress()) {
644 super_load_in_progress = true;
645 superclassname = placeholder->supername();
646 assert(superclassname != NULL, "superclass has to have a name")do { if (!(superclassname != __null)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 646, "assert(" "superclassname != __null" ") failed", "superclass has to have a name"
); ::breakpoint(); } } while (0)
;
647 }
648 }
649 }
650
651 // If the class is in the placeholder table with super_class set,
652 // handle superclass loading in progress.
653 if (super_load_in_progress) {
654 handle_parallel_super_load(name, superclassname,
655 class_loader,
656 protection_domain,
657 CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
658 }
659
660 bool throw_circularity_error = false;
661 if (loaded_class == NULL__null) {
662 bool load_placeholder_added = false;
663
664 // Add placeholder entry to record loading instance class
665 // Four cases:
666 // case 1. Bootstrap classloader
667 // This classloader supports parallelism at the classloader level
668 // but only allows a single thread to load a class/classloader pair.
669 // The LOAD_INSTANCE placeholder is the mechanism for mutual exclusion.
670 // case 2. parallelCapable user level classloaders
671 // These class loaders lock a per-class object lock when ClassLoader.loadClass()
672 // is called. A LOAD_INSTANCE placeholder isn't used for mutual exclusion.
673 // case 3. traditional classloaders that rely on the classloader object lock
674 // There should be no need for need for LOAD_INSTANCE, except:
675 // case 4. traditional class loaders that break the classloader object lock
676 // as a legacy deadlock workaround. Detection of this case requires that
677 // this check is done while holding the classloader object lock,
678 // and that lock is still held when calling classloader's loadClass.
679 // For these classloaders, we ensure that the first requestor
680 // completes the load and other requestors wait for completion.
681 {
682 MutexLocker mu(THREAD__the_thread__, SystemDictionary_lock);
683 if (should_wait_for_loading(class_loader)) {
684 loaded_class = handle_parallel_loading(THREAD__the_thread__,
685 name_hash,
686 name,
687 loader_data,
688 lockObject,
689 &throw_circularity_error);
690 }
691
692 // Recheck if the class has been loaded for all class loader cases and
693 // add a LOAD_INSTANCE placeholder while holding the SystemDictionary_lock.
694 if (!throw_circularity_error && loaded_class == NULL__null) {
695 InstanceKlass* check = dictionary->find_class(name_hash, name);
696 if (check != NULL__null) {
697 loaded_class = check;
698 } else if (should_wait_for_loading(class_loader)) {
699 // Add the LOAD_INSTANCE token. Threads will wait on loading to complete for this thread.
700 PlaceholderEntry* newprobe = placeholders()->find_and_add(name_hash, name, loader_data,
Value stored to 'newprobe' during its initialization is never read
701 PlaceholderTable::LOAD_INSTANCE,
702 NULL__null,
703 THREAD__the_thread__);
704 load_placeholder_added = true;
705 }
706 }
707 }
708
709 // Must throw error outside of owning lock
710 if (throw_circularity_error) {
711 assert(!HAS_PENDING_EXCEPTION && !load_placeholder_added, "circularity error cleanup")do { if (!(!(((ThreadShadow*)__the_thread__)->has_pending_exception
()) && !load_placeholder_added)) { (*g_assert_poison)
= 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 711, "assert(" "!(((ThreadShadow*)__the_thread__)->has_pending_exception()) && !load_placeholder_added"
") failed", "circularity error cleanup"); ::breakpoint(); } }
while (0)
;
712 ResourceMark rm(THREAD__the_thread__);
713 THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), name->as_C_string()){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 713, vmSymbols::java_lang_ClassCircularityError(), name->
as_C_string()); return __null; }
;
714 }
715
716 // Be careful when modifying this code: once you have run
717 // placeholders()->find_and_add(PlaceholderTable::LOAD_INSTANCE),
718 // you need to find_and_remove it before returning.
719 // So be careful to not exit with a CHECK_ macro between these calls.
720
721 if (loaded_class == NULL__null) {
722 // Do actual loading
723 loaded_class = load_instance_class(name_hash, name, class_loader, THREAD__the_thread__);
724 }
725
726 if (load_placeholder_added) {
727 // clean up placeholder entries for LOAD_INSTANCE success or error
728 // This brackets the SystemDictionary updates for both defining
729 // and initiating loaders
730 MutexLocker mu(THREAD__the_thread__, SystemDictionary_lock);
731 placeholders()->find_and_remove(name_hash, name, loader_data, PlaceholderTable::LOAD_INSTANCE, THREAD__the_thread__);
732 SystemDictionary_lock->notify_all();
733 }
734 }
735
736 if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception()) || loaded_class == NULL__null) {
737 return NULL__null;
738 }
739
740 if (class_load_start_event.should_commit()) {
741 post_class_load_event(&class_load_start_event, loaded_class, loader_data);
742 }
743
744 // Make sure we have the right class in the dictionary
745 DEBUG_ONLY(verify_dictionary_entry(name, loaded_class))verify_dictionary_entry(name, loaded_class);
746
747 // Check if the protection domain is present it has the right access
748 if (protection_domain() != NULL__null) {
749 // Verify protection domain. If it fails an exception is thrown
750 dictionary->validate_protection_domain(name_hash, loaded_class, class_loader, protection_domain, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
751 }
752
753 return loaded_class;
754}
755
756
757// This routine does not lock the system dictionary.
758//
759// Since readers don't hold a lock, we must make sure that system
760// dictionary entries are added to in a safe way (all links must
761// be updated in an MT-safe manner). All entries are removed during class
762// unloading, when this class loader is no longer referenced.
763//
764// Callers should be aware that an entry could be added just after
765// _dictionary->bucket(index) is read here, so the caller will not see
766// the new entry.
767
768InstanceKlass* SystemDictionary::find_instance_klass(Symbol* class_name,
769 Handle class_loader,
770 Handle protection_domain) {
771
772 // The result of this call should be consistent with the result
773 // of the call to resolve_instance_class_or_null().
774 // See evaluation 6790209 and 4474172 for more details.
775 oop class_loader_oop = java_lang_ClassLoader::non_reflection_class_loader(class_loader());
776 ClassLoaderData* loader_data = ClassLoaderData::class_loader_data_or_null(class_loader_oop);
777
778 if (loader_data == NULL__null) {
779 // If the ClassLoaderData has not been setup,
780 // then the class loader has no entries in the dictionary.
781 return NULL__null;
782 }
783
784 Dictionary* dictionary = loader_data->dictionary();
785 unsigned int name_hash = dictionary->compute_hash(class_name);
786 return dictionary->find(name_hash, class_name, protection_domain);
787}
788
789// Look for a loaded instance or array klass by name. Do not do any loading.
790// return NULL in case of error.
791Klass* SystemDictionary::find_instance_or_array_klass(Symbol* class_name,
792 Handle class_loader,
793 Handle protection_domain) {
794 Klass* k = NULL__null;
795 assert(class_name != NULL, "class name must be non NULL")do { if (!(class_name != __null)) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 795, "assert(" "class_name != __null" ") failed", "class name must be non NULL"
); ::breakpoint(); } } while (0)
;
796
797 if (Signature::is_array(class_name)) {
798 // The name refers to an array. Parse the name.
799 // dimension and object_key in FieldArrayInfo are assigned as a
800 // side-effect of this call
801 SignatureStream ss(class_name, false);
802 int ndims = ss.skip_array_prefix(); // skip all '['s
803 BasicType t = ss.type();
804 if (t != T_OBJECT) {
805 k = Universe::typeArrayKlassObj(t);
806 } else {
807 k = SystemDictionary::find_instance_klass(ss.as_symbol(), class_loader, protection_domain);
808 }
809 if (k != NULL__null) {
810 k = k->array_klass_or_null(ndims);
811 }
812 } else {
813 k = find_instance_klass(class_name, class_loader, protection_domain);
814 }
815 return k;
816}
817
818// Note: this method is much like resolve_class_from_stream, but
819// does not publish the classes in the SystemDictionary.
820// Handles Lookup.defineClass hidden.
821InstanceKlass* SystemDictionary::resolve_hidden_class_from_stream(
822 ClassFileStream* st,
823 Symbol* class_name,
824 Handle class_loader,
825 const ClassLoadInfo& cl_info,
826 TRAPSJavaThread* __the_thread__) {
827
828 EventClassLoad class_load_start_event;
829 ClassLoaderData* loader_data;
830
831 // - for hidden classes that are not strong: create a new CLD that has a class holder and
832 // whose loader is the Lookup class's loader.
833 // - for hidden class: add the class to the Lookup class's loader's CLD.
834 assert (cl_info.is_hidden(), "only used for hidden classes")do { if (!(cl_info.is_hidden())) { (*g_assert_poison) = 'X';;
report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 834, "assert(" "cl_info.is_hidden()" ") failed", "only used for hidden classes"
); ::breakpoint(); } } while (0)
;
835 bool create_mirror_cld = !cl_info.is_strong_hidden();
836 loader_data = register_loader(class_loader, create_mirror_cld);
837
838 assert(st != NULL, "invariant")do { if (!(st != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 838, "assert(" "st != __null" ") failed", "invariant"); ::breakpoint
(); } } while (0)
;
839 assert(st->need_verify(), "invariant")do { if (!(st->need_verify())) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 839, "assert(" "st->need_verify()" ") failed", "invariant"
); ::breakpoint(); } } while (0)
;
840
841 // Parse stream and create a klass.
842 InstanceKlass* k = KlassFactory::create_from_stream(st,
843 class_name,
844 loader_data,
845 cl_info,
846 CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
847 assert(k != NULL, "no klass created")do { if (!(k != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 847, "assert(" "k != __null" ") failed", "no klass created"
); ::breakpoint(); } } while (0)
;
848
849 // Hidden classes that are not strong must update ClassLoaderData holder
850 // so that they can be unloaded when the mirror is no longer referenced.
851 if (!cl_info.is_strong_hidden()) {
852 k->class_loader_data()->initialize_holder(Handle(THREAD__the_thread__, k->java_mirror()));
853 }
854
855 {
856 MutexLocker mu_r(THREAD__the_thread__, Compile_lock);
857 // Add to class hierarchy, and do possible deoptimizations.
858 add_to_hierarchy(k);
859 // But, do not add to dictionary.
860 }
861
862 k->link_class(CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
863
864 // notify jvmti
865 if (JvmtiExport::should_post_class_load()) {
866 JvmtiExport::post_class_load(THREAD__the_thread__, k);
867 }
868 if (class_load_start_event.should_commit()) {
869 post_class_load_event(&class_load_start_event, k, loader_data);
870 }
871
872 return k;
873}
874
875// Add a klass to the system from a stream (called by jni_DefineClass and
876// JVM_DefineClass).
877// Note: class_name can be NULL. In that case we do not know the name of
878// the class until we have parsed the stream.
879// This function either returns an InstanceKlass or throws an exception. It does
880// not return NULL without a pending exception.
881InstanceKlass* SystemDictionary::resolve_class_from_stream(
882 ClassFileStream* st,
883 Symbol* class_name,
884 Handle class_loader,
885 const ClassLoadInfo& cl_info,
886 TRAPSJavaThread* __the_thread__) {
887
888 HandleMark hm(THREAD__the_thread__);
889
890 ClassLoaderData* loader_data = register_loader(class_loader);
891
892 // Classloaders that support parallelism, e.g. bootstrap classloader,
893 // do not acquire lock here
894 Handle lockObject = get_loader_lock_or_null(class_loader);
895 ObjectLocker ol(lockObject, THREAD__the_thread__);
896
897 // Parse the stream and create a klass.
898 // Note that we do this even though this klass might
899 // already be present in the SystemDictionary, otherwise we would not
900 // throw potential ClassFormatErrors.
901 InstanceKlass* k = NULL__null;
902
903#if INCLUDE_CDS1
904 if (!DumpSharedSpaces) {
905 k = SystemDictionaryShared::lookup_from_stream(class_name,
906 class_loader,
907 cl_info.protection_domain(),
908 st,
909 CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
910 }
911#endif
912
913 if (k == NULL__null) {
914 k = KlassFactory::create_from_stream(st, class_name, loader_data, cl_info, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
915 }
916
917 assert(k != NULL, "no klass created")do { if (!(k != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 917, "assert(" "k != __null" ") failed", "no klass created"
); ::breakpoint(); } } while (0)
;
918 Symbol* h_name = k->name();
919 assert(class_name == NULL || class_name == h_name, "name mismatch")do { if (!(class_name == __null || class_name == h_name)) { (
*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 919, "assert(" "class_name == __null || class_name == h_name"
") failed", "name mismatch"); ::breakpoint(); } } while (0)
;
920
921 // Add class just loaded
922 // If a class loader supports parallel classloading, handle parallel define requests.
923 // find_or_define_instance_class may return a different InstanceKlass,
924 // in which case the old k would be deallocated
925 if (is_parallelCapable(class_loader)) {
926 k = find_or_define_instance_class(h_name, class_loader, k, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
927 } else {
928 define_instance_class(k, class_loader, THREAD__the_thread__);
929
930 // If defining the class throws an exception register 'k' for cleanup.
931 if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) {
932 assert(k != NULL, "Must have an instance klass here!")do { if (!(k != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 932, "assert(" "k != __null" ") failed", "Must have an instance klass here!"
); ::breakpoint(); } } while (0)
;
933 loader_data->add_to_deallocate_list(k);
934 return NULL__null;
935 }
936 }
937
938 // Make sure we have an entry in the SystemDictionary on success
939 DEBUG_ONLY(verify_dictionary_entry(h_name, k))verify_dictionary_entry(h_name, k);
940
941 return k;
942}
943
944InstanceKlass* SystemDictionary::resolve_from_stream(ClassFileStream* st,
945 Symbol* class_name,
946 Handle class_loader,
947 const ClassLoadInfo& cl_info,
948 TRAPSJavaThread* __the_thread__) {
949 if (cl_info.is_hidden()) {
950 return resolve_hidden_class_from_stream(st, class_name, class_loader, cl_info, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
951 } else {
952 return resolve_class_from_stream(st, class_name, class_loader, cl_info, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
953 }
954}
955
956
957#if INCLUDE_CDS1
958// Check if a shared class can be loaded by the specific classloader.
959bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
960 InstanceKlass* ik,
961 PackageEntry* pkg_entry,
962 Handle class_loader) {
963 assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),do { if (!(!ModuleEntryTable::javabase_moduleEntry()->is_patched
())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 964, "assert(" "!ModuleEntryTable::javabase_moduleEntry()->is_patched()"
") failed", "Cannot use sharing if java.base is patched"); ::
breakpoint(); } } while (0)
964 "Cannot use sharing if java.base is patched")do { if (!(!ModuleEntryTable::javabase_moduleEntry()->is_patched
())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 964, "assert(" "!ModuleEntryTable::javabase_moduleEntry()->is_patched()"
") failed", "Cannot use sharing if java.base is patched"); ::
breakpoint(); } } while (0)
;
965
966 // (1) Check if we are loading into the same loader as in dump time.
967
968 if (ik->is_shared_boot_class()) {
969 if (class_loader() != NULL__null) {
970 return false;
971 }
972 } else if (ik->is_shared_platform_class()) {
973 if (class_loader() != java_platform_loader()) {
974 return false;
975 }
976 } else if (ik->is_shared_app_class()) {
977 if (class_loader() != java_system_loader()) {
978 return false;
979 }
980 } else {
981 // ik was loaded by a custom loader during dump time
982 if (class_loader_data(class_loader)->is_builtin_class_loader_data()) {
983 return false;
984 } else {
985 return true;
986 }
987 }
988
989 // (2) Check if we are loading into the same module from the same location as in dump time.
990
991 if (MetaspaceShared::use_optimized_module_handling()) {
992 // Class visibility has not changed between dump time and run time, so a class
993 // that was visible (and thus archived) during dump time is always visible during runtime.
994 assert(SystemDictionary::is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader),do { if (!(SystemDictionary::is_shared_class_visible_impl(class_name
, ik, pkg_entry, class_loader))) { (*g_assert_poison) = 'X';;
report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 995, "assert(" "SystemDictionary::is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader)"
") failed", "visibility cannot change between dump time and runtime"
); ::breakpoint(); } } while (0)
995 "visibility cannot change between dump time and runtime")do { if (!(SystemDictionary::is_shared_class_visible_impl(class_name
, ik, pkg_entry, class_loader))) { (*g_assert_poison) = 'X';;
report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 995, "assert(" "SystemDictionary::is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader)"
") failed", "visibility cannot change between dump time and runtime"
); ::breakpoint(); } } while (0)
;
996 return true;
997 }
998 return is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader);
999}
1000
1001bool SystemDictionary::is_shared_class_visible_impl(Symbol* class_name,
1002 InstanceKlass* ik,
1003 PackageEntry* pkg_entry,
1004 Handle class_loader) {
1005 int scp_index = ik->shared_classpath_index();
1006 assert(!ik->is_shared_unregistered_class(), "this function should be called for built-in classes only")do { if (!(!ik->is_shared_unregistered_class())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1006, "assert(" "!ik->is_shared_unregistered_class()" ") failed"
, "this function should be called for built-in classes only")
; ::breakpoint(); } } while (0)
;
1007 assert(scp_index >= 0, "must be")do { if (!(scp_index >= 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1007, "assert(" "scp_index >= 0" ") failed", "must be");
::breakpoint(); } } while (0)
;
1008 SharedClassPathEntry* scp_entry = FileMapInfo::shared_path(scp_index);
1009 if (!Universe::is_module_initialized()) {
1010 assert(scp_entry != NULL && scp_entry->is_modules_image(),do { if (!(scp_entry != __null && scp_entry->is_modules_image
())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1011, "assert(" "scp_entry != __null && scp_entry->is_modules_image()"
") failed", "Loading non-bootstrap classes before the module system is initialized"
); ::breakpoint(); } } while (0)
1011 "Loading non-bootstrap classes before the module system is initialized")do { if (!(scp_entry != __null && scp_entry->is_modules_image
())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1011, "assert(" "scp_entry != __null && scp_entry->is_modules_image()"
") failed", "Loading non-bootstrap classes before the module system is initialized"
); ::breakpoint(); } } while (0)
;
1012 assert(class_loader.is_null(), "sanity")do { if (!(class_loader.is_null())) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1012, "assert(" "class_loader.is_null()" ") failed", "sanity"
); ::breakpoint(); } } while (0)
;
1013 return true;
1014 }
1015
1016 ModuleEntry* mod_entry = (pkg_entry == NULL__null) ? NULL__null : pkg_entry->module();
1017 bool should_be_in_named_module = (mod_entry != NULL__null && mod_entry->is_named());
1018 bool was_archived_from_named_module = scp_entry->in_named_module();
1019 bool visible;
1020
1021 if (was_archived_from_named_module) {
1022 if (should_be_in_named_module) {
1023 // Is the module loaded from the same location as during dump time?
1024 visible = mod_entry->shared_path_index() == scp_index;
1025 if (visible) {
1026 assert(!mod_entry->is_patched(), "cannot load archived classes for patched module")do { if (!(!mod_entry->is_patched())) { (*g_assert_poison)
= 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1026, "assert(" "!mod_entry->is_patched()" ") failed", "cannot load archived classes for patched module"
); ::breakpoint(); } } while (0)
;
1027 }
1028 } else {
1029 // During dump time, this class was in a named module, but at run time, this class should be
1030 // in an unnamed module.
1031 visible = false;
1032 }
1033 } else {
1034 if (should_be_in_named_module) {
1035 // During dump time, this class was in an unnamed, but at run time, this class should be
1036 // in a named module.
1037 visible = false;
1038 } else {
1039 visible = true;
1040 }
1041 }
1042
1043 return visible;
1044}
1045
1046bool SystemDictionary::check_shared_class_super_type(InstanceKlass* klass, InstanceKlass* super_type,
1047 Handle class_loader, Handle protection_domain,
1048 bool is_superclass, TRAPSJavaThread* __the_thread__) {
1049 assert(super_type->is_shared(), "must be")do { if (!(super_type->is_shared())) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1049, "assert(" "super_type->is_shared()" ") failed", "must be"
); ::breakpoint(); } } while (0)
;
1050
1051 // Quick check if the super type has been already loaded.
1052 // + Don't do it for unregistered classes -- they can be unloaded so
1053 // super_type->class_loader_data() could be stale.
1054 // + Don't check if loader data is NULL, ie. the super_type isn't fully loaded.
1055 if (!super_type->is_shared_unregistered_class() && super_type->class_loader_data() != NULL__null) {
1056 // Check if the superclass is loaded by the current class_loader
1057 Symbol* name = super_type->name();
1058 InstanceKlass* check = find_instance_klass(name, class_loader, protection_domain);
1059 if (check == super_type) {
1060 return true;
1061 }
1062 }
1063
1064 Klass *found = resolve_super_or_fail(klass->name(), super_type->name(),
1065 class_loader, protection_domain, is_superclass, CHECK_0__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return 0; (void)(0
);
1066 if (found == super_type) {
1067 return true;
1068 } else {
1069 // The dynamically resolved super type is not the same as the one we used during dump time,
1070 // so we cannot use the class.
1071 return false;
1072 }
1073}
1074
1075bool SystemDictionary::check_shared_class_super_types(InstanceKlass* ik, Handle class_loader,
1076 Handle protection_domain, TRAPSJavaThread* __the_thread__) {
1077 // Check the superclass and interfaces. They must be the same
1078 // as in dump time, because the layout of <ik> depends on
1079 // the specific layout of ik->super() and ik->local_interfaces().
1080 //
1081 // If unexpected superclass or interfaces are found, we cannot
1082 // load <ik> from the shared archive.
1083
1084 if (ik->super() != NULL__null &&
1085 !check_shared_class_super_type(ik, InstanceKlass::cast(ik->super()),
1086 class_loader, protection_domain, true, THREAD__the_thread__)) {
1087 return false;
1088 }
1089
1090 Array<InstanceKlass*>* interfaces = ik->local_interfaces();
1091 int num_interfaces = interfaces->length();
1092 for (int index = 0; index < num_interfaces; index++) {
1093 if (!check_shared_class_super_type(ik, interfaces->at(index), class_loader, protection_domain, false, THREAD__the_thread__)) {
1094 return false;
1095 }
1096 }
1097
1098 return true;
1099}
1100
1101InstanceKlass* SystemDictionary::load_shared_lambda_proxy_class(InstanceKlass* ik,
1102 Handle class_loader,
1103 Handle protection_domain,
1104 PackageEntry* pkg_entry,
1105 TRAPSJavaThread* __the_thread__) {
1106 InstanceKlass* shared_nest_host = SystemDictionaryShared::get_shared_nest_host(ik);
1107 assert(shared_nest_host->is_shared(), "nest host must be in CDS archive")do { if (!(shared_nest_host->is_shared())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1107, "assert(" "shared_nest_host->is_shared()" ") failed"
, "nest host must be in CDS archive"); ::breakpoint(); } } while
(0)
;
1108 Symbol* cn = shared_nest_host->name();
1109 Klass *s = resolve_or_fail(cn, class_loader, protection_domain, true, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
1110 if (s != shared_nest_host) {
1111 // The dynamically resolved nest_host is not the same as the one we used during dump time,
1112 // so we cannot use ik.
1113 return NULL__null;
1114 } else {
1115 assert(s->is_shared(), "must be")do { if (!(s->is_shared())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1115, "assert(" "s->is_shared()" ") failed", "must be");
::breakpoint(); } } while (0)
;
1116 }
1117
1118 // The lambda proxy class and its nest host have the same class loader and class loader data,
1119 // as verified in SystemDictionaryShared::add_lambda_proxy_class()
1120 assert(shared_nest_host->class_loader() == class_loader(), "mismatched class loader")do { if (!(shared_nest_host->class_loader() == class_loader
())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1120, "assert(" "shared_nest_host->class_loader() == class_loader()"
") failed", "mismatched class loader"); ::breakpoint(); } } while
(0)
;
1121 assert(shared_nest_host->class_loader_data() == ClassLoaderData::class_loader_data(class_loader()), "mismatched class loader data")do { if (!(shared_nest_host->class_loader_data() == ClassLoaderData
::class_loader_data(class_loader()))) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1121, "assert(" "shared_nest_host->class_loader_data() == ClassLoaderData::class_loader_data(class_loader())"
") failed", "mismatched class loader data"); ::breakpoint();
} } while (0)
;
1122 ik->set_nest_host(shared_nest_host);
1123
1124 InstanceKlass* loaded_ik = load_shared_class(ik, class_loader, protection_domain, NULL__null, pkg_entry, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
1125
1126 if (loaded_ik != NULL__null) {
1127 assert(shared_nest_host->is_same_class_package(ik),do { if (!(shared_nest_host->is_same_class_package(ik))) {
(*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1128, "assert(" "shared_nest_host->is_same_class_package(ik)"
") failed", "lambda proxy class and its nest host must be in the same package"
); ::breakpoint(); } } while (0)
1128 "lambda proxy class and its nest host must be in the same package")do { if (!(shared_nest_host->is_same_class_package(ik))) {
(*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1128, "assert(" "shared_nest_host->is_same_class_package(ik)"
") failed", "lambda proxy class and its nest host must be in the same package"
); ::breakpoint(); } } while (0)
;
1129 }
1130
1131 return loaded_ik;
1132}
1133
1134InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
1135 Handle class_loader,
1136 Handle protection_domain,
1137 const ClassFileStream *cfs,
1138 PackageEntry* pkg_entry,
1139 TRAPSJavaThread* __the_thread__) {
1140 assert(ik != NULL, "sanity")do { if (!(ik != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1140, "assert(" "ik != __null" ") failed", "sanity"); ::breakpoint
(); } } while (0)
;
1141 assert(!ik->is_unshareable_info_restored(), "shared class can be loaded only once")do { if (!(!ik->is_unshareable_info_restored())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1141, "assert(" "!ik->is_unshareable_info_restored()" ") failed"
, "shared class can be loaded only once"); ::breakpoint(); } }
while (0)
;
1142 Symbol* class_name = ik->name();
1143
1144 if (!is_shared_class_visible(class_name, ik, pkg_entry, class_loader)) {
1145 return NULL__null;
1146 }
1147
1148 if (!check_shared_class_super_types(ik, class_loader, protection_domain, THREAD__the_thread__)) {
1149 return NULL__null;
1150 }
1151
1152 InstanceKlass* new_ik = NULL__null;
1153 // CFLH check is skipped for VM hidden classes (see KlassFactory::create_from_stream).
1154 // It will be skipped for shared VM hidden lambda proxy classes.
1155 if (!SystemDictionaryShared::is_hidden_lambda_proxy(ik)) {
1156 new_ik = KlassFactory::check_shared_class_file_load_hook(
1157 ik, class_name, class_loader, protection_domain, cfs, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
1158 }
1159 if (new_ik != NULL__null) {
1160 // The class is changed by CFLH. Return the new class. The shared class is
1161 // not used.
1162 return new_ik;
1163 }
1164
1165 // Adjust methods to recover missing data. They need addresses for
1166 // interpreter entry points and their default native method address
1167 // must be reset.
1168
1169 // Shared classes are all currently loaded by either the bootstrap or
1170 // internal parallel class loaders, so this will never cause a deadlock
1171 // on a custom class loader lock.
1172 // Since this class is already locked with parallel capable class
1173 // loaders, including the bootstrap loader via the placeholder table,
1174 // this lock is currently a nop.
1175
1176 ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
1177 {
1178 HandleMark hm(THREAD__the_thread__);
1179 Handle lockObject = get_loader_lock_or_null(class_loader);
1180 ObjectLocker ol(lockObject, THREAD__the_thread__);
1181 // prohibited package check assumes all classes loaded from archive call
1182 // restore_unshareable_info which calls ik->set_package()
1183 ik->restore_unshareable_info(loader_data, protection_domain, pkg_entry, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
1184 }
1185
1186 load_shared_class_misc(ik, loader_data);
1187 return ik;
1188}
1189
1190void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) {
1191 ik->print_class_load_logging(loader_data, NULL__null, NULL__null);
1192
1193 // For boot loader, ensure that GetSystemPackage knows that a class in this
1194 // package was loaded.
1195 if (loader_data->is_the_null_class_loader_data()) {
1196 int path_index = ik->shared_classpath_index();
1197 ik->set_classpath_index(path_index);
1198 }
1199
1200 // notify a class loaded from shared object
1201 ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1202}
1203
1204#endif // INCLUDE_CDS
1205
1206InstanceKlass* SystemDictionary::load_instance_class_impl(Symbol* class_name, Handle class_loader, TRAPSJavaThread* __the_thread__) {
1207
1208 if (class_loader.is_null()) {
1209 ResourceMark rm(THREAD__the_thread__);
1210 PackageEntry* pkg_entry = NULL__null;
1211 bool search_only_bootloader_append = false;
1212 ClassLoaderData *loader_data = class_loader_data(class_loader);
1213
1214 // Find the package in the boot loader's package entry table.
1215 TempNewSymbol pkg_name = ClassLoader::package_from_class_name(class_name);
1216 if (pkg_name != NULL__null) {
1217 pkg_entry = loader_data->packages()->lookup_only(pkg_name);
1218 }
1219
1220 // Prior to attempting to load the class, enforce the boot loader's
1221 // visibility boundaries.
1222 if (!Universe::is_module_initialized()) {
1223 // During bootstrapping, prior to module initialization, any
1224 // class attempting to be loaded must be checked against the
1225 // java.base packages in the boot loader's PackageEntryTable.
1226 // No class outside of java.base is allowed to be loaded during
1227 // this bootstrapping window.
1228 if (pkg_entry == NULL__null || pkg_entry->in_unnamed_module()) {
1229 // Class is either in the unnamed package or in
1230 // a named package within the unnamed module. Either
1231 // case is outside of java.base, do not attempt to
1232 // load the class post java.base definition. If
1233 // java.base has not been defined, let the class load
1234 // and its package will be checked later by
1235 // ModuleEntryTable::verify_javabase_packages.
1236 if (ModuleEntryTable::javabase_defined()) {
1237 return NULL__null;
1238 }
1239 } else {
1240 // Check that the class' package is defined within java.base.
1241 ModuleEntry* mod_entry = pkg_entry->module();
1242 Symbol* mod_entry_name = mod_entry->name();
1243 if (mod_entry_name->fast_compare(vmSymbols::java_base()) != 0) {
1244 return NULL__null;
1245 }
1246 }
1247 } else {
1248 // After the module system has been initialized, check if the class'
1249 // package is in a module defined to the boot loader.
1250 if (pkg_name == NULL__null || pkg_entry == NULL__null || pkg_entry->in_unnamed_module()) {
1251 // Class is either in the unnamed package, in a named package
1252 // within a module not defined to the boot loader or in a
1253 // a named package within the unnamed module. In all cases,
1254 // limit visibility to search for the class only in the boot
1255 // loader's append path.
1256 if (!ClassLoader::has_bootclasspath_append()) {
1257 // If there is no bootclasspath append entry, no need to continue
1258 // searching.
1259 return NULL__null;
1260 }
1261 search_only_bootloader_append = true;
1262 }
1263 }
1264
1265 // Prior to bootstrapping's module initialization, never load a class outside
1266 // of the boot loader's module path
1267 assert(Universe::is_module_initialized() ||do { if (!(Universe::is_module_initialized() || !search_only_bootloader_append
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1269, "assert(" "Universe::is_module_initialized() || !search_only_bootloader_append"
") failed", "Attempt to load a class outside of boot loader's module path"
); ::breakpoint(); } } while (0)
1268 !search_only_bootloader_append,do { if (!(Universe::is_module_initialized() || !search_only_bootloader_append
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1269, "assert(" "Universe::is_module_initialized() || !search_only_bootloader_append"
") failed", "Attempt to load a class outside of boot loader's module path"
); ::breakpoint(); } } while (0)
1269 "Attempt to load a class outside of boot loader's module path")do { if (!(Universe::is_module_initialized() || !search_only_bootloader_append
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1269, "assert(" "Universe::is_module_initialized() || !search_only_bootloader_append"
") failed", "Attempt to load a class outside of boot loader's module path"
); ::breakpoint(); } } while (0)
;
1270
1271 // Search for classes in the CDS archive.
1272 InstanceKlass* k = NULL__null;
1273
1274#if INCLUDE_CDS1
1275 if (UseSharedSpaces)
1276 {
1277 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
1278 InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
1279 if (ik != NULL__null && ik->is_shared_boot_class() && !ik->shared_loading_failed()) {
1280 SharedClassLoadingMark slm(THREAD__the_thread__, ik);
1281 k = load_shared_class(ik, class_loader, Handle(), NULL__null, pkg_entry, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
1282 }
1283 }
1284#endif
1285
1286 if (k == NULL__null) {
1287 // Use VM class loader
1288 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1289 k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
1290 }
1291
1292 // find_or_define_instance_class may return a different InstanceKlass
1293 if (k != NULL__null) {
1294 CDS_ONLY(SharedClassLoadingMark slm(THREAD, k);)SharedClassLoadingMark slm(__the_thread__, k);
1295 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
1296 }
1297 return k;
1298 } else {
1299 // Use user specified class loader to load class. Call loadClass operation on class_loader.
1300 ResourceMark rm(THREAD__the_thread__);
1301
1302 JavaThread* jt = THREAD__the_thread__;
1303
1304 PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
1305 ClassLoader::perf_app_classload_selftime(),
1306 ClassLoader::perf_app_classload_count(),
1307 jt->get_thread_stat()->perf_recursion_counts_addr(),
1308 jt->get_thread_stat()->perf_timers_addr(),
1309 PerfClassTraceTime::CLASS_LOAD);
1310
1311 // Translate to external class name format, i.e., convert '/' chars to '.'
1312 Handle string = java_lang_String::externalize_classname(class_name, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
1313
1314 JavaValue result(T_OBJECT);
1315
1316 InstanceKlass* spec_klass = vmClasses::ClassLoader_klass();
1317
1318 // Call public unsynchronized loadClass(String) directly for all class loaders.
1319 // For parallelCapable class loaders, JDK >=7, loadClass(String, boolean) will
1320 // acquire a class-name based lock rather than the class loader object lock.
1321 // JDK < 7 already acquire the class loader lock in loadClass(String, boolean).
1322 JavaCalls::call_virtual(&result,
1323 class_loader,
1324 spec_klass,
1325 vmSymbols::loadClass_name(),
1326 vmSymbols::string_class_signature(),
1327 string,
1328 CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
1329
1330 assert(result.get_type() == T_OBJECT, "just checking")do { if (!(result.get_type() == T_OBJECT)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1330, "assert(" "result.get_type() == T_OBJECT" ") failed",
"just checking"); ::breakpoint(); } } while (0)
;
1331 oop obj = result.get_oop();
1332
1333 // Primitive classes return null since forName() can not be
1334 // used to obtain any of the Class objects representing primitives or void
1335 if ((obj != NULL__null) && !(java_lang_Class::is_primitive(obj))) {
1336 InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(obj));
1337 // For user defined Java class loaders, check that the name returned is
1338 // the same as that requested. This check is done for the bootstrap
1339 // loader when parsing the class file.
1340 if (class_name == k->name()) {
1341 return k;
1342 }
1343 }
1344 // Class is not found or has the wrong name, return NULL
1345 return NULL__null;
1346 }
1347}
1348
1349InstanceKlass* SystemDictionary::load_instance_class(unsigned int name_hash,
1350 Symbol* name,
1351 Handle class_loader,
1352 TRAPSJavaThread* __the_thread__) {
1353
1354 InstanceKlass* loaded_class = load_instance_class_impl(name, class_loader, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
1355
1356 // If everything was OK (no exceptions, no null return value), and
1357 // class_loader is NOT the defining loader, do a little more bookkeeping.
1358 if (loaded_class != NULL__null &&
1359 loaded_class->class_loader() != class_loader()) {
1360
1361 check_constraints(name_hash, loaded_class, class_loader, false, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
1362
1363 // Record dependency for non-parent delegation.
1364 // This recording keeps the defining class loader of the klass (loaded_class) found
1365 // from being unloaded while the initiating class loader is loaded
1366 // even if the reference to the defining class loader is dropped
1367 // before references to the initiating class loader.
1368 ClassLoaderData* loader_data = class_loader_data(class_loader);
1369 loader_data->record_dependency(loaded_class);
1370
1371 { // Grabbing the Compile_lock prevents systemDictionary updates
1372 // during compilations.
1373 MutexLocker mu(THREAD__the_thread__, Compile_lock);
1374 update_dictionary(name_hash, loaded_class, class_loader);
1375 }
1376
1377 if (JvmtiExport::should_post_class_load()) {
1378 JvmtiExport::post_class_load(THREAD__the_thread__, loaded_class);
1379 }
1380 }
1381 return loaded_class;
1382}
1383
1384static void post_class_define_event(InstanceKlass* k, const ClassLoaderData* def_cld) {
1385 EventClassDefine event;
1386 if (event.should_commit()) {
1387 event.set_definedClass(k);
1388 event.set_definingClassLoader(def_cld);
1389 event.commit();
1390 }
1391}
1392
1393void SystemDictionary::define_instance_class(InstanceKlass* k, Handle class_loader, TRAPSJavaThread* __the_thread__) {
1394
1395 ClassLoaderData* loader_data = k->class_loader_data();
1396 assert(loader_data->class_loader() == class_loader(), "they must be the same")do { if (!(loader_data->class_loader() == class_loader()))
{ (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1396, "assert(" "loader_data->class_loader() == class_loader()"
") failed", "they must be the same"); ::breakpoint(); } } while
(0)
;
1397
1398 // Bootstrap and other parallel classloaders don't acquire a lock,
1399 // they use placeholder token.
1400 // If a parallelCapable class loader calls define_instance_class instead of
1401 // find_or_define_instance_class to get here, we have a timing
1402 // hole with systemDictionary updates and check_constraints
1403 if (!is_parallelCapable(class_loader)) {
1404 assert(ObjectSynchronizer::current_thread_holds_lock(THREAD,do { if (!(ObjectSynchronizer::current_thread_holds_lock(__the_thread__
, get_loader_lock_or_null(class_loader)))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1406, "assert(" "ObjectSynchronizer::current_thread_holds_lock(__the_thread__, get_loader_lock_or_null(class_loader))"
") failed", "define called without lock"); ::breakpoint(); }
} while (0)
1405 get_loader_lock_or_null(class_loader)),do { if (!(ObjectSynchronizer::current_thread_holds_lock(__the_thread__
, get_loader_lock_or_null(class_loader)))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1406, "assert(" "ObjectSynchronizer::current_thread_holds_lock(__the_thread__, get_loader_lock_or_null(class_loader))"
") failed", "define called without lock"); ::breakpoint(); }
} while (0)
1406 "define called without lock")do { if (!(ObjectSynchronizer::current_thread_holds_lock(__the_thread__
, get_loader_lock_or_null(class_loader)))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1406, "assert(" "ObjectSynchronizer::current_thread_holds_lock(__the_thread__, get_loader_lock_or_null(class_loader))"
") failed", "define called without lock"); ::breakpoint(); }
} while (0)
;
1407 }
1408
1409 // Check class-loading constraints. Throw exception if violation is detected.
1410 // Grabs and releases SystemDictionary_lock
1411 // The check_constraints/find_class call and update_dictionary sequence
1412 // must be "atomic" for a specific class/classloader pair so we never
1413 // define two different instanceKlasses for that class/classloader pair.
1414 // Existing classloaders will call define_instance_class with the
1415 // classloader lock held
1416 // Parallel classloaders will call find_or_define_instance_class
1417 // which will require a token to perform the define class
1418 Symbol* name_h = k->name();
1419 Dictionary* dictionary = loader_data->dictionary();
1420 unsigned int name_hash = dictionary->compute_hash(name_h);
1421 check_constraints(name_hash, k, class_loader, true, CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0
);
1422
1423 // Register class just loaded with class loader (placed in ArrayList)
1424 // Note we do this before updating the dictionary, as this can
1425 // fail with an OutOfMemoryError (if it does, we will *not* put this
1426 // class in the dictionary and will not update the class hierarchy).
1427 // JVMTI FollowReferences needs to find the classes this way.
1428 if (k->class_loader() != NULL__null) {
1429 methodHandle m(THREAD__the_thread__, Universe::loader_addClass_method());
1430 JavaValue result(T_VOID);
1431 JavaCallArguments args(class_loader);
1432 args.push_oop(Handle(THREAD__the_thread__, k->java_mirror()));
1433 JavaCalls::call(&result, m, &args, CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0
);
1434 }
1435
1436 // Add the new class. We need recompile lock during update of CHA.
1437 {
1438 MutexLocker mu_r(THREAD__the_thread__, Compile_lock);
1439
1440 // Add to class hierarchy, and do possible deoptimizations.
1441 add_to_hierarchy(k);
1442
1443 // Add to systemDictionary - so other classes can see it.
1444 // Grabs and releases SystemDictionary_lock
1445 update_dictionary(name_hash, k, class_loader);
1446 }
1447 k->eager_initialize(THREAD__the_thread__);
1448
1449 // notify jvmti
1450 if (JvmtiExport::should_post_class_load()) {
1451 JvmtiExport::post_class_load(THREAD__the_thread__, k);
1452 }
1453 post_class_define_event(k, loader_data);
1454}
1455
1456// Support parallel classloading
1457// All parallel class loaders, including bootstrap classloader
1458// lock a placeholder entry for this class/class_loader pair
1459// to allow parallel defines of different classes for this class loader
1460// With AllowParallelDefine flag==true, in case they do not synchronize around
1461// FindLoadedClass/DefineClass, calls, we check for parallel
1462// loading for them, wait if a defineClass is in progress
1463// and return the initial requestor's results
1464// This flag does not apply to the bootstrap classloader.
1465// With AllowParallelDefine flag==false, call through to define_instance_class
1466// which will throw LinkageError: duplicate class definition.
1467// False is the requested default.
1468// For better performance, the class loaders should synchronize
1469// findClass(), i.e. FindLoadedClass/DefineClassIfAbsent or they
1470// potentially waste time reading and parsing the bytestream.
1471// Note: VM callers should ensure consistency of k/class_name,class_loader
1472// Be careful when modifying this code: once you have run
1473// placeholders()->find_and_add(PlaceholderTable::DEFINE_CLASS),
1474// you need to find_and_remove it before returning.
1475// So be careful to not exit with a CHECK_ macro between these calls.
1476InstanceKlass* SystemDictionary::find_or_define_helper(Symbol* class_name, Handle class_loader,
1477 InstanceKlass* k, TRAPSJavaThread* __the_thread__) {
1478
1479 Symbol* name_h = k->name(); // passed in class_name may be null
1480 ClassLoaderData* loader_data = class_loader_data(class_loader);
1481 Dictionary* dictionary = loader_data->dictionary();
1482
1483 unsigned int name_hash = dictionary->compute_hash(name_h);
1484
1485 // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS
1486 {
1487 MutexLocker mu(THREAD__the_thread__, SystemDictionary_lock);
1488 // First check if class already defined
1489 if (is_parallelDefine(class_loader)) {
1490 InstanceKlass* check = dictionary->find_class(name_hash, name_h);
1491 if (check != NULL__null) {
1492 return check;
1493 }
1494 }
1495
1496 // Acquire define token for this class/classloader
1497 assert(placeholders()->compute_hash(name_h) == name_hash, "they're the same hashcode")do { if (!(placeholders()->compute_hash(name_h) == name_hash
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1497, "assert(" "placeholders()->compute_hash(name_h) == name_hash"
") failed", "they're the same hashcode"); ::breakpoint(); } }
while (0)
;
1498 PlaceholderEntry* probe = placeholders()->find_and_add(name_hash, name_h, loader_data,
1499 PlaceholderTable::DEFINE_CLASS, NULL__null, THREAD__the_thread__);
1500 // Wait if another thread defining in parallel
1501 // All threads wait - even those that will throw duplicate class: otherwise
1502 // caller is surprised by LinkageError: duplicate, but findLoadedClass fails
1503 // if other thread has not finished updating dictionary
1504 while (probe->definer() != NULL__null) {
1505 SystemDictionary_lock->wait();
1506 }
1507 // Only special cases allow parallel defines and can use other thread's results
1508 // Other cases fall through, and may run into duplicate defines
1509 // caught by finding an entry in the SystemDictionary
1510 if (is_parallelDefine(class_loader) && (probe->instance_klass() != NULL__null)) {
1511 InstanceKlass* ik = probe->instance_klass();
1512 placeholders()->find_and_remove(name_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD__the_thread__);
1513 SystemDictionary_lock->notify_all();
1514#ifdef ASSERT1
1515 InstanceKlass* check = dictionary->find_class(name_hash, name_h);
1516 assert(check != NULL, "definer missed recording success")do { if (!(check != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1516, "assert(" "check != __null" ") failed", "definer missed recording success"
); ::breakpoint(); } } while (0)
;
1517#endif
1518 return ik;
1519 } else {
1520 // This thread will define the class (even if earlier thread tried and had an error)
1521 probe->set_definer(THREAD__the_thread__);
1522 }
1523 }
1524
1525 define_instance_class(k, class_loader, THREAD__the_thread__);
1526
1527 // definer must notify any waiting threads
1528 {
1529 MutexLocker mu(THREAD__the_thread__, SystemDictionary_lock);
1530 PlaceholderEntry* probe = placeholders()->get_entry(name_hash, name_h, loader_data);
1531 assert(probe != NULL, "DEFINE_CLASS placeholder lost?")do { if (!(probe != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1531, "assert(" "probe != __null" ") failed", "DEFINE_CLASS placeholder lost?"
); ::breakpoint(); } } while (0)
;
1532 if (!HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) {
1533 probe->set_instance_klass(k);
1534 }
1535 probe->set_definer(NULL__null);
1536 placeholders()->find_and_remove(name_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD__the_thread__);
1537 SystemDictionary_lock->notify_all();
1538 }
1539
1540 return HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception()) ? NULL__null : k;
1541}
1542
1543// If a class loader supports parallel classloading handle parallel define requests.
1544// find_or_define_instance_class may return a different InstanceKlass
1545InstanceKlass* SystemDictionary::find_or_define_instance_class(Symbol* class_name, Handle class_loader,
1546 InstanceKlass* k, TRAPSJavaThread* __the_thread__) {
1547 InstanceKlass* defined_k = find_or_define_helper(class_name, class_loader, k, THREAD__the_thread__);
1548 // Clean up original InstanceKlass if duplicate or error
1549 if (!HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception()) && defined_k != k) {
1550 // If a parallel capable class loader already defined this class, register 'k' for cleanup.
1551 assert(defined_k != NULL, "Should have a klass if there's no exception")do { if (!(defined_k != __null)) { (*g_assert_poison) = 'X';;
report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1551, "assert(" "defined_k != __null" ") failed", "Should have a klass if there's no exception"
); ::breakpoint(); } } while (0)
;
1552 k->class_loader_data()->add_to_deallocate_list(k);
1553 } else if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) {
1554 assert(defined_k == NULL, "Should not have a klass if there's an exception")do { if (!(defined_k == __null)) { (*g_assert_poison) = 'X';;
report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1554, "assert(" "defined_k == __null" ") failed", "Should not have a klass if there's an exception"
); ::breakpoint(); } } while (0)
;
1555 k->class_loader_data()->add_to_deallocate_list(k);
1556 }
1557 return defined_k;
1558}
1559
1560
1561// ----------------------------------------------------------------------------
1562// Update hierachy. This is done before the new klass has been added to the SystemDictionary. The Compile_lock
1563// is held, to ensure that the compiler is not using the class hierachy, and that deoptimization will kick in
1564// before a new class is used.
1565
1566void SystemDictionary::add_to_hierarchy(InstanceKlass* k) {
1567 assert(k != NULL, "just checking")do { if (!(k != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1567, "assert(" "k != __null" ") failed", "just checking");
::breakpoint(); } } while (0)
;
1568 if (Universe::is_fully_initialized()) {
1569 assert_locked_or_safepoint(Compile_lock);
1570 }
1571
1572 k->set_init_state(InstanceKlass::loaded);
1573 // make sure init_state store is already done.
1574 // The compiler reads the hierarchy outside of the Compile_lock.
1575 // Access ordering is used to add to hierarchy.
1576
1577 // Link into hierachy.
1578 k->append_to_sibling_list(); // add to superklass/sibling list
1579 k->process_interfaces(); // handle all "implements" declarations
1580
1581 // Now flush all code that depended on old class hierarchy.
1582 // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97)
1583 if (Universe::is_fully_initialized()) {
1584 CodeCache::flush_dependents_on(k);
1585 }
1586}
1587
1588// ----------------------------------------------------------------------------
1589// GC support
1590
1591// Assumes classes in the SystemDictionary are only unloaded at a safepoint
1592bool SystemDictionary::do_unloading(GCTimer* gc_timer) {
1593
1594 bool unloading_occurred;
1595 bool is_concurrent = !SafepointSynchronize::is_at_safepoint();
1596 {
1597 GCTraceTime(Debug, gc, phases)GCTraceTimeWrapper<LogLevel::Debug, (LogTag::_gc), (LogTag
::_phases), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::
__NO_TAG), (LogTag::__NO_TAG)>
t("ClassLoaderData", gc_timer);
1598 assert_locked_or_safepoint(ClassLoaderDataGraph_lock); // caller locks.
1599 // First, mark for unload all ClassLoaderData referencing a dead class loader.
1600 unloading_occurred = ClassLoaderDataGraph::do_unloading();
1601 if (unloading_occurred) {
1602 MutexLocker ml2(is_concurrent ? Module_lock : NULL__null);
1603 JFR_ONLY(Jfr::on_unloading_classes();)Jfr::on_unloading_classes();
1604 MANAGEMENT_ONLY(FinalizerService::purge_unloaded();)FinalizerService::purge_unloaded();
1605 MutexLocker ml1(is_concurrent ? SystemDictionary_lock : NULL__null);
1606 ClassLoaderDataGraph::clean_module_and_package_info();
1607 constraints()->purge_loader_constraints();
1608 resolution_errors()->purge_resolution_errors();
1609 }
1610 }
1611
1612 GCTraceTime(Debug, gc, phases)GCTraceTimeWrapper<LogLevel::Debug, (LogTag::_gc), (LogTag
::_phases), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::
__NO_TAG), (LogTag::__NO_TAG)>
t("Trigger cleanups", gc_timer);
1613
1614 if (unloading_occurred) {
1615 SymbolTable::trigger_cleanup();
1616
1617 if (java_lang_System::allow_security_manager()) {
1618 // Oops referenced by the protection domain cache table may get unreachable independently
1619 // of the class loader (eg. cached protection domain oops). So we need to
1620 // explicitly unlink them here.
1621 // All protection domain oops are linked to the caller class, so if nothing
1622 // unloads, this is not needed.
1623 _pd_cache_table->trigger_cleanup();
1624 } else {
1625 assert(_pd_cache_table->number_of_entries() == 0, "should be empty")do { if (!(_pd_cache_table->number_of_entries() == 0)) { (
*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1625, "assert(" "_pd_cache_table->number_of_entries() == 0"
") failed", "should be empty"); ::breakpoint(); } } while (0
)
;
1626 }
1627
1628 MutexLocker ml(is_concurrent ? ClassInitError_lock : NULL__null);
1629 InstanceKlass::clean_initialization_error_table();
1630 }
1631
1632 return unloading_occurred;
1633}
1634
1635void SystemDictionary::methods_do(void f(Method*)) {
1636 // Walk methods in loaded classes
1637 MutexLocker ml(ClassLoaderDataGraph_lock);
1638 ClassLoaderDataGraph::methods_do(f);
1639 // Walk method handle intrinsics
1640 invoke_method_table()->methods_do(f);
1641}
1642
1643// ----------------------------------------------------------------------------
1644// Initialization
1645
1646void SystemDictionary::initialize(TRAPSJavaThread* __the_thread__) {
1647 // Allocate arrays
1648 _placeholders = new PlaceholderTable(_placeholder_table_size);
1649 _loader_constraints = new LoaderConstraintTable(_loader_constraint_size);
1650 _resolution_errors = new ResolutionErrorTable(_resolution_error_size);
1651 _invoke_method_table = new SymbolPropertyTable(_invoke_method_size);
1652 _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize);
1653
1654 // Resolve basic classes
1655 vmClasses::resolve_all(CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0
);
1656 // Resolve classes used by archived heap objects
1657 if (UseSharedSpaces) {
1658 HeapShared::resolve_classes(THREAD__the_thread__);
1659 }
1660}
1661
1662// Constraints on class loaders. The details of the algorithm can be
1663// found in the OOPSLA'98 paper "Dynamic Class Loading in the Java
1664// Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is
1665// that the dictionary needs to maintain a set of contraints that
1666// must be satisfied by all classes in the dictionary.
1667// if defining is true, then LinkageError if already in dictionary
1668// if initiating loader, then ok if InstanceKlass matches existing entry
1669
1670void SystemDictionary::check_constraints(unsigned int name_hash,
1671 InstanceKlass* k,
1672 Handle class_loader,
1673 bool defining,
1674 TRAPSJavaThread* __the_thread__) {
1675 ResourceMark rm(THREAD__the_thread__);
1676 stringStream ss;
1677 bool throwException = false;
1678
1679 {
1680 Symbol *name = k->name();
1681 ClassLoaderData *loader_data = class_loader_data(class_loader);
1682
1683 MutexLocker mu(THREAD__the_thread__, SystemDictionary_lock);
1684
1685 InstanceKlass* check = loader_data->dictionary()->find_class(name_hash, name);
1686 if (check != NULL__null) {
1687 // If different InstanceKlass - duplicate class definition,
1688 // else - ok, class loaded by a different thread in parallel.
1689 // We should only have found it if it was done loading and ok to use.
1690
1691 if ((defining == true) || (k != check)) {
1692 throwException = true;
1693 ss.print("loader %s", loader_data->loader_name_and_id());
1694 ss.print(" attempted duplicate %s definition for %s. (%s)",
1695 k->external_kind(), k->external_name(), k->class_in_module_of_loader(false, true));
1696 } else {
1697 return;
1698 }
1699 }
1700
1701 if (throwException == false) {
1702 if (constraints()->check_or_update(k, class_loader, name) == false) {
1703 throwException = true;
1704 ss.print("loader constraint violation: loader %s", loader_data->loader_name_and_id());
1705 ss.print(" wants to load %s %s.",
1706 k->external_kind(), k->external_name());
1707 Klass *existing_klass = constraints()->find_constrained_klass(name, class_loader);
1708 if (existing_klass != NULL__null && existing_klass->class_loader() != class_loader()) {
1709 ss.print(" A different %s with the same name was previously loaded by %s. (%s)",
1710 existing_klass->external_kind(),
1711 existing_klass->class_loader_data()->loader_name_and_id(),
1712 existing_klass->class_in_module_of_loader(false, true));
1713 } else {
1714 ss.print(" (%s)", k->class_in_module_of_loader(false, true));
1715 }
1716 }
1717 }
1718 }
1719
1720 // Throw error now if needed (cannot throw while holding
1721 // SystemDictionary_lock because of rank ordering)
1722 if (throwException == true) {
1723 THROW_MSG(vmSymbols::java_lang_LinkageError(), ss.as_string()){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 1723, vmSymbols::java_lang_LinkageError(), ss.as_string());
return; }
;
1724 }
1725}
1726
1727// Update class loader data dictionary - done after check_constraint and add_to_hierachy
1728// have been called.
1729void SystemDictionary::update_dictionary(unsigned int hash,
1730 InstanceKlass* k,
1731 Handle class_loader) {
1732 // Compile_lock prevents systemDictionary updates during compilations
1733 assert_locked_or_safepoint(Compile_lock);
1734 Symbol* name = k->name();
1735 ClassLoaderData *loader_data = class_loader_data(class_loader);
1736
1737 {
1738 MutexLocker mu1(SystemDictionary_lock);
1739
1740 // Make a new dictionary entry.
1741 Dictionary* dictionary = loader_data->dictionary();
1742 InstanceKlass* sd_check = dictionary->find_class(hash, name);
1743 if (sd_check == NULL__null) {
1744 dictionary->add_klass(hash, name, k);
1745 }
1746 SystemDictionary_lock->notify_all();
1747 }
1748}
1749
1750
1751// Try to find a class name using the loader constraints. The
1752// loader constraints might know about a class that isn't fully loaded
1753// yet and these will be ignored.
1754Klass* SystemDictionary::find_constrained_instance_or_array_klass(
1755 Thread* current, Symbol* class_name, Handle class_loader) {
1756
1757 // First see if it has been loaded directly.
1758 // Force the protection domain to be null. (This removes protection checks.)
1759 Handle no_protection_domain;
1760 Klass* klass = find_instance_or_array_klass(class_name, class_loader,
1761 no_protection_domain);
1762 if (klass != NULL__null)
1763 return klass;
1764
1765 // Now look to see if it has been loaded elsewhere, and is subject to
1766 // a loader constraint that would require this loader to return the
1767 // klass that is already loaded.
1768 if (Signature::is_array(class_name)) {
1769 // For array classes, their Klass*s are not kept in the
1770 // constraint table. The element Klass*s are.
1771 SignatureStream ss(class_name, false);
1772 int ndims = ss.skip_array_prefix(); // skip all '['s
1773 BasicType t = ss.type();
1774 if (t != T_OBJECT) {
1775 klass = Universe::typeArrayKlassObj(t);
1776 } else {
1777 MutexLocker mu(current, SystemDictionary_lock);
1778 klass = constraints()->find_constrained_klass(ss.as_symbol(), class_loader);
1779 }
1780 // If element class already loaded, allocate array klass
1781 if (klass != NULL__null) {
1782 klass = klass->array_klass_or_null(ndims);
1783 }
1784 } else {
1785 MutexLocker mu(current, SystemDictionary_lock);
1786 // Non-array classes are easy: simply check the constraint table.
1787 klass = constraints()->find_constrained_klass(class_name, class_loader);
1788 }
1789
1790 return klass;
1791}
1792
1793bool SystemDictionary::add_loader_constraint(Symbol* class_name,
1794 Klass* klass_being_linked,
1795 Handle class_loader1,
1796 Handle class_loader2) {
1797 ClassLoaderData* loader_data1 = class_loader_data(class_loader1);
1798 ClassLoaderData* loader_data2 = class_loader_data(class_loader2);
1799
1800 Symbol* constraint_name = NULL__null;
1801
1802 if (!Signature::is_array(class_name)) {
1803 constraint_name = class_name;
1804 } else {
1805 // For array classes, their Klass*s are not kept in the
1806 // constraint table. The element classes are.
1807 SignatureStream ss(class_name, false);
1808 ss.skip_array_prefix(); // skip all '['s
1809 if (!ss.has_envelope()) {
1810 return true; // primitive types always pass
1811 }
1812 constraint_name = ss.as_symbol();
1813 // Increment refcount to keep constraint_name alive after
1814 // SignatureStream is destructed. It will be decremented below
1815 // before returning.
1816 constraint_name->increment_refcount();
1817 }
1818
1819 Dictionary* dictionary1 = loader_data1->dictionary();
1820 unsigned int name_hash1 = dictionary1->compute_hash(constraint_name);
1821
1822 Dictionary* dictionary2 = loader_data2->dictionary();
1823 unsigned int name_hash2 = dictionary2->compute_hash(constraint_name);
1824
1825 {
1826 MutexLocker mu_s(SystemDictionary_lock);
1827 InstanceKlass* klass1 = dictionary1->find_class(name_hash1, constraint_name);
1828 InstanceKlass* klass2 = dictionary2->find_class(name_hash2, constraint_name);
1829 bool result = constraints()->add_entry(constraint_name, klass1, class_loader1,
1830 klass2, class_loader2);
1831#if INCLUDE_CDS1
1832 if (Arguments::is_dumping_archive() && klass_being_linked != NULL__null &&
1833 !klass_being_linked->is_shared()) {
1834 SystemDictionaryShared::record_linking_constraint(constraint_name,
1835 InstanceKlass::cast(klass_being_linked),
1836 class_loader1, class_loader2);
1837 }
1838#endif // INCLUDE_CDS
1839 if (Signature::is_array(class_name)) {
1840 constraint_name->decrement_refcount();
1841 }
1842 return result;
1843 }
1844}
1845
1846// Add entry to resolution error table to record the error when the first
1847// attempt to resolve a reference to a class has failed.
1848void SystemDictionary::add_resolution_error(const constantPoolHandle& pool, int which,
1849 Symbol* error, Symbol* message,
1850 Symbol* cause, Symbol* cause_msg) {
1851 unsigned int hash = resolution_errors()->compute_hash(pool, which);
1852 int index = resolution_errors()->hash_to_index(hash);
1853 {
1854 MutexLocker ml(Thread::current(), SystemDictionary_lock);
1855 ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
1856 if (entry == NULL__null) {
1857 resolution_errors()->add_entry(index, hash, pool, which, error, message, cause, cause_msg);
1858 }
1859 }
1860}
1861
1862// Delete a resolution error for RedefineClasses for a constant pool is going away
1863void SystemDictionary::delete_resolution_error(ConstantPool* pool) {
1864 resolution_errors()->delete_entry(pool);
1865}
1866
1867// Lookup resolution error table. Returns error if found, otherwise NULL.
1868Symbol* SystemDictionary::find_resolution_error(const constantPoolHandle& pool, int which,
1869 Symbol** message, Symbol** cause, Symbol** cause_msg) {
1870 unsigned int hash = resolution_errors()->compute_hash(pool, which);
1871 int index = resolution_errors()->hash_to_index(hash);
1872 {
1873 MutexLocker ml(Thread::current(), SystemDictionary_lock);
1874 ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
1875 if (entry != NULL__null) {
1876 *message = entry->message();
1877 *cause = entry->cause();
1878 *cause_msg = entry->cause_msg();
1879 return entry->error();
1880 } else {
1881 return NULL__null;
1882 }
1883 }
1884}
1885
1886// Add an entry to resolution error table to record an error in resolving or
1887// validating a nest host. This is used to construct informative error
1888// messages when IllegalAccessError's occur. If an entry already exists it will
1889// be updated with the nest host error message.
1890void SystemDictionary::add_nest_host_error(const constantPoolHandle& pool,
1891 int which,
1892 const char* message) {
1893 unsigned int hash = resolution_errors()->compute_hash(pool, which);
1894 int index = resolution_errors()->hash_to_index(hash);
1895 {
1896 MutexLocker ml(Thread::current(), SystemDictionary_lock);
1897 ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
1898 if (entry != NULL__null && entry->nest_host_error() == NULL__null) {
1899 // An existing entry means we had a true resolution failure (LinkageError) with our nest host, but we
1900 // still want to add the error message for the higher-level access checks to report. We should
1901 // only reach here under the same error condition, so we can ignore the potential race with setting
1902 // the message. If we see it is already set then we can ignore it.
1903 entry->set_nest_host_error(message);
1904 } else {
1905 resolution_errors()->add_entry(index, hash, pool, which, message);
1906 }
1907 }
1908}
1909
1910// Lookup any nest host error
1911const char* SystemDictionary::find_nest_host_error(const constantPoolHandle& pool, int which) {
1912 unsigned int hash = resolution_errors()->compute_hash(pool, which);
1913 int index = resolution_errors()->hash_to_index(hash);
1914 {
1915 MutexLocker ml(Thread::current(), SystemDictionary_lock);
1916 ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
1917 if (entry != NULL__null) {
1918 return entry->nest_host_error();
1919 } else {
1920 return NULL__null;
1921 }
1922 }
1923}
1924
1925
1926// Signature constraints ensure that callers and callees agree about
1927// the meaning of type names in their signatures. This routine is the
1928// intake for constraints. It collects them from several places:
1929//
1930// * LinkResolver::resolve_method (if check_access is true) requires
1931// that the resolving class (the caller) and the defining class of
1932// the resolved method (the callee) agree on each type in the
1933// method's signature.
1934//
1935// * LinkResolver::resolve_interface_method performs exactly the same
1936// checks.
1937//
1938// * LinkResolver::resolve_field requires that the constant pool
1939// attempting to link to a field agree with the field's defining
1940// class about the type of the field signature.
1941//
1942// * klassVtable::initialize_vtable requires that, when a class
1943// overrides a vtable entry allocated by a superclass, that the
1944// overriding method (i.e., the callee) agree with the superclass
1945// on each type in the method's signature.
1946//
1947// * klassItable::initialize_itable requires that, when a class fills
1948// in its itables, for each non-abstract method installed in an
1949// itable, the method (i.e., the callee) agree with the interface
1950// on each type in the method's signature.
1951//
1952// All those methods have a boolean (check_access, checkconstraints)
1953// which turns off the checks. This is used from specialized contexts
1954// such as bootstrapping, dumping, and debugging.
1955//
1956// No direct constraint is placed between the class and its
1957// supertypes. Constraints are only placed along linked relations
1958// between callers and callees. When a method overrides or implements
1959// an abstract method in a supertype (superclass or interface), the
1960// constraints are placed as if the supertype were the caller to the
1961// overriding method. (This works well, since callers to the
1962// supertype have already established agreement between themselves and
1963// the supertype.) As a result of all this, a class can disagree with
1964// its supertype about the meaning of a type name, as long as that
1965// class neither calls a relevant method of the supertype, nor is
1966// called (perhaps via an override) from the supertype.
1967//
1968//
1969// SystemDictionary::check_signature_loaders(sig, klass_being_linked, l1, l2)
1970//
1971// Make sure all class components (including arrays) in the given
1972// signature will be resolved to the same class in both loaders.
1973// Returns the name of the type that failed a loader constraint check, or
1974// NULL if no constraint failed. No exception except OOME is thrown.
1975// Arrays are not added to the loader constraint table, their elements are.
1976Symbol* SystemDictionary::check_signature_loaders(Symbol* signature,
1977 Klass* klass_being_linked,
1978 Handle loader1, Handle loader2,
1979 bool is_method) {
1980 // Nothing to do if loaders are the same.
1981 if (loader1() == loader2()) {
1982 return NULL__null;
1983 }
1984
1985 for (SignatureStream ss(signature, is_method); !ss.is_done(); ss.next()) {
1986 if (ss.is_reference()) {
1987 Symbol* sig = ss.as_symbol();
1988 // Note: In the future, if template-like types can take
1989 // arguments, we will want to recognize them and dig out class
1990 // names hiding inside the argument lists.
1991 if (!add_loader_constraint(sig, klass_being_linked, loader1, loader2)) {
1992 return sig;
1993 }
1994 }
1995 }
1996 return NULL__null;
1997}
1998
1999Method* SystemDictionary::find_method_handle_intrinsic(vmIntrinsicID iid,
2000 Symbol* signature,
2001 TRAPSJavaThread* __the_thread__) {
2002 methodHandle empty;
2003 const int iid_as_int = vmIntrinsics::as_int(iid);
2004 assert(MethodHandles::is_signature_polymorphic(iid) &&do { if (!(MethodHandles::is_signature_polymorphic(iid) &&
MethodHandles::is_signature_polymorphic_intrinsic(iid) &&
iid != vmIntrinsics::_invokeGeneric)) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2007, "assert(" "MethodHandles::is_signature_polymorphic(iid) && MethodHandles::is_signature_polymorphic_intrinsic(iid) && iid != vmIntrinsics::_invokeGeneric"
") failed", "must be a known MH intrinsic iid=%d: %s", iid_as_int
, vmIntrinsics::name_at(iid)); ::breakpoint(); } } while (0)
2005 MethodHandles::is_signature_polymorphic_intrinsic(iid) &&do { if (!(MethodHandles::is_signature_polymorphic(iid) &&
MethodHandles::is_signature_polymorphic_intrinsic(iid) &&
iid != vmIntrinsics::_invokeGeneric)) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2007, "assert(" "MethodHandles::is_signature_polymorphic(iid) && MethodHandles::is_signature_polymorphic_intrinsic(iid) && iid != vmIntrinsics::_invokeGeneric"
") failed", "must be a known MH intrinsic iid=%d: %s", iid_as_int
, vmIntrinsics::name_at(iid)); ::breakpoint(); } } while (0)
2006 iid != vmIntrinsics::_invokeGeneric,do { if (!(MethodHandles::is_signature_polymorphic(iid) &&
MethodHandles::is_signature_polymorphic_intrinsic(iid) &&
iid != vmIntrinsics::_invokeGeneric)) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2007, "assert(" "MethodHandles::is_signature_polymorphic(iid) && MethodHandles::is_signature_polymorphic_intrinsic(iid) && iid != vmIntrinsics::_invokeGeneric"
") failed", "must be a known MH intrinsic iid=%d: %s", iid_as_int
, vmIntrinsics::name_at(iid)); ::breakpoint(); } } while (0)
2007 "must be a known MH intrinsic iid=%d: %s", iid_as_int, vmIntrinsics::name_at(iid))do { if (!(MethodHandles::is_signature_polymorphic(iid) &&
MethodHandles::is_signature_polymorphic_intrinsic(iid) &&
iid != vmIntrinsics::_invokeGeneric)) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2007, "assert(" "MethodHandles::is_signature_polymorphic(iid) && MethodHandles::is_signature_polymorphic_intrinsic(iid) && iid != vmIntrinsics::_invokeGeneric"
") failed", "must be a known MH intrinsic iid=%d: %s", iid_as_int
, vmIntrinsics::name_at(iid)); ::breakpoint(); } } while (0)
;
2008
2009 unsigned int hash = invoke_method_table()->compute_hash(signature, iid_as_int);
2010 int index = invoke_method_table()->hash_to_index(hash);
2011 SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, iid_as_int);
2012 methodHandle m;
2013 if (spe == NULL__null || spe->method() == NULL__null) {
2014 spe = NULL__null;
2015 // Must create lots of stuff here, but outside of the SystemDictionary lock.
2016 m = Method::make_method_handle_intrinsic(iid, signature, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
2017 if (!Arguments::is_interpreter_only()) {
2018 // Generate a compiled form of the MH intrinsic.
2019 AdapterHandlerLibrary::create_native_wrapper(m);
2020 // Check if have the compiled code.
2021 if (!m->has_compiled_code()) {
2022 THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(),{ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2023, vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for method handle intrinsic"
); return __null; }
2023 "Out of space in CodeCache for method handle intrinsic"){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2023, vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for method handle intrinsic"
); return __null; }
;
2024 }
2025 }
2026 // Now grab the lock. We might have to throw away the new method,
2027 // if a racing thread has managed to install one at the same time.
2028 {
2029 MutexLocker ml(THREAD__the_thread__, SystemDictionary_lock);
2030 spe = invoke_method_table()->find_entry(index, hash, signature, iid_as_int);
2031 if (spe == NULL__null)
2032 spe = invoke_method_table()->add_entry(index, hash, signature, iid_as_int);
2033 if (spe->method() == NULL__null)
2034 spe->set_method(m());
2035 }
2036 }
2037
2038 assert(spe != NULL && spe->method() != NULL, "")do { if (!(spe != __null && spe->method() != __null
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2038, "assert(" "spe != __null && spe->method() != __null"
") failed", ""); ::breakpoint(); } } while (0)
;
2039 assert(Arguments::is_interpreter_only() || (spe->method()->has_compiled_code() &&do { if (!(Arguments::is_interpreter_only() || (spe->method
()->has_compiled_code() && spe->method()->code
()->entry_point() == spe->method()->from_compiled_entry
()))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2041, "assert(" "Arguments::is_interpreter_only() || (spe->method()->has_compiled_code() && spe->method()->code()->entry_point() == spe->method()->from_compiled_entry())"
") failed", "MH intrinsic invariant"); ::breakpoint(); } } while
(0)
2040 spe->method()->code()->entry_point() == spe->method()->from_compiled_entry()),do { if (!(Arguments::is_interpreter_only() || (spe->method
()->has_compiled_code() && spe->method()->code
()->entry_point() == spe->method()->from_compiled_entry
()))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2041, "assert(" "Arguments::is_interpreter_only() || (spe->method()->has_compiled_code() && spe->method()->code()->entry_point() == spe->method()->from_compiled_entry())"
") failed", "MH intrinsic invariant"); ::breakpoint(); } } while
(0)
2041 "MH intrinsic invariant")do { if (!(Arguments::is_interpreter_only() || (spe->method
()->has_compiled_code() && spe->method()->code
()->entry_point() == spe->method()->from_compiled_entry
()))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2041, "assert(" "Arguments::is_interpreter_only() || (spe->method()->has_compiled_code() && spe->method()->code()->entry_point() == spe->method()->from_compiled_entry())"
") failed", "MH intrinsic invariant"); ::breakpoint(); } } while
(0)
;
2042 return spe->method();
2043}
2044
2045// Helper for unpacking the return value from linkMethod and linkCallSite.
2046static Method* unpack_method_and_appendix(Handle mname,
2047 Klass* accessing_klass,
2048 objArrayHandle appendix_box,
2049 Handle* appendix_result,
2050 TRAPSJavaThread* __the_thread__) {
2051 if (mname.not_null()) {
2052 Method* m = java_lang_invoke_MemberName::vmtarget(mname());
2053 if (m != NULL__null) {
2054 oop appendix = appendix_box->obj_at(0);
2055 LogTarget(Info, methodhandles)LogTargetImpl<LogLevel::Info, (LogTag::_methodhandles), (LogTag
::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::
__NO_TAG), (LogTag::__NO_TAG)>
lt;
2056 if (lt.develop_is_enabled()) {
2057 ResourceMark rm(THREAD__the_thread__);
2058 LogStream ls(lt);
2059 ls.print("Linked method=" INTPTR_FORMAT"0x%016" "l" "x" ": ", p2i(m));
2060 m->print_on(&ls);
2061 if (appendix != NULL__null) { ls.print("appendix = "); appendix->print_on(&ls); }
2062 ls.cr();
2063 }
2064
2065 (*appendix_result) = Handle(THREAD__the_thread__, appendix);
2066 // the target is stored in the cpCache and if a reference to this
2067 // MemberName is dropped we need a way to make sure the
2068 // class_loader containing this method is kept alive.
2069 methodHandle mh(THREAD__the_thread__, m); // record_dependency can safepoint.
2070 ClassLoaderData* this_key = accessing_klass->class_loader_data();
2071 this_key->record_dependency(m->method_holder());
2072 return mh();
2073 }
2074 }
2075 THROW_MSG_NULL(vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives"){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2075, vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives"
); return __null; }
;
2076}
2077
2078Method* SystemDictionary::find_method_handle_invoker(Klass* klass,
2079 Symbol* name,
2080 Symbol* signature,
2081 Klass* accessing_klass,
2082 Handle *appendix_result,
2083 TRAPSJavaThread* __the_thread__) {
2084 assert(THREAD->can_call_java() ,"")do { if (!(__the_thread__->can_call_java())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2084, "assert(" "__the_thread__->can_call_java()" ") failed"
, ""); ::breakpoint(); } } while (0)
;
2085 Handle method_type =
2086 SystemDictionary::find_method_handle_type(signature, accessing_klass, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
2087
2088 int ref_kind = JVM_REF_invokeVirtual;
2089 oop name_oop = StringTable::intern(name, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
2090 Handle name_str (THREAD__the_thread__, name_oop);
2091 objArrayHandle appendix_box = oopFactory::new_objArray_handle(vmClasses::Object_klass(), 1, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
2092 assert(appendix_box->obj_at(0) == NULL, "")do { if (!(appendix_box->obj_at(0) == __null)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2092, "assert(" "appendix_box->obj_at(0) == __null" ") failed"
, ""); ::breakpoint(); } } while (0)
;
2093
2094 // This should not happen. JDK code should take care of that.
2095 if (accessing_klass == NULL__null || method_type.is_null()) {
2096 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "bad invokehandle"){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2096, vmSymbols::java_lang_InternalError(), "bad invokehandle"
); return __null; }
;
2097 }
2098
2099 // call java.lang.invoke.MethodHandleNatives::linkMethod(... String, MethodType) -> MemberName
2100 JavaCallArguments args;
2101 args.push_oop(Handle(THREAD__the_thread__, accessing_klass->java_mirror()));
2102 args.push_int(ref_kind);
2103 args.push_oop(Handle(THREAD__the_thread__, klass->java_mirror()));
2104 args.push_oop(name_str);
2105 args.push_oop(method_type);
2106 args.push_oop(appendix_box);
2107 JavaValue result(T_OBJECT);
2108 JavaCalls::call_static(&result,
2109 vmClasses::MethodHandleNatives_klass(),
2110 vmSymbols::linkMethod_name(),
2111 vmSymbols::linkMethod_signature(),
2112 &args, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return __null; (void)(0
);
2113 Handle mname(THREAD__the_thread__, result.get_oop());
2114 return unpack_method_and_appendix(mname, accessing_klass, appendix_box, appendix_result, THREAD__the_thread__);
2115}
2116
2117// Decide if we can globally cache a lookup of this class, to be returned to any client that asks.
2118// We must ensure that all class loaders everywhere will reach this class, for any client.
2119// This is a safe bet for public classes in java.lang, such as Object and String.
2120// We also include public classes in java.lang.invoke, because they appear frequently in system-level method types.
2121// Out of an abundance of caution, we do not include any other classes, not even for packages like java.util.
2122static bool is_always_visible_class(oop mirror) {
2123 Klass* klass = java_lang_Class::as_Klass(mirror);
2124 if (klass->is_objArray_klass()) {
2125 klass = ObjArrayKlass::cast(klass)->bottom_klass(); // check element type
2126 }
2127 if (klass->is_typeArray_klass()) {
2128 return true; // primitive array
2129 }
2130 assert(klass->is_instance_klass(), "%s", klass->external_name())do { if (!(klass->is_instance_klass())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2130, "assert(" "klass->is_instance_klass()" ") failed",
"%s", klass->external_name()); ::breakpoint(); } } while (
0)
;
2131 return klass->is_public() &&
2132 (InstanceKlass::cast(klass)->is_same_class_package(vmClasses::Object_klass()) || // java.lang
2133 InstanceKlass::cast(klass)->is_same_class_package(vmClasses::MethodHandle_klass())); // java.lang.invoke
2134}
2135
2136// Find or construct the Java mirror (java.lang.Class instance) for
2137// the given field type signature, as interpreted relative to the
2138// given class loader. Handles primitives, void, references, arrays,
2139// and all other reflectable types, except method types.
2140// N.B. Code in reflection should use this entry point.
2141Handle SystemDictionary::find_java_mirror_for_type(Symbol* signature,
2142 Klass* accessing_klass,
2143 Handle class_loader,
2144 Handle protection_domain,
2145 SignatureStream::FailureMode failure_mode,
2146 TRAPSJavaThread* __the_thread__) {
2147 assert(accessing_klass == NULL || (class_loader.is_null() && protection_domain.is_null()),do { if (!(accessing_klass == __null || (class_loader.is_null
() && protection_domain.is_null()))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2148, "assert(" "accessing_klass == __null || (class_loader.is_null() && protection_domain.is_null())"
") failed", "one or the other, or perhaps neither"); ::breakpoint
(); } } while (0)
2148 "one or the other, or perhaps neither")do { if (!(accessing_klass == __null || (class_loader.is_null
() && protection_domain.is_null()))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2148, "assert(" "accessing_klass == __null || (class_loader.is_null() && protection_domain.is_null())"
") failed", "one or the other, or perhaps neither"); ::breakpoint
(); } } while (0)
;
2149
2150 // What we have here must be a valid field descriptor,
2151 // and all valid field descriptors are supported.
2152 // Produce the same java.lang.Class that reflection reports.
2153 if (accessing_klass != NULL__null) {
2154 class_loader = Handle(THREAD__the_thread__, accessing_klass->class_loader());
2155 protection_domain = Handle(THREAD__the_thread__, accessing_klass->protection_domain());
2156 }
2157 ResolvingSignatureStream ss(signature, class_loader, protection_domain, false);
2158 oop mirror_oop = ss.as_java_mirror(failure_mode, CHECK_NH__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return Handle(); (void)(0
);
2159 if (mirror_oop == NULL__null) {
2160 return Handle(); // report failure this way
2161 }
2162 Handle mirror(THREAD__the_thread__, mirror_oop);
2163
2164 if (accessing_klass != NULL__null) {
2165 // Check accessibility, emulating ConstantPool::verify_constant_pool_resolve.
2166 Klass* sel_klass = java_lang_Class::as_Klass(mirror());
2167 if (sel_klass != NULL__null) {
2168 LinkResolver::check_klass_accessibility(accessing_klass, sel_klass, CHECK_NH__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return Handle(); (void)(0
);
2169 }
2170 }
2171 return mirror;
2172}
2173
2174
2175// Ask Java code to find or construct a java.lang.invoke.MethodType for the given
2176// signature, as interpreted relative to the given class loader.
2177// Because of class loader constraints, all method handle usage must be
2178// consistent with this loader.
2179Handle SystemDictionary::find_method_handle_type(Symbol* signature,
2180 Klass* accessing_klass,
2181 TRAPSJavaThread* __the_thread__) {
2182 Handle empty;
2183 int null_iid = vmIntrinsics::as_int(vmIntrinsics::_none); // distinct from all method handle invoker intrinsics
2184 unsigned int hash = invoke_method_table()->compute_hash(signature, null_iid);
2185 int index = invoke_method_table()->hash_to_index(hash);
2186 SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, null_iid);
2187 if (spe != NULL__null && spe->method_type() != NULL__null) {
2188 assert(java_lang_invoke_MethodType::is_instance(spe->method_type()), "")do { if (!(java_lang_invoke_MethodType::is_instance(spe->method_type
()))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2188, "assert(" "java_lang_invoke_MethodType::is_instance(spe->method_type())"
") failed", ""); ::breakpoint(); } } while (0)
;
2189 return Handle(THREAD__the_thread__, spe->method_type());
2190 } else if (!THREAD__the_thread__->can_call_java()) {
2191 warning("SystemDictionary::find_method_handle_type called from compiler thread"); // FIXME
2192 return Handle(); // do not attempt from within compiler, unless it was cached
2193 }
2194
2195 Handle class_loader, protection_domain;
2196 if (accessing_klass != NULL__null) {
2197 class_loader = Handle(THREAD__the_thread__, accessing_klass->class_loader());
2198 protection_domain = Handle(THREAD__the_thread__, accessing_klass->protection_domain());
2199 }
2200 bool can_be_cached = true;
2201 int npts = ArgumentCount(signature).size();
2202 objArrayHandle pts = oopFactory::new_objArray_handle(vmClasses::Class_klass(), npts, CHECK_(empty)__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return empty; (void)(0
);
2203 int arg = 0;
2204 Handle rt; // the return type from the signature
2205 ResourceMark rm(THREAD__the_thread__);
2206 for (SignatureStream ss(signature); !ss.is_done(); ss.next()) {
2207 oop mirror = NULL__null;
2208 if (can_be_cached) {
2209 // Use neutral class loader to lookup candidate classes to be placed in the cache.
2210 mirror = ss.as_java_mirror(Handle(), Handle(),
2211 SignatureStream::ReturnNull, CHECK_(empty)__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return empty; (void)(0
);
2212 if (mirror == NULL__null || (ss.is_reference() && !is_always_visible_class(mirror))) {
2213 // Fall back to accessing_klass context.
2214 can_be_cached = false;
2215 }
2216 }
2217 if (!can_be_cached) {
2218 // Resolve, throwing a real error if it doesn't work.
2219 mirror = ss.as_java_mirror(class_loader, protection_domain,
2220 SignatureStream::NCDFError, CHECK_(empty)__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return empty; (void)(0
);
2221 }
2222 assert(mirror != NULL, "%s", ss.as_symbol()->as_C_string())do { if (!(mirror != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2222, "assert(" "mirror != __null" ") failed", "%s", ss.as_symbol
()->as_C_string()); ::breakpoint(); } } while (0)
;
2223 if (ss.at_return_type())
2224 rt = Handle(THREAD__the_thread__, mirror);
2225 else
2226 pts->obj_at_put(arg++, mirror);
2227
2228 // Check accessibility.
2229 if (!java_lang_Class::is_primitive(mirror) && accessing_klass != NULL__null) {
2230 Klass* sel_klass = java_lang_Class::as_Klass(mirror);
2231 mirror = NULL__null; // safety
2232 // Emulate ConstantPool::verify_constant_pool_resolve.
2233 LinkResolver::check_klass_accessibility(accessing_klass, sel_klass, CHECK_(empty)__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return empty; (void)(0
);
2234 }
2235 }
2236 assert(arg == npts, "")do { if (!(arg == npts)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2236, "assert(" "arg == npts" ") failed", ""); ::breakpoint
(); } } while (0)
;
2237
2238 // call java.lang.invoke.MethodHandleNatives::findMethodHandleType(Class rt, Class[] pts) -> MethodType
2239 JavaCallArguments args(Handle(THREAD__the_thread__, rt()));
2240 args.push_oop(pts);
2241 JavaValue result(T_OBJECT);
2242 JavaCalls::call_static(&result,
2243 vmClasses::MethodHandleNatives_klass(),
2244 vmSymbols::findMethodHandleType_name(),
2245 vmSymbols::findMethodHandleType_signature(),
2246 &args, CHECK_(empty)__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return empty; (void)(0
);
2247 Handle method_type(THREAD__the_thread__, result.get_oop());
2248
2249 if (can_be_cached) {
2250 // We can cache this MethodType inside the JVM.
2251 MutexLocker ml(THREAD__the_thread__, SystemDictionary_lock);
2252 spe = invoke_method_table()->find_entry(index, hash, signature, null_iid);
2253 if (spe == NULL__null)
2254 spe = invoke_method_table()->add_entry(index, hash, signature, null_iid);
2255 if (spe->method_type() == NULL__null) {
2256 spe->set_method_type(method_type());
2257 }
2258 }
2259
2260 // report back to the caller with the MethodType
2261 return method_type;
2262}
2263
2264Handle SystemDictionary::find_field_handle_type(Symbol* signature,
2265 Klass* accessing_klass,
2266 TRAPSJavaThread* __the_thread__) {
2267 Handle empty;
2268 ResourceMark rm(THREAD__the_thread__);
2269 SignatureStream ss(signature, /*is_method=*/ false);
2270 if (!ss.is_done()) {
2271 Handle class_loader, protection_domain;
2272 if (accessing_klass != NULL__null) {
2273 class_loader = Handle(THREAD__the_thread__, accessing_klass->class_loader());
2274 protection_domain = Handle(THREAD__the_thread__, accessing_klass->protection_domain());
2275 }
2276 oop mirror = ss.as_java_mirror(class_loader, protection_domain, SignatureStream::NCDFError, CHECK_(empty)__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return empty; (void)(0
);
2277 ss.next();
2278 if (ss.is_done()) {
2279 return Handle(THREAD__the_thread__, mirror);
2280 }
2281 }
2282 return empty;
2283}
2284
2285// Ask Java code to find or construct a method handle constant.
2286Handle SystemDictionary::link_method_handle_constant(Klass* caller,
2287 int ref_kind, //e.g., JVM_REF_invokeVirtual
2288 Klass* callee,
2289 Symbol* name,
2290 Symbol* signature,
2291 TRAPSJavaThread* __the_thread__) {
2292 Handle empty;
2293 if (caller == NULL__null) {
2294 THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad MH constant", empty){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2294, vmSymbols::java_lang_InternalError(), "bad MH constant"
); return empty; }
;
2295 }
2296 Handle name_str = java_lang_String::create_from_symbol(name, CHECK_(empty)__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return empty; (void)(0
);
2297 Handle signature_str = java_lang_String::create_from_symbol(signature, CHECK_(empty)__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return empty; (void)(0
);
2298
2299 // Put symbolic info from the MH constant into freshly created MemberName and resolve it.
2300 Handle mname = vmClasses::MemberName_klass()->allocate_instance_handle(CHECK_(empty)__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return empty; (void)(0
);
2301 java_lang_invoke_MemberName::set_clazz(mname(), callee->java_mirror());
2302 java_lang_invoke_MemberName::set_name (mname(), name_str());
2303 java_lang_invoke_MemberName::set_type (mname(), signature_str());
2304 java_lang_invoke_MemberName::set_flags(mname(), MethodHandles::ref_kind_to_flags(ref_kind));
2305
2306 if (ref_kind == JVM_REF_invokeVirtual &&
2307 MethodHandles::is_signature_polymorphic_public_name(callee, name)) {
2308 // Skip resolution for public signature polymorphic methods such as
2309 // j.l.i.MethodHandle.invoke()/invokeExact() and those on VarHandle
2310 // They require appendix argument which MemberName resolution doesn't handle.
2311 // There's special logic on JDK side to handle them
2312 // (see MethodHandles.linkMethodHandleConstant() and MethodHandles.findVirtualForMH()).
2313 } else {
2314 MethodHandles::resolve_MemberName(mname, caller, 0, false /*speculative_resolve*/, CHECK_(empty)__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return empty; (void)(0
);
2315 }
2316
2317 // After method/field resolution succeeded, it's safe to resolve MH signature as well.
2318 Handle type = MethodHandles::resolve_MemberName_type(mname, caller, CHECK_(empty)__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return empty; (void)(0
);
2319
2320 // call java.lang.invoke.MethodHandleNatives::linkMethodHandleConstant(Class caller, int refKind, Class callee, String name, Object type) -> MethodHandle
2321 JavaCallArguments args;
2322 args.push_oop(Handle(THREAD__the_thread__, caller->java_mirror())); // the referring class
2323 args.push_int(ref_kind);
2324 args.push_oop(Handle(THREAD__the_thread__, callee->java_mirror())); // the target class
2325 args.push_oop(name_str);
2326 args.push_oop(type);
2327 JavaValue result(T_OBJECT);
2328 JavaCalls::call_static(&result,
2329 vmClasses::MethodHandleNatives_klass(),
2330 vmSymbols::linkMethodHandleConstant_name(),
2331 vmSymbols::linkMethodHandleConstant_signature(),
2332 &args, CHECK_(empty)__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return empty; (void)(0
);
2333 return Handle(THREAD__the_thread__, result.get_oop());
2334}
2335
2336// Ask Java to run a bootstrap method, in order to create a dynamic call site
2337// while linking an invokedynamic op, or compute a constant for Dynamic_info CP entry
2338// with linkage results being stored back into the bootstrap specifier.
2339void SystemDictionary::invoke_bootstrap_method(BootstrapInfo& bootstrap_specifier, TRAPSJavaThread* __the_thread__) {
2340 // Resolve the bootstrap specifier, its name, type, and static arguments
2341 bootstrap_specifier.resolve_bsm(CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0
);
2342
2343 // This should not happen. JDK code should take care of that.
2344 if (bootstrap_specifier.caller() == NULL__null || bootstrap_specifier.type_arg().is_null()) {
2345 THROW_MSG(vmSymbols::java_lang_InternalError(), "Invalid bootstrap method invocation with no caller or type argument"){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2345, vmSymbols::java_lang_InternalError(), "Invalid bootstrap method invocation with no caller or type argument"
); return; }
;
2346 }
2347
2348 bool is_indy = bootstrap_specifier.is_method_call();
2349 objArrayHandle appendix_box;
2350 if (is_indy) {
2351 // Some method calls may require an appendix argument. Arrange to receive it.
2352 appendix_box = oopFactory::new_objArray_handle(vmClasses::Object_klass(), 1, CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0
);
2353 assert(appendix_box->obj_at(0) == NULL, "")do { if (!(appendix_box->obj_at(0) == __null)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2353, "assert(" "appendix_box->obj_at(0) == __null" ") failed"
, ""); ::breakpoint(); } } while (0)
;
2354 }
2355
2356 // call condy: java.lang.invoke.MethodHandleNatives::linkDynamicConstant(caller, bsm, type, info)
2357 // indy: java.lang.invoke.MethodHandleNatives::linkCallSite(caller, bsm, name, mtype, info, &appendix)
2358 JavaCallArguments args;
2359 args.push_oop(Handle(THREAD__the_thread__, bootstrap_specifier.caller_mirror()));
2360 args.push_oop(bootstrap_specifier.bsm());
2361 args.push_oop(bootstrap_specifier.name_arg());
2362 args.push_oop(bootstrap_specifier.type_arg());
2363 args.push_oop(bootstrap_specifier.arg_values());
2364 if (is_indy) {
2365 args.push_oop(appendix_box);
2366 }
2367 JavaValue result(T_OBJECT);
2368 JavaCalls::call_static(&result,
2369 vmClasses::MethodHandleNatives_klass(),
2370 is_indy ? vmSymbols::linkCallSite_name() : vmSymbols::linkDynamicConstant_name(),
2371 is_indy ? vmSymbols::linkCallSite_signature() : vmSymbols::linkDynamicConstant_signature(),
2372 &args, CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0
);
2373
2374 Handle value(THREAD__the_thread__, result.get_oop());
2375 if (is_indy) {
2376 Handle appendix;
2377 Method* method = unpack_method_and_appendix(value,
2378 bootstrap_specifier.caller(),
2379 appendix_box,
2380 &appendix, CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception
())) return ; (void)(0
);
2381 methodHandle mh(THREAD__the_thread__, method);
2382 bootstrap_specifier.set_resolved_method(mh, appendix);
2383 } else {
2384 bootstrap_specifier.set_resolved_value(value);
2385 }
2386
2387 // sanity check
2388 assert(bootstrap_specifier.is_resolved() ||do { if (!(bootstrap_specifier.is_resolved() || (bootstrap_specifier
.is_method_call() && bootstrap_specifier.resolved_method
().not_null()))) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2390, "assert(" "bootstrap_specifier.is_resolved() || (bootstrap_specifier.is_method_call() && bootstrap_specifier.resolved_method().not_null())"
") failed", "bootstrap method call failed"); ::breakpoint();
} } while (0)
2389 (bootstrap_specifier.is_method_call() &&do { if (!(bootstrap_specifier.is_resolved() || (bootstrap_specifier
.is_method_call() && bootstrap_specifier.resolved_method
().not_null()))) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2390, "assert(" "bootstrap_specifier.is_resolved() || (bootstrap_specifier.is_method_call() && bootstrap_specifier.resolved_method().not_null())"
") failed", "bootstrap method call failed"); ::breakpoint();
} } while (0)
2390 bootstrap_specifier.resolved_method().not_null()), "bootstrap method call failed")do { if (!(bootstrap_specifier.is_resolved() || (bootstrap_specifier
.is_method_call() && bootstrap_specifier.resolved_method
().not_null()))) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2390, "assert(" "bootstrap_specifier.is_resolved() || (bootstrap_specifier.is_method_call() && bootstrap_specifier.resolved_method().not_null())"
") failed", "bootstrap method call failed"); ::breakpoint();
} } while (0)
;
2391}
2392
2393
2394ClassLoaderData* SystemDictionary::class_loader_data(Handle class_loader) {
2395 return ClassLoaderData::class_loader_data(class_loader());
2396}
2397
2398bool SystemDictionary::is_nonpublic_Object_method(Method* m) {
2399 assert(m != NULL, "Unexpected NULL Method*")do { if (!(m != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2399, "assert(" "m != __null" ") failed", "Unexpected NULL Method*"
); ::breakpoint(); } } while (0)
;
2400 return !m->is_public() && m->method_holder() == vmClasses::Object_klass();
2401}
2402
2403// ----------------------------------------------------------------------------
2404
2405void SystemDictionary::print_on(outputStream *st) {
2406 CDS_ONLY(SystemDictionaryShared::print_on(st))SystemDictionaryShared::print_on(st);
2407 GCMutexLocker mu(SystemDictionary_lock);
2408
2409 ClassLoaderDataGraph::print_dictionary(st);
2410
2411 // Placeholders
2412 placeholders()->print_on(st);
2413 st->cr();
2414
2415 // loader constraints - print under SD_lock
2416 constraints()->print_on(st);
2417 st->cr();
2418
2419 _pd_cache_table->print_on(st);
2420 st->cr();
2421}
2422
2423void SystemDictionary::print() { print_on(tty); }
2424
2425void SystemDictionary::verify() {
2426 guarantee(constraints() != NULL,do { if (!(constraints() != __null)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2427, "guarantee(" "constraints() != NULL" ") failed", "Verify of loader constraints failed"
); ::breakpoint(); } } while (0)
2427 "Verify of loader constraints failed")do { if (!(constraints() != __null)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2427, "guarantee(" "constraints() != NULL" ") failed", "Verify of loader constraints failed"
); ::breakpoint(); } } while (0)
;
2428 guarantee(placeholders()->number_of_entries() >= 0,do { if (!(placeholders()->number_of_entries() >= 0)) {
(*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2429, "guarantee(" "placeholders()->number_of_entries() >= 0"
") failed", "Verify of placeholders failed"); ::breakpoint()
; } } while (0)
2429 "Verify of placeholders failed")do { if (!(placeholders()->number_of_entries() >= 0)) {
(*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2429, "guarantee(" "placeholders()->number_of_entries() >= 0"
") failed", "Verify of placeholders failed"); ::breakpoint()
; } } while (0)
;
2430
2431 GCMutexLocker mu(SystemDictionary_lock);
2432
2433 // Verify dictionary
2434 ClassLoaderDataGraph::verify_dictionary();
2435
2436 placeholders()->verify();
2437
2438 // Verify constraint table
2439 guarantee(constraints() != NULL, "Verify of loader constraints failed")do { if (!(constraints() != __null)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/classfile/systemDictionary.cpp"
, 2439, "guarantee(" "constraints() != NULL" ") failed", "Verify of loader constraints failed"
); ::breakpoint(); } } while (0)
;
2440 constraints()->verify(placeholders());
2441
2442 _pd_cache_table->verify();
2443}
2444
2445void SystemDictionary::dump(outputStream *st, bool verbose) {
2446 assert_locked_or_safepoint(SystemDictionary_lock);
2447 if (verbose) {
2448 print_on(st);
2449 } else {
2450 CDS_ONLY(SystemDictionaryShared::print_table_statistics(st))SystemDictionaryShared::print_table_statistics(st);
2451 ClassLoaderDataGraph::print_table_statistics(st);
2452 placeholders()->print_table_statistics(st, "Placeholder Table");
2453 constraints()->print_table_statistics(st, "LoaderConstraints Table");
2454 pd_cache_table()->print_table_statistics(st, "ProtectionDomainCache Table");
2455 }
2456}
2457
2458TableStatistics SystemDictionary::placeholders_statistics() {
2459 MutexLocker ml(SystemDictionary_lock);
2460 return placeholders()->statistics_calculate();
2461}
2462
2463TableStatistics SystemDictionary::loader_constraints_statistics() {
2464 MutexLocker ml(SystemDictionary_lock);
2465 return constraints()->statistics_calculate();
2466}
2467
2468TableStatistics SystemDictionary::protection_domain_cache_statistics() {
2469 MutexLocker ml(SystemDictionary_lock);
2470 return pd_cache_table()->statistics_calculate();
2471}
2472
2473// Utility for dumping dictionaries.
2474SystemDictionaryDCmd::SystemDictionaryDCmd(outputStream* output, bool heap) :
2475 DCmdWithParser(output, heap),
2476 _verbose("-verbose", "Dump the content of each dictionary entry for all class loaders",
2477 "BOOLEAN", false, "false") {
2478 _dcmdparser.add_dcmd_option(&_verbose);
2479}
2480
2481void SystemDictionaryDCmd::execute(DCmdSource source, TRAPSJavaThread* __the_thread__) {
2482 VM_DumpHashtable dumper(output(), VM_DumpHashtable::DumpSysDict,
2483 _verbose.value());
2484 VMThread::execute(&dumper);
2485}