< prev index next >

src/hotspot/share/cds/filemap.cpp

Print this page
@@ -211,11 +211,13 @@
    }
    _compressed_oops = UseCompressedOops;
    _compressed_class_ptrs = UseCompressedClassPointers;
    _max_heap_size = MaxHeapSize;
    _use_optimized_module_handling = MetaspaceShared::use_optimized_module_handling();
+   _has_preloaded_classes = PreloadSharedClasses;
    _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
+   _has_archived_invokedynamic = CDSConfig::is_dumping_invokedynamic();
  
    // The following fields are for sanity checks for whether this archive
    // will function correctly with this JVM and the bootclasspath it's
    // invoked with.
  

@@ -290,10 +292,11 @@
    st->print_cr("- mapped_base_address:            " INTPTR_FORMAT, p2i(_mapped_base_address));
    st->print_cr("- heap_roots_offset:              " SIZE_FORMAT, _heap_roots_offset);
    st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
    st->print_cr("- use_optimized_module_handling:  %d", _use_optimized_module_handling);
    st->print_cr("- has_full_module_graph           %d", _has_full_module_graph);
+   st->print_cr("- has_archived_invokedynamic      %d", _has_archived_invokedynamic);
    st->print_cr("- ptrmap_size_in_bits:            " SIZE_FORMAT, _ptrmap_size_in_bits);
  }
  
  void SharedClassPathEntry::init_as_non_existent(const char* path, TRAPS) {
    _type = non_existent_entry;

@@ -555,10 +558,13 @@
      return 0;
    }
  }
  
  int FileMapInfo::get_module_shared_path_index(Symbol* location) {
+   if (location == nullptr) {
+     return 0; // Used by java/lang/reflect/Proxy$ProxyBuilder
+   }
    if (location->starts_with("jrt:", 4) && get_number_of_shared_paths() > 0) {
      assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image");
      return 0;
    }
  

@@ -1485,11 +1491,11 @@
    return true;
  }
  
  static const char* region_name(int region_index) {
    static const char* names[] = {
-     "rw", "ro", "bm", "hp"
+     "rw", "ro", "bm", "hp", "cc",
    };
    const int num_regions = sizeof(names)/sizeof(names[0]);
    assert(0 <= region_index && region_index < num_regions, "sanity");
  
    return names[region_index];

@@ -1548,10 +1554,13 @@
    if (size > 0) {
      log_info(cds)("Shared file region (%s) %d: " SIZE_FORMAT_W(8)
                     " bytes, addr " INTPTR_FORMAT " file offset 0x%08" PRIxPTR
                     " crc 0x%08x",
                     region_name(region), region, size, p2i(requested_base), _file_offset, crc);
+   } else {
+     log_info(cds)("Shared file region (%s) %d: " SIZE_FORMAT_W(8)
+                   " bytes", region_name(region), region, size);
    }
  
    r->init(region, mapping_offset, size, read_only, allow_exec, crc);
  
    if (base != nullptr) {

@@ -1709,11 +1718,11 @@
    r->set_read_only(false);
    return true;
  }
  
  // Memory map a region in the address space.
- static const char* shared_region_name[] = { "ReadWrite", "ReadOnly", "Bitmap", "Heap" };
+ static const char* shared_region_name[] = { "ReadWrite", "ReadOnly", "Bitmap", "Heap", "Code" };
  
  MapArchiveResult FileMapInfo::map_regions(int regions[], int num_regions, char* mapped_base_address, ReservedSpace rs) {
    DEBUG_ONLY(FileMapRegion* last_region = nullptr);
    intx addr_delta = mapped_base_address - header()->requested_base_address();
  

@@ -1812,12 +1821,13 @@
      }
    } else {
      // Note that this may either be a "fresh" mapping into unreserved address
      // space (Windows, first mapping attempt), or a mapping into pre-reserved
      // space (Posix). See also comment in MetaspaceShared::map_archives().
+     bool read_only = r->read_only() && !CDSConfig::is_dumping_final_static_archive();
      char* base = map_memory(_fd, _full_path, r->file_offset(),
-                             requested_addr, size, r->read_only(),
+                             requested_addr, size, read_only,
                              r->allow_exec(), mtClassShared);
      if (base != requested_addr) {
        log_info(cds)("Unable to map %s shared space at " INTPTR_FORMAT,
                      shared_region_name[i], p2i(requested_addr));
        _memory_mapping_failed = true;

@@ -1865,29 +1875,107 @@
                  MetaspaceShared::bm, p2i(r->mapped_base()), p2i(r->mapped_end()),
                  shared_region_name[MetaspaceShared::bm]);
    return bitmap_base;
  }
  
+ bool FileMapInfo::map_cached_code_region(ReservedSpace rs) {
+   FileMapRegion* r = region_at(MetaspaceShared::cc);
+   assert(r->used() > 0 && rs.size(), "must be");
+ 
+   bool read_only = false, allow_exec = true;
+   char* requested_base = rs.base();
+   char* mapped_base = map_memory(_fd, _full_path, r->file_offset(),
+                                  requested_base, r->used_aligned(), read_only, allow_exec, mtClassShared);
+   if (mapped_base == nullptr) {
+     log_info(cds)("failed to map cached code region");
+     return false;
+   } else {
+     assert(mapped_base == requested_base, "must be");
+     r->set_mapped_from_file(true);
+     r->set_mapped_base(mapped_base);
+     relocate_pointers_in_cached_code_region();
+     log_info(cds)("Mapped static region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
+                   MetaspaceShared::bm, p2i(r->mapped_base()), p2i(r->mapped_end()),
+                   shared_region_name[MetaspaceShared::cc]);
+     return true;
+   }
+ }
+ 
+ class CachedCodeRelocator: public BitMapClosure {
+   address _code_requested_base;
+   address* _patch_base;
+   intx _code_delta;
+   intx _metadata_delta;
+ 
+ public:
+   CachedCodeRelocator(address code_requested_base, address code_mapped_base,
+                       intx metadata_delta) {
+     _code_requested_base = code_requested_base;
+     _patch_base = (address*)code_mapped_base;
+     _code_delta = code_mapped_base - code_requested_base;
+     _metadata_delta = metadata_delta;
+   }
+   
+   bool do_bit(size_t offset) {
+     address* p = _patch_base + offset;
+     address requested_ptr = *p;
+     if (requested_ptr < _code_requested_base) {
+       *p = requested_ptr + _metadata_delta;
+     } else {
+       *p = requested_ptr + _code_delta;
+     }
+     return true; // keep iterating
+   }
+ };
+ 
+ void FileMapInfo::relocate_pointers_in_cached_code_region() {
+   FileMapRegion* r = region_at(MetaspaceShared::cc);
+   char* bitmap_base = map_bitmap_region();
+ 
+   address core_regions_requested_base = (address)header()->requested_base_address();
+   address core_regions_mapped_base = (address)header()->mapped_base_address();
+   address cc_region_requested_base = core_regions_requested_base + r->mapping_offset();
+   address cc_region_mapped_base = (address)r->mapped_base();
+ 
+   size_t max_bits_for_core_regions = pointer_delta(mapped_end(), mapped_base(), // FIXME - renamed to core_regions_mapped_base(), etc
+                                                    sizeof(address));
+   size_t ptrmap_size_in_bits = header()->ptrmap_size_in_bits();
+   if (ptrmap_size_in_bits <= max_bits_for_core_regions) {
+     // No relocation inside the cached code region??
+     return;
+   }
+ 
+   ptrmap_size_in_bits -= max_bits_for_core_regions;
+   assert((max_bits_for_core_regions % 8) == 0, "must be aligned");
+   bitmap_base += max_bits_for_core_regions / 8;
+   BitMapView ptrmap((BitMap::bm_word_t*)bitmap_base, ptrmap_size_in_bits);
+ 
+   log_debug(cds, reloc)("cached code bitmap @ " INTPTR_FORMAT " (" SIZE_FORMAT " bits)",
+                         p2i(bitmap_base), ptrmap_size_in_bits);
+ 
+   CachedCodeRelocator patcher(cc_region_requested_base, cc_region_mapped_base,
+                               core_regions_mapped_base - core_regions_requested_base);
+   ptrmap.iterate(&patcher);
+ }
+ 
  // This is called when we cannot map the archive at the requested[ base address (usually 0x800000000).
  // We relocate all pointers in the 2 core regions (ro, rw).
  bool FileMapInfo::relocate_pointers_in_core_regions(intx addr_delta) {
    log_debug(cds, reloc)("runtime archive relocation start");
    char* bitmap_base = map_bitmap_region();
  
    if (bitmap_base == nullptr) {
      return false; // OOM, or CRC check failure
    } else {
-     size_t ptrmap_size_in_bits = header()->ptrmap_size_in_bits();
-     log_debug(cds, reloc)("mapped relocation bitmap @ " INTPTR_FORMAT " (" SIZE_FORMAT " bits)",
-                           p2i(bitmap_base), ptrmap_size_in_bits);
- 
-     BitMapView ptrmap((BitMap::bm_word_t*)bitmap_base, ptrmap_size_in_bits);
- 
      // Patch all pointers in the mapped region that are marked by ptrmap.
      address patch_base = (address)mapped_base();
      address patch_end  = (address)mapped_end();
  
+     // Exclude the bits used for the code_cache region (if it exists)
+     size_t max_bits_for_core_regions = pointer_delta(patch_end, patch_base, sizeof(address));
+     size_t ptrmap_size_in_bits = MIN2(header()->ptrmap_size_in_bits(), max_bits_for_core_regions);
+ 
      // the current value of the pointers to be patched must be within this
      // range (i.e., must be between the requested base address and the address of the current archive).
      // Note: top archive may point to objects in the base archive, but not the other way around.
      address valid_old_base = (address)header()->requested_base_address();
      address valid_old_end  = valid_old_base + mapping_end_offset();

@@ -1895,10 +1983,14 @@
      // after patching, the pointers must point inside this range
      // (the requested location of the archive, as mapped at runtime).
      address valid_new_base = (address)header()->mapped_base_address();
      address valid_new_end  = (address)mapped_end();
  
+     log_debug(cds, reloc)("mapped relocation bitmap @ " INTPTR_FORMAT " (" SIZE_FORMAT " bits)",
+                           p2i(bitmap_base), ptrmap_size_in_bits);
+     BitMapView ptrmap((BitMap::bm_word_t*)bitmap_base, ptrmap_size_in_bits);
+ 
      SharedDataRelocator patcher((address*)patch_base, (address*)patch_end, valid_old_base, valid_old_end,
                                  valid_new_base, valid_new_end, addr_delta);
      ptrmap.iterate(&patcher);
  
      // The MetaspaceShared::bm region will be unmapped in MetaspaceShared::initialize_shared_spaces().

@@ -1975,11 +2067,11 @@
        }
      }
    }
  
    if (!success) {
-     CDSConfig::disable_loading_full_module_graph();
+     CDSConfig::disable_loading_full_module_graph("archive heap loading failed");
    }
  }
  
  bool FileMapInfo::can_use_heap_region() {
    if (!has_heap_region()) {

@@ -2287,10 +2379,21 @@
        }
        return false;
      }
    }
  
+   if (header()->has_preloaded_classes()) {
+     if (JvmtiExport::should_post_class_file_load_hook()) {
+       log_info(cds)("CDS archive has preloaded classes. It cannot be used when JVMTI ClassFileLoadHook is in use.");
+       return false;
+     }
+     if (JvmtiExport::has_early_vmstart_env()) {
+       log_info(cds)("CDS archive has preloaded classes. It cannot be used when JVMTI early vm start is in use.");
+       return false;
+     }
+   }
+ 
    return true;
  }
  
  // The 2 core spaces are RW->RO
  FileMapRegion* FileMapInfo::first_core_region() const {

@@ -2395,13 +2498,19 @@
    if (!_use_optimized_module_handling) {
      MetaspaceShared::disable_optimized_module_handling();
      log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
    }
  
-   if (is_static() && !_has_full_module_graph) {
+   if (is_static()) {
      // Only the static archive can contain the full module graph.
-     CDSConfig::disable_loading_full_module_graph("archive was created without full module graph");
+     if (!_has_full_module_graph) {
+       CDSConfig::disable_loading_full_module_graph("archive was created without full module graph");
+     }
+ 
+     if (_has_archived_invokedynamic) {
+       CDSConfig::set_is_loading_invokedynamic();
+     }
    }
  
    return true;
  }
  
< prev index next >