Skip to content

Commit 7b21ceb

Browse files
authored
Merge pull request #197 from zakkak/2025-09-08-backport-177
[Backport] [Oracle GraalVM] [GR-66325] Backport to 23.1: Handle getSystemResource method properly in the Native Image agent.
2 parents 3908619 + 89535c8 commit 7b21ceb

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

substratevm/src/com.oracle.svm.agent/src/com/oracle/svm/agent/BreakpointInterceptor.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ private static boolean forName(JNIEnvironment jni, JNIObjectHandle thread, Break
210210
JNIObjectHandle name = getObjectArgument(thread, 0);
211211
String className = fromJniString(jni, name);
212212
if (className == null) {
213-
return false; /* No point in tracing this. */
213+
return true; /* No point in tracing this. */
214214
}
215215
traceReflectBreakpoint(jni, bp.clazz, nullHandle(), callerClass, bp.specification.methodName, null, state.getFullStackTraceOrNull(), className);
216216
return true;
@@ -573,13 +573,27 @@ private static boolean newArrayInstance0(JNIEnvironment jni, Breakpoint bp, JNIV
573573
return true;
574574
}
575575

576+
private static boolean handleResourceRegistration(JNIEnvironment env, JNIObjectHandle clazz, JNIObjectHandle callerClass, String function, JNIMethodId[] stackTrace, String resourceName,
577+
String moduleName) {
578+
if (resourceName == null) {
579+
return true; /* No point in tracing this: resource path is null */
580+
}
581+
582+
if (moduleName == null) {
583+
traceReflectBreakpoint(env, clazz, nullHandle(), callerClass, function, true, stackTrace, resourceName);
584+
} else {
585+
traceReflectBreakpoint(env, clazz, nullHandle(), callerClass, function, true, stackTrace, moduleName, resourceName);
586+
}
587+
588+
return true;
589+
}
590+
576591
private static boolean findResource(JNIEnvironment jni, JNIObjectHandle thread, Breakpoint bp, InterceptedState state) {
577592
JNIObjectHandle callerClass = state.getDirectCallerClass();
578593
JNIObjectHandle module = getObjectArgument(thread, 1);
579594
JNIObjectHandle name = getObjectArgument(thread, 2);
580-
traceReflectBreakpoint(jni, nullHandle(), nullHandle(), callerClass, bp.specification.methodName, true, state.getFullStackTraceOrNull(),
581-
fromJniString(jni, module), fromJniString(jni, name));
582-
return true;
595+
596+
return handleResourceRegistration(jni, nullHandle(), callerClass, bp.specification.methodName, state.getFullStackTraceOrNull(), fromJniString(jni, name), fromJniString(jni, module));
583597
}
584598

585599
private static boolean getResource(JNIEnvironment jni, JNIObjectHandle thread, Breakpoint bp, InterceptedState state) {
@@ -601,8 +615,8 @@ private static boolean handleGetResources(JNIEnvironment jni, JNIObjectHandle th
601615
selfClazz = nullHandle();
602616
}
603617
}
604-
traceReflectBreakpoint(jni, selfClazz, nullHandle(), callerClass, bp.specification.methodName, true, state.getFullStackTraceOrNull(), fromJniString(jni, name));
605-
return true;
618+
619+
return handleResourceRegistration(jni, selfClazz, callerClass, bp.specification.methodName, state.getFullStackTraceOrNull(), fromJniString(jni, name), null);
606620
}
607621

608622
private static boolean getSystemResource(JNIEnvironment jni, JNIObjectHandle thread, Breakpoint bp, InterceptedState state) {
@@ -615,9 +629,9 @@ private static boolean getSystemResources(JNIEnvironment jni, JNIObjectHandle th
615629

616630
private static boolean handleGetSystemResources(JNIEnvironment jni, JNIObjectHandle thread, Breakpoint bp, InterceptedState state) {
617631
JNIObjectHandle callerClass = state.getDirectCallerClass();
618-
JNIObjectHandle name = getReceiver(thread);
619-
traceReflectBreakpoint(jni, nullHandle(), nullHandle(), callerClass, bp.specification.methodName, true, state.getFullStackTraceOrNull(), fromJniString(jni, name));
620-
return true;
632+
JNIObjectHandle name = getObjectArgument(thread, 0);
633+
634+
return handleResourceRegistration(jni, nullHandle(), callerClass, bp.specification.methodName, state.getFullStackTraceOrNull(), fromJniString(jni, name), null);
621635
}
622636

623637
private static boolean newProxyInstance(JNIEnvironment jni, JNIObjectHandle thread, Breakpoint bp, InterceptedState state) {

substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/trace/ReflectionProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public void processEntry(EconomicMap<String, ?> entry, ConfigurationSet configur
106106
configuration.getOrCreateType(condition, type);
107107
}
108108
}
109+
return;
109110
}
110111
String clazz = (String) entry.get("class");
111112
if (advisor.shouldIgnore(lazyValue(clazz), lazyValue(callerClass))) {

0 commit comments

Comments
 (0)