Search in sources :

Example 56 with Method

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

the class VM method getEspressoRootFromFrame.

@TruffleBoundary
public static EspressoRootNode getEspressoRootFromFrame(FrameInstance frameInstance, EspressoContext context) {
    EspressoRootNode root = getRawEspressoRootFromFrame(frameInstance);
    if (root == null) {
        return null;
    }
    Method method = root.getMethod();
    if (method.getContext() != context) {
        return null;
    }
    return root;
}
Also used : EspressoRootNode(com.oracle.truffle.espresso.nodes.EspressoRootNode) Method(com.oracle.truffle.espresso.impl.Method) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 57 with Method

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

the class BytecodeNode method getBaseQuickNode.

private BaseQuickNode getBaseQuickNode(int curBCI, int top, int statementIndex, BaseQuickNode quickNode) {
    // block while class redefinition is ongoing
    quickNode.getContext().getClassRedefinition().check();
    BaseQuickNode result = quickNode;
    synchronized (this) {
        // re-check if node was already replaced by another thread
        if (result != nodes[readCPI(curBCI)]) {
            // another thread beat us
            result = nodes[readCPI(curBCI)];
        } else {
            // other threads might still have beat us but if
            // so, the resolution failed and so will we below
            BytecodeStream original = new BytecodeStream(getMethodVersion().getCodeAttribute().getOriginalCode());
            char cpi = original.readCPI(curBCI);
            int nodeOpcode = original.currentBC(curBCI);
            Method resolutionSeed = resolveMethodNoCache(nodeOpcode, cpi);
            result = insert(dispatchQuickened(top, curBCI, cpi, nodeOpcode, statementIndex, resolutionSeed, getContext().InlineFieldAccessors));
            nodes[readCPI(curBCI)] = result;
        }
    }
    return result;
}
Also used : BytecodeStream(com.oracle.truffle.espresso.bytecode.BytecodeStream) BaseQuickNode(com.oracle.truffle.espresso.nodes.quick.BaseQuickNode) Method(com.oracle.truffle.espresso.impl.Method) TruffleSafepoint(com.oracle.truffle.api.TruffleSafepoint)

Example 58 with Method

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

the class JniEnv method CallNonvirtualCharMethodVarargs.

@JniImpl
public char CallNonvirtualCharMethodVarargs(@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()));
    return getMeta().asChar(result, true);
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Method(com.oracle.truffle.espresso.impl.Method)

Example 59 with Method

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

the class JniEnv method CallStaticVoidMethodVarargs.

@JniImpl
public void CallStaticVoidMethodVarargs(@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()));
    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 60 with Method

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

the class JniEnv method ToReflectedMethod.

// endregion Register/Unregister natives
// region Reflection
/**
 * <h3>jobject ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID methodID, jboolean
 * isStatic);</h3>
 * <p>
 * Converts a method ID derived from cls to a java.lang.reflect.Method or
 * java.lang.reflect.Constructor object. isStatic must be set to JNI_TRUE if the method ID
 * refers to a static field, and JNI_FALSE otherwise.
 * <p>
 * Throws OutOfMemoryError and returns 0 if fails.
 */
@JniImpl
@JavaType(java.lang.reflect.Executable.class)
public StaticObject ToReflectedMethod(@JavaType(Class.class) StaticObject unused, @Handle(Method.class) long methodId, @SuppressWarnings("unused") boolean isStatic) {
    Method method = methodIds.getObject(methodId);
    assert method.getDeclaringKlass().isAssignableFrom(unused.getMirrorKlass());
    StaticObject methods = null;
    if (method.isConstructor()) {
        methods = getVM().JVM_GetClassDeclaredConstructors(method.getDeclaringKlass().mirror(), false);
    } else {
        methods = getVM().JVM_GetClassDeclaredMethods(method.getDeclaringKlass().mirror(), false);
    }
    for (StaticObject declMethod : methods.<StaticObject[]>unwrap()) {
        assert InterpreterToVM.instanceOf(declMethod, getMeta().java_lang_reflect_Executable);
        Method m = null;
        if (method.isConstructor()) {
            assert InterpreterToVM.instanceOf(declMethod, getMeta().java_lang_reflect_Constructor);
            m = (Method) getMeta().HIDDEN_CONSTRUCTOR_KEY.getHiddenObject(declMethod);
        } else {
            assert InterpreterToVM.instanceOf(declMethod, getMeta().java_lang_reflect_Method);
            m = (Method) getMeta().HIDDEN_METHOD_KEY.getHiddenObject(declMethod);
        }
        if (method == m) {
            return declMethod;
        }
    }
    throw EspressoError.shouldNotReachHere("Method/constructor not found ", method);
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

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