Search in sources :

Example 11 with RuntimeConstantPool

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

the class ObjectKlass method permittedSubclassCheck.

public boolean permittedSubclassCheck(ObjectKlass k) {
    CompilerAsserts.neverPartOfCompilation();
    if (!getContext().getJavaVersion().java17OrLater()) {
        return true;
    }
    PermittedSubclassesAttribute permittedSubclasses = (PermittedSubclassesAttribute) getAttribute(PermittedSubclassesAttribute.NAME);
    if (permittedSubclasses == null) {
        return true;
    }
    if (module() != k.module()) {
        return false;
    }
    if (!isPublic() && !sameRuntimePackage(k)) {
        return false;
    }
    RuntimeConstantPool pool = getConstantPool();
    for (int index : permittedSubclasses.getClasses()) {
        if (k.getName().equals(pool.classAt(index).getName(pool))) {
            // resolve to k, but resolving here would cause circularity errors.
            return true;
        }
    }
    return false;
}
Also used : RuntimeConstantPool(com.oracle.truffle.espresso.classfile.RuntimeConstantPool) PermittedSubclassesAttribute(com.oracle.truffle.espresso.classfile.attributes.PermittedSubclassesAttribute)

Example 12 with RuntimeConstantPool

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

the class ObjectKlass method nest.

@Override
public Klass nest() {
    if (nest == null) {
        CompilerDirectives.transferToInterpreterAndInvalidate();
        NestHostAttribute nestHost = (NestHostAttribute) getAttribute(NestHostAttribute.NAME);
        if (nestHost == null) {
            nest = this;
        } else {
            RuntimeConstantPool thisPool = getConstantPool();
            Klass host = thisPool.resolvedKlassAt(this, nestHost.hostClassIndex);
            if (!host.nestMembersCheck(this)) {
                Meta meta = getMeta();
                throw meta.throwException(meta.java_lang_IncompatibleClassChangeError);
            }
            nest = host;
        }
    }
    return nest;
}
Also used : NestHostAttribute(com.oracle.truffle.espresso.classfile.attributes.NestHostAttribute) Meta(com.oracle.truffle.espresso.meta.Meta) RuntimeConstantPool(com.oracle.truffle.espresso.classfile.RuntimeConstantPool)

Example 13 with RuntimeConstantPool

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

the class ObjectKlass method redefineClass.

public void redefineClass(ChangePacket packet, List<ObjectKlass> invalidatedClasses, Ids<Object> ids) {
    DetectedChange change = packet.detectedChange;
    if (change.isChangedSuperClass()) {
        // within this class.
        if (getDeclaredFields().length > 0) {
            ExtensionFieldsMetadata extension = getExtensionFieldsMetadata(true);
            for (Field declaredField : getDeclaredFields()) {
                if (!declaredField.isStatic()) {
                    declaredField.removeByRedefintion();
                    int nextFieldSlot = getContext().getClassRedefinition().getNextAvailableFieldSlot();
                    LinkedField.IdMode mode = LinkedKlassFieldLayout.getIdMode(getLinkedKlass().getParserKlass());
                    LinkedField linkedField = new LinkedField(declaredField.linkedField.getParserField(), nextFieldSlot, mode);
                    Field field = new RedefineAddedField(getKlassVersion(), linkedField, getConstantPool(), false);
                    extension.addNewInstanceField(field);
                }
            }
        }
    }
    if (packet.parserKlass == null) {
        // no further changes
        return;
    }
    ParserKlass parserKlass = packet.parserKlass;
    KlassVersion oldVersion = klassVersion;
    LinkedKlass oldLinkedKlass = oldVersion.linkedKlass;
    RuntimeConstantPool pool = new RuntimeConstantPool(getContext(), parserKlass.getConstantPool(), oldVersion.pool.getClassLoader());
    // class structure
    ObjectKlass[] superInterfaces = change.getSuperInterfaces();
    LinkedKlass[] interfaces = new LinkedKlass[superInterfaces.length];
    for (int i = 0; i < superInterfaces.length; i++) {
        interfaces[i] = superInterfaces[i].getLinkedKlass();
    }
    LinkedKlass linkedKlass;
    if (Modifier.isInterface(change.getSuperKlass().getModifiers())) {
        linkedKlass = LinkedKlass.redefine(parserKlass, null, interfaces, oldLinkedKlass);
    } else {
        linkedKlass = LinkedKlass.redefine(parserKlass, change.getSuperKlass().getLinkedKlass(), interfaces, oldLinkedKlass);
    }
    klassVersion = new KlassVersion(oldVersion, pool, linkedKlass, packet, invalidatedClasses, ids);
    // fields
    if (!change.getAddedStaticFields().isEmpty() || !change.getAddedInstanceFields().isEmpty()) {
        Map<ParserField, Field> compatibleFields = change.getMappedCompatibleFields();
        ExtensionFieldsMetadata extension = getExtensionFieldsMetadata(true);
        // add new fields to the extension object
        extension.addNewStaticFields(klassVersion, change.getAddedStaticFields(), pool, compatibleFields, getContext().getClassRedefinition());
        extension.addNewInstanceFields(klassVersion, change.getAddedInstanceFields(), pool, compatibleFields, getContext().getClassRedefinition());
        // make sure all new fields trigger re-resolution of fields
        // with same name + type in the full class hierarchy
        markForReResolution(change.getAddedStaticFields(), invalidatedClasses);
        markForReResolution(change.getAddedInstanceFields(), invalidatedClasses);
    }
    for (Field removedField : change.getRemovedFields()) {
        removedField.removeByRedefintion();
    }
    incrementKlassRedefinitionCount();
    oldVersion.assumption.invalidate();
}
Also used : DetectedChange(com.oracle.truffle.espresso.redefinition.DetectedChange) RuntimeConstantPool(com.oracle.truffle.espresso.classfile.RuntimeConstantPool)

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