Skip to content

Instantly share code, notes, and snippets.

View jpbempel's full-sized avatar

Jean-Philippe Bempel jpbempel

View GitHub Profile
@jpbempel
jpbempel / exportToCollapsed.java
Created March 3, 2021 14:09
Export JFR events as collapsed format to be able to generate flamegraph
void exportToCollapsed(IItemCollection events, File outputFile) throws IOException {
IMemberAccessor<IMCStackTrace, IItem> ACCESSOR_STACKTRACE = ItemToolkit.accessor(JfrAttributes.EVENT_STACKTRACE);
try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) {
for (IItemIterable chunk : events) {
for (IItem sample : chunk) {
IMCStackTrace stackTrace = ACCESSOR_STACKTRACE.getMember(sample);
if (stackTrace == null) {
continue;
}
List<? extends IMCFrame> frames = stackTrace.getFrames();
361 64 java.util.ArrayList::ensureExplicitCapacity (26 bytes)
@ 22 java.util.ArrayList::grow (45 bytes) force inline by CompilerOracle
@ 28 java.util.ArrayList::hugeCapacity (26 bytes) never executed
@ 38 java.util.Arrays::copyOf (13 bytes) executed < MinInliningThreshold times
@ 19 java.util.ArrayList::ensureExplicitCapacity (26 bytes) inline (hot)
@ 22 java.util.ArrayList::grow (45 bytes) force inline by CompilerOracle
@ 28 java.util.ArrayList::hugeCapacity (26 bytes) never executed
@ 38 java.util.Arrays::copyOf (13 bytes) executed < MinInliningThreshold times
612 64 java.util.ArrayList::ensureExplicitCapacity (26 bytes)
@ 22 java.util.ArrayList::grow (45 bytes) too big
@ 19 java.util.ArrayList::ensureExplicitCapacity (26 bytes) inline (hot)
@ 22 java.util.ArrayList::grow (45 bytes) too big
public static void main(String[] args) throws InterruptedException {
List<String> list = new ArrayList<>();
for (int i = 0; i < 10_000; i++)
{
list.add(String.valueOf(i));
}
Thread.sleep(1000);
}
0x0000000002d2a7df: lea r10,[r11+r9*4+0x10]
0x0000000002d2a7e4: mov r11,QWORD PTR [rsp+0x8]
0x0000000002d2a7e9: mov r8,r11
0x0000000002d2a7ec: mov DWORD PTR [r10],r8d
0x0000000002d2a7ef: shr r10,0x9
0x0000000002d2a7f3: mov eax,0x1
0x0000000002d2a7f8: mov r11d,0x5965000
0x0000000002d2a7fe: mov BYTE PTR [r11+r10*1],r12b
;*synchronization entry
; - java.util.ArrayList::add@-1 (line 458)
0x0000000002d2a807: test DWORD PTR [rip+0xfffffffffe5857f3],eax # 0x00000000012b0000
; {poll_return}
0x0000000002d2a7d3: cmp r10d,0x200022ee ; {metadata('java/lang/Object'[])}
0x0000000002d2a7b2: mov r10d,DWORD PTR [r11+0xc] ; implicit exception: dispatches to 0x0000000002d2a881
0x0000000002d2a7af: inc DWORD PTR [rdx+0xc] ;*putfield modCount
; - java.util.ArrayList::ensureExplicitCapacity@7 (line 231)
; - java.util.ArrayList::ensureCapacityInternal@19 (line 227)
; - java.util.ArrayList::add@7 (line 458)
0x0000000002d2a7a2: cmp r11d,0xd5d0e088 ; {oop(a 'java/lang/Object'[0] )}
0x0000000002d2a7a9: je 0x0000000002d2a861 ;*if_acmpne
; - java.util.ArrayList::ensureCapacityInternal@7 (line 223)
; - java.util.ArrayList::add@7 (line 458)