88
88
import com .oracle .graal .python .lib .PyObjectCallMethodObjArgs ;
89
89
import com .oracle .graal .python .nodes .ErrorMessages ;
90
90
import com .oracle .graal .python .nodes .PNodeWithContext ;
91
- import com .oracle .graal .python .nodes .PNodeWithRaise ;
91
+ import com .oracle .graal .python .nodes .PRaiseNode ;
92
92
import com .oracle .graal .python .nodes .attributes .LookupAttributeInMRONode ;
93
93
import com .oracle .graal .python .nodes .call .special .CallUnaryMethodNode ;
94
94
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
100
100
import com .oracle .truffle .api .dsl .Bind ;
101
101
import com .oracle .truffle .api .dsl .Cached ;
102
102
import com .oracle .truffle .api .dsl .Cached .Shared ;
103
+ import com .oracle .truffle .api .dsl .GenerateCached ;
104
+ import com .oracle .truffle .api .dsl .GenerateInline ;
103
105
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
104
106
import com .oracle .truffle .api .dsl .ImportStatic ;
105
107
import com .oracle .truffle .api .dsl .NodeFactory ;
@@ -123,19 +125,21 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
123
125
124
126
private static final byte [] BLOCKED = new byte [0 ];
125
127
126
- abstract static class RawReadNode extends PNodeWithRaise {
128
+ @ GenerateInline
129
+ @ GenerateCached (false )
130
+ abstract static class RawReadNode extends PNodeWithContext {
127
131
128
- public abstract byte [] execute (VirtualFrame frame , PBuffered self , int len );
132
+ public abstract byte [] execute (VirtualFrame frame , Node inliningTarget , PBuffered self , int len );
129
133
130
134
// This is the spec way
131
135
@ Specialization
132
- byte [] bufferedreaderRawRead (VirtualFrame frame , PBuffered self , int len ,
133
- @ Bind ( "this" ) Node inliningTarget ,
134
- @ Cached BytesNodes . ToBytesNode toBytes ,
135
- @ Cached PythonObjectFactory factory ,
136
- @ Cached PyObjectCallMethodObjArgs callMethodReadInto ,
137
- @ Cached PyNumberAsSizeNode asSizeNode ,
138
- @ Cached InlinedConditionProfile osError ) {
136
+ static byte [] bufferedreaderRawRead (VirtualFrame frame , Node inliningTarget , PBuffered self , int len ,
137
+ @ Cached ( inline = false ) BytesNodes . ToBytesNode toBytes ,
138
+ @ Cached ( inline = false ) PythonObjectFactory factory ,
139
+ @ Cached ( inline = false ) PyObjectCallMethodObjArgs callMethodReadInto ,
140
+ @ Cached ( inline = false ) PyNumberAsSizeNode asSizeNode ,
141
+ @ Cached InlinedConditionProfile osError ,
142
+ @ Cached PRaiseNode . Lazy lazyRaiseNode ) {
139
143
PByteArray memobj = factory .createByteArray (new byte [len ]);
140
144
// TODO _PyIO_trap_eintr [GR-23297]
141
145
Object res = callMethodReadInto .execute (frame , self .getRaw (), T_READINTO , memobj );
@@ -147,10 +151,10 @@ byte[] bufferedreaderRawRead(VirtualFrame frame, PBuffered self, int len,
147
151
try {
148
152
n = asSizeNode .executeExact (frame , res , ValueError );
149
153
} catch (PException e ) {
150
- throw raise (OSError , e , ErrorMessages .RAW_READINTO_FAILED );
154
+ throw lazyRaiseNode . get ( inliningTarget ). raise (OSError , e , ErrorMessages .RAW_READINTO_FAILED );
151
155
}
152
156
if (osError .profile (inliningTarget , n < 0 || n > len )) {
153
- throw raise (OSError , IO_S_INVALID_LENGTH , "readinto()" , n , len );
157
+ throw lazyRaiseNode . get ( inliningTarget ). raise (OSError , IO_S_INVALID_LENGTH , "readinto()" , n , len );
154
158
}
155
159
if (n > 0 && self .getAbsPos () != -1 ) {
156
160
self .incAbsPos (n );
@@ -170,12 +174,14 @@ byte[] bufferedreaderRawRead(VirtualFrame frame, PBuffered self, int len,
170
174
/**
171
175
* implementation of cpython/Modules/_io/bufferedio.c:_bufferedreader_fill_buffer
172
176
*/
177
+ @ GenerateInline
178
+ @ GenerateCached (false )
173
179
abstract static class FillBufferNode extends PNodeWithContext {
174
180
175
- public abstract int execute (VirtualFrame frame , PBuffered self );
181
+ public abstract int execute (VirtualFrame frame , Node inliningTarget , PBuffered self );
176
182
177
183
@ Specialization
178
- static int bufferedreaderFillBuffer (VirtualFrame frame , PBuffered self ,
184
+ static int bufferedreaderFillBuffer (VirtualFrame frame , Node inliningTarget , PBuffered self ,
179
185
@ Cached RawReadNode rawReadNode ) {
180
186
int start ;
181
187
if (isValidReadBuffer (self )) {
@@ -184,7 +190,7 @@ static int bufferedreaderFillBuffer(VirtualFrame frame, PBuffered self,
184
190
start = 0 ;
185
191
}
186
192
int len = self .getBufferSize () - start ;
187
- byte [] fill = rawReadNode .execute (frame , self , len );
193
+ byte [] fill = rawReadNode .execute (frame , inliningTarget , self , len );
188
194
if (fill == BLOCKED ) {
189
195
return -2 ;
190
196
}
@@ -276,7 +282,7 @@ Object bufferedreaderReadGeneric(VirtualFrame frame, PBuffered self, int size,
276
282
@ Shared @ Cached EnterBufferedNode lock ,
277
283
@ Cached RawReadNode rawReadNode ,
278
284
@ Cached FillBufferNode fillBufferNode ,
279
- @ Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode ) {
285
+ @ Shared @ Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode ) {
280
286
checkIsClosedNode .execute (frame , self );
281
287
try {
282
288
lock .enter (inliningTarget , self );
@@ -306,7 +312,7 @@ If we had readv() we could do this in one pass. */
306
312
if (r == 0 ) {
307
313
break ;
308
314
}
309
- byte [] fill = rawReadNode .execute (frame , self , r );
315
+ byte [] fill = rawReadNode .execute (frame , inliningTarget , self , r );
310
316
if (fill == BLOCKED ) {
311
317
r = -2 ;
312
318
} else {
@@ -331,7 +337,7 @@ If we had readv() we could do this in one pass. */
331
337
reads, which could block indefinitely (e.g. on a socket).
332
338
See issue #9550. */
333
339
while (remaining > 0 && self .getReadEnd () < self .getBufferSize ()) {
334
- int r = fillBufferNode .execute (frame , self );
340
+ int r = fillBufferNode .execute (frame , inliningTarget , self );
335
341
if (r == 0 || r == -2 ) {
336
342
/* EOF occurred */
337
343
if (r == 0 || written > 0 ) {
@@ -373,7 +379,7 @@ reads, which could block indefinitely (e.g. on a socket).
373
379
Object bufferedreaderReadAll (VirtualFrame frame , PBuffered self , @ SuppressWarnings ("unused" ) int size ,
374
380
@ Bind ("this" ) Node inliningTarget ,
375
381
@ Shared @ Cached EnterBufferedNode lock ,
376
- @ Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode ,
382
+ @ Shared @ Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode ,
377
383
@ Cached ("create(T_READALL)" ) LookupAttributeInMRONode readallAttr ,
378
384
@ Cached InlinedConditionProfile hasReadallProfile ,
379
385
@ Cached InlinedConditionProfile currentSize0Profile ,
@@ -500,7 +506,7 @@ PBytes doit(VirtualFrame frame, PBuffered self, int size,
500
506
try {
501
507
lock .enter (inliningTarget , self );
502
508
self .resetRead (); // _bufferedreader_reset_buf
503
- byte [] fill = rawReadNode .execute (frame , self , n );
509
+ byte [] fill = rawReadNode .execute (frame , inliningTarget , self , n );
504
510
return factory ().createBytes (fill == BLOCKED ? PythonUtils .EMPTY_BYTE_ARRAY : fill );
505
511
} finally {
506
512
EnterBufferedNode .leave (self );
@@ -519,6 +525,7 @@ abstract static class ReadIntoNode extends PythonBinaryWithInitErrorClinicBuilti
519
525
* implementation of cpython/Modules/_io/bufferedio.c:_buffered_readinto_generic
520
526
*/
521
527
@ Specialization (guards = "self.isOK()" , limit = "3" )
528
+ @ SuppressWarnings ("truffle-static-method" )
522
529
Object bufferedReadintoGeneric (VirtualFrame frame , PBuffered self , Object buffer ,
523
530
@ Bind ("this" ) Node inliningTarget ,
524
531
@ CachedLibrary ("buffer" ) PythonBufferAccessLibrary bufferLib ,
@@ -558,7 +565,7 @@ Object bufferedReadintoGeneric(VirtualFrame frame, PBuffered self, Object buffer
558
565
caller's buffer.
559
566
*/
560
567
if (remaining > self .getBufferSize ()) {
561
- byte [] fill = rawReadNode .execute (frame , self , remaining );
568
+ byte [] fill = rawReadNode .execute (frame , inliningTarget , self , remaining );
562
569
if (fill == BLOCKED ) {
563
570
n = -2 ;
564
571
} else {
@@ -570,7 +577,7 @@ Object bufferedReadintoGeneric(VirtualFrame frame, PBuffered self, Object buffer
570
577
In readinto1 mode, we do not want to fill the internal buffer if we already have
571
578
some data to return
572
579
*/
573
- n = fillBufferNode .execute (frame , self );
580
+ n = fillBufferNode .execute (frame , inliningTarget , self );
574
581
if (n > 0 ) {
575
582
if (n > remaining ) {
576
583
n = remaining ;
@@ -632,13 +639,14 @@ protected ArgumentClinicProvider getArgumentClinic() {
632
639
/**
633
640
* implementation of cpython/Modules/_io/bufferedio.c:_buffered_readline
634
641
*/
642
+ @ GenerateInline
643
+ @ GenerateCached (false )
635
644
abstract static class BufferedReadlineNode extends PNodeWithContext {
636
645
637
- public abstract byte [] execute (VirtualFrame frame , PBuffered self , int size );
646
+ public abstract byte [] execute (VirtualFrame frame , Node inliningTarget , PBuffered self , int size );
638
647
639
648
@ Specialization
640
- static byte [] readline (VirtualFrame frame , PBuffered self , int size ,
641
- @ Bind ("this" ) Node inliningTarget ,
649
+ static byte [] readline (VirtualFrame frame , Node inliningTarget , PBuffered self , int size ,
642
650
@ Cached EnterBufferedNode lock ,
643
651
@ Cached FlushAndRewindUnlockedNode flushAndRewindUnlockedNode ,
644
652
@ Cached FillBufferNode fillBufferNode ,
@@ -684,7 +692,7 @@ static byte[] readline(VirtualFrame frame, PBuffered self, int size,
684
692
685
693
while (true ) {
686
694
self .resetRead (); // _bufferedreader_reset_buf
687
- n = fillBufferNode .execute (frame , self );
695
+ n = fillBufferNode .execute (frame , inliningTarget , self );
688
696
if (n <= 0 ) {
689
697
break ;
690
698
}
@@ -728,11 +736,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
728
736
}
729
737
730
738
@ Specialization (guards = "self.isOK()" )
739
+ @ SuppressWarnings ("truffle-static-method" )
731
740
PBytes doit (VirtualFrame frame , PBuffered self , int size ,
741
+ @ Bind ("this" ) Node inliningTarget ,
732
742
@ Cached ("create(T_READLINE)" ) CheckIsClosedNode checkIsClosedNode ,
733
743
@ Cached BufferedReadlineNode readlineNode ) {
734
744
checkIsClosedNode .execute (frame , self );
735
- byte [] res = readlineNode .execute (frame , self , size );
745
+ byte [] res = readlineNode .execute (frame , inliningTarget , self , size );
736
746
return factory ().createBytes (res );
737
747
}
738
748
}
@@ -750,7 +760,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
750
760
/**
751
761
* implementation of cpython/Modules/_io/bufferedio.c:_bufferedreader_peek_unlocked
752
762
*/
753
- static byte [] bufferedreaderPeekUnlocked (VirtualFrame frame , PBuffered self ,
763
+ static byte [] bufferedreaderPeekUnlocked (VirtualFrame frame , Node inliningTarget , PBuffered self ,
754
764
FillBufferNode fillBufferNode ) {
755
765
int have = safeDowncast (self );
756
766
/*-
@@ -765,7 +775,7 @@ static byte[] bufferedreaderPeekUnlocked(VirtualFrame frame, PBuffered self,
765
775
766
776
/* Fill the buffer from the raw stream, and copy it to the result. */
767
777
self .resetRead (); // _bufferedreader_reset_buf
768
- int r = fillBufferNode .execute (frame , self );
778
+ int r = fillBufferNode .execute (frame , inliningTarget , self );
769
779
if (r == -2 ) {
770
780
r = 0 ;
771
781
}
@@ -774,6 +784,7 @@ static byte[] bufferedreaderPeekUnlocked(VirtualFrame frame, PBuffered self,
774
784
}
775
785
776
786
@ Specialization (guards = "self.isOK()" )
787
+ @ SuppressWarnings ("truffle-static-method" )
777
788
Object doit (VirtualFrame frame , PBuffered self , @ SuppressWarnings ("unused" ) int size ,
778
789
@ Bind ("this" ) Node inliningTarget ,
779
790
@ Cached EnterBufferedNode lock ,
@@ -786,7 +797,7 @@ Object doit(VirtualFrame frame, PBuffered self, @SuppressWarnings("unused") int
786
797
if (self .isWritable ()) {
787
798
flushAndRewindUnlockedNode .execute (frame , inliningTarget , self );
788
799
}
789
- return factory ().createBytes (bufferedreaderPeekUnlocked (frame , self , fillBufferNode ));
800
+ return factory ().createBytes (bufferedreaderPeekUnlocked (frame , inliningTarget , self , fillBufferNode ));
790
801
} finally {
791
802
EnterBufferedNode .leave (self );
792
803
}
@@ -799,11 +810,13 @@ Object doit(VirtualFrame frame, PBuffered self, @SuppressWarnings("unused") int
799
810
abstract static class NextNode extends PythonUnaryWithInitErrorBuiltinNode {
800
811
801
812
@ Specialization (guards = "self.isOK()" )
813
+ @ SuppressWarnings ("truffle-static-method" )
802
814
PBytes doit (VirtualFrame frame , PBuffered self ,
815
+ @ Bind ("this" ) Node inliningTarget ,
803
816
@ Cached ("create(T_READLINE)" ) CheckIsClosedNode checkIsClosedNode ,
804
817
@ Cached BufferedReadlineNode readlineNode ) {
805
818
checkIsClosedNode .execute (frame , self );
806
- byte [] line = readlineNode .execute (frame , self , -1 );
819
+ byte [] line = readlineNode .execute (frame , inliningTarget , self , -1 );
807
820
if (line .length == 0 ) {
808
821
throw raiseStopIteration ();
809
822
}
0 commit comments