Search in sources :

Example 1 with ObjectKlass

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

the class InvokeInterface method methodLookup.

static Method.MethodVersion methodLookup(Method resolutionSeed, Klass receiverKlass) {
    assert !receiverKlass.isArray();
    if (resolutionSeed.isRemovedByRedefition()) {
        /*
             * Accept a slow path once the method has been removed put method behind a boundary to
             * avoid a deopt loop
             */
        return resolutionSeed.getContext().getClassRedefinition().handleRemovedMethod(resolutionSeed, receiverKlass).getMethodVersion();
    }
    int iTableIndex = resolutionSeed.getITableIndex();
    Method method = ((ObjectKlass) receiverKlass).itableLookup(resolutionSeed.getDeclaringKlass(), iTableIndex);
    if (!method.isPublic()) {
        transferToInterpreterAndInvalidate();
        Meta meta = receiverKlass.getMeta();
        throw meta.throwException(meta.java_lang_IllegalAccessError);
    }
    return method.getMethodVersion();
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) Method(com.oracle.truffle.espresso.impl.Method)

Example 2 with ObjectKlass

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

the class DefaultClassHierarchyOracle method addImplementor.

/**
 * Recursively adds {@code implementor} as an implementor of {@code superInterface} and its
 * parent interfaces.
 */
private void addImplementor(ObjectKlass superInterface, ObjectKlass.KlassVersion implementor) {
    superInterface.getNoConcreteSubclassesAssumption(ClassHierarchyAccessor.accessor).getAssumption().invalidate();
    superInterface.getImplementor(ClassHierarchyAccessor.accessor).addImplementor(implementor);
    for (ObjectKlass ancestorInterface : superInterface.getSuperInterfaces()) {
        addImplementor(ancestorInterface, implementor);
    }
}
Also used : ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass)

Example 3 with ObjectKlass

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

the class DefaultClassHierarchyOracle method addImplementorToAncestors.

private void addImplementorToAncestors(ObjectKlass.KlassVersion newKlass) {
    for (ObjectKlass superInterface : newKlass.getSuperInterfaces()) {
        addImplementor(superInterface, newKlass);
    }
    ObjectKlass currentKlass = newKlass.getSuperKlass();
    while (currentKlass != null) {
        currentKlass.getNoConcreteSubclassesAssumption(ClassHierarchyAccessor.accessor).getAssumption().invalidate();
        currentKlass.getImplementor(ClassHierarchyAccessor.accessor).addImplementor(newKlass);
        for (ObjectKlass superInterface : currentKlass.getSuperInterfaces()) {
            addImplementor(superInterface, newKlass);
        }
        currentKlass = currentKlass.getSuperKlass();
    }
}
Also used : ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass)

Example 4 with ObjectKlass

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

the class VM method JVM_LookupDefineClass.

@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(Class.class)
public StaticObject JVM_LookupDefineClass(@JavaType(Class.class) StaticObject lookup, @Pointer TruffleObject namePtr, @Pointer TruffleObject bufPtr, int len, @JavaType(ProtectionDomain.class) StaticObject pd, boolean initialize, int flags, @JavaType(Object.class) StaticObject classData) {
    if (StaticObject.isNull(lookup)) {
        throw getMeta().throwExceptionWithMessage(getMeta().java_lang_InternalError, "Lookup class is null");
    }
    assert !getUncached().isNull(bufPtr);
    assert lookup.getMirrorKlass() instanceof ObjectKlass;
    boolean isNestMate = (flags & NESTMATE_CLASS) == NESTMATE_CLASS;
    boolean isHidden = (flags & HIDDEN_CLASS) == HIDDEN_CLASS;
    boolean isStrong = (flags & STRONG_LOADER_LINK) == STRONG_LOADER_LINK;
    boolean vmAnnotations = (flags & ACCESS_VM_ANNOTATIONS) == ACCESS_VM_ANNOTATIONS;
    ObjectKlass nest = null;
    if (isNestMate) {
        nest = (ObjectKlass) lookup.getMirrorKlass().nest();
    }
    if (!isHidden) {
        if (!StaticObject.isNull(classData)) {
            throw getMeta().throwExceptionWithMessage(getMeta().java_lang_IllegalArgumentException, "classData is only applicable for hidden classes");
        }
        if (isNestMate) {
            throw getMeta().throwExceptionWithMessage(getMeta().java_lang_IllegalArgumentException, "dynamic nestmate is only applicable for hidden classes");
        }
        if (!isStrong) {
            throw getMeta().throwExceptionWithMessage(getMeta().java_lang_IllegalArgumentException, "an ordinary class must be strongly referenced by its defining loader");
        }
        if (vmAnnotations) {
            throw getMeta().throwExceptionWithMessage(getMeta().java_lang_IllegalArgumentException, "vm annotations only allowed for hidden classes");
        }
        if (flags != STRONG_LOADER_LINK) {
            throw getMeta().throwExceptionWithMessage(getMeta().java_lang_IllegalArgumentException, String.format("invalid flag 0x%x", flags));
        }
    }
    ByteBuffer buf = NativeUtils.directByteBuffer(bufPtr, len, JavaKind.Byte);
    final byte[] bytes = new byte[len];
    buf.get(bytes);
    // can be null
    Symbol<Type> type = namePtrToInternal(namePtr);
    StaticObject loader = lookup.getMirrorKlass().getDefiningClassLoader();
    ObjectKlass k;
    if (isHidden) {
        // Special handling
        k = getRegistries().defineKlass(type, bytes, loader, new ClassRegistry.ClassDefinitionInfo(pd, nest, classData, isStrong));
    } else {
        k = getRegistries().defineKlass(type, bytes, loader, new ClassRegistry.ClassDefinitionInfo(pd));
    }
    if (initialize) {
        k.safeInitialize();
    } else {
        k.ensureLinked();
    }
    return k.mirror();
}
Also used : NativeType(com.oracle.truffle.espresso.ffi.NativeType) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ByteBuffer(java.nio.ByteBuffer) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 5 with ObjectKlass

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

Aggregations

ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)35 Klass (com.oracle.truffle.espresso.impl.Klass)15 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)12 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)10 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)9 ArrayList (java.util.ArrayList)8 Method (com.oracle.truffle.espresso.impl.Method)7 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)6 RuntimeConstantPool (com.oracle.truffle.espresso.classfile.RuntimeConstantPool)5 Field (com.oracle.truffle.espresso.impl.Field)5 ParserKlass (com.oracle.truffle.espresso.impl.ParserKlass)5 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)5 Symbol (com.oracle.truffle.espresso.descriptors.Symbol)4 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)4 ClassRegistry (com.oracle.truffle.espresso.impl.ClassRegistry)4 Meta (com.oracle.truffle.espresso.meta.Meta)4 Matcher (java.util.regex.Matcher)4 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)3 EspressoException (com.oracle.truffle.espresso.runtime.EspressoException)3 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)2