58 // can read the dictionary unlocked. This is safe because
59 // - entries are only deleted when the class loader is not alive, when the
60 // entire dictionary is deleted.
61 // - entries must be fully formed before they are available to concurrent
62 // readers (we must ensure write ordering)
63 //
64 // Note that placeholders are deleted at any time, as they are removed
65 // when a class is completely loaded. Therefore, readers as well as writers
66 // of placeholders must hold the SystemDictionary_lock.
67 //
68
69 class BootstrapInfo;
70 class ClassFileStream;
71 class ClassLoadInfo;
72 class Dictionary;
73 class PackageEntry;
74 class GCTimer;
75 class EventClassLoad;
76 class Symbol;
77
78 class SystemDictionary : AllStatic {
79 friend class BootstrapInfo;
80 friend class vmClasses;
81 friend class VMStructs;
82
83 public:
84
85 // Returns a class with a given class name and class loader. Loads the
86 // class if needed. If not found a NoClassDefFoundError or a
87 // ClassNotFoundException is thrown, depending on the value on the
88 // throw_error flag. For most uses the throw_error argument should be set
89 // to true.
90
91 static Klass* resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS);
92 // Convenient call for null loader and protection domain.
93 static Klass* resolve_or_fail(Symbol* class_name, bool throw_error, TRAPS) {
94 return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
95 }
96
97 // Returns a class with a given class name and class loader.
98 // Loads the class if needed. If not found null is returned.
222 static void set_platform_loader(ClassLoaderData *cld);
223
224 static Symbol* check_signature_loaders(Symbol* signature, Klass* klass_being_linked,
225 Handle loader1, Handle loader2, bool is_method);
226
227 // JSR 292
228 // find a java.lang.invoke.MethodHandle.invoke* method for a given signature
229 // (asks Java to compute it if necessary, except in a compiler thread)
230 static Method* find_method_handle_invoker(Klass* klass,
231 Symbol* name,
232 Symbol* signature,
233 Klass* accessing_klass,
234 Handle *appendix_result,
235 TRAPS);
236 // for a given signature, find the internal MethodHandle method (linkTo* or invokeBasic)
237 // (does not ask Java, since this is a low-level intrinsic defined by the JVM)
238 static Method* find_method_handle_intrinsic(vmIntrinsicID iid,
239 Symbol* signature,
240 TRAPS);
241
242 // compute java_mirror (java.lang.Class instance) for a type ("I", "[[B", "LFoo;", etc.)
243 // Either the accessing_klass or the CL/PD can be non-null, but not both.
244 static Handle find_java_mirror_for_type(Symbol* signature,
245 Klass* accessing_klass,
246 Handle class_loader,
247 Handle protection_domain,
248 SignatureStream::FailureMode failure_mode,
249 TRAPS);
250 static Handle find_java_mirror_for_type(Symbol* signature,
251 Klass* accessing_klass,
252 SignatureStream::FailureMode failure_mode,
253 TRAPS) {
254 // callee will fill in CL/PD from AK, if they are needed
255 return find_java_mirror_for_type(signature, accessing_klass, Handle(), Handle(),
256 failure_mode, THREAD);
257 }
258
259 // find a java.lang.invoke.MethodType object for a given signature
260 // (asks Java to compute it if necessary, except in a compiler thread)
261 static Handle find_method_handle_type(Symbol* signature,
276 TRAPS);
277
278 // ask Java to compute a constant by invoking a BSM given a Dynamic_info CP entry
279 static void invoke_bootstrap_method(BootstrapInfo& bootstrap_specifier, TRAPS);
280
281 // Record the error when the first attempt to resolve a reference from a constant
282 // pool entry to a class fails.
283 static void add_resolution_error(const constantPoolHandle& pool, int which,
284 Symbol* error, const char* message,
285 Symbol* cause = nullptr, const char* cause_msg = nullptr);
286 static void delete_resolution_error(ConstantPool* pool);
287 static Symbol* find_resolution_error(const constantPoolHandle& pool, int which,
288 const char** message,
289 Symbol** cause, const char** cause_msg);
290
291 // Record a nest host resolution/validation error
292 static void add_nest_host_error(const constantPoolHandle& pool, int which,
293 const char* message);
294 static const char* find_nest_host_error(const constantPoolHandle& pool, int which);
295
296 static OopHandle _java_system_loader;
297 static OopHandle _java_platform_loader;
298
299 private:
300 // Basic loading operations
301 static InstanceKlass* resolve_instance_class_or_null(Symbol* class_name,
302 Handle class_loader,
303 Handle protection_domain, TRAPS);
304 static Klass* resolve_array_class_or_null(Symbol* class_name,
305 Handle class_loader,
306 Handle protection_domain, TRAPS);
307 static void define_instance_class(InstanceKlass* k, Handle class_loader, TRAPS);
308 static InstanceKlass* find_or_define_helper(Symbol* class_name,
309 Handle class_loader,
310 InstanceKlass* k, TRAPS);
311 static InstanceKlass* load_instance_class_impl(Symbol* class_name, Handle class_loader, TRAPS);
312 static InstanceKlass* load_instance_class(Symbol* class_name,
313 Handle class_loader, TRAPS);
314
315 // Class loader constraints
316 static void check_constraints(InstanceKlass* k, ClassLoaderData* loader,
317 bool defining, TRAPS);
318 static void update_dictionary(JavaThread* current, InstanceKlass* k, ClassLoaderData* loader_data);
319
320 static bool is_shared_class_visible(Symbol* class_name, InstanceKlass* ik,
321 PackageEntry* pkg_entry,
322 Handle class_loader);
323 static bool is_shared_class_visible_impl(Symbol* class_name,
324 InstanceKlass* ik,
325 PackageEntry* pkg_entry,
326 Handle class_loader);
327 static bool check_shared_class_super_type(InstanceKlass* klass, InstanceKlass* super,
328 Handle class_loader, Handle protection_domain,
329 bool is_superclass, TRAPS);
330 static bool check_shared_class_super_types(InstanceKlass* ik, Handle class_loader,
331 Handle protection_domain, TRAPS);
332 // Second part of load_shared_class
333 static void load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) NOT_CDS_RETURN;
334
335 protected:
336 // Used by SystemDictionaryShared
337
338 static bool add_loader_constraint(Symbol* name, Klass* klass_being_linked, Handle loader1,
339 Handle loader2);
340 static void post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld);
341 static InstanceKlass* load_shared_lambda_proxy_class(InstanceKlass* ik,
342 Handle class_loader,
343 Handle protection_domain,
344 PackageEntry* pkg_entry,
345 TRAPS);
346 static InstanceKlass* load_shared_class(InstanceKlass* ik,
347 Handle class_loader,
348 Handle protection_domain,
349 const ClassFileStream *cfs,
350 PackageEntry* pkg_entry,
351 TRAPS);
352 static Handle get_loader_lock_or_null(Handle class_loader);
353 static InstanceKlass* find_or_define_instance_class(Symbol* class_name,
354 Handle class_loader,
355 InstanceKlass* k, TRAPS);
356 public:
357 static bool is_system_class_loader(oop class_loader);
|
58 // can read the dictionary unlocked. This is safe because
59 // - entries are only deleted when the class loader is not alive, when the
60 // entire dictionary is deleted.
61 // - entries must be fully formed before they are available to concurrent
62 // readers (we must ensure write ordering)
63 //
64 // Note that placeholders are deleted at any time, as they are removed
65 // when a class is completely loaded. Therefore, readers as well as writers
66 // of placeholders must hold the SystemDictionary_lock.
67 //
68
69 class BootstrapInfo;
70 class ClassFileStream;
71 class ClassLoadInfo;
72 class Dictionary;
73 class PackageEntry;
74 class GCTimer;
75 class EventClassLoad;
76 class Symbol;
77
78 template <class E> class GrowableArray;
79
80 class SystemDictionary : AllStatic {
81 friend class AOTLinkedClassBulkLoader;
82 friend class BootstrapInfo;
83 friend class vmClasses;
84 friend class VMStructs;
85
86 public:
87
88 // Returns a class with a given class name and class loader. Loads the
89 // class if needed. If not found a NoClassDefFoundError or a
90 // ClassNotFoundException is thrown, depending on the value on the
91 // throw_error flag. For most uses the throw_error argument should be set
92 // to true.
93
94 static Klass* resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS);
95 // Convenient call for null loader and protection domain.
96 static Klass* resolve_or_fail(Symbol* class_name, bool throw_error, TRAPS) {
97 return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
98 }
99
100 // Returns a class with a given class name and class loader.
101 // Loads the class if needed. If not found null is returned.
225 static void set_platform_loader(ClassLoaderData *cld);
226
227 static Symbol* check_signature_loaders(Symbol* signature, Klass* klass_being_linked,
228 Handle loader1, Handle loader2, bool is_method);
229
230 // JSR 292
231 // find a java.lang.invoke.MethodHandle.invoke* method for a given signature
232 // (asks Java to compute it if necessary, except in a compiler thread)
233 static Method* find_method_handle_invoker(Klass* klass,
234 Symbol* name,
235 Symbol* signature,
236 Klass* accessing_klass,
237 Handle *appendix_result,
238 TRAPS);
239 // for a given signature, find the internal MethodHandle method (linkTo* or invokeBasic)
240 // (does not ask Java, since this is a low-level intrinsic defined by the JVM)
241 static Method* find_method_handle_intrinsic(vmIntrinsicID iid,
242 Symbol* signature,
243 TRAPS);
244
245 static void get_all_method_handle_intrinsics(GrowableArray<Method*>* methods) NOT_CDS_RETURN;
246 static void restore_archived_method_handle_intrinsics() NOT_CDS_RETURN;
247
248 // compute java_mirror (java.lang.Class instance) for a type ("I", "[[B", "LFoo;", etc.)
249 // Either the accessing_klass or the CL/PD can be non-null, but not both.
250 static Handle find_java_mirror_for_type(Symbol* signature,
251 Klass* accessing_klass,
252 Handle class_loader,
253 Handle protection_domain,
254 SignatureStream::FailureMode failure_mode,
255 TRAPS);
256 static Handle find_java_mirror_for_type(Symbol* signature,
257 Klass* accessing_klass,
258 SignatureStream::FailureMode failure_mode,
259 TRAPS) {
260 // callee will fill in CL/PD from AK, if they are needed
261 return find_java_mirror_for_type(signature, accessing_klass, Handle(), Handle(),
262 failure_mode, THREAD);
263 }
264
265 // find a java.lang.invoke.MethodType object for a given signature
266 // (asks Java to compute it if necessary, except in a compiler thread)
267 static Handle find_method_handle_type(Symbol* signature,
282 TRAPS);
283
284 // ask Java to compute a constant by invoking a BSM given a Dynamic_info CP entry
285 static void invoke_bootstrap_method(BootstrapInfo& bootstrap_specifier, TRAPS);
286
287 // Record the error when the first attempt to resolve a reference from a constant
288 // pool entry to a class fails.
289 static void add_resolution_error(const constantPoolHandle& pool, int which,
290 Symbol* error, const char* message,
291 Symbol* cause = nullptr, const char* cause_msg = nullptr);
292 static void delete_resolution_error(ConstantPool* pool);
293 static Symbol* find_resolution_error(const constantPoolHandle& pool, int which,
294 const char** message,
295 Symbol** cause, const char** cause_msg);
296
297 // Record a nest host resolution/validation error
298 static void add_nest_host_error(const constantPoolHandle& pool, int which,
299 const char* message);
300 static const char* find_nest_host_error(const constantPoolHandle& pool, int which);
301
302 static void add_to_initiating_loader(JavaThread* current, InstanceKlass* k,
303 ClassLoaderData* loader_data) NOT_CDS_RETURN;
304 protected:
305 static InstanceKlass* _well_known_klasses[];
306
307 private:
308 // table of box klasses (int_klass, etc.)
309 static InstanceKlass* _box_klasses[T_VOID+1];
310
311 static OopHandle _java_system_loader;
312 static OopHandle _java_platform_loader;
313
314 private:
315 // Basic loading operations
316 static InstanceKlass* resolve_instance_class_or_null(Symbol* class_name,
317 Handle class_loader,
318 Handle protection_domain, TRAPS);
319 static Klass* resolve_array_class_or_null(Symbol* class_name,
320 Handle class_loader,
321 Handle protection_domain, TRAPS);
322 static void define_instance_class(InstanceKlass* k, Handle class_loader, TRAPS);
323 static InstanceKlass* find_or_define_helper(Symbol* class_name,
324 Handle class_loader,
325 InstanceKlass* k, TRAPS);
326 static InstanceKlass* load_instance_class_impl(Symbol* class_name, Handle class_loader, TRAPS);
327 static InstanceKlass* load_instance_class(Symbol* class_name,
328 Handle class_loader, TRAPS);
329
330 // Class loader constraints
331 static void check_constraints(InstanceKlass* k, ClassLoaderData* loader,
332 bool defining, TRAPS);
333 static void update_dictionary(JavaThread* current, InstanceKlass* k, ClassLoaderData* loader_data);
334
335 static bool is_shared_class_visible(Symbol* class_name, InstanceKlass* ik,
336 PackageEntry* pkg_entry,
337 Handle class_loader);
338 static bool is_shared_class_visible_impl(Symbol* class_name,
339 InstanceKlass* ik,
340 PackageEntry* pkg_entry,
341 Handle class_loader);
342 static bool check_shared_class_super_type(InstanceKlass* klass, InstanceKlass* super,
343 Handle class_loader, Handle protection_domain,
344 bool is_superclass, TRAPS);
345 static bool check_shared_class_super_types(InstanceKlass* ik, Handle class_loader,
346 Handle protection_domain, TRAPS);
347 static void restore_archived_method_handle_intrinsics_impl(TRAPS);
348
349 protected:
350 // Used by SystemDictionaryShared
351
352 // Second part of load_shared_class
353 static void load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) NOT_CDS_RETURN;
354
355 static bool add_loader_constraint(Symbol* name, Klass* klass_being_linked, Handle loader1,
356 Handle loader2);
357 static void post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld);
358 static InstanceKlass* load_shared_lambda_proxy_class(InstanceKlass* ik,
359 Handle class_loader,
360 Handle protection_domain,
361 PackageEntry* pkg_entry,
362 TRAPS);
363 static InstanceKlass* load_shared_class(InstanceKlass* ik,
364 Handle class_loader,
365 Handle protection_domain,
366 const ClassFileStream *cfs,
367 PackageEntry* pkg_entry,
368 TRAPS);
369 static Handle get_loader_lock_or_null(Handle class_loader);
370 static InstanceKlass* find_or_define_instance_class(Symbol* class_name,
371 Handle class_loader,
372 InstanceKlass* k, TRAPS);
373 public:
374 static bool is_system_class_loader(oop class_loader);
|