From b3480b482a9686bf6f6a5075d95d7f2e5c226af6 Mon Sep 17 00:00:00 2001 From: Robert Toyonaga Date: Mon, 25 Mar 2024 16:43:34 -0400 Subject: [PATCH 1/3] Add correct values to GCHeapSummary (cherry picked from commit f0a6a9c57a81292bc66f5998d8249c90a55727da) --- .../svm/core/genscavenge/JfrGCHeapSummaryEvent.java | 9 +++++---- .../oracle/svm/test/jfr/TestGCHeapSummaryEvent.java | 12 ++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) 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/TestGCHeapSummaryEvent.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestGCHeapSummaryEvent.java index b0f457a7344..95ba749f82e 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 @@ -29,6 +29,7 @@ import java.util.List; +import jdk.jfr.consumer.RecordedObject; import org.junit.Test; import com.oracle.svm.core.jfr.JfrEvent; @@ -49,5 +50,16 @@ public void test() throws Throwable { private static void validateEvents(List events) { assertTrue(events.size() > 0); + for (RecordedEvent event : events) { + RecordedObject heapSpace = event.getValue("heapSpace"); + assertTrue(heapSpace.getLong("start") == -1); + assertTrue(heapSpace.getLong("committedEnd") == -1); + assertTrue(heapSpace.getLong("reservedEnd") == -1); + assertTrue(heapSpace.getLong("committedSize") > 0); + assertTrue(heapSpace.getLong("reservedSize") >= heapSpace.getLong("committedSize")); + assertTrue(event.getLong("gcId") >= 0); + assertTrue(event.getString("when").equals("Before GC") || event.getString("when").equals("After GC")); + assertTrue(event.getLong("heapUsed") > 0); + } } } From 9045610a308f82338667760345bab401cc6c30cd Mon Sep 17 00:00:00 2001 From: Christian Haeubl Date: Wed, 27 Mar 2024 11:23:56 +0100 Subject: [PATCH 2/3] Minor cleanups. (cherry picked from commit 83b936ab7b8a9cde9532f5778eabbe19939a131f) --- .../svm/test/jfr/TestGCHeapSummaryEvent.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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 95ba749f82e..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,17 +25,18 @@ package com.oracle.svm.test.jfr; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.List; -import jdk.jfr.consumer.RecordedObject; import org.junit.Test; import com.oracle.svm.core.jfr.JfrEvent; import jdk.jfr.Recording; import jdk.jfr.consumer.RecordedEvent; +import jdk.jfr.consumer.RecordedObject; public class TestGCHeapSummaryEvent extends JfrRecordingTest { @Test @@ -52,11 +53,13 @@ private static void validateEvents(List events) { assertTrue(events.size() > 0); for (RecordedEvent event : events) { RecordedObject heapSpace = event.getValue("heapSpace"); - assertTrue(heapSpace.getLong("start") == -1); - assertTrue(heapSpace.getLong("committedEnd") == -1); - assertTrue(heapSpace.getLong("reservedEnd") == -1); - assertTrue(heapSpace.getLong("committedSize") > 0); - assertTrue(heapSpace.getLong("reservedSize") >= heapSpace.getLong("committedSize")); + 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); From 810bf87705db7e172edb4c92f6ebebabcc8f8a01 Mon Sep 17 00:00:00 2001 From: Robert Toyonaga Date: Tue, 20 Aug 2024 15:40:49 -0400 Subject: [PATCH 3/3] add JFR test proxy configuration. --- .../com/oracle/svm/test/jfr/AbstractJfrTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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); + } }