Search in sources :

Example 61 with Method

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

the class JniEnv method CallNonvirtualShortMethodVarargs.

@JniImpl
public short CallNonvirtualShortMethodVarargs(@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().asShort(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 62 with Method

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

the class JniEnv method UnregisterNatives.

/**
 * <h3>jint UnregisterNatives(JNIEnv *env, jclass clazz);</h3>
 * <p>
 * Unregisters native methods of a class. The class goes back to the state before it was linked
 * or registered with its native method functions.
 * <p>
 * This function should not be used in normal native code. Instead, it provides special programs
 * a way to reload and relink native libraries.
 *
 * @param clazz a Java class object.
 *            <p>
 *            Returns 0 on success; returns a negative value on failure.
 */
@JniImpl
@TruffleBoundary
public int UnregisterNatives(@JavaType(Class.class) StaticObject clazz) {
    Klass klass = clazz.getMirrorKlass();
    for (Method m : klass.getDeclaredMethods()) {
        if (m.isNative()) {
            getSubstitutions().removeRuntimeSubstitution(m);
            m.unregisterNative();
        }
    }
    return JNI_OK;
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) Method(com.oracle.truffle.espresso.impl.Method) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 63 with Method

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

the class IntrinsifiedNativeMethodNode method executeBody.

@Override
Object executeBody(VirtualFrame frame) {
    Object[] args = frame.getArguments();
    Method method = getMethod();
    if (method.isStatic()) {
        int parameterCount = method.getParameterCount();
        Object[] newArgs = new Object[parameterCount + 1];
        newArgs[0] = method.getDeclaringKlass().mirror();
        System.arraycopy(args, 0, newArgs, 1, parameterCount);
        args = newArgs;
    }
    return nativeMethod.invokeDirect(env, args);
}
Also used : Method(com.oracle.truffle.espresso.impl.Method)

Example 64 with Method

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

the class EspressoInstrumentableNode method getScope.

@ExportMessage
@TruffleBoundary
@SuppressWarnings("static-method")
public final Object getScope(Frame frame, @SuppressWarnings("unused") boolean nodeEnter) {
    // construct the current scope with valid local variables information
    Method method = getMethod();
    Local[] liveLocals = method.getLocalVariableTable().getLocalsAt(getBci(frame));
    if (liveLocals.length == 0) {
        // class was compiled without a local variable table
        // include "this" in method arguments throughout the method
        boolean hasReceiver = !method.isStatic();
        int localCount = hasReceiver ? 1 : 0;
        localCount += method.getParameterCount();
        liveLocals = new Local[localCount];
        Klass[] parameters = (Klass[]) method.getParameters();
        Utf8ConstantTable utf8Constants = getContext().getLanguage().getUtf8ConstantTable();
        int startslot = 0;
        if (hasReceiver) {
            // include 'this' and method arguments
            liveLocals[0] = new Local(utf8Constants.getOrCreate(Symbol.Name.thiz), utf8Constants.getOrCreate(method.getDeclaringKlass().getType()), 0, 65536, 0);
            startslot++;
        }
        // include method parameters
        for (int i = startslot; i < localCount; i++) {
            Klass param = hasReceiver ? parameters[i - 1] : parameters[i];
            liveLocals[i] = new Local(utf8Constants.getOrCreate(ByteSequence.create("param_" + (i))), utf8Constants.getOrCreate(param.getType()), 0, 65536, i);
        }
    }
    return EspressoScope.createVariables(liveLocals, frame, method.getName());
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) Local(com.oracle.truffle.espresso.classfile.attributes.Local) Method(com.oracle.truffle.espresso.impl.Method) Utf8ConstantTable(com.oracle.truffle.espresso.descriptors.Utf8ConstantTable) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 65 with Method

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

the class JniEnv method CallNonvirtualByteMethodVarargs.

@JniImpl
public byte CallNonvirtualByteMethodVarargs(@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().asByte(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)

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