1 30 package org.objectweb.asm.test.cases; 31 32 import java.io.IOException ; 33 34 import org.objectweb.asm.ClassWriter; 35 import org.objectweb.asm.Label; 36 import org.objectweb.asm.MethodVisitor; 37 38 47 public class Wide extends Generator { 48 49 public void generate(final String dir) throws IOException { 50 generate(dir, "pkg/Wide.class", dump()); 51 } 52 53 public byte[] dump() { 54 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); 55 MethodVisitor mv; 56 57 cw.visit(V1_2, ACC_PUBLIC, "pkg/Wide", null, "java/lang/Object", null); 58 59 mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); 60 mv.visitCode(); 61 mv.visitVarInsn(ALOAD, 0); 62 mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); 63 for (int i = 0; i < 256; ++i) { 64 mv.visitLdcInsn(Integer.toString(i)); mv.visitInsn(POP); 66 } 67 mv.visitInsn(RETURN); 68 mv.visitMaxs(0, 0); 69 mv.visitEnd(); 70 71 mv = cw.visitMethod(ACC_PUBLIC, "wideLocals", "(I)I", null, null); 72 mv.visitCode(); 73 Label l0 = new Label(); 74 Label l1 = new Label(); 75 mv.visitJumpInsn(GOTO, l1); 77 mv.visitLabel(l0); 78 mv.visitIincInsn(300, 1); mv.visitVarInsn(ILOAD, 300); mv.visitJumpInsn(IFEQ, l1); 82 84 mv.visitVarInsn(ILOAD, 300); mv.visitInsn(IRETURN); 86 87 mv.visitLabel(l1); 88 for (int i = 1; i < 300; ++i) { 89 mv.visitVarInsn(ILOAD, i); 90 if (i <= 5) { 91 mv.visitInsn(ICONST_0 + i); 92 } else if (i <= Byte.MAX_VALUE) { 93 mv.visitIntInsn(BIPUSH, i); 94 } else { 95 mv.visitIntInsn(SIPUSH, i); 96 } 97 mv.visitInsn(IADD); 98 mv.visitVarInsn(ISTORE, i + 1); 99 } 100 mv.visitInsn(ICONST_0); 101 mv.visitJumpInsn(IFEQ, l0); mv.visitJumpInsn(GOTO, l0); 104 mv.visitMaxs(0, 0); 105 mv.visitEnd(); 106 107 cw.visitEnd(); 108 109 return cw.toByteArray(); 110 } 111 } 112 | Popular Tags |