1 package org.apache.commons.javaflow.bytecode.transformation; 2 3 import org.objectweb.asm.AnnotationVisitor; 4 import org.objectweb.asm.ClassWriter; 5 import org.objectweb.asm.FieldVisitor; 6 import org.objectweb.asm.Label; 7 import org.objectweb.asm.MethodVisitor; 8 import org.objectweb.asm.Opcodes; 9 10 11 public class DefaultConstructorDump implements Opcodes { 12 13 public static byte[] dump() throws Exception { 14 FieldVisitor fv; 15 MethodVisitor mv; 16 AnnotationVisitor av0; 17 18 ClassWriter cw = new ClassWriter(true); 19 cw.visit( V1_2, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, "org/apache/commons/javaflow/bytecode/transformation/asm/data/DefaultConstructor", null, "java/lang/Thread", null); 20 21 cw.visitSource( "DefaultConstructor.java", null); 22 23 { 24 mv = cw.visitMethod( ACC_PUBLIC, "<init>", "()V", null, null); 25 mv.visitCode(); 26 27 Label l0 = new Label(); 28 mv.visitLabel( l0); 29 30 mv.visitVarInsn( ALOAD, 0); 31 mv.visitMethodInsn( INVOKESPECIAL, "java/lang/Thread", "<init>", "()V"); 32 33 mv.visitMethodInsn( INVOKESTATIC, "org/apache/commons/javaflow/bytecode/StackRecorder", "get", "()Lorg/apache/commons/javaflow/bytecode/StackRecorder;"); 34 mv.visitInsn( DUP); 35 mv.visitVarInsn( ASTORE, 1); 36 Label l1 = new Label(); 37 mv.visitJumpInsn( IFNULL, l1); 38 mv.visitVarInsn( ALOAD, 1); 39 mv.visitMethodInsn( INVOKEVIRTUAL, "org/apache/commons/javaflow/bytecode/StackRecorder", "isRestoring", "()Z"); 40 mv.visitJumpInsn( IFEQ, l1); 41 mv.visitVarInsn( ALOAD, 1); 42 mv.visitMethodInsn( INVOKEVIRTUAL, "org/apache/commons/javaflow/bytecode/StackRecorder", "popInt", "()I"); 43 Label l2 = new Label(); 44 mv.visitTableSwitchInsn( 0, 0, l1, new Label[] { l2}); 45 46 mv.visitLabel( l2); 47 mv.visitLdcInsn( "restore locals"); 48 mv.visitInsn( POP); 49 mv.visitVarInsn( ALOAD, 1); 50 mv.visitMethodInsn( INVOKEVIRTUAL, "org/apache/commons/javaflow/bytecode/StackRecorder", "popObject", "()Ljava/lang/Object;"); 51 mv.visitTypeInsn( CHECKCAST, "org/apache/commons/javaflow/bytecode/transformation/asm/data/DefaultConstructor"); 52 mv.visitVarInsn( ASTORE, 0); 53 mv.visitLdcInsn( "restore stack"); 54 mv.visitInsn( POP); 55 mv.visitLdcInsn( "restore reference"); 56 mv.visitInsn( POP); 57 mv.visitVarInsn( ALOAD, 1); 58 mv.visitMethodInsn( INVOKEVIRTUAL, "org/apache/commons/javaflow/bytecode/StackRecorder", "popReference", "()Ljava/lang/Object;"); 59 mv.visitTypeInsn( CHECKCAST, "java/io/PrintStream"); 60 mv.visitLdcInsn( "restore params"); 61 mv.visitInsn( POP); 62 mv.visitInsn( ACONST_NULL); 63 mv.visitTypeInsn( CHECKCAST, "java/lang/String"); 64 Label l3 = new Label(); 65 mv.visitJumpInsn( GOTO, l3); 66 67 mv.visitLabel( l1); 68 69 mv.visitFieldInsn( GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;"); 70 mv.visitLdcInsn( "aaa"); 71 mv.visitLabel( l3); 72 mv.visitMethodInsn( INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V"); 73 mv.visitVarInsn( ALOAD, 1); 74 Label l5 = new Label(); 75 mv.visitJumpInsn( IFNULL, l5); 76 mv.visitVarInsn( ALOAD, 1); 77 mv.visitMethodInsn( INVOKEVIRTUAL, "org/apache/commons/javaflow/bytecode/StackRecorder", "isCapturing", "()Z"); 78 mv.visitJumpInsn( IFEQ, l5); 79 mv.visitVarInsn( ALOAD, 1); 80 mv.visitVarInsn( ALOAD, 0); 81 mv.visitMethodInsn( INVOKEVIRTUAL, "org/apache/commons/javaflow/bytecode/StackRecorder", "pushReference", 82 "(Ljava/lang/Object;)V"); 83 mv.visitVarInsn( ALOAD, 1); 84 mv.visitVarInsn( ALOAD, 0); 85 mv.visitMethodInsn( INVOKEVIRTUAL, "org/apache/commons/javaflow/bytecode/StackRecorder", "pushObject", 86 "(Ljava/lang/Object;)V"); 87 mv.visitVarInsn( ALOAD, 1); 88 mv.visitIntInsn( BIPUSH, 0); 89 mv.visitMethodInsn( INVOKEVIRTUAL, "org/apache/commons/javaflow/bytecode/StackRecorder", "pushInt", "(I)V"); 90 mv.visitInsn( RETURN); 91 92 mv.visitLabel( l5); 93 mv.visitInsn( RETURN); 94 95 Label l6 = new Label(); 96 mv.visitLabel( l6); 97 mv.visitLocalVariable( "this", "Lorg/apache/commons/javaflow/bytecode/transformation/asm/data/DefaultConstructor;", null, l1, l6, 0); 98 mv.visitLocalVariable( "__stackRecorder", "Lorg/apache/commons/javaflow/bytecode/StackRecorder;", null, l0, l6, 1); 99 mv.visitMaxs( 2, 2); 100 mv.visitEnd(); 101 } 102 cw.visitEnd(); 103 104 return cw.toByteArray(); 105 } 106 } 107