RFR 9: 8064932: test java/lang/ProcessBuilder/Basic.java: waitFor didn't take long enough
David Holmes
david.holmes at oracle.com
Tue Nov 18 05:02:05 UTC 2014
Hi Martin,
On 18/11/2014 2:49 PM, Martin Buchholz wrote:
> Hi David,
>
> I'm still hoping to persuade you (and others) to fix the long-standing
> return-early bug in Object.wait.
Are you referring to the low level mechanics or specifically to the
nanosecond version below?
> As new support for my position I offer the "at least" in JLS
> https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.2.1
>
> """
>
> If this is a timed wait, an internal action removing t from m's wait
> set that occurs after at least millisecs milliseconds plusnanosecs
> nanoseconds elapse since the beginning of this wait action.
>
> """
>
> --- a/src/java.base/share/classes/java/lang/Object.java
> +++ b/src/java.base/share/classes/java/lang/Object.java
> @@ -444,16 +444,17 @@
> * this exception is thrown.
> */
> public final void wait(long timeout, int nanos) throws
> InterruptedException {
> - if (timeout < 0) {
> - throw new IllegalArgumentException("timeout value is negative");
> - }
> + if (nanos != 0) {
> + if (timeout < 0) {
> + throw new IllegalArgumentException
> + ("timeout value is negative");
> + }
>
> - if (nanos < 0 || nanos > 999999) {
> - throw new IllegalArgumentException(
> - "nanosecond timeout value out of range");
> - }
> + if (nanos < 0 || nanos > 999999) {
> + throw new IllegalArgumentException
> + ("nanosecond timeout value out of range");
> + }
>
> - if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
> timeout++;
> }
That seems overly complex - after checking for valid values of timeout
and nanos you simply need:
if (nanos > 0) timeout++;
to ensure the >= requirement.
But seriously we should just deprecate this version as we're not likely
to get any underlying OS mechanisms for doing nanosecond resolution
timed blocking actions.
David
-----
>
>
> On Mon, Nov 17, 2014 at 6:11 PM, David Holmes <david.holmes at oracle.com> wrote:
>
>>> On 11/17/2014 2:54 PM, Martin Buchholz wrote:
>>>>
>>>> Returning early is EVIL.
>>
>>
>> Yet every OS seems to allow it <sigh>
More information about the core-libs-dev
mailing list