{"record":{"id":"b2ae154a503cc8ba","repo":"oracle/graal","slug":"failed-to-initialize-the-papi-bridge","errorCode":null,"errorMessage":"Failed to initialize the PAPI bridge","messagePattern":"Failed to initialize the PAPI bridge","errorType":"exception","errorClass":"GraalError","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/HardwarePerformanceCounters.java","lineNumber":211,"sourceCode":"     * Flag to track whether measurements have been started.\n     */\n    private boolean started;\n\n    /**\n     * Creates a new HardwarePerformanceCounters instance.\n     *\n     * @param eventNames the list of event names to be measured\n     * @param bridge the implementation to use for interacting with the PAPI bridge library\n     */\n    HardwarePerformanceCounters(List<String> eventNames, PAPIBridge bridge) {\n        this.bridge = bridge;\n        this.eventNames = List.copyOf(eventNames);\n        for (String eventName : this.eventNames) {\n            Objects.requireNonNull(eventName);\n        }\n        boolean success = bridge.linkAndInitializeOnce();\n        if (!success) {\n            throw new GraalError(\"Failed to initialize the PAPI bridge\");\n        }\n        this.eventSet = bridge.createEventSet(this.eventNames.toArray(String[]::new));\n        this.papiNull = bridge.getNull();\n        GraalError.guarantee(this.eventSet != papiNull, \"failed to create an event set\");\n    }\n\n    /**\n     * Starts measuring the specified events.\n     */\n    public void start() {\n        boolean success = bridge.start(eventSet);\n        GraalError.guarantee(success, \"failed to start measurements\");\n        started = true;\n    }\n\n    /**\n     * Stops measuring the specified events and returns the counts.\n     *","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/HardwarePerformanceCounters.java#L193-L229","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Install PAPI and ensure the bridge library is on LD_LIBRARY_PATH / -Djava.library.path","Lower perf restrictions: sysctl kernel.perf_event_paranoid (and kernel.kptr_restrict), or run with adequate privileges in containers (--perf-event or --privileged)","Verify with papi_avail / papi_native_avail that the requested event names exist on this CPU","If counters are unavailable, disable the hardware-performance-counter feature of replay compilation rather than letting the constructor throw"],"exampleFix":"// before\nnew HardwarePerformanceCounters(eventNames, bridge); // throws GraalError if lib missing\n// after: guard availability first\nif (!bridge.linkAndInitializeOnce()) {\n    // fall back to compilation without HPC measurement\n} else {\n    new HardwarePerformanceCounters(eventNames, bridge);\n}","handlingStrategy":"validation","validationCode":"// Probe the bridge before constructing the counter object\nif (!bridge.linkAndInitializeOnce()) {\n    LOG.warning(\"PAPI bridge unavailable; skipping HPC measurement\");\n} else {\n    counters = new HardwarePerformanceCounters(eventNames, bridge);\n}","typeGuard":null,"tryCatchPattern":"try {\n    counters = new HardwarePerformanceCounters(eventNames, bridge);\n} catch (GraalError e) {\n    if (e.getMessage().contains(\"PAPI bridge\")) { /* degrade to no counters */ }\n    else { throw e; }\n}","preventionTips":["Install PAPI and put the bridge library on LD_LIBRARY_PATH before launching the JVM","In containers, ensure perf_event access (kernel.perf_event_paranoid, --perf-event capability)","Validate event names with papi_native_avail before passing them in"],"tags":["graalvm","papi","native-library","perf-counters"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}