comparison src/hotspot/share/memory/filemap.cpp @ 52424:72d4e10305b9

8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region. Summary: Support shareable archive object subgraphs in closed archive heap regions. Reviewed-by: iklam, ccheung
author jiangli
date Sat, 03 Nov 2018 15:40:19 -0400
parents 625f6c742392
children f4e3900c8d08
comparison
equal deleted inserted replaced
23:8c0291f8ec80 24:0a44a1e7e81d
24 24
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 #include "jvm.h" 26 #include "jvm.h"
27 #include "classfile/classLoader.inline.hpp" 27 #include "classfile/classLoader.inline.hpp"
28 #include "classfile/classLoaderExt.hpp" 28 #include "classfile/classLoaderExt.hpp"
29 #include "classfile/stringTable.hpp"
30 #include "classfile/symbolTable.hpp" 29 #include "classfile/symbolTable.hpp"
31 #include "classfile/systemDictionaryShared.hpp" 30 #include "classfile/systemDictionaryShared.hpp"
32 #include "classfile/altHashing.hpp" 31 #include "classfile/altHashing.hpp"
33 #include "logging/log.hpp" 32 #include "logging/log.hpp"
34 #include "logging/logStream.hpp" 33 #include "logging/logStream.hpp"
613 " bytes, addr " INTPTR_FORMAT " file offset " SIZE_FORMAT_HEX_W(08), 612 " bytes, addr " INTPTR_FORMAT " file offset " SIZE_FORMAT_HEX_W(08),
614 region, size, p2i(base), _file_offset); 613 region, size, p2i(base), _file_offset);
615 } else { 614 } else {
616 si->_file_offset = _file_offset; 615 si->_file_offset = _file_offset;
617 } 616 }
618 if (MetaspaceShared::is_heap_region(region)) { 617 if (HeapShared::is_heap_region(region)) {
619 assert((base - (char*)Universe::narrow_oop_base()) % HeapWordSize == 0, "Sanity"); 618 assert((base - (char*)Universe::narrow_oop_base()) % HeapWordSize == 0, "Sanity");
620 if (base != NULL) { 619 if (base != NULL) {
621 si->_addr._offset = (intx)CompressedOops::encode_not_null((oop)base); 620 si->_addr._offset = (intx)CompressedOops::encode_not_null((oop)base);
622 } else { 621 } else {
623 si->_addr._offset = 0; 622 si->_addr._offset = 0;
812 // Memory map a region in the address space. 811 // Memory map a region in the address space.
813 static const char* shared_region_name[] = { "MiscData", "ReadWrite", "ReadOnly", "MiscCode", "OptionalData", 812 static const char* shared_region_name[] = { "MiscData", "ReadWrite", "ReadOnly", "MiscCode", "OptionalData",
814 "String1", "String2", "OpenArchive1", "OpenArchive2" }; 813 "String1", "String2", "OpenArchive1", "OpenArchive2" };
815 814
816 char* FileMapInfo::map_region(int i, char** top_ret) { 815 char* FileMapInfo::map_region(int i, char** top_ret) {
817 assert(!MetaspaceShared::is_heap_region(i), "sanity"); 816 assert(!HeapShared::is_heap_region(i), "sanity");
818 CDSFileMapRegion* si = space_at(i); 817 CDSFileMapRegion* si = space_at(i);
819 size_t used = si->_used; 818 size_t used = si->_used;
820 size_t alignment = os::vm_allocation_granularity(); 819 size_t alignment = os::vm_allocation_granularity();
821 size_t size = align_up(used, alignment); 820 size_t size = align_up(used, alignment);
822 char *requested_addr = region_addr(i); 821 char *requested_addr = region_addr(i);
855 } else { 854 } else {
856 return (address)HeapShared::decode_from_archive(offset_of_space(spc)); 855 return (address)HeapShared::decode_from_archive(offset_of_space(spc));
857 } 856 }
858 } 857 }
859 858
860 static MemRegion *string_ranges = NULL; 859 static MemRegion *closed_archive_heap_ranges = NULL;
861 static MemRegion *open_archive_heap_ranges = NULL; 860 static MemRegion *open_archive_heap_ranges = NULL;
862 static int num_string_ranges = 0; 861 static int num_closed_archive_heap_ranges = 0;
863 static int num_open_archive_heap_ranges = 0; 862 static int num_open_archive_heap_ranges = 0;
864 863
865 #if INCLUDE_CDS_JAVA_HEAP 864 #if INCLUDE_CDS_JAVA_HEAP
866 bool FileMapInfo::has_heap_regions() { 865 bool FileMapInfo::has_heap_regions() {
867 return (_header->_space[MetaspaceShared::first_string]._used > 0); 866 return (_header->_space[MetaspaceShared::first_closed_archive_heap_region]._used > 0);
868 } 867 }
869 868
870 // Returns the address range of the archived heap regions computed using the 869 // Returns the address range of the archived heap regions computed using the
871 // current oop encoding mode. This range may be different than the one seen at 870 // current oop encoding mode. This range may be different than the one seen at
872 // dump time due to encoding mode differences. The result is used in determining 871 // dump time due to encoding mode differences. The result is used in determining
873 // if/how these regions should be relocated at run time. 872 // if/how these regions should be relocated at run time.
874 MemRegion FileMapInfo::get_heap_regions_range_with_current_oop_encoding_mode() { 873 MemRegion FileMapInfo::get_heap_regions_range_with_current_oop_encoding_mode() {
875 address start = (address) max_uintx; 874 address start = (address) max_uintx;
876 address end = NULL; 875 address end = NULL;
877 876
878 for (int i = MetaspaceShared::first_string; i <= MetaspaceShared::last_valid_region; i++) { 877 for (int i = MetaspaceShared::first_closed_archive_heap_region;
878 i <= MetaspaceShared::last_valid_region;
879 i++) {
879 CDSFileMapRegion* si = space_at(i); 880 CDSFileMapRegion* si = space_at(i);
880 size_t size = si->_used; 881 size_t size = si->_used;
881 if (size > 0) { 882 if (size > 0) {
882 address s = start_address_as_decoded_with_current_oop_encoding_mode(si); 883 address s = start_address_as_decoded_with_current_oop_encoding_mode(si);
883 address e = s + size; 884 address e = s + size;
892 assert(end != NULL, "must have at least one used heap region"); 893 assert(end != NULL, "must have at least one used heap region");
893 return MemRegion((HeapWord*)start, (HeapWord*)end); 894 return MemRegion((HeapWord*)start, (HeapWord*)end);
894 } 895 }
895 896
896 // 897 //
897 // Map the shared string objects and open archive heap objects to the runtime 898 // Map the closed and open archive heap objects to the runtime java heap.
898 // java heap.
899 // 899 //
900 // The shared strings are mapped close to the end of the java heap top in 900 // The shared objects are mapped at (or close to ) the java heap top in
901 // closed archive regions. The mapped strings contain no out-going references 901 // closed archive regions. The mapped objects contain no out-going
902 // to any other java heap regions. GC does not write into the mapped shared strings. 902 // references to any other java heap regions. GC does not write into the
903 // mapped closed archive heap region.
903 // 904 //
904 // The open archive heap objects are mapped below the shared strings in 905 // The open archive heap objects are mapped below the shared objects in
905 // the runtime java heap. The mapped open archive heap data only contain 906 // the runtime java heap. The mapped open archive heap data only contains
906 // references to the shared strings and open archive objects initially. 907 // references to the shared objects and open archive objects initially.
907 // During runtime execution, out-going references to any other java heap 908 // During runtime execution, out-going references to any other java heap
908 // regions may be added. GC may mark and update references in the mapped 909 // regions may be added. GC may mark and update references in the mapped
909 // open archive objects. 910 // open archive objects.
910 void FileMapInfo::map_heap_regions_impl() { 911 void FileMapInfo::map_heap_regions_impl() {
911 if (!HeapShared::is_heap_object_archiving_allowed()) { 912 if (!HeapShared::is_heap_object_archiving_allowed()) {
981 } 982 }
982 983
983 log_info(cds)("CDS heap data relocation delta = " INTX_FORMAT " bytes", delta); 984 log_info(cds)("CDS heap data relocation delta = " INTX_FORMAT " bytes", delta);
984 HeapShared::init_narrow_oop_decoding(narrow_oop_base() + delta, narrow_oop_shift()); 985 HeapShared::init_narrow_oop_decoding(narrow_oop_base() + delta, narrow_oop_shift());
985 986
986 CDSFileMapRegion* si = space_at(MetaspaceShared::first_string); 987 CDSFileMapRegion* si = space_at(MetaspaceShared::first_closed_archive_heap_region);
987 address relocated_strings_bottom = start_address_as_decoded_from_archive(si); 988 address relocated_closed_heap_region_bottom = start_address_as_decoded_from_archive(si);
988 if (!is_aligned(relocated_strings_bottom, HeapRegion::GrainBytes)) { 989 if (!is_aligned(relocated_closed_heap_region_bottom, HeapRegion::GrainBytes)) {
989 // Align the bottom of the string regions at G1 region boundary. This will avoid 990 // Align the bottom of the closed archive heap regions at G1 region boundary.
990 // the situation where the highest open region and the lowest string region sharing 991 // This will avoid the situation where the highest open region and the lowest
991 // the same G1 region. Otherwise we will fail to map the open regions. 992 // closed region sharing the same G1 region. Otherwise we will fail to map the
992 size_t align = size_t(relocated_strings_bottom) % HeapRegion::GrainBytes; 993 // open regions.
994 size_t align = size_t(relocated_closed_heap_region_bottom) % HeapRegion::GrainBytes;
993 delta -= align; 995 delta -= align;
994 log_info(cds)("CDS heap data need to be relocated lower by a further " SIZE_FORMAT 996 log_info(cds)("CDS heap data need to be relocated lower by a further " SIZE_FORMAT
995 " bytes to " INTX_FORMAT " to be aligned with HeapRegion::GrainBytes", align, delta); 997 " bytes to " INTX_FORMAT " to be aligned with HeapRegion::GrainBytes",
998 align, delta);
996 HeapShared::init_narrow_oop_decoding(narrow_oop_base() + delta, narrow_oop_shift()); 999 HeapShared::init_narrow_oop_decoding(narrow_oop_base() + delta, narrow_oop_shift());
997 _heap_pointers_need_patching = true; 1000 _heap_pointers_need_patching = true;
998 relocated_strings_bottom = start_address_as_decoded_from_archive(si); 1001 relocated_closed_heap_region_bottom = start_address_as_decoded_from_archive(si);
999 } 1002 }
1000 assert(is_aligned(relocated_strings_bottom, HeapRegion::GrainBytes), "must be"); 1003 assert(is_aligned(relocated_closed_heap_region_bottom, HeapRegion::GrainBytes),
1001 1004 "must be");
1002 // First, map string regions as closed archive heap regions. 1005
1003 // GC does not write into the regions. 1006 // Map the closed_archive_heap regions, GC does not write into the regions.
1004 if (map_heap_data(&string_ranges, 1007 if (map_heap_data(&closed_archive_heap_ranges,
1005 MetaspaceShared::first_string, 1008 MetaspaceShared::first_closed_archive_heap_region,
1006 MetaspaceShared::max_strings, 1009 MetaspaceShared::max_closed_archive_heap_region,
1007 &num_string_ranges)) { 1010 &num_closed_archive_heap_ranges)) {
1008 StringTable::set_shared_string_mapped(); 1011 HeapShared::set_closed_archive_heap_region_mapped();
1009 1012
1010 // Now, map open_archive heap regions, GC can write into the regions. 1013 // Now, map open_archive heap regions, GC can write into the regions.
1011 if (map_heap_data(&open_archive_heap_ranges, 1014 if (map_heap_data(&open_archive_heap_ranges,
1012 MetaspaceShared::first_open_archive_heap_region, 1015 MetaspaceShared::first_open_archive_heap_region,
1013 MetaspaceShared::max_open_archive_heap_region, 1016 MetaspaceShared::max_open_archive_heap_region,
1021 void FileMapInfo::map_heap_regions() { 1024 void FileMapInfo::map_heap_regions() {
1022 if (has_heap_regions()) { 1025 if (has_heap_regions()) {
1023 map_heap_regions_impl(); 1026 map_heap_regions_impl();
1024 } 1027 }
1025 1028
1026 if (!StringTable::shared_string_mapped()) { 1029 if (!HeapShared::closed_archive_heap_region_mapped()) {
1027 assert(string_ranges == NULL && num_string_ranges == 0, "sanity"); 1030 assert(closed_archive_heap_ranges == NULL &&
1031 num_closed_archive_heap_ranges == 0, "sanity");
1028 } 1032 }
1029 1033
1030 if (!HeapShared::open_archive_heap_region_mapped()) { 1034 if (!HeapShared::open_archive_heap_region_mapped()) {
1031 assert(open_archive_heap_ranges == NULL && num_open_archive_heap_ranges == 0, "sanity"); 1035 assert(open_archive_heap_ranges == NULL && num_open_archive_heap_ranges == 0, "sanity");
1032 } 1036 }
1113 void FileMapInfo::patch_archived_heap_embedded_pointers() { 1117 void FileMapInfo::patch_archived_heap_embedded_pointers() {
1114 if (!_heap_pointers_need_patching) { 1118 if (!_heap_pointers_need_patching) {
1115 return; 1119 return;
1116 } 1120 }
1117 1121
1118 patch_archived_heap_embedded_pointers(string_ranges, 1122 patch_archived_heap_embedded_pointers(closed_archive_heap_ranges,
1119 num_string_ranges, 1123 num_closed_archive_heap_ranges,
1120 MetaspaceShared::first_string); 1124 MetaspaceShared::first_closed_archive_heap_region);
1121 1125
1122 patch_archived_heap_embedded_pointers(open_archive_heap_ranges, 1126 patch_archived_heap_embedded_pointers(open_archive_heap_ranges,
1123 num_open_archive_heap_ranges, 1127 num_open_archive_heap_ranges,
1124 MetaspaceShared::first_open_archive_heap_region); 1128 MetaspaceShared::first_open_archive_heap_region);
1125 } 1129 }
1134 } 1138 }
1135 1139
1136 // This internally allocates objects using SystemDictionary::Object_klass(), so it 1140 // This internally allocates objects using SystemDictionary::Object_klass(), so it
1137 // must be called after the well-known classes are resolved. 1141 // must be called after the well-known classes are resolved.
1138 void FileMapInfo::fixup_mapped_heap_regions() { 1142 void FileMapInfo::fixup_mapped_heap_regions() {
1139 // If any string regions were found, call the fill routine to make them parseable. 1143 // If any closed regions were found, call the fill routine to make them parseable.
1140 // Note that string_ranges may be non-NULL even if no ranges were found. 1144 // Note that closed_archive_heap_ranges may be non-NULL even if no ranges were found.
1141 if (num_string_ranges != 0) { 1145 if (num_closed_archive_heap_ranges != 0) {
1142 assert(string_ranges != NULL, "Null string_ranges array with non-zero count"); 1146 assert(closed_archive_heap_ranges != NULL,
1143 G1CollectedHeap::heap()->fill_archive_regions(string_ranges, num_string_ranges); 1147 "Null closed_archive_heap_ranges array with non-zero count");
1148 G1CollectedHeap::heap()->fill_archive_regions(closed_archive_heap_ranges,
1149 num_closed_archive_heap_ranges);
1144 } 1150 }
1145 1151
1146 // do the same for mapped open archive heap regions 1152 // do the same for mapped open archive heap regions
1147 if (num_open_archive_heap_ranges != 0) { 1153 if (num_open_archive_heap_ranges != 0) {
1148 assert(open_archive_heap_ranges != NULL, "NULL open_archive_heap_ranges array with non-zero count"); 1154 assert(open_archive_heap_ranges != NULL, "NULL open_archive_heap_ranges array with non-zero count");
1168 size_t sz = space_at(i)->_used; 1174 size_t sz = space_at(i)->_used;
1169 1175
1170 if (sz == 0) { 1176 if (sz == 0) {
1171 return true; // no data 1177 return true; // no data
1172 } 1178 }
1173 if ((MetaspaceShared::is_string_region(i) && 1179 if ((HeapShared::is_closed_archive_heap_region(i) &&
1174 !StringTable::shared_string_mapped()) || 1180 !HeapShared::closed_archive_heap_region_mapped()) ||
1175 (MetaspaceShared::is_open_archive_heap_region(i) && 1181 (HeapShared::is_open_archive_heap_region(i) &&
1176 !HeapShared::open_archive_heap_region_mapped())) { 1182 !HeapShared::open_archive_heap_region_mapped())) {
1177 return true; // archived heap data is not mapped 1183 return true; // archived heap data is not mapped
1178 } 1184 }
1179 const char* buf = region_addr(i); 1185 const char* buf = region_addr(i);
1180 int crc = ClassLoader::crc32(0, buf, (jint)sz); 1186 int crc = ClassLoader::crc32(0, buf, (jint)sz);
1186 } 1192 }
1187 1193
1188 // Unmap a memory region in the address space. 1194 // Unmap a memory region in the address space.
1189 1195
1190 void FileMapInfo::unmap_region(int i) { 1196 void FileMapInfo::unmap_region(int i) {
1191 assert(!MetaspaceShared::is_heap_region(i), "sanity"); 1197 assert(!HeapShared::is_heap_region(i), "sanity");
1192 CDSFileMapRegion* si = space_at(i); 1198 CDSFileMapRegion* si = space_at(i);
1193 size_t used = si->_used; 1199 size_t used = si->_used;
1194 size_t size = align_up(used, os::vm_allocation_granularity()); 1200 size_t size = align_up(used, os::vm_allocation_granularity());
1195 1201
1196 if (used == 0) { 1202 if (used == 0) {
1257 return true; 1263 return true;
1258 } 1264 }
1259 1265
1260 char* FileMapInfo::region_addr(int idx) { 1266 char* FileMapInfo::region_addr(int idx) {
1261 CDSFileMapRegion* si = space_at(idx); 1267 CDSFileMapRegion* si = space_at(idx);
1262 if (MetaspaceShared::is_heap_region(idx)) { 1268 if (HeapShared::is_heap_region(idx)) {
1263 assert(DumpSharedSpaces, "The following doesn't work at runtime"); 1269 assert(DumpSharedSpaces, "The following doesn't work at runtime");
1264 return si->_used > 0 ? 1270 return si->_used > 0 ?
1265 (char*)start_address_as_decoded_with_current_oop_encoding_mode(si) : NULL; 1271 (char*)start_address_as_decoded_with_current_oop_encoding_mode(si) : NULL;
1266 } else { 1272 } else {
1267 return si->_addr._base; 1273 return si->_addr._base;
1324 // header data 1330 // header data
1325 const char* prop = Arguments::get_property("java.system.class.loader"); 1331 const char* prop = Arguments::get_property("java.system.class.loader");
1326 if (prop != NULL) { 1332 if (prop != NULL) {
1327 warning("Archived non-system classes are disabled because the " 1333 warning("Archived non-system classes are disabled because the "
1328 "java.system.class.loader property is specified (value = \"%s\"). " 1334 "java.system.class.loader property is specified (value = \"%s\"). "
1329 "To use archived non-system classes, this property must be not be set", prop); 1335 "To use archived non-system classes, this property must not be set", prop);
1330 _has_platform_or_app_classes = false; 1336 _has_platform_or_app_classes = false;
1331 } 1337 }
1332 1338
1333 // For backwards compatibility, we don't check the verification setting 1339 // For backwards compatibility, we don't check the verification setting
1334 // if the archive only contains system classes. 1340 // if the archive only contains system classes.
1381 1387
1382 FileMapInfo *map_info = FileMapInfo::current_info(); 1388 FileMapInfo *map_info = FileMapInfo::current_info();
1383 if (map_info) { 1389 if (map_info) {
1384 map_info->fail_continue("%s", msg); 1390 map_info->fail_continue("%s", msg);
1385 for (int i = 0; i < MetaspaceShared::num_non_heap_spaces; i++) { 1391 for (int i = 0; i < MetaspaceShared::num_non_heap_spaces; i++) {
1386 if (!MetaspaceShared::is_heap_region(i)) { 1392 if (!HeapShared::is_heap_region(i)) {
1387 char *addr = map_info->region_addr(i); 1393 char *addr = map_info->region_addr(i);
1388 if (addr != NULL) { 1394 if (addr != NULL) {
1389 map_info->unmap_region(i); 1395 map_info->unmap_region(i);
1390 map_info->space_at(i)->_addr._base = NULL; 1396 map_info->space_at(i)->_addr._base = NULL;
1391 } 1397 }
1393 } 1399 }
1394 // Dealloc the archive heap regions only without unmapping. The regions are part 1400 // Dealloc the archive heap regions only without unmapping. The regions are part
1395 // of the java heap. Unmapping of the heap regions are managed by GC. 1401 // of the java heap. Unmapping of the heap regions are managed by GC.
1396 map_info->dealloc_archive_heap_regions(open_archive_heap_ranges, 1402 map_info->dealloc_archive_heap_regions(open_archive_heap_ranges,
1397 num_open_archive_heap_ranges); 1403 num_open_archive_heap_ranges);
1398 map_info->dealloc_archive_heap_regions(string_ranges, num_string_ranges); 1404 map_info->dealloc_archive_heap_regions(closed_archive_heap_ranges,
1405 num_closed_archive_heap_ranges);
1399 } else if (DumpSharedSpaces) { 1406 } else if (DumpSharedSpaces) {
1400 fail_stop("%s", msg); 1407 fail_stop("%s", msg);
1401 } 1408 }
1402 } 1409 }