System.currentTimeMillis() is totally wrong after call JNA mlockall

Konstantin Belousov kostikbel at gmail.com
Sun Jun 2 05:17:09 UTC 2013


On Sun, Jun 02, 2013 at 10:33:09AM +0800, ????????? wrote:
> Hi,
> I recently found that Cassandra 1.2.4 could not shutdown when enable JNA,
> so I try to solve it, and found that under OpenJDK6/FreeBSD, 
> System.currentTimeMillis() is totally wrong after call JNA mlockall,
> time seams to not change anymore.

You did not specified the version of the system.  I assume this is either
9-STABLE or HEAD ?  Also, I believe you use TSC as timecounter, check
with the sysctl kern.timecounter.hardware.

Try the patch below.  I also added the C program that should exhibit
the same behaviour of reporting the stale time.

diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 3890157..c45b974 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -1050,8 +1050,9 @@ exec_new_vmspace(imgp, sv)
 		vm_object_reference(obj);
 		error = vm_map_fixed(map, obj, 0,
 		    sv->sv_shared_page_base, sv->sv_shared_page_len,
-		    VM_PROT_READ | VM_PROT_EXECUTE, VM_PROT_ALL,
-		    MAP_COPY_ON_WRITE | MAP_ACC_NO_CHARGE);
+		    VM_PROT_READ | VM_PROT_EXECUTE,
+		    VM_PROT_READ | VM_PROT_EXECUTE,
+		    MAP_INHERIT_SHARE | MAP_ACC_NO_CHARGE);
 		if (error) {
 			vm_object_deallocate(obj);
 			return (error);


/* $Id: time_mlock.c,v 1.4 2013/06/02 05:15:53 kostik Exp kostik $ */

#include <sys/types.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>

int
main(void)
{
	time_t t;
	pid_t child;

	if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
		err(1, "mlockall");
	fflush(stdout);
	child = fork();
	if (child == -1) {
		err(1, "fork");
	} else if (child == 0) {
		time(&t);
		printf("%s", ctime(&t));
		sleep(3);
		time(&t);
		printf("%s", ctime(&t));
	}
	return (0);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-java/attachments/20130602/4e7d59ee/attachment.sig>


More information about the freebsd-java mailing list