From owner-freebsd-java@freebsd.org Tue Apr 11 22:28:19 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 9D430D3A5FE for ; Tue, 11 Apr 2017 22:28:19 +0000 (UTC) (envelope-from eric@vangyzen.net) Received: from smtp.vangyzen.net (hotblack.vangyzen.net [IPv6:2607:fc50:1000:7400:216:3eff:fe72:314f]) by mx1.freebsd.org (Postfix) with ESMTP id 87DF36D5 for ; Tue, 11 Apr 2017 22:28:19 +0000 (UTC) (envelope-from eric@vangyzen.net) Received: from imac.home.vangyzen.net (unknown [76.164.15.242]) by smtp.vangyzen.net (Postfix) with ESMTPSA id D894C5646B; Tue, 11 Apr 2017 17:28:12 -0500 (CDT) Subject: Re: OpenJDK8 Thread.sleep will deadlock while turn down system date time. To: redraiment@gmail.com, freebsd-java@freebsd.org Cc: Konstantin Belousov References: <20170408070340.GD1788@kib.kiev.ua> From: Eric van Gyzen Message-ID: Date: Tue, 11 Apr 2017 17:28:12 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 In-Reply-To: <20170408070340.GD1788@kib.kiev.ua> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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: Tue, 11 Apr 2017 22:28:19 -0000 On 4/8/17 2:03 AM, Konstantin Belousov wrote: > On Fri, Apr 07, 2017 at 08:12:42PM -0700, ????????? wrote: >> Hi all, >> >> I found a Java process deadlock issue, and can be reproduced in FreeBSD >> 10.3 and 11.0 . >> >> My environment: >> >> * VirutalBox 5.1.16 r113841 on Mac OS X 10.12.4 >> * FreeBSD-11.0-RELEASE-amd64.vhd.xz >> >> Reproduction steps: >> >> 1. install openjdk8 >> >> ```sh >> pkg install openjdk8 >> ``` >> >> 2. Java source code >> >> ```java >> public class Main { >> public static void main(String[] args) { >> while (true) { >> System.out.println("tick"); >> Thread.sleep(3000); >> } >> } >> } >> ``` >> >> 3. Run java >> >> ```sh >> $ javac Main.java >> $ java Main >> tick >> tick >> ... >> ``` >> >> 4. Turn down system date time. >> >> ```sh >> $ date '+%Y-%m-%d %H:%M:%S' >> 20170408 11:09:11 >> $ date 201001010000 >> Fri Jan 1 00:00:00 CST 2010 >> ``` >> >> Then, the java process will hung. > Hang != deadlock, why do you claim that the process deadlocked. >> >> The issue will reproduce while turn "DOWN" the date time. It's OK while >> turn up the date time. > > 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.) Eric