Skip to content

Commit 978578b

Browse files
committed
cache on string key, not builtin right now to workaround svm limitation
1 parent 9893a9f commit 978578b

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.io.IOException;
2929
import java.util.ArrayList;
3030
import java.util.Arrays;
31-
import java.util.IdentityHashMap;
3231
import java.util.concurrent.ConcurrentHashMap;
3332
import java.util.concurrent.Semaphore;
3433
import java.util.logging.Level;
@@ -50,6 +49,7 @@
5049
import com.oracle.graal.python.nodes.NodeFactory;
5150
import com.oracle.graal.python.nodes.control.TopLevelExceptionHandler;
5251
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;
@@ -129,7 +129,7 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
129129
public final Assumption singleContextAssumption = Truffle.getRuntime().createAssumption("Only a single context is active");
130130

131131
private final NodeFactory nodeFactory;
132-
private final IdentityHashMap<Builtin, RootCallTarget> builtinCallTargetCache = new IdentityHashMap<>();
132+
private final ConcurrentHashMap<String, RootCallTarget> builtinCallTargetCache = new ConcurrentHashMap<>();
133133

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

@@ -581,9 +581,8 @@ protected void disposeThread(PythonContext context, Thread thread) {
581581
context.disposeThread(thread);
582582
}
583583

584-
public RootCallTarget getOrComputeBuiltinCallTarget(Builtin builtin, Function<Builtin, RootCallTarget> supplier) {
585-
synchronized (this) {
586-
return builtinCallTargetCache.computeIfAbsent(builtin, supplier);
587-
}
584+
public RootCallTarget getOrComputeBuiltinCallTarget(Builtin builtin, Class<? extends PythonBuiltinBaseNode> nodeClass, Function<Builtin, RootCallTarget> supplier) {
585+
String key = builtin.name() + nodeClass.getName();
586+
return builtinCallTargetCache.computeIfAbsent(key, (k) -> supplier.apply(builtin));
588587
}
589588
}

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().getOrComputeBuiltinCallTarget(builtin,
77+
RootCallTarget callTarget = core.getLanguage().getOrComputeBuiltinCallTarget(builtin, factory.getNodeClass(),
7878
(b) -> Truffle.getRuntime().createCallTarget(new BuiltinFunctionRootNode(core.getLanguage(), builtin, factory, declaresExplicitSelf, builtin.reverseOperation())));
7979
Object builtinDoc = builtin.doc().isEmpty() ? PNone.NONE : builtin.doc();
8080
if (builtin.constructsClass().length > 0) {

0 commit comments

Comments
 (0)