69 #include "oops/compressedKlass.hpp"
70 #include "oops/instanceMirrorKlass.hpp"
71 #include "oops/klass.inline.hpp"
72 #include "oops/objArrayOop.hpp"
73 #include "oops/oop.inline.hpp"
74 #include "oops/oopHandle.hpp"
75 #include "prims/jvmtiExport.hpp"
76 #include "runtime/arguments.hpp"
77 #include "runtime/globals.hpp"
78 #include "runtime/globals_extension.hpp"
79 #include "runtime/handles.inline.hpp"
80 #include "runtime/os.inline.hpp"
81 #include "runtime/safepointVerifiers.hpp"
82 #include "runtime/sharedRuntime.hpp"
83 #include "runtime/vmOperations.hpp"
84 #include "runtime/vmThread.hpp"
85 #include "sanitizers/leak.hpp"
86 #include "utilities/align.hpp"
87 #include "utilities/bitMap.inline.hpp"
88 #include "utilities/defaultStream.hpp"
89 #include "utilities/ostream.hpp"
90 #include "utilities/resourceHash.hpp"
91
92 ReservedSpace MetaspaceShared::_symbol_rs;
93 VirtualSpace MetaspaceShared::_symbol_vs;
94 bool MetaspaceShared::_archive_loading_failed = false;
95 bool MetaspaceShared::_remapped_readwrite = false;
96 void* MetaspaceShared::_shared_metaspace_static_top = nullptr;
97 intx MetaspaceShared::_relocation_delta;
98 char* MetaspaceShared::_requested_base_address;
99 bool MetaspaceShared::_use_optimized_module_handling = true;
100
101 // The CDS archive is divided into the following regions:
102 // rw - read-write metadata
103 // ro - read-only metadata and read-only tables
104 // hp - heap region
105 // bm - bitmap for relocating the above 7 regions.
106 //
107 // The rw and ro regions are linearly allocated, in the order of rw->ro.
108 // These regions are aligned with MetaspaceShared::core_region_alignment().
1141 }
1142 } else if (static_result == MAP_ARCHIVE_OTHER_FAILURE) {
1143 result = MAP_ARCHIVE_OTHER_FAILURE;
1144 } else {
1145 result = MAP_ARCHIVE_MMAP_FAILURE;
1146 }
1147 }
1148
1149 if (result == MAP_ARCHIVE_SUCCESS) {
1150 SharedBaseAddress = (size_t)mapped_base_address;
1151 #ifdef _LP64
1152 if (Metaspace::using_class_space()) {
1153 // Set up ccs in metaspace.
1154 Metaspace::initialize_class_space(class_space_rs);
1155
1156 // Set up compressed Klass pointer encoding: the encoding range must
1157 // cover both archive and class space.
1158 address cds_base = (address)static_mapinfo->mapped_base();
1159 address ccs_end = (address)class_space_rs.end();
1160 assert(ccs_end > cds_base, "Sanity check");
1161 #if INCLUDE_CDS_JAVA_HEAP
1162 // We archived objects with pre-computed narrow Klass id. Set up encoding such that these Ids stay valid.
1163 address precomputed_narrow_klass_base = cds_base;
1164 const int precomputed_narrow_klass_shift = ArchiveHeapWriter::precomputed_narrow_klass_shift;
1165 CompressedKlassPointers::initialize_for_given_encoding(
1166 cds_base, ccs_end - cds_base, // Klass range
1167 precomputed_narrow_klass_base, precomputed_narrow_klass_shift // precomputed encoding, see ArchiveHeapWriter
1168 );
1169 #else
1170 CompressedKlassPointers::initialize (
1171 cds_base, ccs_end - cds_base // Klass range
1172 );
1173 #endif // INCLUDE_CDS_JAVA_HEAP
1174 // map_or_load_heap_region() compares the current narrow oop and klass encodings
1175 // with the archived ones, so it must be done after all encodings are determined.
1176 static_mapinfo->map_or_load_heap_region();
1177 }
1178 #endif // _LP64
1179 log_info(cds)("initial optimized module handling: %s", CDSConfig::is_using_optimized_module_handling() ? "enabled" : "disabled");
1180 log_info(cds)("initial full module graph: %s", CDSConfig::is_using_full_module_graph() ? "enabled" : "disabled");
1181 } else {
1182 unmap_archive(static_mapinfo);
1183 unmap_archive(dynamic_mapinfo);
1184 release_reserved_spaces(total_space_rs, archive_space_rs, class_space_rs);
1185 }
1186
1187 return result;
1188 }
1189
1190
1191 // This will reserve two address spaces suitable to house Klass structures, one
1192 // for the cds archives (static archive and optionally dynamic archive) and
1193 // optionally one move for ccs.
1208 // (The gap may result from different alignment requirements between metaspace
1209 // and CDS)
1210 //
1211 // If UseCompressedClassPointers is disabled, only one address space will be
1212 // reserved:
1213 //
1214 // +-- Base address End
1215 // | |
1216 // v v
1217 // +-------------+--------------+
1218 // | static arc | [dyn. arch] |
1219 // +-------------+--------------+
1220 //
1221 // Base address: If use_archive_base_addr address is true, the Base address is
1222 // determined by the address stored in the static archive. If
1223 // use_archive_base_addr address is false, this base address is determined
1224 // by the platform.
1225 //
1226 // If UseCompressedClassPointers=1, the range encompassing both spaces will be
1227 // suitable to en/decode narrow Klass pointers: the base will be valid for
1228 // encoding, the range [Base, End) not surpass KlassEncodingMetaspaceMax.
1229 //
1230 // Return:
1231 //
1232 // - On success:
1233 // - total_space_rs will be reserved as whole for archive_space_rs and
1234 // class_space_rs if UseCompressedClassPointers is true.
1235 // On Windows, try reserve archive_space_rs and class_space_rs
1236 // separately first if use_archive_base_addr is true.
1237 // - archive_space_rs will be reserved and large enough to host static and
1238 // if needed dynamic archive: [Base, A).
1239 // archive_space_rs.base and size will be aligned to CDS reserve
1240 // granularity.
1241 // - class_space_rs: If UseCompressedClassPointers=1, class_space_rs will
1242 // be reserved. Its start address will be aligned to metaspace reserve
1243 // alignment, which may differ from CDS alignment. It will follow the cds
1244 // archive space, close enough such that narrow class pointer encoding
1245 // covers both spaces.
1246 // If UseCompressedClassPointers=0, class_space_rs remains unreserved.
1247 // - On error: null is returned and the spaces remain unreserved.
1248 char* MetaspaceShared::reserve_address_space_for_archives(FileMapInfo* static_mapinfo,
|
69 #include "oops/compressedKlass.hpp"
70 #include "oops/instanceMirrorKlass.hpp"
71 #include "oops/klass.inline.hpp"
72 #include "oops/objArrayOop.hpp"
73 #include "oops/oop.inline.hpp"
74 #include "oops/oopHandle.hpp"
75 #include "prims/jvmtiExport.hpp"
76 #include "runtime/arguments.hpp"
77 #include "runtime/globals.hpp"
78 #include "runtime/globals_extension.hpp"
79 #include "runtime/handles.inline.hpp"
80 #include "runtime/os.inline.hpp"
81 #include "runtime/safepointVerifiers.hpp"
82 #include "runtime/sharedRuntime.hpp"
83 #include "runtime/vmOperations.hpp"
84 #include "runtime/vmThread.hpp"
85 #include "sanitizers/leak.hpp"
86 #include "utilities/align.hpp"
87 #include "utilities/bitMap.inline.hpp"
88 #include "utilities/defaultStream.hpp"
89 #include "utilities/macros.hpp"
90 #include "utilities/ostream.hpp"
91 #include "utilities/resourceHash.hpp"
92
93 ReservedSpace MetaspaceShared::_symbol_rs;
94 VirtualSpace MetaspaceShared::_symbol_vs;
95 bool MetaspaceShared::_archive_loading_failed = false;
96 bool MetaspaceShared::_remapped_readwrite = false;
97 void* MetaspaceShared::_shared_metaspace_static_top = nullptr;
98 intx MetaspaceShared::_relocation_delta;
99 char* MetaspaceShared::_requested_base_address;
100 bool MetaspaceShared::_use_optimized_module_handling = true;
101
102 // The CDS archive is divided into the following regions:
103 // rw - read-write metadata
104 // ro - read-only metadata and read-only tables
105 // hp - heap region
106 // bm - bitmap for relocating the above 7 regions.
107 //
108 // The rw and ro regions are linearly allocated, in the order of rw->ro.
109 // These regions are aligned with MetaspaceShared::core_region_alignment().
1142 }
1143 } else if (static_result == MAP_ARCHIVE_OTHER_FAILURE) {
1144 result = MAP_ARCHIVE_OTHER_FAILURE;
1145 } else {
1146 result = MAP_ARCHIVE_MMAP_FAILURE;
1147 }
1148 }
1149
1150 if (result == MAP_ARCHIVE_SUCCESS) {
1151 SharedBaseAddress = (size_t)mapped_base_address;
1152 #ifdef _LP64
1153 if (Metaspace::using_class_space()) {
1154 // Set up ccs in metaspace.
1155 Metaspace::initialize_class_space(class_space_rs);
1156
1157 // Set up compressed Klass pointer encoding: the encoding range must
1158 // cover both archive and class space.
1159 address cds_base = (address)static_mapinfo->mapped_base();
1160 address ccs_end = (address)class_space_rs.end();
1161 assert(ccs_end > cds_base, "Sanity check");
1162 if (INCLUDE_CDS_JAVA_HEAP || UseCompactObjectHeaders) {
1163 // The CDS archive may contain narrow Klass IDs that were precomputed at archive generation time:
1164 // - every archived java object header (only if INCLUDE_CDS_JAVA_HEAP)
1165 // - every archived Klass' prototype (only if +UseCompactObjectHeaders)
1166 //
1167 // In order for those IDs to still be valid, we need to dictate base and shift: base should be the
1168 // mapping start, shift the shift used at archive generation time.
1169 address precomputed_narrow_klass_base = cds_base;
1170 const int precomputed_narrow_klass_shift = ArchiveBuilder::precomputed_narrow_klass_shift();
1171 CompressedKlassPointers::initialize_for_given_encoding(
1172 cds_base, ccs_end - cds_base, // Klass range
1173 precomputed_narrow_klass_base, precomputed_narrow_klass_shift // precomputed encoding, see ArchiveBuilder
1174 );
1175 } else {
1176 // Let JVM freely chose encoding base and shift
1177 CompressedKlassPointers::initialize (
1178 cds_base, ccs_end - cds_base // Klass range
1179 );
1180 }
1181 // map_or_load_heap_region() compares the current narrow oop and klass encodings
1182 // with the archived ones, so it must be done after all encodings are determined.
1183 static_mapinfo->map_or_load_heap_region();
1184 }
1185 #endif // _LP64
1186 log_info(cds)("initial optimized module handling: %s", CDSConfig::is_using_optimized_module_handling() ? "enabled" : "disabled");
1187 log_info(cds)("initial full module graph: %s", CDSConfig::is_using_full_module_graph() ? "enabled" : "disabled");
1188 } else {
1189 unmap_archive(static_mapinfo);
1190 unmap_archive(dynamic_mapinfo);
1191 release_reserved_spaces(total_space_rs, archive_space_rs, class_space_rs);
1192 }
1193
1194 return result;
1195 }
1196
1197
1198 // This will reserve two address spaces suitable to house Klass structures, one
1199 // for the cds archives (static archive and optionally dynamic archive) and
1200 // optionally one move for ccs.
1215 // (The gap may result from different alignment requirements between metaspace
1216 // and CDS)
1217 //
1218 // If UseCompressedClassPointers is disabled, only one address space will be
1219 // reserved:
1220 //
1221 // +-- Base address End
1222 // | |
1223 // v v
1224 // +-------------+--------------+
1225 // | static arc | [dyn. arch] |
1226 // +-------------+--------------+
1227 //
1228 // Base address: If use_archive_base_addr address is true, the Base address is
1229 // determined by the address stored in the static archive. If
1230 // use_archive_base_addr address is false, this base address is determined
1231 // by the platform.
1232 //
1233 // If UseCompressedClassPointers=1, the range encompassing both spaces will be
1234 // suitable to en/decode narrow Klass pointers: the base will be valid for
1235 // encoding, the range [Base, End) and not surpass the max. range for that encoding.
1236 //
1237 // Return:
1238 //
1239 // - On success:
1240 // - total_space_rs will be reserved as whole for archive_space_rs and
1241 // class_space_rs if UseCompressedClassPointers is true.
1242 // On Windows, try reserve archive_space_rs and class_space_rs
1243 // separately first if use_archive_base_addr is true.
1244 // - archive_space_rs will be reserved and large enough to host static and
1245 // if needed dynamic archive: [Base, A).
1246 // archive_space_rs.base and size will be aligned to CDS reserve
1247 // granularity.
1248 // - class_space_rs: If UseCompressedClassPointers=1, class_space_rs will
1249 // be reserved. Its start address will be aligned to metaspace reserve
1250 // alignment, which may differ from CDS alignment. It will follow the cds
1251 // archive space, close enough such that narrow class pointer encoding
1252 // covers both spaces.
1253 // If UseCompressedClassPointers=0, class_space_rs remains unreserved.
1254 // - On error: null is returned and the spaces remain unreserved.
1255 char* MetaspaceShared::reserve_address_space_for_archives(FileMapInfo* static_mapinfo,
|