Skip to content

Commit 312e9ca

Browse files
committed
provide a cached argument application for multi context mode
1 parent 56a1f5d commit 312e9ca

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/CreateArgumentsNode.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
*/
4141
package com.oracle.graal.python.nodes.argument;
4242

43+
import java.util.ArrayList;
4344
import java.util.Arrays;
45+
import java.util.List;
4446

4547
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4648
import com.oracle.graal.python.builtins.objects.function.PArguments;
@@ -72,6 +74,7 @@
7274
import com.oracle.graal.python.util.PythonUtils;
7375
import com.oracle.truffle.api.CompilerDirectives;
7476
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
77+
import com.oracle.truffle.api.RootCallTarget;
7578
import com.oracle.truffle.api.dsl.Cached;
7679
import com.oracle.truffle.api.dsl.Cached.Exclusive;
7780
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -83,8 +86,6 @@
8386
import com.oracle.truffle.api.nodes.Node;
8487
import com.oracle.truffle.api.profiles.BranchProfile;
8588
import com.oracle.truffle.api.profiles.ConditionProfile;
86-
import java.util.ArrayList;
87-
import java.util.List;
8889

8990
@ImportStatic({PythonOptions.class, PGuards.class})
9091
@GenerateUncached
@@ -166,7 +167,25 @@ Object[] doFunctionCached(PythonObject callable, Object[] userArguments, PKeywor
166167
return createAndCheckArgumentsNode.execute(callable, userArguments, keywords, signature, null, defaults, kwdefaults, false);
167168
}
168169

169-
@Specialization(replaces = {"doFunctionCached", "doMethodCached", "doMethodFunctionAndSelfCached", "doMethodFunctionCached"})
170+
@Specialization(guards = {"getCallTarget(callable) == cachedCallTarget", "cachedCallTarget != null"}, limit = "getVariableArgumentInlineCacheLimit()", replaces = {"doMethodFunctionCached", "doFunctionCached"})
171+
Object[] doCallTargetCached(PythonObject callable, Object[] userArguments, PKeyword[] keywords,
172+
@Cached CreateAndCheckArgumentsNode createAndCheckArgumentsNode,
173+
@SuppressWarnings("unused") @Cached GetSignatureNode getSignatureNode,
174+
@Cached("getSignatureNode.execute(callable)") Signature signature, // signatures are attached to PRootNodes
175+
@Cached ConditionProfile gotMethod,
176+
@Cached GetDefaultsNode getDefaultsNode,
177+
@Cached GetKeywordDefaultsNode getKwDefaultsNode,
178+
@Cached("getCallTarget(callable)") @SuppressWarnings("unused") RootCallTarget cachedCallTarget) {
179+
Object[] defaults = getDefaultsNode.execute(callable);
180+
PKeyword[] kwdefaults = getKwDefaultsNode.execute(callable);
181+
Object self = null;
182+
if (gotMethod.profile(PGuards.isMethod(callable))) {
183+
self = getSelf(callable);
184+
}
185+
return createAndCheckArgumentsNode.execute(callable, userArguments, keywords, signature, self, defaults, kwdefaults, isMethodCall(self));
186+
}
187+
188+
@Specialization(replaces = {"doFunctionCached", "doMethodCached", "doMethodFunctionAndSelfCached", "doMethodFunctionCached", "doCallTargetCached"})
170189
Object[] uncached(PythonObject callable, Object[] userArguments, PKeyword[] keywords,
171190
@Cached("create()") CreateAndCheckArgumentsNode createAndCheckArgumentsNode) {
172191

@@ -866,6 +885,19 @@ protected static Object getFunction(Object callable) {
866885
return null;
867886
}
868887

888+
protected static RootCallTarget getCallTarget(Object callable) {
889+
if (callable instanceof PBuiltinMethod) {
890+
return ((PBuiltinMethod) callable).getFunction().getCallTarget();
891+
} else if (callable instanceof PMethod) {
892+
return getCallTarget(((PMethod) callable).getFunction());
893+
} else if (callable instanceof PBuiltinFunction) {
894+
return ((PBuiltinFunction) callable).getCallTarget();
895+
} else if (callable instanceof PFunction) {
896+
return ((PFunction) callable).getCallTarget();
897+
}
898+
return null;
899+
}
900+
869901
protected static boolean isMethodCall(Object self) {
870902
return !(self instanceof PythonModule);
871903
}

0 commit comments

Comments
 (0)