Search in sources :

Example 11 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class ByteArrayStoreQuickNode method execute.

@Override
public int execute(VirtualFrame frame) {
    byte value = (byte) BytecodeNode.popInt(frame, top - 1);
    int index = BytecodeNode.popInt(frame, top - 2);
    StaticObject array = nullCheck(BytecodeNode.popObject(frame, top - 3));
    byteArrayStore.execute(array, index, value);
    return stackEffectOf_BASTORE;
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject)

Example 12 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class EspressoBindings method readMember.

@ExportMessage
Object readMember(String member, @CachedLibrary("this") InteropLibrary self, @Exclusive @Cached BranchProfile error) throws UnknownIdentifierException {
    if (!isMemberReadable(member)) {
        error.enter();
        throw UnknownIdentifierException.create(member);
    }
    EspressoContext context = EspressoContext.get(self);
    if (withNativeJavaVM && JAVA_VM.equals(member)) {
        return context.getVM().getJavaVM();
    }
    Meta meta = context.getMeta();
    try {
        StaticObject clazz = (StaticObject) meta.java_lang_Class_forName_String_boolean_ClassLoader.invokeDirect(null, meta.toGuestString(member), false, loader);
        return clazz.getMirrorKlass();
    } catch (EspressoException e) {
        error.enter();
        if (InterpreterToVM.instanceOf(e.getGuestException(), meta.java_lang_ClassNotFoundException)) {
            throw UnknownIdentifierException.create(member, e);
        }
        // exception during class loading
        throw e;
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) EspressoException(com.oracle.truffle.espresso.runtime.EspressoException) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) EspressoContext(com.oracle.truffle.espresso.runtime.EspressoContext) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 13 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class JniEnv method CallStaticObjectMethodVarargs.

// endregion CallNonvirtual*Method
// region CallStatic*Method
@JniImpl
@JavaType(Object.class)
public StaticObject CallStaticObjectMethodVarargs(@JavaType(Class.class) StaticObject clazz, @Handle(Method.class) long methodId, @Pointer TruffleObject varargsPtr) {
    Method method = methodIds.getObject(methodId);
    assert method.isStatic();
    assert (clazz.getMirrorKlass()) == method.getDeclaringKlass();
    Object result = method.invokeDirect(null, popVarArgs(varargsPtr, method.getParsedSignature()));
    return getMeta().asObject(result);
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Method(com.oracle.truffle.espresso.impl.Method) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 14 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class JniEnv method GetPrimitiveArrayCritical.

@JniImpl
@Pointer
public TruffleObject GetPrimitiveArrayCritical(@JavaType(Object.class) StaticObject object, @Pointer TruffleObject isCopyPtr) {
    if (!getUncached().isNull(isCopyPtr)) {
        ByteBuffer isCopyBuf = NativeUtils.directByteBuffer(isCopyPtr, 1);
        // Always copy since pinning is not supported.
        isCopyBuf.put((byte) 1);
    }
    StaticObject array = object;
    StaticObject clazz = GetObjectClass(array);
    JavaKind componentKind = ((ArrayKlass) clazz.getMirrorKlass()).getComponentType().getJavaKind();
    assert componentKind.isPrimitive();
    int length = GetArrayLength(array);
    ByteBuffer region = allocateDirect(length, componentKind);
    @Pointer TruffleObject addressPtr = NativeUtils.byteBufferPointer(region);
    // @formatter:off
    switch(componentKind) {
        case Boolean:
            GetBooleanArrayRegion(array, 0, length, addressPtr);
            break;
        case Byte:
            GetByteArrayRegion(array, 0, length, addressPtr);
            break;
        case Short:
            GetShortArrayRegion(array, 0, length, addressPtr);
            break;
        case Char:
            GetCharArrayRegion(array, 0, length, addressPtr);
            break;
        case Int:
            GetIntArrayRegion(array, 0, length, addressPtr);
            break;
        case Float:
            GetFloatArrayRegion(array, 0, length, addressPtr);
            break;
        case Long:
            GetLongArrayRegion(array, 0, length, addressPtr);
            break;
        case Double:
            GetDoubleArrayRegion(array, 0, length, addressPtr);
            break;
        // fall through
        case Object:
        // fall through
        case Void:
        // fall through
        case Illegal:
        default:
            throw EspressoError.shouldNotReachHere();
    }
    return addressPtr;
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Pointer(com.oracle.truffle.espresso.ffi.Pointer) RawPointer(com.oracle.truffle.espresso.ffi.RawPointer) ByteBuffer(java.nio.ByteBuffer) JavaKind(com.oracle.truffle.espresso.meta.JavaKind) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Pointer(com.oracle.truffle.espresso.ffi.Pointer) RawPointer(com.oracle.truffle.espresso.ffi.RawPointer)

Example 15 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class JniEnv method callVirtualMethodGeneric.

// endregion Set*Field
// region Call*Method
private Object callVirtualMethodGeneric(StaticObject receiver, @Handle(Method.class) long methodId, @Pointer TruffleObject varargsPtr) {
    assert !receiver.getKlass().isInterface();
    Method resolutionSeed = methodIds.getObject(methodId);
    assert !resolutionSeed.isStatic();
    assert resolutionSeed.getDeclaringKlass().isAssignableFrom(receiver.getKlass());
    Object[] args = popVarArgs(varargsPtr, resolutionSeed.getParsedSignature());
    Method target;
    if (resolutionSeed.getDeclaringKlass().isInterface()) {
        if (!resolutionSeed.isPrivate() && !resolutionSeed.isStatic()) {
            target = ((ObjectKlass) receiver.getKlass()).itableLookup(resolutionSeed.getDeclaringKlass(), resolutionSeed.getITableIndex());
        } else {
            target = resolutionSeed;
        }
    } else {
        if (resolutionSeed.isConstructor()) {
            target = resolutionSeed;
        } else if (resolutionSeed.isVirtualCall()) {
            target = receiver.getKlass().vtableLookup(resolutionSeed.getVTableIndex());
        } else {
            target = resolutionSeed;
        }
    }
    assert target != null;
    assert target.getName() == resolutionSeed.getName() && resolutionSeed.getRawSignature() == target.getRawSignature();
    return target.invokeDirect(receiver, args);
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Method(com.oracle.truffle.espresso.impl.Method)

Aggregations

StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)199 Method (com.oracle.truffle.espresso.impl.Method)57 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)44 Klass (com.oracle.truffle.espresso.impl.Klass)32 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)32 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)30 Meta (com.oracle.truffle.espresso.meta.Meta)29 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)26 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)23 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)17 ArrayList (java.util.ArrayList)13 EspressoException (com.oracle.truffle.espresso.runtime.EspressoException)9 Symbol (com.oracle.truffle.espresso.descriptors.Symbol)8 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)7 ExportMessage (com.oracle.truffle.api.library.ExportMessage)7 BytecodeNode (com.oracle.truffle.espresso.nodes.BytecodeNode)7 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)6 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)6 EspressoContext (com.oracle.truffle.espresso.runtime.EspressoContext)6 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)5