< 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 

134   }
135 };
136 
137 class SystemDictionaryShared: public SystemDictionary {
138   friend class LambdaProxyClassDictionary;
139 
140   struct ArchiveInfo {
141     RunTimeSharedDictionary _builtin_dictionary;
142     RunTimeSharedDictionary _unregistered_dictionary;
143 
144     void print_on(const char* prefix, outputStream* st, bool is_static_archive);
145     void print_table_statistics(const char* prefix, outputStream* st, bool is_static_archive);
146   };
147 
148 private:
149   class ExclusionCheckCandidates;
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 void link_all_exclusion_check_candidates(InstanceKlass* ik);
179   static bool should_be_excluded_impl(InstanceKlass* k, DumpTimeClassInfo* info);
180 
181   // exclusion checks
182   static void check_exclusion_for_self_and_dependencies(InstanceKlass *k);
183   static bool check_self_exclusion(InstanceKlass* k);
184   static const char* check_self_exclusion_helper(InstanceKlass* k, bool& log_warning);
185   static bool check_dependencies_exclusion(InstanceKlass* k, DumpTimeClassInfo* info);
186   static bool check_verification_constraint_exclusion(InstanceKlass* k, Symbol* constraint_class_name);
187   static bool is_dependency_excluded(InstanceKlass* k, InstanceKlass* dependency, const char* type);
188   static bool is_excluded_verification_constraint(InstanceKlass* k, Symbol* constraint_class_name);
189   static Klass* find_verification_constraint_bottom_class(InstanceKlass* k, Symbol* constraint_class_name);
190 
191   static void remove_dumptime_info(InstanceKlass* k) NOT_CDS_RETURN;
192   static bool has_been_redefined(InstanceKlass* k);
193   DEBUG_ONLY(static bool _class_loading_may_happen;)
194 
195   static void copy_verification_info_from_preimage(InstanceKlass* klass);
196   static void copy_linking_constraints_from_preimage(InstanceKlass* klass);
197 
198   template<typename Function>
199   static void iterate_verification_constraint_names(InstanceKlass* k, DumpTimeClassInfo* info, Function func);
200 
201 public:









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




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

254                   Symbol* from_name, bool from_field_is_protected,
255                   bool from_is_array, bool from_is_object,
256                   bool* skip_assignability_check);
257   static void add_old_verification_constraint(Thread* current, InstanceKlass* k, Symbol* name);
258   static void check_verification_constraints(InstanceKlass* klass,
259                                              TRAPS) NOT_CDS_RETURN;
260   static void add_enum_klass_static_field(InstanceKlass* ik, int root_index);
261   static void set_class_has_failed_verification(InstanceKlass* ik) NOT_CDS_RETURN;
262   static bool has_class_failed_verification(InstanceKlass* ik) NOT_CDS_RETURN_(false);
263   static bool check_linking_constraints(Thread* current, InstanceKlass* klass) NOT_CDS_RETURN_(false);
264   static void record_linking_constraint(Symbol* name, InstanceKlass* klass,
265                                      Handle loader1, Handle loader2) NOT_CDS_RETURN;
266   static bool is_builtin(const InstanceKlass* k) {
267     return (k->shared_classpath_index() != UNREGISTERED_INDEX);
268   }
269   static bool add_unregistered_class(Thread* current, InstanceKlass* k);
270   static InstanceKlass* get_unregistered_class(Symbol* name);
271   static void copy_unregistered_class_size_and_crc32(InstanceKlass* klass);
272 
273   static void finish_exclusion_checks();
274   static DumpTimeSharedClassTable* dumptime_table() { return _dumptime_table; }
275 
276   static bool should_be_excluded(Klass* k);
277   static void validate_before_archiving(InstanceKlass* k);
278   static bool is_excluded_class(InstanceKlass* k);
279   static void set_excluded(InstanceKlass* k);
280   static void set_excluded_locked(InstanceKlass* k);
281   static void set_from_class_file_load_hook(InstanceKlass* k) NOT_CDS_RETURN;
282   static void log_exclusion(InstanceKlass* k, const char* reason, bool is_warning = false);
283   static void dumptime_classes_do(class MetaspaceClosure* it);
284   static void write_to_archive(bool is_static_archive = true);
285   static void serialize_dictionary_headers(class SerializeClosure* soc,
286                                            bool is_static_archive = true);
287   static void serialize_vm_classes(class SerializeClosure* soc);
288   static const char* loader_type_for_shared_class(Klass* k);
289   static void get_all_archived_classes(bool is_static_archive, GrowableArray<Klass*>* classes);
290   static void print() { return print_on(tty); }
291   static void print_on(outputStream* st) NOT_CDS_RETURN;
292   static void print_shared_archive(outputStream* st, bool is_static = true) NOT_CDS_RETURN;
293   static void print_table_statistics(outputStream* st) NOT_CDS_RETURN;
294   static bool is_dumptime_table_empty() NOT_CDS_RETURN_(true);

302   public:
303     NoClassLoadingMark() {
304       assert(_class_loading_may_happen, "must not be nested");
305       _class_loading_may_happen = false;
306     }
307     ~NoClassLoadingMark() {
308       _class_loading_may_happen = true;
309     }
310   };
311 #endif
312 
313   template <typename T>
314   static unsigned int hash_for_shared_dictionary_quick(T* ptr) {
315     assert(MetaspaceObj::in_aot_cache((const MetaspaceObj*)ptr), "must be");
316     assert(ptr > (T*)SharedBaseAddress, "must be");
317     uintx offset = uintx(ptr) - uintx(SharedBaseAddress);
318     return primitive_hash<uintx>(offset);
319   }
320 
321   static unsigned int hash_for_shared_dictionary(address ptr);

322 };
323 
324 #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 

135   }
136 };
137 
138 class SystemDictionaryShared: public SystemDictionary {
139   friend class LambdaProxyClassDictionary;
140 
141   struct ArchiveInfo {
142     RunTimeSharedDictionary _builtin_dictionary;
143     RunTimeSharedDictionary _unregistered_dictionary;
144 
145     void print_on(const char* prefix, outputStream* st, bool is_static_archive);
146     void print_table_statistics(const char* prefix, outputStream* st, bool is_static_archive);
147   };
148 
149 private:
150   class ExclusionCheckCandidates;
151   static DumpTimeSharedClassTable* _dumptime_table;
152 
153   static ArchiveInfo _static_archive;
154   static ArchiveInfo _dynamic_archive;
155   static bool _finished_exclusion_checks;
156 
157   static ArchiveInfo* get_archive(bool is_static_archive) {
158     return is_static_archive ? &_static_archive : &_dynamic_archive;
159   }
160 
161   static InstanceKlass* load_shared_class_for_builtin_loader(
162                                                Symbol* class_name,
163                                                Handle class_loader,
164                                                TRAPS);
165   static InstanceKlass* acquire_class_for_current_thread(
166                                  InstanceKlass *ik,
167                                  Handle class_loader,
168                                  Handle protection_domain,
169                                  const ClassFileStream* cfs,
170                                  TRAPS);
171 




172 
173   static void write_dictionary(RunTimeSharedDictionary* dictionary,
174                                bool is_builtin);
175   static bool is_jfr_event_class(InstanceKlass *k);
176   static void link_all_exclusion_check_candidates(InstanceKlass* ik);
177   static bool should_be_excluded_impl(InstanceKlass* k, DumpTimeClassInfo* info);
178 
179   // exclusion checks
180   static void check_exclusion_for_self_and_dependencies(InstanceKlass *k);
181   static bool check_self_exclusion(InstanceKlass* k);
182   static const char* check_self_exclusion_helper(InstanceKlass* k, bool& log_warning);
183   static bool check_dependencies_exclusion(InstanceKlass* k, DumpTimeClassInfo* info);
184   static bool check_verification_constraint_exclusion(InstanceKlass* k, Symbol* constraint_class_name);
185   static bool is_dependency_excluded(InstanceKlass* k, InstanceKlass* dependency, const char* type);
186   static bool is_excluded_verification_constraint(InstanceKlass* k, Symbol* constraint_class_name);
187   static Klass* find_verification_constraint_bottom_class(InstanceKlass* k, Symbol* constraint_class_name);
188 
189   static void remove_dumptime_info(InstanceKlass* k) NOT_CDS_RETURN;

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

264                   Symbol* from_name, bool from_field_is_protected,
265                   bool from_is_array, bool from_is_object,
266                   bool* skip_assignability_check);
267   static void add_old_verification_constraint(Thread* current, InstanceKlass* k, Symbol* name);
268   static void check_verification_constraints(InstanceKlass* klass,
269                                              TRAPS) NOT_CDS_RETURN;
270   static void add_enum_klass_static_field(InstanceKlass* ik, int root_index);
271   static void set_class_has_failed_verification(InstanceKlass* ik) NOT_CDS_RETURN;
272   static bool has_class_failed_verification(InstanceKlass* ik) NOT_CDS_RETURN_(false);
273   static bool check_linking_constraints(Thread* current, InstanceKlass* klass) NOT_CDS_RETURN_(false);
274   static void record_linking_constraint(Symbol* name, InstanceKlass* klass,
275                                      Handle loader1, Handle loader2) NOT_CDS_RETURN;
276   static bool is_builtin(const InstanceKlass* k) {
277     return (k->shared_classpath_index() != UNREGISTERED_INDEX);
278   }
279   static bool add_unregistered_class(Thread* current, InstanceKlass* k);
280   static InstanceKlass* get_unregistered_class(Symbol* name);
281   static void copy_unregistered_class_size_and_crc32(InstanceKlass* klass);
282 
283   static void finish_exclusion_checks();

284 
285   static bool should_be_excluded(Klass* k);
286   static void validate_before_archiving(InstanceKlass* k);
287   static bool is_excluded_class(InstanceKlass* k);
288   static void set_excluded(InstanceKlass* k);
289   static void set_excluded_locked(InstanceKlass* k);
290   static void set_from_class_file_load_hook(InstanceKlass* k) NOT_CDS_RETURN;
291   static void log_exclusion(InstanceKlass* k, const char* reason, bool is_warning = false);
292   static void dumptime_classes_do(class MetaspaceClosure* it);
293   static void write_to_archive(bool is_static_archive = true);
294   static void serialize_dictionary_headers(class SerializeClosure* soc,
295                                            bool is_static_archive = true);
296   static void serialize_vm_classes(class SerializeClosure* soc);
297   static const char* loader_type_for_shared_class(Klass* k);
298   static void get_all_archived_classes(bool is_static_archive, GrowableArray<Klass*>* classes);
299   static void print() { return print_on(tty); }
300   static void print_on(outputStream* st) NOT_CDS_RETURN;
301   static void print_shared_archive(outputStream* st, bool is_static = true) NOT_CDS_RETURN;
302   static void print_table_statistics(outputStream* st) NOT_CDS_RETURN;
303   static bool is_dumptime_table_empty() NOT_CDS_RETURN_(true);

311   public:
312     NoClassLoadingMark() {
313       assert(_class_loading_may_happen, "must not be nested");
314       _class_loading_may_happen = false;
315     }
316     ~NoClassLoadingMark() {
317       _class_loading_may_happen = true;
318     }
319   };
320 #endif
321 
322   template <typename T>
323   static unsigned int hash_for_shared_dictionary_quick(T* ptr) {
324     assert(MetaspaceObj::in_aot_cache((const MetaspaceObj*)ptr), "must be");
325     assert(ptr > (T*)SharedBaseAddress, "must be");
326     uintx offset = uintx(ptr) - uintx(SharedBaseAddress);
327     return primitive_hash<uintx>(offset);
328   }
329 
330   static unsigned int hash_for_shared_dictionary(address ptr);
331   static void create_loader_positive_lookup_cache(TRAPS);
332 };
333 
334 #endif // SHARE_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
< prev index next >