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();
}
}
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));
}
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();
}
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;
}
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;
}
Aggregations