@@ -298,6 +298,8 @@ public abstract static class WriteToChannelNode extends WriteToChannelBaseNode {
298
298
299
299
@ Specialization
300
300
int writeSeekable (SeekableByteChannel channel , SequenceStorage s , int len ,
301
+ @ Cached BranchProfile limitProfile ,
302
+ @ Cached ("createBinaryProfile()" ) ConditionProfile maxSizeProfile ,
301
303
@ Cached PRaiseNode raise ) {
302
304
long availableSize ;
303
305
try {
@@ -306,31 +308,34 @@ int writeSeekable(SeekableByteChannel channel, SequenceStorage s, int len,
306
308
gotException .enter ();
307
309
throw raise .raise (OSError , e );
308
310
}
309
- if (availableSize > MAX_WRITE ) {
311
+ if (maxSizeProfile . profile ( availableSize > MAX_WRITE ) ) {
310
312
availableSize = MAX_WRITE ;
311
313
}
312
314
int sz = (int ) Math .min (availableSize , len );
313
- return writeWritable (channel , s , sz , raise );
314
-
315
+ return writeWritable (channel , s , sz , limitProfile , raise );
315
316
}
316
317
317
318
@ Specialization
318
319
int writeWritable (WritableByteChannel channel , SequenceStorage s , int len ,
320
+ @ Cached BranchProfile limitProfile ,
319
321
@ Cached PRaiseNode raise ) {
320
322
ByteBuffer src = allocateBuffer (getBytes (s ));
321
323
if (src .remaining () > len ) {
324
+ limitProfile .enter ();
322
325
src .limit (len );
323
326
}
324
327
return writeFromBuffer (channel , src , raise );
325
328
}
326
329
327
330
@ Specialization
328
331
int writeGeneric (Channel channel , SequenceStorage s , int len ,
332
+ @ Cached BranchProfile limitProfile ,
333
+ @ Cached ("createBinaryProfile()" ) ConditionProfile maxSizeProfile ,
329
334
@ Cached PRaiseNode raise ) {
330
335
if (channel instanceof SeekableByteChannel ) {
331
- return writeSeekable ((SeekableByteChannel ) channel , s , len , raise );
336
+ return writeSeekable ((SeekableByteChannel ) channel , s , len , limitProfile , maxSizeProfile , raise );
332
337
} else if (channel instanceof ReadableByteChannel ) {
333
- return writeWritable ((WritableByteChannel ) channel , s , len , raise );
338
+ return writeWritable ((WritableByteChannel ) channel , s , len , limitProfile , raise );
334
339
} else {
335
340
throw raise .raise (OSError , "file not opened for reading" );
336
341
}
0 commit comments