< prev index next >

src/hotspot/share/cds/heapShared.hpp

Print this page

  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 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_CDS_HEAPSHARED_HPP
 26 #define SHARE_CDS_HEAPSHARED_HPP
 27 

 28 #include "cds/dumpTimeClassInfo.hpp"
 29 #include "cds/metaspaceShared.hpp"
 30 #include "classfile/compactHashtable.hpp"
 31 #include "classfile/javaClasses.hpp"
 32 #include "gc/shared/gc_globals.hpp"
 33 #include "memory/allocation.hpp"
 34 #include "memory/allStatic.hpp"
 35 #include "oops/compressedOops.hpp"
 36 #include "oops/oop.hpp"
 37 #include "oops/oopHandle.hpp"
 38 #include "oops/oopsHierarchy.hpp"
 39 #include "utilities/growableArray.hpp"
 40 #include "utilities/resourceHash.hpp"
 41 
 42 #if INCLUDE_CDS_JAVA_HEAP
 43 class DumpedInternedStrings;
 44 class FileMapInfo;
 45 class KlassSubGraphInfo;
 46 class MetaspaceObjToOopHandleTable;
 47 class ResourceBitMap;

126   // (static fields) in the containing class
127   Array<Klass*>* _subgraph_object_klasses;
128  public:
129   ArchivedKlassSubGraphInfoRecord() :
130     _k(nullptr), _entry_field_records(nullptr), _subgraph_object_klasses(nullptr) {}
131   void init(KlassSubGraphInfo* info);
132   Klass* klass() const { return _k; }
133   Array<int>* entry_field_records() const { return _entry_field_records; }
134   Array<Klass*>* subgraph_object_klasses() const { return _subgraph_object_klasses; }
135   bool is_full_module_graph() const { return _is_full_module_graph; }
136   bool has_non_early_klasses() const { return _has_non_early_klasses; }
137 };
138 #endif // INCLUDE_CDS_JAVA_HEAP
139 
140 struct LoadedArchiveHeapRegion;
141 
142 class HeapShared: AllStatic {
143   friend class VerifySharedOopClosure;
144 
145 public:
146   // Can this VM write a heap region into the CDS archive? Currently only G1+compressed{oops,cp}
147   static bool can_write() {
148     CDS_JAVA_HEAP_ONLY(
149       if (_disable_writing) {
150         return false;
151       }
152       return (UseG1GC && UseCompressedClassPointers);
153     )
154     NOT_CDS_JAVA_HEAP(return false;)
155   }
156 
157   static void disable_writing() {
158     CDS_JAVA_HEAP_ONLY(_disable_writing = true;)
159   }
160 
161   static bool is_subgraph_root_class(InstanceKlass* ik);
162 
163   // Scratch objects for archiving Klass::java_mirror()
164   static oop scratch_java_mirror(BasicType t) NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
165   static oop scratch_java_mirror(Klass* k)    NOT_CDS_JAVA_HEAP_RETURN_(nullptr);

166   static bool is_archived_boot_layer_available(JavaThread* current) NOT_CDS_JAVA_HEAP_RETURN_(false);
167 




168 private:
169 #if INCLUDE_CDS_JAVA_HEAP
170   static bool _disable_writing;
171   static DumpedInternedStrings *_dumped_interned_strings;
172 
173   // statistics
174   constexpr static int ALLOC_STAT_SLOTS = 16;
175   static size_t _alloc_count[ALLOC_STAT_SLOTS];
176   static size_t _alloc_size[ALLOC_STAT_SLOTS];
177   static size_t _total_obj_count;
178   static size_t _total_obj_size; // in HeapWords
179 
180   static void count_allocation(size_t size);
181   static void print_stats();
182 public:
183   static unsigned oop_hash(oop const& p);
184   static unsigned string_oop_hash(oop const& string) {
185     return java_lang_String::hash_code(string);
186   }
187 


188   class CachedOopInfo {
189     // Used by CDSHeapVerifier.
190     oop _orig_referrer;
191 
192     // The location of this object inside ArchiveHeapWriter::_buffer
193     size_t _buffer_offset;
194 
195     // One or more fields in this object are pointing to non-null oops.
196     bool _has_oop_pointers;
197 
198     // One or more fields in this object are pointing to MetaspaceObj
199     bool _has_native_pointers;
200   public:
201     CachedOopInfo(oop orig_referrer, bool has_oop_pointers)
202       : _orig_referrer(orig_referrer),
203         _buffer_offset(0),
204         _has_oop_pointers(has_oop_pointers),
205         _has_native_pointers(false) {}
206     oop orig_referrer()             const { return _orig_referrer;   }
207     void set_buffer_offset(size_t offset) { _buffer_offset = offset; }

229   public:
230     int _count;
231   };
232 
233 public: // solaris compiler wants this for RunTimeKlassSubGraphInfoTable
234   inline static bool record_equals_compact_hashtable_entry(
235        const ArchivedKlassSubGraphInfoRecord* value, const Klass* key, int len_unused) {
236     return (value->klass() == key);
237   }
238 
239 private:
240   typedef OffsetCompactHashtable<
241     const Klass*,
242     const ArchivedKlassSubGraphInfoRecord*,
243     record_equals_compact_hashtable_entry
244     > RunTimeKlassSubGraphInfoTable;
245 
246   static DumpTimeKlassSubGraphInfoTable* _dump_time_subgraph_info_table;
247   static RunTimeKlassSubGraphInfoTable _run_time_subgraph_info_table;
248 



249   static CachedOopInfo make_cached_oop_info(oop obj);

250   static void archive_object_subgraphs(ArchivableStaticFieldInfo fields[],
251                                        bool is_full_module_graph);
252 
253   // Archive object sub-graph starting from the given static field
254   // in Klass k's mirror.
255   static void archive_reachable_objects_from_static_field(
256     InstanceKlass* k, const char* klass_name,
257     int field_offset, const char* field_name);
258 
259   static void verify_subgraph_from_static_field(
260     InstanceKlass* k, int field_offset) PRODUCT_RETURN;
261   static void verify_reachable_objects_from(oop obj) PRODUCT_RETURN;
262   static void verify_subgraph_from(oop orig_obj) PRODUCT_RETURN;
263   static void check_default_subgraph_classes();
264 
265   static KlassSubGraphInfo* init_subgraph_info(Klass *k, bool is_full_module_graph);
266   static KlassSubGraphInfo* get_subgraph_info(Klass *k);
267 
268   static void init_subgraph_entry_fields(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
269   static void init_subgraph_entry_fields(ArchivableStaticFieldInfo fields[], TRAPS);

271   // UseCompressedOops only: Used by decode_from_archive
272   static address _narrow_oop_base;
273   static int     _narrow_oop_shift;
274 
275   // !UseCompressedOops only: used to relocate pointers to the archived objects
276   static ptrdiff_t _runtime_delta;
277 
278   typedef ResizeableResourceHashtable<oop, bool,
279       AnyObj::C_HEAP,
280       mtClassShared,
281       HeapShared::oop_hash> SeenObjectsTable;
282 
283   static SeenObjectsTable *_seen_objects_table;
284 
285   // The "default subgraph" is the root of all archived objects that do not belong to any
286   // of the classes defined in the <xxx>_archive_subgraph_entry_fields[] arrays:
287   //    - interned strings
288   //    - Klass::java_mirror()
289   //    - ConstantPool::resolved_references()
290   static KlassSubGraphInfo* _default_subgraph_info;

291 
292   static GrowableArrayCHeap<oop, mtClassShared>* _pending_roots;


293   static OopHandle _roots;

294   static OopHandle _scratch_basic_type_mirrors[T_VOID+1];
295   static MetaspaceObjToOopHandleTable* _scratch_java_mirror_table;
296   static MetaspaceObjToOopHandleTable* _scratch_references_table;
297 
298   static void init_seen_objects_table() {
299     assert(_seen_objects_table == nullptr, "must be");
300     _seen_objects_table = new (mtClass)SeenObjectsTable(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
301   }
302   static void delete_seen_objects_table() {
303     assert(_seen_objects_table != nullptr, "must be");
304     delete _seen_objects_table;
305     _seen_objects_table = nullptr;
306   }
307 



308   // Statistics (for one round of start_recording_subgraph ... done_recording_subgraph)
309   static int _num_new_walked_objs;
310   static int _num_new_archived_objs;
311   static int _num_old_recorded_klasses;
312 
313   // Statistics (for all archived subgraphs)
314   static int _num_total_subgraph_recordings;
315   static int _num_total_walked_objs;
316   static int _num_total_archived_objs;
317   static int _num_total_recorded_klasses;
318   static int _num_total_verifications;
319 
320   static void start_recording_subgraph(InstanceKlass *k, const char* klass_name,
321                                        bool is_full_module_graph);
322   static void done_recording_subgraph(InstanceKlass *k, const char* klass_name);
323 
324   static bool has_been_seen_during_subgraph_recording(oop obj);
325   static void set_has_been_seen_during_subgraph_recording(oop obj);
326   static bool archive_object(oop obj);
327 
328   static void copy_interned_strings();
329 
330   static void resolve_classes_for_subgraphs(JavaThread* current, ArchivableStaticFieldInfo fields[]);
331   static void resolve_classes_for_subgraph_of(JavaThread* current, Klass* k);
332   static void clear_archived_roots_of(Klass* k);
333   static const ArchivedKlassSubGraphInfoRecord*
334                resolve_or_init_classes_for_subgraph_of(Klass* k, bool do_init, TRAPS);

335   static void resolve_or_init(Klass* k, bool do_init, TRAPS);
336   static void init_archived_fields_for(Klass* k, const ArchivedKlassSubGraphInfoRecord* record);
337 
338   static int init_loaded_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
339                                  MemRegion& archive_space);
340   static void sort_loaded_regions(LoadedArchiveHeapRegion* loaded_regions, int num_loaded_regions,
341                                   uintptr_t buffer);
342   static bool load_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
343                            int num_loaded_regions, uintptr_t buffer);
344   static void init_loaded_heap_relocation(LoadedArchiveHeapRegion* reloc_info,
345                                           int num_loaded_regions);
346   static void fill_failed_loaded_region();
347   static void mark_native_pointers(oop orig_obj);
348   static bool has_been_archived(oop orig_obj);

349   static void archive_java_mirrors();
350   static void archive_strings();
351  public:

352   static void reset_archived_object_states(TRAPS);
353   static void create_archived_object_cache() {
354     _archived_object_cache =
355       new (mtClass)ArchivedObjectCache(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
356   }
357   static void destroy_archived_object_cache() {
358     delete _archived_object_cache;
359     _archived_object_cache = nullptr;
360   }
361   static ArchivedObjectCache* archived_object_cache() {
362     return _archived_object_cache;
363   }
364 
365   static int archive_exception_instance(oop exception);
366   static void archive_objects(ArchiveHeapInfo* heap_info);
367   static void copy_objects();
368   static void copy_special_objects();
369 
370   static bool archive_reachable_objects_from(int level,
371                                              KlassSubGraphInfo* subgraph_info,
372                                              oop orig_obj);
373 
374   static ResourceBitMap calculate_oopmap(MemRegion region); // marks all the oop pointers
375   static void add_to_dumped_interned_strings(oop string);
376 


377   // Scratch objects for archiving Klass::java_mirror()
378   static void set_scratch_java_mirror(Klass* k, oop mirror);
379   static void remove_scratch_objects(Klass* k);
380   static void get_pointer_info(oop src_obj, bool& has_oop_pointers, bool& has_native_pointers);
381   static void set_has_native_pointers(oop src_obj);
382 
383   // We use the HeapShared::roots() array to make sure that objects stored in the
384   // archived heap region are not prematurely collected. These roots include:
385   //
386   //    - mirrors of classes that have not yet been loaded.
387   //    - ConstantPool::resolved_references() of classes that have not yet been loaded.
388   //    - ArchivedKlassSubGraphInfoRecords that have not been initialized
389   //    - java.lang.Module objects that have not yet been added to the module graph
390   //
391   // When a mirror M becomes referenced by a newly loaded class K, M will be removed
392   // from HeapShared::roots() via clear_root(), and K will be responsible for
393   // keeping M alive.
394   //
395   // Other types of roots are also cleared similarly when they become referenced.
396 
397   // Dump-time only. Returns the index of the root, which can be used at run time to read
398   // the root using get_root(index, ...).
399   static int append_root(oop obj);
400   static GrowableArrayCHeap<oop, mtClassShared>* pending_roots() { return _pending_roots; }
401 
402   // Dump-time and runtime
403   static objArrayOop roots();
404   static oop get_root(int index, bool clear=false);
405 
406   // Run-time only
407   static void clear_root(int index);
408 
409   static void setup_test_class(const char* test_class_name) PRODUCT_RETURN;
410 #endif // INCLUDE_CDS_JAVA_HEAP
411 
412  public:

413   static objArrayOop scratch_resolved_references(ConstantPool* src);
414   static void add_scratch_resolved_references(ConstantPool* src, objArrayOop dest) NOT_CDS_JAVA_HEAP_RETURN;
415   static void init_scratch_objects(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;

416   static bool is_heap_region(int idx) {
417     CDS_JAVA_HEAP_ONLY(return (idx == MetaspaceShared::hp);)
418     NOT_CDS_JAVA_HEAP_RETURN_(false);
419   }
420 
421   static void resolve_classes(JavaThread* current) NOT_CDS_JAVA_HEAP_RETURN;
422   static void initialize_from_archived_subgraph(JavaThread* current, Klass* k) NOT_CDS_JAVA_HEAP_RETURN;
423 
424   static void init_for_dumping(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
425   static void write_subgraph_info_table() NOT_CDS_JAVA_HEAP_RETURN;

426   static void init_roots(oop roots_oop) NOT_CDS_JAVA_HEAP_RETURN;
427   static void serialize_tables(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN;
428 
429   static bool is_a_test_class_in_unnamed_module(Klass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);















430 };
431 
432 #if INCLUDE_CDS_JAVA_HEAP
433 class DumpedInternedStrings :
434   public ResizeableResourceHashtable<oop, bool,
435                            AnyObj::C_HEAP,
436                            mtClassShared,
437                            HeapShared::string_oop_hash>
438 {
439 public:
440   DumpedInternedStrings(unsigned size, unsigned max_size) :
441     ResizeableResourceHashtable<oop, bool,
442                                 AnyObj::C_HEAP,
443                                 mtClassShared,
444                                 HeapShared::string_oop_hash>(size, max_size) {}
445 };
446 #endif
447 
448 #endif // SHARE_CDS_HEAPSHARED_HPP

  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 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_CDS_HEAPSHARED_HPP
 26 #define SHARE_CDS_HEAPSHARED_HPP
 27 
 28 #include "cds/cds_globals.hpp"
 29 #include "cds/dumpTimeClassInfo.hpp"
 30 #include "cds/metaspaceShared.hpp"
 31 #include "classfile/compactHashtable.hpp"
 32 #include "classfile/javaClasses.hpp"
 33 #include "gc/shared/gc_globals.hpp"
 34 #include "memory/allocation.hpp"
 35 #include "memory/allStatic.hpp"
 36 #include "oops/compressedOops.hpp"
 37 #include "oops/oop.hpp"
 38 #include "oops/oopHandle.hpp"
 39 #include "oops/oopsHierarchy.hpp"
 40 #include "utilities/growableArray.hpp"
 41 #include "utilities/resourceHash.hpp"
 42 
 43 #if INCLUDE_CDS_JAVA_HEAP
 44 class DumpedInternedStrings;
 45 class FileMapInfo;
 46 class KlassSubGraphInfo;
 47 class MetaspaceObjToOopHandleTable;
 48 class ResourceBitMap;

127   // (static fields) in the containing class
128   Array<Klass*>* _subgraph_object_klasses;
129  public:
130   ArchivedKlassSubGraphInfoRecord() :
131     _k(nullptr), _entry_field_records(nullptr), _subgraph_object_klasses(nullptr) {}
132   void init(KlassSubGraphInfo* info);
133   Klass* klass() const { return _k; }
134   Array<int>* entry_field_records() const { return _entry_field_records; }
135   Array<Klass*>* subgraph_object_klasses() const { return _subgraph_object_klasses; }
136   bool is_full_module_graph() const { return _is_full_module_graph; }
137   bool has_non_early_klasses() const { return _has_non_early_klasses; }
138 };
139 #endif // INCLUDE_CDS_JAVA_HEAP
140 
141 struct LoadedArchiveHeapRegion;
142 
143 class HeapShared: AllStatic {
144   friend class VerifySharedOopClosure;
145 
146 public:
147   // Can this VM write a heap region into the CDS archive? Currently only {G1|Parallel|Serial}+compressed_cp
148   static bool can_write() {
149     CDS_JAVA_HEAP_ONLY(
150       if (_disable_writing) {
151         return false;
152       }
153       return (UseG1GC || UseParallelGC || UseSerialGC) && UseCompressedClassPointers;
154     )
155     NOT_CDS_JAVA_HEAP(return false;)
156   }
157 
158   static void disable_writing() {
159     CDS_JAVA_HEAP_ONLY(_disable_writing = true;)
160   }
161 
162   static bool is_subgraph_root_class(InstanceKlass* ik);
163 
164   // Scratch objects for archiving Klass::java_mirror()
165   static oop scratch_java_mirror(BasicType t)     NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
166   static oop scratch_java_mirror(Klass* k)        NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
167   static oop scratch_java_mirror(oop java_mirror) NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
168   static bool is_archived_boot_layer_available(JavaThread* current) NOT_CDS_JAVA_HEAP_RETURN_(false);
169 
170   static void start_finding_archivable_hidden_classes() NOT_CDS_JAVA_HEAP_RETURN;
171   static void find_archivable_hidden_classes_in_object(oop o) NOT_CDS_JAVA_HEAP_RETURN;
172   static void end_finding_archivable_hidden_classes() NOT_CDS_JAVA_HEAP_RETURN;
173 
174 private:
175 #if INCLUDE_CDS_JAVA_HEAP
176   static bool _disable_writing;
177   static DumpedInternedStrings *_dumped_interned_strings;
178 
179   // statistics
180   constexpr static int ALLOC_STAT_SLOTS = 16;
181   static size_t _alloc_count[ALLOC_STAT_SLOTS];
182   static size_t _alloc_size[ALLOC_STAT_SLOTS];
183   static size_t _total_obj_count;
184   static size_t _total_obj_size; // in HeapWords
185 
186   static void count_allocation(size_t size);
187   static void print_stats();
188 public:
189   static unsigned oop_hash(oop const& p);
190   static unsigned string_oop_hash(oop const& string) {
191     return java_lang_String::hash_code(string);
192   }
193 
194   class CopyKlassSubGraphInfoToArchive;
195 
196   class CachedOopInfo {
197     // Used by CDSHeapVerifier.
198     oop _orig_referrer;
199 
200     // The location of this object inside ArchiveHeapWriter::_buffer
201     size_t _buffer_offset;
202 
203     // One or more fields in this object are pointing to non-null oops.
204     bool _has_oop_pointers;
205 
206     // One or more fields in this object are pointing to MetaspaceObj
207     bool _has_native_pointers;
208   public:
209     CachedOopInfo(oop orig_referrer, bool has_oop_pointers)
210       : _orig_referrer(orig_referrer),
211         _buffer_offset(0),
212         _has_oop_pointers(has_oop_pointers),
213         _has_native_pointers(false) {}
214     oop orig_referrer()             const { return _orig_referrer;   }
215     void set_buffer_offset(size_t offset) { _buffer_offset = offset; }

237   public:
238     int _count;
239   };
240 
241 public: // solaris compiler wants this for RunTimeKlassSubGraphInfoTable
242   inline static bool record_equals_compact_hashtable_entry(
243        const ArchivedKlassSubGraphInfoRecord* value, const Klass* key, int len_unused) {
244     return (value->klass() == key);
245   }
246 
247 private:
248   typedef OffsetCompactHashtable<
249     const Klass*,
250     const ArchivedKlassSubGraphInfoRecord*,
251     record_equals_compact_hashtable_entry
252     > RunTimeKlassSubGraphInfoTable;
253 
254   static DumpTimeKlassSubGraphInfoTable* _dump_time_subgraph_info_table;
255   static RunTimeKlassSubGraphInfoTable _run_time_subgraph_info_table;
256 
257   class FindHiddenClassesOopClosure;
258   static void find_archivable_hidden_classes_helper(ArchivableStaticFieldInfo fields[]);
259 
260   static CachedOopInfo make_cached_oop_info(oop obj);
261   static ArchivedKlassSubGraphInfoRecord* archive_subgraph_info(KlassSubGraphInfo* info);
262   static void archive_object_subgraphs(ArchivableStaticFieldInfo fields[],
263                                        bool is_full_module_graph);
264 
265   // Archive object sub-graph starting from the given static field
266   // in Klass k's mirror.
267   static void archive_reachable_objects_from_static_field(
268     InstanceKlass* k, const char* klass_name,
269     int field_offset, const char* field_name);
270 
271   static void verify_subgraph_from_static_field(
272     InstanceKlass* k, int field_offset) PRODUCT_RETURN;
273   static void verify_reachable_objects_from(oop obj) PRODUCT_RETURN;
274   static void verify_subgraph_from(oop orig_obj) PRODUCT_RETURN;
275   static void check_default_subgraph_classes();
276 
277   static KlassSubGraphInfo* init_subgraph_info(Klass *k, bool is_full_module_graph);
278   static KlassSubGraphInfo* get_subgraph_info(Klass *k);
279 
280   static void init_subgraph_entry_fields(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
281   static void init_subgraph_entry_fields(ArchivableStaticFieldInfo fields[], TRAPS);

283   // UseCompressedOops only: Used by decode_from_archive
284   static address _narrow_oop_base;
285   static int     _narrow_oop_shift;
286 
287   // !UseCompressedOops only: used to relocate pointers to the archived objects
288   static ptrdiff_t _runtime_delta;
289 
290   typedef ResizeableResourceHashtable<oop, bool,
291       AnyObj::C_HEAP,
292       mtClassShared,
293       HeapShared::oop_hash> SeenObjectsTable;
294 
295   static SeenObjectsTable *_seen_objects_table;
296 
297   // The "default subgraph" is the root of all archived objects that do not belong to any
298   // of the classes defined in the <xxx>_archive_subgraph_entry_fields[] arrays:
299   //    - interned strings
300   //    - Klass::java_mirror()
301   //    - ConstantPool::resolved_references()
302   static KlassSubGraphInfo* _default_subgraph_info;
303   static ArchivedKlassSubGraphInfoRecord* _runtime_default_subgraph_info;
304 
305   static GrowableArrayCHeap<oop, mtClassShared>* _pending_roots;
306   static GrowableArrayCHeap<oop, mtClassShared>* _trace; // for debugging unarchivable objects
307   static GrowableArrayCHeap<const char*, mtClassShared>* _context; // for debugging unarchivable objects
308   static OopHandle _roots;
309   static int _permobj_segments;
310   static OopHandle _scratch_basic_type_mirrors[T_VOID+1];
311   static MetaspaceObjToOopHandleTable* _scratch_java_mirror_table;
312   static MetaspaceObjToOopHandleTable* _scratch_references_table;
313 
314   static void init_seen_objects_table() {
315     assert(_seen_objects_table == nullptr, "must be");
316     _seen_objects_table = new (mtClass)SeenObjectsTable(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
317   }
318   static void delete_seen_objects_table() {
319     assert(_seen_objects_table != nullptr, "must be");
320     delete _seen_objects_table;
321     _seen_objects_table = nullptr;
322   }
323 
324   class ArchivingObjectMark;
325   class ContextMark;
326 
327   // Statistics (for one round of start_recording_subgraph ... done_recording_subgraph)
328   static int _num_new_walked_objs;
329   static int _num_new_archived_objs;
330   static int _num_old_recorded_klasses;
331 
332   // Statistics (for all archived subgraphs)
333   static int _num_total_subgraph_recordings;
334   static int _num_total_walked_objs;
335   static int _num_total_archived_objs;
336   static int _num_total_recorded_klasses;
337   static int _num_total_verifications;
338 
339   static void start_recording_subgraph(InstanceKlass *k, const char* klass_name,
340                                        bool is_full_module_graph);
341   static void done_recording_subgraph(InstanceKlass *k, const char* klass_name);
342 
343   static bool has_been_seen_during_subgraph_recording(oop obj);
344   static void set_has_been_seen_during_subgraph_recording(oop obj);
345   static bool archive_object(oop obj);
346   static void copy_preinitialized_mirror(Klass* orig_k, oop orig_mirror, oop m);
347   static void copy_interned_strings();
348 
349   static void resolve_classes_for_subgraphs(JavaThread* current, ArchivableStaticFieldInfo fields[]);
350   static void resolve_classes_for_subgraph_of(JavaThread* current, Klass* k);
351   static void clear_archived_roots_of(Klass* k);
352   static const ArchivedKlassSubGraphInfoRecord*
353                resolve_or_init_classes_for_subgraph_of(Klass* k, bool do_init, TRAPS);
354   static void resolve_or_init(const char* klass_name, bool do_init, TRAPS);
355   static void resolve_or_init(Klass* k, bool do_init, TRAPS);
356   static void init_archived_fields_for(Klass* k, const ArchivedKlassSubGraphInfoRecord* record);
357 
358   static int init_loaded_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
359                                  MemRegion& archive_space);
360   static void sort_loaded_regions(LoadedArchiveHeapRegion* loaded_regions, int num_loaded_regions,
361                                   uintptr_t buffer);
362   static bool load_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
363                            int num_loaded_regions, uintptr_t buffer);
364   static void init_loaded_heap_relocation(LoadedArchiveHeapRegion* reloc_info,
365                                           int num_loaded_regions);
366   static void fill_failed_loaded_region();
367   static void mark_native_pointers(oop orig_obj);
368   static bool has_been_archived(oop orig_obj);
369   static bool can_mirror_be_used_in_subgraph(oop orig_java_mirror);
370   static void archive_java_mirrors();
371   static void archive_strings();
372  public:
373   static void exit_on_error();
374   static void reset_archived_object_states(TRAPS);
375   static void create_archived_object_cache() {
376     _archived_object_cache =
377       new (mtClass)ArchivedObjectCache(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
378   }
379   static void destroy_archived_object_cache() {
380     delete _archived_object_cache;
381     _archived_object_cache = nullptr;
382   }
383   static ArchivedObjectCache* archived_object_cache() {
384     return _archived_object_cache;
385   }
386 
387   static int archive_exception_instance(oop exception);
388   static void archive_objects(ArchiveHeapInfo* heap_info);
389   static void copy_objects();
390   static void copy_special_objects();
391 
392   static bool archive_reachable_objects_from(int level,
393                                              KlassSubGraphInfo* subgraph_info,
394                                              oop orig_obj);
395 
396   static ResourceBitMap calculate_oopmap(MemRegion region); // marks all the oop pointers
397   static void add_to_dumped_interned_strings(oop string);
398 
399   static void track_scratch_object(oop orig_obj, oop scratch_obj);
400 
401   // Scratch objects for archiving Klass::java_mirror()
402   static void set_scratch_java_mirror(Klass* k, oop mirror);
403   static void remove_scratch_objects(Klass* k);
404   static void get_pointer_info(oop src_obj, bool& has_oop_pointers, bool& has_native_pointers);
405   static void set_has_native_pointers(oop src_obj);
406 
407   // We use the HeapShared::roots() array to make sure that objects stored in the
408   // archived heap region are not prematurely collected. These roots include:
409   //
410   //    - mirrors of classes that have not yet been loaded.
411   //    - ConstantPool::resolved_references() of classes that have not yet been loaded.
412   //    - ArchivedKlassSubGraphInfoRecords that have not been initialized
413   //    - java.lang.Module objects that have not yet been added to the module graph
414   //
415   // When a mirror M becomes referenced by a newly loaded class K, M will be removed
416   // from HeapShared::roots() via clear_root(), and K will be responsible for
417   // keeping M alive.
418   //
419   // Other types of roots are also cleared similarly when they become referenced.
420 
421   // Dump-time only. Returns the index of the root, which can be used at run time to read
422   // the root using get_root(index, ...).
423   static int append_root(oop obj);
424   static GrowableArrayCHeap<oop, mtClassShared>* pending_roots() { return _pending_roots; }
425 
426   // Dump-time and runtime
427   static objArrayOop roots();
428   static oop get_root(int index, bool clear=false);
429 
430   // Run-time only
431   static void clear_root(int index);
432   static void set_permobj_segments(int n) { _permobj_segments = n; }
433   static void setup_test_class(const char* test_class_name) PRODUCT_RETURN;
434 #endif // INCLUDE_CDS_JAVA_HEAP
435 
436  public:
437   static oop orig_to_scratch_object(oop orig_obj);
438   static objArrayOop scratch_resolved_references(ConstantPool* src);
439   static void add_scratch_resolved_references(ConstantPool* src, objArrayOop dest) NOT_CDS_JAVA_HEAP_RETURN;
440   static void init_scratch_objects(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
441   static void init_box_classes(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
442   static bool is_heap_region(int idx) {
443     CDS_JAVA_HEAP_ONLY(return (idx == MetaspaceShared::hp);)
444     NOT_CDS_JAVA_HEAP_RETURN_(false);
445   }
446 
447   static void resolve_classes(JavaThread* current) NOT_CDS_JAVA_HEAP_RETURN;
448   static void initialize_from_archived_subgraph(JavaThread* current, Klass* k) NOT_CDS_JAVA_HEAP_RETURN;
449 
450   static void init_for_dumping(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
451   static void write_subgraph_info_table() NOT_CDS_JAVA_HEAP_RETURN;
452   static void serialize_misc_info(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN;
453   static void init_roots(oop roots_oop) NOT_CDS_JAVA_HEAP_RETURN;
454   static void serialize_tables(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN;
455 
456   static bool is_a_test_class_in_unnamed_module(Klass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
457 
458   static void add_to_permanent_index_table(oop obj, int index);
459   // AOT-compile time only: get a stable index for an archived object.
460   // Returns 0 if obj is not archived.
461   static int get_archived_object_permanent_index(oop obj) NOT_CDS_JAVA_HEAP_RETURN_(-1);
462   // Runtime only: get back the same object for an index returned by
463   // get_archived_object_permanent_index().
464   static oop get_archived_object(int permanent_index) NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
465 
466   static void initialize_java_lang_invoke(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
467   static void initialize_default_subgraph_classes(Handle loader, TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
468 
469   static bool is_lambda_form_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
470   static bool is_lambda_proxy_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
471   static bool is_archivable_hidden_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
472 };
473 
474 #if INCLUDE_CDS_JAVA_HEAP
475 class DumpedInternedStrings :
476   public ResizeableResourceHashtable<oop, bool,
477                            AnyObj::C_HEAP,
478                            mtClassShared,
479                            HeapShared::string_oop_hash>
480 {
481 public:
482   DumpedInternedStrings(unsigned size, unsigned max_size) :
483     ResizeableResourceHashtable<oop, bool,
484                                 AnyObj::C_HEAP,
485                                 mtClassShared,
486                                 HeapShared::string_oop_hash>(size, max_size) {}
487 };
488 #endif
489 
490 #endif // SHARE_CDS_HEAPSHARED_HPP
< prev index next >