|
28 | 28 | import java.io.IOException;
|
29 | 29 | import java.util.ArrayList;
|
30 | 30 | import java.util.Arrays;
|
| 31 | +import java.util.IdentityHashMap; |
31 | 32 | import java.util.concurrent.ConcurrentHashMap;
|
32 | 33 | import java.util.concurrent.Semaphore;
|
33 |
| -import com.oracle.graal.python.util.Supplier; |
34 | 34 | import java.util.logging.Level;
|
35 | 35 |
|
36 | 36 | import org.graalvm.options.OptionDescriptors;
|
37 | 37 | import org.graalvm.options.OptionKey;
|
38 | 38 | import org.graalvm.options.OptionValues;
|
39 | 39 |
|
| 40 | +import com.oracle.graal.python.builtins.Builtin; |
40 | 41 | import com.oracle.graal.python.builtins.Python3Core;
|
41 | 42 | import com.oracle.graal.python.builtins.objects.PEllipsis;
|
42 | 43 | import com.oracle.graal.python.builtins.objects.PNone;
|
|
49 | 50 | import com.oracle.graal.python.nodes.NodeFactory;
|
50 | 51 | import com.oracle.graal.python.nodes.control.TopLevelExceptionHandler;
|
51 | 52 | import com.oracle.graal.python.nodes.expression.ExpressionNode;
|
52 |
| -import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode; |
53 | 53 | import com.oracle.graal.python.parser.PythonParserImpl;
|
54 | 54 | import com.oracle.graal.python.runtime.PythonContext;
|
55 | 55 | import com.oracle.graal.python.runtime.PythonCore;
|
|
58 | 58 | import com.oracle.graal.python.runtime.exception.PException;
|
59 | 59 | import com.oracle.graal.python.runtime.interop.InteropMap;
|
60 | 60 | import com.oracle.graal.python.runtime.object.PythonObjectFactory;
|
| 61 | +import com.oracle.graal.python.util.Function; |
61 | 62 | import com.oracle.graal.python.util.PFunctionArgsFinder;
|
| 63 | +import com.oracle.graal.python.util.Supplier; |
62 | 64 | import com.oracle.truffle.api.Assumption;
|
63 | 65 | import com.oracle.truffle.api.CallTarget;
|
64 | 66 | import com.oracle.truffle.api.CompilerAsserts;
|
@@ -127,7 +129,7 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
|
127 | 129 | public final Assumption singleContextAssumption = Truffle.getRuntime().createAssumption("Only a single context is active");
|
128 | 130 |
|
129 | 131 | private final NodeFactory nodeFactory;
|
130 |
| - public final ConcurrentHashMap<Class<? extends PythonBuiltinBaseNode>, RootCallTarget> builtinCallTargetCache = new ConcurrentHashMap<>(); |
| 132 | + private final IdentityHashMap<Builtin, RootCallTarget> builtinCallTargetCache = new IdentityHashMap<>(); |
131 | 133 |
|
132 | 134 | @CompilationFinal(dimensions = 1) private static final Object[] CONTEXT_INSENSITIVE_SINGLETONS = new Object[]{PNone.NONE, PNone.NO_VALUE, PEllipsis.INSTANCE, PNotImplemented.NOT_IMPLEMENTED};
|
133 | 135 |
|
@@ -579,4 +581,9 @@ protected void disposeThread(PythonContext context, Thread thread) {
|
579 | 581 | context.disposeThread(thread);
|
580 | 582 | }
|
581 | 583 |
|
| 584 | + public RootCallTarget getOrComputeBuiltinCallTarget(Builtin builtin, Function<Builtin, RootCallTarget> supplier) { |
| 585 | + synchronized(this) { |
| 586 | + return builtinCallTargetCache.computeIfAbsent(builtin, supplier); |
| 587 | + } |
| 588 | + } |
582 | 589 | }
|
0 commit comments