[PATCH] 6523160 :RuntimeMXBean.getUptime() returns negative values
Mandy Chung
Mandy.Chung at Sun.COM
Wed May 23 19:23:51 PDT 2007
Hi Lars,
Thanks for contributing a patch for this bug. Using a high resolution
timer will fix the problem.
One issue with the suggested fix is that the VM is the one recording the
VM start time. The RuntimeImpl instance is not created at startup but
instead, it's lazily initialzed at the first time being accessed. Thus
we need to make change in the VM to record the VM startup nano time for
this bug fix. This will require a coordinated change with the HotSpot
and J2SE repositories.
Do you want to contribute to the HotSpot VM as well?
Thanks
Mandy
Lars Westergren wrote:
>Hi,
>
>Suggested patch for bug 6523160 :RuntimeMXBean.getUptime() returns
>negative values. No unit test unfortunately, works on my Kubuntu Linux
>though. Diff created against svn revision 235.
>
>Cheers,
>Lars
>
>
>------------------------------------------------------------------------
>
>--- origjdk/jdk/trunk/j2se/src/share/classes/sun/management/RuntimeImpl.java 2007-05-16 21:06:59.000000000 +0200
>+++ jdk/trunk/j2se/src/share/classes/sun/management/RuntimeImpl.java 2007-05-17 01:37:58.000000000 +0200
>@@ -32,6 +32,7 @@
> import java.util.Map;
> import java.util.Set;
> import java.util.Properties;
>+import java.util.concurrent.TimeUnit;
> import javax.management.openmbean.CompositeData;
> import javax.management.openmbean.CompositeDataSupport;
> import javax.management.openmbean.CompositeType;
>@@ -50,6 +51,7 @@
>
> private final VMManagement jvm;
> private final long vmStartupTime;
>+ private final long nanoStartup;
>
> /**
> * Constructor of RuntimeImpl class.
>@@ -57,6 +59,7 @@
> RuntimeImpl(VMManagement vm) {
> this.jvm = vm;
> this.vmStartupTime = jvm.getStartupTime();
>+ this.nanoStartup = System.nanoTime();
> }
>
> public String getName() {
>@@ -114,12 +117,12 @@
> }
>
> public long getUptime() {
>- long current = System.currentTimeMillis();
>-
>+ long diff = System.nanoTime() - nanoStartup;
>+
> // TODO: If called from client side when we support
> // MBean proxy to read performance counters from shared memory,
> // need to check if the monitored VM exitd.
>- return (current - vmStartupTime);
>+ return TimeUnit.NANOSECONDS.toMillis(diff);
> }
>
> public long getStartTime() {
>
>
More information about the serviceability-dev
mailing list