hotspot/test/runtime/8003720/Asmator.java
author stefank
Tue, 27 Nov 2012 10:13:20 +0100
changeset 14582 490bb6c0df7c
child 14589 a6649fc2f41d
permissions -rw-r--r--
8003720: NPG: Method in interpreter stack frame can be deallocated Summary: Pass down a closure during root scanning to keep the class of the method alive. Reviewed-by: coleenp, jcoomes

import com.sun.xml.internal.ws.org.objectweb.asm.*;

class Asmator {
    static byte[] fixup(byte[] buf) throws java.io.IOException {
        ClassReader cr = new ClassReader(buf);
        ClassWriter cw = new ClassWriter(0) {
            public MethodVisitor visitMethod(
                final int access,
                final String name,
                final String desc,
                final String signature,
                final String[] exceptions)
            {
                MethodVisitor mv = super.visitMethod(access,
                        name,
                        desc,
                        signature,
                        exceptions);
                if (mv == null)  return null;
                if (name.equals("callme")) {
                    // make receiver go dead!
                    mv.visitInsn(Opcodes.ACONST_NULL);
                    mv.visitVarInsn(Opcodes.ASTORE, 0);
                }
                return mv;
            }
        };
        cr.accept(cw, 0);
        return cw.toByteArray();
    }
}