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

Soumadipta Roy duke at openjdk.org
Wed May 17 11:28:59 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...

This pull request has now been integrated.

Changeset: 76108622
Author:    Soumadipta Roy <roysouma at amazon.com>
Committer: Aleksey Shipilev <shade at openjdk.org>
URL:       https://git.openjdk.org/jdk17u-dev/commit/7610862256f900cd2091c47cd5ba05eeb337cc12
Stats:     13 lines in 2 files changed: 11 ins; 0 del; 2 mod

8307425: Socket input stream read burns CPU cycles with back-to-back poll(0) calls

Reviewed-by: ogillespie, shade
Backport-of: 73ac710533a45bf5ba17f308aa49556b877b8bf9

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

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


More information about the jdk-updates-dev mailing list