88 BUILTIN: (C->shared_classpath_index() >= 0)
89 UNREGISTERED: (C->shared_classpath_index() == UNREGISTERED_INDEX (-9999))
90
91 [4] Lookup of archived classes at run time:
92
93 (a) BUILTIN loaders:
94
95 search _builtin_dictionary
96
97 (b) UNREGISTERED loaders:
98
99 search _unregistered_dictionary for an entry that matches the
100 (name, clsfile_len, clsfile_crc32).
101
102 ===============================================================================*/
103 #define UNREGISTERED_INDEX -9999
104
105 class ClassFileStream;
106 class DumpTimeSharedClassInfo;
107 class DumpTimeSharedClassTable;
108 class RunTimeSharedClassInfo;
109 class RunTimeSharedDictionary;
110
111 class SystemDictionaryShared: public SystemDictionary {
112 friend class ExcludeDumpTimeSharedClasses;
113 public:
114 enum {
115 FROM_FIELD_IS_PROTECTED = 1 << 0,
116 FROM_IS_ARRAY = 1 << 1,
117 FROM_IS_OBJECT = 1 << 2
118 };
119
120 private:
121 // These _shared_xxxs arrays are used to initialize the java.lang.Package and
122 // java.security.ProtectionDomain objects associated with each shared class.
123 //
124 // See SystemDictionaryShared::init_security_info for more info.
125 static objArrayOop _shared_protection_domains;
126 static objArrayOop _shared_jar_urls;
127 static objArrayOop _shared_jar_manifests;
161 // PLATFORM classes: No package is defined.
162 //
163 // The following two define_shared_package() functions are used to define
164 // package for shared APP and PLATFORM classes.
165 static void define_shared_package(Symbol* class_name,
166 Handle class_loader,
167 Handle manifest,
168 Handle url,
169 TRAPS);
170
171 static Handle get_shared_jar_manifest(int shared_path_index, TRAPS);
172 static Handle get_shared_jar_url(int shared_path_index, TRAPS);
173 static Handle get_protection_domain_from_classloader(Handle class_loader,
174 Handle url, TRAPS);
175 static Handle get_shared_protection_domain(Handle class_loader,
176 int shared_path_index,
177 Handle url,
178 TRAPS);
179 static Handle get_shared_protection_domain(Handle class_loader,
180 ModuleEntry* mod, TRAPS);
181 static Handle init_security_info(Handle class_loader, InstanceKlass* ik, PackageEntry* pkg_entry, TRAPS);
182
183 static void atomic_set_array_index(objArrayOop array, int index, oop o) {
184 // Benign race condition: array.obj_at(index) may already be filled in.
185 // The important thing here is that all threads pick up the same result.
186 // It doesn't matter which racing thread wins, as long as only one
187 // result is used by all threads, and all future queries.
188 array->atomic_compare_exchange_oop(index, o, NULL);
189 }
190
191 static oop shared_protection_domain(int index);
192 static void atomic_set_shared_protection_domain(int index, oop pd) {
193 atomic_set_array_index(_shared_protection_domains, index, pd);
194 }
195 static void allocate_shared_protection_domain_array(int size, TRAPS);
196 static oop shared_jar_url(int index);
197 static void atomic_set_shared_jar_url(int index, oop url) {
198 atomic_set_array_index(_shared_jar_urls, index, url);
199 }
200 static void allocate_shared_jar_url_array(int size, TRAPS);
201 static oop shared_jar_manifest(int index);
202 static void atomic_set_shared_jar_manifest(int index, oop man) {
203 atomic_set_array_index(_shared_jar_manifests, index, man);
204 }
205 static void allocate_shared_jar_manifest_array(int size, TRAPS);
206 static InstanceKlass* acquire_class_for_current_thread(
207 InstanceKlass *ik,
208 Handle class_loader,
209 Handle protection_domain,
210 const ClassFileStream* cfs,
211 TRAPS);
212 static DumpTimeSharedClassInfo* find_or_allocate_info_for(InstanceKlass* k);
213 static void write_dictionary(RunTimeSharedDictionary* dictionary,
214 bool is_builtin,
215 bool is_static_archive = true);
216 static bool is_jfr_event_class(InstanceKlass *k);
217 static void warn_excluded(InstanceKlass* k, const char* reason);
218 static bool should_be_excluded(InstanceKlass* k);
219
220 DEBUG_ONLY(static bool _no_class_loading_should_happen;)
221
222 public:
223 static InstanceKlass* find_builtin_class(Symbol* class_name);
224
225 static const RunTimeSharedClassInfo* find_record(RunTimeSharedDictionary* static_dict,
226 RunTimeSharedDictionary* dynamic_dict,
227 Symbol* name);
228
229 static bool has_platform_or_app_classes();
230
231 // Called by PLATFORM/APP loader only
232 static InstanceKlass* find_or_load_shared_class(Symbol* class_name,
233 Handle class_loader,
234 TRAPS);
235
236
237 static void allocate_shared_data_arrays(int size, TRAPS);
238 static void oops_do(OopClosure* f);
239
240 // Check if sharing is supported for the class loader.
241 static bool is_sharing_possible(ClassLoaderData* loader_data);
242 static bool is_shared_class_visible_for_classloader(InstanceKlass* ik,
268 Handle class_loader,
269 Handle protection_domain,
270 const ClassFileStream* st,
271 TRAPS);
272 // "verification_constraints" are a set of checks performed by
273 // VerificationType::is_reference_assignable_from when verifying a shared class during
274 // dump time.
275 //
276 // With AppCDS, it is possible to override archived classes by calling
277 // ClassLoader.defineClass() directly. SystemDictionary::load_shared_class() already
278 // ensures that you cannot load a shared class if its super type(s) are changed. However,
279 // we need an additional check to ensure that the verification_constraints did not change
280 // between dump time and runtime.
281 static bool add_verification_constraint(InstanceKlass* k, Symbol* name,
282 Symbol* from_name, bool from_field_is_protected,
283 bool from_is_array, bool from_is_object) NOT_CDS_RETURN_(false);
284 static void check_verification_constraints(InstanceKlass* klass,
285 TRAPS) NOT_CDS_RETURN;
286 static void set_class_has_failed_verification(InstanceKlass* ik) NOT_CDS_RETURN;
287 static bool has_class_failed_verification(InstanceKlass* ik) NOT_CDS_RETURN_(false);
288 static bool check_linking_constraints(InstanceKlass* klass, TRAPS) NOT_CDS_RETURN_(false);
289 static void record_linking_constraint(Symbol* name, InstanceKlass* klass,
290 Handle loader1, Handle loader2, TRAPS) NOT_CDS_RETURN;
291 static bool is_builtin(InstanceKlass* k) {
292 return (k->shared_classpath_index() != UNREGISTERED_INDEX);
293 }
294 static void check_excluded_classes();
295 static void validate_before_archiving(InstanceKlass* k);
296 static bool is_excluded_class(InstanceKlass* k);
297 static void dumptime_classes_do(class MetaspaceClosure* it);
298 static size_t estimate_size_for_archive();
299 static void write_to_archive(bool is_static_archive = true);
300 static void serialize_dictionary_headers(class SerializeClosure* soc,
301 bool is_static_archive = true);
302 static void serialize_well_known_klasses(class SerializeClosure* soc);
303 static void print() { return print_on(tty); }
304 static void print_on(outputStream* st) NOT_CDS_RETURN;
305 static void print_table_statistics(outputStream* st) NOT_CDS_RETURN;
306 static bool empty_dumptime_table() NOT_CDS_RETURN_(true);
307
308 DEBUG_ONLY(static bool no_class_loading_should_happen() {return _no_class_loading_should_happen;})
309
310 #ifdef ASSERT
311 class NoClassLoadingMark: public StackObj {
312 public:
313 NoClassLoadingMark() {
314 assert(!_no_class_loading_should_happen, "must not be nested");
315 _no_class_loading_should_happen = true;
316 }
317 ~NoClassLoadingMark() {
318 _no_class_loading_should_happen = false;
319 }
|
88 BUILTIN: (C->shared_classpath_index() >= 0)
89 UNREGISTERED: (C->shared_classpath_index() == UNREGISTERED_INDEX (-9999))
90
91 [4] Lookup of archived classes at run time:
92
93 (a) BUILTIN loaders:
94
95 search _builtin_dictionary
96
97 (b) UNREGISTERED loaders:
98
99 search _unregistered_dictionary for an entry that matches the
100 (name, clsfile_len, clsfile_crc32).
101
102 ===============================================================================*/
103 #define UNREGISTERED_INDEX -9999
104
105 class ClassFileStream;
106 class DumpTimeSharedClassInfo;
107 class DumpTimeSharedClassTable;
108 class LambdaProxyClassDictionary;
109 class RunTimeSharedClassInfo;
110 class RunTimeSharedDictionary;
111
112 class SystemDictionaryShared: public SystemDictionary {
113 friend class ExcludeDumpTimeSharedClasses;
114 public:
115 enum {
116 FROM_FIELD_IS_PROTECTED = 1 << 0,
117 FROM_IS_ARRAY = 1 << 1,
118 FROM_IS_OBJECT = 1 << 2
119 };
120
121 private:
122 // These _shared_xxxs arrays are used to initialize the java.lang.Package and
123 // java.security.ProtectionDomain objects associated with each shared class.
124 //
125 // See SystemDictionaryShared::init_security_info for more info.
126 static objArrayOop _shared_protection_domains;
127 static objArrayOop _shared_jar_urls;
128 static objArrayOop _shared_jar_manifests;
162 // PLATFORM classes: No package is defined.
163 //
164 // The following two define_shared_package() functions are used to define
165 // package for shared APP and PLATFORM classes.
166 static void define_shared_package(Symbol* class_name,
167 Handle class_loader,
168 Handle manifest,
169 Handle url,
170 TRAPS);
171
172 static Handle get_shared_jar_manifest(int shared_path_index, TRAPS);
173 static Handle get_shared_jar_url(int shared_path_index, TRAPS);
174 static Handle get_protection_domain_from_classloader(Handle class_loader,
175 Handle url, TRAPS);
176 static Handle get_shared_protection_domain(Handle class_loader,
177 int shared_path_index,
178 Handle url,
179 TRAPS);
180 static Handle get_shared_protection_domain(Handle class_loader,
181 ModuleEntry* mod, TRAPS);
182
183 static void atomic_set_array_index(objArrayOop array, int index, oop o) {
184 // Benign race condition: array.obj_at(index) may already be filled in.
185 // The important thing here is that all threads pick up the same result.
186 // It doesn't matter which racing thread wins, as long as only one
187 // result is used by all threads, and all future queries.
188 array->atomic_compare_exchange_oop(index, o, NULL);
189 }
190
191 static oop shared_protection_domain(int index);
192 static void atomic_set_shared_protection_domain(int index, oop pd) {
193 atomic_set_array_index(_shared_protection_domains, index, pd);
194 }
195 static void allocate_shared_protection_domain_array(int size, TRAPS);
196 static oop shared_jar_url(int index);
197 static void atomic_set_shared_jar_url(int index, oop url) {
198 atomic_set_array_index(_shared_jar_urls, index, url);
199 }
200 static void allocate_shared_jar_url_array(int size, TRAPS);
201 static oop shared_jar_manifest(int index);
202 static void atomic_set_shared_jar_manifest(int index, oop man) {
203 atomic_set_array_index(_shared_jar_manifests, index, man);
204 }
205 static void allocate_shared_jar_manifest_array(int size, TRAPS);
206 static InstanceKlass* acquire_class_for_current_thread(
207 InstanceKlass *ik,
208 Handle class_loader,
209 Handle protection_domain,
210 const ClassFileStream* cfs,
211 TRAPS);
212 static DumpTimeSharedClassInfo* find_or_allocate_info_for(InstanceKlass* k);
213 static void write_dictionary(RunTimeSharedDictionary* dictionary,
214 bool is_builtin,
215 bool is_static_archive = true);
216 static void write_lambda_proxy_class_dictionary(LambdaProxyClassDictionary* dictionary);
217 static bool is_jfr_event_class(InstanceKlass *k);
218 static bool is_registered_lambda_proxy_class(InstanceKlass* ik);
219 static bool is_in_shared_lambda_proxy_table(InstanceKlass* ik);
220 static void warn_excluded(InstanceKlass* k, const char* reason);
221 static bool should_be_excluded(InstanceKlass* k);
222
223 DEBUG_ONLY(static bool _no_class_loading_should_happen;)
224
225 public:
226 static bool is_hidden_lambda_proxy(InstanceKlass* ik);
227 static Handle init_security_info(Handle class_loader, InstanceKlass* ik, PackageEntry* pkg_entry, TRAPS);
228 static InstanceKlass* find_builtin_class(Symbol* class_name);
229
230 static const RunTimeSharedClassInfo* find_record(RunTimeSharedDictionary* static_dict,
231 RunTimeSharedDictionary* dynamic_dict,
232 Symbol* name);
233
234 static bool has_platform_or_app_classes();
235
236 // Called by PLATFORM/APP loader only
237 static InstanceKlass* find_or_load_shared_class(Symbol* class_name,
238 Handle class_loader,
239 TRAPS);
240
241
242 static void allocate_shared_data_arrays(int size, TRAPS);
243 static void oops_do(OopClosure* f);
244
245 // Check if sharing is supported for the class loader.
246 static bool is_sharing_possible(ClassLoaderData* loader_data);
247 static bool is_shared_class_visible_for_classloader(InstanceKlass* ik,
273 Handle class_loader,
274 Handle protection_domain,
275 const ClassFileStream* st,
276 TRAPS);
277 // "verification_constraints" are a set of checks performed by
278 // VerificationType::is_reference_assignable_from when verifying a shared class during
279 // dump time.
280 //
281 // With AppCDS, it is possible to override archived classes by calling
282 // ClassLoader.defineClass() directly. SystemDictionary::load_shared_class() already
283 // ensures that you cannot load a shared class if its super type(s) are changed. However,
284 // we need an additional check to ensure that the verification_constraints did not change
285 // between dump time and runtime.
286 static bool add_verification_constraint(InstanceKlass* k, Symbol* name,
287 Symbol* from_name, bool from_field_is_protected,
288 bool from_is_array, bool from_is_object) NOT_CDS_RETURN_(false);
289 static void check_verification_constraints(InstanceKlass* klass,
290 TRAPS) NOT_CDS_RETURN;
291 static void set_class_has_failed_verification(InstanceKlass* ik) NOT_CDS_RETURN;
292 static bool has_class_failed_verification(InstanceKlass* ik) NOT_CDS_RETURN_(false);
293 static void add_lambda_proxy_class(InstanceKlass* caller_ik,
294 InstanceKlass* lambda_ik,
295 Symbol* invoked_name,
296 Symbol* invoked_type,
297 Symbol* method_type,
298 Method* member_method,
299 Symbol* instantiated_method_type) NOT_CDS_RETURN;
300 static InstanceKlass* get_shared_lambda_proxy_class(InstanceKlass* caller_ik,
301 Symbol* invoked_name,
302 Symbol* invoked_type,
303 Symbol* method_type,
304 Method* member_method,
305 Symbol* instantiated_method_type) NOT_CDS_RETURN_(NULL);
306 static InstanceKlass* get_shared_nest_host(InstanceKlass* lambda_ik) NOT_CDS_RETURN_(NULL);
307 static InstanceKlass* prepare_shared_lambda_proxy_class(InstanceKlass* lambda_ik,
308 InstanceKlass* caller_ik,
309 bool initialize, TRAPS) NOT_CDS_RETURN_(NULL);
310 static bool check_linking_constraints(InstanceKlass* klass, TRAPS) NOT_CDS_RETURN_(false);
311 static void record_linking_constraint(Symbol* name, InstanceKlass* klass,
312 Handle loader1, Handle loader2, TRAPS) NOT_CDS_RETURN;
313 static bool is_builtin(InstanceKlass* k) {
314 return (k->shared_classpath_index() != UNREGISTERED_INDEX);
315 }
316 static void check_excluded_classes();
317 static void validate_before_archiving(InstanceKlass* k);
318 static bool is_excluded_class(InstanceKlass* k);
319 static void dumptime_classes_do(class MetaspaceClosure* it);
320 static size_t estimate_size_for_archive();
321 static void write_to_archive(bool is_static_archive = true);
322 static void adjust_lambda_proxy_class_dictionary();
323 static void serialize_dictionary_headers(class SerializeClosure* soc,
324 bool is_static_archive = true);
325 static void serialize_well_known_klasses(class SerializeClosure* soc);
326 static void print() { return print_on(tty); }
327 static void print_on(outputStream* st) NOT_CDS_RETURN;
328 static void print_table_statistics(outputStream* st) NOT_CDS_RETURN;
329 static bool empty_dumptime_table() NOT_CDS_RETURN_(true);
330
331 DEBUG_ONLY(static bool no_class_loading_should_happen() {return _no_class_loading_should_happen;})
332
333 #ifdef ASSERT
334 class NoClassLoadingMark: public StackObj {
335 public:
336 NoClassLoadingMark() {
337 assert(!_no_class_loading_should_happen, "must not be nested");
338 _no_class_loading_should_happen = true;
339 }
340 ~NoClassLoadingMark() {
341 _no_class_loading_should_happen = false;
342 }
|