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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14582
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
     1
import com.sun.xml.internal.ws.org.objectweb.asm.*;
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
     2
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
     3
class Asmator {
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
     4
    static byte[] fixup(byte[] buf) throws java.io.IOException {
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
     5
        ClassReader cr = new ClassReader(buf);
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
     6
        ClassWriter cw = new ClassWriter(0) {
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
     7
            public MethodVisitor visitMethod(
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
     8
                final int access,
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
     9
                final String name,
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    10
                final String desc,
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    11
                final String signature,
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    12
                final String[] exceptions)
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    13
            {
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    14
                MethodVisitor mv = super.visitMethod(access,
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    15
                        name,
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    16
                        desc,
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    17
                        signature,
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    18
                        exceptions);
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    19
                if (mv == null)  return null;
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    20
                if (name.equals("callme")) {
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    21
                    // make receiver go dead!
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    22
                    mv.visitInsn(Opcodes.ACONST_NULL);
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    23
                    mv.visitVarInsn(Opcodes.ASTORE, 0);
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    24
                }
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    25
                return mv;
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    26
            }
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    27
        };
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    28
        cr.accept(cw, 0);
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    29
        return cw.toByteArray();
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    30
    }
490bb6c0df7c 8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
diff changeset
    31
}