Skip to content

Commit 210eea3

Browse files
committed
cache on @Builtin, not on the Builtin node
1 parent 99e9963 commit 210eea3

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@
2828
import java.io.IOException;
2929
import java.util.ArrayList;
3030
import java.util.Arrays;
31+
import java.util.IdentityHashMap;
3132
import java.util.concurrent.ConcurrentHashMap;
3233
import java.util.concurrent.Semaphore;
33-
import com.oracle.graal.python.util.Supplier;
3434
import java.util.logging.Level;
3535

3636
import org.graalvm.options.OptionDescriptors;
3737
import org.graalvm.options.OptionKey;
3838
import org.graalvm.options.OptionValues;
3939

40+
import com.oracle.graal.python.builtins.Builtin;
4041
import com.oracle.graal.python.builtins.Python3Core;
4142
import com.oracle.graal.python.builtins.objects.PEllipsis;
4243
import com.oracle.graal.python.builtins.objects.PNone;
@@ -49,7 +50,6 @@
4950
import com.oracle.graal.python.nodes.NodeFactory;
5051
import com.oracle.graal.python.nodes.control.TopLevelExceptionHandler;
5152
import com.oracle.graal.python.nodes.expression.ExpressionNode;
52-
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5353
import com.oracle.graal.python.parser.PythonParserImpl;
5454
import com.oracle.graal.python.runtime.PythonContext;
5555
import com.oracle.graal.python.runtime.PythonCore;
@@ -58,7 +58,9 @@
5858
import com.oracle.graal.python.runtime.exception.PException;
5959
import com.oracle.graal.python.runtime.interop.InteropMap;
6060
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
61+
import com.oracle.graal.python.util.Function;
6162
import com.oracle.graal.python.util.PFunctionArgsFinder;
63+
import com.oracle.graal.python.util.Supplier;
6264
import com.oracle.truffle.api.Assumption;
6365
import com.oracle.truffle.api.CallTarget;
6466
import com.oracle.truffle.api.CompilerAsserts;
@@ -127,7 +129,7 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
127129
public final Assumption singleContextAssumption = Truffle.getRuntime().createAssumption("Only a single context is active");
128130

129131
private final NodeFactory nodeFactory;
130-
public final ConcurrentHashMap<Class<? extends PythonBuiltinBaseNode>, RootCallTarget> builtinCallTargetCache = new ConcurrentHashMap<>();
132+
private final IdentityHashMap<Builtin, RootCallTarget> builtinCallTargetCache = new IdentityHashMap<>();
131133

132134
@CompilationFinal(dimensions = 1) private static final Object[] CONTEXT_INSENSITIVE_SINGLETONS = new Object[]{PNone.NONE, PNone.NO_VALUE, PEllipsis.INSTANCE, PNotImplemented.NOT_IMPLEMENTED};
133135

@@ -579,4 +581,9 @@ protected void disposeThread(PythonContext context, Thread thread) {
579581
context.disposeThread(thread);
580582
}
581583

584+
public RootCallTarget getOrComputeBuiltinCallTarget(Builtin builtin, Function<Builtin, RootCallTarget> supplier) {
585+
synchronized(this) {
586+
return builtinCallTargetCache.computeIfAbsent(builtin, supplier);
587+
}
588+
}
582589
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void initialize(PythonCore core) {
7474
} else {
7575
declaresExplicitSelf = true;
7676
}
77-
RootCallTarget callTarget = core.getLanguage().builtinCallTargetCache.computeIfAbsent(factory.getNodeClass(),
77+
RootCallTarget callTarget = core.getLanguage().getOrComputeBuiltinCallTarget(builtin,
7878
(b) -> Truffle.getRuntime().createCallTarget(new BuiltinFunctionRootNode(core.getLanguage(), builtin, factory, declaresExplicitSelf)));
7979
Object builtinDoc = builtin.doc().isEmpty() ? PNone.NONE : builtin.doc();
8080
if (builtin.constructsClass().length > 0) {

0 commit comments

Comments
 (0)