< prev index next >

src/hotspot/share/memory/filemap.cpp

Print this page




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "classfile/classLoader.inline.hpp"
  28 #include "classfile/compactHashtable.inline.hpp"
  29 #include "classfile/sharedClassUtil.hpp"
  30 #include "classfile/stringTable.hpp"
  31 #include "classfile/symbolTable.hpp"
  32 #include "classfile/systemDictionaryShared.hpp"
  33 #include "classfile/altHashing.hpp"
  34 #if INCLUDE_ALL_GCS
  35 #include "gc/g1/g1CollectedHeap.hpp"
  36 #endif
  37 #include "logging/log.hpp"
  38 #include "logging/logStream.hpp"
  39 #include "logging/logMessage.hpp"
  40 #include "memory/filemap.hpp"
  41 #include "memory/metadataFactory.hpp"
  42 #include "memory/metaspaceClosure.hpp"
  43 #include "memory/metaspaceShared.hpp"
  44 #include "memory/oopFactory.hpp"

  45 #include "oops/objArrayOop.hpp"
  46 #include "prims/jvmtiExport.hpp"
  47 #include "runtime/arguments.hpp"
  48 #include "runtime/java.hpp"
  49 #include "runtime/os.hpp"
  50 #include "runtime/vm_version.hpp"
  51 #include "services/memTracker.hpp"
  52 #include "utilities/align.hpp"
  53 #include "utilities/defaultStream.hpp"



  54 
  55 # include <sys/stat.h>
  56 # include <errno.h>
  57 
  58 #ifndef O_BINARY       // if defined (Win32) use binary files.
  59 #define O_BINARY 0     // otherwise do nothing.
  60 #endif
  61 
  62 extern address JVM_FunctionAtStart();
  63 extern address JVM_FunctionAtEnd();
  64 
  65 // Complain and stop. All error conditions occurring during the writing of
  66 // an archive file should stop the process.  Unrecoverable errors during
  67 // the reading of the archive file should stop the process.
  68 
  69 static void fail(const char *msg, va_list ap) {
  70   // This occurs very early during initialization: tty is not initialized.
  71   jio_fprintf(defaultStream::error_stream(),
  72               "An error has occurred while processing the"
  73               " shared archive file.\n");


 451 }
 452 
 453 
 454 // Dump region to file.
 455 
 456 void FileMapInfo::write_region(int region, char* base, size_t size,
 457                                bool read_only, bool allow_exec) {
 458   struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[region];
 459 
 460   if (_file_open) {
 461     guarantee(si->_file_offset == _file_offset, "file offset mismatch.");
 462     log_info(cds)("Shared file region %d: " SIZE_FORMAT_HEX_W(08)
 463                   " bytes, addr " INTPTR_FORMAT " file offset " SIZE_FORMAT_HEX_W(08),
 464                   region, size, p2i(base), _file_offset);
 465   } else {
 466     si->_file_offset = _file_offset;
 467   }
 468   if (MetaspaceShared::is_heap_region(region)) {
 469     assert((base - (char*)Universe::narrow_oop_base()) % HeapWordSize == 0, "Sanity");
 470     if (base != NULL) {
 471       si->_addr._offset = (intx)oopDesc::encode_heap_oop_not_null((oop)base);
 472     } else {
 473       si->_addr._offset = 0;
 474     }
 475   } else {
 476     si->_addr._base = base;
 477   }
 478   si->_used = size;
 479   si->_read_only = read_only;
 480   si->_allow_exec = allow_exec;
 481   si->_crc = ClassLoader::crc32(0, base, (jint)size);
 482   write_bytes_aligned(base, (int)size);
 483 }
 484 
 485 // Write out the given archive heap memory regions.  GC code combines multiple
 486 // consecutive archive GC regions into one MemRegion whenever possible and
 487 // produces the 'heap_mem' array.
 488 //
 489 // If the archive heap memory size is smaller than a single dump time GC region
 490 // size, there is only one MemRegion in the array.
 491 //


 766     assert(string_ranges == NULL && num_string_ranges == 0, "sanity");
 767   }
 768 
 769   if (!MetaspaceShared::open_archive_heap_region_mapped()) {
 770     assert(open_archive_heap_ranges == NULL && num_open_archive_heap_ranges == 0, "sanity");
 771   }
 772 }
 773 
 774 bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first,
 775                                 int max, int* num, bool is_open_archive) {
 776   MemRegion * regions = new MemRegion[max];
 777   struct FileMapInfo::FileMapHeader::space_info* si;
 778   int region_num = 0;
 779 
 780   for (int i = first;
 781            i < first + max; i++) {
 782     si = &_header->_space[i];
 783     size_t used = si->_used;
 784     if (used > 0) {
 785       size_t size = used;
 786       char* requested_addr = (char*)((void*)oopDesc::decode_heap_oop_not_null(
 787                                             (narrowOop)si->_addr._offset));
 788       regions[region_num] = MemRegion((HeapWord*)requested_addr, size / HeapWordSize);
 789       region_num ++;
 790     }
 791   }
 792 
 793   if (region_num == 0) {
 794     return false; // no archived java heap data
 795   }
 796 
 797   // Check that ranges are within the java heap
 798   if (!G1CollectedHeap::heap()->check_archive_addresses(regions, region_num)) {
 799     log_info(cds)("UseSharedSpaces: Unable to allocate region, "
 800                   "range is not within java heap.");
 801     return false;
 802   }
 803 
 804   // allocate from java heap
 805   if (!G1CollectedHeap::heap()->alloc_archive_regions(
 806              regions, region_num, is_open_archive)) {


 947 // [1] validate_header() - done here. This checks the header, including _paths_misc_info.
 948 // [2] validate_classpath_entry_table - this is done later, because the table is in the RW
 949 //     region of the archive, which is not mapped yet.
 950 bool FileMapInfo::initialize() {
 951   assert(UseSharedSpaces, "UseSharedSpaces expected.");
 952 
 953   if (!open_for_read()) {
 954     return false;
 955   }
 956 
 957   init_from_file(_fd);
 958   if (!validate_header()) {
 959     return false;
 960   }
 961   return true;
 962 }
 963 
 964 char* FileMapInfo::FileMapHeader::region_addr(int idx) {
 965   if (MetaspaceShared::is_heap_region(idx)) {
 966     return _space[idx]._used > 0 ?
 967              (char*)((void*)oopDesc::decode_heap_oop_not_null((narrowOop)_space[idx]._addr._offset)) : NULL;
 968   } else {
 969     return _space[idx]._addr._base;
 970   }
 971 }
 972 
 973 int FileMapInfo::FileMapHeader::compute_crc() {
 974   char* header = data();
 975   // start computing from the field after _crc
 976   char* buf = (char*)&_crc + sizeof(int);
 977   size_t sz = data_size() - (buf - header);
 978   int crc = ClassLoader::crc32(0, buf, (jint)sz);
 979   return crc;
 980 }
 981 
 982 bool FileMapInfo::FileMapHeader::validate() {
 983   if (VerifySharedSpaces && compute_crc() != _crc) {
 984     fail_continue("Header checksum verification failed.");
 985     return false;
 986   }
 987 




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "classfile/classLoader.inline.hpp"
  28 #include "classfile/compactHashtable.inline.hpp"
  29 #include "classfile/sharedClassUtil.hpp"
  30 #include "classfile/stringTable.hpp"
  31 #include "classfile/symbolTable.hpp"
  32 #include "classfile/systemDictionaryShared.hpp"
  33 #include "classfile/altHashing.hpp"



  34 #include "logging/log.hpp"
  35 #include "logging/logStream.hpp"
  36 #include "logging/logMessage.hpp"
  37 #include "memory/filemap.hpp"
  38 #include "memory/metadataFactory.hpp"
  39 #include "memory/metaspaceClosure.hpp"
  40 #include "memory/metaspaceShared.hpp"
  41 #include "memory/oopFactory.hpp"
  42 #include "oops/compressedOops.inline.hpp"
  43 #include "oops/objArrayOop.hpp"
  44 #include "prims/jvmtiExport.hpp"
  45 #include "runtime/arguments.hpp"
  46 #include "runtime/java.hpp"
  47 #include "runtime/os.hpp"
  48 #include "runtime/vm_version.hpp"
  49 #include "services/memTracker.hpp"
  50 #include "utilities/align.hpp"
  51 #include "utilities/defaultStream.hpp"
  52 #if INCLUDE_ALL_GCS
  53 #include "gc/g1/g1CollectedHeap.hpp"
  54 #endif
  55 
  56 # include <sys/stat.h>
  57 # include <errno.h>
  58 
  59 #ifndef O_BINARY       // if defined (Win32) use binary files.
  60 #define O_BINARY 0     // otherwise do nothing.
  61 #endif
  62 
  63 extern address JVM_FunctionAtStart();
  64 extern address JVM_FunctionAtEnd();
  65 
  66 // Complain and stop. All error conditions occurring during the writing of
  67 // an archive file should stop the process.  Unrecoverable errors during
  68 // the reading of the archive file should stop the process.
  69 
  70 static void fail(const char *msg, va_list ap) {
  71   // This occurs very early during initialization: tty is not initialized.
  72   jio_fprintf(defaultStream::error_stream(),
  73               "An error has occurred while processing the"
  74               " shared archive file.\n");


 452 }
 453 
 454 
 455 // Dump region to file.
 456 
 457 void FileMapInfo::write_region(int region, char* base, size_t size,
 458                                bool read_only, bool allow_exec) {
 459   struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[region];
 460 
 461   if (_file_open) {
 462     guarantee(si->_file_offset == _file_offset, "file offset mismatch.");
 463     log_info(cds)("Shared file region %d: " SIZE_FORMAT_HEX_W(08)
 464                   " bytes, addr " INTPTR_FORMAT " file offset " SIZE_FORMAT_HEX_W(08),
 465                   region, size, p2i(base), _file_offset);
 466   } else {
 467     si->_file_offset = _file_offset;
 468   }
 469   if (MetaspaceShared::is_heap_region(region)) {
 470     assert((base - (char*)Universe::narrow_oop_base()) % HeapWordSize == 0, "Sanity");
 471     if (base != NULL) {
 472       si->_addr._offset = (intx)CompressedOops::encode_not_null((oop)base);
 473     } else {
 474       si->_addr._offset = 0;
 475     }
 476   } else {
 477     si->_addr._base = base;
 478   }
 479   si->_used = size;
 480   si->_read_only = read_only;
 481   si->_allow_exec = allow_exec;
 482   si->_crc = ClassLoader::crc32(0, base, (jint)size);
 483   write_bytes_aligned(base, (int)size);
 484 }
 485 
 486 // Write out the given archive heap memory regions.  GC code combines multiple
 487 // consecutive archive GC regions into one MemRegion whenever possible and
 488 // produces the 'heap_mem' array.
 489 //
 490 // If the archive heap memory size is smaller than a single dump time GC region
 491 // size, there is only one MemRegion in the array.
 492 //


 767     assert(string_ranges == NULL && num_string_ranges == 0, "sanity");
 768   }
 769 
 770   if (!MetaspaceShared::open_archive_heap_region_mapped()) {
 771     assert(open_archive_heap_ranges == NULL && num_open_archive_heap_ranges == 0, "sanity");
 772   }
 773 }
 774 
 775 bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first,
 776                                 int max, int* num, bool is_open_archive) {
 777   MemRegion * regions = new MemRegion[max];
 778   struct FileMapInfo::FileMapHeader::space_info* si;
 779   int region_num = 0;
 780 
 781   for (int i = first;
 782            i < first + max; i++) {
 783     si = &_header->_space[i];
 784     size_t used = si->_used;
 785     if (used > 0) {
 786       size_t size = used;
 787       char* requested_addr = (char*)((void*)CompressedOops::decode_not_null(
 788                                             (narrowOop)si->_addr._offset));
 789       regions[region_num] = MemRegion((HeapWord*)requested_addr, size / HeapWordSize);
 790       region_num ++;
 791     }
 792   }
 793 
 794   if (region_num == 0) {
 795     return false; // no archived java heap data
 796   }
 797 
 798   // Check that ranges are within the java heap
 799   if (!G1CollectedHeap::heap()->check_archive_addresses(regions, region_num)) {
 800     log_info(cds)("UseSharedSpaces: Unable to allocate region, "
 801                   "range is not within java heap.");
 802     return false;
 803   }
 804 
 805   // allocate from java heap
 806   if (!G1CollectedHeap::heap()->alloc_archive_regions(
 807              regions, region_num, is_open_archive)) {


 948 // [1] validate_header() - done here. This checks the header, including _paths_misc_info.
 949 // [2] validate_classpath_entry_table - this is done later, because the table is in the RW
 950 //     region of the archive, which is not mapped yet.
 951 bool FileMapInfo::initialize() {
 952   assert(UseSharedSpaces, "UseSharedSpaces expected.");
 953 
 954   if (!open_for_read()) {
 955     return false;
 956   }
 957 
 958   init_from_file(_fd);
 959   if (!validate_header()) {
 960     return false;
 961   }
 962   return true;
 963 }
 964 
 965 char* FileMapInfo::FileMapHeader::region_addr(int idx) {
 966   if (MetaspaceShared::is_heap_region(idx)) {
 967     return _space[idx]._used > 0 ?
 968              (char*)((void*)CompressedOops::decode_not_null((narrowOop)_space[idx]._addr._offset)) : NULL;
 969   } else {
 970     return _space[idx]._addr._base;
 971   }
 972 }
 973 
 974 int FileMapInfo::FileMapHeader::compute_crc() {
 975   char* header = data();
 976   // start computing from the field after _crc
 977   char* buf = (char*)&_crc + sizeof(int);
 978   size_t sz = data_size() - (buf - header);
 979   int crc = ClassLoader::crc32(0, buf, (jint)sz);
 980   return crc;
 981 }
 982 
 983 bool FileMapInfo::FileMapHeader::validate() {
 984   if (VerifySharedSpaces && compute_crc() != _crc) {
 985     fail_continue("Header checksum verification failed.");
 986     return false;
 987   }
 988 


< prev index next >