Search in sources :

Example 26 with Method

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

the class VM method getACCUntil11.

private StaticObject getACCUntil11() {
    ArrayList<StaticObject> domains = new ArrayList<>();
    final PrivilegedStack stack = getPrivilegedStack();
    final boolean[] isPrivileged = new boolean[] { false };
    StaticObject context = Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<StaticObject>() {

        StaticObject prevDomain = StaticObject.NULL;

        @Override
        public StaticObject visitFrame(FrameInstance frameInstance) {
            Method m = getMethodFromFrame(frameInstance);
            if (m != null) {
                if (stack.compare(frameInstance)) {
                    isPrivileged[0] = true;
                }
                StaticObject domain = JVM_GetProtectionDomain(m.getDeclaringKlass().mirror());
                if (domain != prevDomain && domain != StaticObject.NULL) {
                    domains.add(domain);
                    prevDomain = domain;
                }
                if (isPrivileged[0]) {
                    return stack.peekContext();
                }
            }
            return null;
        }
    });
    return getAccFromContext(domains, isPrivileged[0], context);
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) ArrayList(java.util.ArrayList) Method(com.oracle.truffle.espresso.impl.Method) FrameInstance(com.oracle.truffle.api.frame.FrameInstance)

Example 27 with Method

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

the class VM method getGuestReflectiveConstructorRoot.

@JavaType(java.lang.reflect.Constructor.class)
private static StaticObject getGuestReflectiveConstructorRoot(@JavaType(java.lang.reflect.Constructor.class) StaticObject seed, Meta meta) {
    assert InterpreterToVM.instanceOf(seed, meta.java_lang_reflect_Constructor);
    StaticObject curConstructor = seed;
    Method target = null;
    while (target == null) {
        target = (Method) meta.HIDDEN_CONSTRUCTOR_KEY.getHiddenObject(curConstructor);
        if (target == null) {
            curConstructor = meta.java_lang_reflect_Constructor_root.getObject(curConstructor);
        }
    }
    return curConstructor;
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 28 with Method

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

Example 29 with Method

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

the class VM method JVM_GetClassDeclaredMethods.

// TODO(tg): inject constructor calltarget.
@VmImpl(isJni = true)
@JavaType(java.lang.reflect.Method[].class)
public StaticObject JVM_GetClassDeclaredMethods(@JavaType(Class.class) StaticObject self, boolean publicOnly) {
    Meta meta = getMeta();
    ArrayList<Method> collectedMethods = new ArrayList<>();
    Klass klass = self.getMirrorKlass();
    klass.ensureLinked();
    for (Method m : klass.getDeclaredMethods()) {
        if ((!publicOnly || m.isPublic()) && // Filter out <init> and <clinit> from reflection.
        !Name._init_.equals(m.getName()) && !Name._clinit_.equals(m.getName())) {
            collectedMethods.add(m);
        }
    }
    final Method[] methods = collectedMethods.toArray(Method.EMPTY_ARRAY);
    return meta.java_lang_reflect_Method.allocateReferenceArray(methods.length, new IntFunction<StaticObject>() {

        @Override
        public StaticObject apply(int i) {
            return methods[i].makeMirror();
        }
    });
}
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) ArrayList(java.util.ArrayList) Method(com.oracle.truffle.espresso.impl.Method) NoSafepoint(com.oracle.truffle.espresso.jni.NoSafepoint) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 30 with Method

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

the class Target_sun_reflect_NativeConstructorAccessorImpl method newInstance0.

@Substitution
@JavaType(Object.class)
public static StaticObject newInstance0(@JavaType(Constructor.class) StaticObject constructor, @JavaType(Object[].class) StaticObject args0, @Inject Meta meta) {
    Klass klass = meta.java_lang_reflect_Constructor_clazz.getObject(constructor).getMirrorKlass();
    klass.safeInitialize();
    if (klass.isArray() || klass.isPrimitive() || klass.isInterface() || klass.isAbstract()) {
        throw meta.throwException(meta.java_lang_InstantiationException);
    }
    Method reflectedMethod = Method.getHostReflectiveConstructorRoot(constructor, meta);
    StaticObject instance = klass.allocateInstance();
    StaticObject parameterTypes = meta.java_lang_reflect_Constructor_parameterTypes.getObject(constructor);
    Target_sun_reflect_NativeMethodAccessorImpl.callMethodReflectively(meta, instance, args0, reflectedMethod, klass, parameterTypes);
    return instance;
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) 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