< prev index next >

src/hotspot/share/cds/heapShared.hpp

Print this page

  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/aotMetaspace.hpp"

 29 #include "cds/dumpTimeClassInfo.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/hashTable.hpp"
 41 
 42 #if INCLUDE_CDS_JAVA_HEAP
 43 class DumpedInternedStrings;
 44 class FileMapInfo;
 45 class KlassSubGraphInfo;
 46 class MetaspaceObjToOopHandleTable;
 47 class ResourceBitMap;
 48 
 49 struct ArchivableStaticFieldInfo;
 50 
 51 #define ARCHIVED_BOOT_LAYER_CLASS "jdk/internal/module/ArchivedBootLayer"
 52 #define ARCHIVED_BOOT_LAYER_FIELD "archivedBootLayer"
 53 
 54 // A dump time sub-graph info for Klass _k. It includes the entry points
 55 // (static fields in _k's mirror) of the archived sub-graphs reachable
 56 // from _k's mirror. It also contains a list of Klasses of the objects
 57 // within the sub-graphs.
 58 class KlassSubGraphInfo: public CHeapObj<mtClass> {
 59  private:
 60   // The class that contains the static field(s) as the entry point(s)
 61   // of archived object sub-graph(s).
 62   Klass* _k;
 63   // A list of classes need to be loaded and initialized before the archived

282   inline static bool is_writing_streaming_mode() NOT_CDS_JAVA_HEAP_RETURN_(false);
283   inline static bool is_writing_mapping_mode() NOT_CDS_JAVA_HEAP_RETURN_(false);
284 
285   static bool is_subgraph_root_class(InstanceKlass* ik);
286 
287   // Scratch objects for archiving Klass::java_mirror()
288   static oop scratch_java_mirror(BasicType t)     NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
289   static oop scratch_java_mirror(Klass* k)        NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
290   static oop scratch_java_mirror(oop java_mirror) NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
291   static bool is_archived_boot_layer_available(JavaThread* current) NOT_CDS_JAVA_HEAP_RETURN_(false);
292 
293   static bool is_archived_heap_in_use() NOT_CDS_JAVA_HEAP_RETURN_(false);
294   static bool can_use_archived_heap() NOT_CDS_JAVA_HEAP_RETURN_(false);
295   static bool is_too_large_to_archive(size_t size);
296   static bool is_string_too_large_to_archive(oop string);
297   static bool is_too_large_to_archive(oop obj);
298 
299   static void initialize_streaming() NOT_CDS_JAVA_HEAP_RETURN;
300   static void enable_gc() NOT_CDS_JAVA_HEAP_RETURN;
301   static void materialize_thread_object() NOT_CDS_JAVA_HEAP_RETURN;
302   static void add_to_dumped_interned_strings(oop string) NOT_CDS_JAVA_HEAP_RETURN;
303   static void finalize_initialization(FileMapInfo* static_mapinfo) NOT_CDS_JAVA_HEAP_RETURN;
304 
305 private:
306 #if INCLUDE_CDS_JAVA_HEAP
307   static HeapArchiveMode _heap_load_mode;
308   static HeapArchiveMode _heap_write_mode;
309 
310   // statistics
311   constexpr static int ALLOC_STAT_SLOTS = 16;
312   static size_t _alloc_count[ALLOC_STAT_SLOTS];
313   static size_t _alloc_size[ALLOC_STAT_SLOTS];
314   static size_t _total_obj_count;
315   static size_t _total_obj_size; // in HeapWords
316 
317   static void count_allocation(size_t size);
318   static void print_stats();
319 public:
320   static void debug_trace();
321   static unsigned oop_hash(oop const& p);
322   static unsigned oop_handle_hash(OopHandle const& oh);
323   static unsigned oop_handle_hash_raw(OopHandle const& oh);
324   static bool oop_handle_equals(const OopHandle& a, const OopHandle& b);
325   static unsigned string_oop_hash(oop const& string) {
326     return java_lang_String::hash_code(string);
327   }
328 
329   class CopyKlassSubGraphInfoToArchive;
330 
331   class CachedOopInfo {
332     // Used by CDSHeapVerifier.
333     OopHandle _orig_referrer;
334 
335     // The location of this object inside {AOTMappedHeapWriter, AOTStreamedHeapWriter}::_buffer
336     size_t _buffer_offset;
337 
338     // One or more fields in this object are pointing to non-null oops.
339     bool _has_oop_pointers;
340 
341     // One or more fields in this object are pointing to MetaspaceObj
342     bool _has_native_pointers;



343   public:
344     CachedOopInfo(OopHandle orig_referrer, bool has_oop_pointers)
345       : _orig_referrer(orig_referrer),
346         _buffer_offset(0),
347         _has_oop_pointers(has_oop_pointers),
348         _has_native_pointers(false) {}

349     oop orig_referrer() const;
350     void set_buffer_offset(size_t offset) { _buffer_offset = offset; }
351     size_t buffer_offset()          const { return _buffer_offset;   }
352     bool has_oop_pointers()         const { return _has_oop_pointers; }
353     bool has_native_pointers()      const { return _has_native_pointers; }
354     void set_has_native_pointers()        { _has_native_pointers = true; }


355   };
356 
357 private:
358   static const int INITIAL_TABLE_SIZE = 15889; // prime number
359   static const int MAX_TABLE_SIZE     = 1000000;




360   typedef ResizeableHashTable<OopHandle, CachedOopInfo,
361       AnyObj::C_HEAP,
362       mtClassShared,
363       HeapShared::oop_handle_hash_raw,
364       HeapShared::oop_handle_equals> ArchivedObjectCache;
365   static ArchivedObjectCache* _archived_object_cache;
366 
367   class DumpTimeKlassSubGraphInfoTable
368     : public HashTable<Klass*, KlassSubGraphInfo,
369                                137, // prime number
370                                AnyObj::C_HEAP,
371                                mtClassShared,
372                                DumpTimeSharedClassTable_hash> {};
373 
374 public: // solaris compiler wants this for RunTimeKlassSubGraphInfoTable
375   inline static bool record_equals_compact_hashtable_entry(
376        const ArchivedKlassSubGraphInfoRecord* value, const Klass* key, int len_unused) {
377     return (value->klass() == key);
378   }
379 
380 private:
381   typedef OffsetCompactHashtable<
382     const Klass*,
383     const ArchivedKlassSubGraphInfoRecord*,

417   // !UseCompressedOops only: used to relocate pointers to the archived objects
418   static ptrdiff_t _runtime_delta;
419 
420   typedef ResizeableHashTable<oop, bool,
421       AnyObj::C_HEAP,
422       mtClassShared,
423       HeapShared::oop_hash> SeenObjectsTable;
424 
425   static SeenObjectsTable *_seen_objects_table;
426 
427   // The "special subgraph" contains all the archived objects that are reachable
428   // from the following roots:
429   //    - interned strings
430   //    - Klass::java_mirror() -- including aot-initialized mirrors such as those of Enum klasses.
431   //    - ConstantPool::resolved_references()
432   //    - Universe::<xxx>_exception_instance()
433   static KlassSubGraphInfo* _dump_time_special_subgraph;              // for collecting info during dump time
434   static ArchivedKlassSubGraphInfoRecord* _run_time_special_subgraph; // for initializing classes during run time.
435 
436   static GrowableArrayCHeap<oop, mtClassShared>* _pending_roots;

437   static OopHandle _scratch_basic_type_mirrors[T_VOID+1];
438   static MetaspaceObjToOopHandleTable* _scratch_objects_table;
439 
440   static void init_seen_objects_table() {
441     assert(_seen_objects_table == nullptr, "must be");
442     _seen_objects_table = new (mtClass)SeenObjectsTable(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
443   }
444   static void delete_seen_objects_table() {
445     assert(_seen_objects_table != nullptr, "must be");
446     delete _seen_objects_table;
447     _seen_objects_table = nullptr;
448   }
449 


450   // Statistics (for one round of start_recording_subgraph ... done_recording_subgraph)
451   static size_t _num_new_walked_objs;
452   static size_t _num_new_archived_objs;
453   static size_t _num_old_recorded_klasses;
454 
455   // Statistics (for all archived subgraphs)
456   static size_t _num_total_subgraph_recordings;
457   static size_t _num_total_walked_objs;
458   static size_t _num_total_archived_objs;
459   static size_t _num_total_recorded_klasses;
460   static size_t _num_total_verifications;
461 
462   static void start_recording_subgraph(InstanceKlass *k, const char* klass_name,
463                                        bool is_full_module_graph);
464   static void done_recording_subgraph(InstanceKlass *k, const char* klass_name);
465 
466   static bool has_been_seen_during_subgraph_recording(oop obj);
467   static void set_has_been_seen_during_subgraph_recording(oop obj);
468   static bool archive_object(oop obj, oop referrer, KlassSubGraphInfo* subgraph_info);
469 

489     oop _referrer;
490     int _level;
491 
492   public:
493     PendingOop() : _obj(nullptr), _referrer(nullptr), _level(-1) {}
494     PendingOop(oop obj, oop referrer, int level) : _obj(obj), _referrer(referrer), _level(level) {}
495 
496     oop obj()      const { return _obj; }
497     oop referrer() const { return _referrer; }
498     int level()    const { return _level; }
499   };
500 
501   class OopFieldPusher;
502   using PendingOopStack = GrowableArrayCHeap<PendingOop, mtClassShared>;
503 
504   static PendingOop _object_being_archived;
505   static bool walk_one_object(PendingOopStack* stack, int level, KlassSubGraphInfo* subgraph_info,
506                               oop orig_obj, oop referrer);
507 
508  public:

509   static void reset_archived_object_states(TRAPS);
510   static void create_archived_object_cache() {
511     _archived_object_cache =
512       new (mtClass)ArchivedObjectCache(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
513   }
514   static void destroy_archived_object_cache() {
515     delete _archived_object_cache;
516     _archived_object_cache = nullptr;
517   }

518   static ArchivedObjectCache* archived_object_cache() {
519     return _archived_object_cache;
520   }
521 
522   static CachedOopInfo* get_cached_oop_info(oop orig_obj);
523 
524   static int archive_exception_instance(oop exception);
525 
526   static bool archive_reachable_objects_from(int level,
527                                              KlassSubGraphInfo* subgraph_info,
528                                              oop orig_obj);
529 

530   static bool is_dumped_interned_string(oop o);
531 


532   // Scratch objects for archiving Klass::java_mirror()
533   static void set_scratch_java_mirror(Klass* k, oop mirror);
534   static void remove_scratch_objects(Klass* k);
535   static bool is_metadata_field(oop src_obj, int offset);
536   template <typename T> static void do_metadata_offsets(oop src_obj, T callback);
537   static void remap_dumped_metadata(oop src_obj, address archived_object);
538   inline static void remap_loaded_metadata(oop obj);
539   inline static oop maybe_remap_referent(bool is_java_lang_ref, size_t field_offset, oop referent);
540   static void get_pointer_info(oop src_obj, bool& has_oop_pointers, bool& has_native_pointers);
541   static void set_has_native_pointers(oop src_obj);
542   static uintptr_t archive_location(oop src_obj);
543 
544   // We use the HeapShared::roots() array to make sure that objects stored in the
545   // archived heap region are not prematurely collected. These roots include:
546   //
547   //    - mirrors of classes that have not yet been loaded.
548   //    - ConstantPool::resolved_references() of classes that have not yet been loaded.
549   //    - ArchivedKlassSubGraphInfoRecords that have not been initialized
550   //    - java.lang.Module objects that have not yet been added to the module graph
551   //
552   // When a mirror M becomes referenced by a newly loaded class K, M will be removed
553   // from HeapShared::roots() via clear_root(), and K will be responsible for
554   // keeping M alive.
555   //
556   // Other types of roots are also cleared similarly when they become referenced.
557 
558   // Dump-time only. Returns the index of the root, which can be used at run time to read
559   // the root using get_root(index, ...).
560   static int append_root(oop obj);





561   static GrowableArrayCHeap<oop, mtClassShared>* pending_roots() { return _pending_roots; }
562 
563   // Dump-time and runtime
564   static objArrayOop root_segment(int segment_idx);
565   static oop get_root(int index, bool clear=false);
566 
567   // Run-time only
568   static void clear_root(int index);
569 
570   static void get_segment_indexes(int index, int& segment_index, int& internal_index);
571 
572   static void setup_test_class(const char* test_class_name) PRODUCT_RETURN;
573 #endif // INCLUDE_CDS_JAVA_HEAP
574 
575  public:
576   static void finish_materialize_objects() NOT_CDS_JAVA_HEAP_RETURN;
577 
578   static void write_heap(ArchiveMappedHeapInfo* mapped_heap_info, ArchiveStreamedHeapInfo* streamed_heap_info) NOT_CDS_JAVA_HEAP_RETURN;
579   static objArrayOop scratch_resolved_references(ConstantPool* src);
580   static void add_scratch_resolved_references(ConstantPool* src, objArrayOop dest) NOT_CDS_JAVA_HEAP_RETURN;
581   static void init_dumping() NOT_CDS_JAVA_HEAP_RETURN;
582   static void init_scratch_objects_for_basic_type_mirrors(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
583   static void init_box_classes(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
584   static bool is_heap_region(int idx) {
585     CDS_JAVA_HEAP_ONLY(return (idx == AOTMetaspace::hp);)
586     NOT_CDS_JAVA_HEAP_RETURN_(false);
587   }
588   static void delete_tables_with_raw_oops() NOT_CDS_JAVA_HEAP_RETURN;
589 
590   static void resolve_classes(JavaThread* current) NOT_CDS_JAVA_HEAP_RETURN;
591   static void initialize_from_archived_subgraph(JavaThread* current, Klass* k) NOT_CDS_JAVA_HEAP_RETURN;
592 
593   static void init_for_dumping(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
594   static void init_heap_writer() NOT_CDS_JAVA_HEAP_RETURN;
595   static void write_subgraph_info_table() NOT_CDS_JAVA_HEAP_RETURN;
596   static void serialize_tables(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN;
597 
598 #ifndef PRODUCT
599   static bool is_a_test_class_in_unnamed_module(Klass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
600   static void initialize_test_class_from_archive(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
601 #endif
602 
603   static void initialize_java_lang_invoke(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
604   static void init_classes_for_special_subgraph(Handle loader, TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
605 

606   static bool is_lambda_form_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
607   static bool is_lambda_proxy_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
608   static bool is_string_concat_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
609   static bool is_archivable_hidden_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
610 
611   // Used by AOTArtifactFinder
612   static void start_scanning_for_oops();
613   static void end_scanning_for_oops();
614   static void scan_java_class(Klass* k);
615   static void scan_java_mirror(oop orig_mirror);
616   static void copy_and_rescan_aot_inited_mirror(InstanceKlass* ik);
617 
618   static void log_heap_roots();
619 
620   static intptr_t log_target_location(oop source_oop);
621   static void log_oop_info(outputStream* st, oop source_oop, address archived_object_start, address archived_object_end);
622   static void log_oop_info(outputStream* st, oop source_oop);
623   static void log_oop_details(oop source_oop, address buffered_addr);
624 };
625 

  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/aotMetaspace.hpp"
 29 #include "cds/cds_globals.hpp"
 30 #include "cds/dumpTimeClassInfo.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/hashTable.hpp"
 42 
 43 #if INCLUDE_CDS_JAVA_HEAP

 44 class FileMapInfo;
 45 class KlassSubGraphInfo;
 46 class MetaspaceObjToOopHandleTable;
 47 class ResourceBitMap;
 48 
 49 struct ArchivableStaticFieldInfo;
 50 
 51 #define ARCHIVED_BOOT_LAYER_CLASS "jdk/internal/module/ArchivedBootLayer"
 52 #define ARCHIVED_BOOT_LAYER_FIELD "archivedBootLayer"
 53 
 54 // A dump time sub-graph info for Klass _k. It includes the entry points
 55 // (static fields in _k's mirror) of the archived sub-graphs reachable
 56 // from _k's mirror. It also contains a list of Klasses of the objects
 57 // within the sub-graphs.
 58 class KlassSubGraphInfo: public CHeapObj<mtClass> {
 59  private:
 60   // The class that contains the static field(s) as the entry point(s)
 61   // of archived object sub-graph(s).
 62   Klass* _k;
 63   // A list of classes need to be loaded and initialized before the archived

282   inline static bool is_writing_streaming_mode() NOT_CDS_JAVA_HEAP_RETURN_(false);
283   inline static bool is_writing_mapping_mode() NOT_CDS_JAVA_HEAP_RETURN_(false);
284 
285   static bool is_subgraph_root_class(InstanceKlass* ik);
286 
287   // Scratch objects for archiving Klass::java_mirror()
288   static oop scratch_java_mirror(BasicType t)     NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
289   static oop scratch_java_mirror(Klass* k)        NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
290   static oop scratch_java_mirror(oop java_mirror) NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
291   static bool is_archived_boot_layer_available(JavaThread* current) NOT_CDS_JAVA_HEAP_RETURN_(false);
292 
293   static bool is_archived_heap_in_use() NOT_CDS_JAVA_HEAP_RETURN_(false);
294   static bool can_use_archived_heap() NOT_CDS_JAVA_HEAP_RETURN_(false);
295   static bool is_too_large_to_archive(size_t size);
296   static bool is_string_too_large_to_archive(oop string);
297   static bool is_too_large_to_archive(oop obj);
298 
299   static void initialize_streaming() NOT_CDS_JAVA_HEAP_RETURN;
300   static void enable_gc() NOT_CDS_JAVA_HEAP_RETURN;
301   static void materialize_thread_object() NOT_CDS_JAVA_HEAP_RETURN;
302   static void archive_interned_string(oop string);
303   static void finalize_initialization(FileMapInfo* static_mapinfo) NOT_CDS_JAVA_HEAP_RETURN;
304 
305 private:
306 #if INCLUDE_CDS_JAVA_HEAP
307   static HeapArchiveMode _heap_load_mode;
308   static HeapArchiveMode _heap_write_mode;
309 
310   // statistics
311   constexpr static int ALLOC_STAT_SLOTS = 16;
312   static size_t _alloc_count[ALLOC_STAT_SLOTS];
313   static size_t _alloc_size[ALLOC_STAT_SLOTS];
314   static size_t _total_obj_count;
315   static size_t _total_obj_size; // in HeapWords
316 
317   static void count_allocation(size_t size);
318   static void print_stats();
319 public:
320   static void debug_trace();
321   static unsigned oop_hash(oop const& p);


322   static bool oop_handle_equals(const OopHandle& a, const OopHandle& b);



323 
324   class CopyKlassSubGraphInfoToArchive;
325 
326   class CachedOopInfo {
327     // Used by CDSHeapVerifier.
328     OopHandle _orig_referrer;
329 
330     // The location of this object inside {AOTMappedHeapWriter, AOTStreamedHeapWriter}::_buffer
331     size_t _buffer_offset;
332 
333     // One or more fields in this object are pointing to non-null oops.
334     bool _has_oop_pointers;
335 
336     // One or more fields in this object are pointing to MetaspaceObj
337     bool _has_native_pointers;
338 
339     // >= 0 if this oop has been append to the list of roots
340     int _root_index;
341   public:
342     CachedOopInfo(OopHandle orig_referrer, bool has_oop_pointers)
343       : _orig_referrer(orig_referrer),
344         _buffer_offset(0),
345         _has_oop_pointers(has_oop_pointers),
346         _has_native_pointers(false),
347         _root_index(-1) {}
348     oop orig_referrer() const;
349     void set_buffer_offset(size_t offset) { _buffer_offset = offset; }
350     size_t buffer_offset()          const { return _buffer_offset;   }
351     bool has_oop_pointers()         const { return _has_oop_pointers; }
352     bool has_native_pointers()      const { return _has_native_pointers; }
353     void set_has_native_pointers()        { _has_native_pointers = true; }
354     int  root_index()               const { return _root_index; }
355     void set_root_index(int i)            { _root_index = i; }
356   };
357 
358 private:
359   static const int INITIAL_TABLE_SIZE = 15889; // prime number
360   static const int MAX_TABLE_SIZE     = 1000000;
361   static bool _use_identity_hash_for_archived_object_cache;
362 
363   static unsigned archived_object_cache_hash(OopHandle const& oh);
364 
365   typedef ResizeableHashTable<OopHandle, CachedOopInfo,
366       AnyObj::C_HEAP,
367       mtClassShared,
368       HeapShared::archived_object_cache_hash,
369       HeapShared::oop_handle_equals> ArchivedObjectCache;
370   static ArchivedObjectCache* _archived_object_cache;
371 
372   class DumpTimeKlassSubGraphInfoTable
373     : public HashTable<Klass*, KlassSubGraphInfo,
374                                137, // prime number
375                                AnyObj::C_HEAP,
376                                mtClassShared,
377                                DumpTimeSharedClassTable_hash> {};
378 
379 public: // solaris compiler wants this for RunTimeKlassSubGraphInfoTable
380   inline static bool record_equals_compact_hashtable_entry(
381        const ArchivedKlassSubGraphInfoRecord* value, const Klass* key, int len_unused) {
382     return (value->klass() == key);
383   }
384 
385 private:
386   typedef OffsetCompactHashtable<
387     const Klass*,
388     const ArchivedKlassSubGraphInfoRecord*,

422   // !UseCompressedOops only: used to relocate pointers to the archived objects
423   static ptrdiff_t _runtime_delta;
424 
425   typedef ResizeableHashTable<oop, bool,
426       AnyObj::C_HEAP,
427       mtClassShared,
428       HeapShared::oop_hash> SeenObjectsTable;
429 
430   static SeenObjectsTable *_seen_objects_table;
431 
432   // The "special subgraph" contains all the archived objects that are reachable
433   // from the following roots:
434   //    - interned strings
435   //    - Klass::java_mirror() -- including aot-initialized mirrors such as those of Enum klasses.
436   //    - ConstantPool::resolved_references()
437   //    - Universe::<xxx>_exception_instance()
438   static KlassSubGraphInfo* _dump_time_special_subgraph;              // for collecting info during dump time
439   static ArchivedKlassSubGraphInfoRecord* _run_time_special_subgraph; // for initializing classes during run time.
440 
441   static GrowableArrayCHeap<oop, mtClassShared>* _pending_roots;
442   static GrowableArrayCHeap<const char*, mtClassShared>* _context; // for debugging unarchivable objects
443   static OopHandle _scratch_basic_type_mirrors[T_VOID+1];
444   static MetaspaceObjToOopHandleTable* _scratch_objects_table;
445 
446   static void init_seen_objects_table() {
447     assert(_seen_objects_table == nullptr, "must be");
448     _seen_objects_table = new (mtClass)SeenObjectsTable(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
449   }
450   static void delete_seen_objects_table() {
451     assert(_seen_objects_table != nullptr, "must be");
452     delete _seen_objects_table;
453     _seen_objects_table = nullptr;
454   }
455 
456   class ContextMark;
457 
458   // Statistics (for one round of start_recording_subgraph ... done_recording_subgraph)
459   static size_t _num_new_walked_objs;
460   static size_t _num_new_archived_objs;
461   static size_t _num_old_recorded_klasses;
462 
463   // Statistics (for all archived subgraphs)
464   static size_t _num_total_subgraph_recordings;
465   static size_t _num_total_walked_objs;
466   static size_t _num_total_archived_objs;
467   static size_t _num_total_recorded_klasses;
468   static size_t _num_total_verifications;
469 
470   static void start_recording_subgraph(InstanceKlass *k, const char* klass_name,
471                                        bool is_full_module_graph);
472   static void done_recording_subgraph(InstanceKlass *k, const char* klass_name);
473 
474   static bool has_been_seen_during_subgraph_recording(oop obj);
475   static void set_has_been_seen_during_subgraph_recording(oop obj);
476   static bool archive_object(oop obj, oop referrer, KlassSubGraphInfo* subgraph_info);
477 

497     oop _referrer;
498     int _level;
499 
500   public:
501     PendingOop() : _obj(nullptr), _referrer(nullptr), _level(-1) {}
502     PendingOop(oop obj, oop referrer, int level) : _obj(obj), _referrer(referrer), _level(level) {}
503 
504     oop obj()      const { return _obj; }
505     oop referrer() const { return _referrer; }
506     int level()    const { return _level; }
507   };
508 
509   class OopFieldPusher;
510   using PendingOopStack = GrowableArrayCHeap<PendingOop, mtClassShared>;
511 
512   static PendingOop _object_being_archived;
513   static bool walk_one_object(PendingOopStack* stack, int level, KlassSubGraphInfo* subgraph_info,
514                               oop orig_obj, oop referrer);
515 
516  public:
517   static void exit_on_error();
518   static void reset_archived_object_states(TRAPS);
519   static void create_archived_object_cache() {
520     _archived_object_cache =
521       new (mtClass)ArchivedObjectCache(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
522   }
523   static void destroy_archived_object_cache() {
524     delete _archived_object_cache;
525     _archived_object_cache = nullptr;
526   }
527   static void make_archived_object_cache_gc_safe();
528   static ArchivedObjectCache* archived_object_cache() {
529     return _archived_object_cache;
530   }
531 
532   static CachedOopInfo* get_cached_oop_info(oop orig_obj);
533 
534   static int archive_exception_instance(oop exception);
535 
536   static bool archive_reachable_objects_from(int level,
537                                              KlassSubGraphInfo* subgraph_info,
538                                              oop orig_obj);
539 
540   static bool is_interned_string(oop obj);
541   static bool is_dumped_interned_string(oop o);
542 
543   static void track_scratch_object(oop orig_obj, oop scratch_obj);
544 
545   // Scratch objects for archiving Klass::java_mirror()
546   static void set_scratch_java_mirror(Klass* k, oop mirror);
547   static void remove_scratch_objects(Klass* k);
548   static bool is_metadata_field(oop src_obj, int offset);
549   template <typename T> static void do_metadata_offsets(oop src_obj, T callback);
550   static void remap_dumped_metadata(oop src_obj, address archived_object);
551   inline static void remap_loaded_metadata(oop obj);
552   inline static oop maybe_remap_referent(bool is_java_lang_ref, size_t field_offset, oop referent);
553   static void get_pointer_info(oop src_obj, bool& has_oop_pointers, bool& has_native_pointers);
554   static void set_has_native_pointers(oop src_obj);
555   static uintptr_t archive_location(oop src_obj);
556 
557   // We use the HeapShared::roots() array to make sure that objects stored in the
558   // archived heap region are not prematurely collected. These roots include:
559   //
560   //    - mirrors of classes that have not yet been loaded.
561   //    - ConstantPool::resolved_references() of classes that have not yet been loaded.
562   //    - ArchivedKlassSubGraphInfoRecords that have not been initialized
563   //    - java.lang.Module objects that have not yet been added to the module graph
564   //
565   // When a mirror M becomes referenced by a newly loaded class K, M will be removed
566   // from HeapShared::roots() via clear_root(), and K will be responsible for
567   // keeping M alive.
568   //
569   // Other types of roots are also cleared similarly when they become referenced.
570 
571   // Dump-time only. Returns the index of the root, which can be used at run time to read
572   // the root using get_root(index, ...).
573   static int append_root(oop obj);
574 
575   // AOT-compile time only.
576   // Returns -1 if obj is not in the heap root set.
577   static int get_root_index(oop obj) NOT_CDS_JAVA_HEAP_RETURN_(-1);
578 
579   static GrowableArrayCHeap<oop, mtClassShared>* pending_roots() { return _pending_roots; }
580 
581   // Dump-time and runtime
582   static objArrayOop root_segment(int segment_idx);
583   static oop get_root(int index, bool clear=false);
584 
585   // Run-time only
586   static void clear_root(int index);

587   static void get_segment_indexes(int index, int& segment_index, int& internal_index);

588   static void setup_test_class(const char* test_class_name) PRODUCT_RETURN;
589 #endif // INCLUDE_CDS_JAVA_HEAP
590 
591  public:
592   static void finish_materialize_objects() NOT_CDS_JAVA_HEAP_RETURN;
593 
594   static void write_heap(ArchiveMappedHeapInfo* mapped_heap_info, ArchiveStreamedHeapInfo* streamed_heap_info) NOT_CDS_JAVA_HEAP_RETURN;
595   static objArrayOop scratch_resolved_references(ConstantPool* src);
596   static void add_scratch_resolved_references(ConstantPool* src, objArrayOop dest) NOT_CDS_JAVA_HEAP_RETURN;
597   static void init_dumping() NOT_CDS_JAVA_HEAP_RETURN;
598   static void init_scratch_objects_for_basic_type_mirrors(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
599   static void init_box_classes(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
600   static bool is_heap_region(int idx) {
601     CDS_JAVA_HEAP_ONLY(return (idx == AOTMetaspace::hp);)
602     NOT_CDS_JAVA_HEAP_RETURN_(false);
603   }
604   static void delete_tables_with_raw_oops() NOT_CDS_JAVA_HEAP_RETURN;
605 
606   static void resolve_classes(JavaThread* current) NOT_CDS_JAVA_HEAP_RETURN;
607   static void initialize_from_archived_subgraph(JavaThread* current, Klass* k) NOT_CDS_JAVA_HEAP_RETURN;
608 
609   static void init_for_dumping(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
610   static void init_heap_writer() NOT_CDS_JAVA_HEAP_RETURN;
611   static void write_subgraph_info_table() NOT_CDS_JAVA_HEAP_RETURN;
612   static void serialize_tables(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN;
613 
614 #ifndef PRODUCT
615   static bool is_a_test_class_in_unnamed_module(Klass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
616   static void initialize_test_class_from_archive(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
617 #endif
618 
619   static void initialize_java_lang_invoke(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
620   static void init_classes_for_special_subgraph(Handle loader, TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
621 
622   static bool is_core_java_lang_invoke_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
623   static bool is_lambda_form_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
624   static bool is_lambda_proxy_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
625   static bool is_string_concat_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
626   static bool is_archivable_hidden_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
627 
628   // Used by AOTArtifactFinder
629   static void start_scanning_for_oops();
630   static void end_scanning_for_oops();
631   static void scan_java_class(Klass* k);
632   static void scan_java_mirror(oop orig_mirror);
633   static void copy_and_rescan_aot_inited_mirror(InstanceKlass* ik);
634 
635   static void log_heap_roots();
636 
637   static intptr_t log_target_location(oop source_oop);
638   static void log_oop_info(outputStream* st, oop source_oop, address archived_object_start, address archived_object_end);
639   static void log_oop_info(outputStream* st, oop source_oop);
640   static void log_oop_details(oop source_oop, address buffered_addr);
641 };
642 
< prev index next >