mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8307425: Socket input stream read burns CPU cycles with back-to-back poll(0) calls
Reviewed-by: alanb
This commit is contained in:
parent
e2b1013f11
commit
73ac710533
3 changed files with 22 additions and 2 deletions
|
@ -78,6 +78,9 @@ import sun.net.ResourceManager;
|
||||||
import sun.net.ext.ExtendedSocketOptions;
|
import sun.net.ext.ExtendedSocketOptions;
|
||||||
import sun.net.util.IPAddressUtil;
|
import sun.net.util.IPAddressUtil;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of DatagramChannels.
|
* An implementation of DatagramChannels.
|
||||||
*/
|
*/
|
||||||
|
@ -497,7 +500,12 @@ class DatagramChannelImpl
|
||||||
if (nanos == 0) {
|
if (nanos == 0) {
|
||||||
millis = -1;
|
millis = -1;
|
||||||
} else {
|
} else {
|
||||||
millis = TimeUnit.NANOSECONDS.toMillis(nanos);
|
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);
|
Net.poll(getFD(), event, millis);
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,6 +182,11 @@ public final class NioSocketImpl extends SocketImpl implements PlatformSocketImp
|
||||||
millis = -1;
|
millis = -1;
|
||||||
} else {
|
} else {
|
||||||
millis = NANOSECONDS.toMillis(nanos);
|
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);
|
Net.poll(fd, event, millis);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2022, 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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -28,6 +28,8 @@ package sun.nio.ch;
|
||||||
import java.nio.channels.Channel;
|
import java.nio.channels.Channel;
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,6 +92,11 @@ public interface SelChImpl extends Channel {
|
||||||
millis = -1;
|
millis = -1;
|
||||||
} else {
|
} else {
|
||||||
millis = NANOSECONDS.toMillis(nanos);
|
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);
|
Net.poll(getFD(), event, millis);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue