212 |
212 |
213 char* MetaspaceShared::read_only_space_alloc(size_t num_bytes) { |
213 char* MetaspaceShared::read_only_space_alloc(size_t num_bytes) { |
214 return _ro_region.allocate(num_bytes); |
214 return _ro_region.allocate(num_bytes); |
215 } |
215 } |
216 |
216 |
217 void MetaspaceShared::initialize_shared_rs() { |
217 void MetaspaceShared::initialize_runtime_shared_and_meta_spaces() { |
|
218 assert(UseSharedSpaces, "Must be called when UseSharedSpaces is enabled"); |
|
219 |
|
220 // If using shared space, open the file that contains the shared space |
|
221 // and map in the memory before initializing the rest of metaspace (so |
|
222 // the addresses don't conflict) |
|
223 address cds_address = NULL; |
|
224 FileMapInfo* mapinfo = new FileMapInfo(); |
|
225 |
|
226 // Open the shared archive file, read and validate the header. If |
|
227 // initialization fails, shared spaces [UseSharedSpaces] are |
|
228 // disabled and the file is closed. |
|
229 // Map in spaces now also |
|
230 if (mapinfo->initialize() && map_shared_spaces(mapinfo)) { |
|
231 size_t cds_total = core_spaces_size(); |
|
232 cds_address = (address)mapinfo->header()->region_addr(0); |
|
233 #ifdef _LP64 |
|
234 if (Metaspace::using_class_space()) { |
|
235 char* cds_end = (char*)(cds_address + cds_total); |
|
236 cds_end = (char *)align_up(cds_end, Metaspace::reserve_alignment()); |
|
237 // If UseCompressedClassPointers is set then allocate the metaspace area |
|
238 // above the heap and above the CDS area (if it exists). |
|
239 Metaspace::allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address); |
|
240 // map_heap_regions() compares the current narrow oop and klass encodings |
|
241 // with the archived ones, so it must be done after all encodings are determined. |
|
242 mapinfo->map_heap_regions(); |
|
243 } |
|
244 #endif // _LP64 |
|
245 } else { |
|
246 assert(!mapinfo->is_open() && !UseSharedSpaces, |
|
247 "archive file not closed or shared spaces not disabled."); |
|
248 } |
|
249 } |
|
250 |
|
251 void MetaspaceShared::initialize_dumptime_shared_and_meta_spaces() { |
|
252 assert(DumpSharedSpaces, "should be called for dump time only"); |
218 const size_t reserve_alignment = Metaspace::reserve_alignment(); |
253 const size_t reserve_alignment = Metaspace::reserve_alignment(); |
219 bool large_pages = false; // No large pages when dumping the CDS archive. |
254 bool large_pages = false; // No large pages when dumping the CDS archive. |
220 char* shared_base = (char*)align_up((char*)SharedBaseAddress, reserve_alignment); |
255 char* shared_base = (char*)align_up((char*)SharedBaseAddress, reserve_alignment); |
221 |
256 |
222 #ifdef _LP64 |
257 #ifdef _LP64 |
223 // On 64-bit VM, the heap and class space layout will be the same as if |
258 // On 64-bit VM, the heap and class space layout will be the same as if |
224 // you're running in -Xshare:on mode: |
259 // you're running in -Xshare:on mode: |
225 // |
260 // |
226 // +-- SharedBaseAddress (default = 0x800000000) |
261 // +-- SharedBaseAddress (default = 0x800000000) |
227 // v |
262 // v |
228 // +-..---------+----+ ... +----+----+----+----+----+---------------+ |
263 // +-..---------+---------+ ... +----+----+----+----+----+---------------+ |
229 // | Heap | ST | | MC | RW | RO | MD | OD | class space | |
264 // | Heap | Archive | | MC | RW | RO | MD | OD | class space | |
230 // +-..---------+----+ ... +----+----+----+----+----+---------------+ |
265 // +-..---------+---------+ ... +----+----+----+----+----+---------------+ |
231 // |<--MaxHeapSize->| |<-- UnscaledClassSpaceMax = 4GB ------->| |
266 // |<-- MaxHeapSize -->| |<-- UnscaledClassSpaceMax = 4GB ------->| |
232 // |
267 // |
233 const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1); |
268 const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1); |
234 const size_t cds_total = align_down(UnscaledClassSpaceMax, reserve_alignment); |
269 const size_t cds_total = align_down(UnscaledClassSpaceMax, reserve_alignment); |
235 #else |
270 #else |
236 // We don't support archives larger than 256MB on 32-bit due to limited virtual address space. |
271 // We don't support archives larger than 256MB on 32-bit due to limited virtual address space. |
266 CompressedClassSpaceSize = align_down(tmp_class_space.size(), reserve_alignment); |
301 CompressedClassSpaceSize = align_down(tmp_class_space.size(), reserve_alignment); |
267 _shared_rs = _shared_rs.first_part(max_archive_size); |
302 _shared_rs = _shared_rs.first_part(max_archive_size); |
268 |
303 |
269 // Set up compress class pointers. |
304 // Set up compress class pointers. |
270 Universe::set_narrow_klass_base((address)_shared_rs.base()); |
305 Universe::set_narrow_klass_base((address)_shared_rs.base()); |
271 if (UseAOT || cds_total > UnscaledClassSpaceMax) { |
306 // Set narrow_klass_shift to be LogKlassAlignmentInBytes. This is consistent |
272 // AOT forces narrow_klass_shift=LogKlassAlignmentInBytes |
307 // with AOT. |
273 Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes); |
308 Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes); |
274 } else { |
|
275 Universe::set_narrow_klass_shift(0); |
|
276 } |
|
277 |
309 |
278 Metaspace::initialize_class_space(tmp_class_space); |
310 Metaspace::initialize_class_space(tmp_class_space); |
279 tty->print_cr("narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d", |
311 tty->print_cr("narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d", |
280 p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift()); |
312 p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift()); |
281 |
313 |