Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix heap allocation measures with Java 18 #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
name: Java ${{ matrix.java }}
strategy:
matrix:
java: [8, 11, 12, 13, 14, 15, 16, 17]
java: [8, 11, 12, 13, 14, 15, 16, 17, 18]
env:
REPO_SLUG: ${{ github.repository }}
BRANCH: ${{ github.head_ref }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ public Statement methodInvoker(FrameworkMethod frameworkMethod, Object test) {
private int findJUnit4AllocationOffset() {
int allocationOffsetBeforeJava16 = findAllocationOffsetBeforeJava16();
JVM.Version jvmVersion = JVM.INSTANCE.version;
if(jvmVersion.isLessThanTo16()) {
if (jvmVersion.isLessThanTo16()) {
return allocationOffsetBeforeJava16;
}
if (jvmVersion.isGreaterThanOrEqualTo18()) {
return findAllocationOffsetFromJava18();
}
return allocationOffsetBeforeJava16 + 8;
}

Expand All @@ -100,6 +103,13 @@ private boolean junit4_13IsUsed() {
return junit4Version.startsWith("4.13");
}

private int findAllocationOffsetFromJava18() {
if (junit4_13IsUsed()) {
return 56_768;
}
return 56_800;
}

@Override
public Statement withBefores(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ public void beforeEach(ExtensionContext extensionContext) {

private int findJunit5AllocationOffset() {
JVM.Version jvmVersion = JVM.INSTANCE.version;
if(jvmVersion.isGreaterThanOrEqualTo18()) {
return 43_224;
}
if(jvmVersion.isGreaterThanOrEqualTo16()) {
return 48;
return 48;
}
return 40;
}
Expand Down
4 changes: 4 additions & 0 deletions jvm/jvm-core/src/main/java/org/quickperf/jvm/JVM.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public boolean isGreaterThanOrEqualTo16() {
return !is7() && !is8() && findJvmVersionAsInt() >= 16;
}

public boolean isGreaterThanOrEqualTo18() {
return !is7() && !is8() && findJvmVersionAsInt() >= 18;
}

public boolean isLessThanTo16() {
return !isGreaterThanOrEqualTo16();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public abstract class AbstractJUnit4SpringTestBase {

boolean testEnabled = true;

boolean noHeapAllocationTestEnabled = true;

@Test public void
a_test_throwing_an_assertion_error_and_a_performance_issue_should_fail() {

Expand Down Expand Up @@ -78,7 +80,7 @@ public abstract class AbstractJUnit4SpringTestBase {
@Test public void
a_test_method_having_a_performance_property_not_respected_in_a_dedicated_jvm_should_fail() {

if(!testEnabled) {
if(!testEnabled || !noHeapAllocationTestEnabled) {
return;
}

Expand All @@ -98,7 +100,7 @@ public abstract class AbstractJUnit4SpringTestBase {
@Test public void
a_test_method_allocating_and_annotated_with_no_allocation_should_fail() {

if(!testEnabled) {
if(!testEnabled || !noHeapAllocationTestEnabled) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.junit.runner.RunWith;
import org.quickperf.annotation.DisableQuickPerf;
import org.quickperf.annotation.FunctionalIteration;
import org.quickperf.jvm.JVM;
import org.quickperf.jvm.annotations.ExpectNoHeapAllocation;
import org.quickperf.spring.database.ClassWithAFailingTestAndTransactionalTestExecutionListener;
import org.quickperf.spring.junit4.QuickPerfSpringRunner;
Expand All @@ -26,6 +27,11 @@

public class JUnit4Spring5Test extends AbstractJUnit4SpringTestBase {

{
JVM.Version jvmVersion = JVM.INSTANCE.version;
noHeapAllocationTestEnabled = !jvmVersion.isGreaterThanOrEqualTo18();
}

private static class TestApplicationContextInitializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.testng.IHookable;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;
import org.testng.annotations.IFactoryAnnotation;

import java.lang.reflect.Method;
import java.util.Collection;
Expand Down Expand Up @@ -85,6 +86,9 @@ private TestExecutionContext buildTestExecutionContext(ITestResult testResult) {

private int findTestNGAllocationOffset() {
JVM.Version jvmVersion = JVM.INSTANCE.version;
if(jvmVersion.isGreaterThanOrEqualTo18()) {
return 56_800;
}
if(jvmVersion.isGreaterThanOrEqualTo16()) {
return 80;
}
Expand Down