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

黄文辉 huanghwh at yahoo.com
Sun Jun 2 11:20:32 UTC 2013


2013-6-2,13:16,Konstantin Belousov <kostikbel at gmail.com> wrote:

> On Sun, Jun 02, 2013 at 10:33:09AM +0800, huanghwh 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 ?  
9-STABLE
> Also, I believe you use TSC as timecounter, check
> with the sysctl kern.timecounter.hardware.
Yes, TSC-low
Switch to HPET fix this problem.
> 
> Try the patch below.  I also added the C program that should exhibit
> the same behaviour of reporting the stale time.
This patch is also fix this problem.
Thanks!

> 
> 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);
> }


More information about the freebsd-java mailing list