Skip to content

Commit

Permalink
8328236: module_entry in CDS map file has stale value
Browse files Browse the repository at this point in the history
Reviewed-by: ccheung, matsaave
  • Loading branch information
iklam committed Mar 16, 2024
1 parent 0204aac commit 0719419
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/hotspot/share/cds/archiveBuilder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -1049,7 +1049,7 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {
#if INCLUDE_CDS_JAVA_HEAP
static void log_heap_region(ArchiveHeapInfo* heap_info) {
MemRegion r = heap_info->buffer_region();
address start = address(r.start());
address start = address(r.start()); // start of the current oop inside the buffer
address end = address(r.end());
log_region("heap", start, end, ArchiveHeapWriter::buffered_addr_to_requested_addr(start));

Expand Down Expand Up @@ -1082,7 +1082,7 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {
log_as_hex(start, oop_end, requested_start, /*is_heap=*/true);

if (source_oop != nullptr) {
log_oop_details(heap_info, source_oop);
log_oop_details(heap_info, source_oop, /*buffered_addr=*/start);
} else if (start == ArchiveHeapWriter::buffered_heap_roots_addr()) {
log_heap_roots();
}
Expand All @@ -1097,9 +1097,10 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {
ArchiveHeapInfo* _heap_info;
outputStream* _st;
oop _source_obj;
address _buffered_addr;
public:
ArchivedFieldPrinter(ArchiveHeapInfo* heap_info, outputStream* st, oop src_obj) :
_heap_info(heap_info), _st(st), _source_obj(src_obj) {}
ArchivedFieldPrinter(ArchiveHeapInfo* heap_info, outputStream* st, oop src_obj, address buffered_addr) :
_heap_info(heap_info), _st(st), _source_obj(src_obj), _buffered_addr(buffered_addr) {}

void do_field(fieldDescriptor* fd) {
_st->print(" - ");
Expand All @@ -1114,7 +1115,7 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {
if (ArchiveHeapWriter::is_marked_as_native_pointer(_heap_info, _source_obj, fd->offset())) {
print_as_native_pointer(fd);
} else {
fd->print_on_for(_st, _source_obj); // name, offset, value
fd->print_on_for(_st, cast_to_oop(_buffered_addr)); // name, offset, value
_st->cr();
}
}
Expand Down Expand Up @@ -1146,7 +1147,7 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {
};

// Print the fields of instanceOops, or the elements of arrayOops
static void log_oop_details(ArchiveHeapInfo* heap_info, oop source_oop) {
static void log_oop_details(ArchiveHeapInfo* heap_info, oop source_oop, address buffered_addr) {
LogStreamHandle(Trace, cds, map, oops) st;
if (st.is_enabled()) {
Klass* source_klass = source_oop->klass();
Expand All @@ -1168,7 +1169,7 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {
}
} else {
st.print_cr(" - fields (" SIZE_FORMAT " words):", source_oop->size());
ArchivedFieldPrinter print_field(heap_info, &st, source_oop);
ArchivedFieldPrinter print_field(heap_info, &st, source_oop, buffered_addr);
InstanceKlass::cast(source_klass)->print_nonstatic_fields(&print_field);
}
}
Expand Down
11 changes: 10 additions & 1 deletion test/hotspot/jtreg/runtime/cds/CDSMapReader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -175,6 +175,10 @@ public static class Field {
// - final 'key' 'Ljava/lang/Object;' @16 0x00000007ffc68260 (0xfff8d04c) java.lang.String
static Pattern oopFieldPattern2 = Pattern.compile(" - [^']* '([^']+)'.*@([0-9]+) 0x([0-9a-f]+) [(]0x([0-9a-f]+)[)] (.*)");

// (injected module_entry)
// - injected 'module_entry' 'J' @16 0 (0x0000000000000000)
static Pattern moduleEntryPattern = Pattern.compile("- injected 'module_entry' 'J' @[0-9]+[ ]+([0-9]+)");

private static Matcher match(String line, Pattern pattern) {
Matcher m = pattern.matcher(line);
if (m.find()) {
Expand Down Expand Up @@ -218,6 +222,11 @@ private static HeapObject parseHeapObjectImpl(String className, String oop, Stri
heapObject.addOopField(m.group(1), m.group(2), m.group(3), m.group(4));
} else if ((m = match(line, oopFieldPattern1)) != null) {
heapObject.addOopField(m.group(1), m.group(2), m.group(3), null);
} else if ((m = match(line, moduleEntryPattern)) != null) {
String value = m.group(1);
if (!value.equals("0")) {
throw new RuntimeException("module_entry should be 0 but found: " + line);
}
}
}
}
Expand Down

0 comments on commit 0719419

Please sign in to comment.