Search in sources :

Example 21 with StaticObject

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

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

the class JniEnv method NewObjectVarargs.

@JniImpl
@JavaType(Object.class)
public StaticObject NewObjectVarargs(@JavaType(Class.class) StaticObject clazz, @Handle(Method.class) long methodId, @Pointer TruffleObject varargsPtr) {
    Method method = methodIds.getObject(methodId);
    assert method.isConstructor();
    Klass klass = clazz.getMirrorKlass();
    if (klass.isInterface() || klass.isAbstract()) {
        Meta meta = getMeta();
        throw meta.throwException(meta.java_lang_InstantiationException);
    }
    klass.initialize();
    StaticObject instance;
    if (CompilerDirectives.isPartialEvaluationConstant(klass)) {
        instance = klass.allocateInstance();
    } else {
        instance = allocateBoundary(klass);
    }
    method.invokeDirect(instance, popVarArgs(varargsPtr, method.getParsedSignature()));
    return instance;
}
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) Method(com.oracle.truffle.espresso.impl.Method) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 23 with StaticObject

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

the class JniEnv method ToReflectedField.

/**
 * <h3>jobject ToReflectedField(JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic);
 * </h3>
 * <p>
 * Converts a field ID derived from cls to a java.lang.reflect.Field object. isStatic must be
 * set to JNI_TRUE if fieldID refers to a static field, and JNI_FALSE otherwise.
 * <p>
 * Throws OutOfMemoryError and returns 0 if fails.
 */
@JniImpl
@JavaType(java.lang.reflect.Field.class)
public StaticObject ToReflectedField(@JavaType(Class.class) StaticObject unused, @Handle(Field.class) long fieldId, @SuppressWarnings("unused") boolean isStatic) {
    Field field = fieldIds.getObject(fieldId);
    assert field.getDeclaringKlass().isAssignableFrom(unused.getMirrorKlass());
    StaticObject fields = getVM().JVM_GetClassDeclaredFields(field.getDeclaringKlass().mirror(), false);
    for (StaticObject declField : fields.<StaticObject[]>unwrap()) {
        assert InterpreterToVM.instanceOf(declField, getMeta().java_lang_reflect_Field);
        Field f = (Field) getMeta().HIDDEN_FIELD_KEY.getHiddenObject(declField);
        if (field == f) {
            return declField;
        }
    }
    throw EspressoError.shouldNotReachHere("Field not found ", field);
}
Also used : Field(com.oracle.truffle.espresso.impl.Field) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 24 with StaticObject

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

the class JniEnv method CallNonvirtualDoubleMethodVarargs.

@JniImpl
public double CallNonvirtualDoubleMethodVarargs(@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().asDouble(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 25 with StaticObject

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

the class ClassRegistry method loadKlass.

/**
 * Queries a registry to load a Klass for us.
 *
 * @param type the symbolic reference to the Klass we want to load
 * @param protectionDomain The protection domain extracted from the guest class, or
 *            {@link StaticObject#NULL} if trusted.
 * @return The Klass corresponding to given type
 */
@SuppressWarnings("try")
Klass loadKlass(Symbol<Type> type, StaticObject protectionDomain) {
    if (Types.isArray(type)) {
        Klass elemental = loadKlass(getTypes().getElementalType(type), protectionDomain);
        if (elemental == null) {
            return null;
        }
        return elemental.getArrayClass(Types.getArrayDimensions(type));
    }
    loadKlassCountInc();
    // Double-checked locking on the symbol (globally unique).
    ClassRegistries.RegistryEntry entry;
    try (DebugCloseable probe = KLASS_PROBE.scope(getContext().getTimers())) {
        entry = classes.get(type);
    }
    if (entry == null) {
        synchronized (type) {
            entry = classes.get(type);
            if (entry == null) {
                if (loadKlassImpl(type) == null) {
                    return null;
                }
                entry = classes.get(type);
            }
        }
    } else {
        // Grabbing a lock to fetch the class is not considered a hit.
        loadKlassCacheHitsInc();
    }
    assert entry != null;
    StaticObject classLoader = getClassLoader();
    if (!StaticObject.isNull(classLoader)) {
        entry.checkPackageAccess(getMeta(), classLoader, protectionDomain);
    }
    return entry.klass();
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) DebugCloseable(com.oracle.truffle.espresso.perf.DebugCloseable)

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