oracle/graal · error · IllegalArgumentException

SpectrePHTBarriers can be set to 'AllTargets' if and only if

Error message

SpectrePHTBarriers can be set to 'AllTargets' if and only if SpeculativeExecutionBarriers is enabled or unspecified.

What it means

The Graal option SpectrePHTBarriers accepts 'AllTargets', which is defined to be exactly equivalent to enabling SpeculativeExecutionBarriers. SpeculativeExecutionBarriers is a derived Boolean option; when its effective value is updated, onValueUpdate enforces the coupling: 'AllTargets' is legal only when SpeculativeExecutionBarriers is enabled or left unspecified, and conversely.

Source

Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/common/SpectrePHTMitigations.java:61

        // @formatter:off

        @Option(help = "Stop speculative execution on all branch targets with execution barrier instructions.", stability = OptionStability.STABLE)
        public static final OptionKey<Boolean> SpeculativeExecutionBarriers = new OptionKey<>(false) {

            @Override
            public Boolean getValue(OptionValues values) {
                // Do not use getValue to avoid an infinite recursion
                if (values.getMap().get(SpectrePHTBarriers) == AllTargets) {
                    return true;
                }
                return super.getValue(values);
            }

            protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean oldValue, Boolean newValue) {
                if (values.containsKey(SpectrePHTBarriers)) {
                    Object otherValue = values.get(SpectrePHTBarriers);
                    if (newValue && otherValue != AllTargets || (!newValue && otherValue == AllTargets)) {
                        throw new IllegalArgumentException("SpectrePHTBarriers can be set to 'AllTargets' if and only if SpeculativeExecutionBarriers is enabled or unspecified.");
                    }
                }
            }
        };

        @Option(help = """
                       Selects a strategy to mitigate speculative bounds check bypass (also known as Spectre-PHT or Spectre V1).
                       The accepted values are:
                                         None - No mitigations are used in JIT compiled code.
                                   AllTargets - Speculative execution on all branch targets is
                                                stopped using speculative execution barrier instructions.
                                                This option is equivalent to setting SpeculativeExecutionBarriers to true.
                                 GuardTargets - Branch targets relevant to Java memory safety are instrumented with barrier instructions.
                                                This option has a lower performance impact than AllTargets.
                         NonDeoptGuardTargets - Same as GuardTargets, except that branches which deoptimize are not protected because they cannot be
                                                executed repeatedly and are thus less likely to be successfully exploited in an attack.

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Remove the conflict: either drop -Dgraal.SpeculativeExecutionBarriers=false, or change SpectrePHTBarriers to None/NormalTargets.
  2. If you only want barriers on protected targets, use -Dgraal.SpectrePHTBarriers=None (or omit it) and keep SpeculativeExecutionBarriers unset.
  3. Audit startup scripts, docker images, and .hotspotrc files for stale copies of one flag without its pair.

Example fix

# before (conflicting)
-Dgraal.SpeculativeExecutionBarriers=false -Dgraal.SpectrePHTBarriers=AllTargets

# after (equivalent mitigation, no conflict)
-Dgraal.SpeculativeExecutionBarriers=true
Defensive patterns

Strategy: validation

Validate before calling

// before applying options, check the coupling
Object barriers = options.getMap().get(GraalOptions.SpeculativeExecutionBarriers);
Object pht = options.getMap().get(SpectrePHTMitigations.Options.SpectrePHTBarriers);
boolean allTargets = pht != null && pht.toString().equals("AllTargets");
boolean barriersDisabled = Boolean.FALSE.equals(barriers);
if (allTargets && barriersDisabled) {
    throw new IllegalArgumentException("AllTargets requires SpeculativeExecutionBarriers enabled or unspecified");
}

Prevention

When it happens

Trigger: Setting -Dgraal.SpeculativeExecutionBarriers=false together with -Dgraal.SpectrePHTBarriers=AllTargets (the newValue=true && otherValue==AllTargets branch), or otherwise updating SpeculativeExecutionBarriers to a value inconsistent with an explicitly set AllTargets. The check fires while option values propagate into the OptionValues map.

Common situations: Hardening-tuning mistakes: an operator copies Spectre mitigation flags from one system to another, disables speculative-execution barriers for performance but leaves the AllTargets barrier mode on, or sets both options in different layers (JVM CI options vs. system properties) that conflict. Common after security-baseline changes or benchmark tuning passes.

Related errors


AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14). Data as JSON: /api/errors/40e5e24643799181. Report an issue: GitHub.