Skip to content

Commit 2f09f21

Browse files
msimacektimfel
authored andcommitted
Inline call/lookup nodes from IONodes
1 parent 6f9c200 commit 2f09f21

14 files changed

+274
-559
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOBaseBuiltins.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import com.oracle.graal.python.builtins.PythonBuiltins;
6161
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
6262
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
63+
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
6364
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
6465
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
6566
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode;
@@ -125,7 +126,7 @@ Object read1(Object self, Object args) {
125126
abstract static class ReadIntoGenericNode extends PythonBinaryClinicBuiltinNode {
126127

127128
@SuppressWarnings("unused")
128-
protected Object callRead(VirtualFrame frame, Object self, int len) {
129+
protected String getMethodName() {
129130
throw CompilerDirectives.shouldNotReachHere("abstract");
130131
}
131132

@@ -135,11 +136,12 @@ protected Object callRead(VirtualFrame frame, Object self, int len) {
135136
@Specialization
136137
Object readinto(VirtualFrame frame, Object self, Object buffer,
137138
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
139+
@Cached PyObjectCallMethodObjArgs callMethod,
138140
@Cached ConditionProfile isBytes,
139141
@Cached ConditionProfile oversize) {
140142
try {
141143
int len = bufferLib.getBufferLength(buffer);
142-
Object data = callRead(frame, self, len);
144+
Object data = callMethod.execute(frame, self, getMethodName(), len);
143145
if (isBytes.profile(!(data instanceof PBytes))) {
144146
throw raise(ValueError, S_SHOULD_RETURN_BYTES, "read()");
145147
}
@@ -166,11 +168,9 @@ protected ArgumentClinicProvider getArgumentClinic() {
166168
@ArgumentClinic(name = "buffer", conversion = ArgumentClinic.ClinicConversion.WritableBuffer)
167169
@GenerateNodeFactory
168170
abstract static class ReadIntoNode extends ReadIntoGenericNode {
169-
@Child IONodes.CallRead read = IONodesFactory.CallReadNodeGen.create();
170-
171171
@Override
172-
protected final Object callRead(VirtualFrame frame, Object self, int len) {
173-
return read.execute(frame, self, len);
172+
protected final String getMethodName() {
173+
return READ;
174174
}
175175

176176
@Override
@@ -183,11 +183,9 @@ protected ArgumentClinicProvider getArgumentClinic() {
183183
@ArgumentClinic(name = "buffer", conversion = ArgumentClinic.ClinicConversion.WritableBuffer)
184184
@GenerateNodeFactory
185185
abstract static class ReadInto1Node extends ReadIntoGenericNode {
186-
@Child IONodes.CallRead1 read1 = IONodesFactory.CallRead1NodeGen.create();
187-
188186
@Override
189-
protected final Object callRead(VirtualFrame frame, Object self, int len) {
190-
return read1.execute(frame, self, len);
187+
protected final String getMethodName() {
188+
return READ1;
191189
}
192190

193191
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOMixinBuiltins.java

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import static com.oracle.graal.python.builtins.modules.io.IONodes.CLOSED;
5454
import static com.oracle.graal.python.builtins.modules.io.IONodes.DETACH;
5555
import static com.oracle.graal.python.builtins.modules.io.IONodes.FILENO;
56+
import static com.oracle.graal.python.builtins.modules.io.IONodes.FLUSH;
5657
import static com.oracle.graal.python.builtins.modules.io.IONodes.ISATTY;
5758
import static com.oracle.graal.python.builtins.modules.io.IONodes.MODE;
5859
import static com.oracle.graal.python.builtins.modules.io.IONodes.NAME;
@@ -78,8 +79,10 @@
7879
import com.oracle.graal.python.builtins.CoreFunctions;
7980
import com.oracle.graal.python.builtins.objects.PNone;
8081
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
82+
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
83+
import com.oracle.graal.python.lib.PyObjectGetAttr;
8184
import com.oracle.graal.python.lib.PyObjectLookupAttr;
82-
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
85+
import com.oracle.graal.python.lib.PyObjectReprAsJavaStringNode;
8386
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
8487
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
8588
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryClinicBuiltinNode;
@@ -113,10 +116,10 @@ abstract static class CloseNode extends PythonUnaryWithInitErrorBuiltinNode {
113116

114117
private static Object close(VirtualFrame frame, PBuffered self,
115118
BufferedIONodes.EnterBufferedNode lock,
116-
IONodes.CallClose callClose) {
119+
PyObjectCallMethodObjArgs callMethodClose) {
117120
try {
118121
lock.enter(self);
119-
Object res = callClose.execute(frame, self.getRaw());
122+
Object res = callMethodClose.execute(frame, self.getRaw(), CLOSE);
120123
if (self.getBuffer() != null) {
121124
self.setBuffer(null);
122125
}
@@ -129,9 +132,9 @@ private static Object close(VirtualFrame frame, PBuffered self,
129132
@Specialization(guards = "self.isOK()")
130133
static Object doit(VirtualFrame frame, PBuffered self,
131134
@Cached BufferedIONodes.IsClosedNode isClosedNode,
132-
@Cached IONodes.CallFlush flush,
133-
@Cached IONodes.CallClose callClose,
134-
@Cached IONodes.CallDeallocWarn deallocWarn,
135+
@Cached PyObjectCallMethodObjArgs callMethodFlush,
136+
@Cached PyObjectCallMethodObjArgs callMethodClose,
137+
@Cached PyObjectCallMethodObjArgs callMethodDeallocWarn,
135138
@Cached BufferedIONodes.EnterBufferedNode lock,
136139
@Cached ConditionProfile profile) {
137140
try {
@@ -141,25 +144,25 @@ static Object doit(VirtualFrame frame, PBuffered self,
141144
}
142145
if (self.isFinalizing()) {
143146
if (self.getRaw() != null) {
144-
deallocWarn.execute(frame, self.getRaw(), self);
147+
callMethodDeallocWarn.execute(frame, self.getRaw(), _DEALLOC_WARN, self);
145148
}
146149
}
147150
} finally {
148151
BufferedIONodes.EnterBufferedNode.leave(self);
149152
}
150153
/* flush() will most probably re-take the lock, so drop it first */
151154
try {
152-
flush.execute(frame, self);
155+
callMethodFlush.execute(frame, self, FLUSH);
153156
} catch (PException e) {
154157
try {
155-
close(frame, self, lock, callClose);
158+
close(frame, self, lock, callMethodClose);
156159
} catch (PException ee) {
157160
chainExceptions(ee.getEscapedException(), e);
158161
throw ee.getExceptionForReraise();
159162
}
160163
throw e;
161164
}
162-
return close(frame, self, lock, callClose);
165+
return close(frame, self, lock, callMethodClose);
163166
}
164167
}
165168

@@ -168,8 +171,8 @@ static Object doit(VirtualFrame frame, PBuffered self,
168171
abstract static class DetachNode extends PythonUnaryWithInitErrorBuiltinNode {
169172
@Specialization(guards = "self.isOK()")
170173
static Object doit(VirtualFrame frame, PBuffered self,
171-
@Cached IONodes.CallFlush flush) {
172-
flush.execute(frame, self);
174+
@Cached PyObjectCallMethodObjArgs callMethodFlush) {
175+
callMethodFlush.execute(frame, self, FLUSH);
173176
Object raw = self.getRaw();
174177
self.clearRaw();
175178
self.setDetached(true);
@@ -183,8 +186,8 @@ static Object doit(VirtualFrame frame, PBuffered self,
183186
abstract static class SeekableNode extends PythonUnaryWithInitErrorBuiltinNode {
184187
@Specialization(guards = "self.isOK()")
185188
static Object doit(VirtualFrame frame, PBuffered self,
186-
@Cached IONodes.CallSeekable seekable) {
187-
return seekable.execute(frame, self.getRaw());
189+
@Cached PyObjectCallMethodObjArgs callMethod) {
190+
return callMethod.execute(frame, self.getRaw(), SEEKABLE);
188191
}
189192
}
190193

@@ -193,8 +196,8 @@ static Object doit(VirtualFrame frame, PBuffered self,
193196
abstract static class FileNoNode extends PythonUnaryWithInitErrorBuiltinNode {
194197
@Specialization(guards = "self.isOK()")
195198
static Object doit(VirtualFrame frame, PBuffered self,
196-
@Cached IONodes.CallFileNo fileNo) {
197-
return fileNo.execute(frame, self.getRaw());
199+
@Cached PyObjectCallMethodObjArgs callMethod) {
200+
return callMethod.execute(frame, self.getRaw(), FILENO);
198201
}
199202
}
200203

@@ -203,8 +206,8 @@ static Object doit(VirtualFrame frame, PBuffered self,
203206
abstract static class IsAttyNode extends PythonUnaryWithInitErrorBuiltinNode {
204207
@Specialization(guards = "self.isOK()")
205208
static Object doit(VirtualFrame frame, PBuffered self,
206-
@Cached IONodes.CallIsAtty isAtty) {
207-
return isAtty.execute(frame, self.getRaw());
209+
@Cached PyObjectCallMethodObjArgs callMethod) {
210+
return callMethod.execute(frame, self.getRaw(), ISATTY);
208211
}
209212
}
210213

@@ -213,8 +216,8 @@ static Object doit(VirtualFrame frame, PBuffered self,
213216
abstract static class DeallocWarnNode extends PythonBinaryBuiltinNode {
214217
@Specialization(guards = {"self.isOK()", "self.getRaw() != null"})
215218
static Object doit(VirtualFrame frame, PBuffered self, Object source,
216-
@Cached IONodes.CallDeallocWarn deallocWarn) {
217-
deallocWarn.execute(frame, self.getRaw(), source);
219+
@Cached PyObjectCallMethodObjArgs callMethod) {
220+
callMethod.execute(frame, self.getRaw(), _DEALLOC_WARN, source);
218221
return PNone.NONE;
219222
}
220223

@@ -296,12 +299,12 @@ static Object doit(VirtualFrame frame, PBuffered self, Object pos,
296299
@Cached("create(TRUNCATE)") BufferedIONodes.CheckIsClosedNode checkIsClosedNode,
297300
@Cached BufferedIONodes.RawTellNode rawTellNode,
298301
@Cached BufferedIONodes.FlushAndRewindUnlockedNode flushAndRewindUnlockedNode,
299-
@Cached IONodes.CallTruncate truncate) {
302+
@Cached PyObjectCallMethodObjArgs callMethodTruncate) {
300303
checkIsClosedNode.execute(frame, self);
301304
try {
302305
lock.enter(self);
303306
flushAndRewindUnlockedNode.execute(frame, self);
304-
Object res = truncate.execute(frame, self.getRaw(), pos);
307+
Object res = callMethodTruncate.execute(frame, self.getRaw(), TRUNCATE, pos);
305308
/* Reset cached position */
306309
rawTellNode.execute(frame, self);
307310
return res;
@@ -349,8 +352,8 @@ static Object doit(VirtualFrame frame, PBuffered self,
349352
abstract static class NameNode extends PythonUnaryWithInitErrorBuiltinNode {
350353
@Specialization(guards = "self.isOK()")
351354
static Object doit(VirtualFrame frame, PBuffered self,
352-
@Cached IONodes.GetName getName) {
353-
return getName.execute(frame, self.getRaw());
355+
@Cached PyObjectGetAttr getAttr) {
356+
return getAttr.execute(frame, self.getRaw(), NAME);
354357
}
355358
}
356359

@@ -359,8 +362,8 @@ static Object doit(VirtualFrame frame, PBuffered self,
359362
abstract static class ModeNode extends PythonUnaryWithInitErrorBuiltinNode {
360363
@Specialization(guards = "self.isOK()")
361364
static Object doit(VirtualFrame frame, PBuffered self,
362-
@Cached IONodes.GetMode getMode) {
363-
return getMode.execute(frame, self.getRaw());
365+
@Cached PyObjectGetAttr getAttr) {
366+
return getAttr.execute(frame, self.getRaw(), MODE);
364367
}
365368
}
366369

@@ -373,8 +376,8 @@ Object repr(VirtualFrame frame, PBuffered self,
373376
@Cached TypeNodes.GetNameNode getNameNode,
374377
@Cached GetClassNode getClassNode,
375378
@Cached IsBuiltinClassProfile isValueError,
376-
@Cached("create(__REPR__)") LookupAndCallUnaryNode repr) {
377-
Object clazz = getNameNode.execute(getClassNode.execute(self));
379+
@Cached PyObjectReprAsJavaStringNode repr) {
380+
String typeName = getNameNode.execute(getClassNode.execute(self));
378381
Object nameobj = PNone.NO_VALUE;
379382
try {
380383
nameobj = lookup.execute(frame, self, NAME);
@@ -383,14 +386,14 @@ Object repr(VirtualFrame frame, PBuffered self,
383386
// ignore
384387
}
385388
if (nameobj instanceof PNone) {
386-
return PythonUtils.format("<%s>", clazz);
389+
return PythonUtils.format("<%s>", typeName);
387390
} else {
388391
if (!getContext().reprEnter(self)) {
389-
throw raise(RuntimeError, "reentrant call inside %s.__repr__", clazz);
392+
throw raise(RuntimeError, "reentrant call inside %s.__repr__", typeName);
390393
} else {
391394
try {
392-
Object name = repr.executeObject(frame, nameobj);
393-
return PythonUtils.format("<%s name=%s>", clazz, name);
395+
String name = repr.execute(frame, nameobj);
396+
return PythonUtils.format("<%s name=%s>", typeName, name);
394397
} finally {
395398
getContext().reprLeave(self);
396399
}

0 commit comments

Comments
 (0)