Skip to content

Commit b9edd79

Browse files
committed
specialize InitWrapper execution
1 parent ed4a42c commit b9edd79

File tree

1 file changed

+40
-35
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi

1 file changed

+40
-35
lines changed

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

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@
5353
import com.oracle.graal.python.nodes.argument.keywords.ExpandKeywordStarargsNode;
5454
import com.oracle.graal.python.nodes.argument.positional.ExecutePositionalStarargsNode;
5555
import com.oracle.graal.python.nodes.argument.positional.PositionalArgumentsNode;
56-
import com.oracle.graal.python.nodes.call.CallNode;
5756
import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
5857
import com.oracle.graal.python.nodes.call.special.CallTernaryMethodNode;
58+
import com.oracle.graal.python.nodes.call.special.CallVarargsMethodNode;
5959
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
6060
import com.oracle.graal.python.runtime.GilNode;
6161
import com.oracle.graal.python.runtime.exception.PException;
6262
import com.oracle.truffle.api.CompilerDirectives;
6363
import com.oracle.truffle.api.dsl.Cached;
6464
import com.oracle.truffle.api.dsl.Cached.Exclusive;
65+
import com.oracle.truffle.api.dsl.Specialization;
6566
import com.oracle.truffle.api.interop.ArityException;
6667
import com.oracle.truffle.api.interop.InteropLibrary;
6768
import com.oracle.truffle.api.interop.UnsupportedMessageException;
@@ -208,44 +209,48 @@ public InitWrapper(Object delegate) {
208209
super(delegate);
209210
}
210211

211-
@ExportMessage
212-
protected int execute(Object[] arguments,
213-
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
214-
@Cached ExecutePositionalStarargsNode.ExecutePositionalStarargsInteropNode posStarargsNode,
215-
@Cached ExpandKeywordStarargsNode expandKwargsNode,
216-
@Exclusive @Cached CallNode callNode,
217-
@Cached ToJavaNode toJavaNode,
218-
@Cached ConditionProfile arityProfile,
219-
@Cached BranchProfile errorProfile,
220-
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
221-
@Exclusive @Cached GilNode gil) throws ArityException {
222-
boolean mustRelease = gil.acquire();
223-
try {
224-
if (arityProfile.profile(arguments.length != 3)) {
225-
CompilerDirectives.transferToInterpreterAndInvalidate();
226-
throw ArityException.create(3, 3, arguments.length);
227-
}
212+
@ExportMessage(name = "execute")
213+
static class Execute {
214+
215+
@Specialization(guards = "arguments.length == 3")
216+
static int init(InitWrapper self, Object[] arguments,
217+
@CachedLibrary("self") PythonNativeWrapperLibrary lib,
218+
@Cached ExecutePositionalStarargsNode.ExecutePositionalStarargsInteropNode posStarargsNode,
219+
@Cached ExpandKeywordStarargsNode expandKwargsNode,
220+
@Cached CallVarargsMethodNode callNode,
221+
@Cached ToJavaNode toJavaNode,
222+
@Cached BranchProfile errorProfile,
223+
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
224+
@Exclusive @Cached GilNode gil) {
225+
boolean mustRelease = gil.acquire();
228226
try {
229-
// convert args
230-
Object receiver = toJavaNode.execute(arguments[0]);
231-
Object starArgs = toJavaNode.execute(arguments[1]);
232-
Object kwArgs = toJavaNode.execute(arguments[2]);
233-
234-
Object[] starArgsArray = posStarargsNode.executeWithGlobalState(starArgs);
235-
Object[] pArgs = PositionalArgumentsNode.prependArgument(receiver, starArgsArray);
236-
PKeyword[] kwArgsArray = expandKwargsNode.execute(kwArgs);
237-
callNode.execute(null, lib.getDelegate(this), pArgs, kwArgsArray);
238-
return 0;
239-
} catch (PException e) {
240-
errorProfile.enter();
241-
transformExceptionToNativeNode.execute(null, e);
242-
return -1;
227+
try {
228+
// convert args
229+
Object receiver = toJavaNode.execute(arguments[0]);
230+
Object starArgs = toJavaNode.execute(arguments[1]);
231+
Object kwArgs = toJavaNode.execute(arguments[2]);
232+
233+
Object[] starArgsArray = posStarargsNode.executeWithGlobalState(starArgs);
234+
Object[] pArgs = PositionalArgumentsNode.prependArgument(receiver, starArgsArray);
235+
PKeyword[] kwArgsArray = expandKwargsNode.execute(kwArgs);
236+
callNode.execute(null, lib.getDelegate(self), pArgs, kwArgsArray);
237+
return 0;
238+
} catch (PException e) {
239+
errorProfile.enter();
240+
transformExceptionToNativeNode.execute(null, e);
241+
return -1;
242+
}
243+
} finally {
244+
gil.release(mustRelease);
243245
}
244-
} finally {
245-
gil.release(mustRelease);
246246
}
247-
}
248247

248+
@Specialization(guards = "arguments.length != 3")
249+
static int error(@SuppressWarnings("unused") InitWrapper self, Object[] arguments) throws ArityException {
250+
throw ArityException.create(3, 3, arguments.length);
251+
}
252+
253+
}
249254
}
250255

251256
@ExportLibrary(InteropLibrary.class)

0 commit comments

Comments
 (0)