34 #include "memory/metaspaceClosure.hpp" |
35 #include "memory/metaspaceClosure.hpp" |
35 #include "memory/metaspaceShared.hpp" |
36 #include "memory/metaspaceShared.hpp" |
36 #include "memory/resourceArea.hpp" |
37 #include "memory/resourceArea.hpp" |
37 #include "oops/compressedOops.inline.hpp" |
38 #include "oops/compressedOops.inline.hpp" |
38 #include "oops/oop.inline.hpp" |
39 #include "oops/oop.inline.hpp" |
|
40 #include "runtime/fieldDescriptor.hpp" |
39 |
41 |
40 #if INCLUDE_CDS_JAVA_HEAP |
42 #if INCLUDE_CDS_JAVA_HEAP |
41 KlassSubGraphInfo* HeapShared::_subgraph_info_list = NULL; |
43 KlassSubGraphInfo* HeapShared::_subgraph_info_list = NULL; |
42 int HeapShared::_num_archived_subgraph_info_records = 0; |
44 int HeapShared::_num_archived_subgraph_info_records = 0; |
43 Array<ArchivedKlassSubGraphInfoRecord>* HeapShared::_archived_subgraph_info_records = NULL; |
45 Array<ArchivedKlassSubGraphInfoRecord>* HeapShared::_archived_subgraph_info_records = NULL; |
524 } else { |
526 } else { |
525 ShouldNotReachHere(); |
527 ShouldNotReachHere(); |
526 } |
528 } |
527 } |
529 } |
528 |
530 |
529 #define do_module_object_graph(archive_object_graph_do) \ |
531 struct ArchivableStaticFieldInfo { |
530 archive_object_graph_do(SystemDictionary::ArchivedModuleGraph_klass(), jdk_internal_module_ArchivedModuleGraph::archivedSystemModules_offset(), T_OBJECT, CHECK); \ |
532 const char* class_name; |
531 archive_object_graph_do(SystemDictionary::ArchivedModuleGraph_klass(), jdk_internal_module_ArchivedModuleGraph::archivedModuleFinder_offset(), T_OBJECT, CHECK); \ |
533 const char* field_name; |
532 archive_object_graph_do(SystemDictionary::ArchivedModuleGraph_klass(), jdk_internal_module_ArchivedModuleGraph::archivedMainModule_offset(), T_OBJECT, CHECK); \ |
534 InstanceKlass* klass; |
533 archive_object_graph_do(SystemDictionary::ArchivedModuleGraph_klass(), jdk_internal_module_ArchivedModuleGraph::archivedConfiguration_offset(), T_OBJECT, CHECK); \ |
535 int offset; |
534 archive_object_graph_do(SystemDictionary::ImmutableCollections_ListN_klass(), java_util_ImmutableCollections_ListN::EMPTY_LIST_offset(), T_OBJECT, CHECK); \ |
536 BasicType type; |
535 archive_object_graph_do(SystemDictionary::ImmutableCollections_MapN_klass(), java_util_ImmutableCollections_MapN::EMPTY_MAP_offset(), T_OBJECT, CHECK); \ |
537 }; |
536 archive_object_graph_do(SystemDictionary::ImmutableCollections_SetN_klass(), java_util_ImmutableCollections_SetN::EMPTY_SET_offset(), T_OBJECT, CHECK); \ |
538 |
537 archive_object_graph_do(SystemDictionary::Integer_IntegerCache_klass(), java_lang_Integer_IntegerCache::archivedCache_offset(), T_OBJECT, CHECK); \ |
539 // If you add new entries to this table, you should know what you're doing! |
538 archive_object_graph_do(SystemDictionary::Configuration_klass(), java_lang_module_Configuration::EMPTY_CONFIGURATION_offset(), T_OBJECT, CHECK) |
540 static ArchivableStaticFieldInfo archivable_static_fields[] = { |
|
541 {"jdk/internal/module/ArchivedModuleGraph", "archivedSystemModules"}, |
|
542 {"jdk/internal/module/ArchivedModuleGraph", "archivedModuleFinder"}, |
|
543 {"jdk/internal/module/ArchivedModuleGraph", "archivedMainModule"}, |
|
544 {"jdk/internal/module/ArchivedModuleGraph", "archivedConfiguration"}, |
|
545 {"java/util/ImmutableCollections$ListN", "EMPTY_LIST"}, |
|
546 {"java/util/ImmutableCollections$MapN", "EMPTY_MAP"}, |
|
547 {"java/util/ImmutableCollections$SetN", "EMPTY_SET"}, |
|
548 {"java/lang/Integer$IntegerCache", "archivedCache"}, |
|
549 {"java/lang/module/Configuration", "EMPTY_CONFIGURATION"}, |
|
550 }; |
|
551 |
|
552 const static int num_archivable_static_fields = sizeof(archivable_static_fields) / sizeof(ArchivableStaticFieldInfo); |
|
553 |
|
554 class ArchivableStaticFieldFinder: public FieldClosure { |
|
555 InstanceKlass* _ik; |
|
556 Symbol* _field_name; |
|
557 bool _found; |
|
558 int _offset; |
|
559 BasicType _type; |
|
560 public: |
|
561 ArchivableStaticFieldFinder(InstanceKlass* ik, Symbol* field_name) : |
|
562 _ik(ik), _field_name(field_name), _found(false), _offset(-1), _type(T_ILLEGAL) {} |
|
563 |
|
564 virtual void do_field(fieldDescriptor* fd) { |
|
565 if (fd->name() == _field_name) { |
|
566 assert(!_found, "fields cannot be overloaded"); |
|
567 _found = true; |
|
568 _offset = fd->offset(); |
|
569 _type = fd->field_type(); |
|
570 assert(_type == T_OBJECT || _type == T_ARRAY, "can archive only obj or array fields"); |
|
571 } |
|
572 } |
|
573 bool found() { return _found; } |
|
574 int offset() { return _offset; } |
|
575 BasicType type() { return _type; } |
|
576 }; |
|
577 |
|
578 void HeapShared::init_archivable_static_fields(Thread* THREAD) { |
|
579 for (int i = 0; i < num_archivable_static_fields; i++) { |
|
580 ArchivableStaticFieldInfo* info = &archivable_static_fields[i]; |
|
581 TempNewSymbol class_name = SymbolTable::new_symbol(info->class_name, THREAD); |
|
582 TempNewSymbol field_name = SymbolTable::new_symbol(info->field_name, THREAD); |
|
583 |
|
584 Klass* k = SystemDictionary::resolve_or_null(class_name, THREAD); |
|
585 assert(k != NULL && !HAS_PENDING_EXCEPTION, "class must exist"); |
|
586 InstanceKlass* ik = InstanceKlass::cast(k); |
|
587 |
|
588 ArchivableStaticFieldFinder finder(ik, field_name); |
|
589 ik->do_local_static_fields(&finder); |
|
590 assert(finder.found(), "field must exist"); |
|
591 |
|
592 info->klass = ik; |
|
593 info->offset = finder.offset(); |
|
594 info->type = finder.type(); |
|
595 } |
|
596 } |
539 |
597 |
540 void HeapShared::archive_module_graph_objects(Thread* THREAD) { |
598 void HeapShared::archive_module_graph_objects(Thread* THREAD) { |
541 do_module_object_graph(archive_reachable_objects_from_static_field); |
599 for (int i = 0; i < num_archivable_static_fields; i++) { |
|
600 ArchivableStaticFieldInfo* info = &archivable_static_fields[i]; |
|
601 archive_reachable_objects_from_static_field(info->klass, info->offset, info->type, CHECK); |
|
602 } |
542 } |
603 } |
543 #endif // INCLUDE_CDS_JAVA_HEAP |
604 #endif // INCLUDE_CDS_JAVA_HEAP |