{"record":{"id":"486465842bbec745","repo":"oracle/graal","slug":"emitting-code-to-write-a-value-to-the-protection-k","errorCode":null,"errorMessage":"Emitting code to write a value to the protection key register is not currently supported on %s","messagePattern":"Emitting code to write a value to the protection key register is not currently supported on (.+?)","errorType":"exception","errorClass":"GraalError","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/lir/gen/LIRGeneratorTool.java","lineNumber":1020,"sourceCode":"    }\n\n    default void emitConvertZeroToNull(AllocatableValue result, Value input) {\n        emitMove(result, input);\n    }\n\n    /**\n     * Emits an instruction that prevents speculative execution from proceeding: no instruction\n     * after this fence will execute until all previous instructions have retired.\n     */\n    void emitSpeculationFence();\n\n    /**\n     * Write value to the protection key register.\n     *\n     * @param value to be written\n     */\n    default void emitProtectionKeyRegisterWrite(Value value) {\n        throw new GraalError(\"Emitting code to write a value to the protection key register is not currently supported on %s\", target().arch);\n    }\n\n    /**\n     * Read contents of the protection key register.\n     *\n     * @return value read from the register\n     */\n    default Value emitProtectionKeyRegisterRead() {\n        throw new GraalError(\"Emitting code to read the contents of the protection key register is not currently supported on %s\", target().arch);\n    }\n\n    default VirtualStackSlot allocateStackMemory(int sizeInBytes, int alignmentInBytes) {\n        return getResult().getFrameMapBuilder().allocateStackMemory(sizeInBytes, alignmentInBytes);\n    }\n\n    default Value emitTimeStamp() {\n        throw new GraalError(\"Emitting code to return the current value of the timestamp counter is not currently supported on %s\", target().arch);\n    }","sourceCodeStart":1002,"sourceCodeEnd":1038,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/lir/gen/LIRGeneratorTool.java#L1002-L1038","documentation":"LIRGeneratorTool declares emitProtectionKeyRegisterWrite(Value) as a default method that throws GraalError, naming the unsupported target architecture. It is the fallback implementation backends inherit when they have not implemented writing the protection key (PKRU/PKEY) register. Hitting it means frontend lowering reached a protection-key-write node on an architecture whose LIRGenerator does not support it.","triggerScenarios":"Lowering a node/intrinsic that emits a protection key register write (e.g., pkey write modeled via ProtectedWord / memory-protection intrinsics) while compiling for a backend (AMD64, AArch64 as of this code) whose LIRGenerator does not override emitProtectionKeyRegisterWrite.","commonSituations":"Running code using Intel MPK / protection-key APIs under a Graal configuration or architecture where the backend support is missing; new feature branches emitting the operation before all backends implement it.","solutions":["Guard the feature at the frontend: do not lower protection-key writes on architectures whose backend does not implement them (check target().arch in the node's lower())","Implement emitProtectionKeyRegisterWrite in the relevant backend's LIRGenerator (see how existing intrinsics emit raw register writes)","Disable the language/feature requiring protection keys on that architecture"],"exampleFix":"// before\n@Override\npublic void lower(LoweringTool tool) {\n    getLIRGeneratorTool().emitProtectionKeyRegisterWrite(key);\n}\n\n// after\n@Override\npublic void lower(LoweringTool tool) {\n    Architecture arch = graph().getProviders().getCodeCache().getTarget().arch;\n    if (!(arch instanceof SPARCArch)) { // only backends that implement it\n        throw GraalError.unsupported(\"protection keys not supported on \" + arch);\n    }\n    getLIRGeneratorTool().emitProtectionKeyRegisterWrite(key);\n}","handlingStrategy":"validation","validationCode":"// Frontend: only emit the operation on backends that implement it\nif (backendOverrides(lirGen.getClass(), \"emitProtectionKeyRegisterWrite\")) {\n    gen.emitProtectionKeyRegisterWrite(value);\n} else {\n    throw GraalError.unsupported(\"pkey write not available on \" + arch);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Gate intrinsics on target().arch in lower(), never assume every backend implements a capability hook","Keep a capability matrix per backend when adding new LIRGeneratorTool operations","Test new intrinsics on all supported architectures in CI"],"tags":["graalvm","lir","backend","protection-keys","unsupported-operation"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}