Skip to content

Commit 88e0d61

Browse files
committed
Make Dynamic access detection platform independent
1 parent bd3008c commit 88e0d61

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/DynamicAccessDetectionFeature.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
import jdk.vm.ci.meta.ResolvedJavaMethod;
4343
import org.graalvm.collections.EconomicMap;
4444
import org.graalvm.collections.EconomicSet;
45-
import org.graalvm.collections.UnmodifiableEconomicSet;
4645
import org.graalvm.nativeimage.ImageSingletons;
4746

47+
import java.io.File;
4848
import java.io.IOException;
4949
import java.io.PrintWriter;
5050
import java.nio.file.Files;
@@ -107,15 +107,15 @@ public ConcurrentLinkedQueue<String> getMethodCallLocations(String methodName) {
107107
"java.lang.reflect.Array.newInstance",
108108
"java.lang.ClassLoader.loadClass");
109109

110-
public static final String GRAAL_SUBPATH = "/graal/";
110+
public static final String GRAAL_SUBPATH = File.separator + "graal" + File.separator;
111111
public static final String TRACK_ALL = "all";
112112

113113
private static final String OUTPUT_DIR_NAME = "dynamic-access";
114114
private static final String TRACK_NONE = "none";
115115
private static final String TO_CONSOLE = "to-console";
116116
private static final String NO_DUMP = "no-dump";
117117

118-
private UnmodifiableEconomicSet<String> sourceEntries; // Class path entries and module or
118+
private EconomicSet<String> sourceEntries; // Class path entries and module or
119119
// package names
120120
private final Map<String, MethodsByAccessKind> callsBySourceEntry;
121121
private final Set<FoldEntry> foldEntries = ConcurrentHashMap.newKeySet();
@@ -144,12 +144,12 @@ public MethodsByAccessKind getMethodsByAccessKind(String entry) {
144144
return callsBySourceEntry.computeIfAbsent(entry, k -> new MethodsByAccessKind());
145145
}
146146

147-
public UnmodifiableEconomicSet<String> getSourceEntries() {
147+
public EconomicSet<String> getSourceEntries() {
148148
return sourceEntries;
149149
}
150150

151151
public static String getEntryName(String path) {
152-
String fileName = path.substring(path.lastIndexOf("/") + 1);
152+
String fileName = path.substring(path.lastIndexOf(File.separator) + 1);
153153
if (fileName.endsWith(".jar")) {
154154
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
155155
}
@@ -321,6 +321,13 @@ public void afterRegistration(AfterRegistrationAccess access) {
321321
public void beforeCompilation(BeforeCompilationAccess access) {
322322
DynamicAccessDetectionFeature.instance().reportDynamicAccess();
323323
DynamicAccessDetectionPhase.clearMethodSignatures();
324+
foldEntries.clear();
325+
}
326+
327+
@Override
328+
public void beforeHeapLayout(BeforeHeapLayoutAccess access) {
329+
callsBySourceEntry.clear();
330+
sourceEntries.clear();
324331
}
325332

326333
@Override

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/DynamicAccessDetectionPhase.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
import jdk.vm.ci.meta.ResolvedJavaMethod;
3737
import jdk.vm.ci.meta.Signature;
3838
import org.graalvm.collections.EconomicMap;
39-
import org.graalvm.collections.UnmodifiableEconomicSet;
39+
import org.graalvm.collections.EconomicSet;
4040

41+
import java.io.File;
4142
import java.io.ObjectInputStream;
4243
import java.io.ObjectOutputStream;
4344
import java.io.ObjectStreamClass;
@@ -245,14 +246,14 @@ private static MethodInfo getMethodInfo(ResolvedJavaMethod method) {
245246
* the value specified by the option, otherwise returns null.
246247
*/
247248
private static String getSourceEntry(AnalysisType callerClass) {
248-
UnmodifiableEconomicSet<String> sourceEntries = DynamicAccessDetectionFeature.instance().getSourceEntries();
249+
EconomicSet<String> sourceEntries = DynamicAccessDetectionFeature.instance().getSourceEntries();
249250
try {
250251
CodeSource entryPathSource = callerClass.getJavaClass().getProtectionDomain().getCodeSource();
251252
if (entryPathSource != null) {
252253
URL entryPathURL = entryPathSource.getLocation();
253254
if (entryPathURL != null) {
254255
String classPathEntry = entryPathURL.toURI().getPath();
255-
if (classPathEntry.endsWith("/")) {
256+
if (classPathEntry.endsWith(File.separator)) {
256257
classPathEntry = classPathEntry.substring(0, classPathEntry.length() - 1);
257258
}
258259
if (sourceEntries.contains(classPathEntry)) {

0 commit comments

Comments
 (0)