< prev index next >

src/hotspot/share/classfile/systemDictionaryShared.hpp

Print this page

 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 

158   static DumpTimeLambdaProxyClassDictionary* _dumptime_lambda_proxy_class_dictionary;
159 
160   static ArchiveInfo _static_archive;
161   static ArchiveInfo _dynamic_archive;
162 
163   static ArchiveInfo* get_archive(bool is_static_archive) {
164     return is_static_archive ? &_static_archive : &_dynamic_archive;
165   }
166 
167   static InstanceKlass* load_shared_class_for_builtin_loader(
168                                                Symbol* class_name,
169                                                Handle class_loader,
170                                                TRAPS);
171   static InstanceKlass* acquire_class_for_current_thread(
172                                  InstanceKlass *ik,
173                                  Handle class_loader,
174                                  Handle protection_domain,
175                                  const ClassFileStream* cfs,
176                                  TRAPS);
177 
178   // Guaranteed to return non-null value for non-shared classes.
179   // k must not be a shared class.
180   static DumpTimeClassInfo* get_info(InstanceKlass* k);
181   static DumpTimeClassInfo* get_info_locked(InstanceKlass* k);
182 
183   static void write_dictionary(RunTimeSharedDictionary* dictionary,
184                                bool is_builtin);
185   static void write_lambda_proxy_class_dictionary(LambdaProxyClassDictionary* dictionary);
186   static void cleanup_lambda_proxy_class_dictionary();
187   static void reset_registered_lambda_proxy_class(InstanceKlass* ik);
188   static bool is_jfr_event_class(InstanceKlass *k);
189   static bool check_for_exclusion_impl(InstanceKlass* k);
190   static void remove_dumptime_info(InstanceKlass* k) NOT_CDS_RETURN;
191   static bool has_been_redefined(InstanceKlass* k);
192   static InstanceKlass* retrieve_lambda_proxy_class(const RunTimeLambdaProxyClassInfo* info) NOT_CDS_RETURN_(nullptr);
193   DEBUG_ONLY(static bool _class_loading_may_happen;)
194 
195   static void copy_verification_constraints_from_preimage(InstanceKlass* klass);
196   static void copy_linking_constraints_from_preimage(InstanceKlass* klass);
197 
198 public:










199   static bool is_registered_lambda_proxy_class(InstanceKlass* ik);

200   static bool is_hidden_lambda_proxy(InstanceKlass* ik);
201   static bool is_early_klass(InstanceKlass* k);   // Was k loaded while JvmtiExport::is_early_phase()==true
202   static bool has_archived_enum_objs(InstanceKlass* ik);
203   static void set_has_archived_enum_objs(InstanceKlass* ik);
204 
205   static InstanceKlass* find_builtin_class(Symbol* class_name);
206 
207   static const RunTimeClassInfo* find_record(RunTimeSharedDictionary* static_dict,
208                                                    RunTimeSharedDictionary* dynamic_dict,
209                                                    Symbol* name);
210 
211   static bool has_platform_or_app_classes();
212 
213   // Called by PLATFORM/APP loader only
214   static InstanceKlass* find_or_load_shared_class(Symbol* class_name,
215                                                Handle class_loader,
216                                                TRAPS);
217 
218 
219   static void allocate_shared_data_arrays(int size, TRAPS);
220 
221   static bool is_builtin_loader(ClassLoaderData* loader_data);
222 
223   static InstanceKlass* lookup_super_for_unregistered_class(Symbol* class_name,
224                                                             Symbol* super_name,  bool is_superclass);
225 
226   static void initialize() NOT_CDS_RETURN;
227   static void init_dumptime_info(InstanceKlass* k) NOT_CDS_RETURN;
228   static void init_dumptime_info_from_preimage(InstanceKlass* k) NOT_CDS_RETURN;
229   static void handle_class_unloading(InstanceKlass* k) NOT_CDS_RETURN;
230 




231   static Dictionary* boot_loader_dictionary() {
232     return ClassLoaderData::the_null_class_loader_data()->dictionary();
233   }
234 
235   static void update_shared_entry(InstanceKlass* klass, int id);
236   static void set_shared_class_misc_info(InstanceKlass* k, ClassFileStream* cfs);
237 
238   static InstanceKlass* lookup_from_stream(Symbol* class_name,
239                                            Handle class_loader,
240                                            Handle protection_domain,
241                                            const ClassFileStream* st,
242                                            TRAPS);
243   // "verification_constraints" are a set of checks performed by
244   // VerificationType::is_reference_assignable_from when verifying a shared class during
245   // dump time.
246   //
247   // With AppCDS, it is possible to override archived classes by calling
248   // ClassLoader.defineClass() directly. SystemDictionary::load_shared_class() already
249   // ensures that you cannot load a shared class if its super type(s) are changed. However,
250   // we need an additional check to ensure that the verification_constraints did not change

261                                      InstanceKlass* lambda_ik,
262                                      Symbol* invoked_name,
263                                      Symbol* invoked_type,
264                                      Symbol* method_type,
265                                      Method* member_method,
266                                      Symbol* instantiated_method_type, TRAPS) NOT_CDS_RETURN;
267   static void add_to_dump_time_lambda_proxy_class_dictionary(LambdaProxyClassKey& key,
268                                                              InstanceKlass* proxy_klass) NOT_CDS_RETURN;
269   static InstanceKlass* get_shared_lambda_proxy_class(InstanceKlass* caller_ik,
270                                                       Symbol* invoked_name,
271                                                       Symbol* invoked_type,
272                                                       Symbol* method_type,
273                                                       Method* member_method,
274                                                       Symbol* instantiated_method_type) NOT_CDS_RETURN_(nullptr);
275   static InstanceKlass* get_shared_nest_host(InstanceKlass* lambda_ik) NOT_CDS_RETURN_(nullptr);
276   static InstanceKlass* prepare_shared_lambda_proxy_class(InstanceKlass* lambda_ik,
277                                                           InstanceKlass* caller_ik, TRAPS) NOT_CDS_RETURN_(nullptr);
278   static bool check_linking_constraints(Thread* current, InstanceKlass* klass) NOT_CDS_RETURN_(false);
279   static void record_linking_constraint(Symbol* name, InstanceKlass* klass,
280                                      Handle loader1, Handle loader2) NOT_CDS_RETURN;
281   static bool is_builtin(InstanceKlass* k) {
282     return (k->shared_classpath_index() != UNREGISTERED_INDEX);
283   }
284   static bool add_unregistered_class(Thread* current, InstanceKlass* k);
285 
286   static void finish_exclusion_checks();
287   static DumpTimeSharedClassTable* dumptime_table() { return _dumptime_table; }
288 
289   static bool should_be_excluded(Klass* k);
290   static bool check_for_exclusion(InstanceKlass* k, DumpTimeClassInfo* info);
291   static void validate_before_archiving(InstanceKlass* k);
292   static bool is_excluded_class(InstanceKlass* k);
293   static void set_excluded(InstanceKlass* k);
294   static void set_excluded_locked(InstanceKlass* k);
295   static bool warn_excluded(InstanceKlass* k, const char* reason);
296   static void dumptime_classes_do(class MetaspaceClosure* it);
297   static void write_to_archive(bool is_static_archive = true);
298   static void adjust_lambda_proxy_class_dictionary();

299   static void serialize_dictionary_headers(class SerializeClosure* soc,
300                                            bool is_static_archive = true);
301   static void serialize_vm_classes(class SerializeClosure* soc);
302   static void print() { return print_on(tty); }
303   static void print_on(outputStream* st) NOT_CDS_RETURN;
304   static void print_shared_archive(outputStream* st, bool is_static = true) NOT_CDS_RETURN;
305   static void print_table_statistics(outputStream* st) NOT_CDS_RETURN;
306   static bool is_dumptime_table_empty() NOT_CDS_RETURN_(true);
307   static bool is_supported_invokedynamic(BootstrapInfo* bsi) NOT_CDS_RETURN_(false);
308   DEBUG_ONLY(static bool class_loading_may_happen() {return _class_loading_may_happen;})



309 
310 #ifdef ASSERT
311   // This object marks a critical period when writing the CDS archive. During this
312   // period, the JVM must not load any new classes, so as to avoid adding new
313   // items in the SystemDictionaryShared::_dumptime_table.
314   class NoClassLoadingMark: public StackObj {
315   public:
316     NoClassLoadingMark() {
317       assert(_class_loading_may_happen, "must not be nested");
318       _class_loading_may_happen = false;
319     }
320     ~NoClassLoadingMark() {
321       _class_loading_may_happen = true;
322     }
323   };
324 #endif
325 
326   template <typename T>
327   static unsigned int hash_for_shared_dictionary_quick(T* ptr) {
328     assert(MetaspaceObj::is_shared((const MetaspaceObj*)ptr), "must be");
329     assert(ptr > (T*)SharedBaseAddress, "must be");
330     uintx offset = uintx(ptr) - uintx(SharedBaseAddress);
331     return primitive_hash<uintx>(offset);
332   }
333 
334   static unsigned int hash_for_shared_dictionary(address ptr);


335 };
336 
337 #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 

159   static DumpTimeLambdaProxyClassDictionary* _dumptime_lambda_proxy_class_dictionary;
160 
161   static ArchiveInfo _static_archive;
162   static ArchiveInfo _dynamic_archive;
163 
164   static ArchiveInfo* get_archive(bool is_static_archive) {
165     return is_static_archive ? &_static_archive : &_dynamic_archive;
166   }
167 
168   static InstanceKlass* load_shared_class_for_builtin_loader(
169                                                Symbol* class_name,
170                                                Handle class_loader,
171                                                TRAPS);
172   static InstanceKlass* acquire_class_for_current_thread(
173                                  InstanceKlass *ik,
174                                  Handle class_loader,
175                                  Handle protection_domain,
176                                  const ClassFileStream* cfs,
177                                  TRAPS);
178 




179 
180   static void write_dictionary(RunTimeSharedDictionary* dictionary,
181                                bool is_builtin);
182   static void write_lambda_proxy_class_dictionary(LambdaProxyClassDictionary* dictionary);
183   static void cleanup_lambda_proxy_class_dictionary();
184   static void reset_registered_lambda_proxy_class(InstanceKlass* ik);

185   static bool check_for_exclusion_impl(InstanceKlass* k);
186   static void remove_dumptime_info(InstanceKlass* k) NOT_CDS_RETURN;

187   static InstanceKlass* retrieve_lambda_proxy_class(const RunTimeLambdaProxyClassInfo* info) NOT_CDS_RETURN_(nullptr);
188   DEBUG_ONLY(static bool _class_loading_may_happen;)
189 
190   static void copy_verification_constraints_from_preimage(InstanceKlass* klass);
191   static void copy_linking_constraints_from_preimage(InstanceKlass* klass);
192 
193 public:
194   // Guaranteed to return non-null value for non-shared classes.
195   // k must not be a shared class.
196   static DumpTimeClassInfo* get_info(InstanceKlass* k);
197   static DumpTimeClassInfo* get_info_locked(InstanceKlass* k);
198   static DumpTimeSharedClassTable* dumptime_table() { return _dumptime_table; }
199 
200   static bool should_hidden_class_be_archived(InstanceKlass* k);
201   static void mark_required_hidden_class(InstanceKlass* k);
202   static bool has_been_redefined(InstanceKlass* k);
203   static bool is_jfr_event_class(InstanceKlass *k);
204   static bool is_registered_lambda_proxy_class(InstanceKlass* ik);
205 
206   static bool is_hidden_lambda_proxy(InstanceKlass* ik);
207   static bool is_early_klass(InstanceKlass* k);   // Was k loaded while JvmtiExport::is_early_phase()==true
208   static bool has_archived_enum_objs(InstanceKlass* ik);
209   static void set_has_archived_enum_objs(InstanceKlass* ik);
210 
211   static InstanceKlass* find_builtin_class(Symbol* class_name);
212 
213   static const RunTimeClassInfo* find_record(RunTimeSharedDictionary* static_dict,
214                                                    RunTimeSharedDictionary* dynamic_dict,
215                                                    Symbol* name);
216 
217   static bool has_platform_or_app_classes();
218 
219   // Called by PLATFORM/APP loader only
220   static InstanceKlass* find_or_load_shared_class(Symbol* class_name,
221                                                Handle class_loader,
222                                                TRAPS);
223 
224 
225   static void allocate_shared_data_arrays(int size, TRAPS);
226 
227   static bool is_builtin_loader(ClassLoaderData* loader_data);
228 
229   static InstanceKlass* lookup_super_for_unregistered_class(Symbol* class_name,
230                                                             Symbol* super_name,  bool is_superclass);
231 
232   static void initialize() NOT_CDS_RETURN;
233   static void init_dumptime_info(InstanceKlass* k) NOT_CDS_RETURN;
234   static void init_dumptime_info_from_preimage(InstanceKlass* k) NOT_CDS_RETURN;
235   static void handle_class_unloading(InstanceKlass* k) NOT_CDS_RETURN;
236 
237   static bool can_be_preinited(InstanceKlass* ik);
238   static bool can_be_preinited_locked(InstanceKlass* ik);
239   static void reset_preinit_check();
240 
241   static Dictionary* boot_loader_dictionary() {
242     return ClassLoaderData::the_null_class_loader_data()->dictionary();
243   }
244 
245   static void update_shared_entry(InstanceKlass* klass, int id);
246   static void set_shared_class_misc_info(InstanceKlass* k, ClassFileStream* cfs);
247 
248   static InstanceKlass* lookup_from_stream(Symbol* class_name,
249                                            Handle class_loader,
250                                            Handle protection_domain,
251                                            const ClassFileStream* st,
252                                            TRAPS);
253   // "verification_constraints" are a set of checks performed by
254   // VerificationType::is_reference_assignable_from when verifying a shared class during
255   // dump time.
256   //
257   // With AppCDS, it is possible to override archived classes by calling
258   // ClassLoader.defineClass() directly. SystemDictionary::load_shared_class() already
259   // ensures that you cannot load a shared class if its super type(s) are changed. However,
260   // we need an additional check to ensure that the verification_constraints did not change

271                                      InstanceKlass* lambda_ik,
272                                      Symbol* invoked_name,
273                                      Symbol* invoked_type,
274                                      Symbol* method_type,
275                                      Method* member_method,
276                                      Symbol* instantiated_method_type, TRAPS) NOT_CDS_RETURN;
277   static void add_to_dump_time_lambda_proxy_class_dictionary(LambdaProxyClassKey& key,
278                                                              InstanceKlass* proxy_klass) NOT_CDS_RETURN;
279   static InstanceKlass* get_shared_lambda_proxy_class(InstanceKlass* caller_ik,
280                                                       Symbol* invoked_name,
281                                                       Symbol* invoked_type,
282                                                       Symbol* method_type,
283                                                       Method* member_method,
284                                                       Symbol* instantiated_method_type) NOT_CDS_RETURN_(nullptr);
285   static InstanceKlass* get_shared_nest_host(InstanceKlass* lambda_ik) NOT_CDS_RETURN_(nullptr);
286   static InstanceKlass* prepare_shared_lambda_proxy_class(InstanceKlass* lambda_ik,
287                                                           InstanceKlass* caller_ik, TRAPS) NOT_CDS_RETURN_(nullptr);
288   static bool check_linking_constraints(Thread* current, InstanceKlass* klass) NOT_CDS_RETURN_(false);
289   static void record_linking_constraint(Symbol* name, InstanceKlass* klass,
290                                      Handle loader1, Handle loader2) NOT_CDS_RETURN;
291   static bool is_builtin(const InstanceKlass* k) {
292     return (k->shared_classpath_index() != UNREGISTERED_INDEX);
293   }
294   static bool add_unregistered_class(Thread* current, InstanceKlass* k);
295 
296   static void finish_exclusion_checks();

297 
298   static bool should_be_excluded(Klass* k);
299   static bool check_for_exclusion(InstanceKlass* k, DumpTimeClassInfo* info);
300   static void validate_before_archiving(InstanceKlass* k);
301   static bool is_excluded_class(InstanceKlass* k);
302   static void set_excluded(InstanceKlass* k);
303   static void set_excluded_locked(InstanceKlass* k);
304   static bool warn_excluded(InstanceKlass* k, const char* reason);
305   static void dumptime_classes_do(class MetaspaceClosure* it);
306   static void write_to_archive(bool is_static_archive = true);
307   static void adjust_lambda_proxy_class_dictionary();
308 
309   static void serialize_dictionary_headers(class SerializeClosure* soc,
310                                            bool is_static_archive = true);
311   static void serialize_vm_classes(class SerializeClosure* soc);
312   static void print() { return print_on(tty); }
313   static void print_on(outputStream* st) NOT_CDS_RETURN;
314   static void print_shared_archive(outputStream* st, bool is_static = true) NOT_CDS_RETURN;
315   static void print_table_statistics(outputStream* st) NOT_CDS_RETURN;
316   static bool is_dumptime_table_empty() NOT_CDS_RETURN_(true);
317   static bool is_supported_invokedynamic(BootstrapInfo* bsi) NOT_CDS_RETURN_(false);
318   DEBUG_ONLY(static bool class_loading_may_happen() {return _class_loading_may_happen;})
319   // Do not archive any new InstanceKlasses that are loaded after this method is called.
320   // This avoids polluting the archive with classes that are only used by GenerateJLIClassesHelper.
321   static void ignore_new_classes();
322 
323 #ifdef ASSERT
324   // This object marks a critical period when writing the CDS archive. During this
325   // period, the JVM must not load any new classes, so as to avoid adding new
326   // items in the SystemDictionaryShared::_dumptime_table.
327   class NoClassLoadingMark: public StackObj {
328   public:
329     NoClassLoadingMark() {
330       assert(_class_loading_may_happen, "must not be nested");
331       _class_loading_may_happen = false;
332     }
333     ~NoClassLoadingMark() {
334       _class_loading_may_happen = true;
335     }
336   };
337 #endif
338 
339   template <typename T>
340   static unsigned int hash_for_shared_dictionary_quick(T* ptr) {
341     assert(MetaspaceObj::is_shared((const MetaspaceObj*)ptr), "must be");
342     assert(ptr > (T*)SharedBaseAddress, "must be");
343     uintx offset = uintx(ptr) - uintx(SharedBaseAddress);
344     return primitive_hash<uintx>(offset);
345   }
346 
347   static unsigned int hash_for_shared_dictionary(address ptr);
348   static const char* class_loader_name_for_shared(Klass* k);
349   static void create_loader_positive_lookup_cache(TRAPS);
350 };
351 
352 #endif // SHARE_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
< prev index next >