{"record":{"id":"47a0a3b390833d76","repo":"oracle/graal","slug":"out-of-scratch-registers-s","errorCode":null,"errorMessage":"Out of scratch registers: %s","messagePattern":"Out of scratch registers: (.+?)","errorType":"exception","errorClass":"GraalError","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/asm/aarch64/AArch64MacroAssembler.java","lineNumber":97,"sourceCode":"\n        public ScratchRegister(Register register) {\n            this.register = register;\n        }\n\n        public Register getRegister() {\n            return register;\n        }\n\n        @Override\n        public void close() {\n            assert nextFreeScratchRegister > 0 : \"Close called too often\";\n            nextFreeScratchRegister--;\n        }\n    }\n\n    public ScratchRegister getScratchRegister() {\n        if (nextFreeScratchRegister == getScratchRegisters().length) {\n            throw new GraalError(\"Out of scratch registers: \" + nextFreeScratchRegister);\n        }\n        return getScratchRegisters()[nextFreeScratchRegister++];\n    }\n\n    @Override\n    public void bind(Label l) {\n        super.bind(l);\n        // Clear last ldr/str instruction to prevent the labeled ldr/str being merged.\n        lastImmLoadStoreEncoding = null;\n    }\n\n    /**\n     * Retrieves pc relative offset between current position and provided bound label.\n     */\n    public int getPCRelativeOffset(Label label) {\n        assert label.isBound();\n        registerPatchInCodeSnippetRecord(position(), label);\n        int offset = label.position() - position();","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/asm/aarch64/AArch64MacroAssembler.java#L79-L115","documentation":"Thrown by readPrimitiveArrayUnaligned when the array constant's type is not a primitive array. Buffer-based byte reads are only valid on primitive guest arrays; reference arrays and non-array objects have no byte buffer to decode from.","triggerScenarios":"Calling readPrimitiveArrayUnaligned with an Object[] constant, an espresso String, or any non-array object constant while the kind itself is a valid primitive.","commonSituations":"Reading a field that is a reference array by mistake; kind/array mismatch where the kind came from one field and the array constant from another; refactors mixing up variables.","solutions":["Verify arrayType.isArray() && getComponentType().isPrimitive() before the read","Match the kind to the actual component type of the array you pass","For reference arrays use readArrayElement and handle elements as object constants"],"exampleFix":"// before\nJavaConstant v = vmAccess.readPrimitiveArrayUnaligned(refArrayConst, JavaKind.Int, offset);\n\n// after\nEspressoResolvedObjectType t = ((EspressoExternalObjectConstant) refArrayConst).getType();\nJavaConstant v = (t.isArray() && t.getComponentType().isPrimitive())\n        ? vmAccess.readPrimitiveArrayUnaligned(refArrayConst, t.getComponentType().getJavaKind(), offset)\n        : vmAccess.readArrayElement(refArrayConst, offset / 4);","handlingStrategy":"validation","validationCode":"EspressoResolvedObjectType t = ((EspressoExternalObjectConstant) array).getType();\nif (!(t.isArray() && t.getComponentType().isPrimitive())) {\n    throw new IllegalArgumentException(\"unaligned read requires a primitive array, got \" + t);\n}","typeGuard":"static boolean isPrimitiveArrayConstant(JavaConstant c) {\n    return c instanceof EspressoExternalObjectConstant o\n            && o.getType().isArray()\n            && o.getType().getComponentType().isPrimitive();\n}","tryCatchPattern":null,"preventionTips":["Pair the kind argument with the array's actual component kind at the call site","For reference arrays, use element-wise object reads"],"tags":["espresso","jvmci","unaligned-read","primitive-array","validation"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}