{"record":{"id":"e1465bdffbc6fe06","repo":"oracle/graal","slug":"profile-file-for-path-s-exists-already","errorCode":null,"errorMessage":"Profile file for path %s exists already","messagePattern":"Profile file for path (.+?) exists already","errorType":"exception","errorClass":"InternalError","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/ProfileReplaySupport.java","lineNumber":271,"sourceCode":"                }\n            }\n            if (SaveProfiles.getValue(debug.getOptions())) {\n                try (DebugContext.Scope scope = debug.scope(\"ProfileReplay\")) {\n                    EconomicMap<String, Object> map = EconomicMap.create();\n                    map.put(\"identifier\", compilationId.toString());\n                    map.put(\"method\", method.format(\"%H.%n(%P)%R\"));\n                    map.put(\"entryBCI\", entryBCI);\n                    map.put(\"codeSignature\", codeSignature);\n                    map.put(\"graphSignature\", graphSignature);\n                    map.put(\"result\", result != null);\n                    profileProvider.recordProfiles(map, profileSaveFilter, lambdaNameFormatter);\n                    String path = null;\n                    if (Options.SaveProfilesPath.getValue(debug.getOptions()) != null) {\n                        String fileName = PathUtilities.sanitizeFileName(method.format(\"%h.%n(%p)%r\") + \".glog\");\n                        String dirName = Options.SaveProfilesPath.getValue(debug.getOptions());\n                        path = Paths.get(dirName).resolve(fileName).toString();\n                        if (new File(path).exists() && !Options.OverrideProfiles.getValue(debug.getOptions())) {\n                            throw new InternalError(\"Profile file for path \" + path + \" exists already\");\n                        }\n                    } else {\n                        path = debug.getDumpPath(\".glog\", false, false);\n                    }\n                    try (JsonPrettyWriter writer = new JsonPrettyWriter(new PrintWriter(PathUtilities.openOutputStream(path)))) {\n                        writer.print(map);\n                    }\n                } catch (Throwable t) {\n                    throw debug.handle(t);\n                }\n            }\n        }\n    }\n\n    private static String getCanonicalGraphString(StructuredGraph graph) {\n        SchedulePhase.runWithoutContextOptimizations(graph, SchedulePhase.SchedulingStrategy.EARLIEST);\n        StructuredGraph.ScheduleResult scheduleResult = graph.getLastSchedule();\n        NodeMap<Integer> canonicalId = graph.createNodeMap();","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/ProfileReplaySupport.java#L253-L289","documentation":"InternalError thrown by ProfileReplaySupport when saving method profiles (-Dgraal.SaveProfilesPath=...) and the target .glog file already exists while -Dgraal.OverrideProfiles is false. The guard exists because blindly overwriting would destroy previously collected replay profiles for that method.","triggerScenarios":"Enabling Options.SaveProfilesPath and compiling the same method twice into the same directory without Options.OverrideProfiles=true; rerunning a benchmark or test suite that recompiles the same methods.","commonSituations":"Collecting replay profiles for a benchmark: first run writes Foo.glog, a second run (or a second JVM in the same output dir) collides. Also stale files left from an earlier collection.","solutions":["Add -Dgraal.OverrideProfiles=true to overwrite existing profile files.","Point -Dgraal.SaveProfilesPath at a fresh/unique directory for each run.","Delete or move the existing .glog files before recollecting."],"exampleFix":"# before\n-Dgraal.SaveProfilesPath=/tmp/profiles\n# second run -> InternalError\n\n# after\n-Dgraal.SaveProfilesPath=/tmp/profiles -Dgraal.OverrideProfiles=true","handlingStrategy":"validation","validationCode":"// Before each profiling run, ensure the target dir is fresh or override is enabled\nPath dir = Paths.get(System.getProperty(\"graal.SaveProfilesPath\"));\nboolean override = Boolean.parseBoolean(System.getProperty(\"graal.OverrideProfiles\", \"false\"));\nif (!override && Files.isDirectory(dir)) {\n    try (var s = Files.list(dir)) {\n        if (s.anyMatch(p -> p.toString().endsWith(\".glog\"))) {\n            throw new IllegalStateException(\"Stale .glog files present; move them or set -Dgraal.OverrideProfiles=true\");\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    // run JVM with -Dgraal.SaveProfilesPath=...\n} catch (InternalError e) {\n    if (e.getMessage().contains(\"exists already\")) { /* archive dir contents, rerun */ }\n    throw e;\n}","preventionTips":["Use a unique SaveProfilesPath per run (timestamped dir) in benchmark harnesses.","Enable -Dgraal.OverrideProfiles=true when recollection is intended."],"tags":["graalvm","profiling","replay","configuration"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}