Search in sources :

Example 41 with Method

use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.

the class MapEntryInterop method readArrayElement.

@ExportMessage
public static Object readArrayElement(StaticObject receiver, long index, @Cached.Exclusive @Cached InvokeEspressoNode invoke) throws InvalidArrayIndexException {
    Meta meta = receiver.getKlass().getMeta();
    Method m;
    if (index == 0) {
        m = doLookup(receiver, meta.java_util_Map_Entry, meta.java_util_Map_Entry_getKey);
    } else if (index == 1) {
        m = doLookup(receiver, meta.java_util_Map_Entry, meta.java_util_Map_Entry_getValue);
    } else {
        throw InvalidArrayIndexException.create(index);
    }
    try {
        return invoke.execute(m, receiver, EMPTY_ARRAY);
    } catch (ArityException | UnsupportedTypeException e) {
        throw EspressoError.shouldNotReachHere(e);
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) Method(com.oracle.truffle.espresso.impl.Method) ArityException(com.oracle.truffle.api.interop.ArityException) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 42 with Method

use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.

the class MapInterop method removeHashEntry.

@ExportMessage
public static void removeHashEntry(StaticObject receiver, Object key, @Cached.Exclusive @Cached InvokeEspressoNode invoke, @Cached.Shared("contains") @Cached InvokeEspressoNode contains) throws UnsupportedMessageException, UnknownKeyException {
    if (!isHashEntryReadable(receiver, key, contains)) {
        throw UnsupportedMessageException.create();
    }
    Meta meta = receiver.getKlass().getMeta();
    Method remove = getInteropKlass(receiver).itableLookup(meta.java_util_Map, meta.java_util_Map_remove.getITableIndex());
    try {
        invoke.execute(remove, receiver, new Object[] { key });
    } catch (UnsupportedTypeException e) {
        throw UnknownKeyException.create(key);
    } catch (ArityException e) {
        throw EspressoError.shouldNotReachHere(e);
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) Method(com.oracle.truffle.espresso.impl.Method) ArityException(com.oracle.truffle.api.interop.ArityException) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 43 with Method

use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.

the class MapInterop method getHashEntriesIterator.

@SuppressWarnings("static-method")
@ExportMessage
public static Object getHashEntriesIterator(StaticObject receiver, @CachedLibrary(limit = "1") InteropLibrary setLibrary, @Cached.Exclusive @Cached InvokeEspressoNode invoke) throws UnsupportedMessageException {
    if (!hasHashEntries(receiver)) {
        throw UnsupportedMessageException.create();
    }
    Meta meta = receiver.getKlass().getMeta();
    Method entrySet = getInteropKlass(receiver).itableLookup(meta.java_util_Map, meta.java_util_Map_entrySet.getITableIndex());
    Object set = null;
    try {
        set = invoke.execute(entrySet, receiver, EMPTY_ARRAY);
    } catch (ArityException | UnsupportedTypeException e) {
        throw EspressoError.shouldNotReachHere(e);
    }
    assert set != null;
    assert setLibrary.hasIterator(set);
    return setLibrary.getIterator(set);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method) ArityException(com.oracle.truffle.api.interop.ArityException) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 44 with Method

use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.

the class LinkToVirtualNode method linkTo.

@Override
public Method linkTo(Method target, Object[] args) {
    Method resolved = target;
    if ((target.getRefKind() == REF_invokeSpecial) || target.isFinalFlagSet() || target.getDeclaringKlass().isFinalFlagSet()) {
        return resolved;
    }
    StaticObject receiver = (StaticObject) args[0];
    resolved = receiver.getKlass().vtableLookup(target.getVTableIndex());
    return resolved;
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method)

Example 45 with Method

use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.

the class InvokeEspressoNode method execute.

public final Object execute(Method method, Object receiver, Object[] arguments) throws ArityException, UnsupportedTypeException {
    Method.MethodVersion resolutionSeed = method.getMethodVersion();
    if (!resolutionSeed.getRedefineAssumption().isValid()) {
        // OK, we know it's a removed method then
        resolutionSeed = method.getContext().getClassRedefinition().handleRemovedMethod(method, method.isStatic() ? method.getDeclaringKlass() : ((StaticObject) receiver).getKlass()).getMethodVersion();
    }
    Object result = executeMethod(resolutionSeed, receiver, arguments);
    /*
         * Unwrap foreign objects (invariant: foreign objects are always wrapped when coming in
         * Espresso and unwrapped when going out)
         */
    if (result instanceof StaticObject && ((StaticObject) result).isForeignObject()) {
        return ((StaticObject) result).rawForeignObject();
    }
    return result;
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method)

Aggregations

Method (com.oracle.truffle.espresso.impl.Method)91 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)57 Meta (com.oracle.truffle.espresso.meta.Meta)27 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)22 Klass (com.oracle.truffle.espresso.impl.Klass)19 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)19 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)16 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)14 ExportMessage (com.oracle.truffle.api.library.ExportMessage)12 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)10 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)9 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)8 ArityException (com.oracle.truffle.api.interop.ArityException)8 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)8 ArrayList (java.util.ArrayList)8 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)7 EspressoException (com.oracle.truffle.espresso.runtime.EspressoException)5 Field (com.oracle.truffle.espresso.impl.Field)4 MethodParametersAttribute (com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute)3 Signature (com.oracle.truffle.espresso.descriptors.Symbol.Signature)3