Search in sources :

Example 11 with Method

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

the class JniEnv method CallNonvirtualLongMethodVarargs.

@JniImpl
public long CallNonvirtualLongMethodVarargs(@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().asLong(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 12 with Method

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

the class JniEnv method NewObjectVarargs.

@JniImpl
@JavaType(Object.class)
public StaticObject NewObjectVarargs(@JavaType(Class.class) StaticObject clazz, @Handle(Method.class) long methodId, @Pointer TruffleObject varargsPtr) {
    Method method = methodIds.getObject(methodId);
    assert method.isConstructor();
    Klass klass = clazz.getMirrorKlass();
    if (klass.isInterface() || klass.isAbstract()) {
        Meta meta = getMeta();
        throw meta.throwException(meta.java_lang_InstantiationException);
    }
    klass.initialize();
    StaticObject instance;
    if (CompilerDirectives.isPartialEvaluationConstant(klass)) {
        instance = klass.allocateInstance();
    } else {
        instance = allocateBoundary(klass);
    }
    method.invokeDirect(instance, popVarArgs(varargsPtr, method.getParsedSignature()));
    return instance;
}
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) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 13 with Method

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

the class JniEnv method CallNonvirtualDoubleMethodVarargs.

@JniImpl
public double CallNonvirtualDoubleMethodVarargs(@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().asDouble(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 14 with Method

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

the class JniEnv method RegisterNative.

// endregion DirectBuffers
// region Register/Unregister natives
@JniImpl
@TruffleBoundary
public int RegisterNative(@JavaType(Class.class) StaticObject clazz, @Pointer TruffleObject methodNamePtr, @Pointer TruffleObject methodSignaturePtr, @Pointer TruffleObject closure) {
    String methodName = NativeUtils.interopPointerToString(methodNamePtr);
    String methodSignature = NativeUtils.interopPointerToString(methodSignaturePtr);
    assert methodName != null && methodSignature != null;
    Symbol<Name> name = getNames().lookup(methodName);
    Symbol<Signature> signature = getSignatures().lookupValidSignature(methodSignature);
    Meta meta = getMeta();
    if (name == null || signature == null) {
        setPendingException(Meta.initException(meta.java_lang_NoSuchMethodError));
        return JNI_ERR;
    }
    Method targetMethod = clazz.getMirrorKlass().lookupDeclaredMethod(name, signature);
    if (targetMethod != null && targetMethod.isNative()) {
        targetMethod.unregisterNative();
        getSubstitutions().removeRuntimeSubstitution(targetMethod);
    } else {
        setPendingException(Meta.initException(meta.java_lang_NoSuchMethodError));
        return JNI_ERR;
    }
    Substitutions.EspressoRootNodeFactory factory = null;
    // Lookup known VM methods to shortcut native boudaries.
    factory = lookupKnownVmMethods(closure, targetMethod);
    if (factory == null) {
        NativeSignature ns = Method.buildJniNativeSignature(targetMethod.getParsedSignature());
        final TruffleObject boundNative = getNativeAccess().bindSymbol(closure, ns);
        factory = createJniRootNodeFactory(() -> new NativeMethodNode(boundNative, targetMethod.getMethodVersion()), targetMethod);
    }
    Symbol<Type> classType = clazz.getMirrorKlass().getType();
    getSubstitutions().registerRuntimeSubstitution(classType, name, signature, factory, true);
    return JNI_OK;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Method(com.oracle.truffle.espresso.impl.Method) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) NativeSignature(com.oracle.truffle.espresso.ffi.NativeSignature) NativeType(com.oracle.truffle.espresso.ffi.NativeType) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) NativeSignature(com.oracle.truffle.espresso.ffi.NativeSignature) Signature(com.oracle.truffle.espresso.descriptors.Symbol.Signature) Substitutions(com.oracle.truffle.espresso.substitutions.Substitutions) NativeMethodNode(com.oracle.truffle.espresso.nodes.NativeMethodNode) IntrinsifiedNativeMethodNode(com.oracle.truffle.espresso.nodes.IntrinsifiedNativeMethodNode) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 15 with Method

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

the class JniEnv method CallNonvirtualObjectMethodVarargs.

// endregion Call*Method
// region CallNonvirtual*Method
@JniImpl
@JavaType(Object.class)
public StaticObject CallNonvirtualObjectMethodVarargs(@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().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)

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