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

292 
293   // !UseCompressedOops only: used to relocate pointers to the archived objects
294   static ptrdiff_t _runtime_delta;
295 
296   typedef ResizeableResourceHashtable<oop, bool,
297       AnyObj::C_HEAP,
298       mtClassShared,
299       HeapShared::oop_hash> SeenObjectsTable;
300 
301   static SeenObjectsTable *_seen_objects_table;
302 
303   // The "special subgraph" contains all the archived objects that are reachable
304   // from the following roots:
305   //    - interned strings
306   //    - Klass::java_mirror() -- including aot-initialized mirrors such as those of Enum klasses.
307   //    - ConstantPool::resolved_references()
308   //    - Universe::<xxx>_exception_instance()
309   static KlassSubGraphInfo* _dump_time_special_subgraph;              // for collecting info during dump time
310   static ArchivedKlassSubGraphInfoRecord* _run_time_special_subgraph; // for initializing classes during run time.
311 
312   static GrowableArrayCHeap<oop, mtClassShared>* _pending_roots;
313   static GrowableArrayCHeap<OopHandle, mtClassShared>* _root_segments;


314   static int _root_segment_max_size_elems;
315   static OopHandle _scratch_basic_type_mirrors[T_VOID+1];
316   static MetaspaceObjToOopHandleTable* _scratch_java_mirror_table;
317   static MetaspaceObjToOopHandleTable* _scratch_references_table;
318 
319   static void init_seen_objects_table() {
320     assert(_seen_objects_table == nullptr, "must be");
321     _seen_objects_table = new (mtClass)SeenObjectsTable(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
322   }
323   static void delete_seen_objects_table() {
324     assert(_seen_objects_table != nullptr, "must be");
325     delete _seen_objects_table;
326     _seen_objects_table = nullptr;
327   }
328 



329   // Statistics (for one round of start_recording_subgraph ... done_recording_subgraph)
330   static int _num_new_walked_objs;
331   static int _num_new_archived_objs;
332   static int _num_old_recorded_klasses;
333 
334   // Statistics (for all archived subgraphs)
335   static int _num_total_subgraph_recordings;
336   static int _num_total_walked_objs;
337   static int _num_total_archived_objs;
338   static int _num_total_recorded_klasses;
339   static int _num_total_verifications;
340 
341   static void start_recording_subgraph(InstanceKlass *k, const char* klass_name,
342                                        bool is_full_module_graph);
343   static void done_recording_subgraph(InstanceKlass *k, const char* klass_name);
344 
345   static bool has_been_seen_during_subgraph_recording(oop obj);
346   static void set_has_been_seen_during_subgraph_recording(oop obj);
347   static bool archive_object(oop obj);
348   static void copy_aot_initialized_mirror(Klass* orig_k, oop orig_mirror, oop m);

362   static void sort_loaded_regions(LoadedArchiveHeapRegion* loaded_regions, int num_loaded_regions,
363                                   uintptr_t buffer);
364   static bool load_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
365                            int num_loaded_regions, uintptr_t buffer);
366   static void init_loaded_heap_relocation(LoadedArchiveHeapRegion* reloc_info,
367                                           int num_loaded_regions);
368   static void fill_failed_loaded_region();
369   static void mark_native_pointers(oop orig_obj);
370   static bool has_been_archived(oop orig_obj);
371   static void prepare_resolved_references();
372   static void archive_java_mirrors();
373   static void archive_strings();
374   static void copy_special_subgraph();
375 
376   class AOTInitializedClassScanner;
377   static void find_all_aot_initialized_classes();
378   static void find_all_aot_initialized_classes_helper();
379   static bool scan_for_aot_initialized_classes(oop obj);
380 
381  public:

382   static void reset_archived_object_states(TRAPS);
383   static void create_archived_object_cache() {
384     _archived_object_cache =
385       new (mtClass)ArchivedObjectCache(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
386   }
387   static void destroy_archived_object_cache() {
388     delete _archived_object_cache;
389     _archived_object_cache = nullptr;
390   }
391   static ArchivedObjectCache* archived_object_cache() {
392     return _archived_object_cache;
393   }
394 
395   static int archive_exception_instance(oop exception);
396   static void archive_objects(ArchiveHeapInfo* heap_info);
397   static void copy_objects();
398 
399   static bool archive_reachable_objects_from(int level,
400                                              KlassSubGraphInfo* subgraph_info,
401                                              oop orig_obj);
402 
403   static void add_to_dumped_interned_strings(oop string);
404 


405   // Scratch objects for archiving Klass::java_mirror()
406   static void set_scratch_java_mirror(Klass* k, oop mirror);
407   static void remove_scratch_objects(Klass* k);
408   static void get_pointer_info(oop src_obj, bool& has_oop_pointers, bool& has_native_pointers);
409   static void set_has_native_pointers(oop src_obj);
410 
411   // We use the HeapShared::roots() array to make sure that objects stored in the
412   // archived heap region are not prematurely collected. These roots include:
413   //
414   //    - mirrors of classes that have not yet been loaded.
415   //    - ConstantPool::resolved_references() of classes that have not yet been loaded.
416   //    - ArchivedKlassSubGraphInfoRecords that have not been initialized
417   //    - java.lang.Module objects that have not yet been added to the module graph
418   //
419   // When a mirror M becomes referenced by a newly loaded class K, M will be removed
420   // from HeapShared::roots() via clear_root(), and K will be responsible for
421   // keeping M alive.
422   //
423   // Other types of roots are also cleared similarly when they become referenced.
424 
425   // Dump-time only. Returns the index of the root, which can be used at run time to read
426   // the root using get_root(index, ...).
427   static int append_root(oop obj);
428   static GrowableArrayCHeap<oop, mtClassShared>* pending_roots() { return _pending_roots; }
429 
430   // Dump-time and runtime
431   static objArrayOop root_segment(int segment_idx);
432   static oop get_root(int index, bool clear=false);
433 
434   // Run-time only
435   static void clear_root(int index);
436 
437   static void get_segment_indexes(int index, int& segment_index, int& internal_index);
438 
439   static void setup_test_class(const char* test_class_name) PRODUCT_RETURN;
440 #endif // INCLUDE_CDS_JAVA_HEAP
441 
442  public:

443   static objArrayOop scratch_resolved_references(ConstantPool* src);
444   static void add_scratch_resolved_references(ConstantPool* src, objArrayOop dest) NOT_CDS_JAVA_HEAP_RETURN;
445   static void init_scratch_objects(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
446   static void init_box_classes(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
447   static bool is_heap_region(int idx) {
448     CDS_JAVA_HEAP_ONLY(return (idx == MetaspaceShared::hp);)
449     NOT_CDS_JAVA_HEAP_RETURN_(false);
450   }
451 
452   static void resolve_classes(JavaThread* current) NOT_CDS_JAVA_HEAP_RETURN;
453   static void initialize_from_archived_subgraph(JavaThread* current, Klass* k) NOT_CDS_JAVA_HEAP_RETURN;
454 
455   static void init_for_dumping(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
456   static void write_subgraph_info_table() NOT_CDS_JAVA_HEAP_RETURN;
457   static void add_root_segment(objArrayOop segment_oop) NOT_CDS_JAVA_HEAP_RETURN;
458   static void init_root_segment_sizes(int max_size_elems) NOT_CDS_JAVA_HEAP_RETURN;
459   static void serialize_tables(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN;
460 
461 #ifndef PRODUCT
462   static bool is_a_test_class_in_unnamed_module(Klass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
463   static void initialize_test_class_from_archive(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
464 #endif
465 









466   static void initialize_java_lang_invoke(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
467   static void init_classes_for_special_subgraph(Handle loader, TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
468 
469   static bool is_lambda_form_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
470   static bool is_lambda_proxy_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
471   static bool is_string_concat_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
472   static bool is_archivable_hidden_klass(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN_(false);
473 };
474 








475 #if INCLUDE_CDS_JAVA_HEAP
476 class DumpedInternedStrings :
477   public ResizeableResourceHashtable<oop, bool,
478                            AnyObj::C_HEAP,
479                            mtClassShared,
480                            HeapShared::string_oop_hash>
481 {
482 public:
483   DumpedInternedStrings(unsigned size, unsigned max_size) :
484     ResizeableResourceHashtable<oop, bool,
485                                 AnyObj::C_HEAP,
486                                 mtClassShared,
487                                 HeapShared::string_oop_hash>(size, max_size) {}
488 };
489 #endif
490 
491 #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;

293 
294   // !UseCompressedOops only: used to relocate pointers to the archived objects
295   static ptrdiff_t _runtime_delta;
296 
297   typedef ResizeableResourceHashtable<oop, bool,
298       AnyObj::C_HEAP,
299       mtClassShared,
300       HeapShared::oop_hash> SeenObjectsTable;
301 
302   static SeenObjectsTable *_seen_objects_table;
303 
304   // The "special subgraph" contains all the archived objects that are reachable
305   // from the following roots:
306   //    - interned strings
307   //    - Klass::java_mirror() -- including aot-initialized mirrors such as those of Enum klasses.
308   //    - ConstantPool::resolved_references()
309   //    - Universe::<xxx>_exception_instance()
310   static KlassSubGraphInfo* _dump_time_special_subgraph;              // for collecting info during dump time
311   static ArchivedKlassSubGraphInfoRecord* _run_time_special_subgraph; // for initializing classes during run time.
312 
313   static GrowableArrayCHeap<OopHandle, mtClassShared>* _pending_roots;
314   static GrowableArrayCHeap<OopHandle, mtClassShared>* _root_segments;
315   static GrowableArrayCHeap<oop, mtClassShared>* _trace; // for debugging unarchivable objects
316   static GrowableArrayCHeap<const char*, mtClassShared>* _context; // for debugging unarchivable objects
317   static int _root_segment_max_size_elems;
318   static OopHandle _scratch_basic_type_mirrors[T_VOID+1];
319   static MetaspaceObjToOopHandleTable* _scratch_java_mirror_table;
320   static MetaspaceObjToOopHandleTable* _scratch_references_table;
321 
322   static void init_seen_objects_table() {
323     assert(_seen_objects_table == nullptr, "must be");
324     _seen_objects_table = new (mtClass)SeenObjectsTable(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
325   }
326   static void delete_seen_objects_table() {
327     assert(_seen_objects_table != nullptr, "must be");
328     delete _seen_objects_table;
329     _seen_objects_table = nullptr;
330   }
331 
332   class ArchivingObjectMark;
333   class ContextMark;
334 
335   // Statistics (for one round of start_recording_subgraph ... done_recording_subgraph)
336   static int _num_new_walked_objs;
337   static int _num_new_archived_objs;
338   static int _num_old_recorded_klasses;
339 
340   // Statistics (for all archived subgraphs)
341   static int _num_total_subgraph_recordings;
342   static int _num_total_walked_objs;
343   static int _num_total_archived_objs;
344   static int _num_total_recorded_klasses;
345   static int _num_total_verifications;
346 
347   static void start_recording_subgraph(InstanceKlass *k, const char* klass_name,
348                                        bool is_full_module_graph);
349   static void done_recording_subgraph(InstanceKlass *k, const char* klass_name);
350 
351   static bool has_been_seen_during_subgraph_recording(oop obj);
352   static void set_has_been_seen_during_subgraph_recording(oop obj);
353   static bool archive_object(oop obj);
354   static void copy_aot_initialized_mirror(Klass* orig_k, oop orig_mirror, oop m);

368   static void sort_loaded_regions(LoadedArchiveHeapRegion* loaded_regions, int num_loaded_regions,
369                                   uintptr_t buffer);
370   static bool load_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
371                            int num_loaded_regions, uintptr_t buffer);
372   static void init_loaded_heap_relocation(LoadedArchiveHeapRegion* reloc_info,
373                                           int num_loaded_regions);
374   static void fill_failed_loaded_region();
375   static void mark_native_pointers(oop orig_obj);
376   static bool has_been_archived(oop orig_obj);
377   static void prepare_resolved_references();
378   static void archive_java_mirrors();
379   static void archive_strings();
380   static void copy_special_subgraph();
381 
382   class AOTInitializedClassScanner;
383   static void find_all_aot_initialized_classes();
384   static void find_all_aot_initialized_classes_helper();
385   static bool scan_for_aot_initialized_classes(oop obj);
386 
387  public:
388   static void exit_on_error();
389   static void reset_archived_object_states(TRAPS);
390   static void create_archived_object_cache() {
391     _archived_object_cache =
392       new (mtClass)ArchivedObjectCache(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE);
393   }
394   static void destroy_archived_object_cache() {
395     delete _archived_object_cache;
396     _archived_object_cache = nullptr;
397   }
398   static ArchivedObjectCache* archived_object_cache() {
399     return _archived_object_cache;
400   }
401 
402   static int archive_exception_instance(oop exception);
403   static void archive_objects(ArchiveHeapInfo* heap_info);
404   static void copy_objects();
405 
406   static bool archive_reachable_objects_from(int level,
407                                              KlassSubGraphInfo* subgraph_info,
408                                              oop orig_obj);
409 
410   static void add_to_dumped_interned_strings(oop string);
411 
412   static void track_scratch_object(oop orig_obj, oop scratch_obj);
413 
414   // Scratch objects for archiving Klass::java_mirror()
415   static void set_scratch_java_mirror(Klass* k, oop mirror);
416   static void remove_scratch_objects(Klass* k);
417   static void get_pointer_info(oop src_obj, bool& has_oop_pointers, bool& has_native_pointers);
418   static void set_has_native_pointers(oop src_obj);
419 
420   // We use the HeapShared::roots() array to make sure that objects stored in the
421   // archived heap region are not prematurely collected. These roots include:
422   //
423   //    - mirrors of classes that have not yet been loaded.
424   //    - ConstantPool::resolved_references() of classes that have not yet been loaded.
425   //    - ArchivedKlassSubGraphInfoRecords that have not been initialized
426   //    - java.lang.Module objects that have not yet been added to the module graph
427   //
428   // When a mirror M becomes referenced by a newly loaded class K, M will be removed
429   // from HeapShared::roots() via clear_root(), and K will be responsible for
430   // keeping M alive.
431   //
432   // Other types of roots are also cleared similarly when they become referenced.
433 
434   // Dump-time only. Returns the index of the root, which can be used at run time to read
435   // the root using get_root(index, ...).
436   static int append_root(oop obj);
437   static GrowableArrayCHeap<OopHandle, mtClassShared>* pending_roots() { return _pending_roots; }
438 
439   // Dump-time and runtime
440   static objArrayOop root_segment(int segment_idx);
441   static oop get_root(int index, bool clear=false);
442 
443   // Run-time only
444   static void clear_root(int index);

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

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