You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix two correctness bugs:
- INSTANCE_DUMP: stackTraceSerialNumber is always u4 (4 bytes), not
identifier-sized. This was silently corrupting output for heap dumps
with 8-byte identifiers.
- PRIMITIVE_ARRAY_DUMP: CopyingSource.transferUnsignedByte() already
copies the type byte to the sink — the extra sink.writeByte(type) call
was writing it twice, corrupting all primitive array records.
Fix a third bug in CopyingSource.transferUtf8: it decoded bytes as
UTF-8 into a Java String then re-encoded, which produces different byte
counts for Modified UTF-8 sequences (used by HotSpot HPROF). The fix
reads the raw bytes and copies them unchanged, only decoding to String
for the return value.
Other changes:
- Add StreamingSinkProvider (mirrors StreamingSourceProvider) so the
sink lifecycle is managed inside the function via .use {}
- Replace BufferedSink parameter with StreamingSinkProvider in the
streaming overload
- Refactor parsing into a private stripPrimitiveArrays(CopyingSource)
method
- Add CopyingSource.indexOf delegate
- Also updates all primitive wrapper instance values to 0 (in addition
to primitive arrays), as an additional PII safety measure
- Add deleteInputHprofFile parameter to delete the input file eagerly
after the source is opened, using the Unix trick
- Clean up test: replace raw-byte helpers with HprofWriter-based
fixture, add JVM heap dump tests for string replacement and wrapper
value zeroing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: shark/shark-hprof/api/shark-hprof.api
+26-3Lines changed: 26 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,24 @@ public final class shark/ConstantMemoryMetricsDualSourceProvider : shark/DualSou
14
14
public fun openStreamingSource ()Lokio/BufferedSource;
15
15
}
16
16
17
+
public final class shark/CopyingSource {
18
+
public fun <init> (Lokio/BufferedSource;Lokio/BufferedSink;)V
19
+
public final fun exhausted ()Z
20
+
public final fun getBytesRead ()J
21
+
public final fun indexOf (B)J
22
+
public final fun overwrite ([B)V
23
+
public final fun transfer (I)V
24
+
public final fun transfer (J)V
25
+
public final fun transferByte ()B
26
+
public final fun transferInt ()I
27
+
public final fun transferLong ()J
28
+
public final fun transferShort ()I
29
+
public final fun transferUnsignedByte ()I
30
+
public final fun transferUnsignedInt ()J
31
+
public final fun transferUnsignedShort ()I
32
+
public final fun transferUtf8 (J)Ljava/lang/String;
33
+
}
34
+
17
35
public abstract interface class shark/DualSourceProvider : shark/RandomAccessSourceProvider, shark/StreamingSourceProvider {
18
36
}
19
37
@@ -150,9 +168,10 @@ public final class shark/HprofHeader$Companion {
150
168
151
169
public final class shark/HprofPrimitiveArrayStripper {
152
170
public fun <init> ()V
153
-
public final fun stripPrimitiveArrays (Ljava/io/File;Ljava/io/File;)Ljava/io/File;
154
-
public final fun stripPrimitiveArrays (Lshark/StreamingSourceProvider;Lokio/BufferedSink;)V
155
-
public static synthetic fun stripPrimitiveArrays$default (Lshark/HprofPrimitiveArrayStripper;Ljava/io/File;Ljava/io/File;ILjava/lang/Object;)Ljava/io/File;
171
+
public final fun stripPrimitiveArrays (Ljava/io/File;Ljava/io/File;Z)Ljava/io/File;
172
+
public final fun stripPrimitiveArrays (Lshark/StreamingSourceProvider;Lshark/StreamingSinkProvider;Lkotlin/jvm/functions/Function0;)V
173
+
public static synthetic fun stripPrimitiveArrays$default (Lshark/HprofPrimitiveArrayStripper;Ljava/io/File;Ljava/io/File;ZILjava/lang/Object;)Ljava/io/File;
174
+
public static synthetic fun stripPrimitiveArrays$default (Lshark/HprofPrimitiveArrayStripper;Lshark/StreamingSourceProvider;Lshark/StreamingSinkProvider;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V
156
175
}
157
176
158
177
public abstract class shark/HprofRecord {
@@ -583,6 +602,10 @@ public final class shark/StreamingRecordReaderAdapter$Companion {
583
602
public final fun asStreamingRecordReader (Lshark/StreamingHprofReader;)Lshark/StreamingRecordReaderAdapter;
584
603
}
585
604
605
+
public abstract interface class shark/StreamingSinkProvider {
606
+
public abstract fun openStreamingSink ()Lokio/BufferedSink;
607
+
}
608
+
586
609
public abstract interface class shark/StreamingSourceProvider {
587
610
public abstract fun openStreamingSource ()Lokio/BufferedSource;
0 commit comments