diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/JfrGCHeapSummaryEvent.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/JfrGCHeapSummaryEvent.java index 232456a9fc2..76194023be8 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/JfrGCHeapSummaryEvent.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/JfrGCHeapSummaryEvent.java @@ -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); diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/AbstractJfrTest.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/AbstractJfrTest.java index ffde76ad560..73b95ece753 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/AbstractJfrTest.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/AbstractJfrTest.java @@ -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; @@ -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 { @@ -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); + } } diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestGCHeapSummaryEvent.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestGCHeapSummaryEvent.java index b0f457a7344..627cb16d408 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestGCHeapSummaryEvent.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestGCHeapSummaryEvent.java @@ -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; @@ -35,6 +36,7 @@ import jdk.jfr.Recording; import jdk.jfr.consumer.RecordedEvent; +import jdk.jfr.consumer.RecordedObject; public class TestGCHeapSummaryEvent extends JfrRecordingTest { @Test @@ -49,5 +51,18 @@ public void test() throws Throwable { private static void validateEvents(List 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); + } } }