345 char *base = os::remap_memory(_fd, _full_path, si->_file_offset, 346 si->_base, size, false /* !read_only */, 347 si->_allow_exec); 348 close(); 349 if (base == NULL) { 350 fail_continue("Unable to remap shared readonly space (errno=%d).", errno); 351 return false; 352 } 353 if (base != si->_base) { 354 fail_continue("Unable to remap shared readonly space at required address."); 355 return false; 356 } 357 si->_read_only = false; 358 return true; 359 } 360 361 // Map the whole region at once, assumed to be allocated contiguously. 362 ReservedSpace FileMapInfo::reserve_shared_memory() { 363 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[0]; 364 char* requested_addr = si->_base; 365 size_t alignment = os::vm_allocation_granularity(); 366 367 size_t size = align_size_up(SharedReadOnlySize + SharedReadWriteSize + 368 SharedMiscDataSize + SharedMiscCodeSize, 369 alignment); 370 371 // Reserve the space first, then map otherwise map will go right over some 372 // other reserved memory (like the code cache). 373 ReservedSpace rs(size, alignment, false, requested_addr); 374 if (!rs.is_reserved()) { 375 fail_continue(err_msg("Unable to reserve shared space at required address " INTPTR_FORMAT, requested_addr)); 376 return rs; 377 } 378 // the reserved virtual memory is for mapping class data sharing archive 379 MemTracker::record_virtual_memory_type((address)rs.base(), mtClassShared); 380 381 return rs; 382 } 383 384 // Memory map a region in the address space. 385 static const char* shared_region_name[] = { "ReadOnly", "ReadWrite", "MiscData", "MiscCode"}; 386 387 char* FileMapInfo::map_region(int i) { 388 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i]; 389 size_t used = si->_used; 390 size_t alignment = os::vm_allocation_granularity(); 391 size_t size = align_size_up(used, alignment); 392 char *requested_addr = si->_base; 393 542 bool FileMapInfo::is_in_shared_space(const void* p) { 543 for (int i = 0; i < MetaspaceShared::n_regions; i++) { 544 if (p >= _header._space[i]._base && 545 p < _header._space[i]._base + _header._space[i]._used) { 546 return true; 547 } 548 } 549 550 return false; 551 } 552 553 void FileMapInfo::print_shared_spaces() { 554 gclog_or_tty->print_cr("Shared Spaces:"); 555 for (int i = 0; i < MetaspaceShared::n_regions; i++) { 556 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i]; 557 gclog_or_tty->print(" %s " INTPTR_FORMAT "-" INTPTR_FORMAT, 558 shared_region_name[i], 559 si->_base, si->_base + si->_used); 560 } 561 } | 345 char *base = os::remap_memory(_fd, _full_path, si->_file_offset, 346 si->_base, size, false /* !read_only */, 347 si->_allow_exec); 348 close(); 349 if (base == NULL) { 350 fail_continue("Unable to remap shared readonly space (errno=%d).", errno); 351 return false; 352 } 353 if (base != si->_base) { 354 fail_continue("Unable to remap shared readonly space at required address."); 355 return false; 356 } 357 si->_read_only = false; 358 return true; 359 } 360 361 // Map the whole region at once, assumed to be allocated contiguously. 362 ReservedSpace FileMapInfo::reserve_shared_memory() { 363 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[0]; 364 char* requested_addr = si->_base; 365 366 size_t size = FileMapInfo::shared_spaces_size(); 367 368 // Reserve the space first, then map otherwise map will go right over some 369 // other reserved memory (like the code cache). 370 ReservedSpace rs(size, os::vm_allocation_granularity(), false, requested_addr); 371 if (!rs.is_reserved()) { 372 fail_continue(err_msg("Unable to reserve shared space at required address " INTPTR_FORMAT, requested_addr)); 373 return rs; 374 } 375 // the reserved virtual memory is for mapping class data sharing archive 376 MemTracker::record_virtual_memory_type((address)rs.base(), mtClassShared); 377 378 return rs; 379 } 380 381 // Memory map a region in the address space. 382 static const char* shared_region_name[] = { "ReadOnly", "ReadWrite", "MiscData", "MiscCode"}; 383 384 char* FileMapInfo::map_region(int i) { 385 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i]; 386 size_t used = si->_used; 387 size_t alignment = os::vm_allocation_granularity(); 388 size_t size = align_size_up(used, alignment); 389 char *requested_addr = si->_base; 390 539 bool FileMapInfo::is_in_shared_space(const void* p) { 540 for (int i = 0; i < MetaspaceShared::n_regions; i++) { 541 if (p >= _header._space[i]._base && 542 p < _header._space[i]._base + _header._space[i]._used) { 543 return true; 544 } 545 } 546 547 return false; 548 } 549 550 void FileMapInfo::print_shared_spaces() { 551 gclog_or_tty->print_cr("Shared Spaces:"); 552 for (int i = 0; i < MetaspaceShared::n_regions; i++) { 553 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i]; 554 gclog_or_tty->print(" %s " INTPTR_FORMAT "-" INTPTR_FORMAT, 555 shared_region_name[i], 556 si->_base, si->_base + si->_used); 557 } 558 } 559 560 // Unmap mapped regions of shared space. 561 void FileMapInfo::stop_sharing_and_unmap(const char* msg) { 562 FileMapInfo *map_info = FileMapInfo::current_info(); 563 if (map_info) { 564 map_info->fail_continue(msg); 565 for (int i = 0; i < MetaspaceShared::n_regions; i++) { 566 if (map_info->_header._space[i]._base != NULL) { 567 map_info->unmap_region(i); 568 map_info->_header._space[i]._base = NULL; 569 } 570 } 571 } else if (DumpSharedSpaces) { 572 fail_stop(msg, NULL); 573 } 574 } |