Skip to content

Commit

Permalink
Merge pull request #2 from roberttoyonaga/GR-52940
Browse files Browse the repository at this point in the history
Backport of GR-52940: Fix reported values in GCHeapSummary JFR event
  • Loading branch information
zakkak authored Aug 28, 2024
2 parents cba7b53 + 810bf87 commit d2a466d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ private static void emit0(UnsignedWord gcEpoch, long start, UnsignedWord committ
JfrNativeEventWriter.putLong(data, gcWhen.getId());

// VirtualSpace
JfrNativeEventWriter.putLong(data, 0L); // start
JfrNativeEventWriter.putLong(data, 0L); // committedEnd
JfrNativeEventWriter.putLong(data, -1); // start
JfrNativeEventWriter.putLong(data, -1); // committedEnd
JfrNativeEventWriter.putLong(data, committedSize.rawValue());
JfrNativeEventWriter.putLong(data, 0L); // reservedEnd
JfrNativeEventWriter.putLong(data, 0L); // reservedSize
JfrNativeEventWriter.putLong(data, -1); // reservedEnd
// Reserved heap size matches committed size
JfrNativeEventWriter.putLong(data, committedSize.rawValue()); // reservedSize

JfrNativeEventWriter.putLong(data, heapUsed.rawValue());
JfrNativeEventWriter.endSmallEvent(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import org.graalvm.nativeimage.ImageInfo;
import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.nativeimage.hosted.RuntimeProxyCreation;
import org.junit.After;
import org.junit.Assert;
import org.junit.BeforeClass;
Expand All @@ -54,6 +55,7 @@
import jdk.jfr.Configuration;
import jdk.jfr.consumer.RecordedEvent;
import jdk.jfr.consumer.RecordingFile;
import jdk.jfr.Unsigned;

/** Base class for JFR unit tests. */
public abstract class AbstractJfrTest {
Expand Down Expand Up @@ -196,4 +198,16 @@ public void afterRegistration(AfterRegistrationAccess access) {
*/
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, JfrTestFeature.class, false, "jdk.internal.vm.compiler", "org.graalvm.compiler.serviceprovider");
}

@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
/*
* Register proxies for event data assertion
*
* Unsigned added to be able to query RecordedObject.getLong() method, and this method
* checks if the value returned has the jdk.jfr.Unsigned. The jfr layer in HotSpot creates a
* proxy to query this information.
*/
RuntimeProxyCreation.register(Unsigned.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package com.oracle.svm.test.jfr;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.List;
Expand All @@ -35,6 +36,7 @@

import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;
import jdk.jfr.consumer.RecordedObject;

public class TestGCHeapSummaryEvent extends JfrRecordingTest {
@Test
Expand All @@ -49,5 +51,18 @@ public void test() throws Throwable {

private static void validateEvents(List<RecordedEvent> events) {
assertTrue(events.size() > 0);
for (RecordedEvent event : events) {
RecordedObject heapSpace = event.getValue("heapSpace");
assertEquals(-1, heapSpace.getLong("start"));
assertEquals(-1, heapSpace.getLong("committedEnd"));
assertEquals(-1, heapSpace.getLong("reservedEnd"));

long committedSize = heapSpace.getLong("committedSize");
assertTrue(committedSize > 0);
assertTrue(heapSpace.getLong("reservedSize") >= committedSize);
assertTrue(event.getLong("gcId") >= 0);
assertTrue(event.getString("when").equals("Before GC") || event.getString("when").equals("After GC"));
assertTrue(event.getLong("heapUsed") > 0);
}
}
}

0 comments on commit d2a466d

Please sign in to comment.