use of com.oracle.svm.core.posix.headers.darwin.DarwinTime.MachTimebaseInfo in project graal by oracle.
the class DarwinSubstitutions method nanoTime.
@Substitute
@Uninterruptible(reason = "Does basic math after a few simple system calls")
private static long nanoTime() {
final Util_java_lang_System utilJavaLangSystem = ImageSingletons.lookup(Util_java_lang_System.class);
if (utilJavaLangSystem.fastTime) {
return mach_absolute_time();
}
if (!utilJavaLangSystem.timeBaseValid) {
MachTimebaseInfo timeBaseInfo = StackValue.get(SizeOf.get(MachTimebaseInfo.class));
if (mach_timebase_info(timeBaseInfo) == 0) {
if (timeBaseInfo.getdenom() == 1 && timeBaseInfo.getnumer() == 1) {
utilJavaLangSystem.fastTime = true;
return mach_absolute_time();
}
utilJavaLangSystem.factor = (double) timeBaseInfo.getnumer() / (double) timeBaseInfo.getdenom();
}
utilJavaLangSystem.timeBaseValid = true;
}
if (utilJavaLangSystem.factor != 0) {
return (long) (mach_absolute_time() * utilJavaLangSystem.factor);
}
/* High precision time is not available, fall back to low precision. */
timeval timeval = StackValue.get(SizeOf.get(timeval.class));
timezone timezone = WordFactory.nullPointer();
gettimeofday(timeval, timezone);
return timeval.tv_sec() * 1_000_000_000L + timeval.tv_usec() * 1_000L;
}
Aggregations