Skip to content

Commit f56e8ce

Browse files
christianhaeublbulasevich
authored andcommitted
In heap dumps, use the slash format instead of the dot format for class names.
(cherry picked from commit e367a6e0070875650812ae834ab49f1205f71db4)
1 parent adf733c commit f56e8ce

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
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
@@ -76,6 +76,8 @@
7676
import com.oracle.svm.core.heap.dump.HeapDumpMetadata.FieldNameAccess;
7777
import com.oracle.svm.core.hub.DynamicHub;
7878
import com.oracle.svm.core.hub.LayoutEncoding;
79+
import com.oracle.svm.core.jdk.UninterruptibleUtils.CharReplacer;
80+
import com.oracle.svm.core.jdk.UninterruptibleUtils.ReplaceDotWithSlash;
7981
import com.oracle.svm.core.log.Log;
8082
import com.oracle.svm.core.os.BufferedFileOperationSupport;
8183
import com.oracle.svm.core.os.BufferedFileOperationSupport.BufferedFile;
@@ -396,6 +398,7 @@ public class HeapDumpWriter {
396398
private static final int HEAP_DUMP_SEGMENT_TARGET_SIZE = 1 * 1024 * 1024;
397399

398400
private final NoAllocationVerifier noAllocationVerifier = NoAllocationVerifier.factory("HeapDumpWriter", false);
401+
private final ReplaceDotWithSlash dotWithSlashReplacer = new ReplaceDotWithSlash();
399402
private final DumpStackFrameVisitor dumpStackFrameVisitor = new DumpStackFrameVisitor();
400403
private final DumpObjectsVisitor dumpObjectsVisitor = new DumpObjectsVisitor();
401404
private final CodeMetadataVisitor codeMetadataVisitor = new CodeMetadataVisitor();
@@ -543,15 +546,19 @@ private void writeClassNames() {
543546
for (int i = 0; i < metadata.getClassInfoCount(); i++) {
544547
ClassInfo classInfo = metadata.getClassInfo(i);
545548
if (ClassInfoAccess.isValid(classInfo)) {
546-
writeSymbol(classInfo.getHub().getName());
549+
writeSymbol(classInfo.getHub().getName(), dotWithSlashReplacer);
547550
}
548551
}
549552
}
550553

551554
private void writeSymbol(String value) {
555+
writeSymbol(value, null);
556+
}
557+
558+
private void writeSymbol(String value, CharReplacer replacer) {
552559
startTopLevelRecord(HProfTopLevelRecord.UTF8);
553560
writeObjectId(value);
554-
writeUTF8(value);
561+
writeUTF8(value, replacer);
555562
endTopLevelRecord();
556563
}
557564

@@ -1107,7 +1114,11 @@ private void writeId0(long value) {
11071114
}
11081115

11091116
private void writeUTF8(String value) {
1110-
boolean success = file().writeUTF8(f, value);
1117+
writeUTF8(value, null);
1118+
}
1119+
1120+
private void writeUTF8(String value, CharReplacer replacer) {
1121+
boolean success = file().writeUTF8(f, value, replacer);
11111122
handleError(success);
11121123
}
11131124

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,4 +627,15 @@ public interface CharReplacer {
627627
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
628628
char replace(char val);
629629
}
630+
631+
public static final class ReplaceDotWithSlash implements CharReplacer {
632+
@Override
633+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
634+
public char replace(char ch) {
635+
if (ch == '.') {
636+
return '/';
637+
}
638+
return ch;
639+
}
640+
}
630641
}

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
@@ -41,6 +41,7 @@
4141
import com.oracle.svm.core.heap.Heap;
4242
import com.oracle.svm.core.jdk.UninterruptibleUtils;
4343
import com.oracle.svm.core.jdk.UninterruptibleUtils.CharReplacer;
44+
import com.oracle.svm.core.jdk.UninterruptibleUtils.ReplaceDotWithSlash;
4445
import com.oracle.svm.core.jfr.traceid.JfrTraceIdEpoch;
4546
import com.oracle.svm.core.locks.VMMutex;
4647

@@ -238,15 +239,4 @@ void teardown() {
238239
buffer = WordFactory.nullPointer();
239240
}
240241
}
241-
242-
private static class ReplaceDotWithSlash implements CharReplacer {
243-
@Override
244-
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
245-
public char replace(char ch) {
246-
if (ch == '.') {
247-
return '/';
248-
}
249-
return ch;
250-
}
251-
}
252242
}

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
@@ -47,6 +47,7 @@
4747
import com.oracle.svm.core.hub.DynamicHub;
4848
import com.oracle.svm.core.hub.LayoutEncoding;
4949
import com.oracle.svm.core.jdk.JavaLangSubstitutions;
50+
import com.oracle.svm.core.jdk.UninterruptibleUtils.CharReplacer;
5051
import com.oracle.svm.core.os.BufferedFileOperationSupport.BufferedFileOperationSupportHolder;
5152
import com.oracle.svm.core.os.RawFileOperationSupport.RawFileDescriptor;
5253
import com.oracle.svm.core.snippets.KnownIntrinsics;
@@ -342,17 +343,26 @@ public boolean writeDouble(BufferedFile f, double v) {
342343
return writeLong(f, Double.doubleToLongBits(v));
343344
}
344345

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

0 commit comments

Comments
 (0)