Skip to content

[GR-64781] Pass correct node to inlined branch profiles in InteropLookupAndInvoke. #11480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,22 @@ Object callDirect(Object[] args,
@Specialization
@ReportPolymorphism.Megamorphic
Object callIndirect(Object[] args,
@Bind Node node,
@Cached InlinedBranchProfile error,
@Cached IndirectCallNode indirectCallNode) {
StaticObject receiver = (StaticObject) args[0];
assert args[0] == receiver;
assert !StaticObject.isNull(receiver);
// vtable lookup.
Method.MethodVersion target = genericMethodLookup(this, resolutionSeed, receiver.getKlass(), error);
Method.MethodVersion target = genericMethodLookup(node, resolutionSeed, receiver.getKlass(), error);
return indirectCallNode.call(target.getCallTarget(), args);
}
}

static Method.MethodVersion methodLookup(Method resolutionSeed, Klass receiverKlass) {
CompilerAsserts.neverPartOfCompilation();
return genericMethodLookup(null, resolutionSeed, receiverKlass, InlinedBranchProfile.getUncached());
return genericMethodLookup(null, // OK for uncached branch profile.
resolutionSeed, receiverKlass, InlinedBranchProfile.getUncached());
}

static Method.MethodVersion genericMethodLookup(Node node, Method resolutionSeed, Klass receiverKlass, InlinedBranchProfile error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
*/
package com.oracle.truffle.espresso.nodes.bytecodes;

import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeInfo;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.espresso.nodes.EspressoNode;
Expand All @@ -37,9 +39,11 @@ public abstract class NullCheck extends EspressoNode {
abstract StaticObject execute(StaticObject receiver);

@Specialization
StaticObject doNullCheck(StaticObject receiver, @Cached InlinedBranchProfile exceptionProfile) {
StaticObject doNullCheck(StaticObject receiver,
@Bind Node node,
@Cached InlinedBranchProfile exceptionProfile) {
if (StaticObject.isNull(receiver)) {
exceptionProfile.enter(this);
exceptionProfile.enter(node);
throw getMeta().throwNullPointerException();
}
return receiver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,7 @@ public StaticObject doEspresso(StaticObject value,
"isHostObject(getContext(), value)"
})
StaticObject doForeignInternalConverter(Object value,
@Bind Node node,
@Shared("value") @CachedLibrary(limit = "LIMIT") InteropLibrary interop,
@Cached LookupInternalTypeConverterNode lookupTypeConverterNode,
@Cached ToReference.DynamicToReference converterToEspresso,
Expand All @@ -1875,7 +1876,7 @@ StaticObject doForeignInternalConverter(Object value,
} catch (UnsupportedMessageException e) {
// no meta object, fall through to throw unsupported type
}
errorProfile.enter(this);
errorProfile.enter(node);
throw ToEspressoNode.unsupportedType(value, targetType.getRawType());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
*/
package com.oracle.truffle.espresso.runtime.dispatch.staticobject;

import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.interop.ArityException;
import com.oracle.truffle.api.interop.UnknownIdentifierException;
import com.oracle.truffle.api.interop.UnsupportedTypeException;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.espresso.impl.Klass;
import com.oracle.truffle.espresso.impl.Method;
Expand Down Expand Up @@ -71,7 +73,8 @@ public abstract Object execute(StaticObject receiver, Klass klass, Object[] argu
@GenerateUncached
public abstract static class Virtual extends InteropLookupAndInvoke {
@Specialization
public Object doVirtual(StaticObject receiver, Klass klass, Object[] arguments, String member,
Object doVirtual(StaticObject receiver, Klass klass, Object[] arguments, String member,
@Bind Node node,
@Cached LookupVirtualMethodNode lookup,
@Cached SelectAndInvokeNode selectAndInvoke,
@Cached InlinedBranchProfile error,
Expand All @@ -80,17 +83,18 @@ public Object doVirtual(StaticObject receiver, Klass klass, Object[] arguments,
assert receiver != null;
Method[] candidates = lookup.execute(klass, member, arguments.length);
if (candidates != null) {
return selectAndInvoke(selectAndInvoke, exception, receiver, arguments, candidates);
return selectAndInvoke(selectAndInvoke, exception, node, receiver, arguments, candidates);
}
error.enter(this);
error.enter(node);
throw ArityException.create(arguments.length + 1, -1, arguments.length);
}
}

@GenerateUncached
public abstract static class NonVirtual extends InteropLookupAndInvoke {
@Specialization
public Object doNonVirtual(StaticObject receiver, Klass klass, Object[] arguments, String member,
Object doNonVirtual(StaticObject receiver, Klass klass, Object[] arguments, String member,
@Bind Node node,
@Cached LookupDeclaredMethod lookup,
@Cached SelectAndInvokeNode selectAndInvoke,
@Cached InlinedBranchProfile error,
Expand All @@ -99,19 +103,20 @@ public Object doNonVirtual(StaticObject receiver, Klass klass, Object[] argument
boolean isStatic = receiver == null;
Method[] candidates = lookup.execute(klass, member, true, isStatic, arguments.length);
if (candidates != null) {
return selectAndInvoke(selectAndInvoke, exception, receiver, arguments, candidates);
return selectAndInvoke(selectAndInvoke, exception, node, receiver, arguments, candidates);
}
error.enter(this);
error.enter(node);
throw ArityException.create(arguments.length + 1, -1, arguments.length);
}
}

Object selectAndInvoke(SelectAndInvokeNode selectAndInvoke, InlinedBranchProfile exception,
Object selectAndInvoke(SelectAndInvokeNode selectAndInvoke,
InlinedBranchProfile exception, Node node,
StaticObject receiver, Object[] args, Method[] candidates) throws UnsupportedTypeException, ArityException {
try {
return selectAndInvoke.execute(receiver, args, candidates);
} catch (EspressoException e) {
exception.enter(this);
exception.enter(node);
throw InteropUtils.unwrapExceptionBoundary(getLanguage(), e, getMeta());
}
}
Expand All @@ -121,7 +126,7 @@ abstract static class SelectAndInvokeNode extends EspressoNode {
public abstract Object execute(StaticObject receiver, Object[] args, Method[] candidates) throws ArityException, UnsupportedTypeException;

@Specialization(guards = {"isSingleNonVarargs(candidates)"})
Object doSingleNonVarargs(StaticObject receiver, Object[] args, Method[] candidates,
static Object doSingleNonVarargs(StaticObject receiver, Object[] args, Method[] candidates,
@Cached @Exclusive InvokeEspressoNode invoke,
@Cached InteropUnwrapNode unwrapNode)
throws ArityException, UnsupportedTypeException {
Expand All @@ -133,7 +138,8 @@ Object doSingleNonVarargs(StaticObject receiver, Object[] args, Method[] candida
}

@Specialization(guards = {"isSingleVarargs(candidates)"})
Object doSingleVarargs(StaticObject receiver, Object[] args, Method[] candidates,
static Object doSingleVarargs(StaticObject receiver, Object[] args, Method[] candidates,
@Bind Node node,
@Cached @Exclusive InvokeEspressoNode invoke,
@Cached ToEspressoNode.DynamicToEspresso toEspresso,
@Cached InteropUnwrapNode unwrapNode,
Expand All @@ -148,12 +154,13 @@ Object doSingleVarargs(StaticObject receiver, Object[] args, Method[] candidates
assert matched != null;
return invoke.execute(matched.getMethod(), receiver, matched.getConvertedArgs(), true, unwrapNode);
}
error.enter(this);
error.enter(node);
throw UnsupportedTypeException.create(args);
}

@Specialization(guards = {"isMulti(candidates)"})
Object doMulti(StaticObject receiver, Object[] args, Method[] candidates,
static Object doMulti(StaticObject receiver, Object[] args, Method[] candidates,
@Bind Node node,
@Cached OverLoadedMethodSelectorNode selector,
@Cached @Exclusive InvokeEspressoNode invoke,
@Cached InteropUnwrapNode unwrapNode,
Expand All @@ -165,7 +172,7 @@ Object doMulti(StaticObject receiver, Object[] args, Method[] candidates,
return invoke.execute(typeMatched.getMethod(), receiver, typeMatched.getConvertedArgs(), true, unwrapNode);
} else {
// unable to select exactly one best candidate for the input args!
error.enter(this);
error.enter(node);
throw UnsupportedTypeException.create(args);
}
}
Expand Down
Loading