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 48 public class JSR extends Generator { 49 50 public void generate(final String dir) throws IOException { 51 generate(dir, "pkg/JSR1.class", dumpForwardJSR()); 52 generate(dir, "pkg/JSR2.class", dumpBackwardJSR()); 53 } 54 55 public byte[] dumpForwardJSR() { 56 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); 57 MethodVisitor mv; 58 59 cw.visit(V1_1, ACC_PUBLIC, "pkg/JSR1", null, "java/lang/Object", null); 60 61 mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); 62 mv.visitCode(); 63 mv.visitVarInsn(ALOAD, 0); 64 mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); 65 mv.visitInsn(RETURN); 66 mv.visitMaxs(0, 0); 67 mv.visitEnd(); 68 69 mv = cw.visitMethod(ACC_PUBLIC, "forwardJSR", "([I)V", null, null); 70 mv.visitCode(); 71 Label l0 = new Label(); 72 Label l1 = new Label(); 73 Label l2 = new Label(); 74 Label l3 = new Label(); 75 Label l4 = new Label(); 76 Label l5 = new Label(); 77 mv.visitTryCatchBlock(l0, l1, l2, null); 78 mv.visitTryCatchBlock(l2, l3, l2, null); 79 mv.visitLabel(l0); 80 mv.visitVarInsn(ALOAD, 0); 81 mv.visitVarInsn(ALOAD, 1); 82 mv.visitMethodInsn(INVOKEVIRTUAL, "pkg/JSR1", "forwardJSR", "([I)V"); 83 mv.visitJumpInsn(JSR, l4); 85 87 mv.visitLabel(l1); 88 mv.visitJumpInsn(GOTO, l5); 89 mv.visitLabel(l2); 90 mv.visitVarInsn(ASTORE, 2); 91 mv.visitJumpInsn(JSR, l4); 92 mv.visitLabel(l3); 93 mv.visitVarInsn(ALOAD, 2); 94 mv.visitInsn(ATHROW); 95 mv.visitLabel(l4); 96 mv.visitVarInsn(ASTORE, 3); 97 mv.visitInsn(DCONST_0); 98 mv.visitVarInsn(DSTORE, 4); 99 mv.visitVarInsn(RET, 3); 100 mv.visitLabel(l5); 101 mv.visitInsn(RETURN); 102 mv.visitMaxs(0, 0); 103 mv.visitEnd(); 104 105 cw.visitEnd(); 106 107 return cw.toByteArray(); 108 } 109 110 public byte[] dumpBackwardJSR() { 111 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); 112 MethodVisitor mv; 113 114 cw.visit(V1_1, ACC_PUBLIC, "pkg/JSR2", null, "java/lang/Object", null); 115 116 mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); 117 mv.visitCode(); 118 mv.visitVarInsn(ALOAD, 0); 119 mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); 120 mv.visitInsn(RETURN); 121 mv.visitMaxs(0, 0); 122 mv.visitEnd(); 123 124 mv = cw.visitMethod(ACC_PUBLIC, "backwardJSR", "([I)V", null, null); 125 mv.visitCode(); 126 Label l0 = new Label(); 127 Label l1 = new Label(); 128 Label l2 = new Label(); 129 Label l3 = new Label(); 130 Label l4 = new Label(); 131 Label l5 = new Label(); 132 Label l6 = new Label(); 133 mv.visitTryCatchBlock(l0, l1, l2, null); 134 mv.visitTryCatchBlock(l2, l3, l2, null); 135 mv.visitInsn(ICONST_0); 136 mv.visitVarInsn(ISTORE, 4); 137 mv.visitJumpInsn(GOTO, l0); 138 mv.visitLabel(l4); 139 mv.visitVarInsn(ASTORE, 3); 140 mv.visitIincInsn(4, 1); 141 mv.visitVarInsn(RET, 3); 142 143 144 mv.visitLabel(l0); 145 mv.visitInsn(ACONST_NULL); 146 mv.visitJumpInsn(IFNULL, l6); mv.visitJumpInsn(GOTO, l6); 149 mv.visitLabel(l6); 150 151 mv.visitJumpInsn(JSR, l4); mv.visitLabel(l1); 153 mv.visitJumpInsn(GOTO, l5); 154 mv.visitLabel(l2); 155 mv.visitVarInsn(ASTORE, 2); 156 mv.visitJumpInsn(JSR, l4); 157 mv.visitLabel(l3); 158 mv.visitVarInsn(ALOAD, 2); 159 mv.visitInsn(ATHROW); 160 mv.visitLabel(l5); 161 mv.visitInsn(RETURN); 162 mv.visitMaxs(0, 0); 163 mv.visitEnd(); 164 165 cw.visitEnd(); 166 167 return cw.toByteArray(); 168 } 169 } 170 | Popular Tags |