Search in sources :

Example 76 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class ArraycopySnippets method objectCopyForwardUninterruptibly.

@Uninterruptible(reason = "Only the first writeObject has a write-barrier.")
private static void objectCopyForwardUninterruptibly(Object fromArray, UnsignedWord fromOffset, Object toArray, UnsignedWord toOffset, UnsignedWord elementSize, UnsignedWord size) {
    UnsignedWord copied = WordFactory.zero();
    // TODO: I am explicitly not making the first read have a read barrier.
    if (copied.belowThan(size)) {
        BarrieredAccess.writeObject(toArray, toOffset.add(copied), ObjectAccess.readObject(fromArray, fromOffset.add(copied)));
        copied = copied.add(elementSize);
        while (copied.belowThan(size)) {
            ObjectAccess.writeObject(toArray, toOffset.add(copied), ObjectAccess.readObject(fromArray, fromOffset.add(copied)));
            copied = copied.add(elementSize);
        }
    }
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 77 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class PointerUtils method absoluteDifference.

/**
 * Return the distance between two Pointers.
 *
 * @param pointer1 A first Pointer.
 * @param pointer2 A second Pointer.
 * @return The distance in bytes between the two Pointers.
 */
public static UnsignedWord absoluteDifference(PointerBase pointer1, PointerBase pointer2) {
    Pointer p1 = (Pointer) pointer1;
    Pointer p2 = (Pointer) pointer2;
    final UnsignedWord result;
    if (p1.aboveOrEqual(p2)) {
        result = p1.subtract(p2);
    } else {
        result = p2.subtract(p1);
    }
    return result;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer)

Example 78 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class TimeUtils method weightedNanos.

/**
 * Weight a nanosecond value by a percentage between 0 and 100.
 */
public static long weightedNanos(int percent, long nanos) {
    final UnsignedWord unweightedNanos = WordFactory.unsigned(nanos);
    final long result = unweightedNanos.unsignedDivide(100).multiply(percent).rawValue();
    return result;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord)

Example 79 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class PosixOSInterface method writeBytesUninterruptibly.

@Override
@Uninterruptible(reason = "Bytes might be from an Object.")
public boolean writeBytesUninterruptibly(FileDescriptor descriptor, CCharPointer bytes, UnsignedWord length) {
    CCharPointer curBuf = bytes;
    UnsignedWord curLen = length;
    while (curLen.notEqual(0)) {
        int fd = Util_java_io_FileDescriptor.getFD(descriptor);
        if (fd == -1) {
            return false;
        }
        SignedWord n = UnistdNoTransitions.write(fd, curBuf, curLen);
        if (n.equal(-1)) {
            return false;
        }
        curBuf = curBuf.addressOf(n);
        curLen = curLen.subtract((UnsignedWord) n);
    }
    return true;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) SignedWord(org.graalvm.word.SignedWord) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 80 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class JavaMainWrapper method getCRuntimeArgumentBlockLength.

/**
 * Argv is an array of C strings (i.e. array of pointers to characters). Each entry points to a
 * different C string corresponding to a program argument. The program argument strings
 * themselves are located in a contiguous block of memory followed by the environment variables
 * key-value strings:
 *
 * <pre>
 * &lt;argument_0&gt;\n&lt;argument_1&gt;\n...&lt;argument_n&gt;\n
 * &lt;env_key_value_1&gt;\n&lt;env_key_value_2&gt;\n...&lt;env_key_value_n&gt;\n
 * </pre>
 *
 * @return maximum length of C chars that can be stored in the program argument part of the
 *         contiguous memory block without writing into the environment variables part.
 */
public static long getCRuntimeArgumentBlockLength() {
    VMError.guarantee(argv.notEqual(WordFactory.zero()) && argc > 0, "Requires JavaMainWrapper.run(int, CCharPointerPointer) entry point!");
    CCharPointer firstArgPos = argv.read(0);
    if (argvLength.equal(WordFactory.zero())) {
        // Get char* to last program argument
        CCharPointer lastArgPos = argv.read(argc - 1);
        // Determine the length of the last program argument
        UnsignedWord lastArgLength = SubstrateUtil.strlen(lastArgPos);
        // Determine maximum C string length that can be stored in the program argument part
        argvLength = WordFactory.unsigned(lastArgPos.rawValue()).add(lastArgLength).subtract(WordFactory.unsigned(firstArgPos.rawValue()));
    }
    return argvLength.rawValue();
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer)

Aggregations

UnsignedWord (org.graalvm.word.UnsignedWord)137 Pointer (org.graalvm.word.Pointer)43 Log (com.oracle.svm.core.log.Log)30 DynamicHub (com.oracle.svm.core.hub.DynamicHub)11 Fold (org.graalvm.compiler.api.replacements.Fold)11 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)9 Snippet (org.graalvm.compiler.api.replacements.Snippet)9 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)6 AlignedHeader (com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader)4 WordBase (org.graalvm.word.WordBase)4 AlwaysInline (com.oracle.svm.core.annotate.AlwaysInline)3 ValueInfo (com.oracle.svm.core.code.FrameInfoQueryResult.ValueInfo)3 UnalignedHeader (com.oracle.svm.core.genscavenge.UnalignedHeapChunk.UnalignedHeader)3 XOptions (com.oracle.svm.core.option.XOptions)3 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)3 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)2 DeoptEntryInfopoint (com.oracle.svm.core.deopt.DeoptEntryInfopoint)2 SubstrateForeignCallTarget (com.oracle.svm.core.snippets.SubstrateForeignCallTarget)2 Infopoint (jdk.vm.ci.code.site.Infopoint)2 JavaKind (jdk.vm.ci.meta.JavaKind)2