< prev index next >

src/hotspot/share/cds/metaspaceShared.cpp

Print this page

  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().

1148       }
1149     } else if (static_result == MAP_ARCHIVE_OTHER_FAILURE) {
1150       result = MAP_ARCHIVE_OTHER_FAILURE;
1151     } else {
1152       result = MAP_ARCHIVE_MMAP_FAILURE;
1153     }
1154   }
1155 
1156   if (result == MAP_ARCHIVE_SUCCESS) {
1157     SharedBaseAddress = (size_t)mapped_base_address;
1158 #ifdef _LP64
1159         if (Metaspace::using_class_space()) {
1160           // Set up ccs in metaspace.
1161           Metaspace::initialize_class_space(class_space_rs);
1162 
1163           // Set up compressed Klass pointer encoding: the encoding range must
1164           //  cover both archive and class space.
1165           address cds_base = (address)static_mapinfo->mapped_base();
1166           address ccs_end = (address)class_space_rs.end();
1167           assert(ccs_end > cds_base, "Sanity check");
1168 #if INCLUDE_CDS_JAVA_HEAP
1169           // We archived objects with pre-computed narrow Klass id. Set up encoding such that these Ids stay valid.
1170           address precomputed_narrow_klass_base = cds_base;
1171           const int precomputed_narrow_klass_shift = ArchiveHeapWriter::precomputed_narrow_klass_shift;
1172           CompressedKlassPointers::initialize_for_given_encoding(
1173             cds_base, ccs_end - cds_base, // Klass range
1174             precomputed_narrow_klass_base, precomputed_narrow_klass_shift // precomputed encoding, see ArchiveHeapWriter
1175             );
1176 #else
1177           CompressedKlassPointers::initialize (
1178             cds_base, ccs_end - cds_base // Klass range

1179             );
1180 #endif // INCLUDE_CDS_JAVA_HEAP





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) not surpass KlassEncodingMetaspaceMax.
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,

  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().

1149       }
1150     } else if (static_result == MAP_ARCHIVE_OTHER_FAILURE) {
1151       result = MAP_ARCHIVE_OTHER_FAILURE;
1152     } else {
1153       result = MAP_ARCHIVE_MMAP_FAILURE;
1154     }
1155   }
1156 
1157   if (result == MAP_ARCHIVE_SUCCESS) {
1158     SharedBaseAddress = (size_t)mapped_base_address;
1159 #ifdef _LP64
1160         if (Metaspace::using_class_space()) {
1161           // Set up ccs in metaspace.
1162           Metaspace::initialize_class_space(class_space_rs);
1163 
1164           // Set up compressed Klass pointer encoding: the encoding range must
1165           //  cover both archive and class space.
1166           address cds_base = (address)static_mapinfo->mapped_base();
1167           address ccs_end = (address)class_space_rs.end();
1168           assert(ccs_end > cds_base, "Sanity check");
1169           if (INCLUDE_CDS_JAVA_HEAP || UseCompactObjectHeaders) {
1170             // The CDS archive may contain narrow Klass IDs that were precomputed at archive generation time:
1171             // - every archived java object header (only if INCLUDE_CDS_JAVA_HEAP)
1172             // - every archived Klass' prototype   (only if +UseCompactObjectHeaders)
1173             //
1174             // In order for those IDs to still be valid, we need to dictate base and shift: base should be the
1175             // mapping start, shift the shift used at archive generation time.
1176             address precomputed_narrow_klass_base = cds_base;
1177             const int precomputed_narrow_klass_shift = ArchiveBuilder::precomputed_narrow_klass_shift();
1178             CompressedKlassPointers::initialize_for_given_encoding(
1179               cds_base, ccs_end - cds_base, // Klass range
1180               precomputed_narrow_klass_base, precomputed_narrow_klass_shift // precomputed encoding, see ArchiveBuilder
1181             );
1182           } else {
1183             // Let JVM freely chose encoding base and shift
1184             CompressedKlassPointers::initialize (
1185               cds_base, ccs_end - cds_base // Klass range
1186               );
1187           }
1188           // map_or_load_heap_region() compares the current narrow oop and klass encodings
1189           // with the archived ones, so it must be done after all encodings are determined.
1190           static_mapinfo->map_or_load_heap_region();
1191         }
1192 #endif // _LP64
1193     log_info(cds)("initial optimized module handling: %s", CDSConfig::is_using_optimized_module_handling() ? "enabled" : "disabled");
1194     log_info(cds)("initial full module graph: %s", CDSConfig::is_using_full_module_graph() ? "enabled" : "disabled");
1195   } else {
1196     unmap_archive(static_mapinfo);
1197     unmap_archive(dynamic_mapinfo);
1198     release_reserved_spaces(total_space_rs, archive_space_rs, class_space_rs);
1199   }
1200 
1201   return result;
1202 }
1203 
1204 
1205 // This will reserve two address spaces suitable to house Klass structures, one
1206 //  for the cds archives (static archive and optionally dynamic archive) and
1207 //  optionally one move for ccs.

1222 // (The gap may result from different alignment requirements between metaspace
1223 //  and CDS)
1224 //
1225 // If UseCompressedClassPointers is disabled, only one address space will be
1226 //  reserved:
1227 //
1228 // +-- Base address             End
1229 // |                            |
1230 // v                            v
1231 // +-------------+--------------+
1232 // | static arc  | [dyn. arch]  |
1233 // +-------------+--------------+
1234 //
1235 // Base address: If use_archive_base_addr address is true, the Base address is
1236 //  determined by the address stored in the static archive. If
1237 //  use_archive_base_addr address is false, this base address is determined
1238 //  by the platform.
1239 //
1240 // If UseCompressedClassPointers=1, the range encompassing both spaces will be
1241 //  suitable to en/decode narrow Klass pointers: the base will be valid for
1242 //  encoding, the range [Base, End) and not surpass the max. range for that encoding.
1243 //
1244 // Return:
1245 //
1246 // - On success:
1247 //    - total_space_rs will be reserved as whole for archive_space_rs and
1248 //      class_space_rs if UseCompressedClassPointers is true.
1249 //      On Windows, try reserve archive_space_rs and class_space_rs
1250 //      separately first if use_archive_base_addr is true.
1251 //    - archive_space_rs will be reserved and large enough to host static and
1252 //      if needed dynamic archive: [Base, A).
1253 //      archive_space_rs.base and size will be aligned to CDS reserve
1254 //      granularity.
1255 //    - class_space_rs: If UseCompressedClassPointers=1, class_space_rs will
1256 //      be reserved. Its start address will be aligned to metaspace reserve
1257 //      alignment, which may differ from CDS alignment. It will follow the cds
1258 //      archive space, close enough such that narrow class pointer encoding
1259 //      covers both spaces.
1260 //      If UseCompressedClassPointers=0, class_space_rs remains unreserved.
1261 // - On error: null is returned and the spaces remain unreserved.
1262 char* MetaspaceShared::reserve_address_space_for_archives(FileMapInfo* static_mapinfo,
< prev index next >