JDK-8055923 : jdk.nashorn.internal.{codegen.CompilationPhase|runtime.Timing} should use System.nanoTime
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-08-25
  • Updated: 2015-06-04
  • Resolved: 2014-08-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u40Fixed 9 b29Fixed
Related Reports
Relates :  
Description
If you look into CompilationPhase internal profiling, you will notice it uses System.currentTimeMillis for internal profiling, which limits the resolution to 1ms. If the compilation phase is faster than 1ms, then runtime.Timing will "aggregate" zero result into its accumulated statistics. Please change the uses to System.nanoTime.

Additionally, it might be worthwhile to consider other places as well:

$ ack-grep currentTimeMillis
src/jdk/nashorn/internal/codegen/OptimisticTypesPersistence.java
198:        final long now = System.currentTimeMillis();

src/jdk/nashorn/internal/codegen/CompilationPhase.java
633:         startTime = System.currentTimeMillis();
646:        endTime = System.currentTimeMillis();

src/jdk/nashorn/internal/objects/NativeDate.java
134:        this(System.currentTimeMillis());
257:        return System.currentTimeMillis();

src/jdk/nashorn/internal/parser/Parser.java
258:        final long t0 = isTimingEnabled ? System.currentTimeMillis() : 0L;
279:                env._timing.accumulateTime(toString(), System.currentTimeMillis() - t0);
280:                log.info(end, "' in ", System.currentTimeMillis() - t0, " ms");

src/jdk/nashorn/internal/runtime/Timing.java
60:        this.startTime = System.currentTimeMillis();
169:            final long t = System.currentTimeMillis();

Comments
You are a veritable cornucopia of good suggestions, Aleksey. Thanks for this.
25-08-2014