Search in sources :

Example 1 with SignatureAttribute

use of com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute in project graal by oracle.

the class Method method makeMirror.

public StaticObject makeMirror() {
    Meta meta = getMeta();
    Attribute rawRuntimeVisibleAnnotations = getAttribute(Name.RuntimeVisibleAnnotations);
    StaticObject runtimeVisibleAnnotations = rawRuntimeVisibleAnnotations != null ? StaticObject.wrap(rawRuntimeVisibleAnnotations.getData(), meta) : StaticObject.NULL;
    Attribute rawRuntimeVisibleParameterAnnotations = getAttribute(Name.RuntimeVisibleParameterAnnotations);
    StaticObject runtimeVisibleParameterAnnotations = rawRuntimeVisibleParameterAnnotations != null ? StaticObject.wrap(rawRuntimeVisibleParameterAnnotations.getData(), meta) : StaticObject.NULL;
    Attribute rawRuntimeVisibleTypeAnnotations = getAttribute(Name.RuntimeVisibleTypeAnnotations);
    StaticObject runtimeVisibleTypeAnnotations = rawRuntimeVisibleTypeAnnotations != null ? StaticObject.wrap(rawRuntimeVisibleTypeAnnotations.getData(), meta) : StaticObject.NULL;
    Attribute rawAnnotationDefault = getAttribute(Name.AnnotationDefault);
    StaticObject annotationDefault = rawAnnotationDefault != null ? StaticObject.wrap(rawAnnotationDefault.getData(), meta) : StaticObject.NULL;
    final Klass[] rawParameterKlasses = resolveParameterKlasses();
    StaticObject parameterTypes = meta.java_lang_Class.allocateReferenceArray(getParameterCount(), new IntFunction<StaticObject>() {

        @Override
        public StaticObject apply(int j) {
            return rawParameterKlasses[j].mirror();
        }
    });
    final Klass[] rawCheckedExceptions = getCheckedExceptions();
    StaticObject guestCheckedExceptions = meta.java_lang_Class.allocateReferenceArray(rawCheckedExceptions.length, new IntFunction<StaticObject>() {

        @Override
        public StaticObject apply(int j) {
            return rawCheckedExceptions[j].mirror();
        }
    });
    SignatureAttribute signatureAttribute = (SignatureAttribute) getAttribute(Name.Signature);
    StaticObject guestGenericSignature = StaticObject.NULL;
    if (signatureAttribute != null) {
        String sig = getConstantPool().symbolAt(signatureAttribute.getSignatureIndex(), "signature").toString();
        guestGenericSignature = meta.toGuestString(sig);
    }
    StaticObject instance = meta.java_lang_reflect_Method.allocateInstance();
    meta.java_lang_reflect_Method_init.invokeDirect(/* this */
    instance, /* declaringClass */
    getDeclaringKlass().mirror(), /* name */
    getContext().getStrings().intern(getName()), /* parameterTypes */
    parameterTypes, /* returnType */
    resolveReturnKlass().mirror(), /* checkedExceptions */
    guestCheckedExceptions, /* modifiers */
    getMethodModifiers(), /* slot */
    getVTableIndex(), /* signature */
    guestGenericSignature, /* annotations */
    runtimeVisibleAnnotations, /* parameterAnnotations */
    runtimeVisibleParameterAnnotations, /* annotationDefault */
    annotationDefault);
    meta.HIDDEN_METHOD_KEY.setHiddenObject(instance, this);
    meta.HIDDEN_METHOD_RUNTIME_VISIBLE_TYPE_ANNOTATIONS.setHiddenObject(instance, runtimeVisibleTypeAnnotations);
    return instance;
}
Also used : SignatureAttribute(com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute) Meta(com.oracle.truffle.espresso.meta.Meta) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) BootstrapMethodsAttribute(com.oracle.truffle.espresso.classfile.attributes.BootstrapMethodsAttribute) SourceFileAttribute(com.oracle.truffle.espresso.classfile.attributes.SourceFileAttribute) LineNumberTableAttribute(com.oracle.truffle.espresso.classfile.attributes.LineNumberTableAttribute) ExceptionsAttribute(com.oracle.truffle.espresso.classfile.attributes.ExceptionsAttribute) CodeAttribute(com.oracle.truffle.espresso.classfile.attributes.CodeAttribute) Attribute(com.oracle.truffle.espresso.runtime.Attribute) SignatureAttribute(com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute)

Example 2 with SignatureAttribute

use of com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute in project graal by oracle.

the class VM method JVM_GetClassSignature.

@VmImpl(isJni = true)
@JavaType(String.class)
public StaticObject JVM_GetClassSignature(@JavaType(Class.class) StaticObject self) {
    if (self.getMirrorKlass() instanceof ObjectKlass) {
        ObjectKlass klass = (ObjectKlass) self.getMirrorKlass();
        SignatureAttribute signature = (SignatureAttribute) klass.getAttribute(Name.Signature);
        if (signature != null) {
            String sig = klass.getConstantPool().symbolAt(signature.getSignatureIndex(), "signature").toString();
            return getMeta().toGuestString(sig);
        }
    }
    return StaticObject.NULL;
}
Also used : SignatureAttribute(com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 3 with SignatureAttribute

use of com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute in project graal by oracle.

the class VM method JVM_GetClassDeclaredConstructors.

// TODO(tg): inject constructor calltarget.
@VmImpl(isJni = true)
@JavaType(Constructor[].class)
public StaticObject JVM_GetClassDeclaredConstructors(@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.getDeclaredConstructors()) {
        if (Name._init_.equals(m.getName()) && (!publicOnly || m.isPublic())) {
            collectedMethods.add(m);
        }
    }
    final Method[] constructors = collectedMethods.toArray(Method.EMPTY_ARRAY);
    EspressoContext context = meta.getContext();
    // TODO(peterssen): Cache guest j.l.reflect.Constructor constructor.
    // Calling the constructor is just for validation, manually setting the fields would be
    // faster.
    Method constructorInit = meta.java_lang_reflect_Constructor.lookupDeclaredMethod(Name._init_, context.getSignatures().makeRaw(Type._void, /* declaringClass */
    Type.java_lang_Class, /* parameterTypes */
    Type.java_lang_Class_array, /* checkedExceptions */
    Type.java_lang_Class_array, /* modifiers */
    Type._int, /* slot */
    Type._int, /* signature */
    Type.java_lang_String, /* annotations */
    Type._byte_array, /* parameterAnnotations */
    Type._byte_array));
    StaticObject arr = meta.java_lang_reflect_Constructor.allocateReferenceArray(constructors.length, new IntFunction<StaticObject>() {

        @Override
        public StaticObject apply(int i) {
            final Method m = constructors[i];
            Attribute rawRuntimeVisibleAnnotations = m.getAttribute(Name.RuntimeVisibleAnnotations);
            StaticObject runtimeVisibleAnnotations = rawRuntimeVisibleAnnotations != null ? StaticObject.wrap(rawRuntimeVisibleAnnotations.getData(), meta) : StaticObject.NULL;
            Attribute rawRuntimeVisibleParameterAnnotations = m.getAttribute(Name.RuntimeVisibleParameterAnnotations);
            StaticObject runtimeVisibleParameterAnnotations = rawRuntimeVisibleParameterAnnotations != null ? StaticObject.wrap(rawRuntimeVisibleParameterAnnotations.getData(), meta) : StaticObject.NULL;
            Attribute rawRuntimeVisibleTypeAnnotations = m.getAttribute(Name.RuntimeVisibleTypeAnnotations);
            StaticObject runtimeVisibleTypeAnnotations = rawRuntimeVisibleTypeAnnotations != null ? StaticObject.wrap(rawRuntimeVisibleTypeAnnotations.getData(), meta) : StaticObject.NULL;
            final Klass[] rawParameterKlasses = m.resolveParameterKlasses();
            StaticObject parameterTypes = meta.java_lang_Class.allocateReferenceArray(m.getParameterCount(), new IntFunction<StaticObject>() {

                @Override
                public StaticObject apply(int j) {
                    return rawParameterKlasses[j].mirror();
                }
            });
            final Klass[] rawCheckedExceptions = m.getCheckedExceptions();
            StaticObject checkedExceptions = meta.java_lang_Class.allocateReferenceArray(rawCheckedExceptions.length, new IntFunction<StaticObject>() {

                @Override
                public StaticObject apply(int j) {
                    return rawCheckedExceptions[j].mirror();
                }
            });
            SignatureAttribute signatureAttribute = (SignatureAttribute) m.getAttribute(Name.Signature);
            StaticObject genericSignature = StaticObject.NULL;
            if (signatureAttribute != null) {
                String sig = m.getConstantPool().symbolAt(signatureAttribute.getSignatureIndex(), "signature").toString();
                genericSignature = meta.toGuestString(sig);
            }
            StaticObject instance = meta.java_lang_reflect_Constructor.allocateInstance();
            constructorInit.invokeDirect(/* this */
            instance, /* declaringKlass */
            m.getDeclaringKlass().mirror(), /* parameterTypes */
            parameterTypes, /* checkedExceptions */
            checkedExceptions, /* modifiers */
            m.getMethodModifiers(), // TODO(peterssen): Fill method slot.
            i, /* signature */
            genericSignature, /* annotations */
            runtimeVisibleAnnotations, /* parameterAnnotations */
            runtimeVisibleParameterAnnotations);
            meta.HIDDEN_CONSTRUCTOR_KEY.setHiddenObject(instance, m);
            meta.HIDDEN_CONSTRUCTOR_RUNTIME_VISIBLE_TYPE_ANNOTATIONS.setHiddenObject(instance, runtimeVisibleTypeAnnotations);
            return instance;
        }
    });
    return arr;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) PermittedSubclassesAttribute(com.oracle.truffle.espresso.classfile.attributes.PermittedSubclassesAttribute) MethodParametersAttribute(com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute) EnclosingMethodAttribute(com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute) Attribute(com.oracle.truffle.espresso.runtime.Attribute) InnerClassesAttribute(com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute) RecordAttribute(com.oracle.truffle.espresso.classfile.attributes.RecordAttribute) SignatureAttribute(com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute) ArrayList(java.util.ArrayList) EspressoContext(com.oracle.truffle.espresso.runtime.EspressoContext) Method(com.oracle.truffle.espresso.impl.Method) NoSafepoint(com.oracle.truffle.espresso.jni.NoSafepoint) SignatureAttribute(com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute) 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) IntFunction(java.util.function.IntFunction) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Aggregations

SignatureAttribute (com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute)3 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)2 Meta (com.oracle.truffle.espresso.meta.Meta)2 Attribute (com.oracle.truffle.espresso.runtime.Attribute)2 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)2 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)2 BootstrapMethodsAttribute (com.oracle.truffle.espresso.classfile.attributes.BootstrapMethodsAttribute)1 CodeAttribute (com.oracle.truffle.espresso.classfile.attributes.CodeAttribute)1 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)1 ExceptionsAttribute (com.oracle.truffle.espresso.classfile.attributes.ExceptionsAttribute)1 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)1 LineNumberTableAttribute (com.oracle.truffle.espresso.classfile.attributes.LineNumberTableAttribute)1 MethodParametersAttribute (com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute)1 PermittedSubclassesAttribute (com.oracle.truffle.espresso.classfile.attributes.PermittedSubclassesAttribute)1 RecordAttribute (com.oracle.truffle.espresso.classfile.attributes.RecordAttribute)1 SourceFileAttribute (com.oracle.truffle.espresso.classfile.attributes.SourceFileAttribute)1 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)1 Klass (com.oracle.truffle.espresso.impl.Klass)1 Method (com.oracle.truffle.espresso.impl.Method)1 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)1