oracle/graal · error · UnsupportedOperationException
size() is not supported for performance reasons
Error message
size() is not supported for performance reasons
What it means
NodeMap is a fixed array indexed by node id, so it does not maintain an element count; size() would either require expensive bookkeeping or return a misleading number (array capacity). It therefore throws UnsupportedOperationException('size() is not supported for performance reasons'). Use capacity() for the backing array length, or track counts yourself if you need cardinality.
Solutions
- Track the number of meaningful entries in a separate counter updated wherever you call set().
- Use map.capacity() when you actually need the array dimension, not the entry count.
- Snapshot into a HashMap when interoperating with Map-based APIs: copy entries for nodes you care about, then call size() on that.
Example fix
// before
int entries = map.size(); // throws
// after
int entries = 0;
for (int i = 0; i < map.capacity(); i++) {
if (map.get(map.getKey(i)) != null) entries++; // or maintain a counter at set() sites Defensive patterns
Strategy: validation
Validate before calling
// never call map.size(); use capacity() for array length and your own counter for entries int backingLength = map.capacity();
Prevention
- Track entry counts at set() call sites if cardinality matters.
- Snapshot into a HashMap when handing data to Map-based APIs.
- Grep for .size() when migrating from HashMap to NodeMap.
When it happens
Trigger: Calling nodeMap.size() directly, or passing a NodeMap where Map-shaped APIs call size(): logging helpers, toString implementations, assertion libraries, or generic utility methods typed against java.util.Map.
Common situations: Refactoring code from HashMap<Node,T> to NodeMap for speed and forgetting to remove size()-based logic. Debug output that prints map sizes. Test assertions comparing entry counts.
Related errors
- isEmpty() is not supported for performance reasons
- not implemented
- this node is not alive:
- accessing node id in
- Could not load Graal NodeClass TYPE field for
AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14).
Data as JSON: /api/errors/dd4eb65dbee9133a.
Report an issue: GitHub.
Appendix: source
Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graph/NodeMap.java:125
values[getNodeId(node)] = value;
}
public void setAndGrow(Node node, T value) {
checkAndGrow(node);
set(node, value);
}
/**
* @param i
* @return Return the key for the entry at index {@code i}
*/
protected Node getKey(int i) {
return graph.getNode(i);
}
@Override
public int size() {
throw new UnsupportedOperationException("size() is not supported for performance reasons");
}
public int capacity() {
return values.length;
}
public boolean isNew(Node node) {
return getNodeId(node) >= capacity();
}
private boolean check(Node node) {
assert node.graph() == graph : String.format("%s is not part of the graph", node);
assert !isNew(node) : "this node was added to the graph after creating the node map : " + node;
assert node.isAlive() : "this node is not alive: " + node;
return true;
}
@OverrideView on GitHub (pinned to a66e9ccd1d)