use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostObject method writeBufferFloat.
@ExportMessage
public void writeBufferFloat(ByteOrder order, long index, float value, @Shared("isBuffer") @Cached IsBufferNode isBuffer, @Shared("error") @Cached BranchProfile error, @Shared("classProfile") @Cached("createClassProfile()") ValueProfile classProfile) throws InvalidBufferOffsetException, UnsupportedMessageException {
if (!isBuffer.execute(this)) {
error.enter();
throw UnsupportedMessageException.create();
}
if (index < 0 || Integer.MAX_VALUE < index) {
error.enter();
throw InvalidBufferOffsetException.create(index, Float.BYTES);
}
try {
final ByteBuffer buffer = (ByteBuffer) classProfile.profile(obj);
final ByteOrder originalOrder = buffer.order();
buffer.order(order);
if (isPEFriendlyBuffer(buffer)) {
buffer.putFloat((int) index, value);
} else {
putBufferFloatBoundary(buffer, (int) index, value);
}
buffer.order(originalOrder);
} catch (IndexOutOfBoundsException e) {
error.enter();
throw InvalidBufferOffsetException.create(index, Float.BYTES);
} catch (ReadOnlyBufferException e) {
error.enter();
throw UnsupportedMessageException.create();
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostObject method writeBufferInt.
@ExportMessage
public void writeBufferInt(ByteOrder order, long index, int value, @Shared("isBuffer") @Cached IsBufferNode isBuffer, @Shared("error") @Cached BranchProfile error, @Shared("classProfile") @Cached("createClassProfile()") ValueProfile classProfile) throws InvalidBufferOffsetException, UnsupportedMessageException {
if (!isBuffer.execute(this)) {
error.enter();
throw UnsupportedMessageException.create();
}
if (index < 0 || Integer.MAX_VALUE < index) {
error.enter();
throw InvalidBufferOffsetException.create(index, Integer.BYTES);
}
try {
final ByteBuffer buffer = (ByteBuffer) classProfile.profile(obj);
final ByteOrder originalOrder = buffer.order();
buffer.order(order);
if (isPEFriendlyBuffer(buffer)) {
buffer.putInt((int) index, value);
} else {
putBufferIntBoundary(buffer, (int) index, value);
}
buffer.order(originalOrder);
} catch (IndexOutOfBoundsException e) {
error.enter();
throw InvalidBufferOffsetException.create(index, Integer.BYTES);
} catch (ReadOnlyBufferException e) {
error.enter();
throw UnsupportedMessageException.create();
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostObject method readBufferShort.
@ExportMessage
public short readBufferShort(ByteOrder order, long index, @Shared("isBuffer") @Cached IsBufferNode isBuffer, @Shared("error") @Cached BranchProfile error, @Shared("classProfile") @Cached("createClassProfile()") ValueProfile classProfile) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (!isBuffer.execute(this)) {
error.enter();
throw UnsupportedMessageException.create();
}
if (index < 0 || Integer.MAX_VALUE < index) {
error.enter();
throw InvalidBufferOffsetException.create(index, Short.BYTES);
}
try {
final ByteBuffer buffer = (ByteBuffer) classProfile.profile(obj);
final ByteOrder originalOrder = buffer.order();
buffer.order(order);
final short result = isPEFriendlyBuffer(buffer) ? buffer.getShort((int) index) : getBufferShortBoundary(buffer, (int) index);
buffer.order(originalOrder);
return result;
} catch (IndexOutOfBoundsException e) {
error.enter();
throw InvalidBufferOffsetException.create(index, Short.BYTES);
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostObject method readBufferDouble.
@ExportMessage
public double readBufferDouble(ByteOrder order, long index, @Shared("isBuffer") @Cached IsBufferNode isBuffer, @Shared("error") @Cached BranchProfile error, @Shared("classProfile") @Cached("createClassProfile()") ValueProfile classProfile) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (!isBuffer.execute(this)) {
error.enter();
throw UnsupportedMessageException.create();
}
if (index < 0 || Integer.MAX_VALUE < index) {
error.enter();
throw InvalidBufferOffsetException.create(index, Double.BYTES);
}
try {
final ByteBuffer buffer = (ByteBuffer) classProfile.profile(obj);
final ByteOrder originalOrder = buffer.order();
buffer.order(order);
final double result = isPEFriendlyBuffer(buffer) ? buffer.getDouble((int) index) : getBufferDoubleBoundary(buffer, (int) index);
buffer.order(originalOrder);
return result;
} catch (IndexOutOfBoundsException e) {
error.enter();
throw InvalidBufferOffsetException.create(index, Double.BYTES);
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class EspressoInterop method asInstant.
@ExportMessage
@TruffleBoundary
static Instant asInstant(StaticObject receiver, @CachedLibrary("receiver") InteropLibrary receiverLibrary, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
receiver.checkNotForeign();
if (receiverLibrary.isInstant(receiver)) {
StaticObject instant;
Meta meta = receiver.getKlass().getMeta();
if (instanceOf(receiver, meta.java_time_ZonedDateTime)) {
instant = (StaticObject) meta.java_time_ZonedDateTime_toInstant.invokeDirect(receiver);
} else if (instanceOf(receiver, meta.java_util_Date)) {
int index = meta.java_util_Date_toInstant.getVTableIndex();
Method virtualToInstant = receiver.getKlass().vtableLookup(index);
instant = (StaticObject) virtualToInstant.invokeDirect(receiver);
} else {
instant = receiver;
}
assert instanceOf(instant, meta.java_time_Instant);
long seconds = (long) meta.java_time_Instant_seconds.get(instant);
int nanos = (int) meta.java_time_Instant_nanos.get(instant);
return Instant.ofEpochSecond(seconds, nanos);
}
error.enter();
throw UnsupportedMessageException.create();
}
Aggregations