Skip to content

Commit eca3288

Browse files
committed
Add GenerateUncached to CreateFunctionNode
1 parent c379ffd commit eca3288

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PythonCextBuiltins.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@
234234
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
235235
import com.oracle.graal.python.nodes.attributes.WriteAttributeToDynamicObjectNode;
236236
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
237-
import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetSignatureNode;
238237
import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetCallTargetNode;
238+
import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetSignatureNode;
239239
import com.oracle.graal.python.nodes.call.CallNode;
240240
import com.oracle.graal.python.nodes.call.GenericInvokeNode;
241241
import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
@@ -298,6 +298,7 @@
298298
import com.oracle.truffle.api.dsl.Cached.Shared;
299299
import com.oracle.truffle.api.dsl.Fallback;
300300
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
301+
import com.oracle.truffle.api.dsl.GenerateUncached;
301302
import com.oracle.truffle.api.dsl.ImportStatic;
302303
import com.oracle.truffle.api.dsl.NodeFactory;
303304
import com.oracle.truffle.api.dsl.ReportPolymorphism;
@@ -537,6 +538,7 @@ Object importCExtFunction(String name, Object capiLibrary,
537538
}
538539
}
539540

541+
@GenerateUncached
540542
@ImportStatic(PGuards.class)
541543
abstract static class CreateFunctionNode extends Node {
542544

@@ -556,28 +558,23 @@ static Object doPythonCallableWithoutWrapper(@SuppressWarnings("unused") String
556558
return nativeWrapperLibrary.getDelegate(callable);
557559
}
558560

559-
@Specialization(guards = "lib.isLazyPythonClass(type)", limit = "3")
561+
@Specialization(guards = "lib.isLazyPythonClass(type)")
560562
@TruffleBoundary
561-
Object doPythonCallable(String name, PythonNativeWrapper callable, int signature, Object type, int flags, PythonObjectFactory factory,
562-
@CachedLibrary("callable") PythonNativeWrapperLibrary nativeWrapperLibrary,
563+
static Object doPythonCallable(String name, PythonNativeWrapper callable, int signature, Object type, int flags, PythonObjectFactory factory,
563564
@SuppressWarnings("unused") @CachedLibrary(limit = "2") PythonObjectLibrary lib) {
564565
// This can happen if a native type inherits slots from a managed type. Therefore,
565566
// something like 'base->tp_new' will be a wrapper of the managed '__new__'. So, in this
566567
// case, we assume that the object is already callable.
567-
Object managedCallable = nativeWrapperLibrary.getDelegate(callable);
568-
PBuiltinFunction function = PExternalFunctionWrapper.createWrapperFunction(name, managedCallable, type, flags,
569-
signature, PythonLanguage.get(nativeWrapperLibrary), factory, false);
568+
Object managedCallable = callable.getDelegateSlowPath();
569+
PBuiltinFunction function = PExternalFunctionWrapper.createWrapperFunction(name, managedCallable, type, flags, signature, PythonLanguage.get(lib), factory, false);
570570
return function != null ? function : managedCallable;
571571
}
572572

573573
@Specialization(guards = {"lib.isLazyPythonClass(type)", "isDecoratedManagedFunction(callable)", "isNoValue(wrapper)"})
574-
static Object doDecoratedManagedWithoutWrapper(@SuppressWarnings("unused") String name, PyCFunctionDecorator callable,
575-
@SuppressWarnings("unused") PNone wrapper,
576-
@SuppressWarnings("unused") Object type,
577-
@SuppressWarnings("unused") Object flags,
578-
@SuppressWarnings("unused") PythonObjectFactory factory,
574+
@SuppressWarnings("unused")
575+
static Object doDecoratedManagedWithoutWrapper(@SuppressWarnings("unused") String name, PyCFunctionDecorator callable, PNone wrapper, Object type, Object flags, PythonObjectFactory factory,
579576
@CachedLibrary(limit = "3") PythonNativeWrapperLibrary nativeWrapperLibrary,
580-
@SuppressWarnings("unused") @CachedLibrary(limit = "2") PythonObjectLibrary lib) {
577+
@CachedLibrary(limit = "2") PythonObjectLibrary lib) {
581578
// This can happen if a native type inherits slots from a managed type. Therefore,
582579
// something like 'base->tp_new' will be a wrapper of the managed '__new__'. So, in this
583580
// case, we assume that the object is already callable.
@@ -588,7 +585,7 @@ static Object doDecoratedManagedWithoutWrapper(@SuppressWarnings("unused") Strin
588585

589586
@Specialization(guards = "isDecoratedManagedFunction(callable)")
590587
@TruffleBoundary
591-
Object doDecoratedManaged(String name, PyCFunctionDecorator callable, int signature, Object type, int flags, PythonObjectFactory factory,
588+
static Object doDecoratedManaged(String name, PyCFunctionDecorator callable, int signature, Object type, int flags, PythonObjectFactory factory,
592589
@CachedLibrary(limit = "3") PythonNativeWrapperLibrary nativeWrapperLibrary) {
593590
// This can happen if a native type inherits slots from a managed type. Therefore,
594591
// something like 'base->tp_new' will be a wrapper of the managed '__new__'. So, in this
@@ -610,21 +607,21 @@ Object doDecoratedManaged(String name, PyCFunctionDecorator callable, int signat
610607

611608
@Specialization(guards = {"lib.isLazyPythonClass(type)", "!isNativeWrapper(callable)"})
612609
@TruffleBoundary
613-
PBuiltinFunction doNativeCallableWithType(String name, Object callable, int signature, Object type, int flags, PythonObjectFactory factory,
610+
static PBuiltinFunction doNativeCallableWithType(String name, Object callable, int signature, Object type, int flags, PythonObjectFactory factory,
614611
@SuppressWarnings("unused") @CachedLibrary(limit = "2") PythonObjectLibrary lib) {
615612
return PExternalFunctionWrapper.createWrapperFunction(name, callable, type, flags,
616613
signature, PythonLanguage.get(lib), factory, true);
617614
}
618615

619616
@Specialization(guards = {"isNoValue(type)", "!isNativeWrapper(callable)"})
620617
@TruffleBoundary
621-
PBuiltinFunction doNativeCallableWithoutType(String name, Object callable, int signature, @SuppressWarnings("unused") PNone type, int flags, PythonObjectFactory factory) {
618+
static PBuiltinFunction doNativeCallableWithoutType(String name, Object callable, int signature, @SuppressWarnings("unused") PNone type, int flags, PythonObjectFactory factory) {
622619
return doNativeCallableWithType(name, callable, signature, null, flags, factory, null);
623620
}
624621

625622
@Specialization(guards = {"lib.isLazyPythonClass(type)", "isNoValue(wrapper)", "!isNativeWrapper(callable)"})
626623
@TruffleBoundary
627-
PBuiltinFunction doNativeCallableWithoutWrapper(String name, Object callable, Object type,
624+
static PBuiltinFunction doNativeCallableWithoutWrapper(String name, Object callable, Object type,
628625
@SuppressWarnings("unused") PNone wrapper,
629626
@SuppressWarnings("unused") Object flags, PythonObjectFactory factory,
630627
@SuppressWarnings("unused") @CachedLibrary(limit = "2") PythonObjectLibrary lib) {
@@ -634,7 +631,7 @@ PBuiltinFunction doNativeCallableWithoutWrapper(String name, Object callable, Ob
634631

635632
@Specialization(guards = {"isNoValue(wrapper)", "isNoValue(type)", "!isNativeWrapper(callable)"})
636633
@TruffleBoundary
637-
PBuiltinFunction doNativeCallableWithoutWrapperAndType(String name, Object callable, PNone wrapper, @SuppressWarnings("unused") PNone type, Object flags, PythonObjectFactory factory) {
634+
static PBuiltinFunction doNativeCallableWithoutWrapperAndType(String name, Object callable, PNone wrapper, @SuppressWarnings("unused") PNone type, Object flags, PythonObjectFactory factory) {
638635
return doNativeCallableWithoutWrapper(name, callable, null, wrapper, flags, factory, null);
639636
}
640637

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PythonNativeWrapper.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected static class GetDelegate {
129129
@Specialization(guards = {"cachedWrapper == wrapper", "delegate != null"}, assumptions = "singleContextAssumption()")
130130
protected static Object getCachedDel(@SuppressWarnings("unused") PythonNativeWrapper wrapper,
131131
@SuppressWarnings("unused") @Cached(value = "wrapper", weak = true) PythonNativeWrapper cachedWrapper,
132-
@Cached(value = "wrapper.getDelegatePrivate()", weak = true) Object delegate) {
132+
@Cached(value = "wrapper.getDelegateSlowPath()", weak = true) Object delegate) {
133133
return delegate;
134134
}
135135

@@ -139,7 +139,11 @@ protected static Object getGenericDel(PythonNativeWrapper wrapper) {
139139
}
140140
}
141141

142-
protected final Object getDelegatePrivate() {
142+
/**
143+
* Only use this method if acting behing a {@code TruffleBoundary}. It returns the delegate of
144+
* this wrapper for uncached paths such that a uncached library lookup can be avoided.
145+
*/
146+
public final Object getDelegateSlowPath() {
143147
return delegate;
144148
}
145149

0 commit comments

Comments
 (0)