From owner-freebsd-java@freebsd.org Wed Apr 12 00:03:06 2017 Return-Path: Delivered-To: freebsd-java@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1A2CAD3A346 for ; Wed, 12 Apr 2017 00:03:06 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.netplex.net", Issuer "RapidSSL SHA256 CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D426794C for ; Wed, 12 Apr 2017 00:03:05 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.15.1/8.15.1/NETPLEX) with ESMTP id v3BNtvWb037329; Tue, 11 Apr 2017 19:55:57 -0400 X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.4.3 (mail.netplex.net [204.213.176.9]); Tue, 11 Apr 2017 19:55:57 -0400 (EDT) Date: Tue, 11 Apr 2017 19:55:57 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net Reply-To: Daniel Eischen To: Eric van Gyzen cc: redraiment@gmail.com, freebsd-java@freebsd.org, Konstantin Belousov Subject: Re: OpenJDK8 Thread.sleep will deadlock while turn down system date time. In-Reply-To: Message-ID: References: <20170408070340.GD1788@kib.kiev.ua> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Apr 2017 00:03:06 -0000 On Tue, 11 Apr 2017, Eric van Gyzen wrote: > On 4/8/17 2:03 AM, Konstantin Belousov wrote: [ ... ] >> >> If JVM sets timeouts using absolute times than it might be fixed in latest >> HEAD and stable/11. > > The JVM uses pthread_cond_timedwait() to implement Thread.sleep(), so it > always uses absolute times. Furthermore, it uses the default clock, > CLOCK_REALTIME. My recent change (r315280) does not fix this behavior; in > fact, I believe it will make the problem worse, since moving the clock > forward will wake the thread prematurely. > > I think the JVM should be fixed to use CLOCK_MONOTONIC. Would someone like > to do the research to determine the correct behavior of Thread.sleep()? > Specifically, should the duration of the sleep be affected by adjustments to > the real-time clock? I expect that it should /not/ be affected, especially > since the API takes a relative/interval time. Ideally, we would find the > answer in the formal language specification; failing that, I would be > satisfied with empirical data from testing on Windows, Linux, MacOS, and > Solaris. I'll be happy to write a patch once we know what it should do. > > Please keep me CC'd, since I'm not on freebsd-java@. (Thanks for the CC, > Kostik.) It seems CLOCK_REALTIME behavior has bugged Linux in the past, too. I think using CLOCK_MONOTONIC, perhaps via pthread_condattr_setclock() in our JVM, would be the better approach. You'd probably also want to check that whatever java.util.concurrent relies on, if different, also behaves similarly (monotonically). -- DE