Skip to content

Commit 4b51d24

Browse files
fix JFR GC events
1 parent 8fa7b17 commit 4b51d24

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/JfrGCEventSupport.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public void emitGarbageCollectionEvent(UnsignedWord gcEpoch, GCCause cause, long
7575
JfrNativeEventWriter.beginSmallEvent(data, JfrEvent.GarbageCollection);
7676
JfrNativeEventWriter.putLong(data, startTicks);
7777
JfrNativeEventWriter.putLong(data, duration);
78+
JfrNativeEventWriter.putEventThread(data);
7879
JfrNativeEventWriter.putLong(data, gcEpoch.rawValue());
7980
JfrNativeEventWriter.putLong(data, gcName.getId());
8081
JfrNativeEventWriter.putLong(data, cause.getId());
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2022, 2022, Red Hat Inc. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation. Oracle designates this
9+
* particular file as subject to the "Classpath" exception as provided
10+
* by Oracle in the LICENSE file that accompanied this code.
11+
*
12+
* This code is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15+
* version 2 for more details (a copy is included in the LICENSE file that
16+
* accompanied this code).
17+
*
18+
* You should have received a copy of the GNU General Public License version
19+
* 2 along with this work; if not, write to the Free Software Foundation,
20+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21+
*
22+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23+
* or visit www.oracle.com if you need additional information or have any
24+
* questions.
25+
*/
26+
27+
package com.oracle.svm.test.jfr;
28+
29+
import com.oracle.svm.core.jfr.JfrEvent;
30+
import jdk.jfr.Recording;
31+
import jdk.jfr.consumer.RecordedEvent;
32+
import jdk.jfr.consumer.RecordedThread;
33+
import org.junit.Test;
34+
35+
import java.util.List;
36+
37+
import static org.junit.Assert.assertTrue;
38+
39+
public class TestGarbageCollectionEvents extends JfrRecordingTest {
40+
@Test
41+
public void test() throws Throwable {
42+
String[] events = new String[]{JfrEvent.GarbageCollection.getName()};
43+
Recording recording = startRecording(events);
44+
System.gc();
45+
System.gc();
46+
System.gc();
47+
stopRecording(recording, TestGarbageCollectionEvents::validateEvents);
48+
}
49+
50+
private static void validateEvents(List<RecordedEvent> events) {
51+
assertTrue(events.size() > 0);
52+
int foundSystemGc = 0;
53+
int expectedId = 0;
54+
for (RecordedEvent event : events) {
55+
assertTrue(expectedId == event.getInt("gcId"));
56+
assertTrue(event.getThread("eventThread").getJavaName() != null);
57+
assertTrue(!event.getDuration().isZero());
58+
assertTrue(event.getString("name") != null);
59+
assertTrue(event.getLong("longestPause") > 0);
60+
assertTrue(event.getLong("sumOfPauses") > 0);
61+
if (event.getString("cause").equals("java.lang.System.gc()")) {
62+
foundSystemGc++;
63+
}
64+
expectedId++;
65+
}
66+
assertTrue(foundSystemGc >= 3);
67+
assertTrue(expectedId >= 3);
68+
}
69+
}

0 commit comments

Comments
 (0)