oracle/graal · error · GraalError
Failed to print the optimization log to a file: %s
Error message
Failed to print the optimization log to a file: %s
What it means
OptimizationLogImpl.flushToFile writes the accumulated JSON log to OptimizationLogPath (isolate/thread-named file, appended, one JSON per line). Any IOException while creating directories, opening, or writing the stream is wrapped in a GraalError with the underlying message. The error is environmental: the compiler produced the log fine, it just could not persist it.
Source
Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/OptimizationLogImpl.java:722
}
if (printToFile) {
try {
String pathOptionValue = DebugOptions.OptimizationLogPath.getValue(graph.getOptions());
if (pathOptionValue == null) {
pathOptionValue = PathUtilities.getPath(DebugOptions.getDumpDirectory(graph.getOptions()), OPTIMIZATION_LOG_DIRECTORY);
}
PathUtilities.createDirectories(pathOptionValue);
@SuppressWarnings("deprecation")
String fileName = IsolateUtil.getIsolateID() + "_" + Thread.currentThread().getId();
String filePath = PathUtilities.getPath(pathOptionValue, fileName);
try (OutputStream outputStream = PathUtilities.openOutputStream(filePath, true);
PrintStream printStream = new PrintStream(outputStream)) {
printStream.print(json);
printStream.print(LINE_SEPARATOR);
printStream.flush();
}
} catch (IOException exception) {
throw new GraalError("Failed to print the optimization log to a file: %s", exception.getMessage());
}
}
}
/**
* Finds and returns the root of the optimization tree.
*
* @return the root of the optimization tree
*/
public OptimizationPhaseNode findRootPhase() {
OptimizationPhaseNode root = currentPhase;
while (root.predecessor() != null) {
root = (OptimizationPhaseNode) root.predecessor();
}
assert ROOT_PHASE_NAME.contentEquals(root.getPhaseName()) : "the found phase must be the root phase";
return root;
}
View on GitHub (pinned to a66e9ccd1d)
Solutions
- Point -Dgraal.OptimizationLogPath at an existing, writable directory (verify with touch)
- Free disk space or raise the container's storage/ephemeral limit
- In containers/sandboxes, mount a writable volume for dump and log output and pass that path
- If the log is not needed, disable the OptimizationLog option to remove the write entirely
Example fix
# before native-image -H:OptimizationLog=... -H:OptimizationLogPath=/opt/app/logs ... # /opt read-only # after mkdir -p /tmp/optlog && chmod u+w /tmp/optlog native-image -H:OptimizationLog=... -H:OptimizationLogPath=/tmp/optlog ...
Defensive patterns
Strategy: try-catch
Validate before calling
Path dir = Path.of(options.get("graal.OptimizationLogPath"));
Files.createDirectories(dir);
if (!Files.isWritable(dir)) throw new IllegalStateException("OptimizationLogPath not writable: " + dir); Try / catch
// The error is thrown by the compiler itself; guard around launching the build:
if (!Files.isWritable(logDir)) { disableOptimizationLog(); } // or fail fast with a clear message Prevention
- Verify the log directory is writable before builds (esp. in containers)
- Use absolute paths for dump/log options to avoid cwd surprises
- Monitor disk space on CI agents that accumulate optimization logs
When it happens
Trigger: Enabling the optimization log (e.g., -Dgraal.OptimizationLog=... plus -Dgraal.OptimizationLogPath=DIR) where DIR does not exist and cannot be created, is read-only, the disk is full, or (in sandboxed/containerized runs) the process lacks write permission to that path.
Common situations: CI containers running as non-root writing to /graal-dumps; disk-full agents; a relative OptimizationLogPath resolving against an unexpected working directory (e.g., read-only image root in native-image builds); path strings with characters the filesystem rejects.
Related errors
- The provided optimization log path does not denote a directo
- Could not read the files of the experiment {experimentId}: {
- Cannot use the specified log.file
- LogFile substitution %s cannot be combined with any other ch
- Profile file for path %s exists already
AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14).
Data as JSON: /api/errors/23100735cb18bf6c.
Report an issue: GitHub.