oracle/graal · error · GraalError

Can't store into VarargsParameter array

Error message

Can't store into VarargsParameter array

What it means

Snippet templates model a varargs snippet parameter with VarargsParameterNode, which is a placeholder, not a real array. Reads of its elements are rewritten to LoadSnippetVarargParameterNode, but a store back into the varargs array has no lowering, so SnippetTemplate throws GraalError during template instantiation when it sees a StoreIndexedNode on the varargs parameter.

Source

Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/SnippetTemplate.java:1160

                    parameters[i] = params;

                    VarargsPlaceholderNode placeholder = placeholders[i];
                    if (placeholder != null) {
                        for (Node usage : placeholder.usages().snapshot()) {
                            if (usage instanceof LoadIndexedNode) {
                                LoadIndexedNode loadIndexed = (LoadIndexedNode) usage;
                                debug.dump(DebugContext.INFO_LEVEL, snippetCopy, "Before replacing %s", loadIndexed);
                                LoadSnippetVarargParameterNode loadSnippetParameter = snippetCopy.add(
                                                new LoadSnippetVarargParameterNode(params, loadIndexed.index(), loadIndexed.stamp(NodeView.DEFAULT)));
                                snippetCopy.replaceFixedWithFixed(loadIndexed, loadSnippetParameter);
                                debug.dump(DebugContext.INFO_LEVEL, snippetCopy, "After replacing %s", loadIndexed);
                            } else if (usage instanceof StoreIndexedNode) {
                                /*
                                 * The template lowering doesn't really treat this as an array so
                                 * you can't store back into the varargs. Allocate your own array if
                                 * you really need this and EA should eliminate it.
                                 */
                                throw new GraalError("Can't store into VarargsParameter array");
                            }
                        }
                    }
                } else {
                    ParameterNode local = snippetCopy.getParameter(i);
                    if (local == null) {
                        // Parameter value was eliminated
                        parameters[i] = UNUSED_PARAMETER;
                    } else {
                        parameters[i] = local;
                    }
                }
            }

            explodeLoops(snippetCopy, providers);

            List<UnwindNode> unwindNodes = snippetCopy.getNodes(UnwindNode.TYPE).snapshot();
            if (unwindNodes.size() == 0) {

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Copy the varargs into a locally allocated array before writing it; escape analysis removes the copy in generated code (as the source comment says).
  2. Restructure the snippet to only read the varargs parameter and build a fresh result array.

Example fix

// before (inside the @Snippet method)
params[0] = fallback; // GraalError: can't store into VarargsParameter array

// after
Object[] copy = Arrays.copyOf(params, params.length); // EA eliminates this allocation
copy[0] = fallback;
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: A @Snippet method declares an Object... varargs parameter and its body executes arr[i] = value (any store into the varargs parameter array).

Common situations: Writing a snippet that tries to normalize or mutate its varargs input in place; porting regular Java utility code into a snippet without adjusting for varargs handling.

Related errors


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