< prev index next >

src/share/vm/memory/filemap.cpp

Print this page




 690         return false;
 691       }
 692 
 693       // allocate from java heap
 694       if (!G1CollectedHeap::heap()->alloc_archive_regions(string_ranges, num_ranges)) {
 695         fail_continue("Unable to allocate shared string space: range is "
 696                       "already in use.");
 697         return false;
 698       }
 699 
 700       // Map the string data. No need to call MemTracker::record_virtual_memory_type()
 701       // for mapped string regions as they are part of the reserved java heap, which
 702       // is already recorded.
 703       for (int i = 0; i < num_ranges; i++) {
 704         si = &_header->_space[MetaspaceShared::first_string + i];
 705         char* addr = (char*)string_ranges[i].start();
 706         char* base = os::map_memory(_fd, _full_path, si->_file_offset,
 707                                     addr, string_ranges[i].byte_size(), si->_read_only,
 708                                     si->_allow_exec);
 709         if (base == NULL || base != addr) {


 710           fail_continue("Unable to map shared string space at required address.");
 711           return false;
 712         }
 713       }
 714 
 715       if (!verify_string_regions()) {


 716         fail_continue("Shared string regions are corrupt");
 717         return false;
 718       }
 719 
 720       // the shared string data is mapped successfully
 721       return true;
 722     }
 723   } else {
 724     if (PrintSharedSpaces && _header->_space[MetaspaceShared::first_string]._used > 0) {
 725       tty->print_cr("Shared string data from the CDS archive is being ignored. UseG1GC, "
 726                     "UseCompressedOops and UseCompressedClassPointers are required.");
 727     }
 728   }
 729 
 730   // if we get here, the shared string data is not mapped
 731   assert(string_ranges == NULL && num_ranges == 0, "sanity");
 732   StringTable::ignore_shared_strings(true);
 733 #endif
 734   return true;
 735 }
 736 
 737 bool FileMapInfo::verify_string_regions() {
 738   for (int i = MetaspaceShared::first_string;
 739            i < MetaspaceShared::first_string + MetaspaceShared::max_strings; i++) {
 740     if (!verify_region_checksum(i)) {
 741       return false;
 742     }
 743   }
 744   return true;
 745 }
 746 
 747 void FileMapInfo::fixup_string_regions() {

 748   // If any string regions were found, call the fill routine to make them parseable.
 749   // Note that string_ranges may be non-NULL even if no ranges were found.
 750   if (num_ranges != 0) {
 751     assert(string_ranges != NULL, "Null string_ranges array with non-zero count");
 752     G1CollectedHeap::heap()->fill_archive_regions(string_ranges, num_ranges);
 753   }

 754 }
 755 
 756 bool FileMapInfo::verify_region_checksum(int i) {
 757   if (!VerifySharedSpaces) {
 758     return true;
 759   }
 760 
 761   size_t sz = _header->_space[i]._used;
 762 
 763   if (sz == 0) {
 764     return true; // no data
 765   }
 766   if (MetaspaceShared::is_string_region(i) && StringTable::shared_string_ignored()) {
 767     return true; // shared string data are not mapped
 768   }
 769   const char* buf = _header->region_addr(i);
 770   int crc = ClassLoader::crc32(0, buf, (jint)sz);
 771   if (crc != _header->_space[i]._crc) {
 772     fail_continue("Checksum verification failed.");
 773     return false;


 776 }
 777 
 778 // Unmap a memory region in the address space.
 779 
 780 void FileMapInfo::unmap_region(int i) {
 781   assert(!MetaspaceShared::is_string_region(i), "sanity");
 782   struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
 783   size_t used = si->_used;
 784   size_t size = align_size_up(used, os::vm_allocation_granularity());
 785 
 786   if (used == 0) {
 787     return;
 788   }
 789 
 790   char* addr = _header->region_addr(i);
 791   if (!os::unmap_memory(addr, size)) {
 792     fail_stop("Unable to unmap shared space.");
 793   }
 794 }
 795 
 796 void FileMapInfo::unmap_string_regions() {
 797   for (int i = MetaspaceShared::first_string;
 798            i < MetaspaceShared::first_string + MetaspaceShared::max_strings; i++) {
 799     struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
 800     size_t used = si->_used;
 801     if (used > 0) {
 802       size_t size = align_size_up(used, os::vm_allocation_granularity());
 803       char* addr = (char*)((void*)oopDesc::decode_heap_oop_not_null(
 804                                              (narrowOop)si->_addr._offset));
 805       if (!os::unmap_memory(addr, size)) {
 806         fail_stop("Unable to unmap shared space.");
 807       }
 808     }
 809   }

 810 }
 811 
 812 void FileMapInfo::assert_mark(bool check) {
 813   if (!check) {
 814     fail_stop("Mark mismatch while restoring from shared file.");
 815   }
 816 }
 817 
 818 
 819 FileMapInfo* FileMapInfo::_current_info = NULL;
 820 SharedClassPathEntry* FileMapInfo::_classpath_entry_table = NULL;
 821 int FileMapInfo::_classpath_entry_table_size = 0;
 822 size_t FileMapInfo::_classpath_entry_size = 0x1234baad;
 823 bool FileMapInfo::_validating_classpath_entry_table = false;
 824 
 825 // Open the shared archive file, read and validate the header
 826 // information (version, boot classpath, etc.).  If initialization
 827 // fails, shared spaces are disabled and the file is closed. [See
 828 // fail_continue.]
 829 //


 950     struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
 951     char *base = _header->region_addr(i);
 952     gclog_or_tty->print("  %s " INTPTR_FORMAT "-" INTPTR_FORMAT,
 953                         shared_region_name[i],
 954                         base, base + si->_used);
 955   }
 956 }
 957 
 958 // Unmap mapped regions of shared space.
 959 void FileMapInfo::stop_sharing_and_unmap(const char* msg) {
 960   FileMapInfo *map_info = FileMapInfo::current_info();
 961   if (map_info) {
 962     map_info->fail_continue("%s", msg);
 963     for (int i = 0; i < MetaspaceShared::num_non_strings; i++) {
 964       char *addr = map_info->_header->region_addr(i);
 965       if (addr != NULL && !MetaspaceShared::is_string_region(i)) {
 966         map_info->unmap_region(i);
 967         map_info->_header->_space[i]._addr._base = NULL;
 968       }
 969     }
 970     map_info->unmap_string_regions();


 971   } else if (DumpSharedSpaces) {
 972     fail_stop("%s", msg);
 973   }
 974 }


 690         return false;
 691       }
 692 
 693       // allocate from java heap
 694       if (!G1CollectedHeap::heap()->alloc_archive_regions(string_ranges, num_ranges)) {
 695         fail_continue("Unable to allocate shared string space: range is "
 696                       "already in use.");
 697         return false;
 698       }
 699 
 700       // Map the string data. No need to call MemTracker::record_virtual_memory_type()
 701       // for mapped string regions as they are part of the reserved java heap, which
 702       // is already recorded.
 703       for (int i = 0; i < num_ranges; i++) {
 704         si = &_header->_space[MetaspaceShared::first_string + i];
 705         char* addr = (char*)string_ranges[i].start();
 706         char* base = os::map_memory(_fd, _full_path, si->_file_offset,
 707                                     addr, string_ranges[i].byte_size(), si->_read_only,
 708                                     si->_allow_exec);
 709         if (base == NULL || base != addr) {
 710           // dealloc the string regions from java heap
 711           dealloc_string_regions();
 712           fail_continue("Unable to map shared string space at required address.");
 713           return false;
 714         }
 715       }
 716 
 717       if (!verify_string_regions()) {
 718         // dealloc the string regions from java heap
 719         dealloc_string_regions(); 
 720         fail_continue("Shared string regions are corrupt");
 721         return false;
 722       }
 723 
 724       // the shared string data is mapped successfully
 725       return true;
 726     }
 727   } else {
 728     if (PrintSharedSpaces && _header->_space[MetaspaceShared::first_string]._used > 0) {
 729       tty->print_cr("Shared string data from the CDS archive is being ignored. UseG1GC, "
 730                     "UseCompressedOops and UseCompressedClassPointers are required.");
 731     }
 732   }
 733 
 734   // if we get here, the shared string data is not mapped
 735   assert(string_ranges == NULL && num_ranges == 0, "sanity");
 736   StringTable::ignore_shared_strings(true);
 737 #endif
 738   return true;
 739 }
 740 
 741 bool FileMapInfo::verify_string_regions() {
 742   for (int i = MetaspaceShared::first_string;
 743            i < MetaspaceShared::first_string + MetaspaceShared::max_strings; i++) {
 744     if (!verify_region_checksum(i)) {
 745       return false;
 746     }
 747   }
 748   return true;
 749 }
 750 
 751 void FileMapInfo::fixup_string_regions() {
 752 #if INCLUDE_ALL_GCS
 753   // If any string regions were found, call the fill routine to make them parseable.
 754   // Note that string_ranges may be non-NULL even if no ranges were found.
 755   if (num_ranges != 0) {
 756     assert(string_ranges != NULL, "Null string_ranges array with non-zero count");
 757     G1CollectedHeap::heap()->fill_archive_regions(string_ranges, num_ranges);
 758   }
 759 #endif
 760 }
 761 
 762 bool FileMapInfo::verify_region_checksum(int i) {
 763   if (!VerifySharedSpaces) {
 764     return true;
 765   }
 766 
 767   size_t sz = _header->_space[i]._used;
 768 
 769   if (sz == 0) {
 770     return true; // no data
 771   }
 772   if (MetaspaceShared::is_string_region(i) && StringTable::shared_string_ignored()) {
 773     return true; // shared string data are not mapped
 774   }
 775   const char* buf = _header->region_addr(i);
 776   int crc = ClassLoader::crc32(0, buf, (jint)sz);
 777   if (crc != _header->_space[i]._crc) {
 778     fail_continue("Checksum verification failed.");
 779     return false;


 782 }
 783 
 784 // Unmap a memory region in the address space.
 785 
 786 void FileMapInfo::unmap_region(int i) {
 787   assert(!MetaspaceShared::is_string_region(i), "sanity");
 788   struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
 789   size_t used = si->_used;
 790   size_t size = align_size_up(used, os::vm_allocation_granularity());
 791 
 792   if (used == 0) {
 793     return;
 794   }
 795 
 796   char* addr = _header->region_addr(i);
 797   if (!os::unmap_memory(addr, size)) {
 798     fail_stop("Unable to unmap shared space.");
 799   }
 800 }
 801 
 802 // dealloc the archived string region from java heap
 803 void FileMapInfo::dealloc_string_regions() {
 804 #if INCLUDE_ALL_GCS
 805   if (num_ranges > 0) {
 806     assert(string_ranges != NULL, "Null string_ranges array with non-zero count");
 807     G1CollectedHeap::heap()->dealloc_archive_regions(string_ranges, num_ranges);







 808   }
 809 #endif
 810 }
 811 
 812 void FileMapInfo::assert_mark(bool check) {
 813   if (!check) {
 814     fail_stop("Mark mismatch while restoring from shared file.");
 815   }
 816 }
 817 
 818 
 819 FileMapInfo* FileMapInfo::_current_info = NULL;
 820 SharedClassPathEntry* FileMapInfo::_classpath_entry_table = NULL;
 821 int FileMapInfo::_classpath_entry_table_size = 0;
 822 size_t FileMapInfo::_classpath_entry_size = 0x1234baad;
 823 bool FileMapInfo::_validating_classpath_entry_table = false;
 824 
 825 // Open the shared archive file, read and validate the header
 826 // information (version, boot classpath, etc.).  If initialization
 827 // fails, shared spaces are disabled and the file is closed. [See
 828 // fail_continue.]
 829 //


 950     struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
 951     char *base = _header->region_addr(i);
 952     gclog_or_tty->print("  %s " INTPTR_FORMAT "-" INTPTR_FORMAT,
 953                         shared_region_name[i],
 954                         base, base + si->_used);
 955   }
 956 }
 957 
 958 // Unmap mapped regions of shared space.
 959 void FileMapInfo::stop_sharing_and_unmap(const char* msg) {
 960   FileMapInfo *map_info = FileMapInfo::current_info();
 961   if (map_info) {
 962     map_info->fail_continue("%s", msg);
 963     for (int i = 0; i < MetaspaceShared::num_non_strings; i++) {
 964       char *addr = map_info->_header->region_addr(i);
 965       if (addr != NULL && !MetaspaceShared::is_string_region(i)) {
 966         map_info->unmap_region(i);
 967         map_info->_header->_space[i]._addr._base = NULL;
 968       }
 969     }
 970     // Dealloc the string regions only without unmapping. The string regions are part
 971     // of the java heap. Unmapping of the heap regions are managed by GC.
 972     map_info->dealloc_string_regions();
 973   } else if (DumpSharedSpaces) {
 974     fail_stop("%s", msg);
 975   }
 976 }
< prev index next >