< prev index next >

src/hotspot/share/cds/dumpTimeClassInfo.hpp

Print this page

 26 #define SHARE_CDS_DUMPTIMECLASSINFO_HPP
 27 
 28 #include "cds/aotMetaspace.hpp"
 29 #include "cds/archiveBuilder.hpp"
 30 #include "cds/archiveUtils.hpp"
 31 #include "cds/cdsConfig.hpp"
 32 #include "classfile/compactHashtable.hpp"
 33 #include "memory/metaspaceClosure.hpp"
 34 #include "oops/instanceKlass.hpp"
 35 #include "prims/jvmtiExport.hpp"
 36 #include "utilities/growableArray.hpp"
 37 
 38 class Method;
 39 class Symbol;
 40 
 41 class DumpTimeClassInfo: public CHeapObj<mtClass> {
 42   bool _excluded;
 43   bool _is_aot_tooling_class;
 44   bool _is_early_klass;
 45   bool _has_checked_exclusion;


 46 
 47   class DTLoaderConstraint {
 48     Symbol* _name;
 49     char _loader_type1;
 50     char _loader_type2;
 51   public:
 52     DTLoaderConstraint() : _name(nullptr), _loader_type1('0'), _loader_type2('0') {}
 53     DTLoaderConstraint(Symbol* name, char l1, char l2) : _name(name), _loader_type1(l1), _loader_type2(l2) {
 54       Symbol::maybe_increment_refcount(_name);
 55     }
 56     DTLoaderConstraint(const DTLoaderConstraint& src) {
 57       _name = src._name;
 58       _loader_type1 = src._loader_type1;
 59       _loader_type2 = src._loader_type2;
 60       Symbol::maybe_increment_refcount(_name);
 61     }
 62     DTLoaderConstraint& operator=(DTLoaderConstraint src) {
 63       swap(_name, src._name); // c++ copy-and-swap idiom
 64       _loader_type1 = src._loader_type1;
 65       _loader_type2 = src._loader_type2;

121 
122 public:
123   InstanceKlass*               _klass;
124   InstanceKlass*               _nest_host;
125   bool                         _failed_verification;
126   bool                         _is_registered_lambda_proxy;
127   int                          _id;
128   int                          _clsfile_size;
129   int                          _clsfile_crc32;
130   GrowableArray<DTVerifierConstraint>* _verifier_constraints;
131   GrowableArray<char>*                 _verifier_constraint_flags;
132   GrowableArray<DTLoaderConstraint>*   _loader_constraints;
133   GrowableArray<int>*                  _enum_klass_static_fields;
134 
135   DumpTimeClassInfo() {
136     _klass = nullptr;
137     _nest_host = nullptr;
138     _failed_verification = false;
139     _is_registered_lambda_proxy = false;
140     _has_checked_exclusion = false;


141     _id = -1;
142     _clsfile_size = -1;
143     _clsfile_crc32 = -1;
144     _excluded = false;
145     _is_aot_tooling_class = false;
146     _is_early_klass = JvmtiExport::is_early_phase();
147     _verifier_constraints = nullptr;
148     _verifier_constraint_flags = nullptr;
149     _loader_constraints = nullptr;
150     _enum_klass_static_fields = nullptr;
151   }
152   DumpTimeClassInfo& operator=(const DumpTimeClassInfo&) = delete;
153   ~DumpTimeClassInfo();
154 
155   // For old verifier: only name is saved; all other fields are null/false.
156   void add_verification_constraint(Symbol* name,
157          Symbol* from_name = nullptr, bool from_field_is_protected = false, bool from_is_array = false, bool from_is_object = false);
158   void record_linking_constraint(Symbol* name, Handle loader1, Handle loader2);
159   void add_enum_klass_static_field(int archived_heap_root_index);
160   int  enum_klass_static_field(int which_field);

216   }
217 
218   void set_is_aot_tooling_class() {
219     _is_aot_tooling_class = true;
220   }
221 
222   // Was this class loaded while JvmtiExport::is_early_phase()==true
223   bool is_early_klass() {
224     return _is_early_klass;
225   }
226 
227   // simple accessors
228   void set_excluded()                               { _excluded = true; }
229   bool has_checked_exclusion() const                { return _has_checked_exclusion; }
230   void set_has_checked_exclusion()                  { _has_checked_exclusion = true; }
231   bool failed_verification() const                  { return _failed_verification; }
232   void set_failed_verification()                    { _failed_verification = true; }
233   InstanceKlass* nest_host() const                  { return _nest_host; }
234   void set_nest_host(InstanceKlass* nest_host)      { _nest_host = nest_host; }
235 












236   size_t runtime_info_bytesize() const;
237 };
238 
239 template <typename T>
240 inline unsigned DumpTimeSharedClassTable_hash(T* const& k) {
241   if (CDSConfig::is_dumping_static_archive()) {
242     // Deterministic archive contents
243     uintx delta = k->name() - AOTMetaspace::symbol_rs_base();
244     return primitive_hash<uintx>(delta);
245   } else {
246     // Deterministic archive is not possible because classes can be loaded
247     // in multiple threads.
248     return primitive_hash<T*>(k);
249   }
250 }
251 
252 using DumpTimeSharedClassTableBaseType = HashTable<
253   InstanceKlass*,
254   DumpTimeClassInfo,
255   15889, // prime number

264 public:
265   DumpTimeSharedClassTable() {
266     _builtin_count = 0;
267     _unregistered_count = 0;
268   }
269   DumpTimeClassInfo* allocate_info(InstanceKlass* k);
270   DumpTimeClassInfo* get_info(InstanceKlass* k);
271   void inc_builtin_count()      { _builtin_count++; }
272   void inc_unregistered_count() { _unregistered_count++; }
273   void update_counts();
274   int count_of(bool is_builtin) const {
275     if (is_builtin) {
276       return _builtin_count;
277     } else {
278       return _unregistered_count;
279     }
280   }
281 
282   template<class ITER> void iterate_all_live_classes(ITER* iter) const;
283   template<typename Function> void iterate_all_live_classes(Function function) const;

284 
285 private:
286   // It's unsafe to iterate on classes whose loader is dead.
287   // Declare these private and don't implement them. This forces users of
288   // DumpTimeSharedClassTable to use the iterate_all_live_classes() methods
289   // instead.
290   template<class ITER> void iterate(ITER* iter) const;
291   template<typename Function> void iterate(Function function) const;
292   template<typename Function> void iterate_all(Function function) const;
293 };
294 
295 #endif // SHARE_CDS_DUMPTIMECLASSINFO_HPP

 26 #define SHARE_CDS_DUMPTIMECLASSINFO_HPP
 27 
 28 #include "cds/aotMetaspace.hpp"
 29 #include "cds/archiveBuilder.hpp"
 30 #include "cds/archiveUtils.hpp"
 31 #include "cds/cdsConfig.hpp"
 32 #include "classfile/compactHashtable.hpp"
 33 #include "memory/metaspaceClosure.hpp"
 34 #include "oops/instanceKlass.hpp"
 35 #include "prims/jvmtiExport.hpp"
 36 #include "utilities/growableArray.hpp"
 37 
 38 class Method;
 39 class Symbol;
 40 
 41 class DumpTimeClassInfo: public CHeapObj<mtClass> {
 42   bool _excluded;
 43   bool _is_aot_tooling_class;
 44   bool _is_early_klass;
 45   bool _has_checked_exclusion;
 46   bool _can_be_preinited;
 47   bool _has_done_preinit_check;
 48 
 49   class DTLoaderConstraint {
 50     Symbol* _name;
 51     char _loader_type1;
 52     char _loader_type2;
 53   public:
 54     DTLoaderConstraint() : _name(nullptr), _loader_type1('0'), _loader_type2('0') {}
 55     DTLoaderConstraint(Symbol* name, char l1, char l2) : _name(name), _loader_type1(l1), _loader_type2(l2) {
 56       Symbol::maybe_increment_refcount(_name);
 57     }
 58     DTLoaderConstraint(const DTLoaderConstraint& src) {
 59       _name = src._name;
 60       _loader_type1 = src._loader_type1;
 61       _loader_type2 = src._loader_type2;
 62       Symbol::maybe_increment_refcount(_name);
 63     }
 64     DTLoaderConstraint& operator=(DTLoaderConstraint src) {
 65       swap(_name, src._name); // c++ copy-and-swap idiom
 66       _loader_type1 = src._loader_type1;
 67       _loader_type2 = src._loader_type2;

123 
124 public:
125   InstanceKlass*               _klass;
126   InstanceKlass*               _nest_host;
127   bool                         _failed_verification;
128   bool                         _is_registered_lambda_proxy;
129   int                          _id;
130   int                          _clsfile_size;
131   int                          _clsfile_crc32;
132   GrowableArray<DTVerifierConstraint>* _verifier_constraints;
133   GrowableArray<char>*                 _verifier_constraint_flags;
134   GrowableArray<DTLoaderConstraint>*   _loader_constraints;
135   GrowableArray<int>*                  _enum_klass_static_fields;
136 
137   DumpTimeClassInfo() {
138     _klass = nullptr;
139     _nest_host = nullptr;
140     _failed_verification = false;
141     _is_registered_lambda_proxy = false;
142     _has_checked_exclusion = false;
143     _can_be_preinited = false;
144     _has_done_preinit_check = false;
145     _id = -1;
146     _clsfile_size = -1;
147     _clsfile_crc32 = -1;
148     _excluded = false;
149     _is_aot_tooling_class = false;
150     _is_early_klass = JvmtiExport::is_early_phase();
151     _verifier_constraints = nullptr;
152     _verifier_constraint_flags = nullptr;
153     _loader_constraints = nullptr;
154     _enum_klass_static_fields = nullptr;
155   }
156   DumpTimeClassInfo& operator=(const DumpTimeClassInfo&) = delete;
157   ~DumpTimeClassInfo();
158 
159   // For old verifier: only name is saved; all other fields are null/false.
160   void add_verification_constraint(Symbol* name,
161          Symbol* from_name = nullptr, bool from_field_is_protected = false, bool from_is_array = false, bool from_is_object = false);
162   void record_linking_constraint(Symbol* name, Handle loader1, Handle loader2);
163   void add_enum_klass_static_field(int archived_heap_root_index);
164   int  enum_klass_static_field(int which_field);

220   }
221 
222   void set_is_aot_tooling_class() {
223     _is_aot_tooling_class = true;
224   }
225 
226   // Was this class loaded while JvmtiExport::is_early_phase()==true
227   bool is_early_klass() {
228     return _is_early_klass;
229   }
230 
231   // simple accessors
232   void set_excluded()                               { _excluded = true; }
233   bool has_checked_exclusion() const                { return _has_checked_exclusion; }
234   void set_has_checked_exclusion()                  { _has_checked_exclusion = true; }
235   bool failed_verification() const                  { return _failed_verification; }
236   void set_failed_verification()                    { _failed_verification = true; }
237   InstanceKlass* nest_host() const                  { return _nest_host; }
238   void set_nest_host(InstanceKlass* nest_host)      { _nest_host = nest_host; }
239 
240   bool can_be_preinited() const                     { return _can_be_preinited; }
241   bool has_done_preinit_check() const               { return _has_done_preinit_check; }
242 
243   void set_can_be_preinited(bool v) {
244     _can_be_preinited = v;
245     _has_done_preinit_check = true;
246   }
247   void reset_preinit_check() {
248     _can_be_preinited = false;
249     _has_done_preinit_check = false;
250   }
251 
252   size_t runtime_info_bytesize() const;
253 };
254 
255 template <typename T>
256 inline unsigned DumpTimeSharedClassTable_hash(T* const& k) {
257   if (CDSConfig::is_dumping_static_archive()) {
258     // Deterministic archive contents
259     uintx delta = k->name() - AOTMetaspace::symbol_rs_base();
260     return primitive_hash<uintx>(delta);
261   } else {
262     // Deterministic archive is not possible because classes can be loaded
263     // in multiple threads.
264     return primitive_hash<T*>(k);
265   }
266 }
267 
268 using DumpTimeSharedClassTableBaseType = HashTable<
269   InstanceKlass*,
270   DumpTimeClassInfo,
271   15889, // prime number

280 public:
281   DumpTimeSharedClassTable() {
282     _builtin_count = 0;
283     _unregistered_count = 0;
284   }
285   DumpTimeClassInfo* allocate_info(InstanceKlass* k);
286   DumpTimeClassInfo* get_info(InstanceKlass* k);
287   void inc_builtin_count()      { _builtin_count++; }
288   void inc_unregistered_count() { _unregistered_count++; }
289   void update_counts();
290   int count_of(bool is_builtin) const {
291     if (is_builtin) {
292       return _builtin_count;
293     } else {
294       return _unregistered_count;
295     }
296   }
297 
298   template<class ITER> void iterate_all_live_classes(ITER* iter) const;
299   template<typename Function> void iterate_all_live_classes(Function function) const;
300   template<typename Function> void iterate_all_classes_in_builtin_loaders(Function function) const;
301 
302 private:
303   // It's unsafe to iterate on classes whose loader is dead.
304   // Declare these private and don't implement them. This forces users of
305   // DumpTimeSharedClassTable to use the iterate_all_live_classes() methods
306   // instead.
307   template<class ITER> void iterate(ITER* iter) const;
308   template<typename Function> void iterate(Function function) const;
309   template<typename Function> void iterate_all(Function function) const;
310 };
311 
312 #endif // SHARE_CDS_DUMPTIMECLASSINFO_HPP
< prev index next >