Search in sources :

Example 1 with MachTimebaseInfo

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;
}
Also used : Time.timezone(com.oracle.svm.core.posix.headers.Time.timezone) MachTimebaseInfo(com.oracle.svm.core.posix.headers.darwin.DarwinTime.MachTimebaseInfo) Time.timeval(com.oracle.svm.core.posix.headers.Time.timeval) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) Substitute(com.oracle.svm.core.annotate.Substitute)

Aggregations

Substitute (com.oracle.svm.core.annotate.Substitute)1 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)1 Time.timeval (com.oracle.svm.core.posix.headers.Time.timeval)1 Time.timezone (com.oracle.svm.core.posix.headers.Time.timezone)1 MachTimebaseInfo (com.oracle.svm.core.posix.headers.darwin.DarwinTime.MachTimebaseInfo)1