Search in sources :

Example 16 with ExportMessage

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);
    }
}
Also used : ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 17 with ExportMessage

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();
    }
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 18 with ExportMessage

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();
    }
}
Also used : ReadOnlyBufferException(java.nio.ReadOnlyBufferException) ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 19 with ExportMessage

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);
    }
}
Also used : ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 20 with ExportMessage

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();
    }
}
Also used : ReadOnlyBufferException(java.nio.ReadOnlyBufferException) ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Aggregations

ExportMessage (com.oracle.truffle.api.library.ExportMessage)68 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)24 Meta (com.oracle.truffle.espresso.meta.Meta)24 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)16 Method (com.oracle.truffle.espresso.impl.Method)13 ByteBuffer (java.nio.ByteBuffer)10 ByteOrder (java.nio.ByteOrder)10 Klass (com.oracle.truffle.espresso.impl.Klass)8 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)8 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)8 Value (org.graalvm.polyglot.Value)8 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)8 ArityException (com.oracle.truffle.api.interop.ArityException)7 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)7 ProxyNativeObject (org.graalvm.polyglot.proxy.ProxyNativeObject)7 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)6 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)5 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)4 Field (com.oracle.truffle.espresso.impl.Field)4 ProxyHashMap (org.graalvm.polyglot.proxy.ProxyHashMap)4