Skip to content

Commit 7eb086f

Browse files
[GR-63524] Fix class names in heap dumps.
PullRequest: graal/20397
2 parents c91e452 + e367a6e commit 7eb086f

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/dump/HeapDumpWriter.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
import com.oracle.svm.core.heap.dump.HeapDumpMetadata.FieldNameAccess;
7272
import com.oracle.svm.core.hub.DynamicHub;
7373
import com.oracle.svm.core.hub.LayoutEncoding;
74+
import com.oracle.svm.core.jdk.UninterruptibleUtils.CharReplacer;
75+
import com.oracle.svm.core.jdk.UninterruptibleUtils.ReplaceDotWithSlash;
7476
import com.oracle.svm.core.layeredimagesingleton.MultiLayeredImageSingleton;
7577
import com.oracle.svm.core.log.Log;
7678
import com.oracle.svm.core.nmt.NmtCategory;
@@ -400,6 +402,7 @@ public class HeapDumpWriter {
400402
private static final int HEAP_DUMP_SEGMENT_TARGET_SIZE = 1 * 1024 * 1024;
401403

402404
private final NoAllocationVerifier noAllocationVerifier = NoAllocationVerifier.factory("HeapDumpWriter", false);
405+
private final ReplaceDotWithSlash dotWithSlashReplacer = new ReplaceDotWithSlash();
403406
private final DumpStackFrameVisitor dumpStackFrameVisitor = new DumpStackFrameVisitor();
404407
private final DumpObjectsVisitor dumpObjectsVisitor = new DumpObjectsVisitor();
405408
private final CodeMetadataVisitor codeMetadataVisitor = new CodeMetadataVisitor();
@@ -547,15 +550,19 @@ private void writeClassNames() {
547550
for (int i = 0; i < metadata.getClassInfoCount(); i++) {
548551
ClassInfo classInfo = metadata.getClassInfo(i);
549552
if (ClassInfoAccess.isValid(classInfo)) {
550-
writeSymbol(classInfo.getHub().getName());
553+
writeSymbol(classInfo.getHub().getName(), dotWithSlashReplacer);
551554
}
552555
}
553556
}
554557

555558
private void writeSymbol(String value) {
559+
writeSymbol(value, null);
560+
}
561+
562+
private void writeSymbol(String value, CharReplacer replacer) {
556563
startTopLevelRecord(HProfTopLevelRecord.UTF8);
557564
writeObjectId(value);
558-
writeUTF8(value);
565+
writeUTF8(value, replacer);
559566
endTopLevelRecord();
560567
}
561568

@@ -1109,7 +1116,11 @@ private void writeId0(long value) {
11091116
}
11101117

11111118
private void writeUTF8(String value) {
1112-
boolean success = file().writeUTF8(f, value);
1119+
writeUTF8(value, null);
1120+
}
1121+
1122+
private void writeUTF8(String value, CharReplacer replacer) {
1123+
boolean success = file().writeUTF8(f, value, replacer);
11131124
handleError(success);
11141125
}
11151126

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/UninterruptibleUtils.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE;
2828

29-
import jdk.graal.compiler.word.Word;
3029
import org.graalvm.word.Pointer;
3130
import org.graalvm.word.PointerBase;
3231
import org.graalvm.word.UnsignedWord;
@@ -37,6 +36,7 @@
3736
import com.oracle.svm.core.util.VMError;
3837

3938
import jdk.graal.compiler.core.common.SuppressFBWarnings;
39+
import jdk.graal.compiler.word.Word;
4040
import jdk.internal.misc.Unsafe;
4141

4242
/**
@@ -714,6 +714,17 @@ public interface CharReplacer {
714714
char replace(char val);
715715
}
716716

717+
public static final class ReplaceDotWithSlash implements CharReplacer {
718+
@Override
719+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
720+
public char replace(char ch) {
721+
if (ch == '.') {
722+
return '/';
723+
}
724+
return ch;
725+
}
726+
}
727+
717728
public static class CodeUtil {
718729
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
719730
public static long signExtend(long value, int inputBits) {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrSymbolRepository.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.oracle.svm.core.heap.Heap;
3939
import com.oracle.svm.core.jdk.UninterruptibleUtils;
4040
import com.oracle.svm.core.jdk.UninterruptibleUtils.CharReplacer;
41+
import com.oracle.svm.core.jdk.UninterruptibleUtils.ReplaceDotWithSlash;
4142
import com.oracle.svm.core.jfr.traceid.JfrTraceIdEpoch;
4243
import com.oracle.svm.core.locks.VMMutex;
4344
import com.oracle.svm.core.nmt.NmtCategory;
@@ -244,15 +245,4 @@ void teardown() {
244245
buffer = Word.nullPointer();
245246
}
246247
}
247-
248-
private static final class ReplaceDotWithSlash implements CharReplacer {
249-
@Override
250-
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
251-
public char replace(char ch) {
252-
if (ch == '.') {
253-
return '/';
254-
}
255-
return ch;
256-
}
257-
}
258248
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/BufferedFileOperationSupport.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.oracle.svm.core.hub.DynamicHub;
4444
import com.oracle.svm.core.hub.LayoutEncoding;
4545
import com.oracle.svm.core.jdk.UninterruptibleUtils;
46+
import com.oracle.svm.core.jdk.UninterruptibleUtils.CharReplacer;
4647
import com.oracle.svm.core.memory.NullableNativeMemory;
4748
import com.oracle.svm.core.nmt.NmtCategory;
4849
import com.oracle.svm.core.os.BufferedFileOperationSupport.BufferedFileOperationSupportHolder;
@@ -343,17 +344,26 @@ public boolean writeDouble(BufferedFile f, double v) {
343344
return writeLong(f, Double.doubleToLongBits(v));
344345
}
345346

347+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
348+
public boolean writeUTF8(BufferedFile f, String string) {
349+
return writeUTF8(f, string, null);
350+
}
351+
346352
/**
347353
* Writes the String characters encoded as UTF8 to the current file position and advances the
348354
* file position.
349355
*
350356
* @return true if the data was written, false otherwise.
351357
*/
352358
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
353-
public boolean writeUTF8(BufferedFile f, String string) {
359+
public boolean writeUTF8(BufferedFile f, String string, CharReplacer replacer) {
354360
boolean success = true;
355361
for (int index = 0; index < string.length() && success; index++) {
356-
success &= writeUTF8(f, UninterruptibleUtils.String.charAt(string, index));
362+
char ch = UninterruptibleUtils.String.charAt(string, index);
363+
if (replacer != null) {
364+
ch = replacer.replace(ch);
365+
}
366+
success &= writeUTF8(f, ch);
357367
}
358368
return success;
359369
}

0 commit comments

Comments
 (0)