Search in sources :

Example 61 with UnsignedWord

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

the class ArraycopySnippets method objectCopyForward.

private static void objectCopyForward(Object fromArray, int fromIndex, Object toArray, int toIndex, int length, int le) {
    UnsignedWord fromOffset = LayoutEncoding.getArrayElementOffset(le, fromIndex);
    UnsignedWord toOffset = LayoutEncoding.getArrayElementOffset(le, toIndex);
    UnsignedWord elementSize = WordFactory.unsigned(LayoutEncoding.getArrayIndexScale(le));
    UnsignedWord size = elementSize.multiply(length);
    objectCopyForwardUninterruptibly(fromArray, fromOffset, toArray, toOffset, elementSize, size);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord)

Example 62 with UnsignedWord

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

the class ArraycopySnippets method primitiveCopyForward.

private static void primitiveCopyForward(Object fromArray, int fromIndex, Object toArray, int toIndex, int length, int le) {
    UnsignedWord fromOffset = LayoutEncoding.getArrayElementOffset(le, fromIndex);
    UnsignedWord toOffset = LayoutEncoding.getArrayElementOffset(le, toIndex);
    UnsignedWord elementSize = WordFactory.unsigned(LayoutEncoding.getArrayIndexScale(le));
    UnsignedWord size = elementSize.multiply(length);
    UnsignedWord i = WordFactory.zero();
    if (size.and(1).notEqual(0)) {
        ObjectAccess.writeByte(toArray, toOffset.add(i), ObjectAccess.readByte(fromArray, fromOffset.add(i)));
        size = size.subtract(1);
        i = i.add(1);
    }
    if (size.and(3).notEqual(0)) {
        ObjectAccess.writeShort(toArray, toOffset.add(i), ObjectAccess.readShort(fromArray, fromOffset.add(i)));
        size = size.subtract(2);
        i = i.add(2);
    }
    if (size.and(7).notEqual(0)) {
        ObjectAccess.writeInt(toArray, toOffset.add(i), ObjectAccess.readInt(fromArray, fromOffset.add(i)));
        size = size.subtract(4);
        i = i.add(4);
    }
    while (i.belowThan(size)) {
        ObjectAccess.writeLong(toArray, toOffset.add(i), ObjectAccess.readLong(fromArray, fromOffset.add(i)));
        i = i.add(8);
    }
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord)

Example 63 with UnsignedWord

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

the class WordTest method cast.

@Snippet
public static long cast(long input) {
    WordBase base = WordFactory.signed(input);
    UnsignedWord unsigned = (UnsignedWord) base;
    Pointer pointer = (Pointer) unsigned;
    Word word = (Word) pointer;
    return word.rawValue();
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Word(org.graalvm.compiler.word.Word) UnsignedWord(org.graalvm.word.UnsignedWord) WordBase(org.graalvm.word.WordBase) Pointer(org.graalvm.word.Pointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 64 with UnsignedWord

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

the class TruffleNFISupport method utf8ToJavaString.

@TruffleBoundary
static String utf8ToJavaString(CCharPointer str) {
    if (str.equal(WordFactory.zero())) {
        return null;
    } else {
        UnsignedWord len = SubstrateUtil.strlen(str);
        ByteBuffer buffer = SubstrateUtil.wrapAsByteBuffer(str, (int) len.rawValue());
        return UTF8.decode(buffer).toString();
    }
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) ByteBuffer(java.nio.ByteBuffer) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 65 with UnsignedWord

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

the class PosixOSInterface method writeBytes0.

// @formatter:off
// @Override
// protected void writeBytes0(FileDescriptor descriptor, byte[] bytes, int off, int len, boolean append) throws IOException {
// try (PinnedObject bytesPin = PinnedObject.open(bytes)) {
// CCharPointer curBuf = bytesPin.addressOfArrayElement(off);
// Unsigned curLen = Word.unsigned(len);
// while (curLen.notEqual(0)) {
// int fd = FileDescriptorAlias.getFD(descriptor);
// if (fd == -1) {
// throw new IOException("Stream Closed");
// }
// 
// Signed n = write(fd, curBuf, curLen);
// 
// if (n.equal(-1)) {
// throw new IOException(lastErrorString("Write error"));
// }
// curBuf = curBuf.addressOf(n);
// curLen = curLen.subtract((Unsigned) n);
// }
// }
// }
// @formatter:on
/*
     * TODO Temporarily removed the pinning of 'bytes' to allow it to be region allocation. See
     * above.
     */
@Override
protected boolean writeBytes0(FileDescriptor descriptor, byte[] bytes, int off, int len, boolean append) {
    final DynamicHub hub = ObjectHeader.readDynamicHubFromObject(bytes);
    final UnsignedWord offsetOfArrayElement = LayoutEncoding.getArrayElementOffset(hub.getLayoutEncoding(), off);
    final UnsignedWord length = WordFactory.unsigned(len);
    return writeBytes0Uninterruptibly(descriptor, bytes, length, offsetOfArrayElement);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) DynamicHub(com.oracle.svm.core.hub.DynamicHub)

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