[jdk17u-dev] RFR: 8307425: Socket input stream read burns CPU cycles with back-to-back poll(0) calls

Soumadipta Roy duke at openjdk.org
Wed May 10 20:37:01 UTC 2023


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;
            } 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(getFD(), event, millis);
        }
    }

-------------

Commit messages:
 - Backport 73ac710533a45bf5ba17f308aa49556b877b8bf9

Changes: https://git.openjdk.org/jdk17u-dev/pull/1341/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk17u-dev&pr=1341&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8307425
  Stats: 13 lines in 2 files changed: 11 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/jdk17u-dev/pull/1341.diff
  Fetch: git fetch https://git.openjdk.org/jdk17u-dev.git pull/1341/head:pull/1341

PR: https://git.openjdk.org/jdk17u-dev/pull/1341


More information about the jdk-updates-dev mailing list