From owner-freebsd-java@FreeBSD.ORG Sun Jun 2 02:33:17 2013 Return-Path: Delivered-To: java@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id D7635EFF for ; Sun, 2 Jun 2013 02:33:17 +0000 (UTC) (envelope-from huanghwh@yahoo.com) Received: from nm25-vm4.bullet.mail.sg3.yahoo.com (nm25-vm4.bullet.mail.sg3.yahoo.com [106.10.151.99]) by mx1.freebsd.org (Postfix) with ESMTP id 168701AE for ; Sun, 2 Jun 2013 02:33:16 +0000 (UTC) Received: from [106.10.166.124] by nm25.bullet.mail.sg3.yahoo.com with NNFMP; 02 Jun 2013 02:33:10 -0000 Received: from [106.10.151.235] by tm13.bullet.mail.sg3.yahoo.com with NNFMP; 02 Jun 2013 02:33:10 -0000 Received: from [127.0.0.1] by omp1019.mail.sg3.yahoo.com with NNFMP; 02 Jun 2013 02:33:10 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 241205.95464.bm@omp1019.mail.sg3.yahoo.com Received: (qmail 35964 invoked by uid 60001); 2 Jun 2013 02:33:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1370140389; bh=Zfb6Vy11SqbVF//RuyJg269cYEFq4vbNByj7NfXesJY=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=h/NIXpBFxRpxBq5e9w2R5fFT8diSjjThbvQxb3mF6GgC/wDQj1RAhdbRItThti0ers1xWh0JTTvx9Lxt7IsqHG5cC5tpZlcNrPaoOj5QBShqtaKoUpDzxEHn7pwer4RDzNNWChSiqUxLU1oLudTXfiYz/svnNe7IgBEvzGr9BXQ= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=G2ZtV6s6w2rh7RWunLwFXMbhzQ9MI5PbK5Pdjr5SKFPwabNiIQY1KPIWuUH2rhkbNNDKjBMWc4TR25MWE20d2hTaXs5Tgl7EXVcPdDjVl9VQETROk9glc7GM1n5KmOocyIuAhKkoDyEaDqRNsH2b+BomCtJYhdUgZQ96CjS1AFA=; X-YMail-OSG: BxhubTkVM1kXZrKtCTElqJYP3O50xO9LUeqN2IU5LbUV.e2 GYPMLQfYQpvP1tBqpev5UtEstQfCFn3wIxtl.yBhsLjfT_XjtR4._Vr2ZGRX OBze3QJwE4L9ItXO4eRmhq20V.B.dnqQUEkQa4nYSq6pYfNCMYRNtJ62hhT2 8QLQYDANUIJWqe6woXcrq01HjhLiwAWcPqcyZ6rT7TNucIOnM3UyRys_oyXq 1QOpRcxOhW05WiIOISeJLP6U7EYFR8ead.cwoFqfNWpUzv.E0L5Ra4Oz5Edl GwLmt1.xHsB7pmS316vHygRJlNPvbuysgdpSu553yZd9RP0MlvlHVq78_5Eo HpQ.CEd8NgniCQTe.lMnv66m849KlfSxah1.B5iPDksvFvpdqinfY0pUaGNT NVs2rcZbWInjlCq080XGEuXHZWGpVMsUJro9GTlr2a7I- Received: from [219.141.159.61] by web15306.mail.cnb.yahoo.com via HTTP; Sun, 02 Jun 2013 10:33:09 CST X-Rocket-MIMEInfo: 002.001, SGksCkkgcmVjZW50bHkgZm91bmQgdGhhdCBDYXNzYW5kcmEgMS4yLjQgY291bGQgbm90IHNodXRkb3duIHdoZW4gZW5hYmxlIEpOQSwKc28gSSB0cnkgdG8gc29sdmUgaXQsIGFuZCBmb3VuZCB0aGF0IHVuZGVyIE9wZW5KREs2L0ZyZWVCU0QswqAKU3lzdGVtLmN1cnJlbnRUaW1lTWlsbGlzKCkgaXMgdG90YWxseSB3cm9uZyBhZnRlciBjYWxsIEpOQSBtbG9ja2FsbCwKdGltZSBzZWFtcyB0byBub3QgY2hhbmdlIGFueW1vcmUuCgpUaGUgc2FtcGxlIGNvZGUgbGlzdCBoZXJlOgoKaW1wb3J0IGphdmEudXRpbC4BMAEBAQE- X-Mailer: YahooMailWebService/0.8.145.547 Message-ID: <1370140389.34142.YahooMailNeo@web15306.mail.cnb.yahoo.com> Date: Sun, 2 Jun 2013 10:33:09 +0800 (CST) From: =?utf-8?B?6buE5paH6L6J?= Subject: System.currentTimeMillis() is totally wrong after call JNA mlockall To: "java@freebsd.org" MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: =?utf-8?B?6buE5paH6L6J?= List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Jun 2013 02:33:17 -0000 Hi,=0AI recently found that Cassandra 1.2.4 could not shutdown when enable = JNA,=0Aso I try to solve it, and found that under OpenJDK6/FreeBSD,=C2=A0= =0ASystem.currentTimeMillis() is totally wrong after call JNA mlockall,=0At= ime seams to not change anymore.=0A=0AThe sample code list here:=0A=0Aimpor= t java.util.Date;=0A=0Aimport com.sun.jna.LastErrorException;=0Aimport com.= sun.jna.Native;=0A=0Apublic class Test_mlockall2 {=0A=0A=C2=A0 static boole= an run =3D true;=0A=C2=A0 private static final int MCL_CURRENT =3D 1;=0A=C2= =A0 private static final int MCL_FUTURE =3D 2;=0A=0A=C2=A0 static { =C2=A0 = =C2=A0=0A=C2=A0 =C2=A0 try=0A=C2=A0 =C2=A0 {=0A=C2=A0 =C2=A0 =C2=A0 Native.= register("c");=0A=C2=A0 =C2=A0 }=0A=C2=A0 =C2=A0 catch (NoClassDefFoundErro= r e)=0A=C2=A0 =C2=A0 {=0A=C2=A0 =C2=A0 =C2=A0 System.err.println("JNA not f= ound. Native methods will be disabled.");=0A=C2=A0 =C2=A0 }=0A=C2=A0 =C2=A0= catch (UnsatisfiedLinkError e)=0A=C2=A0 =C2=A0 {=0A=C2=A0 =C2=A0 =C2=A0 Sy= stem.err.println("JNA link failure, one or more native method will be unava= ilable.");=0A=C2=A0 =C2=A0 =C2=A0 System.err.println("JNA link failure deta= ils: " + e.getMessage());=0A=C2=A0 =C2=A0 }=0A=C2=A0 =C2=A0 catch (NoSuchMe= thodError e)=0A=C2=A0 =C2=A0 {=0A=C2=A0 =C2=A0 =C2=A0 System.err.println("O= bsolete version of JNA present; unable to register C library. Upgrade to JN= A 3.2.7 or later");=0A=C2=A0 =C2=A0 }=0A=0A=C2=A0 }=0A=0A=C2=A0 private sta= tic native int mlockall(int flags) throws LastErrorException;=0A=0A=C2=A0 p= ublic static void tryMlockall()=0A=C2=A0 {=0A=C2=A0 =C2=A0 try=0A=C2=A0 =C2= =A0 {=0A=C2=A0 =C2=A0 =C2=A0 mlockall(MCL_CURRENT);=0A=C2=A0 =C2=A0 =C2=A0 = System.err.println("JNA mlockall successful");=0A=C2=A0 =C2=A0 }=0A=C2=A0 = =C2=A0 catch (UnsatisfiedLinkError e)=0A=C2=A0 =C2=A0 {=0A=C2=A0 =C2=A0 =C2= =A0 // this will have already been logged by CLibrary, no need to repeat it= =0A=C2=A0 =C2=A0 }=0A=C2=A0 =C2=A0 catch (RuntimeException e)=0A=C2=A0 =C2= =A0 {=0A=C2=A0 =C2=A0 =C2=A0 if (!(e instanceof LastErrorException))=0A=C2= =A0 =C2=A0 =C2=A0 =C2=A0 throw e;=0A=C2=A0 =C2=A0 =C2=A0 System.err.println= ("Unknown mlockall error " + e);=0A=0A=C2=A0 =C2=A0 }=0A=C2=A0 }=0A=0A=C2= =A0 public static void main(String[] args) throws Exception {=0A=C2=A0 =C2= =A0 tryMlockall();=0A=C2=A0 =C2=A0 while(run){=0A=C2=A0 =C2=A0 =C2=A0 long = prev_time =3D System.currentTimeMillis();=0A=C2=A0 =C2=A0 =C2=A0 System.out= .println("prev_time=3D"+new Date(prev_time));=0A=C2=A0 =C2=A0 =C2=A0 try {= =0A=C2=A0 =C2=A0 =C2=A0 =C2=A0 Thread.sleep(1000);=0A=C2=A0 =C2=A0 =C2=A0 = =C2=A0 System.out.println("Sleep 1 second.");=0A=C2=A0 =C2=A0 =C2=A0 }=0A= =C2=A0 =C2=A0 =C2=A0 catch (InterruptedException e) {=0A=C2=A0 =C2=A0 =C2= =A0 =C2=A0 e.printStackTrace();=0A=C2=A0 =C2=A0 =C2=A0 }=0A=C2=A0 =C2=A0 = =C2=A0 long now =3D System.currentTimeMillis();=0A=C2=A0 =C2=A0 =C2=A0 Syst= em.out.println("now time"+new Date(now));=0A=C2=A0 =C2=A0 =C2=A0 System.out= .printf("%d, %d, diff=3D%d\n", prev_time, now, now-prev_time);=0A=C2=A0 =C2= =A0 =C2=A0 if(now-prev_time>=3D1000){=0A=C2=A0 =C2=A0 =C2=A0 =C2=A0 System.= out.println("Hi.");=0A=C2=A0 =C2=A0 =C2=A0 }=0A=C2=A0 =C2=A0 }=0A=C2=A0 =C2= =A0 System.err.println("thr1 quit!");=0A=C2=A0 }=0A}=0A=0A=0AThe sample pro= gram output:=0A=0AJNA mlockall successful=0Aprev_time=3DSat Jun 01 21:12:22= CST 2013=0ASleep 1 second.=0Anow timeSat Jun 01 21:12:22 CST 2013=0A137009= 2342096, 1370092342347, diff=3D251=0Aprev_time=3DSat Jun 01 21:12:22 CST 20= 13=0ASleep 1 second.=0Anow timeSat Jun 01 21:12:22 CST 2013=0A1370092342382= , 1370092342386, diff=3D4=0Aprev_time=3DSat Jun 01 21:12:22 CST 2013=0ASlee= p 1 second.=0Anow timeSat Jun 01 21:12:22 CST 2013=0A1370092342390, 1370092= 342397, diff=3D7=0Aprev_time=3DSat Jun 01 21:12:22 CST 2013=0ASleep 1 secon= d.=0Anow timeSat Jun 01 21:12:22 CST 2013=0A1370092342397, 1370092342401, d= iff=3D4=0Aprev_time=3DSat Jun 01 21:12:22 CST 2013=0A=0A=0Ayou need user ro= ot to run it or=C2=A0=0Asysctl security.bsd.unprivileged_mlock=3D1=0A=0AAny= ideas how to solve it?=0A=0ACheers,=0AHuang Wen Hui=0A