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 #ifndef SHARE_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
26 #define SHARE_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
27
28 #include "cds/cds_globals.hpp"
29 #include "cds/filemap.hpp"
30 #include "cds/dumpTimeClassInfo.hpp"
31 #include "cds/lambdaProxyClassDictionary.hpp"
32 #include "cds/runTimeClassInfo.hpp"
33 #include "classfile/classLoaderData.hpp"
34 #include "classfile/packageEntry.hpp"
35 #include "classfile/systemDictionary.hpp"
36 #include "oops/klass.hpp"
37 #include "oops/oopHandle.hpp"
38
39
40 /*===============================================================================
41
42 Handling of the classes in the AppCDS archive
43
44 To ensure safety and to simplify the implementation, archived classes are
45 "segregated" into 2 types. The following rules describe how they
46 are stored and looked up.
47
48 [1] Category of archived classes
49
50 There are 2 disjoint groups of classes stored in the AppCDS archive:
51
52 BUILTIN: These classes may be defined ONLY by the BOOT/PLATFORM/APP
53 loaders.
54
55 UNREGISTERED: These classes may be defined ONLY by a ClassLoader
56 instance that's not listed above (using fingerprint matching)
57
166 static DumpTimeLambdaProxyClassDictionary* _dumptime_lambda_proxy_class_dictionary;
167
168 static ArchiveInfo _static_archive;
169 static ArchiveInfo _dynamic_archive;
170
171 static ArchiveInfo* get_archive(bool is_static_archive) {
172 return is_static_archive ? &_static_archive : &_dynamic_archive;
173 }
174
175 static InstanceKlass* load_shared_class_for_builtin_loader(
176 Symbol* class_name,
177 Handle class_loader,
178 TRAPS);
179 static InstanceKlass* acquire_class_for_current_thread(
180 InstanceKlass *ik,
181 Handle class_loader,
182 Handle protection_domain,
183 const ClassFileStream* cfs,
184 TRAPS);
185
186 // Guaranteed to return non-null value for non-shared classes.
187 // k must not be a shared class.
188 static DumpTimeClassInfo* get_info(InstanceKlass* k);
189 static DumpTimeClassInfo* get_info_locked(InstanceKlass* k);
190
191 static void find_all_archivable_classes_impl();
192 static void write_dictionary(RunTimeSharedDictionary* dictionary,
193 bool is_builtin);
194 static void write_lambda_proxy_class_dictionary(LambdaProxyClassDictionary* dictionary);
195 static void cleanup_lambda_proxy_class_dictionary();
196 static void reset_registered_lambda_proxy_class(InstanceKlass* ik);
197 static bool is_jfr_event_class(InstanceKlass *k);
198 static bool is_registered_lambda_proxy_class(InstanceKlass* ik);
199 static bool check_for_exclusion_impl(InstanceKlass* k);
200 static void remove_dumptime_info(InstanceKlass* k) NOT_CDS_RETURN;
201 static bool has_been_redefined(InstanceKlass* k);
202 static InstanceKlass* retrieve_lambda_proxy_class(const RunTimeLambdaProxyClassInfo* info) NOT_CDS_RETURN_(nullptr);
203 static void scan_constant_pool(InstanceKlass* k);
204 DEBUG_ONLY(static bool _class_loading_may_happen;)
205
206 public:
207 static bool should_hidden_class_be_archived(InstanceKlass* k);
208 static void mark_required_hidden_class(InstanceKlass* k);
209 static bool is_hidden_lambda_proxy(InstanceKlass* ik);
210 static bool is_early_klass(InstanceKlass* k); // Was k loaded while JvmtiExport::is_early_phase()==true
211 static bool has_archived_enum_objs(InstanceKlass* ik);
212 static void set_has_archived_enum_objs(InstanceKlass* ik);
213
214 static InstanceKlass* find_builtin_class(Symbol* class_name);
215
216 static const RunTimeClassInfo* find_record(RunTimeSharedDictionary* static_dict,
217 RunTimeSharedDictionary* dynamic_dict,
218 Symbol* name);
219
220 static bool has_platform_or_app_classes();
221
222 // Called by PLATFORM/APP loader only
223 static InstanceKlass* find_or_load_shared_class(Symbol* class_name,
224 Handle class_loader,
225 TRAPS);
226
227
228 static void allocate_shared_data_arrays(int size, TRAPS);
229
230 static bool is_builtin_loader(ClassLoaderData* loader_data);
231
232 static InstanceKlass* lookup_super_for_unregistered_class(Symbol* class_name,
233 Symbol* super_name, bool is_superclass);
234
235 static void initialize() NOT_CDS_RETURN;
236 static void init_dumptime_info(InstanceKlass* k) NOT_CDS_RETURN;
237 static void handle_class_unloading(InstanceKlass* k) NOT_CDS_RETURN;
238
239 static Dictionary* boot_loader_dictionary() {
240 return ClassLoaderData::the_null_class_loader_data()->dictionary();
241 }
242
243 static void update_shared_entry(InstanceKlass* klass, int id);
244 static void set_shared_class_misc_info(InstanceKlass* k, ClassFileStream* cfs);
245
246 static InstanceKlass* lookup_from_stream(Symbol* class_name,
247 Handle class_loader,
248 Handle protection_domain,
249 const ClassFileStream* st,
250 TRAPS);
251 // "verification_constraints" are a set of checks performed by
252 // VerificationType::is_reference_assignable_from when verifying a shared class during
253 // dump time.
254 //
255 // With AppCDS, it is possible to override archived classes by calling
256 // ClassLoader.defineClass() directly. SystemDictionary::load_shared_class() already
257 // ensures that you cannot load a shared class if its super type(s) are changed. However,
258 // we need an additional check to ensure that the verification_constraints did not change
269 InstanceKlass* lambda_ik,
270 Symbol* invoked_name,
271 Symbol* invoked_type,
272 Symbol* method_type,
273 Method* member_method,
274 Symbol* instantiated_method_type, TRAPS) NOT_CDS_RETURN;
275 static void add_to_dump_time_lambda_proxy_class_dictionary(LambdaProxyClassKey& key,
276 InstanceKlass* proxy_klass) NOT_CDS_RETURN;
277 static InstanceKlass* get_shared_lambda_proxy_class(InstanceKlass* caller_ik,
278 Symbol* invoked_name,
279 Symbol* invoked_type,
280 Symbol* method_type,
281 Method* member_method,
282 Symbol* instantiated_method_type) NOT_CDS_RETURN_(nullptr);
283 static InstanceKlass* get_shared_nest_host(InstanceKlass* lambda_ik) NOT_CDS_RETURN_(nullptr);
284 static InstanceKlass* prepare_shared_lambda_proxy_class(InstanceKlass* lambda_ik,
285 InstanceKlass* caller_ik, TRAPS) NOT_CDS_RETURN_(nullptr);
286 static bool check_linking_constraints(Thread* current, InstanceKlass* klass) NOT_CDS_RETURN_(false);
287 static void record_linking_constraint(Symbol* name, InstanceKlass* klass,
288 Handle loader1, Handle loader2) NOT_CDS_RETURN;
289 static bool is_builtin(InstanceKlass* k) {
290 return (k->shared_classpath_index() != UNREGISTERED_INDEX);
291 }
292 static bool add_unregistered_class(Thread* current, InstanceKlass* k);
293
294 static void find_all_archivable_classes();
295 static bool should_be_excluded(Klass* k);
296 static bool check_for_exclusion(InstanceKlass* k, DumpTimeClassInfo* info);
297 static void validate_before_archiving(InstanceKlass* k);
298 static bool is_excluded_class(InstanceKlass* k);
299 static void set_excluded(InstanceKlass* k);
300 static void set_excluded_locked(InstanceKlass* k);
301 static bool warn_excluded(InstanceKlass* k, const char* reason);
302 static void dumptime_classes_do(class MetaspaceClosure* it);
303 static size_t estimate_size_for_archive();
304 static void write_to_archive(bool is_static_archive = true);
305 static void adjust_lambda_proxy_class_dictionary();
306 static void serialize_dictionary_headers(class SerializeClosure* soc,
307 bool is_static_archive = true);
308 static void serialize_vm_classes(class SerializeClosure* soc);
309 static void print() { return print_on(tty); }
310 static void print_on(outputStream* st) NOT_CDS_RETURN;
311 static void print_shared_archive(outputStream* st, bool is_static = true) NOT_CDS_RETURN;
312 static void print_table_statistics(outputStream* st) NOT_CDS_RETURN;
313 static bool is_dumptime_table_empty() NOT_CDS_RETURN_(true);
314 static bool is_supported_invokedynamic(BootstrapInfo* bsi) NOT_CDS_RETURN_(false);
315 DEBUG_ONLY(static bool class_loading_may_happen() {return _class_loading_may_happen;})
316
317 #ifdef ASSERT
318 // This object marks a critical period when writing the CDS archive. During this
319 // period, the JVM must not load any new classes, so as to avoid adding new
320 // items in the SystemDictionaryShared::_dumptime_table.
321 class NoClassLoadingMark: public StackObj {
322 public:
323 NoClassLoadingMark() {
324 assert(_class_loading_may_happen, "must not be nested");
325 _class_loading_may_happen = false;
326 }
327 ~NoClassLoadingMark() {
328 _class_loading_may_happen = true;
329 }
330 };
331 #endif
332
333 template <typename T>
334 static unsigned int hash_for_shared_dictionary_quick(T* ptr) {
335 assert(MetaspaceObj::is_shared((const MetaspaceObj*)ptr), "must be");
336 assert(ptr > (T*)SharedBaseAddress, "must be");
337 uintx offset = uintx(ptr) - uintx(SharedBaseAddress);
338 return primitive_hash<uintx>(offset);
339 }
340
341 static unsigned int hash_for_shared_dictionary(address ptr);
342 };
343
344 #endif // SHARE_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
|
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 #ifndef SHARE_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
26 #define SHARE_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
27
28 #include "cds/cds_globals.hpp"
29 #include "cds/filemap.hpp"
30 #include "cds/dumpTimeClassInfo.hpp"
31 #include "cds/lambdaProxyClassDictionary.hpp"
32 #include "cds/runTimeClassInfo.hpp"
33 #include "classfile/classLoaderData.hpp"
34 #include "classfile/packageEntry.hpp"
35 #include "classfile/systemDictionary.hpp"
36 #include "oops/klass.hpp"
37 #include "oops/oopHandle.hpp"
38 #include "oops/trainingData.hpp"
39
40
41 /*===============================================================================
42
43 Handling of the classes in the AppCDS archive
44
45 To ensure safety and to simplify the implementation, archived classes are
46 "segregated" into 2 types. The following rules describe how they
47 are stored and looked up.
48
49 [1] Category of archived classes
50
51 There are 2 disjoint groups of classes stored in the AppCDS archive:
52
53 BUILTIN: These classes may be defined ONLY by the BOOT/PLATFORM/APP
54 loaders.
55
56 UNREGISTERED: These classes may be defined ONLY by a ClassLoader
57 instance that's not listed above (using fingerprint matching)
58
167 static DumpTimeLambdaProxyClassDictionary* _dumptime_lambda_proxy_class_dictionary;
168
169 static ArchiveInfo _static_archive;
170 static ArchiveInfo _dynamic_archive;
171
172 static ArchiveInfo* get_archive(bool is_static_archive) {
173 return is_static_archive ? &_static_archive : &_dynamic_archive;
174 }
175
176 static InstanceKlass* load_shared_class_for_builtin_loader(
177 Symbol* class_name,
178 Handle class_loader,
179 TRAPS);
180 static InstanceKlass* acquire_class_for_current_thread(
181 InstanceKlass *ik,
182 Handle class_loader,
183 Handle protection_domain,
184 const ClassFileStream* cfs,
185 TRAPS);
186
187
188 static void find_all_archivable_classes_impl();
189 static void write_dictionary(RunTimeSharedDictionary* dictionary,
190 bool is_builtin);
191 static void write_lambda_proxy_class_dictionary(LambdaProxyClassDictionary* dictionary);
192 static void cleanup_lambda_proxy_class_dictionary();
193 static void reset_registered_lambda_proxy_class(InstanceKlass* ik);
194 static bool is_registered_lambda_proxy_class(InstanceKlass* ik);
195 static bool check_for_exclusion_impl(InstanceKlass* k);
196 static void remove_dumptime_info(InstanceKlass* k) NOT_CDS_RETURN;
197 static InstanceKlass* retrieve_lambda_proxy_class(const RunTimeLambdaProxyClassInfo* info) NOT_CDS_RETURN_(nullptr);
198 static void scan_constant_pool(InstanceKlass* k);
199 DEBUG_ONLY(static bool _class_loading_may_happen;)
200
201 public:
202 // Guaranteed to return non-null value for non-shared classes.
203 // k must not be a shared class.
204 static DumpTimeClassInfo* get_info(InstanceKlass* k);
205 static DumpTimeClassInfo* get_info_locked(InstanceKlass* k);
206 static DumpTimeSharedClassTable* dumptime_table() { return _dumptime_table; }
207
208 static bool should_hidden_class_be_archived(InstanceKlass* k);
209 static void mark_required_hidden_class(InstanceKlass* k);
210 static bool has_been_redefined(InstanceKlass* k);
211 static bool is_jfr_event_class(InstanceKlass *k);
212
213 static bool is_hidden_lambda_proxy(InstanceKlass* ik);
214 static bool is_early_klass(InstanceKlass* k); // Was k loaded while JvmtiExport::is_early_phase()==true
215 static bool has_archived_enum_objs(InstanceKlass* ik);
216 static void set_has_archived_enum_objs(InstanceKlass* ik);
217
218 static InstanceKlass* find_builtin_class(Symbol* class_name);
219
220 static const RunTimeClassInfo* find_record(RunTimeSharedDictionary* static_dict,
221 RunTimeSharedDictionary* dynamic_dict,
222 Symbol* name);
223
224 static bool has_platform_or_app_classes();
225
226 // Called by PLATFORM/APP loader only
227 static InstanceKlass* find_or_load_shared_class(Symbol* class_name,
228 Handle class_loader,
229 TRAPS);
230
231
232 static void allocate_shared_data_arrays(int size, TRAPS);
233
234 static bool is_builtin_loader(ClassLoaderData* loader_data);
235
236 static InstanceKlass* lookup_super_for_unregistered_class(Symbol* class_name,
237 Symbol* super_name, bool is_superclass);
238
239 static void initialize() NOT_CDS_RETURN;
240 static void init_dumptime_info(InstanceKlass* k) NOT_CDS_RETURN;
241 static void handle_class_unloading(InstanceKlass* k) NOT_CDS_RETURN;
242
243 static bool can_be_preinited(InstanceKlass* ik);
244 static bool can_be_preinited_locked(InstanceKlass* ik);
245 static void reset_preinit_check();
246
247 static Dictionary* boot_loader_dictionary() {
248 return ClassLoaderData::the_null_class_loader_data()->dictionary();
249 }
250
251 static void update_shared_entry(InstanceKlass* klass, int id);
252 static void set_shared_class_misc_info(InstanceKlass* k, ClassFileStream* cfs);
253
254 static InstanceKlass* lookup_from_stream(Symbol* class_name,
255 Handle class_loader,
256 Handle protection_domain,
257 const ClassFileStream* st,
258 TRAPS);
259 // "verification_constraints" are a set of checks performed by
260 // VerificationType::is_reference_assignable_from when verifying a shared class during
261 // dump time.
262 //
263 // With AppCDS, it is possible to override archived classes by calling
264 // ClassLoader.defineClass() directly. SystemDictionary::load_shared_class() already
265 // ensures that you cannot load a shared class if its super type(s) are changed. However,
266 // we need an additional check to ensure that the verification_constraints did not change
277 InstanceKlass* lambda_ik,
278 Symbol* invoked_name,
279 Symbol* invoked_type,
280 Symbol* method_type,
281 Method* member_method,
282 Symbol* instantiated_method_type, TRAPS) NOT_CDS_RETURN;
283 static void add_to_dump_time_lambda_proxy_class_dictionary(LambdaProxyClassKey& key,
284 InstanceKlass* proxy_klass) NOT_CDS_RETURN;
285 static InstanceKlass* get_shared_lambda_proxy_class(InstanceKlass* caller_ik,
286 Symbol* invoked_name,
287 Symbol* invoked_type,
288 Symbol* method_type,
289 Method* member_method,
290 Symbol* instantiated_method_type) NOT_CDS_RETURN_(nullptr);
291 static InstanceKlass* get_shared_nest_host(InstanceKlass* lambda_ik) NOT_CDS_RETURN_(nullptr);
292 static InstanceKlass* prepare_shared_lambda_proxy_class(InstanceKlass* lambda_ik,
293 InstanceKlass* caller_ik, TRAPS) NOT_CDS_RETURN_(nullptr);
294 static bool check_linking_constraints(Thread* current, InstanceKlass* klass) NOT_CDS_RETURN_(false);
295 static void record_linking_constraint(Symbol* name, InstanceKlass* klass,
296 Handle loader1, Handle loader2) NOT_CDS_RETURN;
297 static bool is_builtin(const InstanceKlass* k) {
298 return (k->shared_classpath_index() != UNREGISTERED_INDEX);
299 }
300 static bool add_unregistered_class(Thread* current, InstanceKlass* k);
301
302 static void find_all_archivable_classes();
303 static bool should_be_excluded(Klass* k);
304 static bool check_for_exclusion(InstanceKlass* k, DumpTimeClassInfo* info);
305 static void validate_before_archiving(InstanceKlass* k);
306 static bool is_excluded_class(InstanceKlass* k);
307 static void set_excluded(InstanceKlass* k);
308 static void set_excluded_locked(InstanceKlass* k);
309 static bool warn_excluded(InstanceKlass* k, const char* reason);
310 static void dumptime_classes_do(class MetaspaceClosure* it);
311 static size_t estimate_size_for_archive();
312 static void write_to_archive(bool is_static_archive = true);
313 static void adjust_lambda_proxy_class_dictionary();
314
315 static void serialize_dictionary_headers(class SerializeClosure* soc,
316 bool is_static_archive = true);
317 static void serialize_vm_classes(class SerializeClosure* soc);
318 static void print() { return print_on(tty); }
319 static void print_on(outputStream* st) NOT_CDS_RETURN;
320 static void print_shared_archive(outputStream* st, bool is_static = true) NOT_CDS_RETURN;
321 static void print_table_statistics(outputStream* st) NOT_CDS_RETURN;
322 static bool is_dumptime_table_empty() NOT_CDS_RETURN_(true);
323 static bool is_supported_invokedynamic(BootstrapInfo* bsi) NOT_CDS_RETURN_(false);
324 DEBUG_ONLY(static bool class_loading_may_happen() {return _class_loading_may_happen;})
325 // Do not archive any new InstanceKlasses that are loaded after this method is called.
326 // This avoids polluting the archive with classes that are only used by GenerateJLIClassesHelper.
327 static void ignore_new_classes();
328
329 #ifdef ASSERT
330 // This object marks a critical period when writing the CDS archive. During this
331 // period, the JVM must not load any new classes, so as to avoid adding new
332 // items in the SystemDictionaryShared::_dumptime_table.
333 class NoClassLoadingMark: public StackObj {
334 public:
335 NoClassLoadingMark() {
336 assert(_class_loading_may_happen, "must not be nested");
337 _class_loading_may_happen = false;
338 }
339 ~NoClassLoadingMark() {
340 _class_loading_may_happen = true;
341 }
342 };
343 #endif
344
345 template <typename T>
346 static unsigned int hash_for_shared_dictionary_quick(T* ptr) {
347 assert(MetaspaceObj::is_shared((const MetaspaceObj*)ptr), "must be");
348 assert(ptr > (T*)SharedBaseAddress, "must be");
349 uintx offset = uintx(ptr) - uintx(SharedBaseAddress);
350 return primitive_hash<uintx>(offset);
351 }
352
353 static unsigned int hash_for_shared_dictionary(address ptr);
354 static const char* class_loader_name_for_shared(Klass* k);
355 static void create_loader_positive_lookup_cache(TRAPS);
356 };
357
358 #endif // SHARE_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
|