Search in sources :

Example 1 with HotSwapClassInfo

use of com.oracle.truffle.espresso.redefinition.HotSwapClassInfo in project graal by oracle.

the class JDWPContextImpl method doRedefine.

private void doRedefine(List<RedefineInfo> redefineInfos, List<ObjectKlass> changedKlasses) throws RedefintionNotSupportedException {
    // list to hold removed inner classes that must be marked removed
    List<ObjectKlass> removedInnerClasses = new ArrayList<>(0);
    // list of classes that need to refresh due to
    // changes in other classes for things like vtable
    List<ObjectKlass> invalidatedClasses = new ArrayList<>();
    // list of all classes that have been redefined within this transaction
    List<ObjectKlass> redefinedClasses = new ArrayList<>();
    // match anon inner classes with previous state
    HotSwapClassInfo[] matchedInfos = innerClassRedefiner.matchAnonymousInnerClasses(redefineInfos, removedInnerClasses);
    // detect all changes to all classes, throws if redefinition cannot be completed
    // due to the nature of the changes
    List<ChangePacket> changePackets = classRedefinition.detectClassChanges(matchedInfos);
    // We have to redefine super classes prior to subclasses
    Collections.sort(changePackets, new HierarchyComparator());
    for (ChangePacket packet : changePackets) {
        JDWP.LOGGER.fine(() -> "Redefining class " + packet.info.getNewName());
        int result = classRedefinition.redefineClass(packet, invalidatedClasses, redefinedClasses);
        if (result != 0) {
            throw new RedefintionNotSupportedException(result);
        }
    }
    // refresh invalidated classes if not already redefined
    Collections.sort(invalidatedClasses, new SubClassHierarchyComparator());
    for (ObjectKlass invalidatedClass : invalidatedClasses) {
        if (!redefinedClasses.contains(invalidatedClass)) {
            JDWP.LOGGER.fine(() -> "Updating invalidated class " + invalidatedClass.getName());
            invalidatedClass.swapKlassVersion(ids);
        }
    }
    // include invalidated classes in all changed classes list
    changedKlasses.addAll(invalidatedClasses);
    // update the JWDP IDs for renamed inner classes
    for (ChangePacket changePacket : changePackets) {
        ObjectKlass klass = changePacket.info.getKlass();
        changedKlasses.add(klass);
        if (changePacket.info.isRenamed()) {
            if (klass != null) {
                ids.updateId(klass);
            }
        }
    }
    // tell the InnerClassRedefiner to commit the changes to cache
    innerClassRedefiner.commit(matchedInfos);
    for (ObjectKlass removed : removedInnerClasses) {
        removed.removeByRedefinition();
    }
}
Also used : ChangePacket(com.oracle.truffle.espresso.redefinition.ChangePacket) ArrayList(java.util.ArrayList) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) HotSwapClassInfo(com.oracle.truffle.espresso.redefinition.HotSwapClassInfo) RedefintionNotSupportedException(com.oracle.truffle.espresso.redefinition.RedefintionNotSupportedException)

Aggregations

ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)1 ChangePacket (com.oracle.truffle.espresso.redefinition.ChangePacket)1 HotSwapClassInfo (com.oracle.truffle.espresso.redefinition.HotSwapClassInfo)1 RedefintionNotSupportedException (com.oracle.truffle.espresso.redefinition.RedefintionNotSupportedException)1 ArrayList (java.util.ArrayList)1