System.nanoTime is specified, in part, as follows:
- Returns the current value of the running Java Virtual Machine's high-resolution time source, in nanoseconds.
- The value returned represents nanoseconds since some fixed but arbitrary origin time (perhaps in the future, so values may be negative).
A concern has been raised that if the origin time were sufficiently in the past, then the value reported could wrap/overflow within a single execution of the JVM, rendering computations of elapsed time incorrect. Although the specification also contains this cautionary note:
- Differences in successive calls that span greater than approximately 292 years (2^63 nanoseconds) will not correctly compute elapsed time due to numerical overflow.
it is not clear whether users of the API need to try and account for such overflow.
The intent of this API is that they do not - the time origin will be such that overflow will not occur in any realistic single execution of the JVM. But we should add an implNote to that effect for clarity.
- Returns the current value of the running Java Virtual Machine's high-resolution time source, in nanoseconds.
- The value returned represents nanoseconds since some fixed but arbitrary origin time (perhaps in the future, so values may be negative).
A concern has been raised that if the origin time were sufficiently in the past, then the value reported could wrap/overflow within a single execution of the JVM, rendering computations of elapsed time incorrect. Although the specification also contains this cautionary note:
- Differences in successive calls that span greater than approximately 292 years (2^63 nanoseconds) will not correctly compute elapsed time due to numerical overflow.
it is not clear whether users of the API need to try and account for such overflow.
The intent of this API is that they do not - the time origin will be such that overflow will not occur in any realistic single execution of the JVM. But we should add an implNote to that effect for clarity.