[jdk17u-dev] RFR: 8307425: Socket input stream read burns CPU cycles with back-to-back poll(0) calls
Christoph Langer
clanger at openjdk.org
Wed May 17 07:12:03 UTC 2023
On Wed, 10 May 2023 11:17:08 GMT, Soumadipta Roy <duke at openjdk.org> wrote:
> Backport 73ac710533a45bf5ba17f308aa49556b877b8bf9 to JDK 17u.
>
> Backporting the fix for https://bugs.openjdk.org/browse/JDK-8307425 merged as part of https://github.com/openjdk/jdk/pull/13798#
> Almost all the hunks were rejected. DatagramChannelImpl doesn't override park in jdk17, and hence has been left unchanged. Respective hunks for NioSocketImpl and SelChImpl were not cleanly applied due to the difference in how park is implemented for the respective classes between openjdk/jdk17u and openjdk/jdk. In openjdk/jdk in park, current thread is checked to be virtual or not and if that equates to true Poller.poll is used instead of Net.poll.
>
> NioSocketImpl.java in openjdk/jdk17u:
>
> private void park(FileDescriptor fd, int event, long nanos) throws IOException {
> long millis;
> if (nanos == 0) {
> millis = -1;
> } else {
> millis = NANOSECONDS.toMillis(nanos);
> }
> Net.poll(fd, event, millis);
> }
>
> NioSocketImpl.java in openjdk/jdk:
>
> private void park(FileDescriptor fd, int event, long nanos) throws IOException {
> Thread t = Thread.currentThread();
> if (t.isVirtual()) {
> Poller.poll(fdVal(fd), event, nanos, this::isOpen);
> if (t.isInterrupted()) {
> throw new InterruptedIOException();
> }
> } else {
> long millis;
> if (nanos == 0) {
> millis = -1;
> } else {
> millis = NANOSECONDS.toMillis(nanos);
> if (nanos > MILLISECONDS.toNanos(millis)) {
> // Round up any excess nanos to the nearest millisecond to
> // avoid parking for less than requested.
> millis++;
> }
> }
> Net.poll(fd, event, millis);
> }
> }
>
>
> SelChImpl.java in openjdk/jdk17u:
>
> default void park(int event, long nanos) throws IOException {
> long millis;
> if (nanos <= 0) {
> millis = -1;
> } else {
> millis = NANOSECONDS.toMillis(nanos);
> }
> Net.poll(getFD(), event, millis);
> }
>
> SelChImpl.java in openjdk/jdk17u:
>
> default void park(int event, long nanos) throws IOException {
> if (Thread.currentThread().isVirtual()) {
> Poller.poll(getFDVal(), event, nanos, this::isOpen);
> } else {
> long millis;
> if (nanos <= 0) {
> millis = -1;
> } e...
Thanks. Backport is approved and somebody can sponsor it now.
-------------
PR Comment: https://git.openjdk.org/jdk17u-dev/pull/1341#issuecomment-1550866316
More information about the jdk-updates-dev
mailing list