< prev index next >

src/hotspot/share/classfile/systemDictionaryShared.hpp

Print this page

 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 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/dumpTimeClassInfo.hpp"
 30 #include "cds/filemap.hpp"
 31 #include "cds/runTimeClassInfo.hpp"
 32 #include "classfile/classLoaderData.hpp"
 33 #include "classfile/packageEntry.hpp"
 34 #include "classfile/systemDictionary.hpp"
 35 #include "oops/klass.hpp"
 36 #include "oops/oopHandle.hpp"

 37 
 38 
 39 /*===============================================================================
 40 
 41     Handling of the classes in the AppCDS archive
 42 
 43     To ensure safety and to simplify the implementation, archived classes are
 44     "segregated" into 2 types. The following rules describe how they
 45     are stored and looked up.
 46 
 47 [1] Category of archived classes
 48 
 49     There are 2 disjoint groups of classes stored in the AppCDS archive:
 50 
 51     BUILTIN:              These classes may be defined ONLY by the BOOT/PLATFORM/APP
 52                           loaders.
 53 
 54     UNREGISTERED:         These classes may be defined ONLY by a ClassLoader
 55                           instance that's not listed above (using fingerprint matching)
 56 

150   static DumpTimeSharedClassTable* _dumptime_table;
151 
152   static ArchiveInfo _static_archive;
153   static ArchiveInfo _dynamic_archive;
154 
155   static ArchiveInfo* get_archive(bool is_static_archive) {
156     return is_static_archive ? &_static_archive : &_dynamic_archive;
157   }
158 
159   static InstanceKlass* load_shared_class_for_builtin_loader(
160                                                Symbol* class_name,
161                                                Handle class_loader,
162                                                TRAPS);
163   static InstanceKlass* acquire_class_for_current_thread(
164                                  InstanceKlass *ik,
165                                  Handle class_loader,
166                                  Handle protection_domain,
167                                  const ClassFileStream* cfs,
168                                  TRAPS);
169 
170   // Guaranteed to return non-null value for non-shared classes.
171   // k must not be a shared class.
172   static DumpTimeClassInfo* get_info(InstanceKlass* k);
173   static DumpTimeClassInfo* get_info_locked(InstanceKlass* k);
174 
175   static void write_dictionary(RunTimeSharedDictionary* dictionary,
176                                bool is_builtin);
177   static bool is_jfr_event_class(InstanceKlass *k);
178   static bool check_for_exclusion_impl(InstanceKlass* k);
179   static void remove_dumptime_info(InstanceKlass* k) NOT_CDS_RETURN;
180   static bool has_been_redefined(InstanceKlass* k);
181   DEBUG_ONLY(static bool _class_loading_may_happen;)
182 
183   static void copy_verification_constraints_from_preimage(InstanceKlass* klass);
184   static void copy_linking_constraints_from_preimage(InstanceKlass* klass);
185 
186 public:










187   static bool is_early_klass(InstanceKlass* k);   // Was k loaded while JvmtiExport::is_early_phase()==true
188   static bool has_archived_enum_objs(InstanceKlass* ik);
189   static void set_has_archived_enum_objs(InstanceKlass* ik);
190 
191   static InstanceKlass* find_builtin_class(Symbol* class_name);
192 
193   static const RunTimeClassInfo* find_record(RunTimeSharedDictionary* static_dict,
194                                                    RunTimeSharedDictionary* dynamic_dict,
195                                                    Symbol* name);
196 
197   static bool has_platform_or_app_classes();
198 
199   // Called by PLATFORM/APP loader only
200   static InstanceKlass* find_or_load_shared_class(Symbol* class_name,
201                                                Handle class_loader,
202                                                TRAPS);
203 
204 
205   static void allocate_shared_data_arrays(int size, TRAPS);
206 
207   static bool is_builtin_loader(ClassLoaderData* loader_data);
208 
209   static InstanceKlass* lookup_super_for_unregistered_class(Symbol* class_name,
210                                                             Symbol* super_name,  bool is_superclass);
211 
212   static void initialize() NOT_CDS_RETURN;
213   static void init_dumptime_info(InstanceKlass* k) NOT_CDS_RETURN;
214   static void init_dumptime_info_from_preimage(InstanceKlass* k) NOT_CDS_RETURN;
215   static void handle_class_unloading(InstanceKlass* k) NOT_CDS_RETURN;
216 




217   static Dictionary* boot_loader_dictionary() {
218     return ClassLoaderData::the_null_class_loader_data()->dictionary();
219   }
220 
221   static void update_shared_entry(InstanceKlass* klass, int id);
222   static void set_shared_class_misc_info(InstanceKlass* k, ClassFileStream* cfs);
223 
224   static InstanceKlass* lookup_from_stream(Symbol* class_name,
225                                            Handle class_loader,
226                                            Handle protection_domain,
227                                            const ClassFileStream* st,
228                                            TRAPS);
229   // "verification_constraints" are a set of checks performed by
230   // VerificationType::is_reference_assignable_from when verifying a shared class during
231   // dump time.
232   //
233   // With AppCDS, it is possible to override archived classes by calling
234   // ClassLoader.defineClass() directly. SystemDictionary::load_shared_class() already
235   // ensures that you cannot load a shared class if its super type(s) are changed. However,
236   // we need an additional check to ensure that the verification_constraints did not change

238   static void add_verification_constraint(InstanceKlass* k, Symbol* name,
239                   Symbol* from_name, bool from_field_is_protected,
240                   bool from_is_array, bool from_is_object,
241                   bool* skip_assignability_check);
242   static void check_verification_constraints(InstanceKlass* klass,
243                                              TRAPS) NOT_CDS_RETURN;
244   static void add_enum_klass_static_field(InstanceKlass* ik, int root_index);
245   static void set_class_has_failed_verification(InstanceKlass* ik) NOT_CDS_RETURN;
246   static bool has_class_failed_verification(InstanceKlass* ik) NOT_CDS_RETURN_(false);
247   static bool check_linking_constraints(Thread* current, InstanceKlass* klass) NOT_CDS_RETURN_(false);
248   static void record_linking_constraint(Symbol* name, InstanceKlass* klass,
249                                      Handle loader1, Handle loader2) NOT_CDS_RETURN;
250   static bool is_builtin(const InstanceKlass* k) {
251     return (k->shared_classpath_index() != UNREGISTERED_INDEX);
252   }
253   static bool add_unregistered_class(Thread* current, InstanceKlass* k);
254   static InstanceKlass* get_unregistered_class(Symbol* name);
255   static void copy_unregistered_class_size_and_crc32(InstanceKlass* klass);
256 
257   static void finish_exclusion_checks();
258   static DumpTimeSharedClassTable* dumptime_table() { return _dumptime_table; }
259 
260   static bool should_be_excluded(Klass* k);
261   static bool check_for_exclusion(InstanceKlass* k, DumpTimeClassInfo* info);
262   static void validate_before_archiving(InstanceKlass* k);
263   static bool is_excluded_class(InstanceKlass* k);
264   static void set_excluded(InstanceKlass* k);
265   static void set_excluded_locked(InstanceKlass* k);
266   static void set_from_class_file_load_hook(InstanceKlass* k) NOT_CDS_RETURN;
267   static bool warn_excluded(InstanceKlass* k, const char* reason);
268   static void dumptime_classes_do(class MetaspaceClosure* it);
269   static void write_to_archive(bool is_static_archive = true);
270   static void serialize_dictionary_headers(class SerializeClosure* soc,
271                                            bool is_static_archive = true);
272   static void serialize_vm_classes(class SerializeClosure* soc);
273   static const char* loader_type_for_shared_class(Klass* k);
274   static void get_all_archived_classes(bool is_static_archive, GrowableArray<Klass*>* classes);
275   static void print() { return print_on(tty); }
276   static void print_on(outputStream* st) NOT_CDS_RETURN;
277   static void print_shared_archive(outputStream* st, bool is_static = true) NOT_CDS_RETURN;
278   static void print_table_statistics(outputStream* st) NOT_CDS_RETURN;

287   public:
288     NoClassLoadingMark() {
289       assert(_class_loading_may_happen, "must not be nested");
290       _class_loading_may_happen = false;
291     }
292     ~NoClassLoadingMark() {
293       _class_loading_may_happen = true;
294     }
295   };
296 #endif
297 
298   template <typename T>
299   static unsigned int hash_for_shared_dictionary_quick(T* ptr) {
300     assert(MetaspaceObj::in_aot_cache((const MetaspaceObj*)ptr), "must be");
301     assert(ptr > (T*)SharedBaseAddress, "must be");
302     uintx offset = uintx(ptr) - uintx(SharedBaseAddress);
303     return primitive_hash<uintx>(offset);
304   }
305 
306   static unsigned int hash_for_shared_dictionary(address ptr);

307 };
308 
309 #endif // SHARE_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP

 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 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/dumpTimeClassInfo.hpp"
 30 #include "cds/filemap.hpp"
 31 #include "cds/runTimeClassInfo.hpp"
 32 #include "classfile/classLoaderData.hpp"
 33 #include "classfile/packageEntry.hpp"
 34 #include "classfile/systemDictionary.hpp"
 35 #include "oops/klass.hpp"
 36 #include "oops/oopHandle.hpp"
 37 #include "oops/trainingData.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 

151   static DumpTimeSharedClassTable* _dumptime_table;
152 
153   static ArchiveInfo _static_archive;
154   static ArchiveInfo _dynamic_archive;
155 
156   static ArchiveInfo* get_archive(bool is_static_archive) {
157     return is_static_archive ? &_static_archive : &_dynamic_archive;
158   }
159 
160   static InstanceKlass* load_shared_class_for_builtin_loader(
161                                                Symbol* class_name,
162                                                Handle class_loader,
163                                                TRAPS);
164   static InstanceKlass* acquire_class_for_current_thread(
165                                  InstanceKlass *ik,
166                                  Handle class_loader,
167                                  Handle protection_domain,
168                                  const ClassFileStream* cfs,
169                                  TRAPS);
170 




171 
172   static void write_dictionary(RunTimeSharedDictionary* dictionary,
173                                bool is_builtin);

174   static bool check_for_exclusion_impl(InstanceKlass* k);
175   static void remove_dumptime_info(InstanceKlass* k) NOT_CDS_RETURN;

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

247   static void add_verification_constraint(InstanceKlass* k, Symbol* name,
248                   Symbol* from_name, bool from_field_is_protected,
249                   bool from_is_array, bool from_is_object,
250                   bool* skip_assignability_check);
251   static void check_verification_constraints(InstanceKlass* klass,
252                                              TRAPS) NOT_CDS_RETURN;
253   static void add_enum_klass_static_field(InstanceKlass* ik, int root_index);
254   static void set_class_has_failed_verification(InstanceKlass* ik) NOT_CDS_RETURN;
255   static bool has_class_failed_verification(InstanceKlass* ik) NOT_CDS_RETURN_(false);
256   static bool check_linking_constraints(Thread* current, InstanceKlass* klass) NOT_CDS_RETURN_(false);
257   static void record_linking_constraint(Symbol* name, InstanceKlass* klass,
258                                      Handle loader1, Handle loader2) NOT_CDS_RETURN;
259   static bool is_builtin(const InstanceKlass* k) {
260     return (k->shared_classpath_index() != UNREGISTERED_INDEX);
261   }
262   static bool add_unregistered_class(Thread* current, InstanceKlass* k);
263   static InstanceKlass* get_unregistered_class(Symbol* name);
264   static void copy_unregistered_class_size_and_crc32(InstanceKlass* klass);
265 
266   static void finish_exclusion_checks();

267 
268   static bool should_be_excluded(Klass* k);
269   static bool check_for_exclusion(InstanceKlass* k, DumpTimeClassInfo* info);
270   static void validate_before_archiving(InstanceKlass* k);
271   static bool is_excluded_class(InstanceKlass* k);
272   static void set_excluded(InstanceKlass* k);
273   static void set_excluded_locked(InstanceKlass* k);
274   static void set_from_class_file_load_hook(InstanceKlass* k) NOT_CDS_RETURN;
275   static bool warn_excluded(InstanceKlass* k, const char* reason);
276   static void dumptime_classes_do(class MetaspaceClosure* it);
277   static void write_to_archive(bool is_static_archive = true);
278   static void serialize_dictionary_headers(class SerializeClosure* soc,
279                                            bool is_static_archive = true);
280   static void serialize_vm_classes(class SerializeClosure* soc);
281   static const char* loader_type_for_shared_class(Klass* k);
282   static void get_all_archived_classes(bool is_static_archive, GrowableArray<Klass*>* classes);
283   static void print() { return print_on(tty); }
284   static void print_on(outputStream* st) NOT_CDS_RETURN;
285   static void print_shared_archive(outputStream* st, bool is_static = true) NOT_CDS_RETURN;
286   static void print_table_statistics(outputStream* st) NOT_CDS_RETURN;

295   public:
296     NoClassLoadingMark() {
297       assert(_class_loading_may_happen, "must not be nested");
298       _class_loading_may_happen = false;
299     }
300     ~NoClassLoadingMark() {
301       _class_loading_may_happen = true;
302     }
303   };
304 #endif
305 
306   template <typename T>
307   static unsigned int hash_for_shared_dictionary_quick(T* ptr) {
308     assert(MetaspaceObj::in_aot_cache((const MetaspaceObj*)ptr), "must be");
309     assert(ptr > (T*)SharedBaseAddress, "must be");
310     uintx offset = uintx(ptr) - uintx(SharedBaseAddress);
311     return primitive_hash<uintx>(offset);
312   }
313 
314   static unsigned int hash_for_shared_dictionary(address ptr);
315   static void create_loader_positive_lookup_cache(TRAPS);
316 };
317 
318 #endif // SHARE_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
< prev index next >