oracle/graal · error · GraalError

Failed to initialize the PAPI bridge

Error message

Failed to initialize the PAPI bridge

What it means

HardwarePerformanceCounters wraps the PAPI (Performance Application Programming Interface) bridge and throws GraalError when bridge.linkAndInitializeOnce() returns false, i.e. the native PAPI bridge library could not be loaded, linked, or initialized. This is a hard failure because replay-based compilation measurement cannot proceed without working hardware counters.

Source

Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/HardwarePerformanceCounters.java:211

     * Flag to track whether measurements have been started.
     */
    private boolean started;

    /**
     * Creates a new HardwarePerformanceCounters instance.
     *
     * @param eventNames the list of event names to be measured
     * @param bridge the implementation to use for interacting with the PAPI bridge library
     */
    HardwarePerformanceCounters(List<String> eventNames, PAPIBridge bridge) {
        this.bridge = bridge;
        this.eventNames = List.copyOf(eventNames);
        for (String eventName : this.eventNames) {
            Objects.requireNonNull(eventName);
        }
        boolean success = bridge.linkAndInitializeOnce();
        if (!success) {
            throw new GraalError("Failed to initialize the PAPI bridge");
        }
        this.eventSet = bridge.createEventSet(this.eventNames.toArray(String[]::new));
        this.papiNull = bridge.getNull();
        GraalError.guarantee(this.eventSet != papiNull, "failed to create an event set");
    }

    /**
     * Starts measuring the specified events.
     */
    public void start() {
        boolean success = bridge.start(eventSet);
        GraalError.guarantee(success, "failed to start measurements");
        started = true;
    }

    /**
     * Stops measuring the specified events and returns the counts.
     *

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Install PAPI and ensure the bridge library is on LD_LIBRARY_PATH / -Djava.library.path
  2. Lower perf restrictions: sysctl kernel.perf_event_paranoid (and kernel.kptr_restrict), or run with adequate privileges in containers (--perf-event or --privileged)
  3. Verify with papi_avail / papi_native_avail that the requested event names exist on this CPU
  4. If counters are unavailable, disable the hardware-performance-counter feature of replay compilation rather than letting the constructor throw

Example fix

// before
new HardwarePerformanceCounters(eventNames, bridge); // throws GraalError if lib missing
// after: guard availability first
if (!bridge.linkAndInitializeOnce()) {
    // fall back to compilation without HPC measurement
} else {
    new HardwarePerformanceCounters(eventNames, bridge);
}
Defensive patterns

Strategy: validation

Validate before calling

// Probe the bridge before constructing the counter object
if (!bridge.linkAndInitializeOnce()) {
    LOG.warning("PAPI bridge unavailable; skipping HPC measurement");
} else {
    counters = new HardwarePerformanceCounters(eventNames, bridge);
}

Try / catch

try {
    counters = new HardwarePerformanceCounters(eventNames, bridge);
} catch (GraalError e) {
    if (e.getMessage().contains("PAPI bridge")) { /* degrade to no counters */ }
    else { throw e; }
}

Prevention

When it happens

Trigger: Constructing HardwarePerformanceCounters (used by replay compilation to measure compile-time events) when the native PAPI bridge library is absent from the library path, has the wrong ABI/version, or PAPI_initialize fails on the machine (no perf counter access, sandboxed container).

Common situations: libpapi / the Graal PAPI bridge .so not on java.library.path or LD_LIBRARY_PATH; running in a container without perf_event permissions (kernel.perf_event_paranoid); PAPI version mismatch; missing /proc/sys/kernel/perf_event_paranoid=0 setting; CPU without requested counters.

Related errors


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