use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostObject method readBufferInt.
@ExportMessage
public int readBufferInt(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, Integer.BYTES);
}
try {
final ByteBuffer buffer = (ByteBuffer) classProfile.profile(obj);
final ByteOrder originalOrder = buffer.order();
buffer.order(order);
final int result = isPEFriendlyBuffer(buffer) ? buffer.getInt((int) index) : getBufferIntBoundary(buffer, (int) index);
buffer.order(originalOrder);
return result;
} catch (IndexOutOfBoundsException e) {
error.enter();
throw InvalidBufferOffsetException.create(index, Integer.BYTES);
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostObject method getMetaObject.
@ExportMessage
Object getMetaObject() throws UnsupportedMessageException {
if (hasMetaObject()) {
Object javaObject = this.obj;
Class<?> javaType = javaObject.getClass();
return HostObject.forClass(javaType, context);
} else {
throw UnsupportedMessageException.create();
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostObject method writeBufferDouble.
@ExportMessage
public void writeBufferDouble(ByteOrder order, long index, double 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, Double.BYTES);
}
try {
final ByteBuffer buffer = (ByteBuffer) classProfile.profile(obj);
final ByteOrder originalOrder = buffer.order();
buffer.order(order);
if (isPEFriendlyBuffer(buffer)) {
buffer.putDouble((int) index, value);
} else {
putBufferDoubleBoundary(buffer, (int) index, value);
}
buffer.order(originalOrder);
} catch (IndexOutOfBoundsException e) {
error.enter();
throw InvalidBufferOffsetException.create(index, Double.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 readBufferLong.
@ExportMessage
public long readBufferLong(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, Long.BYTES);
}
try {
final ByteBuffer buffer = (ByteBuffer) classProfile.profile(obj);
final ByteOrder originalOrder = buffer.order();
buffer.order(order);
final long result = isPEFriendlyBuffer(buffer) ? buffer.getLong((int) index) : getBufferLongBoundary(buffer, (int) index);
buffer.order(originalOrder);
return result;
} catch (IndexOutOfBoundsException e) {
error.enter();
throw InvalidBufferOffsetException.create(index, Long.BYTES);
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostObject method writeBufferShort.
@ExportMessage
public void writeBufferShort(ByteOrder order, long index, short 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, Short.BYTES);
}
try {
final ByteBuffer buffer = (ByteBuffer) classProfile.profile(obj);
final ByteOrder originalOrder = buffer.order();
buffer.order(order);
if (isPEFriendlyBuffer(buffer)) {
buffer.putShort((int) index, value);
} else {
putBufferShortBoundary(buffer, (int) index, value);
}
buffer.order(originalOrder);
} catch (IndexOutOfBoundsException e) {
error.enter();
throw InvalidBufferOffsetException.create(index, Short.BYTES);
} catch (ReadOnlyBufferException e) {
error.enter();
throw UnsupportedMessageException.create();
}
}
Aggregations