< 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/filemap.hpp"
 30 #include "cds/dumpTimeClassInfo.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 

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










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




215   static Dictionary* boot_loader_dictionary() {
216     return ClassLoaderData::the_null_class_loader_data()->dictionary();
217   }
218 
219   static void update_shared_entry(InstanceKlass* klass, int id);
220   static void set_shared_class_misc_info(InstanceKlass* k, ClassFileStream* cfs);
221 
222   static InstanceKlass* lookup_from_stream(Symbol* class_name,
223                                            Handle class_loader,
224                                            Handle protection_domain,
225                                            const ClassFileStream* st,
226                                            TRAPS);
227   // "verification_constraints" are a set of checks performed by
228   // VerificationType::is_reference_assignable_from when verifying a shared class during
229   // dump time.
230   //
231   // With AppCDS, it is possible to override archived classes by calling
232   // ClassLoader.defineClass() directly. SystemDictionary::load_shared_class() already
233   // ensures that you cannot load a shared class if its super type(s) are changed. However,
234   // we need an additional check to ensure that the verification_constraints did not change
235   // between dump time and runtime.
236   static bool add_verification_constraint(InstanceKlass* k, Symbol* name,
237                   Symbol* from_name, bool from_field_is_protected,
238                   bool from_is_array, bool from_is_object) NOT_CDS_RETURN_(false);
239   static void check_verification_constraints(InstanceKlass* klass,
240                                              TRAPS) NOT_CDS_RETURN;
241   static void add_enum_klass_static_field(InstanceKlass* ik, int root_index);
242   static void set_class_has_failed_verification(InstanceKlass* ik) NOT_CDS_RETURN;
243   static bool has_class_failed_verification(InstanceKlass* ik) NOT_CDS_RETURN_(false);
244   static bool check_linking_constraints(Thread* current, InstanceKlass* klass) NOT_CDS_RETURN_(false);
245   static void record_linking_constraint(Symbol* name, InstanceKlass* klass,
246                                      Handle loader1, Handle loader2) NOT_CDS_RETURN;
247   static bool is_builtin(const InstanceKlass* k) {
248     return (k->shared_classpath_index() != UNREGISTERED_INDEX);
249   }
250   static bool add_unregistered_class(Thread* current, InstanceKlass* k);
251   static void copy_unregistered_class_size_and_crc32(InstanceKlass* klass);
252 
253   static void finish_exclusion_checks();
254   static DumpTimeSharedClassTable* dumptime_table() { return _dumptime_table; }
255 
256   static bool should_be_excluded(Klass* k);
257   static bool check_for_exclusion(InstanceKlass* k, DumpTimeClassInfo* info);
258   static void validate_before_archiving(InstanceKlass* k);
259   static bool is_excluded_class(InstanceKlass* k);
260   static void set_excluded(InstanceKlass* k);
261   static void set_excluded_locked(InstanceKlass* k);
262   static bool warn_excluded(InstanceKlass* k, const char* reason);
263   static void dumptime_classes_do(class MetaspaceClosure* it);
264   static void write_to_archive(bool is_static_archive = true);
265   static void serialize_dictionary_headers(class SerializeClosure* soc,
266                                            bool is_static_archive = true);
267   static void serialize_vm_classes(class SerializeClosure* soc);
268   static const char* loader_type_for_shared_class(Klass* k);
269   static void print() { return print_on(tty); }
270   static void print_on(outputStream* st) NOT_CDS_RETURN;
271   static void print_shared_archive(outputStream* st, bool is_static = true) NOT_CDS_RETURN;
272   static void print_table_statistics(outputStream* st) NOT_CDS_RETURN;
273   static bool is_dumptime_table_empty() NOT_CDS_RETURN_(true);
274   DEBUG_ONLY(static bool class_loading_may_happen() {return _class_loading_may_happen;})

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

301 };
302 
303 #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/filemap.hpp"
 30 #include "cds/dumpTimeClassInfo.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 

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




169 
170   static void write_dictionary(RunTimeSharedDictionary* dictionary,
171                                bool is_builtin);

172   static bool check_for_exclusion_impl(InstanceKlass* k);
173   static void remove_dumptime_info(InstanceKlass* k) NOT_CDS_RETURN;

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

263 
264   static bool should_be_excluded(Klass* k);
265   static bool check_for_exclusion(InstanceKlass* k, DumpTimeClassInfo* info);
266   static void validate_before_archiving(InstanceKlass* k);
267   static bool is_excluded_class(InstanceKlass* k);
268   static void set_excluded(InstanceKlass* k);
269   static void set_excluded_locked(InstanceKlass* k);
270   static bool warn_excluded(InstanceKlass* k, const char* reason);
271   static void dumptime_classes_do(class MetaspaceClosure* it);
272   static void write_to_archive(bool is_static_archive = true);
273   static void serialize_dictionary_headers(class SerializeClosure* soc,
274                                            bool is_static_archive = true);
275   static void serialize_vm_classes(class SerializeClosure* soc);
276   static const char* loader_type_for_shared_class(Klass* k);
277   static void print() { return print_on(tty); }
278   static void print_on(outputStream* st) NOT_CDS_RETURN;
279   static void print_shared_archive(outputStream* st, bool is_static = true) NOT_CDS_RETURN;
280   static void print_table_statistics(outputStream* st) NOT_CDS_RETURN;
281   static bool is_dumptime_table_empty() NOT_CDS_RETURN_(true);
282   DEBUG_ONLY(static bool class_loading_may_happen() {return _class_loading_may_happen;})

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