Skip to content

Commit

Permalink
[GR-52324] Add InsertGuardFencesPhase into runtime compilation phases.
Browse files Browse the repository at this point in the history
  • Loading branch information
tzezula committed Mar 1, 2024
1 parent 877d903 commit 3c8e0e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.List;
import java.util.Optional;

import jdk.graal.compiler.core.common.SpectrePHTMitigations;
import jdk.graal.compiler.core.common.type.IntegerStamp;
import jdk.graal.compiler.debug.Assertions;
import jdk.graal.compiler.debug.DebugContext;
Expand Down Expand Up @@ -68,6 +69,10 @@ public Optional<NotApplicable> notApplicableTo(GraphState graphState) {

@Override
protected void run(StructuredGraph graph) {
SpectrePHTMitigations mitigations = SpectrePHTBarriers.getValue(graph.getOptions());
if (mitigations == SpectrePHTMitigations.None || mitigations == SpectrePHTMitigations.AllTargets) {
return;
}
ControlFlowGraph cfg = ControlFlowGraph.newBuilder(graph).connectBlocks(true).computeFrequency(true).build();
for (AbstractBeginNode beginNode : graph.getNodes(AbstractBeginNode.TYPE)) {
if (hasPotentialUnsafeAccess(cfg, beginNode)) {
Expand All @@ -76,7 +81,7 @@ protected void run(StructuredGraph graph) {
continue;
}
if (hasGuardUsages(beginNode)) {
if (SpectrePHTBarriers.getValue(graph.getOptions()) == NonDeoptGuardTargets) {
if (mitigations == NonDeoptGuardTargets) {
if (isDeoptGuard(beginNode)) {
graph.getDebug().log(DebugContext.VERBOSE_LEVEL, "Skipping deoptimizing guard speculation fence at %s", beginNode);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import java.util.function.ToLongFunction;
import java.util.function.UnaryOperator;

import jdk.graal.compiler.phases.common.InsertGuardFencesPhase;
import org.graalvm.collections.Pair;
import org.graalvm.nativeimage.AnnotationAccess;
import org.graalvm.nativeimage.ImageSingletons;
Expand Down Expand Up @@ -970,6 +971,15 @@ public void registerGraalPhases(Providers providers, Suites suites, boolean host
if (hosted && HostInliningPhase.Options.TruffleHostInlining.getValue(HostedOptionValues.singleton()) && suites.getHighTier() instanceof HighTier) {
suites.getHighTier().prependPhase(new SubstrateHostInliningPhase(CanonicalizerPhase.create()));
}
/*
* On HotSpot, the InsertGuardFencesPhase is inserted into the mid-tier depending on the
* runtime option SpectrePHTBarriers. However, TruffleFeature registers phases during
* image-build time. Therefore, for Truffle compilations, we need to register the phase
* eagerly because the SpectrePHTBarriers options is set only at image-execution time.
*/
if (!hosted && suites.getMidTier().findPhase(InsertGuardFencesPhase.class, true) == null) {
suites.getMidTier().appendPhase(new InsertGuardFencesPhase());
}
}
}

Expand Down

0 comments on commit 3c8e0e0

Please sign in to comment.