Search in sources :

Example 21 with Uninterruptible

use of com.oracle.svm.core.annotate.Uninterruptible in project graal by oracle.

the class LinuxSubstitutions method nanoTime.

@Substitute
@Uninterruptible(reason = "Does basic math after a simple system call")
private static long nanoTime() {
    timespec timespec = StackValue.get(SizeOf.get(timespec.class));
    if (clock_gettime(CLOCK_MONOTONIC(), timespec) == 0) {
        return timespec.tv_sec() * 1_000_000_000L + timespec.tv_nsec();
    } else {
        /* 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.timespec(com.oracle.svm.core.posix.headers.Time.timespec) Time.timezone(com.oracle.svm.core.posix.headers.Time.timezone) Time.timeval(com.oracle.svm.core.posix.headers.Time.timeval) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 22 with Uninterruptible

use of com.oracle.svm.core.annotate.Uninterruptible in project graal by oracle.

the class PthreadConditionUtils method deadlineTimespecToDelayNanos.

@Uninterruptible(reason = "Called from uninterruptible code.")
public static long deadlineTimespecToDelayNanos(Time.timespec deadlineTimespec) {
    timespec currentTimespec = StackValue.get(SizeOf.get(timespec.class));
    getAbsoluteTimeNanos(currentTimespec);
    return TimeUtils.addOrMaxValue(deadlineTimespec.tv_nsec() - currentTimespec.tv_nsec(), TimeUtils.secondsToNanos((deadlineTimespec.tv_sec() - currentTimespec.tv_sec())));
}
Also used : Time.timespec(com.oracle.svm.core.posix.headers.Time.timespec) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 23 with Uninterruptible

use of com.oracle.svm.core.annotate.Uninterruptible in project graal by oracle.

the class PthreadConditionUtils method delayNanosToDeadlineTimespec.

/**
 * Turn a delay in nanoseconds into a deadline in a Time.timespec.
 */
@Uninterruptible(reason = "Called from uninterruptible code.")
public static void delayNanosToDeadlineTimespec(long delayNanos, Time.timespec result) {
    timespec currentTimespec = StackValue.get(SizeOf.get(timespec.class));
    getAbsoluteTimeNanos(currentTimespec);
    assert delayNanos >= 0;
    long sec = TimeUtils.addOrMaxValue(currentTimespec.tv_sec(), TimeUtils.divideNanosToSeconds(delayNanos));
    long nsec = currentTimespec.tv_nsec() + TimeUtils.remainderNanosToSeconds(delayNanos);
    if (nsec > TimeUtils.nanosPerSecond) {
        sec = TimeUtils.addOrMaxValue(sec, 1);
        nsec -= TimeUtils.nanosPerSecond;
    }
    assert nsec < TimeUtils.nanosPerSecond;
    result.set_tv_sec(sec);
    result.set_tv_nsec(nsec);
}
Also used : Time.timespec(com.oracle.svm.core.posix.headers.Time.timespec) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 24 with Uninterruptible

use of com.oracle.svm.core.annotate.Uninterruptible in project graal by oracle.

the class MemoryUtil method fillToMemoryAtomic.

@Uninterruptible(reason = "Arguments may be managed objects")
public static void fillToMemoryAtomic(Pointer to, UnsignedWord size, byte value) {
    UnsignedWord bits = to.or(size);
    if (bits.unsignedRemainder(8).equal(0)) {
        // zero-extend
        long fill = value & 0xffL;
        if (fill != 0) {
            fill += fill << 8;
            fill += fill << 16;
            fill += fill << 32;
        }
        for (UnsignedWord offset = WordFactory.zero(); offset.belowThan(size); offset = offset.add(8)) {
            to.writeLong(offset, fill);
        }
    } else if (bits.unsignedRemainder(4).equal(0)) {
        // zero-extend
        int fill = value & 0xff;
        if (fill != 0) {
            fill += fill << 8;
            fill += fill << 16;
        }
        for (UnsignedWord offset = WordFactory.zero(); offset.belowThan(size); offset = offset.add(4)) {
            to.writeInt(offset, fill);
        }
    } else if (bits.unsignedRemainder(2).equal(0)) {
        // zero-extend
        short fill = (short) (value & 0xff);
        if (fill != 0) {
            fill += fill << 8;
        }
        for (UnsignedWord offset = WordFactory.zero(); offset.belowThan(size); offset = offset.add(2)) {
            to.writeShort(offset, fill);
        }
    } else {
        byte fill = value;
        for (UnsignedWord offset = WordFactory.zero(); offset.belowThan(size); offset = offset.add(1)) {
            to.writeByte(offset, fill);
        }
    }
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 25 with Uninterruptible

use of com.oracle.svm.core.annotate.Uninterruptible in project graal by oracle.

the class CEntryPointNativeFunctions method createIsolate.

@Uninterruptible(reason = UNINTERRUPTIBLE_REASON)
@CEntryPoint(name = "create_isolate", documentation = { "Create a new isolate, considering the passed parameters (which may be NULL).", "Returns 0 on success, or a non-zero value on failure.", "On success, the current thread is attached to the created isolate, and the", "address of the isolate structure is written to the passed pointer." })
@CEntryPointOptions(prologue = NoPrologue.class, epilogue = NoEpilogue.class, nameTransformation = NameTransformation.class)
public static int createIsolate(CEntryPointCreateIsolateParameters params, IsolatePointer isolate) {
    int result = CEntryPointActions.enterCreateIsolate(params);
    if (result == 0) {
        isolate.write(CEntryPointContext.getCurrentIsolate());
        result = CEntryPointActions.leave();
    }
    return result;
}
Also used : CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Aggregations

Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)54 Pointer (org.graalvm.word.Pointer)15 UnsignedWord (org.graalvm.word.UnsignedWord)9 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)7 SubstrateForeignCallTarget (com.oracle.svm.core.snippets.SubstrateForeignCallTarget)5 IsolateThread (org.graalvm.nativeimage.IsolateThread)5 AlignedHeader (com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader)4 Safepoint (com.oracle.svm.core.thread.Safepoint)4 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)4 CodePointer (org.graalvm.nativeimage.c.function.CodePointer)4 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)4 RestrictHeapAccess (com.oracle.svm.core.annotate.RestrictHeapAccess)3 Substitute (com.oracle.svm.core.annotate.Substitute)3 Log (com.oracle.svm.core.log.Log)3 Time.timespec (com.oracle.svm.core.posix.headers.Time.timespec)3 Time.timeval (com.oracle.svm.core.posix.headers.Time.timeval)3 Time.timezone (com.oracle.svm.core.posix.headers.Time.timezone)3 DebugContext (org.graalvm.compiler.debug.DebugContext)3 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)3 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)3