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

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     // See "TEMP notes: What are these?" in archiveHeapWriter.hpp
190     oop _orig_referrer;
191 
192     // The location of this object inside ArchiveHeapWriter::_buffer
193     size_t _buffer_offset;
194   public:
195     CachedOopInfo(oop orig_referrer)
196       : _orig_referrer(orig_referrer),
197         _buffer_offset(0) {}
198     oop orig_referrer()             const { return _orig_referrer;   }
199     void set_buffer_offset(size_t offset) { _buffer_offset = offset; }
200     size_t buffer_offset()          const { return _buffer_offset;   }
201   };
202 
203 private:
204   static void check_enum_obj(int level, KlassSubGraphInfo* subgraph_info,
205                              oop orig_obj);
206 
207   typedef ResourceHashtable<oop, CachedOopInfo,
208       36137, // prime number
209       AnyObj::C_HEAP,
210       mtClassShared,
211       HeapShared::oop_hash> ArchivedObjectCache;
212   static ArchivedObjectCache* _archived_object_cache;
213 
214   class DumpTimeKlassSubGraphInfoTable
215     : public ResourceHashtable<Klass*, KlassSubGraphInfo,
216                                137, // prime number
217                                AnyObj::C_HEAP,
218                                mtClassShared,
219                                DumpTimeSharedClassTable_hash> {
220   public:
221     int _count;
222   };
223 
224 public: // solaris compiler wants this for RunTimeKlassSubGraphInfoTable
225   inline static bool record_equals_compact_hashtable_entry(
226        const ArchivedKlassSubGraphInfoRecord* value, const Klass* key, int len_unused) {
227     return (value->klass() == key);
228   }
229 
230 private:
231   typedef OffsetCompactHashtable<
232     const Klass*,
233     const ArchivedKlassSubGraphInfoRecord*,
234     record_equals_compact_hashtable_entry
235     > RunTimeKlassSubGraphInfoTable;
236 
237   static DumpTimeKlassSubGraphInfoTable* _dump_time_subgraph_info_table;
238   static RunTimeKlassSubGraphInfoTable _run_time_subgraph_info_table;
239 
240   static CachedOopInfo make_cached_oop_info();

241   static void archive_object_subgraphs(ArchivableStaticFieldInfo fields[],
242                                        bool is_full_module_graph);
243 
244   // Archive object sub-graph starting from the given static field
245   // in Klass k's mirror.
246   static void archive_reachable_objects_from_static_field(
247     InstanceKlass* k, const char* klass_name,
248     int field_offset, const char* field_name);
249 
250   static void verify_subgraph_from_static_field(
251     InstanceKlass* k, int field_offset) PRODUCT_RETURN;
252   static void verify_reachable_objects_from(oop obj) PRODUCT_RETURN;
253   static void verify_subgraph_from(oop orig_obj) PRODUCT_RETURN;
254   static void check_default_subgraph_classes();
255 
256   static KlassSubGraphInfo* init_subgraph_info(Klass *k, bool is_full_module_graph);
257   static KlassSubGraphInfo* get_subgraph_info(Klass *k);
258 
259   static void init_subgraph_entry_fields(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
260   static void init_subgraph_entry_fields(ArchivableStaticFieldInfo fields[], TRAPS);

263   static address _narrow_oop_base;
264   static int     _narrow_oop_shift;
265 
266   // !UseCompressedOops only: used to relocate pointers to the archived objects
267   static ptrdiff_t _runtime_delta;
268 
269   typedef ResourceHashtable<oop, bool,
270       15889, // prime number
271       AnyObj::C_HEAP,
272       mtClassShared,
273       HeapShared::oop_hash> SeenObjectsTable;
274 
275   static SeenObjectsTable *_seen_objects_table;
276 
277   // The "default subgraph" is the root of all archived objects that do not belong to any
278   // of the classes defined in the <xxx>_archive_subgraph_entry_fields[] arrays:
279   //    - interned strings
280   //    - Klass::java_mirror()
281   //    - ConstantPool::resolved_references()
282   static KlassSubGraphInfo* _default_subgraph_info;

283 
284   static GrowableArrayCHeap<oop, mtClassShared>* _pending_roots;


285   static OopHandle _roots;

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();
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);
319 
320   static void copy_interned_strings();
321 
322   static void resolve_classes_for_subgraphs(JavaThread* current, ArchivableStaticFieldInfo fields[]);
323   static void resolve_classes_for_subgraph_of(JavaThread* current, Klass* k);
324   static void clear_archived_roots_of(Klass* k);
325   static const ArchivedKlassSubGraphInfoRecord*
326                resolve_or_init_classes_for_subgraph_of(Klass* k, bool do_init, TRAPS);

327   static void resolve_or_init(Klass* k, bool do_init, TRAPS);
328   static void init_archived_fields_for(Klass* k, const ArchivedKlassSubGraphInfoRecord* record);
329 
330   static int init_loaded_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
331                                  MemRegion& archive_space);
332   static void sort_loaded_regions(LoadedArchiveHeapRegion* loaded_regions, int num_loaded_regions,
333                                   uintptr_t buffer);
334   static bool load_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
335                            int num_loaded_regions, uintptr_t buffer);
336   static void init_loaded_heap_relocation(LoadedArchiveHeapRegion* reloc_info,
337                                           int num_loaded_regions);
338   static void fill_failed_loaded_region();
339   static void mark_native_pointers(oop orig_obj);
340   static bool has_been_archived(oop orig_obj);

341   static void archive_java_mirrors();
342   static void archive_strings();


343  public:
344   static void reset_archived_object_states(TRAPS);
345   static void create_archived_object_cache() {
346     _archived_object_cache =
347       new (mtClass)ArchivedObjectCache();
348   }
349   static void destroy_archived_object_cache() {
350     delete _archived_object_cache;
351     _archived_object_cache = nullptr;
352   }
353   static ArchivedObjectCache* archived_object_cache() {
354     return _archived_object_cache;
355   }
356 
357   static void archive_objects(ArchiveHeapInfo* heap_info);
358   static void copy_objects();
359   static void copy_special_objects();
360 
361   static bool archive_reachable_objects_from(int level,
362                                              KlassSubGraphInfo* subgraph_info,
363                                              oop orig_obj);
364 
365   static ResourceBitMap calculate_oopmap(MemRegion region); // marks all the oop pointers
366   static void add_to_dumped_interned_strings(oop string);
367 



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

402   static objArrayOop scratch_resolved_references(ConstantPool* src);
403   static void add_scratch_resolved_references(ConstantPool* src, objArrayOop dest) NOT_CDS_JAVA_HEAP_RETURN;
404   static void init_scratch_objects(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;


405   static bool is_heap_region(int idx) {
406     CDS_JAVA_HEAP_ONLY(return (idx == MetaspaceShared::hp);)
407     NOT_CDS_JAVA_HEAP_RETURN_(false);
408   }
409 
410   static void resolve_classes(JavaThread* current) NOT_CDS_JAVA_HEAP_RETURN;
411   static void initialize_from_archived_subgraph(JavaThread* current, Klass* k) NOT_CDS_JAVA_HEAP_RETURN;
412 
413   static void init_for_dumping(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
414   static void write_subgraph_info_table() NOT_CDS_JAVA_HEAP_RETURN;

415   static void init_roots(oop roots_oop) NOT_CDS_JAVA_HEAP_RETURN;
416   static void serialize_tables(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN;
417   static bool initialize_enum_klass(InstanceKlass* k, TRAPS) NOT_CDS_JAVA_HEAP_RETURN_(false);
418 
419   static bool is_a_test_class_in_unnamed_module(Klass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);















420 };
421 
422 #if INCLUDE_CDS_JAVA_HEAP
423 class DumpedInternedStrings :
424   public ResourceHashtable<oop, bool,
425                            15889, // prime number
426                            AnyObj::C_HEAP,
427                            mtClassShared,
428                            HeapShared::string_oop_hash>
429 {};
430 #endif
431 
432 #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;

145 
146 public:
147   // Can this VM write a heap region into the CDS archive? Currently only G1+compressed{oops,cp}
148   static bool can_write() {
149     CDS_JAVA_HEAP_ONLY(
150       if (_disable_writing) {
151         return false;
152       }
153       return (UseG1GC && 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 private:
171 #if INCLUDE_CDS_JAVA_HEAP
172   static bool _disable_writing;
173   static bool _box_classes_inited;
174   static DumpedInternedStrings *_dumped_interned_strings;
175 
176   // statistics
177   constexpr static int ALLOC_STAT_SLOTS = 16;
178   static size_t _alloc_count[ALLOC_STAT_SLOTS];
179   static size_t _alloc_size[ALLOC_STAT_SLOTS];
180   static size_t _total_obj_count;
181   static size_t _total_obj_size; // in HeapWords
182 
183   static void count_allocation(size_t size);
184   static void print_stats();
185 public:
186   static unsigned oop_hash(oop const& p);
187   static unsigned string_oop_hash(oop const& string) {
188     return java_lang_String::hash_code(string);
189   }
190 
191   class CopyKlassSubGraphInfoToArchive;
192 
193   class CachedOopInfo {
194     // See "TEMP notes: What are these?" in archiveHeapWriter.hpp
195     oop _orig_referrer;
196 
197     // The location of this object inside ArchiveHeapWriter::_buffer
198     size_t _buffer_offset;
199   public:
200     CachedOopInfo(oop orig_referrer)
201       : _orig_referrer(orig_referrer),
202         _buffer_offset(0) {}
203     oop orig_referrer()             const { return _orig_referrer;   }
204     void set_buffer_offset(size_t offset) { _buffer_offset = offset; }
205     size_t buffer_offset()          const { return _buffer_offset;   }
206   };
207 
208 private:



209   typedef ResourceHashtable<oop, CachedOopInfo,
210       36137, // prime number
211       AnyObj::C_HEAP,
212       mtClassShared,
213       HeapShared::oop_hash> ArchivedObjectCache;
214   static ArchivedObjectCache* _archived_object_cache;
215 
216   class DumpTimeKlassSubGraphInfoTable
217     : public ResourceHashtable<Klass*, KlassSubGraphInfo,
218                                137, // prime number
219                                AnyObj::C_HEAP,
220                                mtClassShared,
221                                DumpTimeSharedClassTable_hash> {
222   public:
223     int _count;
224   };
225 
226 public: // solaris compiler wants this for RunTimeKlassSubGraphInfoTable
227   inline static bool record_equals_compact_hashtable_entry(
228        const ArchivedKlassSubGraphInfoRecord* value, const Klass* key, int len_unused) {
229     return (value->klass() == key);
230   }
231 
232 private:
233   typedef OffsetCompactHashtable<
234     const Klass*,
235     const ArchivedKlassSubGraphInfoRecord*,
236     record_equals_compact_hashtable_entry
237     > RunTimeKlassSubGraphInfoTable;
238 
239   static DumpTimeKlassSubGraphInfoTable* _dump_time_subgraph_info_table;
240   static RunTimeKlassSubGraphInfoTable _run_time_subgraph_info_table;
241 
242   static CachedOopInfo make_cached_oop_info();
243   static ArchivedKlassSubGraphInfoRecord* archive_subgraph_info(KlassSubGraphInfo* info);
244   static void archive_object_subgraphs(ArchivableStaticFieldInfo fields[],
245                                        bool is_full_module_graph);
246 
247   // Archive object sub-graph starting from the given static field
248   // in Klass k's mirror.
249   static void archive_reachable_objects_from_static_field(
250     InstanceKlass* k, const char* klass_name,
251     int field_offset, const char* field_name);
252 
253   static void verify_subgraph_from_static_field(
254     InstanceKlass* k, int field_offset) PRODUCT_RETURN;
255   static void verify_reachable_objects_from(oop obj) PRODUCT_RETURN;
256   static void verify_subgraph_from(oop orig_obj) PRODUCT_RETURN;
257   static void check_default_subgraph_classes();
258 
259   static KlassSubGraphInfo* init_subgraph_info(Klass *k, bool is_full_module_graph);
260   static KlassSubGraphInfo* get_subgraph_info(Klass *k);
261 
262   static void init_subgraph_entry_fields(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
263   static void init_subgraph_entry_fields(ArchivableStaticFieldInfo fields[], TRAPS);

266   static address _narrow_oop_base;
267   static int     _narrow_oop_shift;
268 
269   // !UseCompressedOops only: used to relocate pointers to the archived objects
270   static ptrdiff_t _runtime_delta;
271 
272   typedef ResourceHashtable<oop, bool,
273       15889, // prime number
274       AnyObj::C_HEAP,
275       mtClassShared,
276       HeapShared::oop_hash> SeenObjectsTable;
277 
278   static SeenObjectsTable *_seen_objects_table;
279 
280   // The "default subgraph" is the root of all archived objects that do not belong to any
281   // of the classes defined in the <xxx>_archive_subgraph_entry_fields[] arrays:
282   //    - interned strings
283   //    - Klass::java_mirror()
284   //    - ConstantPool::resolved_references()
285   static KlassSubGraphInfo* _default_subgraph_info;
286   static ArchivedKlassSubGraphInfoRecord* _runtime_default_subgraph_info;
287 
288   static GrowableArrayCHeap<oop, mtClassShared>* _pending_roots;
289   static GrowableArrayCHeap<oop, mtClassShared>* _trace; // for debugging unarchivable objects
290   static GrowableArrayCHeap<const char*, mtClassShared>* _context; // for debugging unarchivable objects
291   static OopHandle _roots;
292   static int _permobj_segments;
293   static OopHandle _scratch_basic_type_mirrors[T_VOID+1];
294   static OopHandle _scratch_null_ptr_exception_instance;
295   static OopHandle _scratch_arithmetic_exception_instance;
296   static OopHandle _scratch_virtual_machine_error_instance;
297   static OopHandle _scratch_array_index_oob_exception_instance;
298   static OopHandle _scratch_array_store_exception_instance;
299   static OopHandle _scratch_class_cast_exception_instance;
300 
301   static MetaspaceObjToOopHandleTable* _scratch_java_mirror_table;
302   static MetaspaceObjToOopHandleTable* _scratch_references_table;
303 
304   static void init_seen_objects_table() {
305     assert(_seen_objects_table == nullptr, "must be");
306     _seen_objects_table = new (mtClass)SeenObjectsTable();
307   }
308   static void delete_seen_objects_table() {
309     assert(_seen_objects_table != nullptr, "must be");
310     delete _seen_objects_table;
311     _seen_objects_table = nullptr;
312   }
313 
314   class ArchivingObjectMark;
315   class ContextMark;
316 
317   // Statistics (for one round of start_recording_subgraph ... done_recording_subgraph)
318   static int _num_new_walked_objs;
319   static int _num_new_archived_objs;
320   static int _num_old_recorded_klasses;
321 
322   // Statistics (for all archived subgraphs)
323   static int _num_total_subgraph_recordings;
324   static int _num_total_walked_objs;
325   static int _num_total_archived_objs;
326   static int _num_total_recorded_klasses;
327   static int _num_total_verifications;
328 
329   static void start_recording_subgraph(InstanceKlass *k, const char* klass_name,
330                                        bool is_full_module_graph);
331   static void done_recording_subgraph(InstanceKlass *k, const char* klass_name);
332 
333   static bool has_been_seen_during_subgraph_recording(oop obj);
334   static void set_has_been_seen_during_subgraph_recording(oop obj);
335   static bool archive_object(oop obj);
336   static void copy_preinitialized_mirror(Klass* orig_k, oop orig_mirror, oop m);
337   static void copy_interned_strings();
338 
339   static void resolve_classes_for_subgraphs(JavaThread* current, ArchivableStaticFieldInfo fields[]);
340   static void resolve_classes_for_subgraph_of(JavaThread* current, Klass* k);
341   static void clear_archived_roots_of(Klass* k);
342   static const ArchivedKlassSubGraphInfoRecord*
343                resolve_or_init_classes_for_subgraph_of(Klass* k, bool do_init, TRAPS);
344   static void resolve_or_init(const char* klass_name, bool do_init, TRAPS);
345   static void resolve_or_init(Klass* k, bool do_init, TRAPS);
346   static void init_archived_fields_for(Klass* k, const ArchivedKlassSubGraphInfoRecord* record);
347 
348   static int init_loaded_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
349                                  MemRegion& archive_space);
350   static void sort_loaded_regions(LoadedArchiveHeapRegion* loaded_regions, int num_loaded_regions,
351                                   uintptr_t buffer);
352   static bool load_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
353                            int num_loaded_regions, uintptr_t buffer);
354   static void init_loaded_heap_relocation(LoadedArchiveHeapRegion* reloc_info,
355                                           int num_loaded_regions);
356   static void fill_failed_loaded_region();
357   static void mark_native_pointers(oop orig_obj);
358   static bool has_been_archived(oop orig_obj);
359   static bool can_mirror_be_used_in_subgraph(oop orig_java_mirror);
360   static void archive_java_mirrors();
361   static void archive_strings();
362   static void archive_exception_instances();
363   static void exit_on_error();
364  public:
365   static void reset_archived_object_states(TRAPS);
366   static void create_archived_object_cache() {
367     _archived_object_cache =
368       new (mtClass)ArchivedObjectCache();
369   }
370   static void destroy_archived_object_cache() {
371     delete _archived_object_cache;
372     _archived_object_cache = nullptr;
373   }
374   static ArchivedObjectCache* archived_object_cache() {
375     return _archived_object_cache;
376   }
377 
378   static void archive_objects(ArchiveHeapInfo* heap_info);
379   static void copy_objects();
380   static void copy_special_objects();
381 
382   static bool archive_reachable_objects_from(int level,
383                                              KlassSubGraphInfo* subgraph_info,
384                                              oop orig_obj);
385 
386   static ResourceBitMap calculate_oopmap(MemRegion region); // marks all the oop pointers
387   static void add_to_dumped_interned_strings(oop string);
388 
389   static OopHandle init_scratch_exception(oop orig_exception_obj, TRAPS);
390   static void track_scratch_object(oop orig_obj, oop scratch_obj);
391 
392   // Scratch objects for archiving Klass::java_mirror()
393   static void set_scratch_java_mirror(Klass* k, oop mirror);
394   static void remove_scratch_objects(Klass* k);
395 
396   // We use the HeapShared::roots() array to make sure that objects stored in the
397   // archived heap region are not prematurely collected. These roots include:
398   //
399   //    - mirrors of classes that have not yet been loaded.
400   //    - ConstantPool::resolved_references() of classes that have not yet been loaded.
401   //    - ArchivedKlassSubGraphInfoRecords that have not been initialized
402   //    - java.lang.Module objects that have not yet been added to the module graph
403   //
404   // When a mirror M becomes referenced by a newly loaded class K, M will be removed
405   // from HeapShared::roots() via clear_root(), and K will be responsible for
406   // keeping M alive.
407   //
408   // Other types of roots are also cleared similarly when they become referenced.
409 
410   // Dump-time only. Returns the index of the root, which can be used at run time to read
411   // the root using get_root(index, ...).
412   static int append_root(oop obj);
413   static GrowableArrayCHeap<oop, mtClassShared>* pending_roots() { return _pending_roots; }
414 
415   // Dump-time and runtime
416   static objArrayOop roots();
417   static oop get_root(int index, bool clear=false);
418 
419   // Run-time only
420   static void clear_root(int index);
421   static void set_permobj_segments(int n) { _permobj_segments = n; }
422   static void setup_test_class(const char* test_class_name) PRODUCT_RETURN;
423 #endif // INCLUDE_CDS_JAVA_HEAP
424 
425  public:
426   static oop orig_to_scratch_object(oop orig_obj);
427   static objArrayOop scratch_resolved_references(ConstantPool* src);
428   static void add_scratch_resolved_references(ConstantPool* src, objArrayOop dest) NOT_CDS_JAVA_HEAP_RETURN;
429   static void init_scratch_objects(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
430   static void init_scratch_exceptions(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
431   static void init_box_classes(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
432   static bool is_heap_region(int idx) {
433     CDS_JAVA_HEAP_ONLY(return (idx == MetaspaceShared::hp);)
434     NOT_CDS_JAVA_HEAP_RETURN_(false);
435   }
436 
437   static void resolve_classes(JavaThread* current) NOT_CDS_JAVA_HEAP_RETURN;
438   static void initialize_from_archived_subgraph(JavaThread* current, Klass* k) NOT_CDS_JAVA_HEAP_RETURN;
439 
440   static void init_for_dumping(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
441   static void write_subgraph_info_table() NOT_CDS_JAVA_HEAP_RETURN;
442   static void serialize_misc_info(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN;
443   static void init_roots(oop roots_oop) NOT_CDS_JAVA_HEAP_RETURN;
444   static void serialize_tables(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN;

445 
446   static bool is_a_test_class_in_unnamed_module(Klass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
447 
448   static void add_to_permanent_index_table(oop obj, int index);
449   // AOT-compile time only: get a stable index for an archived object.
450   // Returns 0 if obj is not archived.
451   static int get_archived_object_permanent_index(oop obj) NOT_CDS_JAVA_HEAP_RETURN_(-1);
452   // Runtime only: get back the same object for an index returned by
453   // get_archived_object_permanent_index().
454   static oop get_archived_object(int permanent_index) NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
455 
456   static void initialize_java_lang_invoke(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
457   static void initialize_default_subgraph_classes(Handle loader, TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
458 
459   static bool is_lambda_form_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
460   static bool is_lambda_proxy_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
461   static bool is_archivable_hidden_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
462 };
463 
464 #if INCLUDE_CDS_JAVA_HEAP
465 class DumpedInternedStrings :
466   public ResourceHashtable<oop, bool,
467                            15889, // prime number
468                            AnyObj::C_HEAP,
469                            mtClassShared,
470                            HeapShared::string_oop_hash>
471 {};
472 #endif
473 
474 #endif // SHARE_CDS_HEAPSHARED_HPP
< prev index next >