< prev index next >

src/hotspot/share/memory/filemap.cpp

Print this page


 642   size_t size = FileMapInfo::core_spaces_size();
 643 
 644   // Reserve the space first, then map otherwise map will go right over some
 645   // other reserved memory (like the code cache).
 646   ReservedSpace rs(size, os::vm_allocation_granularity(), false, requested_addr);
 647   if (!rs.is_reserved()) {
 648     fail_continue("Unable to reserve shared space at required address "
 649                   INTPTR_FORMAT, p2i(requested_addr));
 650     return rs;
 651   }
 652   // the reserved virtual memory is for mapping class data sharing archive
 653   MemTracker::record_virtual_memory_type((address)rs.base(), mtClassShared);
 654 
 655   return rs;
 656 }
 657 
 658 // Memory map a region in the address space.
 659 static const char* shared_region_name[] = { "MiscData", "ReadWrite", "ReadOnly", "MiscCode", "OptionalData",
 660                                             "String1", "String2", "OpenArchive1", "OpenArchive2" };
 661 
 662 char* FileMapInfo::map_region(int i) {
 663   assert(!MetaspaceShared::is_heap_region(i), "sanity");
 664   struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
 665   size_t used = si->_used;
 666   size_t alignment = os::vm_allocation_granularity();
 667   size_t size = align_up(used, alignment);
 668   char *requested_addr = _header->region_addr(i);
 669 
 670   // If a tool agent is in use (debugging enabled), we must map the address space RW
 671   if (JvmtiExport::can_modify_any_class() || JvmtiExport::can_walk_any_space()) {
 672     si->_read_only = false;
 673   }
 674 
 675   // map the contents of the CDS archive in this memory
 676   char *base = os::map_memory(_fd, _full_path, si->_file_offset,
 677                               requested_addr, size, si->_read_only,
 678                               si->_allow_exec);
 679   if (base == NULL || base != requested_addr) {
 680     fail_continue("Unable to map %s shared space at required address.", shared_region_name[i]);
 681     return NULL;
 682   }
 683 #ifdef _WINDOWS
 684   // This call is Windows-only because the memory_type gets recorded for the other platforms
 685   // in method FileMapInfo::reserve_shared_memory(), which is not called on Windows.
 686   MemTracker::record_virtual_memory_type((address)base, mtClassShared);
 687 #endif
 688 






 689   return base;
 690 }
 691 
 692 static MemRegion *string_ranges = NULL;
 693 static MemRegion *open_archive_heap_ranges = NULL;
 694 static int num_string_ranges = 0;
 695 static int num_open_archive_heap_ranges = 0;
 696 
 697 #if INCLUDE_CDS_JAVA_HEAP
 698 //
 699 // Map the shared string objects and open archive heap objects to the runtime
 700 // java heap.
 701 //
 702 // The shared strings are mapped near the runtime java heap top. The
 703 // mapped strings contain no out-going references to any other java heap
 704 // regions. GC does not write into the mapped shared strings.
 705 //
 706 // The open archive heap objects are mapped below the shared strings in
 707 // the runtime java heap. The mapped open archive heap data only contain
 708 // references to the shared strings and open archive objects initially.


1021   return true;
1022 }
1023 
1024 bool FileMapInfo::validate_header() {
1025   bool status = _header->validate();
1026 
1027   if (status) {
1028     if (!ClassLoader::check_shared_paths_misc_info(_paths_misc_info, _header->_paths_misc_info_size)) {
1029       if (!PrintSharedArchiveAndExit) {
1030         fail_continue("shared class paths mismatch (hint: enable -Xlog:class+path=info to diagnose the failure)");
1031         status = false;
1032       }
1033     }
1034   }
1035 
1036   if (_paths_misc_info != NULL) {
1037     FREE_C_HEAP_ARRAY(char, _paths_misc_info);
1038     _paths_misc_info = NULL;
1039   }
1040   return status;
1041 }
1042 
1043 // The following method is provided to see whether a given pointer
1044 // falls in the mapped shared metadata space.
1045 // Param:
1046 // p, The given pointer
1047 // Return:
1048 // True if the p is within the mapped shared space, otherwise, false.
1049 bool FileMapInfo::is_in_shared_space(const void* p) {
1050   for (int i = 0; i < MetaspaceShared::num_non_heap_spaces; i++) {
1051     char *base;
1052     if (_header->_space[i]._used == 0) {
1053       continue;
1054     }
1055     base = _header->region_addr(i);
1056     if (p >= base && p < base + _header->_space[i]._used) {
1057       return true;
1058     }
1059   }
1060 
1061   return false;
1062 }
1063 
1064 // Check if a given address is within one of the shared regions
1065 bool FileMapInfo::is_in_shared_region(const void* p, int idx) {
1066   assert(idx == MetaspaceShared::ro ||
1067          idx == MetaspaceShared::rw ||
1068          idx == MetaspaceShared::mc ||
1069          idx == MetaspaceShared::md, "invalid region index");
1070   char* base = _header->region_addr(idx);
1071   if (p >= base && p < base + _header->_space[idx]._used) {
1072     return true;
1073   }
1074   return false;
1075 }
1076 
1077 void FileMapInfo::print_shared_spaces() {
1078   tty->print_cr("Shared Spaces:");
1079   for (int i = 0; i < MetaspaceShared::n_regions; i++) {
1080     struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
1081     char *base = _header->region_addr(i);




 642   size_t size = FileMapInfo::core_spaces_size();
 643 
 644   // Reserve the space first, then map otherwise map will go right over some
 645   // other reserved memory (like the code cache).
 646   ReservedSpace rs(size, os::vm_allocation_granularity(), false, requested_addr);
 647   if (!rs.is_reserved()) {
 648     fail_continue("Unable to reserve shared space at required address "
 649                   INTPTR_FORMAT, p2i(requested_addr));
 650     return rs;
 651   }
 652   // the reserved virtual memory is for mapping class data sharing archive
 653   MemTracker::record_virtual_memory_type((address)rs.base(), mtClassShared);
 654 
 655   return rs;
 656 }
 657 
 658 // Memory map a region in the address space.
 659 static const char* shared_region_name[] = { "MiscData", "ReadWrite", "ReadOnly", "MiscCode", "OptionalData",
 660                                             "String1", "String2", "OpenArchive1", "OpenArchive2" };
 661 
 662 char* FileMapInfo::map_region(int i, char** top_ret) {
 663   assert(!MetaspaceShared::is_heap_region(i), "sanity");
 664   struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
 665   size_t used = si->_used;
 666   size_t alignment = os::vm_allocation_granularity();
 667   size_t size = align_up(used, alignment);
 668   char *requested_addr = _header->region_addr(i);
 669 
 670   // If a tool agent is in use (debugging enabled), we must map the address space RW
 671   if (JvmtiExport::can_modify_any_class() || JvmtiExport::can_walk_any_space()) {
 672     si->_read_only = false;
 673   }
 674 
 675   // map the contents of the CDS archive in this memory
 676   char *base = os::map_memory(_fd, _full_path, si->_file_offset,
 677                               requested_addr, size, si->_read_only,
 678                               si->_allow_exec);
 679   if (base == NULL || base != requested_addr) {
 680     fail_continue("Unable to map %s shared space at required address.", shared_region_name[i]);
 681     return NULL;
 682   }
 683 #ifdef _WINDOWS
 684   // This call is Windows-only because the memory_type gets recorded for the other platforms
 685   // in method FileMapInfo::reserve_shared_memory(), which is not called on Windows.
 686   MemTracker::record_virtual_memory_type((address)base, mtClassShared);
 687 #endif
 688 
 689 
 690   if (!verify_region_checksum(i)) {
 691     return NULL;
 692   }
 693 
 694   *top_ret = base + size;
 695   return base;
 696 }
 697 
 698 static MemRegion *string_ranges = NULL;
 699 static MemRegion *open_archive_heap_ranges = NULL;
 700 static int num_string_ranges = 0;
 701 static int num_open_archive_heap_ranges = 0;
 702 
 703 #if INCLUDE_CDS_JAVA_HEAP
 704 //
 705 // Map the shared string objects and open archive heap objects to the runtime
 706 // java heap.
 707 //
 708 // The shared strings are mapped near the runtime java heap top. The
 709 // mapped strings contain no out-going references to any other java heap
 710 // regions. GC does not write into the mapped shared strings.
 711 //
 712 // The open archive heap objects are mapped below the shared strings in
 713 // the runtime java heap. The mapped open archive heap data only contain
 714 // references to the shared strings and open archive objects initially.


1027   return true;
1028 }
1029 
1030 bool FileMapInfo::validate_header() {
1031   bool status = _header->validate();
1032 
1033   if (status) {
1034     if (!ClassLoader::check_shared_paths_misc_info(_paths_misc_info, _header->_paths_misc_info_size)) {
1035       if (!PrintSharedArchiveAndExit) {
1036         fail_continue("shared class paths mismatch (hint: enable -Xlog:class+path=info to diagnose the failure)");
1037         status = false;
1038       }
1039     }
1040   }
1041 
1042   if (_paths_misc_info != NULL) {
1043     FREE_C_HEAP_ARRAY(char, _paths_misc_info);
1044     _paths_misc_info = NULL;
1045   }
1046   return status;





















1047 }
1048 
1049 // Check if a given address is within one of the shared regions
1050 bool FileMapInfo::is_in_shared_region(const void* p, int idx) {
1051   assert(idx == MetaspaceShared::ro ||
1052          idx == MetaspaceShared::rw ||
1053          idx == MetaspaceShared::mc ||
1054          idx == MetaspaceShared::md, "invalid region index");
1055   char* base = _header->region_addr(idx);
1056   if (p >= base && p < base + _header->_space[idx]._used) {
1057     return true;
1058   }
1059   return false;
1060 }
1061 
1062 void FileMapInfo::print_shared_spaces() {
1063   tty->print_cr("Shared Spaces:");
1064   for (int i = 0; i < MetaspaceShared::n_regions; i++) {
1065     struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
1066     char *base = _header->region_addr(i);


< prev index next >