< 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;

217   public:
218     int _count;
219   };
220 
221 public: // solaris compiler wants this for RunTimeKlassSubGraphInfoTable
222   inline static bool record_equals_compact_hashtable_entry(
223        const ArchivedKlassSubGraphInfoRecord* value, const Klass* key, int len_unused) {
224     return (value->klass() == key);
225   }
226 
227 private:
228   typedef OffsetCompactHashtable<
229     const Klass*,
230     const ArchivedKlassSubGraphInfoRecord*,
231     record_equals_compact_hashtable_entry
232     > RunTimeKlassSubGraphInfoTable;
233 
234   static DumpTimeKlassSubGraphInfoTable* _dump_time_subgraph_info_table;
235   static RunTimeKlassSubGraphInfoTable _run_time_subgraph_info_table;
236 
237   static CachedOopInfo make_cached_oop_info(oop obj);
238   static ArchivedKlassSubGraphInfoRecord* archive_subgraph_info(KlassSubGraphInfo* info);
239   static void archive_object_subgraphs(ArchivableStaticFieldInfo fields[],
240                                        bool is_full_module_graph);
241 
242   // Archive object sub-graph starting from the given static field
243   // in Klass k's mirror.
244   static void archive_reachable_objects_from_static_field(
245     InstanceKlass* k, const char* klass_name,
246     int field_offset, const char* field_name);
247 
248   static void verify_subgraph_from_static_field(
249     InstanceKlass* k, int field_offset) PRODUCT_RETURN;
250   static void verify_reachable_objects_from(oop obj) PRODUCT_RETURN;
251   static void verify_subgraph_from(oop orig_obj) PRODUCT_RETURN;
252   static void check_special_subgraph_classes();
253 
254   static KlassSubGraphInfo* init_subgraph_info(Klass *k, bool is_full_module_graph);
255   static KlassSubGraphInfo* get_subgraph_info(Klass *k);
256 
257   static void init_subgraph_entry_fields(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
258   static void init_subgraph_entry_fields(ArchivableStaticFieldInfo fields[], TRAPS);
259 
260   // UseCompressedOops only: Used by decode_from_archive
261   static address _narrow_oop_base;
262   static int     _narrow_oop_shift;
263 
264   // !UseCompressedOops only: used to relocate pointers to the archived objects
265   static ptrdiff_t _runtime_delta;
266 
267   typedef ResizeableResourceHashtable<oop, bool,
268       AnyObj::C_HEAP,
269       mtClassShared,
270       HeapShared::oop_hash> SeenObjectsTable;
271 
272   static SeenObjectsTable *_seen_objects_table;
273 
274   // The "special subgraph" contains all the archived objects that are reachable
275   // from the following roots:
276   //    - interned strings
277   //    - Klass::java_mirror() -- including aot-initialized mirrors such as those of Enum klasses.
278   //    - ConstantPool::resolved_references()
279   //    - Universe::<xxx>_exception_instance()
280   static KlassSubGraphInfo* _dump_time_special_subgraph;              // for collecting info during dump time
281   static ArchivedKlassSubGraphInfoRecord* _run_time_special_subgraph; // for initializing classes during run time.
282 
283   static GrowableArrayCHeap<oop, mtClassShared>* _pending_roots;
284   static GrowableArrayCHeap<OopHandle, mtClassShared>* _root_segments;

285   static int _root_segment_max_size_elems;
286   static OopHandle _scratch_basic_type_mirrors[T_VOID+1];
287   static MetaspaceObjToOopHandleTable* _scratch_java_mirror_table;
288   static MetaspaceObjToOopHandleTable* _scratch_references_table;
289 
290   static void init_seen_objects_table() {
291     assert(_seen_objects_table == nullptr, "must be");
292     _seen_objects_table = new (mtClass)SeenObjectsTable(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
293   }
294   static void delete_seen_objects_table() {
295     assert(_seen_objects_table != nullptr, "must be");
296     delete _seen_objects_table;
297     _seen_objects_table = nullptr;
298   }
299 


300   // Statistics (for one round of start_recording_subgraph ... done_recording_subgraph)
301   static int _num_new_walked_objs;
302   static int _num_new_archived_objs;
303   static int _num_old_recorded_klasses;
304 
305   // Statistics (for all archived subgraphs)
306   static int _num_total_subgraph_recordings;
307   static int _num_total_walked_objs;
308   static int _num_total_archived_objs;
309   static int _num_total_recorded_klasses;
310   static int _num_total_verifications;
311 
312   static void start_recording_subgraph(InstanceKlass *k, const char* klass_name,
313                                        bool is_full_module_graph);
314   static void done_recording_subgraph(InstanceKlass *k, const char* klass_name);
315 
316   static bool has_been_seen_during_subgraph_recording(oop obj);
317   static void set_has_been_seen_during_subgraph_recording(oop obj);
318   static bool archive_object(oop obj, KlassSubGraphInfo* subgraph_info);
319 
320   static void resolve_classes_for_subgraphs(JavaThread* current, ArchivableStaticFieldInfo fields[]);
321   static void resolve_classes_for_subgraph_of(JavaThread* current, Klass* k);
322   static void clear_archived_roots_of(Klass* k);
323   static const ArchivedKlassSubGraphInfoRecord*
324                resolve_or_init_classes_for_subgraph_of(Klass* k, bool do_init, TRAPS);
325   static void resolve_or_init(const char* klass_name, bool do_init, TRAPS);
326   static void resolve_or_init(Klass* k, bool do_init, TRAPS);
327   static void init_archived_fields_for(Klass* k, const ArchivedKlassSubGraphInfoRecord* record);
328 
329   static int init_loaded_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
330                                  MemRegion& archive_space);
331   static void sort_loaded_regions(LoadedArchiveHeapRegion* loaded_regions, int num_loaded_regions,
332                                   uintptr_t buffer);
333   static bool load_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
334                            int num_loaded_regions, uintptr_t buffer);
335   static void init_loaded_heap_relocation(LoadedArchiveHeapRegion* reloc_info,
336                                           int num_loaded_regions);
337   static void fill_failed_loaded_region();
338   static void mark_native_pointers(oop orig_obj);
339   static bool has_been_archived(oop orig_obj);
340   static void prepare_resolved_references();
341   static void archive_strings();
342   static void archive_subgraphs();























343 
344  public:

345   static void reset_archived_object_states(TRAPS);
346   static void create_archived_object_cache() {
347     _archived_object_cache =
348       new (mtClass)ArchivedObjectCache(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
349   }
350   static void destroy_archived_object_cache() {
351     delete _archived_object_cache;
352     _archived_object_cache = nullptr;
353   }
354   static ArchivedObjectCache* archived_object_cache() {
355     return _archived_object_cache;
356   }
357 
358   static int archive_exception_instance(oop exception);
359 
360   static bool archive_reachable_objects_from(int level,
361                                              KlassSubGraphInfo* subgraph_info,
362                                              oop orig_obj);
363 
364   static void add_to_dumped_interned_strings(oop string);
365   static bool is_dumped_interned_string(oop o);
366 


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

405   static void write_heap(ArchiveHeapInfo* heap_info) NOT_CDS_JAVA_HEAP_RETURN;
406   static objArrayOop scratch_resolved_references(ConstantPool* src);
407   static void add_scratch_resolved_references(ConstantPool* src, objArrayOop dest) NOT_CDS_JAVA_HEAP_RETURN;
408   static void init_dumping() NOT_CDS_JAVA_HEAP_RETURN;
409   static void init_scratch_objects(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
410   static void init_box_classes(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
411   static bool is_heap_region(int idx) {
412     CDS_JAVA_HEAP_ONLY(return (idx == MetaspaceShared::hp);)
413     NOT_CDS_JAVA_HEAP_RETURN_(false);
414   }
415 
416   static void resolve_classes(JavaThread* current) NOT_CDS_JAVA_HEAP_RETURN;
417   static void initialize_from_archived_subgraph(JavaThread* current, Klass* k) NOT_CDS_JAVA_HEAP_RETURN;
418 
419   static void init_for_dumping(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
420   static void write_subgraph_info_table() NOT_CDS_JAVA_HEAP_RETURN;
421   static void add_root_segment(objArrayOop segment_oop) NOT_CDS_JAVA_HEAP_RETURN;
422   static void init_root_segment_sizes(int max_size_elems) NOT_CDS_JAVA_HEAP_RETURN;
423   static void serialize_tables(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN;
424 
425 #ifndef PRODUCT
426   static bool is_a_test_class_in_unnamed_module(Klass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
427   static void initialize_test_class_from_archive(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
428 #endif
429 









430   static void initialize_java_lang_invoke(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
431   static void init_classes_for_special_subgraph(Handle loader, TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
432 
433   static bool is_lambda_form_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
434   static bool is_lambda_proxy_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
435   static bool is_string_concat_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
436   static bool is_archivable_hidden_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
437 
438   // Used by AOTArtifactFinder
439   static void start_scanning_for_oops();
440   static void end_scanning_for_oops();
441   static void scan_java_class(Klass* k);
442   static void scan_java_mirror(oop orig_mirror);
443   static void copy_and_rescan_aot_inited_mirror(InstanceKlass* ik);
444 };
445 








446 #if INCLUDE_CDS_JAVA_HEAP
447 class DumpedInternedStrings :
448   public ResizeableResourceHashtable<oop, bool,
449                            AnyObj::C_HEAP,
450                            mtClassShared,
451                            HeapShared::string_oop_hash>
452 {
453 public:
454   DumpedInternedStrings(unsigned size, unsigned max_size) :
455     ResizeableResourceHashtable<oop, bool,
456                                 AnyObj::C_HEAP,
457                                 mtClassShared,
458                                 HeapShared::string_oop_hash>(size, max_size) {}
459 };
460 #endif
461 
462 #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;

218   public:
219     int _count;
220   };
221 
222 public: // solaris compiler wants this for RunTimeKlassSubGraphInfoTable
223   inline static bool record_equals_compact_hashtable_entry(
224        const ArchivedKlassSubGraphInfoRecord* value, const Klass* key, int len_unused) {
225     return (value->klass() == key);
226   }
227 
228 private:
229   typedef OffsetCompactHashtable<
230     const Klass*,
231     const ArchivedKlassSubGraphInfoRecord*,
232     record_equals_compact_hashtable_entry
233     > RunTimeKlassSubGraphInfoTable;
234 
235   static DumpTimeKlassSubGraphInfoTable* _dump_time_subgraph_info_table;
236   static RunTimeKlassSubGraphInfoTable _run_time_subgraph_info_table;
237 
238   static CachedOopInfo make_cached_oop_info(oop obj, oop referrer);
239   static ArchivedKlassSubGraphInfoRecord* archive_subgraph_info(KlassSubGraphInfo* info);
240   static void archive_object_subgraphs(ArchivableStaticFieldInfo fields[],
241                                        bool is_full_module_graph);
242 
243   // Archive object sub-graph starting from the given static field
244   // in Klass k's mirror.
245   static void archive_reachable_objects_from_static_field(
246     InstanceKlass* k, const char* klass_name,
247     int field_offset, const char* field_name);
248 
249   static void verify_subgraph_from_static_field(
250     InstanceKlass* k, int field_offset) PRODUCT_RETURN;
251   static void verify_reachable_objects_from(oop obj) PRODUCT_RETURN;
252   static void verify_subgraph_from(oop orig_obj) PRODUCT_RETURN;
253   static void check_special_subgraph_classes();
254 
255   static KlassSubGraphInfo* init_subgraph_info(Klass *k, bool is_full_module_graph);
256   static KlassSubGraphInfo* get_subgraph_info(Klass *k);
257 
258   static void init_subgraph_entry_fields(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
259   static void init_subgraph_entry_fields(ArchivableStaticFieldInfo fields[], TRAPS);
260 
261   // UseCompressedOops only: Used by decode_from_archive
262   static address _narrow_oop_base;
263   static int     _narrow_oop_shift;
264 
265   // !UseCompressedOops only: used to relocate pointers to the archived objects
266   static ptrdiff_t _runtime_delta;
267 
268   typedef ResizeableResourceHashtable<oop, bool,
269       AnyObj::C_HEAP,
270       mtClassShared,
271       HeapShared::oop_hash> SeenObjectsTable;
272 
273   static SeenObjectsTable *_seen_objects_table;

274   // The "special subgraph" contains all the archived objects that are reachable
275   // from the following roots:
276   //    - interned strings
277   //    - Klass::java_mirror() -- including aot-initialized mirrors such as those of Enum klasses.
278   //    - ConstantPool::resolved_references()
279   //    - Universe::<xxx>_exception_instance()
280   static KlassSubGraphInfo* _dump_time_special_subgraph;              // for collecting info during dump time
281   static ArchivedKlassSubGraphInfoRecord* _run_time_special_subgraph; // for initializing classes during run time.
282 
283   static GrowableArrayCHeap<OopHandle, mtClassShared>* _pending_roots;
284   static GrowableArrayCHeap<OopHandle, mtClassShared>* _root_segments;
285   static GrowableArrayCHeap<const char*, mtClassShared>* _context; // for debugging unarchivable objects
286   static int _root_segment_max_size_elems;
287   static OopHandle _scratch_basic_type_mirrors[T_VOID+1];
288   static MetaspaceObjToOopHandleTable* _scratch_java_mirror_table;
289   static MetaspaceObjToOopHandleTable* _scratch_references_table;
290 
291   static void init_seen_objects_table() {
292     assert(_seen_objects_table == nullptr, "must be");
293     _seen_objects_table = new (mtClass)SeenObjectsTable(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
294   }
295   static void delete_seen_objects_table() {
296     assert(_seen_objects_table != nullptr, "must be");
297     delete _seen_objects_table;
298     _seen_objects_table = nullptr;
299   }
300 
301   class ContextMark;
302 
303   // Statistics (for one round of start_recording_subgraph ... done_recording_subgraph)
304   static int _num_new_walked_objs;
305   static int _num_new_archived_objs;
306   static int _num_old_recorded_klasses;
307 
308   // Statistics (for all archived subgraphs)
309   static int _num_total_subgraph_recordings;
310   static int _num_total_walked_objs;
311   static int _num_total_archived_objs;
312   static int _num_total_recorded_klasses;
313   static int _num_total_verifications;
314 
315   static void start_recording_subgraph(InstanceKlass *k, const char* klass_name,
316                                        bool is_full_module_graph);
317   static void done_recording_subgraph(InstanceKlass *k, const char* klass_name);
318 
319   static bool has_been_seen_during_subgraph_recording(oop obj);
320   static void set_has_been_seen_during_subgraph_recording(oop obj);
321   static bool archive_object(oop obj, oop referrer, KlassSubGraphInfo* subgraph_info);
322 
323   static void resolve_classes_for_subgraphs(JavaThread* current, ArchivableStaticFieldInfo fields[]);
324   static void resolve_classes_for_subgraph_of(JavaThread* current, Klass* k);
325   static void clear_archived_roots_of(Klass* k);
326   static const ArchivedKlassSubGraphInfoRecord*
327                resolve_or_init_classes_for_subgraph_of(Klass* k, bool do_init, TRAPS);
328   static void resolve_or_init(const char* klass_name, bool do_init, TRAPS);
329   static void resolve_or_init(Klass* k, bool do_init, TRAPS);
330   static void init_archived_fields_for(Klass* k, const ArchivedKlassSubGraphInfoRecord* record);
331 
332   static int init_loaded_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
333                                  MemRegion& archive_space);
334   static void sort_loaded_regions(LoadedArchiveHeapRegion* loaded_regions, int num_loaded_regions,
335                                   uintptr_t buffer);
336   static bool load_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
337                            int num_loaded_regions, uintptr_t buffer);
338   static void init_loaded_heap_relocation(LoadedArchiveHeapRegion* reloc_info,
339                                           int num_loaded_regions);
340   static void fill_failed_loaded_region();
341   static void mark_native_pointers(oop orig_obj);
342   static bool has_been_archived(oop orig_obj);
343   static void prepare_resolved_references();
344   static void archive_strings();
345   static void archive_subgraphs();
346   // PendingOop and PendingOopStack are used for recursively discovering all cacheable
347   // heap objects. The recursion is done using PendingOopStack so we won't overflow the
348   // C stack with deep reference chains.
349   class PendingOop {
350     oop _obj;
351     oop _referrer;
352     int _level;
353 
354   public:
355     PendingOop() : _obj(nullptr), _referrer(nullptr), _level(-1) {}
356     PendingOop(oop obj, oop referrer, int level) : _obj(obj), _referrer(referrer), _level(level) {}
357 
358     oop obj()      const { return _obj; }
359     oop referrer() const { return _referrer; }
360     int level()    const { return _level; }
361   };
362 
363   class ReferentPusher;
364   using PendingOopStack = GrowableArrayCHeap<PendingOop, mtClassShared>;
365 
366   static PendingOop _object_being_archived;
367   static bool walk_one_object(PendingOopStack* stack, int level, KlassSubGraphInfo* subgraph_info,
368                               oop orig_obj, oop referrer);
369 
370  public:
371   static void exit_on_error();
372   static void reset_archived_object_states(TRAPS);
373   static void create_archived_object_cache() {
374     _archived_object_cache =
375       new (mtClass)ArchivedObjectCache(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
376   }
377   static void destroy_archived_object_cache() {
378     delete _archived_object_cache;
379     _archived_object_cache = nullptr;
380   }
381   static ArchivedObjectCache* archived_object_cache() {
382     return _archived_object_cache;
383   }
384 
385   static int archive_exception_instance(oop exception);
386 
387   static bool archive_reachable_objects_from(int level,
388                                              KlassSubGraphInfo* subgraph_info,
389                                              oop orig_obj);
390 
391   static void add_to_dumped_interned_strings(oop string);
392   static bool is_dumped_interned_string(oop o);
393 
394   static void track_scratch_object(oop orig_obj, oop scratch_obj);
395 
396   // Scratch objects for archiving Klass::java_mirror()
397   static void set_scratch_java_mirror(Klass* k, oop mirror);
398   static void remove_scratch_objects(Klass* k);
399   static void get_pointer_info(oop src_obj, bool& has_oop_pointers, bool& has_native_pointers);
400   static void set_has_native_pointers(oop src_obj);
401 
402   // We use the HeapShared::roots() array to make sure that objects stored in the
403   // archived heap region are not prematurely collected. These roots include:
404   //
405   //    - mirrors of classes that have not yet been loaded.
406   //    - ConstantPool::resolved_references() of classes that have not yet been loaded.
407   //    - ArchivedKlassSubGraphInfoRecords that have not been initialized
408   //    - java.lang.Module objects that have not yet been added to the module graph
409   //
410   // When a mirror M becomes referenced by a newly loaded class K, M will be removed
411   // from HeapShared::roots() via clear_root(), and K will be responsible for
412   // keeping M alive.
413   //
414   // Other types of roots are also cleared similarly when they become referenced.
415 
416   // Dump-time only. Returns the index of the root, which can be used at run time to read
417   // the root using get_root(index, ...).
418   static int append_root(oop obj);
419   static GrowableArrayCHeap<OopHandle, mtClassShared>* pending_roots() { return _pending_roots; }
420 
421   // Dump-time and runtime
422   static objArrayOop root_segment(int segment_idx);
423   static oop get_root(int index, bool clear=false);
424 
425   // Run-time only
426   static void clear_root(int index);

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

428   static void setup_test_class(const char* test_class_name) PRODUCT_RETURN;
429 #endif // INCLUDE_CDS_JAVA_HEAP
430 
431  public:
432   static oop orig_to_scratch_object(oop orig_obj);
433   static void write_heap(ArchiveHeapInfo* heap_info) NOT_CDS_JAVA_HEAP_RETURN;
434   static objArrayOop scratch_resolved_references(ConstantPool* src);
435   static void add_scratch_resolved_references(ConstantPool* src, objArrayOop dest) NOT_CDS_JAVA_HEAP_RETURN;
436   static void init_dumping() NOT_CDS_JAVA_HEAP_RETURN;
437   static void init_scratch_objects(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
438   static void init_box_classes(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
439   static bool is_heap_region(int idx) {
440     CDS_JAVA_HEAP_ONLY(return (idx == MetaspaceShared::hp);)
441     NOT_CDS_JAVA_HEAP_RETURN_(false);
442   }
443 
444   static void resolve_classes(JavaThread* current) NOT_CDS_JAVA_HEAP_RETURN;
445   static void initialize_from_archived_subgraph(JavaThread* current, Klass* k) NOT_CDS_JAVA_HEAP_RETURN;
446 
447   static void init_for_dumping(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
448   static void write_subgraph_info_table() NOT_CDS_JAVA_HEAP_RETURN;
449   static void add_root_segment(objArrayOop segment_oop) NOT_CDS_JAVA_HEAP_RETURN;
450   static void init_root_segment_sizes(int max_size_elems) NOT_CDS_JAVA_HEAP_RETURN;
451   static void serialize_tables(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN;
452 
453 #ifndef PRODUCT
454   static bool is_a_test_class_in_unnamed_module(Klass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
455   static void initialize_test_class_from_archive(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
456 #endif
457 
458   static void add_to_permanent_oop_table(oop obj, int offset);
459 
460   // AOT-compile time only: get a stable index for an archived object.
461   // Returns 0 if obj is not archived.
462   static int get_archived_object_permanent_index(oop obj) NOT_CDS_JAVA_HEAP_RETURN_(-1);
463   // Runtime only: get back the same object for an index returned by
464   // get_archived_object_permanent_index().
465   static oop get_archived_object(int permanent_index) NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
466 
467   static void initialize_java_lang_invoke(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
468   static void init_classes_for_special_subgraph(Handle loader, TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
469 
470   static bool is_lambda_form_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
471   static bool is_lambda_proxy_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
472   static bool is_string_concat_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
473   static bool is_archivable_hidden_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
474 
475   // Used by AOTArtifactFinder
476   static void start_scanning_for_oops();
477   static void end_scanning_for_oops();
478   static void scan_java_class(Klass* k);
479   static void scan_java_mirror(oop orig_mirror);
480   static void copy_and_rescan_aot_inited_mirror(InstanceKlass* ik);
481 };
482 
483 class CachedCodeDirectoryInternal {
484   int _permanent_oop_count;
485   int* _permanent_oop_offsets; // offset of each permanent object from the bottom of the archived heap
486 public:
487   void dumptime_init_internal() NOT_CDS_JAVA_HEAP_RETURN;
488   void runtime_init_internal() NOT_CDS_JAVA_HEAP_RETURN;
489 };
490 
491 #if INCLUDE_CDS_JAVA_HEAP
492 class DumpedInternedStrings :
493   public ResizeableResourceHashtable<oop, bool,
494                            AnyObj::C_HEAP,
495                            mtClassShared,
496                            HeapShared::string_oop_hash>
497 {
498 public:
499   DumpedInternedStrings(unsigned size, unsigned max_size) :
500     ResizeableResourceHashtable<oop, bool,
501                                 AnyObj::C_HEAP,
502                                 mtClassShared,
503                                 HeapShared::string_oop_hash>(size, max_size) {}
504 };
505 #endif
506 
507 #endif // SHARE_CDS_HEAPSHARED_HPP
< prev index next >