< prev index next >

src/hotspot/share/cds/archiveBuilder.cpp

Print this page
@@ -31,10 +31,11 @@
  #include "cds/archiveUtils.hpp"
  #include "cds/cdsConfig.hpp"
  #include "cds/cppVtables.hpp"
  #include "cds/dumpAllocStats.hpp"
  #include "cds/dynamicArchive.hpp"
+ #include "cds/finalImageRecipes.hpp"
  #include "cds/heapShared.hpp"
  #include "cds/metaspaceShared.hpp"
  #include "cds/regeneratedClasses.hpp"
  #include "classfile/classLoader.hpp"
  #include "classfile/classLoaderDataShared.hpp"

@@ -62,10 +63,11 @@
  #include "oops/trainingData.hpp"
  #include "runtime/arguments.hpp"
  #include "runtime/fieldDescriptor.inline.hpp"
  #include "runtime/globals_extension.hpp"
  #include "runtime/javaThread.hpp"
+ #include "runtime/safepointVerifiers.hpp"
  #include "runtime/sharedRuntime.hpp"
  #include "utilities/align.hpp"
  #include "utilities/bitMap.inline.hpp"
  #include "utilities/formatBuffer.hpp"
  

@@ -184,10 +186,11 @@
    _ro_region("ro", MAX_SHARED_DELTA),
    _ac_region("ac", MAX_SHARED_DELTA),
    _ptrmap(mtClassShared),
    _rw_ptrmap(mtClassShared),
    _ro_ptrmap(mtClassShared),
+   _ac_ptrmap(mtClassShared),
    _rw_src_objs(),
    _ro_src_objs(),
    _src_obj_table(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE),
    _buffered_to_src_table(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE),
    _total_heap_region_size(0)

@@ -1325,10 +1328,11 @@
        if (source_oop != nullptr) {
          // This is a regular oop that got archived.
          // Don't print the requested addr again as we have just printed it at the beginning of the line.
          // Example:
          // 0x00000007ffd27938: @@ Object (0xfffa4f27) java.util.HashMap
+         assert(HeapShared::has_been_archived(source_oop), "did you call HeapShared::rehash_archived_object_cache()?");
          print_oop_info_cr(&st, source_oop, /*print_requested_addr=*/false);
          byte_size = source_oop->size() * BytesPerWord;
        } else if ((byte_size = ArchiveHeapWriter::get_filler_size_at(start)) > 0) {
          // We have a filler oop, which also does not exist in BufferOffsetToSourceObjectTable.
          // Example:

@@ -1374,11 +1378,11 @@
            }
            print_oop_info_cr(_st, obj);
          }
          break;
        default:
-         if (ArchiveHeapWriter::is_marked_as_native_pointer(_heap_info, _source_obj, fd->offset())) {
+         if (ArchiveHeapWriter::is_marked_as_native_pointer(_heap_info, _buffered_addr, fd->offset())) {
            print_as_native_pointer(fd);
          } else {
            fd->print_on_for(_st, cast_to_oop(_buffered_addr)); // name, offset, value
            _st->cr();
          }

@@ -1397,11 +1401,11 @@
  
        // The value of the native pointer at runtime.
        address requested_native_ptr = builder->to_requested(builder->get_buffered_addr(source_native_ptr));
  
        // The address of _source_obj at runtime
-       oop requested_obj = ArchiveHeapWriter::source_obj_to_requested_obj(_source_obj);
+       oop requested_obj = cast_to_oop(ArchiveHeapWriter::buffered_addr_to_requested_addr(_buffered_addr));
        // The address of this field in the requested space
        assert(requested_obj != nullptr, "Attempting to load field from null oop");
        address requested_field_addr = cast_from_oop<address>(requested_obj) + fd->offset();
  
        fd->print_on(_st);

@@ -1482,11 +1486,11 @@
    static void log_heap_roots() {
      LogStreamHandle(Trace, aot, map, oops) st;
      if (st.is_enabled()) {
        for (int i = 0; i < HeapShared::pending_roots()->length(); i++) {
          st.print("roots[%4d]: ", i);
-         print_oop_info_cr(&st, HeapShared::pending_roots()->at(i));
+         print_oop_info_cr(&st, HeapShared::pending_roots()->at(i).resolve());
        }
      }
    }
  
    // Example output:

@@ -1497,10 +1501,11 @@
    static void print_oop_info_cr(outputStream* st, oop source_oop, bool print_requested_addr = true) {
      if (source_oop == nullptr) {
        st->print_cr("null");
      } else {
        ResourceMark rm;
+       assert(HeapShared::has_been_archived(source_oop), "did you call HeapShared::rehash_archived_object_cache()?");
        oop requested_obj = ArchiveHeapWriter::source_obj_to_requested_obj(source_oop);
        if (print_requested_addr) {
          st->print(PTR_FORMAT " ", p2i(requested_obj));
        }
        if (UseCompressedOops) {

@@ -1513,10 +1518,13 @@
          st->print("%s", source_oop->klass()->external_name());
  
          if (java_lang_String::is_instance(source_oop)) {
            st->print(" ");
            java_lang_String::print(source_oop, st);
+         } else if (java_lang_invoke_MethodType::is_instance(source_oop)) {
+           st->print(" ");
+           java_lang_invoke_MethodType::print_signature(source_oop, st);
          } else if (java_lang_Class::is_instance(source_oop)) {
            oop scratch_mirror = source_oop;
  
            st->print(" ");
            print_class_signature_for_mirror(st, scratch_mirror);

@@ -1562,10 +1570,15 @@
  
  public:
    static void log(ArchiveBuilder* builder, FileMapInfo* mapinfo,
                    ArchiveHeapInfo* heap_info,
                    char* bitmap, size_t bitmap_size_in_bytes) {
+     // HeapShared::archived_object_cache() uses raw address of oop to compute the hash. At this point,
+     // a GC might have happened and moved some of the oops, so the table needs to be rehashed.
+     NoSafepointVerifier nsv;
+     HeapShared::rehash_archived_object_cache();
+ 
      log_info(aot, map)("%s CDS archive map for %s", CDSConfig::is_dumping_static_archive() ? "Static" : "Dynamic", mapinfo->full_path());
  
      address header = address(mapinfo->header());
      address header_end = header + mapinfo->header()->header_size();
      log_region("header", header, header_end, nullptr);

@@ -1604,14 +1617,17 @@
    write_region(mapinfo, MetaspaceShared::rw, &_rw_region, /*read_only=*/false,/*allow_exec=*/false);
    write_region(mapinfo, MetaspaceShared::ro, &_ro_region, /*read_only=*/true, /*allow_exec=*/false);
    write_region(mapinfo, MetaspaceShared::ac, &_ac_region, /*read_only=*/false,/*allow_exec=*/false);
  
    // Split pointer map into read-write and read-only bitmaps
-   ArchivePtrMarker::initialize_rw_ro_maps(&_rw_ptrmap, &_ro_ptrmap);
+   ArchivePtrMarker::initialize_rw_ro_ac_maps(&_rw_ptrmap, &_ro_ptrmap, &_ac_ptrmap);
  
    size_t bitmap_size_in_bytes;
-   char* bitmap = mapinfo->write_bitmap_region(ArchivePtrMarker::rw_ptrmap(), ArchivePtrMarker::ro_ptrmap(), heap_info,
+   char* bitmap = mapinfo->write_bitmap_region(ArchivePtrMarker::rw_ptrmap(),
+                                               ArchivePtrMarker::ro_ptrmap(),
+                                               ArchivePtrMarker::ac_ptrmap(),
+                                               heap_info,
                                                bitmap_size_in_bytes);
  
    if (heap_info->is_used()) {
      _total_heap_region_size = mapinfo->write_heap_region(heap_info);
    }

@@ -1623,12 +1639,12 @@
    // After this point, we should not write any data into mapinfo->header() since this
    // would corrupt its checksum we have calculated before.
    mapinfo->write_header();
    mapinfo->close();
  
+   aot_log_info(aot)("Full module graph = %s", CDSConfig::is_dumping_full_module_graph() ? "enabled" : "disabled");
    if (log_is_enabled(Info, aot)) {
-     log_info(aot)("Full module graph = %s", CDSConfig::is_dumping_full_module_graph() ? "enabled" : "disabled");
      print_stats();
    }
  
    if (log_is_enabled(Info, aot, map)) {
      CDSMapLogger::log(this, mapinfo, heap_info,
< prev index next >