RFR: JDK-8249367: JShell uses 100% of one core all the time

Robert Field robert.field at oracle.com
Wed Jul 15 18:01:12 UTC 2020


Thanks Jan!

+1


-Robert

On 7/15/20 5:15 AM, Jan Lahoda wrote:
> Hi,
>
> JShell consumes basically a 100% of one CPU thread on Windows all the 
> time while waiting for a user input. The reason is that:
> -JShell's StopDetectingInputStream invokes "read()" method  on 
> NonBlockingReaderInputStream (without a timeout, which is an addition 
> of JLine's non blocking streams and readers), which is converted to a 
> read with timeout 0. The NonBlockingReaderInputStream then delegates 
> to NonBlockingPumpReader, using its read method with timeout 0. But 
> with timeout zero, this particular reader returns immediately, and 
> because there was no input, and no timeout set to 
> NonBlockingReaderInputStream, it will loop and ask the 
> NonBlockingPumpReader again, and ultimately 
> NonBlockingReaderInputStream.read spins in a loop.
>
> The ultimate problem is, I believe, in NonBlockingPumpReader, which 
> should not return immediately for timeout 0 (other non blocking 
> streams/readers wait indefinitely for input for timeout 0). I have 
> filled a bug to JLine for this:
> https://github.com/jline/jline3/issues/552
>
> But, mostly as a workaround, I suggest that StopDetectingInputStream 
> uses a timeout while reading from non blocking streams. That should be 
> safe, and we can revert to the current state when the above bug is fixed.
>
> Proposed patch:
> http://cr.openjdk.java.net/~jlahoda/8249367/webrev.00/
>
> JBS:
> https://bugs.openjdk.java.net/browse/JDK-8249367
>
> What do you think?
>
> Thanks,
>     Jan


More information about the kulla-dev mailing list