Skip to content

Commit

Permalink
8307425: Socket input stream read burns CPU cycles with back-to-back …
Browse files Browse the repository at this point in the history
…poll(0) calls

Reviewed-by: ogillespie, shade
Backport-of: 73ac710533a45bf5ba17f308aa49556b877b8bf9
  • Loading branch information
roy-soumadipta authored and shipilev committed May 17, 2023
1 parent 1087e3b commit 7610862
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -177,6 +177,11 @@ private void park(FileDescriptor fd, int event, long nanos) throws IOException {
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);
}
Expand Down
8 changes: 7 additions & 1 deletion src/java.base/share/classes/sun/nio/ch/SelChImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -29,6 +29,7 @@
import java.io.FileDescriptor;
import java.io.IOException;

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.NANOSECONDS;

/**
Expand Down Expand Up @@ -88,6 +89,11 @@ default void park(int event, long nanos) throws IOException {
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);
}
Expand Down

1 comment on commit 7610862

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.