diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/oldobject/JfrOldObjectSampler.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/oldobject/JfrOldObjectSampler.java index 36a7b0254645..19258c9da4a3 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/oldobject/JfrOldObjectSampler.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/oldobject/JfrOldObjectSampler.java @@ -120,9 +120,12 @@ private void remove(JfrOldObject sample) { next.increaseSpan(sample.getSpan()); queue.add(next); } else { - /* No remaining elements, we can't redistribute the weight. */ + /* + * No younger element, we can't redistribute the weight. The next sample should absorb + * the extra span. + */ totalInQueue = totalInQueue.subtract(sample.getSpan()); - assert totalInQueue.equal(0); + assert totalInQueue.aboveOrEqual(0); } queue.remove(sample); release(sample); diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/oldobject/TestOldObjectProfiler.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/oldobject/TestOldObjectProfiler.java index 5a1096bebd53..9886db719b49 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/oldobject/TestOldObjectProfiler.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/oldobject/TestOldObjectProfiler.java @@ -33,8 +33,10 @@ import java.util.Collections; import java.util.List; +import jdk.jfr.Recording; import org.graalvm.word.WordFactory; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; import com.oracle.svm.core.jfr.HasJfrSupport; @@ -45,6 +47,16 @@ import jdk.graal.compiler.api.directives.GraalDirectives; public class TestOldObjectProfiler extends AbstractJfrTest { + + /* + * Old object samples will not have allocation ticks set correctly if JfrTicks is not first + * initialized. We need to create the first JFR recording to lazily initialize JfrTicks. + */ + @BeforeClass + public static void initializeJfrTicks() { + GraalDirectives.blackhole(new Recording()); + } + @Test public void testScavenge() { int count = 10;