< prev index next >

src/hotspot/share/cds/filemap.cpp

Print this page

  38 #include "classfile/classLoader.hpp"
  39 #include "classfile/classLoader.inline.hpp"
  40 #include "classfile/classLoaderData.inline.hpp"
  41 #include "classfile/classLoaderExt.hpp"
  42 #include "classfile/symbolTable.hpp"
  43 #include "classfile/systemDictionaryShared.hpp"
  44 #include "classfile/vmClasses.hpp"
  45 #include "classfile/vmSymbols.hpp"
  46 #include "jvm.h"
  47 #include "logging/log.hpp"
  48 #include "logging/logMessage.hpp"
  49 #include "logging/logStream.hpp"
  50 #include "memory/iterator.inline.hpp"
  51 #include "memory/metadataFactory.hpp"
  52 #include "memory/metaspaceClosure.hpp"
  53 #include "memory/oopFactory.hpp"
  54 #include "memory/universe.hpp"
  55 #include "nmt/memTracker.hpp"
  56 #include "oops/compressedOops.hpp"
  57 #include "oops/compressedOops.inline.hpp"

  58 #include "oops/objArrayOop.hpp"
  59 #include "oops/oop.inline.hpp"
  60 #include "prims/jvmtiExport.hpp"
  61 #include "runtime/arguments.hpp"
  62 #include "runtime/globals_extension.hpp"
  63 #include "runtime/java.hpp"
  64 #include "runtime/mutexLocker.hpp"
  65 #include "runtime/os.hpp"
  66 #include "runtime/vm_version.hpp"
  67 #include "utilities/align.hpp"
  68 #include "utilities/bitMap.inline.hpp"
  69 #include "utilities/classpathStream.hpp"
  70 #include "utilities/defaultStream.hpp"
  71 #include "utilities/ostream.hpp"
  72 #if INCLUDE_G1GC
  73 #include "gc/g1/g1CollectedHeap.hpp"
  74 #include "gc/g1/g1HeapRegion.hpp"
  75 #endif
  76 
  77 # include <sys/stat.h>

 187 void FileMapHeader::populate(FileMapInfo *info, size_t core_region_alignment,
 188                              size_t header_size, size_t base_archive_name_size,
 189                              size_t base_archive_name_offset, size_t common_app_classpath_prefix_size) {
 190   // 1. We require _generic_header._magic to be at the beginning of the file
 191   // 2. FileMapHeader also assumes that _generic_header is at the beginning of the file
 192   assert(offset_of(FileMapHeader, _generic_header) == 0, "must be");
 193   set_header_size((unsigned int)header_size);
 194   set_base_archive_name_offset((unsigned int)base_archive_name_offset);
 195   set_base_archive_name_size((unsigned int)base_archive_name_size);
 196   set_common_app_classpath_prefix_size((unsigned int)common_app_classpath_prefix_size);
 197   set_magic(CDSConfig::is_dumping_dynamic_archive() ? CDS_DYNAMIC_ARCHIVE_MAGIC : CDS_ARCHIVE_MAGIC);
 198   set_version(CURRENT_CDS_ARCHIVE_VERSION);
 199 
 200   if (!info->is_static() && base_archive_name_size != 0) {
 201     // copy base archive name
 202     copy_base_archive_name(CDSConfig::static_archive_path());
 203   }
 204   _core_region_alignment = core_region_alignment;
 205   _obj_alignment = ObjectAlignmentInBytes;
 206   _compact_strings = CompactStrings;

 207   if (CDSConfig::is_dumping_heap()) {
 208     _narrow_oop_mode = CompressedOops::mode();
 209     _narrow_oop_base = CompressedOops::base();
 210     _narrow_oop_shift = CompressedOops::shift();
 211   }
 212   _compressed_oops = UseCompressedOops;
 213   _compressed_class_ptrs = UseCompressedClassPointers;








 214   _max_heap_size = MaxHeapSize;
 215   _use_optimized_module_handling = CDSConfig::is_using_optimized_module_handling();
 216   _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
 217 
 218   // The following fields are for sanity checks for whether this archive
 219   // will function correctly with this JVM and the bootclasspath it's
 220   // invoked with.
 221 
 222   // JVM version string ... changes on each build.
 223   get_header_version(_jvm_ident);
 224 
 225   _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
 226   _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
 227   _max_used_path_index = ClassLoaderExt::max_used_path_index();
 228   _num_module_paths = ClassLoader::num_module_path_entries();
 229 
 230   _verify_local = BytecodeVerificationLocal;
 231   _verify_remote = BytecodeVerificationRemote;
 232   _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
 233   _has_non_jar_in_classpath = ClassLoaderExt::has_non_jar_in_classpath();

 253   st->print_cr("- magic:                          0x%08x", magic());
 254   st->print_cr("- crc:                            0x%08x", crc());
 255   st->print_cr("- version:                        0x%x", version());
 256   st->print_cr("- header_size:                    " UINT32_FORMAT, header_size());
 257   st->print_cr("- common_app_classpath_size:      " UINT32_FORMAT, common_app_classpath_prefix_size());
 258   st->print_cr("- base_archive_name_offset:       " UINT32_FORMAT, base_archive_name_offset());
 259   st->print_cr("- base_archive_name_size:         " UINT32_FORMAT, base_archive_name_size());
 260 
 261   for (int i = 0; i < NUM_CDS_REGIONS; i++) {
 262     FileMapRegion* r = region_at(i);
 263     r->print(st, i);
 264   }
 265   st->print_cr("============ end regions ======== ");
 266 
 267   st->print_cr("- core_region_alignment:          " SIZE_FORMAT, _core_region_alignment);
 268   st->print_cr("- obj_alignment:                  %d", _obj_alignment);
 269   st->print_cr("- narrow_oop_base:                " INTPTR_FORMAT, p2i(_narrow_oop_base));
 270   st->print_cr("- narrow_oop_base:                " INTPTR_FORMAT, p2i(_narrow_oop_base));
 271   st->print_cr("- narrow_oop_shift                %d", _narrow_oop_shift);
 272   st->print_cr("- compact_strings:                %d", _compact_strings);

 273   st->print_cr("- max_heap_size:                  " UINTX_FORMAT, _max_heap_size);
 274   st->print_cr("- narrow_oop_mode:                %d", _narrow_oop_mode);
 275   st->print_cr("- compressed_oops:                %d", _compressed_oops);
 276   st->print_cr("- compressed_class_ptrs:          %d", _compressed_class_ptrs);


 277   st->print_cr("- cloned_vtables_offset:          " SIZE_FORMAT_X, _cloned_vtables_offset);
 278   st->print_cr("- serialized_data_offset:         " SIZE_FORMAT_X, _serialized_data_offset);
 279   st->print_cr("- jvm_ident:                      %s", _jvm_ident);
 280   st->print_cr("- shared_path_table_offset:       " SIZE_FORMAT_X, _shared_path_table_offset);
 281   st->print_cr("- app_class_paths_start_index:    %d", _app_class_paths_start_index);
 282   st->print_cr("- app_module_paths_start_index:   %d", _app_module_paths_start_index);
 283   st->print_cr("- num_module_paths:               %d", _num_module_paths);
 284   st->print_cr("- max_used_path_index:            %d", _max_used_path_index);
 285   st->print_cr("- verify_local:                   %d", _verify_local);
 286   st->print_cr("- verify_remote:                  %d", _verify_remote);
 287   st->print_cr("- has_platform_or_app_classes:    %d", _has_platform_or_app_classes);
 288   st->print_cr("- has_non_jar_in_classpath:       %d", _has_non_jar_in_classpath);
 289   st->print_cr("- requested_base_address:         " INTPTR_FORMAT, p2i(_requested_base_address));
 290   st->print_cr("- mapped_base_address:            " INTPTR_FORMAT, p2i(_mapped_base_address));
 291   st->print_cr("- heap_roots_offset:              " SIZE_FORMAT, _heap_roots_offset);
 292   st->print_cr("- _heap_oopmap_start_pos:         " SIZE_FORMAT, _heap_oopmap_start_pos);
 293   st->print_cr("- _heap_ptrmap_start_pos:         " SIZE_FORMAT, _heap_ptrmap_start_pos);
 294   st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
 295   st->print_cr("- use_optimized_module_handling:  %d", _use_optimized_module_handling);
 296   st->print_cr("- has_full_module_graph           %d", _has_full_module_graph);

2028 }
2029 
2030 bool FileMapInfo::can_use_heap_region() {
2031   if (!has_heap_region()) {
2032     return false;
2033   }
2034   if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) {
2035     ShouldNotReachHere(); // CDS should have been disabled.
2036     // The archived objects are mapped at JVM start-up, but we don't know if
2037     // j.l.String or j.l.Class might be replaced by the ClassFileLoadHook,
2038     // which would make the archived String or mirror objects invalid. Let's be safe and not
2039     // use the archived objects. These 2 classes are loaded during the JVMTI "early" stage.
2040     //
2041     // If JvmtiExport::has_early_class_hook_env() is false, the classes of some objects
2042     // in the archived subgraphs may be replaced by the ClassFileLoadHook. But that's OK
2043     // because we won't install an archived object subgraph if the klass of any of the
2044     // referenced objects are replaced. See HeapShared::initialize_from_archived_subgraph().
2045   }
2046 
2047   // We pre-compute narrow Klass IDs with the runtime mapping start intended to be the base, and a shift of
2048   // ArchiveHeapWriter::precomputed_narrow_klass_shift. We enforce this encoding at runtime (see
2049   // CompressedKlassPointers::initialize_for_given_encoding()). Therefore, the following assertions must
2050   // hold:
2051   address archive_narrow_klass_base = (address)header()->mapped_base_address();
2052   const int archive_narrow_klass_shift = ArchiveHeapWriter::precomputed_narrow_klass_shift;

2053 
2054   log_info(cds)("CDS archive was created with max heap size = " SIZE_FORMAT "M, and the following configuration:",
2055                 max_heap_size()/M);
2056   log_info(cds)("    narrow_klass_base at mapping start address, narrow_klass_shift = %d",
2057                 archive_narrow_klass_shift);
2058   log_info(cds)("    narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d",
2059                 narrow_oop_mode(), p2i(narrow_oop_base()), narrow_oop_shift());
2060   log_info(cds)("The current max heap size = " SIZE_FORMAT "M, HeapRegion::GrainBytes = " SIZE_FORMAT,
2061                 MaxHeapSize/M, HeapRegion::GrainBytes);
2062   log_info(cds)("    narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d",
2063                 p2i(CompressedKlassPointers::base()), CompressedKlassPointers::shift());
2064   log_info(cds)("    narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d",
2065                 CompressedOops::mode(), p2i(CompressedOops::base()), CompressedOops::shift());
2066   log_info(cds)("    heap range = [" PTR_FORMAT " - "  PTR_FORMAT "]",
2067                 UseCompressedOops ? p2i(CompressedOops::begin()) :
2068                                     UseG1GC ? p2i((address)G1CollectedHeap::heap()->reserved().start()) : 0L,
2069                 UseCompressedOops ? p2i(CompressedOops::end()) :
2070                                     UseG1GC ? p2i((address)G1CollectedHeap::heap()->reserved().end()) : 0L);
2071 
2072   assert(archive_narrow_klass_base == CompressedKlassPointers::base(), "Unexpected encoding base encountered "
2073          "(" PTR_FORMAT ", expected " PTR_FORMAT ")", p2i(CompressedKlassPointers::base()), p2i(archive_narrow_klass_base));
2074   assert(archive_narrow_klass_shift == CompressedKlassPointers::shift(), "Unexpected encoding shift encountered "
2075          "(%d, expected %d)", CompressedKlassPointers::shift(), archive_narrow_klass_shift);

























2076 
2077   return true;
2078 }
2079 
2080 // The actual address of this region during dump time.
2081 address FileMapInfo::heap_region_dumptime_address() {
2082   FileMapRegion* r = region_at(MetaspaceShared::hp);
2083   assert(UseSharedSpaces, "runtime only");
2084   assert(is_aligned(r->mapping_offset(), sizeof(HeapWord)), "must be");
2085   if (UseCompressedOops) {
2086     return /*dumptime*/ narrow_oop_base() + r->mapping_offset();
2087   } else {
2088     return heap_region_requested_address();
2089   }
2090 }
2091 
2092 // The address where this region can be mapped into the runtime heap without
2093 // patching any of the pointers that are embedded in this region.
2094 address FileMapInfo::heap_region_requested_address() {
2095   assert(UseSharedSpaces, "runtime only");

2421   // while AllowArchivingWithJavaAgent is set during the current run.
2422   if (_allow_archiving_with_java_agent && !AllowArchivingWithJavaAgent) {
2423     log_warning(cds)("The setting of the AllowArchivingWithJavaAgent is different "
2424                                "from the setting in the shared archive.");
2425     return false;
2426   }
2427 
2428   if (_allow_archiving_with_java_agent) {
2429     log_warning(cds)("This archive was created with AllowArchivingWithJavaAgent. It should be used "
2430             "for testing purposes only and should not be used in a production environment");
2431   }
2432 
2433   log_info(cds)("Archive was created with UseCompressedOops = %d, UseCompressedClassPointers = %d",
2434                           compressed_oops(), compressed_class_pointers());
2435   if (compressed_oops() != UseCompressedOops || compressed_class_pointers() != UseCompressedClassPointers) {
2436     log_info(cds)("Unable to use shared archive.\nThe saved state of UseCompressedOops and UseCompressedClassPointers is "
2437                                "different from runtime, CDS will be disabled.");
2438     return false;
2439   }
2440 








2441   if (!_use_optimized_module_handling) {
2442     CDSConfig::stop_using_optimized_module_handling();
2443     log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
2444   }
2445 
2446   if (is_static() && !_has_full_module_graph) {
2447     // Only the static archive can contain the full module graph.
2448     CDSConfig::stop_using_full_module_graph("archive was created without full module graph");
2449   }
2450 
2451   return true;
2452 }
2453 
2454 bool FileMapInfo::validate_header() {
2455   if (!header()->validate()) {
2456     return false;
2457   }
2458   if (_is_static) {
2459     return true;
2460   } else {

  38 #include "classfile/classLoader.hpp"
  39 #include "classfile/classLoader.inline.hpp"
  40 #include "classfile/classLoaderData.inline.hpp"
  41 #include "classfile/classLoaderExt.hpp"
  42 #include "classfile/symbolTable.hpp"
  43 #include "classfile/systemDictionaryShared.hpp"
  44 #include "classfile/vmClasses.hpp"
  45 #include "classfile/vmSymbols.hpp"
  46 #include "jvm.h"
  47 #include "logging/log.hpp"
  48 #include "logging/logMessage.hpp"
  49 #include "logging/logStream.hpp"
  50 #include "memory/iterator.inline.hpp"
  51 #include "memory/metadataFactory.hpp"
  52 #include "memory/metaspaceClosure.hpp"
  53 #include "memory/oopFactory.hpp"
  54 #include "memory/universe.hpp"
  55 #include "nmt/memTracker.hpp"
  56 #include "oops/compressedOops.hpp"
  57 #include "oops/compressedOops.inline.hpp"
  58 #include "oops/compressedKlass.hpp"
  59 #include "oops/objArrayOop.hpp"
  60 #include "oops/oop.inline.hpp"
  61 #include "prims/jvmtiExport.hpp"
  62 #include "runtime/arguments.hpp"
  63 #include "runtime/globals_extension.hpp"
  64 #include "runtime/java.hpp"
  65 #include "runtime/mutexLocker.hpp"
  66 #include "runtime/os.hpp"
  67 #include "runtime/vm_version.hpp"
  68 #include "utilities/align.hpp"
  69 #include "utilities/bitMap.inline.hpp"
  70 #include "utilities/classpathStream.hpp"
  71 #include "utilities/defaultStream.hpp"
  72 #include "utilities/ostream.hpp"
  73 #if INCLUDE_G1GC
  74 #include "gc/g1/g1CollectedHeap.hpp"
  75 #include "gc/g1/g1HeapRegion.hpp"
  76 #endif
  77 
  78 # include <sys/stat.h>

 188 void FileMapHeader::populate(FileMapInfo *info, size_t core_region_alignment,
 189                              size_t header_size, size_t base_archive_name_size,
 190                              size_t base_archive_name_offset, size_t common_app_classpath_prefix_size) {
 191   // 1. We require _generic_header._magic to be at the beginning of the file
 192   // 2. FileMapHeader also assumes that _generic_header is at the beginning of the file
 193   assert(offset_of(FileMapHeader, _generic_header) == 0, "must be");
 194   set_header_size((unsigned int)header_size);
 195   set_base_archive_name_offset((unsigned int)base_archive_name_offset);
 196   set_base_archive_name_size((unsigned int)base_archive_name_size);
 197   set_common_app_classpath_prefix_size((unsigned int)common_app_classpath_prefix_size);
 198   set_magic(CDSConfig::is_dumping_dynamic_archive() ? CDS_DYNAMIC_ARCHIVE_MAGIC : CDS_ARCHIVE_MAGIC);
 199   set_version(CURRENT_CDS_ARCHIVE_VERSION);
 200 
 201   if (!info->is_static() && base_archive_name_size != 0) {
 202     // copy base archive name
 203     copy_base_archive_name(CDSConfig::static_archive_path());
 204   }
 205   _core_region_alignment = core_region_alignment;
 206   _obj_alignment = ObjectAlignmentInBytes;
 207   _compact_strings = CompactStrings;
 208   _compact_headers = UseCompactObjectHeaders;
 209   if (CDSConfig::is_dumping_heap()) {
 210     _narrow_oop_mode = CompressedOops::mode();
 211     _narrow_oop_base = CompressedOops::base();
 212     _narrow_oop_shift = CompressedOops::shift();
 213   }
 214   _compressed_oops = UseCompressedOops;
 215   _compressed_class_ptrs = UseCompressedClassPointers;
 216   if (UseCompressedClassPointers) {
 217 #ifdef _LP64
 218     _narrow_klass_pointer_bits = CompressedKlassPointers::narrow_klass_pointer_bits();
 219     _narrow_klass_shift = ArchiveBuilder::precomputed_narrow_klass_shift();
 220 #endif
 221   } else {
 222     _narrow_klass_pointer_bits = _narrow_klass_shift = -1;
 223   }
 224   _max_heap_size = MaxHeapSize;
 225   _use_optimized_module_handling = CDSConfig::is_using_optimized_module_handling();
 226   _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
 227 
 228   // The following fields are for sanity checks for whether this archive
 229   // will function correctly with this JVM and the bootclasspath it's
 230   // invoked with.
 231 
 232   // JVM version string ... changes on each build.
 233   get_header_version(_jvm_ident);
 234 
 235   _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
 236   _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
 237   _max_used_path_index = ClassLoaderExt::max_used_path_index();
 238   _num_module_paths = ClassLoader::num_module_path_entries();
 239 
 240   _verify_local = BytecodeVerificationLocal;
 241   _verify_remote = BytecodeVerificationRemote;
 242   _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
 243   _has_non_jar_in_classpath = ClassLoaderExt::has_non_jar_in_classpath();

 263   st->print_cr("- magic:                          0x%08x", magic());
 264   st->print_cr("- crc:                            0x%08x", crc());
 265   st->print_cr("- version:                        0x%x", version());
 266   st->print_cr("- header_size:                    " UINT32_FORMAT, header_size());
 267   st->print_cr("- common_app_classpath_size:      " UINT32_FORMAT, common_app_classpath_prefix_size());
 268   st->print_cr("- base_archive_name_offset:       " UINT32_FORMAT, base_archive_name_offset());
 269   st->print_cr("- base_archive_name_size:         " UINT32_FORMAT, base_archive_name_size());
 270 
 271   for (int i = 0; i < NUM_CDS_REGIONS; i++) {
 272     FileMapRegion* r = region_at(i);
 273     r->print(st, i);
 274   }
 275   st->print_cr("============ end regions ======== ");
 276 
 277   st->print_cr("- core_region_alignment:          " SIZE_FORMAT, _core_region_alignment);
 278   st->print_cr("- obj_alignment:                  %d", _obj_alignment);
 279   st->print_cr("- narrow_oop_base:                " INTPTR_FORMAT, p2i(_narrow_oop_base));
 280   st->print_cr("- narrow_oop_base:                " INTPTR_FORMAT, p2i(_narrow_oop_base));
 281   st->print_cr("- narrow_oop_shift                %d", _narrow_oop_shift);
 282   st->print_cr("- compact_strings:                %d", _compact_strings);
 283   st->print_cr("- compact_headers:                %d", _compact_headers);
 284   st->print_cr("- max_heap_size:                  " UINTX_FORMAT, _max_heap_size);
 285   st->print_cr("- narrow_oop_mode:                %d", _narrow_oop_mode);
 286   st->print_cr("- compressed_oops:                %d", _compressed_oops);
 287   st->print_cr("- compressed_class_ptrs:          %d", _compressed_class_ptrs);
 288   st->print_cr("- narrow_klass_pointer_bits:      %d", _narrow_klass_pointer_bits);
 289   st->print_cr("- narrow_klass_shift:             %d", _narrow_klass_shift);
 290   st->print_cr("- cloned_vtables_offset:          " SIZE_FORMAT_X, _cloned_vtables_offset);
 291   st->print_cr("- serialized_data_offset:         " SIZE_FORMAT_X, _serialized_data_offset);
 292   st->print_cr("- jvm_ident:                      %s", _jvm_ident);
 293   st->print_cr("- shared_path_table_offset:       " SIZE_FORMAT_X, _shared_path_table_offset);
 294   st->print_cr("- app_class_paths_start_index:    %d", _app_class_paths_start_index);
 295   st->print_cr("- app_module_paths_start_index:   %d", _app_module_paths_start_index);
 296   st->print_cr("- num_module_paths:               %d", _num_module_paths);
 297   st->print_cr("- max_used_path_index:            %d", _max_used_path_index);
 298   st->print_cr("- verify_local:                   %d", _verify_local);
 299   st->print_cr("- verify_remote:                  %d", _verify_remote);
 300   st->print_cr("- has_platform_or_app_classes:    %d", _has_platform_or_app_classes);
 301   st->print_cr("- has_non_jar_in_classpath:       %d", _has_non_jar_in_classpath);
 302   st->print_cr("- requested_base_address:         " INTPTR_FORMAT, p2i(_requested_base_address));
 303   st->print_cr("- mapped_base_address:            " INTPTR_FORMAT, p2i(_mapped_base_address));
 304   st->print_cr("- heap_roots_offset:              " SIZE_FORMAT, _heap_roots_offset);
 305   st->print_cr("- _heap_oopmap_start_pos:         " SIZE_FORMAT, _heap_oopmap_start_pos);
 306   st->print_cr("- _heap_ptrmap_start_pos:         " SIZE_FORMAT, _heap_ptrmap_start_pos);
 307   st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
 308   st->print_cr("- use_optimized_module_handling:  %d", _use_optimized_module_handling);
 309   st->print_cr("- has_full_module_graph           %d", _has_full_module_graph);

2041 }
2042 
2043 bool FileMapInfo::can_use_heap_region() {
2044   if (!has_heap_region()) {
2045     return false;
2046   }
2047   if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) {
2048     ShouldNotReachHere(); // CDS should have been disabled.
2049     // The archived objects are mapped at JVM start-up, but we don't know if
2050     // j.l.String or j.l.Class might be replaced by the ClassFileLoadHook,
2051     // which would make the archived String or mirror objects invalid. Let's be safe and not
2052     // use the archived objects. These 2 classes are loaded during the JVMTI "early" stage.
2053     //
2054     // If JvmtiExport::has_early_class_hook_env() is false, the classes of some objects
2055     // in the archived subgraphs may be replaced by the ClassFileLoadHook. But that's OK
2056     // because we won't install an archived object subgraph if the klass of any of the
2057     // referenced objects are replaced. See HeapShared::initialize_from_archived_subgraph().
2058   }
2059 
2060   // We pre-compute narrow Klass IDs with the runtime mapping start intended to be the base, and a shift of
2061   // ArchiveBuilder::precomputed_narrow_klass_shift. We enforce this encoding at runtime (see
2062   // CompressedKlassPointers::initialize_for_given_encoding()). Therefore, the following assertions must
2063   // hold:
2064   address archive_narrow_klass_base = (address)header()->mapped_base_address();
2065   const int archive_narrow_klass_pointer_bits = header()->narrow_klass_pointer_bits();
2066   const int archive_narrow_klass_shift = header()->narrow_klass_shift();
2067 
2068   log_info(cds)("CDS archive was created with max heap size = " SIZE_FORMAT "M, and the following configuration:",
2069                 max_heap_size()/M);
2070   log_info(cds)("    narrow_klass_base at mapping start address, narrow_klass_pointer_bits = %d, narrow_klass_shift = %d",
2071                 archive_narrow_klass_pointer_bits, archive_narrow_klass_shift);
2072   log_info(cds)("    narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d",
2073                 narrow_oop_mode(), p2i(narrow_oop_base()), narrow_oop_shift());
2074   log_info(cds)("The current max heap size = " SIZE_FORMAT "M, HeapRegion::GrainBytes = " SIZE_FORMAT,
2075                 MaxHeapSize/M, HeapRegion::GrainBytes);
2076   log_info(cds)("    narrow_klass_base = " PTR_FORMAT ", arrow_klass_pointer_bits = %d, narrow_klass_shift = %d",
2077                 p2i(CompressedKlassPointers::base()), CompressedKlassPointers::narrow_klass_pointer_bits(), CompressedKlassPointers::shift());
2078   log_info(cds)("    narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d",
2079                 CompressedOops::mode(), p2i(CompressedOops::base()), CompressedOops::shift());
2080   log_info(cds)("    heap range = [" PTR_FORMAT " - "  PTR_FORMAT "]",
2081                 UseCompressedOops ? p2i(CompressedOops::begin()) :
2082                                     UseG1GC ? p2i((address)G1CollectedHeap::heap()->reserved().start()) : 0L,
2083                 UseCompressedOops ? p2i(CompressedOops::end()) :
2084                                     UseG1GC ? p2i((address)G1CollectedHeap::heap()->reserved().end()) : 0L);
2085 
2086   int err = 0;
2087   if ( archive_narrow_klass_base != CompressedKlassPointers::base() ||
2088        (err = 1, archive_narrow_klass_pointer_bits != CompressedKlassPointers::narrow_klass_pointer_bits()) ||
2089        (err = 2, archive_narrow_klass_shift != CompressedKlassPointers::shift()) ) {
2090     stringStream ss;
2091     switch (err) {
2092     case 0:
2093       ss.print("Unexpected encoding base encountered (" PTR_FORMAT ", expected " PTR_FORMAT ")",
2094                p2i(CompressedKlassPointers::base()), p2i(archive_narrow_klass_base));
2095       break;
2096     case 1:
2097       ss.print("Unexpected narrow Klass bit length encountered (%d, expected %d)",
2098                CompressedKlassPointers::narrow_klass_pointer_bits(), archive_narrow_klass_pointer_bits);
2099       break;
2100     case 2:
2101       ss.print("Unexpected narrow Klass shift encountered (%d, expected %d)",
2102                CompressedKlassPointers::shift(), archive_narrow_klass_shift);
2103       break;
2104     default:
2105       ShouldNotReachHere();
2106     };
2107     LogTarget(Info, cds) lt;
2108     if (lt.is_enabled()) {
2109       LogStream ls(lt);
2110       ls.print_raw(ss.base());
2111       header()->print(&ls);
2112     }
2113     assert(false, "%s", ss.base());
2114   }
2115 
2116   return true;
2117 }
2118 
2119 // The actual address of this region during dump time.
2120 address FileMapInfo::heap_region_dumptime_address() {
2121   FileMapRegion* r = region_at(MetaspaceShared::hp);
2122   assert(UseSharedSpaces, "runtime only");
2123   assert(is_aligned(r->mapping_offset(), sizeof(HeapWord)), "must be");
2124   if (UseCompressedOops) {
2125     return /*dumptime*/ narrow_oop_base() + r->mapping_offset();
2126   } else {
2127     return heap_region_requested_address();
2128   }
2129 }
2130 
2131 // The address where this region can be mapped into the runtime heap without
2132 // patching any of the pointers that are embedded in this region.
2133 address FileMapInfo::heap_region_requested_address() {
2134   assert(UseSharedSpaces, "runtime only");

2460   // while AllowArchivingWithJavaAgent is set during the current run.
2461   if (_allow_archiving_with_java_agent && !AllowArchivingWithJavaAgent) {
2462     log_warning(cds)("The setting of the AllowArchivingWithJavaAgent is different "
2463                                "from the setting in the shared archive.");
2464     return false;
2465   }
2466 
2467   if (_allow_archiving_with_java_agent) {
2468     log_warning(cds)("This archive was created with AllowArchivingWithJavaAgent. It should be used "
2469             "for testing purposes only and should not be used in a production environment");
2470   }
2471 
2472   log_info(cds)("Archive was created with UseCompressedOops = %d, UseCompressedClassPointers = %d",
2473                           compressed_oops(), compressed_class_pointers());
2474   if (compressed_oops() != UseCompressedOops || compressed_class_pointers() != UseCompressedClassPointers) {
2475     log_info(cds)("Unable to use shared archive.\nThe saved state of UseCompressedOops and UseCompressedClassPointers is "
2476                                "different from runtime, CDS will be disabled.");
2477     return false;
2478   }
2479 
2480   if (compact_headers() != UseCompactObjectHeaders) {
2481     log_info(cds)("The shared archive file's UseCompactObjectHeaders setting (%s)"
2482                   " does not equal the current UseCompactObjectHeaders setting (%s).",
2483                   _compact_headers          ? "enabled" : "disabled",
2484                   UseCompactObjectHeaders   ? "enabled" : "disabled");
2485     return false;
2486   }
2487 
2488   if (!_use_optimized_module_handling) {
2489     CDSConfig::stop_using_optimized_module_handling();
2490     log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
2491   }
2492 
2493   if (is_static() && !_has_full_module_graph) {
2494     // Only the static archive can contain the full module graph.
2495     CDSConfig::stop_using_full_module_graph("archive was created without full module graph");
2496   }
2497 
2498   return true;
2499 }
2500 
2501 bool FileMapInfo::validate_header() {
2502   if (!header()->validate()) {
2503     return false;
2504   }
2505   if (_is_static) {
2506     return true;
2507   } else {
< prev index next >