Skip to content

Commit 4c0255c

Browse files
committed
[GR-62523] Fix jck instrumentation test failures.
PullRequest: graal/20172
2 parents e3d74d9 + 75d9412 commit 4c0255c

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/jni/JniEnv.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,30 +2195,26 @@ public int RegisterNative(@JavaType(Class.class) StaticObject clazz, @Pointer Tr
21952195
return handleNoSuchMethod(meta);
21962196
}
21972197
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()) {
22022199
// 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);
22142201
}
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);
22152210

22162211
// Lookup known VM methods to shortcut native boundaries.
22172212
Substitutions.EspressoRootNodeFactory factory = lookupKnownVmMethods(closure, targetMethod);
22182213
if (factory == null) {
22192214
NativeSignature ns = Method.buildJniNativeSignature(targetMethod.getParsedSignature());
22202215
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);
22222218
}
22232219

22242220
Symbol<Type> classType = clazz.getMirrorKlass(getMeta()).getType();
@@ -2227,6 +2223,9 @@ public int RegisterNative(@JavaType(Class.class) StaticObject clazz, @Pointer Tr
22272223
}
22282224

22292225
private Method findPrefixedNative(Symbol<Name> name, @JavaType(Class.class) StaticObject clazz, Symbol<Signature> signature) {
2226+
if (getContext().getJavaAgents() == null) {
2227+
return null;
2228+
}
22302229
Symbol<Name>[] allNativePrefixes = getContext().getJavaAgents().getAllNativePrefixes();
22312230
if (allNativePrefixes == Symbol.EMPTY_ARRAY) {
22322231
return null;

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/runtime/JavaAgents.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public Symbol<Name> resolveMethodNameFromPrefixes(Symbol<Name> originalName) {
379379
for (int i = allNativePrefixes.length - 1; i >= 0; i--) {
380380
Symbol<Name> prefix = allNativePrefixes[i];
381381
if (resolvedName.contentStartsWith(prefix)) {
382-
resolvedName = resolvedName.subSequence(prefix.length(), resolvedName.length() - prefix.length());
382+
resolvedName = resolvedName.subSequence(prefix.length(), resolvedName.length());
383383
}
384384
}
385385
return getContext().getNames().getOrCreate(resolvedName);
@@ -419,7 +419,7 @@ public void grantReadAccessToUnnamedModules(ModuleTable.ModuleEntry module) {
419419
// we lost the race, so nothing to do
420420
return;
421421
}
422-
getContext().getMeta().jdk_internal_module_Modules_transformedByAgent.invokeDirect(module.module());
422+
getContext().getMeta().jdk_internal_module_Modules_transformedByAgent.invokeDirectStatic(module.module());
423423
// no reason to call into guest for a module more than once,
424424
// so flip the hasDefaultReads flag
425425
module.setHasDefaultReads();

0 commit comments

Comments
 (0)