Skip to content

Commit 5ddfcb9

Browse files
committed
[GR-65090] Fix possible VMError when dumping runtime compiled code
PullRequest: graal/20822
2 parents 0a51ebb + 7c86c01 commit 5ddfcb9

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,4 +520,18 @@ public static Class<?> toUnboxedClassWithDefault(Class<?> clazz, Class<?> defaul
520520
return defaultClass;
521521
}
522522
}
523+
524+
/** Sanitizes a name to be used in a file name. Special characters are replaced with '_'. */
525+
public static String sanitizeForFileName(String name) {
526+
StringBuilder buf = new StringBuilder(name.length());
527+
for (int i = 0; i < name.length(); i++) {
528+
char c = name.charAt(i);
529+
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '.' || (c >= '0' && c <= '9')) {
530+
buf.append(c);
531+
} else {
532+
buf.append('_');
533+
}
534+
}
535+
return buf.toString();
536+
}
523537
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/RuntimeCodeCache.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -65,8 +65,6 @@
6565
import jdk.graal.compiler.options.OptionType;
6666
import jdk.graal.compiler.word.Word;
6767

68-
import java.text.SimpleDateFormat;
69-
7068
public class RuntimeCodeCache {
7169

7270
public static class Options {
@@ -174,11 +172,18 @@ private static RawFileOperationSupport getFileSupport() {
174172
}
175173

176174
private static void dumpMethod(CodeInfo info) {
177-
String methodName = CodeInfoAccess.getName(info);
178-
int tier = CodeInfoAccess.getTier(info);
179-
String date = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date());
180175
String tmpDirPath = getFileSupport().getTempDirectory();
181-
String filePath = tmpDirPath + "/" + date + "_" + methodName + "_" + tier + ".bin";
176+
String prefix = System.nanoTime() + "_";
177+
String methodName = SubstrateUtil.sanitizeForFileName(CodeInfoAccess.getName(info));
178+
String suffix = "_" + CodeInfoAccess.getTier(info) + ".bin";
179+
180+
// Check that the file name size does not exceed the 255 chars
181+
int maxMethodNameSize = 255 - prefix.length() - suffix.length();
182+
if (methodName.length() > maxMethodNameSize) {
183+
methodName = methodName.substring(maxMethodNameSize);
184+
}
185+
186+
String filePath = tmpDirPath + "/" + prefix + methodName + suffix;
182187

183188
RawFileOperationSupport.RawFileDescriptor fd = getFileSupport().create(filePath, CREATE_OR_REPLACE, WRITE);
184189
if (!getFileSupport().isValid(fd)) {

0 commit comments

Comments
 (0)