Skip to content

Commit 8520370

Browse files
committed
[GR-58038] [GR-55092] Phase plan fuzzing fixes
PullRequest: graal/18842
2 parents 373db91 + db2e208 commit 8520370

File tree

7 files changed

+51
-14
lines changed

7 files changed

+51
-14
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotFuzzedSuitesProvider.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2024, 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
@@ -32,14 +32,17 @@
3232
import jdk.graal.compiler.options.OptionValues;
3333
import jdk.graal.compiler.phases.tiers.Suites;
3434
import jdk.graal.compiler.phases.tiers.SuitesProvider;
35-
35+
import jdk.graal.compiler.serviceprovider.GraalServices;
3636
import jdk.vm.ci.code.Architecture;
3737

3838
/**
3939
* {@link SuitesProvider} that provides different {@link FuzzedSuites} for each call to
4040
* {@link SuitesProvider#getDefaultSuites}.
4141
*/
4242
public class HotSpotFuzzedSuitesProvider extends HotSpotSuitesProvider {
43+
44+
public static final String SEED_SYSTEM_PROPERTY = "test.graal.compilationplan.fuzzing.seed";
45+
4346
private static ThreadLocal<Long> lastSeed = new ThreadLocal<>();
4447

4548
private final HotSpotSuitesProvider provider;
@@ -53,7 +56,13 @@ public HotSpotFuzzedSuitesProvider(HotSpotSuitesProvider provider) {
5356

5457
@Override
5558
public Suites getDefaultSuites(OptionValues options, Architecture arch) {
56-
long seed = random.nextLong();
59+
long seed;
60+
String seedString = GraalServices.getSavedProperty(SEED_SYSTEM_PROPERTY);
61+
if (seedString != null) {
62+
seed = Long.parseLong(seedString);
63+
} else {
64+
seed = random.nextLong();
65+
}
5766
lastSeed.set(seed);
5867
return createSuites(options, seed);
5968
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/loop/phases/LoopPeelingPhase.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024, 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
@@ -64,13 +64,16 @@ public Optional<NotApplicable> notApplicableTo(GraphState graphState) {
6464
return NotApplicable.ifAny(
6565
super.notApplicableTo(graphState),
6666
// keep in sync with stateAllowsPeeling()
67+
NotApplicable.unlessRunAfter(this, StageFlag.LOOP_OVERFLOWS_CHECKED, graphState),
6768
NotApplicable.unlessRunBefore(this, StageFlag.FSA, graphState),
6869
NotApplicable.unlessRunBefore(this, StageFlag.VALUE_PROXY_REMOVAL, graphState));
6970
}
7071

7172
private static boolean stateAllowsPeeling(GraphState graphState) {
7273
// keep in sync with notApplicableTo()
73-
return graphState.isBeforeStage(StageFlag.FSA) && graphState.isBeforeStage(StageFlag.VALUE_PROXY_REMOVAL);
74+
return graphState.isAfterStage(StageFlag.LOOP_OVERFLOWS_CHECKED) &&
75+
graphState.isBeforeStage(StageFlag.FSA) &&
76+
graphState.isBeforeStage(StageFlag.VALUE_PROXY_REMOVAL);
7477
}
7578

7679
@Override

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/loop/phases/LoopSafepointEliminationPhase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2024, 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
@@ -122,7 +122,7 @@ public static boolean loopIsIn32BitRange(Loop loop) {
122122

123123
@Override
124124
public Optional<NotApplicable> notApplicableTo(GraphState graphState) {
125-
return ALWAYS_APPLICABLE;
125+
return NotApplicable.unlessRunAfter(this, GraphState.StageFlag.LOOP_OVERFLOWS_CHECKED, graphState);
126126
}
127127

128128
@Override

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/common/AbstractInliningPhase.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2024, 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
@@ -26,8 +26,10 @@
2626

2727
import java.util.Optional;
2828

29+
import jdk.graal.compiler.graph.Graph;
2930
import jdk.graal.compiler.nodes.GraphState;
3031
import jdk.graal.compiler.nodes.GraphState.StageFlag;
32+
import jdk.graal.compiler.nodes.StructuredGraph;
3133
import jdk.graal.compiler.phases.BasePhase;
3234
import jdk.graal.compiler.phases.tiers.HighTierContext;
3335

@@ -41,4 +43,24 @@ public Optional<NotApplicable> notApplicableTo(GraphState graphState) {
4143
NotApplicable.unlessRunBefore(this, StageFlag.HIGH_TIER_LOWERING, graphState),
4244
NotApplicable.unlessRunBefore(this, StageFlag.FINAL_CANONICALIZATION, graphState));
4345
}
46+
47+
@Override
48+
protected final void run(StructuredGraph graph, HighTierContext context) {
49+
Graph.Mark mark = graph.getMark();
50+
runInlining(graph, context);
51+
if (!mark.isCurrent() && graph.getSpeculationLog() != null && graph.hasLoops()) {
52+
/*
53+
* We may have inlined new loops. We must make sure that counted loops are checked for
54+
* overflow before we apply the next loop optimization phase. Inlining may run multiple
55+
* times in different versions, possibly after some loop optimizations, and even on
56+
* demand (i.e., without explicitly appearing in the phase plan). For such phases the
57+
* stage flag mechanism isn't strong enough to express the constraint that we must run
58+
* DisableOverflownCountedLoops before the next loop phase. Therefore, run it
59+
* explicitly.
60+
*/
61+
new DisableOverflownCountedLoopsPhase().run(graph);
62+
}
63+
}
64+
65+
protected abstract void runInlining(StructuredGraph graph, HighTierContext context);
4466
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/common/DisableOverflownCountedLoopsPhase.java

Lines changed: 5 additions & 2 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, 2024, 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
@@ -64,9 +64,12 @@ protected void run(StructuredGraph graph) {
6464
@Override
6565
public void updateGraphState(GraphState graphState) {
6666
super.updateGraphState(graphState);
67+
graphState.removeRequirementToStage(LOOP_OVERFLOWS_CHECKED);
6768
/*
6869
* This phase can run multiple times which is fine as long as we run it before all loop
69-
* phases.
70+
* phases. Note that newly inlined loops after this phase essentially invalidate this flag,
71+
* but we have no formal invalidation mechanism. Inlining must therefore run this phase
72+
* explicitly if it introduces new loops.
7073
*/
7174
if (graphState.isBeforeStage(LOOP_OVERFLOWS_CHECKED)) {
7275
graphState.setAfterStage(LOOP_OVERFLOWS_CHECKED);

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/common/inlining/InliningPhase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2024, 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
@@ -87,7 +87,7 @@ public float codeSizeIncrease() {
8787
*
8888
*/
8989
@Override
90-
protected void run(final StructuredGraph graph, final HighTierContext context) {
90+
protected void runInlining(final StructuredGraph graph, final HighTierContext context) {
9191
final InliningData data = new InliningData(graph, context, maxMethodPerInlining, canonicalizer, inliningPolicy, rootInvokes);
9292

9393
int count = 0;

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/host/HostInliningPhase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2024, 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
@@ -179,7 +179,7 @@ private boolean isTransferToInterpreterMethod(InliningPhaseContext context, Reso
179179
}
180180

181181
@Override
182-
protected final void run(StructuredGraph graph, HighTierContext highTierContext) {
182+
protected final void runInlining(StructuredGraph graph, HighTierContext highTierContext) {
183183
ResolvedJavaMethod method = graph.method();
184184
TruffleHostEnvironment env = TruffleHostEnvironment.get(method);
185185
if (env == null) {

0 commit comments

Comments
 (0)