Search in sources :

Example 16 with JavaType

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

use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.

the class VM method JVM_AssertionStatusDirectives.

// endregion array
// region assertion
/**
 * Espresso only supports basic -ea and -esa options. Complex per-class/package filters are
 * unsupported.
 */
@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(internalName = "Ljava/lang/AssertionStatusDirectives;")
public StaticObject JVM_AssertionStatusDirectives(@SuppressWarnings("unused") @JavaType(Class.class) StaticObject unused) {
    Meta meta = getMeta();
    StaticObject instance = meta.java_lang_AssertionStatusDirectives.allocateInstance();
    meta.java_lang_AssertionStatusDirectives.lookupMethod(Name._init_, Signature._void).invokeDirect(instance);
    meta.java_lang_AssertionStatusDirectives_classes.set(instance, meta.java_lang_String.allocateReferenceArray(0));
    meta.java_lang_AssertionStatusDirectives_classEnabled.set(instance, meta._boolean.allocatePrimitiveArray(0));
    meta.java_lang_AssertionStatusDirectives_packages.set(instance, meta.java_lang_String.allocateReferenceArray(0));
    meta.java_lang_AssertionStatusDirectives_packageEnabled.set(instance, meta._boolean.allocatePrimitiveArray(0));
    boolean ea = getContext().getEnv().getOptions().get(EspressoOptions.EnableAssertions);
    meta.java_lang_AssertionStatusDirectives_deflt.set(instance, ea);
    return instance;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 18 with JavaType

use of com.oracle.truffle.espresso.substitutions.JavaType 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 19 with JavaType

use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.

the class VM method JVM_InitProperties.

@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(Properties.class)
public StaticObject JVM_InitProperties(@JavaType(Properties.class) StaticObject properties) {
    Map<String, String> props = buildPropertiesMap();
    Method setProperty = properties.getKlass().lookupMethod(Name.setProperty, Signature.Object_String_String);
    for (Map.Entry<String, String> entry : props.entrySet()) {
        setProperty.invokeWithConversions(properties, entry.getKey(), entry.getValue());
    }
    return properties;
}
Also used : Method(com.oracle.truffle.espresso.impl.Method) Map(java.util.Map) EconomicMap(org.graalvm.collections.EconomicMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 20 with JavaType

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

Aggregations

JavaType (com.oracle.truffle.espresso.substitutions.JavaType)58 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)44 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)28 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)24 Klass (com.oracle.truffle.espresso.impl.Klass)24 Meta (com.oracle.truffle.espresso.meta.Meta)20 Method (com.oracle.truffle.espresso.impl.Method)19 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)15 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)13 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)8 NativeType (com.oracle.truffle.espresso.ffi.NativeType)8 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)5 Field (com.oracle.truffle.espresso.impl.Field)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 RuntimeConstantPool (com.oracle.truffle.espresso.classfile.RuntimeConstantPool)4 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)4 ArrayList (java.util.ArrayList)4 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)3 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)3 MethodParametersAttribute (com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute)3