51 // When class loading is finished, a new entry is added to the dictionary
52 // of the class loader and the placeholder is removed.
53 //
54 // Clients of this class who are interested in finding if a class has
55 // been completely loaded -- not classes in the process of being loaded --
56 // can read the dictionary unlocked. This is safe because
57 // - entries are only deleted when the class loader is not alive, when the
58 // entire dictionary is deleted.
59 // - entries must be fully formed before they are available to concurrent
60 // readers (we must ensure write ordering)
61 //
62 // Note that placeholders are deleted at any time, as they are removed
63 // when a class is completely loaded. Therefore, readers as well as writers
64 // of placeholders must hold the SystemDictionary_lock.
65 //
66
67 class BootstrapInfo;
68 class ClassFileStream;
69 class ClassLoadInfo;
70 class Dictionary;
71 class PackageEntry;
72 class GCTimer;
73 class EventClassLoad;
74 class Symbol;
75
76 template <class E> class GrowableArray;
77
78 class SystemDictionary : AllStatic {
79 friend class AOTLinkedClassBulkLoader;
80 friend class BootstrapInfo;
81 friend class LambdaProxyClassDictionary;
82 friend class vmClasses;
83
84 public:
85
86 // Returns a class with a given class name and class loader. Loads the
87 // class if needed. If not found a NoClassDefFoundError or a
88 // ClassNotFoundException is thrown, depending on the value on the
89 // throw_error flag. For most uses the throw_error argument should be set
90 // to true.
95 return resolve_or_fail(class_name, Handle(), throw_error, THREAD);
96 }
97
98 // Returns a class with a given class name and class loader.
99 // Loads the class if needed. If not found null is returned.
100 static Klass* resolve_or_null(Symbol* class_name, Handle class_loader, TRAPS);
101 // Version with null loader and protection domain
102 static Klass* resolve_or_null(Symbol* class_name, TRAPS) {
103 return resolve_or_null(class_name, Handle(), THREAD);
104 }
105
106 static InstanceKlass* resolve_with_circularity_detection(Symbol* class_name,
107 Symbol* next_name,
108 Handle class_loader,
109 bool is_superclass,
110 TRAPS);
111
112 // Resolve a superclass or superinterface. Called from ClassFileParser,
113 // parse_interfaces, resolve_instance_class_or_null, load_shared_class
114 // "class_name" is the class whose super class or interface is being resolved.
115 static InstanceKlass* resolve_super_or_fail(Symbol* class_name, Symbol* super_name,
116 Handle class_loader,
117 bool is_superclass, TRAPS) {
118 return resolve_with_circularity_detection(class_name, super_name, class_loader, is_superclass, THREAD);
119 }
120
121 private:
122 // Parse the stream to create a hidden class.
123 // Used by jvm_lookup_define_class.
124 static InstanceKlass* resolve_hidden_class_from_stream(ClassFileStream* st,
125 Symbol* class_name,
126 Handle class_loader,
127 const ClassLoadInfo& cl_info,
128 TRAPS);
129
130 // Resolve a class from stream (called by jni_DefineClass and JVM_DefineClass)
131 // This class is added to the SystemDictionary.
132 static InstanceKlass* resolve_class_from_stream(ClassFileStream* st,
133 Symbol* class_name,
134 Handle class_loader,
135 const ClassLoadInfo& cl_info,
136 TRAPS);
137
138 static oop get_system_class_loader_impl(TRAPS);
139 static oop get_platform_class_loader_impl(TRAPS);
140
141 public:
142 // Resolve either a hidden or normal class from a stream of bytes, based on ClassLoadInfo
143 static InstanceKlass* resolve_from_stream(ClassFileStream* st,
144 Symbol* class_name,
145 Handle class_loader,
146 const ClassLoadInfo& cl_info,
147 TRAPS);
148
149 // Lookup an already loaded class. If not found null is returned.
150 static InstanceKlass* find_instance_klass(Thread* current, Symbol* class_name,
151 Handle class_loader);
152
153 // Lookup an already loaded instance or array class.
154 // Do not make any queries to class loaders; consult only the cache.
155 // If not found null is returned.
156 static Klass* find_instance_or_array_klass(Thread* current, Symbol* class_name,
157 Handle class_loader);
158
159 // Lookup an instance or array class that has already been loaded
160 // either into the given class loader, or else into another class
161 // loader that is constrained (via loader constraints) to produce
314 PackageEntry* pkg_entry,
315 Handle class_loader);
316 static bool is_shared_class_visible_impl(Symbol* class_name,
317 InstanceKlass* ik,
318 PackageEntry* pkg_entry,
319 Handle class_loader);
320 static bool check_shared_class_super_type(InstanceKlass* klass, InstanceKlass* super,
321 Handle class_loader,
322 bool is_superclass, TRAPS);
323 static bool check_shared_class_super_types(InstanceKlass* ik, Handle class_loader, TRAPS);
324 // Second part of load_shared_class
325 static void load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) NOT_CDS_RETURN;
326 static void restore_archived_method_handle_intrinsics_impl(TRAPS) NOT_CDS_RETURN;
327
328 protected:
329 // Used by SystemDictionaryShared and LambdaProxyClassDictionary
330
331 static bool add_loader_constraint(Symbol* name, Klass* klass_being_linked, Handle loader1,
332 Handle loader2);
333 static void post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld);
334 static InstanceKlass* load_shared_class(InstanceKlass* ik,
335 Handle class_loader,
336 Handle protection_domain,
337 const ClassFileStream *cfs,
338 PackageEntry* pkg_entry,
339 TRAPS);
340 static Handle get_loader_lock_or_null(Handle class_loader);
341 static InstanceKlass* find_or_define_instance_class(Symbol* class_name,
342 Handle class_loader,
343 InstanceKlass* k, TRAPS);
344
345 public:
346 static bool is_system_class_loader(oop class_loader);
347 static bool is_platform_class_loader(oop class_loader);
348 static bool is_boot_class_loader(oop class_loader) { return class_loader == nullptr; }
349 static bool is_builtin_class_loader(oop class_loader) {
350 return is_boot_class_loader(class_loader) ||
351 is_platform_class_loader(class_loader) ||
352 is_system_class_loader(class_loader);
353 }
|
51 // When class loading is finished, a new entry is added to the dictionary
52 // of the class loader and the placeholder is removed.
53 //
54 // Clients of this class who are interested in finding if a class has
55 // been completely loaded -- not classes in the process of being loaded --
56 // can read the dictionary unlocked. This is safe because
57 // - entries are only deleted when the class loader is not alive, when the
58 // entire dictionary is deleted.
59 // - entries must be fully formed before they are available to concurrent
60 // readers (we must ensure write ordering)
61 //
62 // Note that placeholders are deleted at any time, as they are removed
63 // when a class is completely loaded. Therefore, readers as well as writers
64 // of placeholders must hold the SystemDictionary_lock.
65 //
66
67 class BootstrapInfo;
68 class ClassFileStream;
69 class ClassLoadInfo;
70 class Dictionary;
71 class AllFieldStream;
72 class PackageEntry;
73 class GCTimer;
74 class EventClassLoad;
75 class Symbol;
76
77 template <class E> class GrowableArray;
78
79 class SystemDictionary : AllStatic {
80 friend class AOTLinkedClassBulkLoader;
81 friend class BootstrapInfo;
82 friend class LambdaProxyClassDictionary;
83 friend class vmClasses;
84
85 public:
86
87 // Returns a class with a given class name and class loader. Loads the
88 // class if needed. If not found a NoClassDefFoundError or a
89 // ClassNotFoundException is thrown, depending on the value on the
90 // throw_error flag. For most uses the throw_error argument should be set
91 // to true.
96 return resolve_or_fail(class_name, Handle(), throw_error, THREAD);
97 }
98
99 // Returns a class with a given class name and class loader.
100 // Loads the class if needed. If not found null is returned.
101 static Klass* resolve_or_null(Symbol* class_name, Handle class_loader, TRAPS);
102 // Version with null loader and protection domain
103 static Klass* resolve_or_null(Symbol* class_name, TRAPS) {
104 return resolve_or_null(class_name, Handle(), THREAD);
105 }
106
107 static InstanceKlass* resolve_with_circularity_detection(Symbol* class_name,
108 Symbol* next_name,
109 Handle class_loader,
110 bool is_superclass,
111 TRAPS);
112
113 // Resolve a superclass or superinterface. Called from ClassFileParser,
114 // parse_interfaces, resolve_instance_class_or_null, load_shared_class
115 // "class_name" is the class whose super class or interface is being resolved.
116 static InstanceKlass* resolve_with_circularity_detection_or_fail(Symbol* class_name,
117 Symbol* super_name,
118 Handle class_loader,
119 bool is_superclass, TRAPS) {
120 return resolve_with_circularity_detection(class_name, super_name, class_loader, is_superclass, THREAD);
121 }
122
123 private:
124 // Parse the stream to create a hidden class.
125 // Used by jvm_lookup_define_class.
126 static InstanceKlass* resolve_hidden_class_from_stream(ClassFileStream* st,
127 Symbol* class_name,
128 Handle class_loader,
129 const ClassLoadInfo& cl_info,
130 TRAPS);
131
132 // Resolve a class from stream (called by jni_DefineClass and JVM_DefineClass)
133 // This class is added to the SystemDictionary.
134 static InstanceKlass* resolve_class_from_stream(ClassFileStream* st,
135 Symbol* class_name,
136 Handle class_loader,
137 const ClassLoadInfo& cl_info,
138 TRAPS);
139
140 static oop get_system_class_loader_impl(TRAPS);
141 static oop get_platform_class_loader_impl(TRAPS);
142
143 public:
144
145 // Resolve either a hidden or normal class from a stream of bytes, based on ClassLoadInfo
146 static InstanceKlass* resolve_from_stream(ClassFileStream* st,
147 Symbol* class_name,
148 Handle class_loader,
149 const ClassLoadInfo& cl_info,
150 TRAPS);
151
152 // Lookup an already loaded class. If not found null is returned.
153 static InstanceKlass* find_instance_klass(Thread* current, Symbol* class_name,
154 Handle class_loader);
155
156 // Lookup an already loaded instance or array class.
157 // Do not make any queries to class loaders; consult only the cache.
158 // If not found null is returned.
159 static Klass* find_instance_or_array_klass(Thread* current, Symbol* class_name,
160 Handle class_loader);
161
162 // Lookup an instance or array class that has already been loaded
163 // either into the given class loader, or else into another class
164 // loader that is constrained (via loader constraints) to produce
317 PackageEntry* pkg_entry,
318 Handle class_loader);
319 static bool is_shared_class_visible_impl(Symbol* class_name,
320 InstanceKlass* ik,
321 PackageEntry* pkg_entry,
322 Handle class_loader);
323 static bool check_shared_class_super_type(InstanceKlass* klass, InstanceKlass* super,
324 Handle class_loader,
325 bool is_superclass, TRAPS);
326 static bool check_shared_class_super_types(InstanceKlass* ik, Handle class_loader, TRAPS);
327 // Second part of load_shared_class
328 static void load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) NOT_CDS_RETURN;
329 static void restore_archived_method_handle_intrinsics_impl(TRAPS) NOT_CDS_RETURN;
330
331 protected:
332 // Used by SystemDictionaryShared and LambdaProxyClassDictionary
333
334 static bool add_loader_constraint(Symbol* name, Klass* klass_being_linked, Handle loader1,
335 Handle loader2);
336 static void post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld);
337 static bool preload_from_null_free_field(InstanceKlass* ik, Handle class_loader, Symbol* sig, int field_index, TRAPS);
338 static void try_preload_from_loadable_descriptors(InstanceKlass* ik, Handle class_loader, Symbol* sig, int field_index, TRAPS);
339 static InstanceKlass* load_shared_class(InstanceKlass* ik,
340 Handle class_loader,
341 Handle protection_domain,
342 const ClassFileStream *cfs,
343 PackageEntry* pkg_entry,
344 TRAPS);
345 static Handle get_loader_lock_or_null(Handle class_loader);
346 static InstanceKlass* find_or_define_instance_class(Symbol* class_name,
347 Handle class_loader,
348 InstanceKlass* k, TRAPS);
349
350 public:
351 static bool is_system_class_loader(oop class_loader);
352 static bool is_platform_class_loader(oop class_loader);
353 static bool is_boot_class_loader(oop class_loader) { return class_loader == nullptr; }
354 static bool is_builtin_class_loader(oop class_loader) {
355 return is_boot_class_loader(class_loader) ||
356 is_platform_class_loader(class_loader) ||
357 is_system_class_loader(class_loader);
358 }
|