@@ -2195,30 +2195,26 @@ public int RegisterNative(@JavaType(Class.class) StaticObject clazz, @Pointer Tr
2195
2195
return handleNoSuchMethod (meta );
2196
2196
}
2197
2197
Method targetMethod = clazz .getMirrorKlass (getMeta ()).lookupDeclaredMethod (name , signature );
2198
- if (targetMethod != null && targetMethod .isNative ()) {
2199
- targetMethod .unregisterNative ();
2200
- getSubstitutions ().removeRuntimeSubstitution (targetMethod );
2201
- } else {
2198
+ if (targetMethod == null || !targetMethod .isNative ()) {
2202
2199
// agents might have set native method prefix, so check with those as well
2203
- if (targetMethod == null || getContext ().getJavaAgents () == null ) {
2204
- return handleNoSuchMethod (meta );
2205
- }
2206
- if (findPrefixedNative (name , clazz , signature ) != null ) {
2207
- // we found a native wrapper method for the target method
2208
- // use the original target method which match the native implementation
2209
- targetMethod .unregisterNative ();
2210
- getSubstitutions ().removeRuntimeSubstitution (targetMethod );
2211
- } else {
2212
- return handleNoSuchMethod (meta );
2213
- }
2200
+ targetMethod = findPrefixedNative (name , clazz , signature );
2214
2201
}
2202
+ if (targetMethod == null ) {
2203
+ // OK, nowhere to be found, so give up
2204
+ return handleNoSuchMethod (meta );
2205
+ }
2206
+ // make sure we have the correct method name also for prefixed methods
2207
+ name = targetMethod .getName ();
2208
+ targetMethod .unregisterNative ();
2209
+ getSubstitutions ().removeRuntimeSubstitution (targetMethod );
2215
2210
2216
2211
// Lookup known VM methods to shortcut native boundaries.
2217
2212
Substitutions .EspressoRootNodeFactory factory = lookupKnownVmMethods (closure , targetMethod );
2218
2213
if (factory == null ) {
2219
2214
NativeSignature ns = Method .buildJniNativeSignature (targetMethod .getParsedSignature ());
2220
2215
final TruffleObject boundNative = getNativeAccess ().bindSymbol (closure , ns );
2221
- factory = createJniRootNodeFactory (() -> EspressoRootNode .createNative (getContext ().getJNI (closure ), targetMethod .getMethodVersion (), boundNative ), targetMethod );
2216
+ final Method finalTargetMethod = targetMethod ;
2217
+ factory = createJniRootNodeFactory (() -> EspressoRootNode .createNative (getContext ().getJNI (closure ), finalTargetMethod .getMethodVersion (), boundNative ), targetMethod );
2222
2218
}
2223
2219
2224
2220
Symbol <Type > classType = clazz .getMirrorKlass (getMeta ()).getType ();
@@ -2227,6 +2223,9 @@ public int RegisterNative(@JavaType(Class.class) StaticObject clazz, @Pointer Tr
2227
2223
}
2228
2224
2229
2225
private Method findPrefixedNative (Symbol <Name > name , @ JavaType (Class .class ) StaticObject clazz , Symbol <Signature > signature ) {
2226
+ if (getContext ().getJavaAgents () == null ) {
2227
+ return null ;
2228
+ }
2230
2229
Symbol <Name >[] allNativePrefixes = getContext ().getJavaAgents ().getAllNativePrefixes ();
2231
2230
if (allNativePrefixes == Symbol .EMPTY_ARRAY ) {
2232
2231
return null ;
0 commit comments