Search in sources :

Example 6 with Method

use of com.oracle.truffle.espresso.impl.Method 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 7 with Method

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

the class JniEnv method GetMethodID.

/**
 * <h3>jmethodID GetMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig);</h3>
 * <p>
 * Returns the method ID for an instance (nonstatic) method of a class or interface. The method
 * may be defined in one of the clazz’s superclasses and inherited by clazz. The method is
 * determined by its name and signature.
 * <p>
 * GetMethodID() causes an uninitialized class to be initialized.
 * <p>
 * To obtain the method ID of a constructor, supply <init> as the method name and void (V) as
 * the return type.
 *
 * @param clazz a Java class object.
 * @param namePtr the method name in a 0-terminated modified UTF-8 string.
 * @param signaturePtr the method signature in 0-terminated modified UTF-8 string.
 * @return a method ID, or NULL if the specified method cannot be found.
 * @throws NoSuchMethodError if the specified method cannot be found.
 * @throws ExceptionInInitializerError if the class initializer fails due to an exception.
 * @throws OutOfMemoryError if the system runs out of memory.
 */
@JniImpl
@Handle(Method.class)
public long GetMethodID(@JavaType(Class.class) StaticObject clazz, @Pointer TruffleObject namePtr, @Pointer TruffleObject signaturePtr) {
    String name = NativeUtils.interopPointerToString(namePtr);
    String signature = NativeUtils.interopPointerToString(signaturePtr);
    assert name != null && signature != null;
    Method method = null;
    Symbol<Name> methodName = getNames().lookup(name);
    if (methodName != null) {
        Symbol<Signature> methodSignature = getSignatures().lookupValidSignature(signature);
        if (methodSignature != null) {
            Klass klass = clazz.getMirrorKlass();
            klass.safeInitialize();
            // Lookup only if name and type are known symbols.
            method = klass.lookupMethod(methodName, methodSignature, klass);
        }
    }
    if (method == null || method.isStatic()) {
        Meta meta = getMeta();
        throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchMethodError, name);
    }
    return methodIds.handlify(method);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) NativeSignature(com.oracle.truffle.espresso.ffi.NativeSignature) Signature(com.oracle.truffle.espresso.descriptors.Symbol.Signature) Method(com.oracle.truffle.espresso.impl.Method) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 8 with Method

use of com.oracle.truffle.espresso.impl.Method 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)

Example 9 with Method

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

the class JniEnv method CallNonvirtualVoidMethodVarargs.

@JniImpl
public void CallNonvirtualVoidMethodVarargs(@JavaType(Object.class) StaticObject receiver, @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(receiver, popVarArgs(varargsPtr, method.getParsedSignature()));
    assert result instanceof StaticObject && StaticObject.isNull((StaticObject) result) : "void methods must return StaticObject.NULL";
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Method(com.oracle.truffle.espresso.impl.Method)

Example 10 with Method

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

the class JniEnv method ExceptionDescribe.

/**
 * <h3>void ExceptionDescribe(JNIEnv *env);</h3>
 * <p>
 * Prints an exception and a backtrace of the stack to a system error-reporting channel, such as
 * stderr. This is a convenience routine provided for debugging.
 */
@JniImpl
public void ExceptionDescribe() {
    EspressoException ex = getPendingEspressoException();
    if (ex != null) {
        StaticObject guestException = ex.getGuestException();
        assert InterpreterToVM.instanceOf(guestException, getMeta().java_lang_Throwable);
        // Dynamic lookup.
        Method printStackTrace = guestException.getKlass().lookupMethod(Name.printStackTrace, Signature._void);
        printStackTrace.invokeDirect(guestException);
        // Restore exception cleared by invokeDirect.
        setPendingException(ex);
    }
}
Also used : EspressoException(com.oracle.truffle.espresso.runtime.EspressoException) 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