Skip to content

Commit 97f5129

Browse files
committed
svm: add JVMCIReflectionUtil#getOrigin
1 parent e3ba98d commit 97f5129

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/JVMCIReflectionUtil.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package com.oracle.svm.util;
2626

2727
import java.lang.reflect.Method;
28+
import java.net.URL;
2829
import java.util.Arrays;
2930
import java.util.Collections;
3031
import java.util.List;
@@ -282,4 +283,15 @@ public static String getTypeName(ResolvedJavaType type) {
282283
public static ResolvedJavaModule getModule(ResolvedJavaType declaringClass) {
283284
return JVMCIReflectionUtilFallback.getModule(declaringClass);
284285
}
286+
287+
/**
288+
* Returns the <em>origin</em> associated with this {@link ResolvedJavaType}.
289+
*
290+
* This is not yet properly implemented as it falls back to the original class (GR-71068).
291+
*
292+
* @return the location (URL), or {@code null} if no URL was supplied during construction.
293+
*/
294+
public static URL getOrigin(ResolvedJavaType type) {
295+
return JVMCIReflectionUtilFallback.getOrigin(type);
296+
}
285297
}

substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/JVMCIReflectionUtilFallback.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
*/
2525
package com.oracle.svm.util;
2626

27+
import java.net.URL;
28+
import java.security.CodeSource;
29+
import java.security.ProtectionDomain;
30+
2731
import jdk.vm.ci.meta.ResolvedJavaType;
2832

2933
/**
@@ -43,4 +47,13 @@ static ResolvedJavaPackage getPackage(ResolvedJavaType type) {
4347
static ResolvedJavaModule getModule(ResolvedJavaType declaringClass) {
4448
return new ResolvedJavaModuleImpl(getJavaClass(declaringClass).getModule());
4549
}
50+
51+
static URL getOrigin(ResolvedJavaType type) {
52+
ProtectionDomain pd = getJavaClass(type).getProtectionDomain();
53+
CodeSource cs = pd.getCodeSource();
54+
if (cs == null) {
55+
return null;
56+
}
57+
return cs.getLocation();
58+
}
4659
}

0 commit comments

Comments
 (0)