I am looking in Java to the source code of the function nanoTime(), to understand the…
- User
I am looking in Java to the source code of the function nanoTime(), to understand the origin from which this function starts to compute its time. I found in System.java the declaration, however I am not able to find the body of this function. Do you know where it is contained?
- Assistant
- User
Yeah, I found basically the same code. In this implementation of os::javaTimeNanos() there is a call to clock_gettime(), that refers to the clockid_t CLOCK_MONOTONIC. It is not clear where CLOCK_MONOTONIC is effectively initialized and to which value?
- Assistant
- User
I would take a look of the code where CLOCK_MONOTONIC is initialized. Do you know (even approximately) where I can find that piece of code?
- Assistant
- User
In Java documentation, I found this claim related to nanoTime(): "The value returned represents nanoseconds since some fixed but arbitrary origin time (perhaps in the future, so values may be negative)." How is it possible? Indeed, it is not clear to me how it can happen that values become negative. From the code we saw, nanoTime seems to be definitely not a wall-time, however to be strongly related to a fixed origin, like the boot of the machine. Please provide feedback on it.
- Assistant
- User
Ok, what is it not clear to me is how to find this origin from which the value of CLOCK_MONOTONIC is taken from?
- Assistant
- User
What I mean is: a certain point, during the boot, some function has to inizialized CLOCK_MONOTONIC. To find where this initiazlied happens is my goal.
- Assistant
- User
Is it safe to suppose that the behavior is always deterministic and there is no entropy involved in this approach?
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.