Search in sources :

Example 16 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject 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 17 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class JniEnv method FindClass.

/**
 * <h3>jclass FindClass(JNIEnv *env, const char *name);</h3>
 *
 * <p>
 * FindClass locates the class loader associated with the current native method; that is, the
 * class loader of the class that declared the native method. If the native method belongs to a
 * system class, no class loader will be involved. Otherwise, the proper class loader will be
 * invoked to load and link the named class. Since Java 2 SDK release 1.2, when FindClass is
 * called through the Invocation Interface, there is no current native method or its associated
 * class loader. In that case, the result of {@link ClassLoader#getSystemClassLoader} is used.
 * This is the class loader the virtual machine creates for applications, and is able to locate
 * classes listed in the java.class.path property. The name argument is a fully-qualified class
 * name or an array type signature .
 * <p>
 * For example, the fully-qualified class name for the {@code java.lang.String} class is:
 *
 * <pre>
 * "java/lang/String"}
 * </pre>
 *
 * <p>
 * The array type signature of the array class {@code java.lang.Object[]} is:
 *
 * <pre>
 * "[Ljava/lang/Object;"
 * </pre>
 *
 * @param namePtr a fully-qualified class name (that is, a package name, delimited by "/",
 *            followed by the class name). If the name begins with "[" (the array signature
 *            character), it returns an array class. The string is encoded in modified UTF-8.
 * @return Returns a class object from a fully-qualified name, or NULL if the class cannot be
 *         found.
 * @throws ClassFormatError if the class data does not specify a valid class.
 * @throws ClassCircularityError if a class or interface would be its own superclass or
 *             superinterface.
 * @throws NoClassDefFoundError if no definition for a requested class or interface can be
 *             found.
 * @throws OutOfMemoryError if the system runs out of memory.
 */
@TruffleBoundary
@JniImpl
@JavaType(Class.class)
public StaticObject FindClass(@Pointer TruffleObject namePtr, @Inject SubstitutionProfiler profiler) {
    String name = NativeUtils.interopPointerToString(namePtr);
    Meta meta = getMeta();
    if (name == null || (name.indexOf('.') > -1)) {
        profiler.profile(7);
        throw meta.throwExceptionWithMessage(meta.java_lang_NoClassDefFoundError, name);
    }
    String internalName = name;
    if (!name.startsWith("[")) {
        // Force 'L' type.
        internalName = "L" + name + ";";
    }
    if (!Validation.validTypeDescriptor(ByteSequence.create(internalName), true)) {
        profiler.profile(6);
        throw meta.throwExceptionWithMessage(meta.java_lang_NoClassDefFoundError, name);
    }
    StaticObject protectionDomain = StaticObject.NULL;
    StaticObject loader = StaticObject.NULL;
    // security stack walk
    StaticObject caller = getVM().JVM_GetCallerClass(0, profiler);
    if (StaticObject.notNull(caller)) {
        Klass callerKlass = caller.getMirrorKlass();
        loader = callerKlass.getDefiningClassLoader();
        if (StaticObject.isNull(loader) && Type.java_lang_ClassLoader$NativeLibrary.equals(callerKlass.getType())) {
            StaticObject result = (StaticObject) getMeta().java_lang_ClassLoader$NativeLibrary_getFromClass.invokeDirect(null);
            loader = result.getMirrorKlass().getDefiningClassLoader();
            protectionDomain = getVM().JVM_GetProtectionDomain(result);
        }
    } else {
        loader = (StaticObject) getMeta().java_lang_ClassLoader_getSystemClassLoader.invokeDirect(null);
    }
    StaticObject guestClass = StaticObject.NULL;
    try {
        String dotName = name.replace('/', '.');
        guestClass = (StaticObject) getMeta().java_lang_Class_forName_String_boolean_ClassLoader.invokeDirect(null, meta.toGuestString(dotName), false, loader);
        EspressoError.guarantee(StaticObject.notNull(guestClass), "Class.forName returned null");
    } catch (EspressoException e) {
        profiler.profile(5);
        if (InterpreterToVM.instanceOf(e.getGuestException(), meta.java_lang_ClassNotFoundException)) {
            profiler.profile(4);
            throw meta.throwExceptionWithMessage(meta.java_lang_NoClassDefFoundError, name);
        }
        throw e;
    }
    meta.HIDDEN_PROTECTION_DOMAIN.setHiddenObject(guestClass, protectionDomain);
    // FindClass should initialize the class.
    guestClass.getMirrorKlass().safeInitialize();
    return guestClass;
}
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) EspressoException(com.oracle.truffle.espresso.runtime.EspressoException) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 18 with StaticObject

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

Example 19 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject 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 20 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class Method method getHostReflectiveConstructorRoot.

public static Method getHostReflectiveConstructorRoot(StaticObject seed, Meta meta) {
    assert seed.getKlass().getMeta().java_lang_reflect_Constructor.isAssignableFrom(seed.getKlass());
    StaticObject curMethod = seed;
    Method target = null;
    while (target == null) {
        target = (Method) meta.HIDDEN_CONSTRUCTOR_KEY.getHiddenObject(curMethod);
        if (target == null) {
            curMethod = meta.java_lang_reflect_Constructor_root.getObject(curMethod);
        }
    }
    return target;
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject)

Aggregations

StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)199 Method (com.oracle.truffle.espresso.impl.Method)57 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)44 Klass (com.oracle.truffle.espresso.impl.Klass)32 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)32 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)30 Meta (com.oracle.truffle.espresso.meta.Meta)29 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)26 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)23 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)17 ArrayList (java.util.ArrayList)13 EspressoException (com.oracle.truffle.espresso.runtime.EspressoException)9 Symbol (com.oracle.truffle.espresso.descriptors.Symbol)8 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)7 ExportMessage (com.oracle.truffle.api.library.ExportMessage)7 BytecodeNode (com.oracle.truffle.espresso.nodes.BytecodeNode)7 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)6 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)6 EspressoContext (com.oracle.truffle.espresso.runtime.EspressoContext)6 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)5