Search in sources :

Example 1 with RuntimeConstantPool

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

the class Method method redefine.

public SharedRedefinitionContent redefine(ObjectKlass.KlassVersion klassVersion, ParserMethod newMethod, ParserKlass newKlass, Ids<Object> ids) {
    // install the new method version immediately
    LinkedMethod newLinkedMethod = new LinkedMethod(newMethod);
    RuntimeConstantPool runtimePool = new RuntimeConstantPool(getContext(), newKlass.getConstantPool(), getDeclaringKlass().getDefiningClassLoader());
    CodeAttribute newCodeAttribute = (CodeAttribute) newMethod.getAttribute(Name.Code);
    MethodVersion oldVersion = methodVersion;
    methodVersion = oldVersion.replace(klassVersion, runtimePool, newLinkedMethod, newCodeAttribute);
    ids.replaceObject(oldVersion, methodVersion);
    return new SharedRedefinitionContent(newLinkedMethod, runtimePool, newCodeAttribute);
}
Also used : RuntimeConstantPool(com.oracle.truffle.espresso.classfile.RuntimeConstantPool) CodeAttribute(com.oracle.truffle.espresso.classfile.attributes.CodeAttribute)

Example 2 with RuntimeConstantPool

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

the class ObjectKlass method getNestMembers.

@Override
public Klass[] getNestMembers() {
    if (this != nest()) {
        return nest().getNestMembers();
    }
    NestMembersAttribute nestMembers = (NestMembersAttribute) getAttribute(NestMembersAttribute.NAME);
    if (nestMembers == null || nestMembers.getClasses().length == 0) {
        return new Klass[] { nest() };
    }
    RuntimeConstantPool pool = getConstantPool();
    ArrayList<Klass> klasses = new ArrayList<>(1 + nestMembers.getClasses().length);
    klasses.add(nest());
    for (int i = 0; i < nestMembers.getClasses().length; i++) {
        int index = nestMembers.getClasses()[i];
        try {
            klasses.add(pool.resolvedKlassAt(this, index));
        } catch (EspressoException e) {
        /*
                 * Don't allow badly constructed nest members to break execution here, only report
                 * well-constructed entries.
                 */
        }
    }
    return klasses.toArray(Klass.EMPTY_ARRAY);
}
Also used : RuntimeConstantPool(com.oracle.truffle.espresso.classfile.RuntimeConstantPool) EspressoException(com.oracle.truffle.espresso.runtime.EspressoException) ArrayList(java.util.ArrayList) NestMembersAttribute(com.oracle.truffle.espresso.classfile.attributes.NestMembersAttribute)

Example 3 with RuntimeConstantPool

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

the class ObjectKlass method nestMembersCheck.

@Override
public boolean nestMembersCheck(Klass k) {
    NestMembersAttribute nestMembers = (NestMembersAttribute) getAttribute(NestMembersAttribute.NAME);
    if (nestMembers == null) {
        return false;
    }
    if (!this.sameRuntimePackage(k)) {
        return false;
    }
    RuntimeConstantPool pool = getConstantPool();
    for (int index : nestMembers.getClasses()) {
        if (k.getName().equals(pool.classAt(index).getName(pool))) {
            if (k == pool.resolvedKlassAt(this, index)) {
                return true;
            }
        }
    }
    return false;
}
Also used : RuntimeConstantPool(com.oracle.truffle.espresso.classfile.RuntimeConstantPool) NestMembersAttribute(com.oracle.truffle.espresso.classfile.attributes.NestMembersAttribute)

Example 4 with RuntimeConstantPool

use of com.oracle.truffle.espresso.classfile.RuntimeConstantPool 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 5 with RuntimeConstantPool

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

the class VM method JVM_GetEnclosingMethodInfo.

@VmImpl(isJni = true)
@JavaType(Object[].class)
public StaticObject JVM_GetEnclosingMethodInfo(@JavaType(Class.class) StaticObject self) {
    Meta meta = getMeta();
    InterpreterToVM vm = meta.getInterpreterToVM();
    if (self.getMirrorKlass() instanceof ObjectKlass) {
        ObjectKlass klass = (ObjectKlass) self.getMirrorKlass();
        EnclosingMethodAttribute enclosingMethodAttr = klass.getEnclosingMethod();
        if (enclosingMethodAttr == null) {
            return StaticObject.NULL;
        }
        int classIndex = enclosingMethodAttr.getClassIndex();
        if (classIndex == 0) {
            return StaticObject.NULL;
        }
        StaticObject arr = meta.java_lang_Object.allocateReferenceArray(3);
        RuntimeConstantPool pool = klass.getConstantPool();
        Klass enclosingKlass = pool.resolvedKlassAt(klass, classIndex);
        vm.setArrayObject(enclosingKlass.mirror(), 0, arr);
        int methodIndex = enclosingMethodAttr.getMethodIndex();
        if (methodIndex != 0) {
            NameAndTypeConstant nmt = pool.nameAndTypeAt(methodIndex);
            StaticObject name = meta.toGuestString(nmt.getName(pool));
            StaticObject desc = meta.toGuestString(nmt.getDescriptor(pool));
            vm.setArrayObject(name, 1, arr);
            vm.setArrayObject(desc, 2, arr);
        }
        return arr;
    }
    return StaticObject.NULL;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) RuntimeConstantPool(com.oracle.truffle.espresso.classfile.RuntimeConstantPool) 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) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) NameAndTypeConstant(com.oracle.truffle.espresso.classfile.constantpool.NameAndTypeConstant) NoSafepoint(com.oracle.truffle.espresso.jni.NoSafepoint) EnclosingMethodAttribute(com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Aggregations

RuntimeConstantPool (com.oracle.truffle.espresso.classfile.RuntimeConstantPool)13 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)6 Klass (com.oracle.truffle.espresso.impl.Klass)6 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)5 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)4 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)4 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)4 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)3 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)3 Meta (com.oracle.truffle.espresso.meta.Meta)3 NestMembersAttribute (com.oracle.truffle.espresso.classfile.attributes.NestMembersAttribute)2 PermittedSubclassesAttribute (com.oracle.truffle.espresso.classfile.attributes.PermittedSubclassesAttribute)2 InvokeDynamicConstant (com.oracle.truffle.espresso.classfile.constantpool.InvokeDynamicConstant)2 EspressoException (com.oracle.truffle.espresso.runtime.EspressoException)2 ArrayList (java.util.ArrayList)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)1 CodeAttribute (com.oracle.truffle.espresso.classfile.attributes.CodeAttribute)1 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)1 NestHostAttribute (com.oracle.truffle.espresso.classfile.attributes.NestHostAttribute)1