< prev index next >

src/hotspot/share/classfile/systemDictionary.hpp

Print this page

 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.
 99   static Klass* resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);

214   static void set_platform_loader(ClassLoaderData *cld);
215 
216   static Symbol* check_signature_loaders(Symbol* signature, Klass* klass_being_linked,
217                                          Handle loader1, Handle loader2, bool is_method);
218 
219   // JSR 292
220   // find a java.lang.invoke.MethodHandle.invoke* method for a given signature
221   // (asks Java to compute it if necessary, except in a compiler thread)
222   static Method* find_method_handle_invoker(Klass* klass,
223                                             Symbol* name,
224                                             Symbol* signature,
225                                             Klass* accessing_klass,
226                                             Handle *appendix_result,
227                                             TRAPS);
228   // for a given signature, find the internal MethodHandle method (linkTo* or invokeBasic)
229   // (does not ask Java, since this is a low-level intrinsic defined by the JVM)
230   static Method* find_method_handle_intrinsic(vmIntrinsicID iid,
231                                               Symbol* signature,
232                                               TRAPS);
233 



234   // compute java_mirror (java.lang.Class instance) for a type ("I", "[[B", "LFoo;", etc.)
235   // Either the accessing_klass or the CL/PD can be non-null, but not both.
236   static Handle    find_java_mirror_for_type(Symbol* signature,
237                                              Klass* accessing_klass,
238                                              Handle class_loader,
239                                              Handle protection_domain,
240                                              SignatureStream::FailureMode failure_mode,
241                                              TRAPS);
242   static Handle    find_java_mirror_for_type(Symbol* signature,
243                                              Klass* accessing_klass,
244                                              SignatureStream::FailureMode failure_mode,
245                                              TRAPS) {
246     // callee will fill in CL/PD from AK, if they are needed
247     return find_java_mirror_for_type(signature, accessing_klass, Handle(), Handle(),
248                                      failure_mode, THREAD);
249   }
250 
251   // find a java.lang.invoke.MethodType object for a given signature
252   // (asks Java to compute it if necessary, except in a compiler thread)
253   static Handle    find_method_handle_type(Symbol* signature,

268                                                TRAPS);
269 
270   // ask Java to compute a constant by invoking a BSM given a Dynamic_info CP entry
271   static void      invoke_bootstrap_method(BootstrapInfo& bootstrap_specifier, TRAPS);
272 
273   // Record the error when the first attempt to resolve a reference from a constant
274   // pool entry to a class fails.
275   static void add_resolution_error(const constantPoolHandle& pool, int which,
276                                    Symbol* error, const char* message,
277                                    Symbol* cause = nullptr, const char* cause_msg = nullptr);
278   static void delete_resolution_error(ConstantPool* pool);
279   static Symbol* find_resolution_error(const constantPoolHandle& pool, int which,
280                                        const char** message,
281                                        Symbol** cause, const char** cause_msg);
282 
283   // Record a nest host resolution/validation error
284   static void add_nest_host_error(const constantPoolHandle& pool, int which,
285                                   const char* message);
286   static const char* find_nest_host_error(const constantPoolHandle& pool, int which);
287 


288 protected:
289   static InstanceKlass* _well_known_klasses[];
290 
291 private:
292   // table of box klasses (int_klass, etc.)
293   static InstanceKlass* _box_klasses[T_VOID+1];
294 
295   static OopHandle  _java_system_loader;
296   static OopHandle  _java_platform_loader;
297 
298 private:
299   // Basic loading operations
300   static InstanceKlass* resolve_instance_class_or_null(Symbol* class_name,
301                                                        Handle class_loader,
302                                                        Handle protection_domain, TRAPS);
303   static Klass* resolve_array_class_or_null(Symbol* class_name,
304                                             Handle class_loader,
305                                             Handle protection_domain, TRAPS);
306   static void define_instance_class(InstanceKlass* k, Handle class_loader, TRAPS);
307   static InstanceKlass* find_or_define_helper(Symbol* class_name,

311   static InstanceKlass* load_instance_class(Symbol* class_name,
312                                             Handle class_loader, TRAPS);
313 
314   // Class loader constraints
315   static void check_constraints(InstanceKlass* k, ClassLoaderData* loader,
316                                 bool defining, TRAPS);
317   static void update_dictionary(JavaThread* current, InstanceKlass* k, ClassLoaderData* loader_data);
318 
319   static bool is_shared_class_visible(Symbol* class_name, InstanceKlass* ik,
320                                       PackageEntry* pkg_entry,
321                                       Handle class_loader);
322   static bool is_shared_class_visible_impl(Symbol* class_name,
323                                            InstanceKlass* ik,
324                                            PackageEntry* pkg_entry,
325                                            Handle class_loader);
326   static bool check_shared_class_super_type(InstanceKlass* klass, InstanceKlass* super,
327                                             Handle class_loader,  Handle protection_domain,
328                                             bool is_superclass, TRAPS);
329   static bool check_shared_class_super_types(InstanceKlass* ik, Handle class_loader,
330                                                Handle protection_domain, TRAPS);
331   // Second part of load_shared_class
332   static void load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) NOT_CDS_RETURN;
333 
334 protected:
335   // Used by SystemDictionaryShared
336 



337   static bool add_loader_constraint(Symbol* name, Klass* klass_being_linked,  Handle loader1,
338                                     Handle loader2);
339   static void post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld);
340   static InstanceKlass* load_shared_lambda_proxy_class(InstanceKlass* ik,
341                                                        Handle class_loader,
342                                                        Handle protection_domain,
343                                                        PackageEntry* pkg_entry,
344                                                        TRAPS);
345   static InstanceKlass* load_shared_class(InstanceKlass* ik,
346                                           Handle class_loader,
347                                           Handle protection_domain,
348                                           const ClassFileStream *cfs,
349                                           PackageEntry* pkg_entry,
350                                           TRAPS);
351   static Handle get_loader_lock_or_null(Handle class_loader);
352   static InstanceKlass* find_or_define_instance_class(Symbol* class_name,
353                                                       Handle class_loader,
354                                                       InstanceKlass* k, TRAPS);
355 public:
356   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 BootstrapInfo;
 82   friend class ClassPrelinker;
 83   friend class ClassPreloader;
 84   friend class vmClasses;
 85   friend class VMStructs;
 86 
 87  public:
 88 
 89   // Returns a class with a given class name and class loader.  Loads the
 90   // class if needed. If not found a NoClassDefFoundError or a
 91   // ClassNotFoundException is thrown, depending on the value on the
 92   // throw_error flag.  For most uses the throw_error argument should be set
 93   // to true.
 94 
 95   static Klass* resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS);
 96   // Convenient call for null loader and protection domain.
 97   static Klass* resolve_or_fail(Symbol* class_name, bool throw_error, TRAPS) {
 98     return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
 99   }
100 
101   // Returns a class with a given class name and class loader.
102   // Loads the class if needed. If not found null is returned.
103   static Klass* resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);

218   static void set_platform_loader(ClassLoaderData *cld);
219 
220   static Symbol* check_signature_loaders(Symbol* signature, Klass* klass_being_linked,
221                                          Handle loader1, Handle loader2, bool is_method);
222 
223   // JSR 292
224   // find a java.lang.invoke.MethodHandle.invoke* method for a given signature
225   // (asks Java to compute it if necessary, except in a compiler thread)
226   static Method* find_method_handle_invoker(Klass* klass,
227                                             Symbol* name,
228                                             Symbol* signature,
229                                             Klass* accessing_klass,
230                                             Handle *appendix_result,
231                                             TRAPS);
232   // for a given signature, find the internal MethodHandle method (linkTo* or invokeBasic)
233   // (does not ask Java, since this is a low-level intrinsic defined by the JVM)
234   static Method* find_method_handle_intrinsic(vmIntrinsicID iid,
235                                               Symbol* signature,
236                                               TRAPS);
237 
238   static void get_all_method_handle_intrinsics(GrowableArray<Method*>* methods) NOT_CDS_RETURN;
239   static void restore_archived_method_handle_intrinsics() NOT_CDS_RETURN;
240 
241   // compute java_mirror (java.lang.Class instance) for a type ("I", "[[B", "LFoo;", etc.)
242   // Either the accessing_klass or the CL/PD can be non-null, but not both.
243   static Handle    find_java_mirror_for_type(Symbol* signature,
244                                              Klass* accessing_klass,
245                                              Handle class_loader,
246                                              Handle protection_domain,
247                                              SignatureStream::FailureMode failure_mode,
248                                              TRAPS);
249   static Handle    find_java_mirror_for_type(Symbol* signature,
250                                              Klass* accessing_klass,
251                                              SignatureStream::FailureMode failure_mode,
252                                              TRAPS) {
253     // callee will fill in CL/PD from AK, if they are needed
254     return find_java_mirror_for_type(signature, accessing_klass, Handle(), Handle(),
255                                      failure_mode, THREAD);
256   }
257 
258   // find a java.lang.invoke.MethodType object for a given signature
259   // (asks Java to compute it if necessary, except in a compiler thread)
260   static Handle    find_method_handle_type(Symbol* signature,

275                                                TRAPS);
276 
277   // ask Java to compute a constant by invoking a BSM given a Dynamic_info CP entry
278   static void      invoke_bootstrap_method(BootstrapInfo& bootstrap_specifier, TRAPS);
279 
280   // Record the error when the first attempt to resolve a reference from a constant
281   // pool entry to a class fails.
282   static void add_resolution_error(const constantPoolHandle& pool, int which,
283                                    Symbol* error, const char* message,
284                                    Symbol* cause = nullptr, const char* cause_msg = nullptr);
285   static void delete_resolution_error(ConstantPool* pool);
286   static Symbol* find_resolution_error(const constantPoolHandle& pool, int which,
287                                        const char** message,
288                                        Symbol** cause, const char** cause_msg);
289 
290   // Record a nest host resolution/validation error
291   static void add_nest_host_error(const constantPoolHandle& pool, int which,
292                                   const char* message);
293   static const char* find_nest_host_error(const constantPoolHandle& pool, int which);
294 
295   static void preload_class(JavaThread* current,  InstanceKlass* k,
296                             ClassLoaderData* loader_data) NOT_CDS_RETURN;
297 protected:
298   static InstanceKlass* _well_known_klasses[];
299 
300 private:
301   // table of box klasses (int_klass, etc.)
302   static InstanceKlass* _box_klasses[T_VOID+1];
303 
304   static OopHandle  _java_system_loader;
305   static OopHandle  _java_platform_loader;
306 
307 private:
308   // Basic loading operations
309   static InstanceKlass* resolve_instance_class_or_null(Symbol* class_name,
310                                                        Handle class_loader,
311                                                        Handle protection_domain, TRAPS);
312   static Klass* resolve_array_class_or_null(Symbol* class_name,
313                                             Handle class_loader,
314                                             Handle protection_domain, TRAPS);
315   static void define_instance_class(InstanceKlass* k, Handle class_loader, TRAPS);
316   static InstanceKlass* find_or_define_helper(Symbol* class_name,

320   static InstanceKlass* load_instance_class(Symbol* class_name,
321                                             Handle class_loader, TRAPS);
322 
323   // Class loader constraints
324   static void check_constraints(InstanceKlass* k, ClassLoaderData* loader,
325                                 bool defining, TRAPS);
326   static void update_dictionary(JavaThread* current, InstanceKlass* k, ClassLoaderData* loader_data);
327 
328   static bool is_shared_class_visible(Symbol* class_name, InstanceKlass* ik,
329                                       PackageEntry* pkg_entry,
330                                       Handle class_loader);
331   static bool is_shared_class_visible_impl(Symbol* class_name,
332                                            InstanceKlass* ik,
333                                            PackageEntry* pkg_entry,
334                                            Handle class_loader);
335   static bool check_shared_class_super_type(InstanceKlass* klass, InstanceKlass* super,
336                                             Handle class_loader,  Handle protection_domain,
337                                             bool is_superclass, TRAPS);
338   static bool check_shared_class_super_types(InstanceKlass* ik, Handle class_loader,
339                                                Handle protection_domain, TRAPS);
340   static void restore_archived_method_handle_intrinsics_impl(TRAPS);

341 
342 protected:
343   // Used by SystemDictionaryShared
344 
345   // Second part of load_shared_class
346   static void load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) NOT_CDS_RETURN;
347 
348   static bool add_loader_constraint(Symbol* name, Klass* klass_being_linked,  Handle loader1,
349                                     Handle loader2);
350   static void post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld);
351   static InstanceKlass* load_shared_lambda_proxy_class(InstanceKlass* ik,
352                                                        Handle class_loader,
353                                                        Handle protection_domain,
354                                                        PackageEntry* pkg_entry,
355                                                        TRAPS);
356   static InstanceKlass* load_shared_class(InstanceKlass* ik,
357                                           Handle class_loader,
358                                           Handle protection_domain,
359                                           const ClassFileStream *cfs,
360                                           PackageEntry* pkg_entry,
361                                           TRAPS);
362   static Handle get_loader_lock_or_null(Handle class_loader);
363   static InstanceKlass* find_or_define_instance_class(Symbol* class_name,
364                                                       Handle class_loader,
365                                                       InstanceKlass* k, TRAPS);
366 public:
367   static bool is_system_class_loader(oop class_loader);
< prev index next >