Skip to content

Commit 6fee397

Browse files
committed
invalidate compilation that was installed as default after test
1 parent 9c4c400 commit 6fee397

16 files changed

+66
-95
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/CountedLoopOverflowTest.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,18 +24,18 @@
2424
*/
2525
package jdk.graal.compiler.core.test;
2626

27-
import java.util.Collections;
2827
import java.util.EnumMap;
2928
import java.util.EnumSet;
3029
import java.util.Formatter;
3130
import java.util.Map;
31+
import java.util.Set;
32+
33+
import org.junit.Test;
3234

3335
import jdk.graal.compiler.api.directives.GraalDirectives;
3436
import jdk.graal.compiler.core.common.GraalOptions;
3537
import jdk.graal.compiler.options.OptionValues;
3638
import jdk.graal.compiler.phases.OptimisticOptimizations;
37-
import org.junit.Test;
38-
3939
import jdk.vm.ci.meta.DeoptimizationReason;
4040
import jdk.vm.ci.meta.ProfilingInfo;
4141
import jdk.vm.ci.meta.ResolvedJavaMethod;
@@ -121,19 +121,14 @@ public void testDownOverflow() {
121121
// first should deopt with a failed speculation, second not
122122
Map<DeoptimizationReason, Integer> deoptCountsBefore = getDeoptCounts(method);
123123
try {
124-
executeActualCheckDeopt(new OptionValues(getInitialOptions(), GraalOptions.LoopPeeling, false, GraalOptions.FullUnroll, false), method, Collections.emptySet(), null);
124+
executeActualCheckDeopt(new OptionValues(getInitialOptions(), GraalOptions.LoopPeeling, false, GraalOptions.FullUnroll, false), method, true, Set.of(), null);
125125
deoptCountsBefore = getDeoptCounts(method);
126126
executeActualCheckDeopt(new OptionValues(getInitialOptions(), GraalOptions.LoopPeeling, false, GraalOptions.FullUnroll, false), method, EnumSet.allOf(DeoptimizationReason.class), null);
127127
} catch (Throwable t) {
128128
throw new AssertionError(deoptsToString(method, deoptCountsBefore), t);
129129
}
130130
}
131131

132-
@Override
133-
protected boolean installAsDefault() {
134-
return true;
135-
}
136-
137132
@Test
138133
public void testDownOverflowUnsigned() {
139134
try {
@@ -147,7 +142,7 @@ public void testDownOverflowUnsigned() {
147142
// first should deopt with a failed speculation, second not
148143
Map<DeoptimizationReason, Integer> deoptCountsBefore = getDeoptCounts(method);
149144
try {
150-
executeActualCheckDeopt(new OptionValues(getInitialOptions(), GraalOptions.LoopPeeling, false, GraalOptions.FullUnroll, false), method, Collections.emptySet(), null);
145+
executeActualCheckDeopt(new OptionValues(getInitialOptions(), GraalOptions.LoopPeeling, false, GraalOptions.FullUnroll, false), method, true, Set.of(), null);
151146
deoptCountsBefore = getDeoptCounts(method);
152147
executeActualCheckDeopt(new OptionValues(getInitialOptions(), GraalOptions.LoopPeeling, false, GraalOptions.FullUnroll, false), method, EnumSet.allOf(DeoptimizationReason.class), null);
153148
} catch (Throwable t) {
@@ -168,7 +163,7 @@ public void testUpOverflow() {
168163
// first should deopt with a failed speculation, second not
169164
Map<DeoptimizationReason, Integer> deoptCountsBefore = getDeoptCounts(method);
170165
try {
171-
executeActualCheckDeopt(new OptionValues(getInitialOptions(), GraalOptions.LoopPeeling, false, GraalOptions.FullUnroll, false), method, Collections.emptySet(), null);
166+
executeActualCheckDeopt(new OptionValues(getInitialOptions(), GraalOptions.LoopPeeling, false, GraalOptions.FullUnroll, false), method, true, Set.of(), null);
172167
deoptCountsBefore = getDeoptCounts(method);
173168
executeActualCheckDeopt(new OptionValues(getInitialOptions(), GraalOptions.LoopPeeling, false, GraalOptions.FullUnroll, false), method, EnumSet.allOf(DeoptimizationReason.class), null);
174169
} catch (Throwable t) {

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/GraalCompilerTest.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,10 @@ protected Result executeActual(OptionValues options, ResolvedJavaMethod method,
917917
} catch (Throwable e) {
918918
return new Result(null, e);
919919
} finally {
920+
// Prevent a subsequent `executeExpected' call from entering the compiled method
921+
if (installAsDefault) {
922+
compiledMethod.invalidate();
923+
}
920924
after();
921925
}
922926
}
@@ -1010,9 +1014,13 @@ protected Result test(ResolvedJavaMethod method, Object receiver, Object... args
10101014
}
10111015

10121016
protected Result test(OptionValues options, ResolvedJavaMethod method, Object receiver, Object... args) {
1017+
return test(options, method, false, receiver, args);
1018+
}
1019+
1020+
protected final Result test(OptionValues options, ResolvedJavaMethod method, boolean installAsDefault, Object receiver, Object... args) {
10131021
Result expect = executeExpected(method, receiver, args);
10141022
if (getCodeCache() != null) {
1015-
testAgainstExpected(options, method, expect, receiver, args);
1023+
testAgainstExpected(options, method, installAsDefault, expect, Set.of(), receiver, args);
10161024
}
10171025
return expect;
10181026
}
@@ -1035,29 +1043,34 @@ protected Object[] applyArgSuppliers(Object... args) {
10351043
}
10361044

10371045
protected final void testAgainstExpected(ResolvedJavaMethod method, Result expect, Object receiver, Object... args) {
1038-
testAgainstExpected(getInitialOptions(), method, expect, Collections.<DeoptimizationReason> emptySet(), receiver, args);
1039-
}
1040-
1041-
protected void testAgainstExpected(ResolvedJavaMethod method, Result expect, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) {
1042-
testAgainstExpected(getInitialOptions(), method, expect, shouldNotDeopt, receiver, args);
1046+
testAgainstExpected(getInitialOptions(), method, false, expect, Set.of(), receiver, args);
10431047
}
10441048

10451049
protected final void testAgainstExpected(OptionValues options, ResolvedJavaMethod method, Result expect, Object receiver, Object... args) {
1046-
testAgainstExpected(options, method, expect, Collections.<DeoptimizationReason> emptySet(), receiver, args);
1050+
testAgainstExpected(options, method, false, expect, Set.of(), receiver, args);
10471051
}
10481052

10491053
protected void testAgainstExpected(OptionValues options, ResolvedJavaMethod method, Result expect, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) {
1050-
Result actual = executeActualCheckDeopt(options, method, shouldNotDeopt, receiver, args);
1054+
testAgainstExpected(options, method, true, expect, shouldNotDeopt, receiver, args);
1055+
}
1056+
1057+
private void testAgainstExpected(OptionValues options, ResolvedJavaMethod method, boolean installAsDefault, Result expect, Set<DeoptimizationReason> shouldNotDeopt, Object receiver,
1058+
Object... args) {
1059+
Result actual = executeActualCheckDeopt(options, method, installAsDefault, shouldNotDeopt, receiver, args);
10511060
assertEquals(expect, actual);
10521061
}
10531062

1054-
protected Result executeActualCheckDeopt(OptionValues options, ResolvedJavaMethod method, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) {
1063+
protected final Result executeActualCheckDeopt(OptionValues options, ResolvedJavaMethod method, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) {
1064+
return executeActualCheckDeopt(options, method, !shouldNotDeopt.isEmpty(), shouldNotDeopt, receiver, args);
1065+
}
1066+
1067+
protected final Result executeActualCheckDeopt(OptionValues options, ResolvedJavaMethod method, boolean installAsDefault, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) {
10551068
Map<DeoptimizationReason, Integer> deoptCounts = new EnumMap<>(DeoptimizationReason.class);
10561069
ProfilingInfo profile = method.getProfilingInfo();
10571070
for (DeoptimizationReason reason : shouldNotDeopt) {
10581071
deoptCounts.put(reason, profile.getDeoptimizationCount(reason));
10591072
}
1060-
Result actual = executeActual(options, method, !shouldNotDeopt.isEmpty(), receiver, args);
1073+
Result actual = executeActual(options, method, installAsDefault, receiver, args);
10611074
profile = method.getProfilingInfo(); // profile can change after execution
10621075
for (DeoptimizationReason reason : shouldNotDeopt) {
10631076
Assert.assertEquals("wrong number of deopt counts for " + reason, (int) deoptCounts.get(reason), profile.getDeoptimizationCount(reason));
@@ -1166,7 +1179,7 @@ protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, Str
11661179
try (DebugContext.Scope _ = debug.scope("CodeInstall", getCodeCache(), installedCodeOwner, compResult);
11671180
DebugContext.Activation _ = debug.activate()) {
11681181
try {
1169-
if (installAsDefault || installAsDefault()) {
1182+
if (installAsDefault) {
11701183
installedCode = addDefaultMethod(debug, installedCodeOwner, compResult);
11711184
} else {
11721185
installedCode = addMethod(debug, installedCodeOwner, compResult);
@@ -1190,23 +1203,14 @@ protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, Str
11901203
} catch (Throwable e) {
11911204
throw debug.handle(e);
11921205
}
1193-
1194-
if (useCache) {
1206+
if (useCache && !installAsDefault) {
11951207
cache.get().put(installedCodeOwner, Pair.create(options, installedCode));
11961208
}
11971209
return installedCode;
11981210
}
11991211
throw GraalError.shouldNotReachHere("Bailout limit reached"); // ExcludeFromJacocoGeneratedReport
12001212
}
12011213

1202-
/**
1203-
* Allows subclasses to override and install compiled code as the default. Note that since
1204-
* JDK26+5, deoptimization counts are only updated for default compiled code.
1205-
*/
1206-
protected boolean installAsDefault() {
1207-
return false;
1208-
}
1209-
12101214
private static boolean optionsMapDeepEquals(UnmodifiableEconomicMap<OptionKey<?>, Object> map1, UnmodifiableEconomicMap<OptionKey<?>, Object> map2) {
12111215
if (map1.size() != map2.size()) {
12121216
return false;

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/SubWordInputTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.lang.constant.ClassDesc;
3434
import java.lang.constant.MethodTypeDesc;
3535
import java.util.ArrayList;
36-
import java.util.Collections;
3736
import java.util.List;
3837

3938
import org.junit.Test;
@@ -78,7 +77,7 @@ public void testSubWordInput() throws ClassNotFoundException {
7877
getCode(getResolvedJavaMethod(testClass, GET), null, false, true, getInitialOptions());
7978
assertEquals(executeExpected(wrapper, null, value), expected);
8079
// test with inlining
81-
testAgainstExpected(wrapper, expected, Collections.emptySet(), null, value);
80+
testAgainstExpected(wrapper, expected, null, new Object[]{value});
8281
}
8382

8483
@Override

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/SubWordInputTest2.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.lang.constant.ClassDesc;
3434
import java.lang.constant.MethodTypeDesc;
3535
import java.util.ArrayList;
36-
import java.util.Collections;
3736
import java.util.List;
3837

3938
import org.junit.Test;
@@ -76,7 +75,7 @@ public void testSubWordInput() throws ClassNotFoundException {
7675
getCode(getResolvedJavaMethod(testClass, GET), null, false, true, getInitialOptions());
7776
assertEquals(executeExpected(wrapper, null, value), expected);
7877
// test with inlining
79-
testAgainstExpected(wrapper, expected, Collections.emptySet(), null, value);
78+
testAgainstExpected(wrapper, expected, null, new Object[]{value});
8079
}
8180

8281
@Override

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/lir/test/BenchmarkCounterOverflowTest.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -35,22 +35,20 @@
3535
import java.util.regex.Matcher;
3636
import java.util.regex.Pattern;
3737

38+
import org.junit.Assert;
39+
import org.junit.Assume;
40+
import org.junit.Before;
41+
import org.junit.Test;
42+
3843
import jdk.graal.compiler.api.directives.GraalDirectives;
39-
import jdk.graal.compiler.core.test.GraalCompilerTest;
40-
import jdk.graal.compiler.jtt.JTTTest;
41-
import jdk.graal.compiler.lir.jtt.LIRTest;
42-
import jdk.graal.compiler.lir.jtt.LIRTestSpecification;
4344
import jdk.graal.compiler.core.common.LIRKind;
4445
import jdk.graal.compiler.hotspot.HotSpotBackend;
4546
import jdk.graal.compiler.hotspot.debug.BenchmarkCounters;
4647
import jdk.graal.compiler.lir.ConstantValue;
4748
import jdk.graal.compiler.lir.gen.LIRGeneratorTool;
49+
import jdk.graal.compiler.lir.jtt.LIRTest;
50+
import jdk.graal.compiler.lir.jtt.LIRTestSpecification;
4851
import jdk.graal.compiler.test.SubprocessUtil;
49-
import org.junit.Assert;
50-
import org.junit.Assume;
51-
import org.junit.Before;
52-
import org.junit.Test;
53-
5452
import jdk.vm.ci.meta.JavaConstant;
5553
import jdk.vm.ci.meta.JavaKind;
5654
import jdk.vm.ci.meta.ResolvedJavaMethod;
@@ -97,7 +95,7 @@ public void incrementCounter() {
9795

9896
Object[] args = new Object[]{Integer.MAX_VALUE * 4L};
9997
ResolvedJavaMethod method = getResolvedJavaMethod("test");
100-
executeActualCheckDeopt(GraalCompilerTest.getInitialOptions(), method, JTTTest.EMPTY, null, args);
98+
executeActual(method, null, args);
10199
}
102100

103101
@Test

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/DeoptimizeReasonAccountingTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,11 @@ public void testDeoptimize() {
124124
for (boolean osr : new boolean[]{false}) {
125125
this.reason = r;
126126
this.isOSR = osr;
127-
test("deoptimizeSnippet");
127+
test(getInitialOptions(), getResolvedJavaMethod("deoptimizeSnippet"), true, null, new Object[0]);
128128
ProfilingInfo info = lastCompiledGraph.method().getProfilingInfo(!isOSR, isOSR);
129129
int count = info.getDeoptimizationCount(reason);
130130
Assert.assertEquals(String.format("reason:%s, osr:%s", r, osr), 1, count);
131131
}
132132
}
133133
}
134-
135-
@Override
136-
protected boolean installAsDefault() {
137-
return true;
138-
}
139134
}

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/RangeCheckPredicatesTest.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2020, Red Hat Inc. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -102,7 +102,7 @@ private void runOutOfBound(String methodName, int size, boolean loopLimitCheck,
102102
Object[] args = new Object[testParameters.length + 1];
103103
args[0] = array;
104104
System.arraycopy(testParameters, 0, args, 1, testParameters.length);
105-
Result result = executeActual(getOptionsMainPath(), method, null, args);
105+
Result result = executeActual(getOptionsMainPath(), method, true, null, args);
106106
Assert.assertNotNull(result.exception);
107107
Assert.assertTrue(result.exception instanceof ArrayIndexOutOfBoundsException);
108108
profile = method.getProfilingInfo();
@@ -1142,9 +1142,4 @@ public static int rangeCheckPredicatesGuardAboveExitTest(int[] array, int start,
11421142
public void testGuardAboveExitTest() {
11431143
verifyRangeCheckInLoop("rangeCheckPredicatesGuardAboveExitTest");
11441144
}
1145-
1146-
@Override
1147-
protected boolean installAsDefault() {
1148-
return true;
1149-
}
11501145
}

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/jtt/JTTTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030
import java.nio.file.Files;
3131
import java.nio.file.Paths;
3232
import java.util.Arrays;
33-
import java.util.Collections;
3433
import java.util.Formatter;
3534
import java.util.ListIterator;
3635
import java.util.Optional;
3736
import java.util.Set;
3837

38+
import org.junit.Assert;
39+
import org.junit.AssumptionViolatedException;
40+
3941
import jdk.graal.compiler.api.test.Graal;
4042
import jdk.graal.compiler.core.phases.fuzzing.AbstractCompilationPlan;
4143
import jdk.graal.compiler.core.phases.fuzzing.FullFuzzedCompilationPlan;
@@ -56,9 +58,6 @@
5658
import jdk.graal.compiler.phases.tiers.MidTierContext;
5759
import jdk.graal.compiler.phases.tiers.Suites;
5860
import jdk.graal.compiler.runtime.RuntimeProvider;
59-
import org.junit.Assert;
60-
import org.junit.AssumptionViolatedException;
61-
6261
import jdk.vm.ci.meta.DeoptimizationReason;
6362
import jdk.vm.ci.meta.ResolvedJavaMethod;
6463

@@ -80,7 +79,6 @@ public class JTTTest extends GraalCompilerTest {
8079
public static final class DummyTestClass {
8180
}
8281

83-
protected static final Set<DeoptimizationReason> EMPTY = Collections.<DeoptimizationReason> emptySet();
8482
/**
8583
* The arguments which, if non-null, will replace the Locals in the test method's graph.
8684
*/
@@ -134,7 +132,7 @@ protected void runTest(String name, Object... args) {
134132
}
135133

136134
protected void runTest(OptionValues options, String name, Object... args) {
137-
runTest(options, EMPTY, name, args);
135+
runTest(options, Set.of(), name, args);
138136
}
139137

140138
protected void runTest(Set<DeoptimizationReason> shouldNotDeopt, String name, Object... args) {
@@ -191,7 +189,7 @@ protected void runTest(OptionValues options, Set<DeoptimizationReason> shouldNot
191189
* to the usual compilation using {@link GraalCompilerTest#testAgainstExpected}.
192190
*/
193191
@Override
194-
protected void testAgainstExpected(OptionValues options, ResolvedJavaMethod method, Result expect, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) {
192+
protected final void testAgainstExpected(OptionValues options, ResolvedJavaMethod method, Result expect, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) {
195193
if (Boolean.getBoolean(COMPILATION_PLAN_FUZZING_SYSTEM_PROPERTY)) {
196194
testAgainstExpectedWithFuzzedCompilationPlan(options, method, expect, shouldNotDeopt, receiver, args);
197195
} else {

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/jtt/except/BC_getfield1.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -55,7 +55,7 @@ public void run0() throws Throwable {
5555
@Test
5656
public void run1() throws Throwable {
5757
// tests that the null check isn't removed along with the read
58-
runTest(EMPTY, "test", (Object) null);
58+
runTest("test", (Object) null);
5959
}
6060

6161
@Test

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/jtt/jdk/Unsafe_compareAndSwapNullCheck.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -57,6 +57,6 @@ public static void test(Unsafe_compareAndSwapNullCheck u, long expected, long ne
5757

5858
@Test
5959
public void run0() throws Throwable {
60-
runTest(EMPTY, "test", null, 1L, 2L);
60+
runTest("test", null, 1L, 2L);
6161
}
6262
}

0 commit comments

Comments
 (0)