|
55 | 55 | import java.util.HashSet;
|
56 | 56 | import java.util.Map;
|
57 | 57 | import java.util.Objects;
|
| 58 | +import java.util.WeakHashMap; |
58 | 59 | import java.util.concurrent.ConcurrentHashMap;
|
59 | 60 | import java.util.concurrent.atomic.AtomicLong;
|
60 | 61 |
|
|
75 | 76 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory.ToJavaNodeGen;
|
76 | 77 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory.ToNewRefNodeGen;
|
77 | 78 | import com.oracle.graal.python.builtins.objects.cext.capi.DynamicObjectNativeWrapper.PrimitiveNativeWrapper;
|
| 79 | +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor; |
78 | 80 | import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions;
|
79 | 81 | import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandleTester;
|
80 | 82 | import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.JavaStringToTruffleString;
|
|
102 | 104 | import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
|
103 | 105 | import com.oracle.graal.python.runtime.PythonOptions;
|
104 | 106 | import com.oracle.graal.python.runtime.exception.PException;
|
105 |
| -import com.oracle.graal.python.util.Function; |
| 107 | +import com.oracle.graal.python.util.BiFunction; |
106 | 108 | import com.oracle.graal.python.util.PythonUtils;
|
107 | 109 | import com.oracle.graal.python.util.WeakIdentityHashMap;
|
108 | 110 | import com.oracle.truffle.api.CallTarget;
|
@@ -201,8 +203,6 @@ public final class CApiContext extends CExtContext {
|
201 | 203 | private boolean loadNativeLibrary = true;
|
202 | 204 | public RootCallTarget signatureContainer;
|
203 | 205 |
|
204 |
| - private final WeakIdentityHashMap<Object, Object> procWrappers = new WeakIdentityHashMap<>(); |
205 |
| - |
206 | 206 | public static TruffleLogger getLogger(Class<?> clazz) {
|
207 | 207 | return PythonLanguage.getLogger(LOGGER_CAPI_NAME + "." + clazz.getSimpleName());
|
208 | 208 | }
|
@@ -1071,8 +1071,26 @@ public void retainClosure(Object closure) {
|
1071 | 1071 | callableClosures.add(closure);
|
1072 | 1072 | }
|
1073 | 1073 |
|
| 1074 | + private record ProcCacheItem(ArgDescriptor signature, Object callable) { |
| 1075 | + |
| 1076 | + @Override |
| 1077 | + public boolean equals(Object o) { |
| 1078 | + if (o instanceof ProcCacheItem other) { |
| 1079 | + return signature == other.signature && callable == other.callable; |
| 1080 | + } |
| 1081 | + return false; |
| 1082 | + } |
| 1083 | + |
| 1084 | + @Override |
| 1085 | + public int hashCode() { |
| 1086 | + return System.identityHashCode(signature) + 31 * System.identityHashCode(callable); |
| 1087 | + } |
| 1088 | + } |
| 1089 | + |
| 1090 | + private final Map<ProcCacheItem, Object> procWrappers = new WeakHashMap<>(); |
| 1091 | + |
1074 | 1092 | @TruffleBoundary
|
1075 |
| - public Object getOrCreateProcWrapper(Object callable, Function<Object, Object> factory) { |
1076 |
| - return procWrappers.computeIfAbsent(callable, factory); |
| 1093 | + public Object getOrCreateProcWrapper(ArgDescriptor signature, Object callable, BiFunction<ArgDescriptor, Object, Object> factory) { |
| 1094 | + return procWrappers.computeIfAbsent(new ProcCacheItem(signature, callable), (cacheItem) -> factory.apply(cacheItem.signature, cacheItem.callable)); |
1077 | 1095 | }
|
1078 | 1096 | }
|
0 commit comments