Search in sources :

Example 6 with SignedWord

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

the class Deoptimizer method readConstant.

private static JavaConstant readConstant(Pointer addr, SignedWord offset, JavaKind kind, boolean compressed) {
    switch(kind) {
        case Boolean:
            return JavaConstant.forBoolean(addr.readByte(offset) != 0);
        case Byte:
            return JavaConstant.forByte(addr.readByte(offset));
        case Char:
            return JavaConstant.forChar(addr.readChar(offset));
        case Short:
            return JavaConstant.forShort(addr.readShort(offset));
        case Int:
            return JavaConstant.forInt(addr.readInt(offset));
        case Long:
            return JavaConstant.forLong(addr.readLong(offset));
        case Float:
            return JavaConstant.forFloat(addr.readFloat(offset));
        case Double:
            return JavaConstant.forDouble(addr.readDouble(offset));
        case Object:
            Word p = ((Word) addr).add(offset);
            Object obj = ReferenceAccess.singleton().readObjectAt(p, compressed);
            return SubstrateObjectConstant.forObject(obj, compressed);
        default:
            throw VMError.shouldNotReachHere();
    }
}
Also used : SignedWord(org.graalvm.word.SignedWord) Word(org.graalvm.compiler.word.Word) UnsignedWord(org.graalvm.word.UnsignedWord)

Example 7 with SignedWord

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

the class CInterfaceTutorial method javaEntryPoint4.

@CEntryPoint(name = "java_entry_point4")
protected static void javaEntryPoint4(@SuppressWarnings("unused") IsolateThread thread, SUData sudata) {
    int i = 0;
    UnsignedWord u = sudata.getUB1Unsigned();
    SignedWord s = sudata.getSB1Signed();
    i = sudata.getUB1();
    System.out.println(" getUB1() = " + i + (i < 0 ? "<" : ">=") + " 0");
    System.out.println(" getUB1Unsigned() = " + u.rawValue() + (u.rawValue() < 0 ? "<" : ">=") + " 0");
    i = sudata.getSB1();
    System.out.println(" getSB1() = " + i + (i < 0 ? "<" : ">=") + " 0");
    System.out.println(" getSB1Signed() = " + s.rawValue() + (s.rawValue() < 0 ? "<" : ">=") + " 0");
    System.out.println("(byte) 245        = " + ((byte) 245));
    System.out.println("(byte) 245 & 0xFF = " + (((byte) 245) & 0xFF));
    System.out.println("sudata.getUB1Unsigned().aboveOrEqual(220) = " + sudata.getUB1Unsigned().aboveOrEqual(220));
    System.out.println("sudata.getUB1Unsigned().aboveOrEqual(245) = " + sudata.getUB1Unsigned().aboveOrEqual(245));
    System.out.println("sudata.getUB1Unsigned().aboveOrEqual((byte)220) = " + sudata.getUB1Unsigned().aboveOrEqual((byte) 220));
    System.out.println("sudata.getUB1Unsigned().aboveOrEqual((byte)245) = " + sudata.getUB1Unsigned().aboveOrEqual((byte) 245));
    System.out.println("sudata.getUB1() && 0xFF >  220 = " + ((sudata.getUB1() & 0xFF) > 220));
    System.out.println("sudata.getUB1() && 0xFF >  245 = " + ((sudata.getUB1() & 0xFF) > 245));
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) SignedWord(org.graalvm.word.SignedWord) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Example 8 with SignedWord

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

the class PosixUtils method readBytes.

static int readBytes(byte[] b, int off, int len, FileDescriptor fd) throws IOException {
    if (b == null) {
        throw new NullPointerException();
    } else if (PosixUtils.outOfBounds(off, len, b)) {
        throw new IndexOutOfBoundsException();
    }
    if (len == 0) {
        return 0;
    }
    SignedWord nread;
    CCharPointer buf = LibC.malloc(WordFactory.unsigned(len));
    try {
        if (buf.equal(WordFactory.zero())) {
            throw new OutOfMemoryError();
        }
        int handle = getFDHandle(fd);
        nread = read(handle, buf, WordFactory.unsigned(len));
        if (nread.greaterThan(0)) {
            /*
                 * We do not read directly into the (pinned) result array because read can block,
                 * and that could lead to object pinned for an unexpectedly long time.
                 */
            try (PinnedObject pin = PinnedObject.create(b)) {
                LibC.memcpy(pin.addressOfArrayElement(off), buf, (UnsignedWord) nread);
            }
        } else if (nread.equal(-1)) {
            throw new IOException(lastErrorString("Read error"));
        } else {
            // EOF
            nread = WordFactory.signed(-1);
        }
    } finally {
        LibC.free(buf);
    }
    return (int) nread.rawValue();
}
Also used : PinnedObject(org.graalvm.nativeimage.PinnedObject) IOException(java.io.IOException) SignedWord(org.graalvm.word.SignedWord) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer)

Example 9 with SignedWord

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

the class SubstrateMemoryAccessProviderImpl method readObjectConstant.

private static JavaConstant readObjectConstant(Constant baseConstant, long displacement, boolean requireCompressed) {
    SignedWord offset = WordFactory.signed(displacement);
    if (baseConstant instanceof SubstrateObjectConstant) {
        // always compressed (if enabled)
        assert !requireCompressed || ReferenceAccess.singleton().haveCompressedReferences();
        Object baseObject = ((SubstrateObjectConstant) baseConstant).getObject();
        assert baseObject != null : "SubstrateObjectConstant does not wrap null value";
        Object rawValue = BarrieredAccess.readObject(baseObject, offset);
        return SubstrateObjectConstant.forObject(rawValue, requireCompressed);
    }
    if (baseConstant instanceof PrimitiveConstant) {
        // never compressed
        assert !requireCompressed;
        PrimitiveConstant prim = (PrimitiveConstant) baseConstant;
        if (!prim.getJavaKind().isNumericInteger()) {
            return null;
        }
        Word baseAddress = WordFactory.unsigned(prim.asLong());
        if (baseAddress.equal(0)) {
            return null;
        }
        Word address = baseAddress.add(offset);
        Object rawValue = ReferenceAccess.singleton().readObjectAt(address, false);
        return SubstrateObjectConstant.forObject(rawValue, false);
    }
    return null;
}
Also used : Word(org.graalvm.compiler.word.Word) SignedWord(org.graalvm.word.SignedWord) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) SubstrateObjectConstant(com.oracle.svm.core.meta.SubstrateObjectConstant) SignedWord(org.graalvm.word.SignedWord)

Example 10 with SignedWord

use of org.graalvm.word.SignedWord 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)

Aggregations

SignedWord (org.graalvm.word.SignedWord)16 IOException (java.io.IOException)9 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)7 Substitute (com.oracle.svm.core.annotate.Substitute)6 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)4 CCharPointerPointer (org.graalvm.nativeimage.c.type.CCharPointerPointer)3 Pointer (org.graalvm.word.Pointer)3 UnsignedWord (org.graalvm.word.UnsignedWord)3 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)2 SubstrateObjectConstant (com.oracle.svm.core.meta.SubstrateObjectConstant)2 Dirent.direntPointer (com.oracle.svm.core.posix.headers.Dirent.direntPointer)2 PrimitiveConstant (jdk.vm.ci.meta.PrimitiveConstant)2 Word (org.graalvm.compiler.word.Word)2 PinnedObject (org.graalvm.nativeimage.PinnedObject)2 Stat.fstat (com.oracle.svm.core.posix.headers.Stat.fstat)1 Stat.stat (com.oracle.svm.core.posix.headers.Stat.stat)1 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)1