Search in sources :

Example 11 with Klass

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

the class VM method JVM_DoPrivileged.

@VmImpl(isJni = true)
@SuppressWarnings("unused")
@JavaType(Object.class)
public StaticObject JVM_DoPrivileged(@JavaType(Class.class) StaticObject cls, /* PrivilegedAction or PrivilegedActionException */
@JavaType(Object.class) StaticObject action, @JavaType(AccessControlContext.class) StaticObject context, boolean wrapException, @Inject Meta meta, @Inject SubstitutionProfiler profiler) {
    if (StaticObject.isNull(action)) {
        profiler.profile(0);
        throw meta.throwNullPointerException();
    }
    FrameInstance callerFrame = getCallerFrame(1, false, meta);
    assert callerFrame != null : "No caller ?";
    Klass caller = getMethodFromFrame(callerFrame).getDeclaringKlass();
    StaticObject acc = context;
    if (!StaticObject.isNull(context)) {
        if (!isAuthorized(context, caller)) {
            acc = createDummyACC();
        }
    }
    Method run = action.getKlass().lookupMethod(Name.run, Signature.Object);
    if (run == null || !run.isPublic() || run.isStatic()) {
        profiler.profile(1);
        throw meta.throwException(meta.java_lang_InternalError);
    }
    // Prepare the privileged stack
    PrivilegedStack stack = getPrivilegedStack();
    stack.push(callerFrame, acc, caller);
    // Execute the action.
    StaticObject result;
    try {
        result = (StaticObject) run.invokeDirect(action);
    } catch (EspressoException e) {
        profiler.profile(2);
        if (meta.java_lang_Exception.isAssignableFrom(e.getGuestException().getKlass()) && !meta.java_lang_RuntimeException.isAssignableFrom(e.getGuestException().getKlass())) {
            profiler.profile(3);
            StaticObject wrapper = meta.java_security_PrivilegedActionException.allocateInstance();
            getMeta().java_security_PrivilegedActionException_init_Exception.invokeDirect(wrapper, e.getGuestException());
            throw meta.throwException(wrapper);
        }
        profiler.profile(4);
        throw e;
    } finally {
        stack.pop();
    }
    return result;
}
Also used : 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) Method(com.oracle.truffle.espresso.impl.Method) FrameInstance(com.oracle.truffle.api.frame.FrameInstance) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 12 with Klass

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

the class VM method JVM_GetSimpleBinaryName.

@VmImpl(isJni = true)
@JavaType(String.class)
public StaticObject JVM_GetSimpleBinaryName(@JavaType(Class.class) StaticObject self) {
    Klass k = self.getMirrorKlass();
    if (k.isPrimitive() || k.isArray()) {
        return StaticObject.NULL;
    }
    ObjectKlass klass = (ObjectKlass) k;
    RuntimeConstantPool pool = klass.getConstantPool();
    InnerClassesAttribute inner = klass.getInnerClasses();
    for (InnerClassesAttribute.Entry entry : inner.entries()) {
        int innerClassIndex = entry.innerClassIndex;
        if (innerClassIndex != 0) {
            if (pool.classAt(innerClassIndex).getName(pool) == klass.getName()) {
                if (pool.resolvedKlassAt(k, innerClassIndex) == k) {
                    if (entry.innerNameIndex != 0) {
                        Symbol<Name> innerName = pool.symbolAt(entry.innerNameIndex);
                        return getMeta().toGuestString(innerName);
                    } else {
                        break;
                    }
                }
            }
        }
    }
    return StaticObject.NULL;
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) RuntimeConstantPool(com.oracle.truffle.espresso.classfile.RuntimeConstantPool) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) NoSafepoint(com.oracle.truffle.espresso.jni.NoSafepoint) InnerClassesAttribute(com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 13 with Klass

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

the class VM method JVM_GetDeclaringClass.

@VmImpl(isJni = true)
@JavaType(Class.class)
public static StaticObject JVM_GetDeclaringClass(@JavaType(Class.class) StaticObject self) {
    // Primitives and arrays are not "enclosed".
    if (!(self.getMirrorKlass() instanceof ObjectKlass)) {
        return StaticObject.NULL;
    }
    ObjectKlass k = (ObjectKlass) self.getMirrorKlass();
    Klass outerKlass = computeEnclosingClass(k);
    if (outerKlass == null) {
        return StaticObject.NULL;
    }
    return outerKlass.mirror();
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 14 with Klass

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

the class VM method JVM_GetClassInterfaces.

@VmImpl(isJni = true)
@JavaType(Class[].class)
public StaticObject JVM_GetClassInterfaces(@JavaType(Class.class) StaticObject self) {
    final Klass[] superInterfaces = self.getMirrorKlass().getImplementedInterfaces();
    StaticObject instance = getMeta().java_lang_Class.allocateReferenceArray(superInterfaces.length, new IntFunction<StaticObject>() {

        @Override
        public StaticObject apply(int i) {
            return superInterfaces[i].mirror();
        }
    });
    return instance;
}
Also used : 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) NoSafepoint(com.oracle.truffle.espresso.jni.NoSafepoint) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 15 with Klass

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

the class VM method fillInElement.

private void fillInElement(@JavaType(StackTraceElement.class) StaticObject ste, VM.StackElement element, Method classGetName) {
    Method m = element.getMethod();
    Klass k = m.getDeclaringKlass();
    StaticObject guestClass = k.mirror();
    StaticObject loader = k.getDefiningClassLoader();
    ModuleEntry module = k.module();
    // Fill in class name
    getMeta().java_lang_StackTraceElement_declaringClass.setObject(ste, classGetName.invokeDirect(guestClass));
    getMeta().java_lang_StackTraceElement_declaringClassObject.setObject(ste, guestClass);
    // Fill in loader name
    if (!StaticObject.isNull(loader)) {
        StaticObject loaderName = getMeta().java_lang_ClassLoader_name.getObject(loader);
        if (!StaticObject.isNull(loader)) {
            getMeta().java_lang_StackTraceElement_classLoaderName.setObject(ste, loaderName);
        }
    }
    // Fill in method name
    Symbol<Name> mname = m.getName();
    getMeta().java_lang_StackTraceElement_methodName.setObject(ste, getMeta().toGuestString(mname));
    // Fill in module
    if (module.isNamed()) {
        getMeta().java_lang_StackTraceElement_moduleName.setObject(ste, getMeta().toGuestString(module.getName()));
    // TODO: module version
    }
    // Fill in source information
    getMeta().java_lang_StackTraceElement_fileName.setObject(ste, getMeta().toGuestString(m.getSourceFile()));
    getMeta().java_lang_StackTraceElement_lineNumber.setInt(ste, m.bciToLineNumber(element.getBCI()));
}
Also used : 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) ModuleEntry(com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry) Method(com.oracle.truffle.espresso.impl.Method) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Aggregations

Klass (com.oracle.truffle.espresso.impl.Klass)71 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)54 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)49 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)33 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)24 Meta (com.oracle.truffle.espresso.meta.Meta)21 Method (com.oracle.truffle.espresso.impl.Method)19 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)10 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)10 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)10 ExportMessage (com.oracle.truffle.api.library.ExportMessage)8 Field (com.oracle.truffle.espresso.impl.Field)7 ArrayList (java.util.ArrayList)7 RuntimeConstantPool (com.oracle.truffle.espresso.classfile.RuntimeConstantPool)6 EspressoException (com.oracle.truffle.espresso.runtime.EspressoException)6 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)5 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)5 NativeType (com.oracle.truffle.espresso.ffi.NativeType)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)3 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)3