Example #1
0
  public static byte[] dumpInner() {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    FieldVisitor fv;
    MethodVisitor mv;

    cw.visit(V1_4, ACC_SUPER, "pkg/Outer$Inner", null, "java/lang/Object", null);

    cw.visitInnerClass("pkg/Outer$Inner", "pkg/Outer", "C", 0);

    fv = cw.visitField(ACC_FINAL + ACC_SYNTHETIC, "this$0", "Lpkg/Outer;", null, null);
    fv.visitEnd();

    mv = cw.visitMethod(0, "<init>", "(Lpkg/Outer;)V", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitFieldInsn(PUTFIELD, "pkg/Outer$Inner", "this$0", "Lpkg/Outer;");
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

    cw.visitEnd();

    return cw.toByteArray();
  }
Example #2
0
  public static byte[] dump1() {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    FieldVisitor fv;
    MethodVisitor mv;

    cw.visit(V1_4, ACC_SUPER, "pkg/Outer$1", null, "pkg/Outer", null);

    cw.visitOuterClass("pkg/Outer", "m", "()V");
    cw.visitInnerClass("pkg/Outer$1", null, null, 0);

    fv = cw.visitField(ACC_FINAL + ACC_SYNTHETIC, "this$0", "Lpkg/Outer;", null, null);
    fv.visitEnd();

    mv = cw.visitMethod(0, "<init>", "(Lpkg/Outer;)V", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitFieldInsn(PUTFIELD, "pkg/Outer$1", "this$0", "Lpkg/Outer;");
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "pkg/Outer", "<init>", "()V");
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

    mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
    mv.visitCode();
    mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
    mv.visitInsn(DUP);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V");
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, "pkg/Outer$1", "this$0", "Lpkg/Outer;");
    mv.visitMethodInsn(
        INVOKEVIRTUAL,
        "java/lang/StringBuilder",
        "append",
        "(Ljava/lang/Object;)Ljava/lang/StringBuilder;");
    mv.visitLdcInsn(" ");
    mv.visitMethodInsn(
        INVOKEVIRTUAL,
        "java/lang/StringBuilder",
        "append",
        "(Ljava/lang/String;)Ljava/lang/StringBuilder;");
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, "pkg/Outer$1", "this$0", "Lpkg/Outer;");
    mv.visitMethodInsn(INVOKESTATIC, "pkg/Outer", "access$000", "(Lpkg/Outer;)I");
    mv.visitMethodInsn(
        INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;");
    mv.visitMethodInsn(
        INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;");
    mv.visitInsn(ARETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

    cw.visitEnd();

    return cw.toByteArray();
  }
Example #3
0
 public void visitEnd() {
   if (!isInterface) {
     FieldVisitor fv = cv.visitField(ACC_PUBLIC + ACC_STATIC, "timer", "J", null, null);
     if (fv != null) {
       fv.visitEnd();
     }
     cv.visitEnd();
   }
 }
 @Override
 public void visitAttribute(final Attribute attr) {
   checkEnd();
   if (attr == null) {
     throw new IllegalArgumentException("Invalid attribute (must not be null)");
   }
   super.visitAttribute(attr);
 }
Example #5
0
  public byte[] dump() {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    FieldVisitor fv;
    MethodVisitor mv;

    cw.visit(
        V1_4, ACC_PUBLIC + ACC_SUPER + ACC_DEPRECATED, "pkg/Outer", null, "java/lang/Object", null);

    cw.visitInnerClass("pkg/Outer$Inner", "pkg/Outer", "C", 0);
    cw.visitInnerClass("pkg/Outer$1", null, null, 0);

    fv = cw.visitField(ACC_PRIVATE + ACC_DEPRECATED, "i", "I", null, null);
    fv.visitEnd();

    mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

    mv = cw.visitMethod(ACC_DEPRECATED, "m", "()V", null, null);
    mv.visitCode();
    mv.visitTypeInsn(NEW, "pkg/Outer$1");
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "pkg/Outer$1", "<init>", "(Lpkg/Outer;)V");
    mv.visitInsn(POP);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

    mv = cw.visitMethod(ACC_STATIC + ACC_SYNTHETIC, "access$000", "(Lpkg/Outer;)I", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, "pkg/Outer", "i", "I");
    mv.visitInsn(IRETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

    cw.visitEnd();

    return cw.toByteArray();
  }
Example #6
0
 @Override
 public Object visitVarDec(VarDec varDec, Object arg) throws Exception {
   // System.out.println(varDec.type.getJVMType());
   if (varDec.type.getJVMType().startsWith("Ljava/util/List"))
     fv = cw.visitField(ACC_STATIC, varDec.identToken.getText(), emptyList, null, null);
   else
     fv =
         cw.visitField(
             ACC_STATIC, varDec.identToken.getText(), varDec.type.getJVMType(), null, null);
   fv.visitEnd();
   return null;
   // throw new UnsupportedOperationException("code generation not yet implemented");
 }
Example #7
0
 @Override
 public void visitAttribute(Attribute attr) {
   super.visitAttribute(attr);
 }
Example #8
0
 @Override
 public void visitEnd() {
   super.visitEnd();
 }
 @Override
 public int hashCode() {
   return fieldVisitor.hashCode();
 }
Example #10
0
 public void visitAttribute(Attribute attr) {
   fv1.visitAttribute(attr);
   fv2.visitAttribute(attr);
 }
Example #11
0
  private static byte[] compileBytes(
      Rule rule,
      Class helperClass,
      String helperName,
      String compiledHelperName,
      boolean compileToBytecode)
      throws Exception {
    ClassWriter cw = new ClassWriter(0);
    FieldVisitor fv;
    MethodVisitor mv;
    AnnotationVisitor av0;
    // create the class as a subclass of the rule helper class, appending Compiled to the front
    // of the class name and a unique number to the end of the class helperName
    // also ensure it implements the HelperAdapter interface
    //
    // public class foo.bar.Compiled_<helper>_<NNN> extends foo.bar.<helper> implements
    // HelperAdapter

    cw.visit(
        V1_5,
        ACC_PUBLIC + ACC_SUPER,
        compiledHelperName,
        null,
        helperName,
        new String[] {"org/jboss/byteman/rule/helper/HelperAdapter"});
    // we need to install the source file name
    {
      String fullFileName = rule.getFile();
      int idx = fullFileName.lastIndexOf(java.io.File.separatorChar);
      String basicFileName = (idx < 0 ? fullFileName : fullFileName.substring(idx + 1));
      String debug = "// compiled from: " + fullFileName + "\n// generated by Byteman\n";
      cw.visitSource(basicFileName, debug);
    }
    {
      // we need a Hashmap field to hold the bindings
      //
      // private HashMap<String, Object> bindingMap;

      fv =
          cw.visitField(
              ACC_PRIVATE,
              "bindingMap",
              "Ljava/util/HashMap;",
              "Ljava/util/HashMap<Ljava/lang/String;Ljava/lang/Object;>;",
              null);
      fv.visitEnd();
    }
    {
      // and a rule field to hold the rule
      //
      // private Rule rule;

      fv =
          cw.visitField(
              ACC_PRIVATE,
              "rule",
              "Lorg/jboss/byteman/rule/Rule;",
              "Lorg/jboss/byteman/rule/Rule;",
              null);
      fv.visitEnd();
    }
    {
      // we need a constructor which takes a Rule as argument
      // if the helper implements a constructor which takes a Rule as argument then we invoke it
      // otherwise we invoke the empty helper constructor

      Constructor superConstructor = null;
      try {
        superConstructor = helperClass.getDeclaredConstructor(Rule.class);
      } catch (NoSuchMethodException e) {
        // hmm, ok see if there is an empty constructor
      } catch (SecurityException e) {
        throw new CompileException(
            "Compiler.compileBytes : unable to access constructor for helper class "
                + helperClass.getCanonicalName());
      }
      boolean superWantsRule = (superConstructor != null);
      if (!superWantsRule) {
        try {
          superConstructor = helperClass.getDeclaredConstructor();
        } catch (NoSuchMethodException e) {
          throw new CompileException(
              "Compiler.compileBytes : no valid constructor found for helper class "
                  + helperClass.getCanonicalName());
        } catch (SecurityException e) {
          throw new CompileException(
              "Compiler.compileBytes : unable to access constructor for helper class "
                  + helperClass.getCanonicalName());
        }
      }
      //
      //  public Compiled<helper>_<NNN>()Rule rule)
      mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(Lorg/jboss/byteman/rule/Rule;)V", null, null);
      mv.visitCode();
      // super();
      //
      // or
      //
      // super(Rule);
      if (superWantsRule) {
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKESPECIAL, helperName, "<init>", "(Lorg/jboss/byteman/rule/Rule;)V");
      } else {
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, helperName, "<init>", "()V");
      }
      // bindingMap = new HashMap<String, Object);
      mv.visitVarInsn(ALOAD, 0);
      mv.visitTypeInsn(NEW, "java/util/HashMap");
      mv.visitInsn(DUP);
      mv.visitMethodInsn(INVOKESPECIAL, "java/util/HashMap", "<init>", "()V");
      mv.visitFieldInsn(PUTFIELD, compiledHelperName, "bindingMap", "Ljava/util/HashMap;");
      // this.rule = rule
      mv.visitVarInsn(ALOAD, 0);
      mv.visitVarInsn(ALOAD, 1);
      mv.visitFieldInsn(PUTFIELD, compiledHelperName, "rule", "Lorg/jboss/byteman/rule/Rule;");
      // return;
      mv.visitInsn(RETURN);
      mv.visitMaxs(3, 2);
      mv.visitEnd();
    }
    {
      // create the execute method
      //
      // public void execute(Bindings bindings, Object recipient, Object[] args) throws
      // ExecuteException
      mv =
          cw.visitMethod(
              ACC_PUBLIC,
              "execute",
              "(Ljava/lang/Object;[Ljava/lang/Object;)V",
              null,
              new String[] {"org/jboss/byteman/rule/exception/ExecuteException"});
      mv.visitCode();
      // if (Transformer.isVerbose())
      mv.visitMethodInsn(INVOKESTATIC, "org/jboss/byteman/agent/Transformer", "isVerbose", "()Z");
      Label l0 = new Label();
      mv.visitJumpInsn(IFEQ, l0);
      // then
      // System.out.println(rule.getName() + " execute");
      mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
      mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
      mv.visitInsn(DUP);
      mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V");
      mv.visitVarInsn(ALOAD, 0);
      mv.visitFieldInsn(GETFIELD, compiledHelperName, "rule", "Lorg/jboss/byteman/rule/Rule;");
      mv.visitMethodInsn(
          INVOKEVIRTUAL, "org/jboss/byteman/rule/Rule", "getName", "()Ljava/lang/String;");
      mv.visitMethodInsn(
          INVOKEVIRTUAL,
          "java/lang/StringBuilder",
          "append",
          "(Ljava/lang/String;)Ljava/lang/StringBuilder;");
      mv.visitLdcInsn(" execute()");
      mv.visitMethodInsn(
          INVOKEVIRTUAL,
          "java/lang/StringBuilder",
          "append",
          "(Ljava/lang/String;)Ljava/lang/StringBuilder;");
      mv.visitMethodInsn(
          INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;");
      mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
      // end if
      mv.visitLabel(l0);

      Bindings bindings = rule.getBindings();
      Iterator<Binding> iterator = bindings.iterator();

      while (iterator.hasNext()) {
        Binding binding = iterator.next();
        String name = binding.getName();
        if (binding.isAlias()) {
          // lookups and updates will use the aliased name
          continue;
        }
        if (binding.isHelper()) {
          // bindingMap.put(name, this);
          mv.visitVarInsn(ALOAD, 0);
          mv.visitFieldInsn(GETFIELD, compiledHelperName, "bindingMap", "Ljava/util/HashMap;");
          mv.visitLdcInsn(name);
          mv.visitVarInsn(ALOAD, 0);
          mv.visitMethodInsn(
              INVOKEVIRTUAL,
              "java/util/HashMap",
              "put",
              "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
          mv.visitInsn(POP);
        } else if (binding.isRecipient()) {
          // bindingMap.put(name, recipient);
          mv.visitVarInsn(ALOAD, 0);
          mv.visitFieldInsn(GETFIELD, compiledHelperName, "bindingMap", "Ljava/util/HashMap;");
          mv.visitLdcInsn(name);
          mv.visitVarInsn(ALOAD, 1);
          mv.visitMethodInsn(
              INVOKEVIRTUAL,
              "java/util/HashMap",
              "put",
              "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
          mv.visitInsn(POP);
          // } else if (binding.isParam() || binding.isLocalVar() || binding.isReturn() ||
          //             binding.isThrowable() || binding.isParamCount() || binding.isParamArray())
          // {
        } else if (!binding.isBindVar()) {
          // bindingMap.put(name, args[binding.getCallArrayIndex()]);
          mv.visitVarInsn(ALOAD, 0);
          mv.visitFieldInsn(GETFIELD, compiledHelperName, "bindingMap", "Ljava/util/HashMap;");
          mv.visitLdcInsn(name);
          mv.visitVarInsn(ALOAD, 2);
          mv.visitLdcInsn(binding.getCallArrayIndex());
          mv.visitInsn(AALOAD);
          mv.visitMethodInsn(
              INVOKEVIRTUAL,
              "java/util/HashMap",
              "put",
              "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
          mv.visitInsn(POP);
        }
      }

      // execute0()
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKEVIRTUAL, compiledHelperName, "execute0", "()V");

      // now restore update bindings

      iterator = bindings.iterator();

      while (iterator.hasNext()) {
        Binding binding = iterator.next();
        if (binding.isAlias()) {
          continue;
        }
        String name = binding.getName();

        if (binding.isUpdated()) {
          // if (binding.isParam() || binding.isLocalVar() || binding.isReturn()) {
          if (!binding.isBindVar()) {
            int idx = binding.getCallArrayIndex();
            // Object value = bindingMap.get(name);
            // args[idx] = value;
            mv.visitVarInsn(ALOAD, 2); // args
            mv.visitLdcInsn(idx);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(GETFIELD, compiledHelperName, "bindingMap", "Ljava/util/HashMap;");
            mv.visitLdcInsn(name);
            mv.visitMethodInsn(
                INVOKEVIRTUAL,
                "java/util/HashMap",
                "get",
                "(Ljava/lang/Object;)Ljava/lang/Object;");
            mv.visitInsn(AASTORE);
          }
        }
      }

      // return
      mv.visitInsn(RETURN);
      mv.visitMaxs(4, 3);
      mv.visitEnd();
    }
    {
      // create the setBinding method
      //
      // public void setBinding(String name, Object value)
      mv =
          cw.visitMethod(
              ACC_PUBLIC, "setBinding", "(Ljava/lang/String;Ljava/lang/Object;)V", null, null);
      mv.visitCode();
      //  bindingMap.put(name, value);
      mv.visitVarInsn(ALOAD, 0);
      mv.visitFieldInsn(GETFIELD, compiledHelperName, "bindingMap", "Ljava/util/HashMap;");
      mv.visitVarInsn(ALOAD, 1);
      mv.visitVarInsn(ALOAD, 2);
      mv.visitMethodInsn(
          INVOKEVIRTUAL,
          "java/util/HashMap",
          "put",
          "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
      mv.visitInsn(POP);
      // return
      mv.visitInsn(RETURN);
      mv.visitMaxs(3, 3);
      mv.visitEnd();
    }
    {
      // create the getBinding method
      //
      // public Object getBinding(String name)
      mv =
          cw.visitMethod(
              ACC_PUBLIC, "getBinding", "(Ljava/lang/String;)Ljava/lang/Object;", null, null);
      mv.visitCode();
      // {TOS} <== bindingMap.get(name);
      mv.visitVarInsn(ALOAD, 0);
      mv.visitFieldInsn(GETFIELD, compiledHelperName, "bindingMap", "Ljava/util/HashMap;");
      mv.visitVarInsn(ALOAD, 1);
      mv.visitMethodInsn(
          INVOKEVIRTUAL, "java/util/HashMap", "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
      // return {TOS}
      mv.visitInsn(ARETURN);
      mv.visitMaxs(2, 2);
      mv.visitEnd();
    }
    {
      // create the getName method
      //
      // public String getName()
      mv = cw.visitMethod(ACC_PUBLIC, "getName", "()Ljava/lang/String;", null, null);
      mv.visitCode();
      // {TOS} <== rule.getName()
      mv.visitVarInsn(ALOAD, 0);
      mv.visitFieldInsn(GETFIELD, compiledHelperName, "rule", "Lorg/jboss/byteman/rule/Rule;");
      mv.visitMethodInsn(
          INVOKEVIRTUAL, "org/jboss/byteman/rule/Rule", "getName", "()Ljava/lang/String;");
      // return {TOS}
      mv.visitInsn(ARETURN);
      mv.visitMaxs(1, 1);
      mv.visitEnd();
    }
    // create the getAccessibleField method
    //
    // public Object getAccessibleField(Object owner, int fieldIndex)
    {
      mv =
          cw.visitMethod(
              ACC_PUBLIC,
              "getAccessibleField",
              "(Ljava/lang/Object;I)Ljava/lang/Object;",
              null,
              null);
      mv.visitCode();
      // {TOS} <== rule.getAccessibleField(owner, fieldIndex);
      mv.visitVarInsn(ALOAD, 0);
      mv.visitFieldInsn(GETFIELD, compiledHelperName, "rule", "Lorg/jboss/byteman/rule/Rule;");
      mv.visitVarInsn(ALOAD, 1);
      mv.visitVarInsn(ILOAD, 2);
      mv.visitMethodInsn(
          INVOKEVIRTUAL,
          "org/jboss/byteman/rule/Rule",
          "getAccessibleField",
          "(Ljava/lang/Object;I)Ljava/lang/Object;");
      // return {TOS}
      mv.visitInsn(ARETURN);
      mv.visitMaxs(3, 3);
      mv.visitEnd();
    }

    // create the setAccessibleField method
    //
    // public void setAccessibleField(Object owner, Object value, int fieldIndex)
    // rule.setAccessibleField(owner, value, fieldIndex);
    {
      mv =
          cw.visitMethod(
              ACC_PUBLIC,
              "setAccessibleField",
              "(Ljava/lang/Object;Ljava/lang/Object;I)V",
              null,
              null);
      mv.visitCode();
      // rule.setAccessibleField(owner, value, fieldIndex);
      mv.visitVarInsn(ALOAD, 0);
      mv.visitFieldInsn(GETFIELD, compiledHelperName, "rule", "Lorg/jboss/byteman/rule/Rule;");
      mv.visitVarInsn(ALOAD, 1);
      mv.visitVarInsn(ALOAD, 2);
      mv.visitVarInsn(ILOAD, 3);
      mv.visitMethodInsn(
          INVOKEVIRTUAL,
          "org/jboss/byteman/rule/Rule",
          "setAccessibleField",
          "(Ljava/lang/Object;Ljava/lang/Object;I)V");
      // return
      mv.visitInsn(RETURN);
      mv.visitMaxs(4, 4);
      mv.visitEnd();
    }

    // create the invokeAccessibleMethod method
    //
    // public Object invokeAccessibleMethod(Object target, Object[] args, int methodIndex)
    // {TOS} <==  rule.invokeAccessibleMethod(target, args, methodIndex);
    {
      mv =
          cw.visitMethod(
              ACC_PUBLIC,
              "invokeAccessibleMethod",
              "(Ljava/lang/Object;[Ljava/lang/Object;I)Ljava/lang/Object;",
              null,
              null);
      mv.visitCode();
      // rule.invokeAccessibleMethod(target, args, fieldIndex);
      mv.visitVarInsn(ALOAD, 0);
      mv.visitFieldInsn(GETFIELD, compiledHelperName, "rule", "Lorg/jboss/byteman/rule/Rule;");
      mv.visitVarInsn(ALOAD, 1);
      mv.visitVarInsn(ALOAD, 2);
      mv.visitVarInsn(ILOAD, 3);
      mv.visitMethodInsn(
          INVOKEVIRTUAL,
          "org/jboss/byteman/rule/Rule",
          "invokeAccessibleMethod",
          "(Ljava/lang/Object;[Ljava/lang/Object;I)Ljava/lang/Object;");
      // return {TOS}
      mv.visitInsn(ARETURN);
      mv.visitMaxs(4, 4);
      mv.visitEnd();
    }
    if (compileToBytecode) {
      // we generate a single execute0 method if we want to run compiled and get
      // the event, condiiton and action to insert the relevant bytecode to implement
      // bind(), test() and fire()

      {
        // create the execute0() method
        //
        // private void execute0()
        mv =
            cw.visitMethod(
                ACC_PRIVATE,
                "execute0",
                "()V",
                null,
                new String[] {"org/jboss/byteman/rule/exception/ExecuteException"});
        mv.visitCode();
        CompileContext compileContext = new CompileContext(mv);
        // make sure we set the first line number before generating any code
        compileContext.notifySourceLine(rule.getLine());
        compileContext.addLocalCount(3); // for this and 2 object args
        // bind();
        rule.getEvent().compile(mv, compileContext);
        // if (test())
        rule.getCondition().compile(mv, compileContext);
        Label l0 = new Label();
        mv.visitJumpInsn(IFEQ, l0);
        compileContext.addStackCount(-1);
        // then
        rule.getAction().compile(mv, compileContext);
        // fire();
        // end if
        mv.visitLabel(l0);
        // this will match the ENDRULE line
        compileContext.notifySourceEnd();
        // return
        mv.visitInsn(RETURN);
        // need to specify correct Maxs values
        mv.visitMaxs(compileContext.getStackMax(), compileContext.getLocalMax());
        mv.visitEnd();
      }
    } else {
      // we generate the following methods if we want to run interpreted
      {
        // create the execute0() method
        //
        // private void execute0()
        mv =
            cw.visitMethod(
                ACC_PRIVATE,
                "execute0",
                "()V",
                null,
                new String[] {"org/jboss/byteman/rule/exception/ExecuteException"});
        mv.visitCode();
        // bind();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, compiledHelperName, "bind", "()V");
        // if (test())
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, compiledHelperName, "test", "()Z");
        Label l0 = new Label();
        mv.visitJumpInsn(IFEQ, l0);
        // then
        // fire();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, compiledHelperName, "fire", "()V");
        // end if
        mv.visitLabel(l0);
        // return
        mv.visitInsn(RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
      }
      {
        // create the bind method
        //
        // private void bind()
        mv =
            cw.visitMethod(
                ACC_PRIVATE,
                "bind",
                "()V",
                null,
                new String[] {"org/jboss/byteman/rule/exception/ExecuteException"});
        mv.visitCode();
        // rule.getEvent().interpret(this);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, compiledHelperName, "rule", "Lorg/jboss/byteman/rule/Rule;");
        mv.visitMethodInsn(
            INVOKEVIRTUAL,
            "org/jboss/byteman/rule/Rule",
            "getEvent",
            "()Lorg/jboss/byteman/rule/Event;");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(
            INVOKEVIRTUAL,
            "org/jboss/byteman/rule/Event",
            "interpret",
            "(Lorg/jboss/byteman/rule/helper/HelperAdapter;)Ljava/lang/Object;");
        mv.visitInsn(RETURN);
        mv.visitMaxs(2, 1);
        mv.visitEnd();
      }
      {
        // create the test method
        //
        // private boolean test()
        mv =
            cw.visitMethod(
                ACC_PRIVATE,
                "test",
                "()Z",
                null,
                new String[] {"org/jboss/byteman/rule/exception/ExecuteException"});
        mv.visitCode();
        // {TOS} <== rule.getCondition().interpret(this);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, compiledHelperName, "rule", "Lorg/jboss/byteman/rule/Rule;");
        mv.visitMethodInsn(
            INVOKEVIRTUAL,
            "org/jboss/byteman/rule/Rule",
            "getCondition",
            "()Lorg/jboss/byteman/rule/Condition;");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(
            INVOKEVIRTUAL,
            "org/jboss/byteman/rule/Condition",
            "interpret",
            "(Lorg/jboss/byteman/rule/helper/HelperAdapter;)Ljava/lang/Object;");
        mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Boolean");
        // unbox the returned Boolean
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z");
        // return {TOS}
        mv.visitInsn(IRETURN);
        mv.visitMaxs(2, 1);
        mv.visitEnd();
      }
      {
        // create the fire method
        //
        // private void fire()
        mv =
            cw.visitMethod(
                ACC_PRIVATE,
                "fire",
                "()V",
                null,
                new String[] {"org/jboss/byteman/rule/exception/ExecuteException"});
        mv.visitCode();
        // rule.getAction().interpret(this);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, compiledHelperName, "rule", "Lorg/jboss/byteman/rule/Rule;");
        mv.visitMethodInsn(
            INVOKEVIRTUAL,
            "org/jboss/byteman/rule/Rule",
            "getAction",
            "()Lorg/jboss/byteman/rule/Action;");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(
            INVOKEVIRTUAL,
            "org/jboss/byteman/rule/Action",
            "interpret",
            "(Lorg/jboss/byteman/rule/helper/HelperAdapter;)Ljava/lang/Object;");
        // return
        mv.visitInsn(RETURN);
        mv.visitMaxs(2, 1);
        mv.visitEnd();
      }
    }

    cw.visitEnd();

    return cw.toByteArray();
  }
Example #12
0
 public static void generateField(ClassWriter classWriter, Property<Class<?>, Method> property) {
   FieldVisitor fv =
       classWriter.visitField(
           ACC_PRIVATE, property.getName(), Type.getDescriptor(property.getType()), null, null);
   fv.visitEnd();
 }
  /**
   * Generate bytecodes for runtime class
   *
   * @return byte array containing bytecodes for runtime class
   * @throws Exception
   */
  public byte[] genBytecode() throws Exception {

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    FieldVisitor fv = null;
    MethodVisitor mv = null;
    ImplHelper.FieldDesc[] fieldDesc = ImplHelper.getFieldDesc(clazz);
    int isVariableLengthLayout = 0;
    final boolean itf = false;
    String superImpl = "java/lang/Object";

    if (null == fieldDesc) {
      createBody = false;
      /* find layout superType */
      for (Class<?> c : clazz.getInterfaces()) {
        if (Layout.class.isAssignableFrom(c)) {
          superImpl = ImplHelper.getImplClassName(c);
        }
      }
    }

    if (createBody) {
      eaCW.visit(
          52,
          ACC_SUPER,
          implClassName + "$EffectiveAddressImpl",
          null,
          "java/lang/Object",
          new String[] {interfaceClassName + "$EffectiveAddress"});

      eaCW.visitInnerClass(
          interfaceClassName + "$EffectiveAddress",
          interfaceClassName,
          "EffectiveAddress",
          ACC_PUBLIC + ACC_STATIC + ACC_ABSTRACT + ACC_INTERFACE);

      eaCW.visitInnerClass(
          implClassName + "$EffectiveAddressImpl", implClassName, "EffectiveAddressImpl", 0);

      {
        fv =
            eaCW.visitField(
                ACC_FINAL + ACC_SYNTHETIC, "this$0", "L" + implClassName + ";", null, null);
        fv.visitEnd();
      }

      {
        eaMV = eaCW.visitMethod(0, "<init>", "(L" + implClassName + ";)V", null, null);
        eaMV.visitCode();
        eaMV.visitVarInsn(ALOAD, 0);
        eaMV.visitVarInsn(ALOAD, 1);
        eaMV.visitFieldInsn(
            PUTFIELD, implClassName + "$EffectiveAddressImpl", "this$0", "L" + implClassName + ";");
        eaMV.visitVarInsn(ALOAD, 0);
        eaMV.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        eaMV.visitInsn(RETURN);
        eaMV.visitMaxs(2, 2);
        eaMV.visitEnd();
      }
    }

    cw.visit(
        V1_8,
        ACC_PUBLIC + ACC_SUPER,
        implClassName,
        null,
        superImpl,
        new String[] {interfaceClassName});
    if (createBody) {
      cw.visitInnerClass(
          implClassName + "$EffectiveAddressImpl", implClassName, "EffectiveAddressImpl", 0);
    }
    {
      mv = cw.visitMethod(0, "<init>", "()V", null, null);
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKESPECIAL, superImpl, "<init>", "()V", false);
      mv.visitInsn(RETURN);
      mv.visitMaxs(1, 1);
      mv.visitEnd();
    }
    if (!createBody) {
      {
        fv =
            cw.visitField(
                ACC_PRIVATE + ACC_FINAL + ACC_STATIC, "unsafe", "Lsun/misc/Unsafe;", null, null);
        fv.visitEnd();
      }
      cw.visitEnd();
      return cw.toByteArray();
    }

    for (int i = 0; i < fieldDesc.length; i++) {

      startWayPointCounter = wayPointCounter;
      if (!ImplHelper.isPointerType(fieldDesc[i].rawType)) {
        if (ImplHelper.isTypePrimitive(fieldDesc[i].sig)) {
          // getter
          mv = cw.visitMethod(ACC_PUBLIC, fieldDesc[i].name, "()" + fieldDesc[i].sig, null, null);
          mv.visitCode();
          mv.visitVarInsn(ALOAD, 0);
          mv.visitFieldInsn(GETFIELD, implClassName, "location", "Lcom/ibm/layout/Location;");
          mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getData", "()[B", itf);
          mv.visitVarInsn(ALOAD, 0);
          mv.visitFieldInsn(GETFIELD, implClassName, "location", "Lcom/ibm/layout/Location;");
          mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getOffset", "()J", itf);
          if (wayPointCounter > 0) {
            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(
                INVOKESPECIAL, implClassName, "waypoint" + (wayPointCounter - 1), "()J", false);
            mv.visitInsn(LADD);
          }
          mv.visitLdcInsn(fieldDesc[i].offset);
          mv.visitInsn(LADD);

          mv.visitMethodInsn(
              INVOKESTATIC,
              "com/ibm/layout/gen/UnsafeImplHelper",
              "load" + fieldDesc[i].endian + ImplHelper.fieldSig2MethodType(fieldDesc[i].sig),
              "(Ljava/lang/Object;J)" + fieldDesc[i].sig,
              itf);
          if (fieldDesc[i].sig == "D") {
            mv.visitInsn(DRETURN);
          } else if (fieldDesc[i].sig == "J") {
            mv.visitInsn(LRETURN);
          } else if (fieldDesc[i].sig == "F") {
            mv.visitInsn(FRETURN);
          } else {
            mv.visitInsn(IRETURN);
          }
          mv.visitMaxs(5, 1);
          mv.visitEnd();

          // setter
          mv =
              cw.visitMethod(
                  ACC_PUBLIC, fieldDesc[i].name, "(" + fieldDesc[i].sig + ")V", null, null);
          mv.visitCode();
          mv.visitVarInsn(ALOAD, 0);
          mv.visitFieldInsn(GETFIELD, implClassName, "location", "Lcom/ibm/layout/Location;");
          mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getData", "()[B", itf);
          mv.visitVarInsn(ALOAD, 0);
          mv.visitFieldInsn(GETFIELD, implClassName, "location", "Lcom/ibm/layout/Location;");
          mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getOffset", "()J", itf);
          mv.visitLdcInsn(fieldDesc[i].offset);
          if (wayPointCounter > 0) {
            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(
                INVOKESPECIAL, implClassName, "waypoint" + (wayPointCounter - 1), "()J", false);
            mv.visitInsn(LADD);
          }
          mv.visitInsn(LADD);
          if (fieldDesc[i].sig == "D") {
            mv.visitVarInsn(DLOAD, 1);
          } else if (fieldDesc[i].sig == "J") {
            mv.visitVarInsn(LLOAD, 1);
          } else if (fieldDesc[i].sig == "F") {
            mv.visitVarInsn(FLOAD, 1);
          } else {
            mv.visitVarInsn(ILOAD, 1);
          }
          mv.visitMethodInsn(
              INVOKESTATIC,
              "com/ibm/layout/gen/UnsafeImplHelper",
              "store" + fieldDesc[i].endian + ImplHelper.fieldSig2MethodType(fieldDesc[i].sig),
              "(Ljava/lang/Object;J" + fieldDesc[i].sig + ")V",
              itf);
          mv.visitInsn(RETURN);
          mv.visitMaxs(5, 2);
          mv.visitEnd();

        } else if (fieldDesc[i].repeatCountMember != null) {
          {
            isVariableLengthLayout++;
            ImplHelper.FieldDesc repeatCountField =
                ImplHelper.findField(fieldDesc[i].repeatCountMember, fieldDesc);
            mv =
                cw.visitMethod(
                    ACC_PUBLIC,
                    fieldDesc[i].name,
                    "()" + fieldDesc[i].sig,
                    "()" + fieldDesc[i].elementImpl,
                    null);
            mv.visitCode();
            if ("" != fieldDesc[i].elementImpl) {
              mv.visitTypeInsn(NEW, fieldDesc[i].elementImpl);
              mv.visitInsn(DUP);
              mv.visitMethodInsn(INVOKESPECIAL, fieldDesc[i].elementImpl, "<init>", "()V", false);
              mv.visitVarInsn(ASTORE, 1);
              mv.visitTypeInsn(NEW, fieldDesc[i].impl);
              mv.visitInsn(DUP);
              mv.visitVarInsn(ALOAD, 0);
              if (fieldDesc[i].priviliedgedUserClass) {
                FieldDesc header = ImplHelper.findField(fieldDesc[i].repeatCountMember, fieldDesc);
                boolean primitivePointer = ImplHelper.isTypePrimitive(header.sig);

                mv.visitMethodInsn(
                    INVOKEVIRTUAL,
                    implClassName,
                    "EA",
                    "()L" + interfaceClassName + "$EffectiveAddress;",
                    false);

                if (primitivePointer) {
                  mv.visitMethodInsn(
                      INVOKEINTERFACE,
                      interfaceClassName + "$EffectiveAddress",
                      fieldDesc[i].repeatCountMember,
                      "()L" + header.pointerSig + ";",
                      true);
                } else {
                  mv.visitMethodInsn(
                      INVOKEINTERFACE,
                      interfaceClassName + "$EffectiveAddress",
                      fieldDesc[i].repeatCountMember,
                      "()Lcom/ibm/layout/Pointer;",
                      true);
                }
                if (fieldDesc[i].isVarSized) {
                  mv.visitMethodInsn(
                      INVOKESPECIAL,
                      fieldDesc[i].impl,
                      "<init>",
                      "(Lcom/ibm/layout/PointerType;)V",
                      false);
                } else {
                  mv.visitVarInsn(ALOAD, 1);
                  mv.visitMethodInsn(
                      INVOKEVIRTUAL, fieldDesc[i].elementImpl, "sizeof", "()J", false);
                  mv.visitMethodInsn(
                      INVOKESPECIAL,
                      fieldDesc[i].impl,
                      "<init>",
                      "(Lcom/ibm/layout/PointerType;J)V",
                      false);
                }
              } else {
                mv.visitMethodInsn(
                    INVOKEVIRTUAL,
                    implClassName,
                    fieldDesc[i].repeatCountMember,
                    "()" + repeatCountField.sig,
                    false);
                if (!repeatCountField.sig.equals("J")) {
                  mv.visitInsn(I2L);
                }
                if (fieldDesc[i].isVarSized) {
                  mv.visitMethodInsn(INVOKESPECIAL, fieldDesc[i].impl, "<init>", "(J)V", false);
                } else {
                  mv.visitVarInsn(ALOAD, 1);
                  mv.visitMethodInsn(
                      INVOKEVIRTUAL, fieldDesc[i].elementImpl, "sizeof", "()J", false);
                  mv.visitMethodInsn(INVOKESPECIAL, fieldDesc[i].impl, "<init>", "(JJ)V", false);
                }
              }
              mv.visitVarInsn(ASTORE, 2);
              mv.visitTypeInsn(NEW, "com/ibm/layout/Location");
              mv.visitInsn(DUP);
              mv.visitVarInsn(ALOAD, 0);
              mv.visitFieldInsn(GETFIELD, implClassName, "location", "Lcom/ibm/layout/Location;");
              mv.visitLdcInsn(fieldDesc[i].offset);
              if (wayPointCounter > 0) {
                mv.visitVarInsn(ALOAD, 0);
                mv.visitMethodInsn(
                    INVOKESPECIAL, implClassName, "waypoint" + (wayPointCounter - 1), "()J", false);
                mv.visitInsn(LADD);
              }
              mv.visitMethodInsn(
                  INVOKESPECIAL,
                  "com/ibm/layout/Location",
                  "<init>",
                  "(Lcom/ibm/layout/Location;J)V",
                  false);
              mv.visitVarInsn(ASTORE, 3);
              mv.visitVarInsn(ALOAD, 2);
              mv.visitVarInsn(ALOAD, 3);
              mv.visitMethodInsn(
                  INVOKEINTERFACE,
                  "com/ibm/layout/VLArray",
                  "bindLocation",
                  "(Lcom/ibm/layout/Location;)V",
                  true);
              mv.visitVarInsn(ALOAD, 2);
              mv.visitInsn(ARETURN);
              if (fieldDesc[i].priviliedgedUserClass) {
                mv.visitMaxs(7, 4);
              } else {
                mv.visitMaxs(6, 4);
              }

              mv.visitEnd();
            } else {
              throw new RuntimeException("primitive VLAs are unsupported");
            }
            if ((isVariableLengthLayout == 1) && ((fieldDesc.length - 1) == i)) {
              mv =
                  cw.visitMethod(
                      ACC_PUBLIC,
                      "bindLocation",
                      "(Lcom/ibm/layout/Location;" + repeatCountField.sig + ")V",
                      null,
                      new String[] {"java/lang/UnsupportedOperationException"});
              mv.visitCode();
              mv.visitVarInsn(ALOAD, 0);
              mv.visitVarInsn(ALOAD, 1);
              mv.visitFieldInsn(PUTFIELD, implClassName, "location", "Lcom/ibm/layout/Location;");
              mv.visitVarInsn(ALOAD, 0);
              if (repeatCountField.sig.equals("J")) {
                mv.visitVarInsn(LLOAD, 2);
              } else {
                mv.visitVarInsn(ILOAD, 2);
              }
              mv.visitMethodInsn(
                  INVOKEVIRTUAL,
                  implClassName,
                  fieldDesc[i].repeatCountMember,
                  "(" + repeatCountField.sig + ")V",
                  false);
              mv.visitInsn(RETURN);
              mv.visitMaxs(2, 3);
              mv.visitEnd();
            }
            if (wayPointCounter == 0) {
              mv = cw.visitMethod(ACC_PRIVATE, "waypoint" + wayPointCounter++, "()J", null, null);
              mv.visitCode();
              mv.visitLdcInsn(fieldDesc[i].offset);
              mv.visitVarInsn(ALOAD, 0);
              mv.visitMethodInsn(
                  INVOKEVIRTUAL,
                  this.implClassName,
                  fieldDesc[i].name,
                  "()" + fieldDesc[i].sig,
                  false);
              mv.visitMethodInsn(INVOKEINTERFACE, "com/ibm/layout/VLArray", "sizeof", "()J", true);
              mv.visitInsn(LADD);
              mv.visitInsn(LRETURN);
              mv.visitMaxs(4, 1);
              mv.visitEnd();
            } else {
              long oldWayPoint = wayPointCounter - 1;
              mv = cw.visitMethod(ACC_PRIVATE, "waypoint" + wayPointCounter++, "()J", null, null);
              mv.visitCode();
              mv.visitLdcInsn(fieldDesc[i].offset);
              mv.visitVarInsn(ALOAD, 0);
              mv.visitMethodInsn(
                  INVOKEVIRTUAL,
                  this.implClassName,
                  fieldDesc[i].name,
                  "()" + fieldDesc[i].sig,
                  false);
              mv.visitMethodInsn(INVOKEINTERFACE, "com/ibm/layout/VLArray", "sizeof", "()J", true);
              mv.visitInsn(LADD);
              mv.visitVarInsn(ALOAD, 0);
              mv.visitMethodInsn(
                  INVOKESPECIAL, this.implClassName, "waypoint" + oldWayPoint, "()J", false);
              mv.visitInsn(LADD);
              mv.visitInsn(LRETURN);
              mv.visitMaxs(4, 1);
              mv.visitEnd();
            }
            {
              // access for EA class
              mv =
                  cw.visitMethod(
                      ACC_STATIC + ACC_SYNTHETIC,
                      "access$" + (wayPointCounter),
                      "(L" + this.implClassName + ";)J",
                      null,
                      null);
              mv.visitCode();
              mv.visitVarInsn(ALOAD, 0);
              mv.visitMethodInsn(
                  INVOKESPECIAL,
                  this.implClassName,
                  "waypoint" + (wayPointCounter - 1),
                  "()J",
                  false);
              mv.visitInsn(LRETURN);
              mv.visitMaxs(2, 1);
              mv.visitEnd();
            }
          }
        } else if (fieldDesc[i].dims == null) {
          /* nested field */
          mv = cw.visitMethod(ACC_PUBLIC, fieldDesc[i].name, "()" + fieldDesc[i].sig, null, null);
          mv.visitCode();
          mv.visitTypeInsn(NEW, ImplHelper.getImplClassName(fieldDesc[i].rawType));
          mv.visitInsn(DUP);
          mv.visitMethodInsn(
              INVOKESPECIAL,
              ImplHelper.getImplClassName(fieldDesc[i].rawType),
              "<init>",
              "()V",
              itf);
          mv.visitVarInsn(ASTORE, 1);
          mv.visitTypeInsn(NEW, "com/ibm/layout/Location");
          mv.visitInsn(DUP);
          mv.visitVarInsn(ALOAD, 0);
          mv.visitFieldInsn(GETFIELD, this.implClassName, "location", "Lcom/ibm/layout/Location;");
          mv.visitLdcInsn(fieldDesc[i].offset);
          if (wayPointCounter > 0) {
            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(
                INVOKESPECIAL, implClassName, "waypoint" + (wayPointCounter - 1), "()J", false);
            mv.visitInsn(LADD);
          }
          mv.visitMethodInsn(
              INVOKESPECIAL,
              "com/ibm/layout/Location",
              "<init>",
              "(Lcom/ibm/layout/Location;J)V",
              itf);
          mv.visitVarInsn(ASTORE, 2);
          mv.visitVarInsn(ALOAD, 1);
          mv.visitVarInsn(ALOAD, 2);
          mv.visitMethodInsn(
              INVOKEVIRTUAL,
              ImplHelper.getImplClassName(fieldDesc[i].rawType),
              "bindLocation",
              "(Lcom/ibm/layout/Location;)V",
              itf);
          mv.visitVarInsn(ALOAD, 1);
          mv.visitInsn(ARETURN);
          mv.visitMaxs(5, 3);
          mv.visitEnd();
        } else if (fieldDesc[i].dims.length == 1) {
          mv =
              cw.visitMethod(
                  ACC_PUBLIC,
                  fieldDesc[i].name,
                  "()" + fieldDesc[i].sig,
                  "()" + fieldDesc[i].sigGeneric,
                  null);
          mv.visitCode();
          if ("" != fieldDesc[i].elementImpl) {
            mv.visitTypeInsn(NEW, fieldDesc[i].elementImpl);
            mv.visitInsn(DUP);
            mv.visitMethodInsn(INVOKESPECIAL, fieldDesc[i].elementImpl, "<init>", "()V", itf);
            mv.visitVarInsn(ASTORE, 1);
            mv.visitTypeInsn(NEW, fieldDesc[i].impl);
            mv.visitInsn(DUP);
            mv.visitLdcInsn(fieldDesc[i].dims[0]);
            mv.visitVarInsn(ALOAD, 1);
            mv.visitMethodInsn(INVOKEVIRTUAL, fieldDesc[i].elementImpl, "sizeof", "()J", itf);
            mv.visitMethodInsn(INVOKESPECIAL, fieldDesc[i].impl, "<init>", "(JJ)V", itf);
            mv.visitVarInsn(ASTORE, 2);
            mv.visitTypeInsn(NEW, "com/ibm/layout/Location");
            mv.visitInsn(DUP);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(
                GETFIELD, this.implClassName, "location", "Lcom/ibm/layout/Location;");
            mv.visitLdcInsn(fieldDesc[i].offset);
            if (wayPointCounter > 0) {
              mv.visitVarInsn(ALOAD, 0);
              mv.visitMethodInsn(
                  INVOKESPECIAL, implClassName, "waypoint" + (wayPointCounter - 1), "()J", false);
              mv.visitInsn(LADD);
            }
            mv.visitMethodInsn(
                INVOKESPECIAL,
                "com/ibm/layout/Location",
                "<init>",
                "(Lcom/ibm/layout/Location;J)V",
                itf);
            mv.visitVarInsn(ASTORE, 3);
            mv.visitVarInsn(ALOAD, 2);
            mv.visitVarInsn(ALOAD, 3);
            mv.visitMethodInsn(
                INVOKEVIRTUAL,
                fieldDesc[i].impl,
                "bindLocation",
                "(Lcom/ibm/layout/Location;)V",
                itf);
            mv.visitVarInsn(ALOAD, 2);
            mv.visitInsn(ARETURN);
            mv.visitMaxs(6, 4);
            mv.visitEnd();
          } else {
            mv.visitTypeInsn(NEW, fieldDesc[i].impl);
            mv.visitInsn(DUP);
            mv.visitLdcInsn(fieldDesc[i].dims[0]);
            mv.visitMethodInsn(INVOKESPECIAL, fieldDesc[i].impl, "<init>", "(J)V", itf);
            mv.visitVarInsn(ASTORE, 1);
            mv.visitTypeInsn(NEW, "com/ibm/layout/Location");
            mv.visitInsn(DUP);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(
                GETFIELD, this.implClassName, "location", "Lcom/ibm/layout/Location;");
            mv.visitLdcInsn(fieldDesc[i].offset);
            if (wayPointCounter > 0) {
              mv.visitVarInsn(ALOAD, 0);
              mv.visitMethodInsn(
                  INVOKESPECIAL, implClassName, "waypoint" + (wayPointCounter - 1), "()J", false);
              mv.visitInsn(LADD);
            }
            mv.visitMethodInsn(
                INVOKESPECIAL,
                "com/ibm/layout/Location",
                "<init>",
                "(Lcom/ibm/layout/Location;J)V",
                itf);
            mv.visitVarInsn(ASTORE, 2);
            mv.visitVarInsn(ALOAD, 1);
            mv.visitVarInsn(ALOAD, 2);
            mv.visitMethodInsn(
                INVOKEVIRTUAL,
                fieldDesc[i].impl,
                "bindLocation",
                "(Lcom/ibm/layout/Location;)V",
                itf);
            mv.visitVarInsn(ALOAD, 1);
            mv.visitInsn(ARETURN);
            mv.visitMaxs(5, 3);
            mv.visitEnd();
          }
        } else if (fieldDesc[i].dims.length == 2) {
          if ("" != fieldDesc[i].elementImpl) {
            mv =
                cw.visitMethod(
                    ACC_PUBLIC,
                    fieldDesc[i].name,
                    "()" + fieldDesc[i].sig,
                    "()" + fieldDesc[i].sigGeneric,
                    null);
            mv.visitCode();
            mv.visitTypeInsn(NEW, fieldDesc[i].elementImpl);
            mv.visitInsn(DUP);
            mv.visitMethodInsn(INVOKESPECIAL, fieldDesc[i].elementImpl, "<init>", "()V", itf);
            mv.visitVarInsn(ASTORE, 1);
            mv.visitTypeInsn(NEW, fieldDesc[i].impl);
            mv.visitInsn(DUP);
            mv.visitLdcInsn(fieldDesc[i].dims[0]);
            mv.visitLdcInsn(fieldDesc[i].dims[1]);
            mv.visitVarInsn(ALOAD, 1);
            mv.visitMethodInsn(INVOKEVIRTUAL, fieldDesc[i].elementImpl, "sizeof", "()J", itf);
            mv.visitMethodInsn(INVOKESPECIAL, fieldDesc[i].impl, "<init>", "(JJJ)V", itf);
            mv.visitVarInsn(ASTORE, 2);
            mv.visitTypeInsn(NEW, "com/ibm/layout/Location");
            mv.visitInsn(DUP);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(
                GETFIELD, this.implClassName, "location", "Lcom/ibm/layout/Location;");
            mv.visitLdcInsn(fieldDesc[i].offset);
            if (wayPointCounter > 0) {
              mv.visitVarInsn(ALOAD, 0);
              mv.visitMethodInsn(
                  INVOKESPECIAL, implClassName, "waypoint" + (wayPointCounter - 1), "()J", false);
              mv.visitInsn(LADD);
            }
            mv.visitMethodInsn(
                INVOKESPECIAL,
                "com/ibm/layout/Location",
                "<init>",
                "(Lcom/ibm/layout/Location;J)V",
                itf);
            mv.visitVarInsn(ASTORE, 3);
            mv.visitVarInsn(ALOAD, 2);
            mv.visitVarInsn(ALOAD, 3);
            mv.visitMethodInsn(
                INVOKEVIRTUAL,
                fieldDesc[i].impl,
                "bindLocation",
                "(Lcom/ibm/layout/Location;)V",
                itf);
            mv.visitVarInsn(ALOAD, 2);
            mv.visitInsn(ARETURN);
            mv.visitMaxs(8, 4);
            mv.visitEnd();
          } else {
            mv =
                cw.visitMethod(
                    ACC_PUBLIC,
                    fieldDesc[i].name,
                    "()" + fieldDesc[i].sig,
                    "()" + fieldDesc[i].sigGeneric,
                    null);
            mv.visitCode();
            mv.visitTypeInsn(NEW, fieldDesc[i].impl);
            mv.visitInsn(DUP);
            mv.visitLdcInsn(fieldDesc[i].dims[0]);
            mv.visitLdcInsn(fieldDesc[i].dims[1]);
            mv.visitMethodInsn(INVOKESPECIAL, fieldDesc[i].impl, "<init>", "(JJ)V", itf);
            mv.visitVarInsn(ASTORE, 1);
            mv.visitTypeInsn(NEW, "com/ibm/layout/Location");
            mv.visitInsn(DUP);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(
                GETFIELD, this.implClassName, "location", "Lcom/ibm/layout/Location;");
            mv.visitLdcInsn(fieldDesc[i].offset);
            if (wayPointCounter > 0) {
              mv.visitVarInsn(ALOAD, 0);
              mv.visitMethodInsn(
                  INVOKESPECIAL, implClassName, "waypoint" + (wayPointCounter - 1), "()J", false);
              mv.visitInsn(LADD);
            }
            mv.visitMethodInsn(
                INVOKESPECIAL,
                "com/ibm/layout/Location",
                "<init>",
                "(Lcom/ibm/layout/Location;J)V",
                itf);
            mv.visitVarInsn(ASTORE, 2);
            mv.visitVarInsn(ALOAD, 1);
            mv.visitVarInsn(ALOAD, 2);
            mv.visitMethodInsn(
                INVOKEVIRTUAL,
                fieldDesc[i].impl,
                "bindLocation",
                "(Lcom/ibm/layout/Location;)V",
                itf);
            mv.visitVarInsn(ALOAD, 1);
            mv.visitInsn(ARETURN);
            mv.visitMaxs(6, 3);
            mv.visitEnd();
          }
        }
      }
      {
        boolean primitivePointer = ImplHelper.isTypePrimitive(fieldDesc[i].sig);
        eaMV =
            eaCW.visitMethod(
                ACC_PUBLIC,
                fieldDesc[i].name,
                primitivePointer
                    ? "()L" + fieldDesc[i].pointerSig + ";"
                    : "()Lcom/ibm/layout/Pointer;",
                primitivePointer ? null : "()L" + fieldDesc[i].pointerSig + ";",
                null);
        eaMV.visitCode();
        if (primitivePointer) {
          eaMV.visitFieldInsn(
              GETSTATIC,
              "java/lang/" + ImplHelper.fieldSig2MethodTypeLongForm(fieldDesc[i].sig),
              "TYPE",
              "Ljava/lang/Class;");
          eaMV.visitMethodInsn(
              INVOKESTATIC,
              "com/ibm/layout/LayoutType",
              "getPrimPointer",
              "(Ljava/lang/Class;)Lcom/ibm/layout/LayoutType;",
              true);
          eaMV.visitTypeInsn(CHECKCAST, fieldDesc[i].pointerSig);
        } else {
          if (null != fieldDesc[i].element) {
            eaMV.visitLdcInsn(Type.getType("L" + fieldDesc[i].element.replace(".", "/") + ";"));
          } else {
            eaMV.visitLdcInsn(Type.getType(fieldDesc[i].sig));
          }
          eaMV.visitMethodInsn(
              INVOKESTATIC,
              "com/ibm/layout/LayoutType",
              "getPointer",
              "(Ljava/lang/Class;)Lcom/ibm/layout/Pointer;",
              true);
        }
        eaMV.visitVarInsn(ASTORE, 1);
        eaMV.visitVarInsn(ALOAD, 1);
        eaMV.visitTypeInsn(NEW, "com/ibm/layout/Location");
        eaMV.visitInsn(DUP);
        eaMV.visitVarInsn(ALOAD, 0);
        eaMV.visitFieldInsn(
            GETFIELD, implClassName + "$EffectiveAddressImpl", "this$0", "L" + implClassName + ";");
        eaMV.visitMethodInsn(
            INVOKESTATIC,
            implClassName,
            "access$0",
            "(L" + implClassName + ";)Lcom/ibm/layout/Location;",
            false);
        if (startWayPointCounter > 0) {
          eaMV.visitVarInsn(ALOAD, 0);
          eaMV.visitFieldInsn(
              GETFIELD,
              implClassName + "$EffectiveAddressImpl",
              "this$0",
              "L" + implClassName + ";");
          eaMV.visitMethodInsn(
              INVOKESTATIC,
              implClassName,
              "access$" + (startWayPointCounter),
              "(L" + implClassName + ";)J",
              false);
        }
        eaMV.visitLdcInsn(new Long(fieldDesc[i].offset));
        if (startWayPointCounter > 0) {
          eaMV.visitInsn(LADD);
        }
        eaMV.visitMethodInsn(
            INVOKESPECIAL,
            "com/ibm/layout/Location",
            "<init>",
            "(Lcom/ibm/layout/Location;J)V",
            false);
        if (primitivePointer) {
          eaMV.visitMethodInsn(
              INVOKEINTERFACE,
              "com/ibm/layout/" + ImplHelper.fieldSig2MethodType(fieldDesc[i].sig) + "Pointer",
              "bindLocation",
              "(Lcom/ibm/layout/Location;)V",
              true);
        } else {
          eaMV.visitMethodInsn(
              INVOKEINTERFACE,
              "com/ibm/layout/Pointer",
              "bindLocation",
              "(Lcom/ibm/layout/Location;)V",
              true);
        }
        eaMV.visitVarInsn(ALOAD, 1);
        eaMV.visitInsn(ARETURN);
        if (startWayPointCounter > 0) {
          eaMV.visitMaxs(8, 2);
        } else {
          eaMV.visitMaxs(6, 2);
        }
        eaMV.visitEnd();
      }
    }

    {
      mv = cw.visitMethod(ACC_PUBLIC, "copyFrom", "(L" + implClassName + ";)V", null, null);
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitVarInsn(ALOAD, 1);
      mv.visitMethodInsn(
          INVOKESPECIAL, implClassName, "copyFrom", "(Lcom/ibm/layout/Layout;)V", itf);
      mv.visitInsn(RETURN);
      mv.visitMaxs(2, 2);
      mv.visitEnd();
    }
    {
      mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
      mv.visitCode();
      mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
      mv.visitInsn(DUP);
      mv.visitLdcInsn("(");
      mv.visitMethodInsn(
          INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false);
      for (int i = 0; i < fieldDesc.length; i++) {
        if (ImplHelper.isTypePrimitive(fieldDesc[i].sig)) {
          mv.visitLdcInsn(fieldDesc[i].name + ": ");
          mv.visitMethodInsn(
              INVOKEVIRTUAL,
              "java/lang/StringBuilder",
              "append",
              "(Ljava/lang/String;)Ljava/lang/StringBuilder;",
              false);
          mv.visitVarInsn(ALOAD, 0);
          mv.visitMethodInsn(
              INVOKEVIRTUAL, implClassName, fieldDesc[i].name, "()" + fieldDesc[i].sig, false);
          mv.visitMethodInsn(
              INVOKEVIRTUAL,
              "java/lang/StringBuilder",
              "append",
              "(" + ImplHelper.getByteCodeSig(fieldDesc[i].sig) + ")Ljava/lang/StringBuilder;",
              false);
          if (i < (fieldDesc.length - 1)) {
            mv.visitLdcInsn(", ");
            mv.visitMethodInsn(
                INVOKEVIRTUAL,
                "java/lang/StringBuilder",
                "append",
                "(Ljava/lang/String;)Ljava/lang/StringBuilder;",
                false);
          }
        } else {
          mv.visitVarInsn(ALOAD, 0);
          mv.visitMethodInsn(
              INVOKEVIRTUAL, implClassName, fieldDesc[i].name, "()" + fieldDesc[i].sig, false);
          mv.visitMethodInsn(
              INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;", false);
          mv.visitMethodInsn(
              INVOKEVIRTUAL,
              "java/lang/StringBuilder",
              "append",
              "(Ljava/lang/String;)Ljava/lang/StringBuilder;",
              false);
        }
      }
      mv.visitLdcInsn(")");
      mv.visitMethodInsn(
          INVOKEVIRTUAL,
          "java/lang/StringBuilder",
          "append",
          "(Ljava/lang/String;)Ljava/lang/StringBuilder;",
          false);
      mv.visitMethodInsn(
          INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
      mv.visitInsn(ARETURN);
      mv.visitMaxs(3, 1);
      mv.visitEnd();
    }

    if (isVariableLengthLayout > 0) {
      mv = cw.visitMethod(ACC_PUBLIC, "sizeof", "()J", null, null);
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(
          INVOKESPECIAL, implClassName, "waypoint" + (wayPointCounter - 1), "()J", false);
      mv.visitLdcInsn(new Long(getClassSize(fieldDesc)));
      mv.visitInsn(LADD);
      mv.visitInsn(LRETURN);
      mv.visitMaxs(4, 1);
      mv.visitEnd();
    } else {
      mv = cw.visitMethod(ACC_PUBLIC, "sizeof", "()J", null, null);
      mv.visitCode();
      mv.visitLdcInsn(new Long(getClassSize(fieldDesc)));
      mv.visitInsn(LRETURN);
      mv.visitMaxs(2, 1);
      mv.visitEnd();
    }
    {
      mv =
          cw.visitMethod(
              ACC_PUBLIC, "EA", "()L" + interfaceClassName + "$EffectiveAddress;", null, null);
      mv.visitCode();
      mv.visitTypeInsn(NEW, implClassName + "$EffectiveAddressImpl");
      mv.visitInsn(DUP);
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(
          INVOKESPECIAL,
          implClassName + "$EffectiveAddressImpl",
          "<init>",
          "(L" + implClassName + ";)V",
          false);
      mv.visitInsn(ARETURN);
      mv.visitMaxs(3, 1);
      mv.visitEnd();
    }
    {
      mv =
          cw.visitMethod(
              ACC_STATIC + ACC_SYNTHETIC,
              "access$0",
              "(L" + implClassName + ";)Lcom/ibm/layout/Location;",
              null,
              null);
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(
          INVOKESPECIAL, implClassName, "getLocation", "()Lcom/ibm/layout/Location;", false);
      mv.visitInsn(ARETURN);
      mv.visitMaxs(1, 1);
      mv.visitEnd();
    }
    {
      mv =
          cw.visitMethod(
              ACC_PRIVATE + ACC_FINAL, "getLocation", "()Lcom/ibm/layout/Location;", null, null);
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitFieldInsn(GETFIELD, implClassName, "location", "Lcom/ibm/layout/Location;");
      mv.visitInsn(ARETURN);
      mv.visitMaxs(1, 1);
      mv.visitEnd();
    }
    if (isVariableLengthLayout == 1) {
      if (fieldDesc[fieldDesc.length - 1].repeatCountMember == null) {
        // not fixed header var tail
        isVariableLengthLayout++;
      }
    }

    ImplHelper.genLayoutTypeImpl(cw, mv, fv, implClassName, isVariableLengthLayout, false);
    ImplHelper.getLayoutImpl(cw, mv, implClassName);

    cw.visitEnd();

    return cw.toByteArray();
  }
Example #14
0
  public static byte[] createPojo(
      String className, ASMProperty[] properties, Class parent, Class[] interfaces, String srcName)
      throws PageException {
    className = className.replace('.', '/');
    className = className.replace('\\', '/');
    className = ListUtil.trim(className, "/");
    String[] inter = null;
    if (interfaces != null) {
      inter = new String[interfaces.length];
      for (int i = 0; i < inter.length; i++) {
        inter[i] = interfaces[i].getName().replace('.', '/');
      }
    }
    // CREATE CLASS
    ClassWriter cw = ASMUtil.getClassWriter();
    cw.visit(
        Opcodes.V1_6,
        Opcodes.ACC_PUBLIC,
        className,
        null,
        parent.getName().replace('.', '/'),
        inter);
    String md5;
    try {
      md5 = createMD5(properties);
    } catch (Throwable t) {
      md5 = "";
      t.printStackTrace();
    }

    FieldVisitor fv =
        cw.visitField(
            Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC,
            "_md5_",
            "Ljava/lang/String;",
            null,
            md5);
    fv.visitEnd();

    // Constructor
    GeneratorAdapter adapter =
        new GeneratorAdapter(Opcodes.ACC_PUBLIC, CONSTRUCTOR_OBJECT, null, null, cw);
    adapter.loadThis();
    adapter.invokeConstructor(toType(parent, true), CONSTRUCTOR_OBJECT);
    adapter.returnValue();
    adapter.endMethod();

    // properties
    for (int i = 0; i < properties.length; i++) {
      createProperty(cw, className, properties[i]);
    }

    // complexType src
    if (!StringUtil.isEmpty(srcName)) {
      GeneratorAdapter _adapter =
          new GeneratorAdapter(
              Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC,
              _SRC_NAME,
              null,
              null,
              cw);
      _adapter.push(srcName);
      _adapter.returnValue();
      _adapter.endMethod();
    }

    cw.visitEnd();
    return cw.toByteArray();
  }
 @Override
 public void visitEnd() {
   checkEnd();
   end = true;
   super.visitEnd();
 }
  public static byte[] generate(EventClassModel model) {
    ClassWriter cwriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);

    ClassVisitor cw;
    if (TRACE) {
      cw = new TraceClassVisitor(cwriter, new ASMifier(), new PrintWriter(System.out));
      cw = new CheckClassAdapter(cw);
    } else {
      cw = cwriter;
    }

    FieldVisitor fv;
    MethodVisitor mv;

    String concreteClassName =
        model.getRootPackageInternalPrefix() + "event/" + model.technicalNameCapitalized + "Event";
    String className =
        model.isCustomized
            ? model.getRootPackageInternalPrefix()
                + "event/Abstract"
                + model.technicalNameCapitalized
                + "Event"
            : concreteClassName;

    cw.visit(
        V1_7,
        ACC_PUBLIC + ACC_SUPER + (model.isCustomized ? ACC_ABSTRACT : 0),
        className,
        null,
        "org/instantlogic/interaction/flow/impl/SimpleFlowEvent",
        null);

    // public static final HomeEvent
    {
      fv =
          cw.visitField(
              ACC_PUBLIC + ACC_FINAL + ACC_STATIC,
              "INSTANCE",
              "L" + concreteClassName + ";",
              null,
              null);
      fv.visitEnd();
    }

    {
      mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null);
      mv.visitCode();

      // INSTANCE = new HomeEvent();
      mv.visitTypeInsn(NEW, concreteClassName);
      mv.visitInsn(DUP);
      mv.visitMethodInsn(INVOKESPECIAL, concreteClassName, "<init>", "()V");
      mv.visitFieldInsn(PUTSTATIC, className, "INSTANCE", "L" + concreteClassName + ";");

      mv.visitInsn(RETURN);
      mv.visitMaxs(9, 99);
      mv.visitEnd();
    }
    // Default synthetic constructor
    {
      mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitLdcInsn(model.name);
      mv.visitIntInsn(BIPUSH, model.parameters.size());
      mv.visitTypeInsn(ANEWARRAY, "org/instantlogic/fabric/model/Entity");
      int i = 0;
      for (String parameter : model.parameters) {
        mv.visitInsn(DUP);
        mv.visitIntInsn(BIPUSH, i);
        mv.visitFieldInsn(
            GETSTATIC,
            model.getRootPackageInternalPrefix() + "entity/" + parameter + "Entity",
            "INSTANCE",
            "L" + model.getRootPackageInternalPrefix() + "entity/" + parameter + "Entity;");
        mv.visitInsn(AASTORE);
        i++;
      }
      mv.visitMethodInsn(
          INVOKESPECIAL,
          "org/instantlogic/interaction/flow/impl/SimpleFlowEvent",
          "<init>",
          "(Ljava/lang/String;[Lorg/instantlogic/fabric/model/Entity;)V");
      mv.visitInsn(RETURN);
      mv.visitMaxs(9, 99);
      mv.visitEnd();
    }

    cw.visitEnd();
    return cwriter.toByteArray();
  }
  public static <T> byte[] createTargetSetterClass(
      String className,
      DelayedCellSetterFactory<T, ?>[] delayedCellSetters,
      CellSetter<T>[] setters,
      Type type,
      boolean ignoreException,
      int maxMethodSize)
      throws Exception {

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);

    FieldVisitor fv;
    MethodVisitor mv;

    final String targetType = AsmUtils.toType(type);
    final String classType = AsmUtils.toType(className);

    cw.visit(
        V1_6,
        ACC_FINAL + ACC_PUBLIC + ACC_SUPER,
        classType,
        "L" + CSV_CELL_MAPPER_TYPE + "<L" + targetType + ";>;",
        CSV_CELL_MAPPER_TYPE,
        null);

    // declare fields
    for (int i = 0; i < delayedCellSetters.length; i++) {
      if (delayedCellSetters[i] != null) {
        fv =
            cw.visitField(
                ACC_PROTECTED + ACC_FINAL,
                "delayedCellSetter" + i,
                AsmUtils.toDeclaredLType(DELAYED_CELL_SETTER_TYPE),
                "L" + DELAYED_CELL_SETTER_TYPE + "<L" + targetType + ";*>;",
                null);
        fv.visitEnd();
      }
    }

    for (int i = 0; i < setters.length; i++) {
      if (setters[i] != null) {
        fv =
            cw.visitField(
                ACC_PROTECTED + ACC_FINAL,
                "setter" + i,
                AsmUtils.toDeclaredLType(CELL_SETTER_TYPE),
                "L" + CELL_SETTER_TYPE + "<L" + targetType + ";>;",
                null);
        fv.visitEnd();
      }
    }
    appendInit(delayedCellSetters, setters, cw, targetType, classType, maxMethodSize);

    appendDelayedCellValue(delayedCellSetters, ignoreException, cw, classType);
    append_delayedCellValue(delayedCellSetters, cw, classType, maxMethodSize);

    appendCellValue(setters, ignoreException, cw, classType);
    append_cellValue(delayedCellSetters, setters, cw, classType, maxMethodSize);

    appendApplyDelayedSetter(delayedCellSetters, ignoreException, cw, classType, maxMethodSize);
    appendApplyDelayedCellSetterN(delayedCellSetters, cw, classType);

    appendGetDelayedCellSetter(delayedCellSetters, cw, targetType, classType, maxMethodSize);
    appendPeekDelayedCellSetterValue(delayedCellSetters, cw, classType, maxMethodSize);

    cw.visitEnd();

    return AsmUtils.writeClassToFile(className, cw.toByteArray());
  }
 protected void injectFieldTable(ClassWriter classWriter) {
   FieldVisitor fieldVisitor =
       classWriter.visitField(
           ACC_PRIVATE + ACC_FINAL, "fieldTable", "[Ljava/lang/reflect/Field;", null, null);
   fieldVisitor.visitEnd();
 }
 @Override
 public AnnotationVisitor visit(String annotationTypeDescriptor, boolean visible) {
   return fieldVisitor.visitAnnotation(annotationTypeDescriptor, visible);
 }
 @Override
 public AnnotationVisitor visit(
     String annotationTypeDescriptor, boolean visible, int typeReference, String typePath) {
   return fieldVisitor.visitTypeAnnotation(
       typeReference, TypePath.fromString(typePath), annotationTypeDescriptor, visible);
 }
Example #21
0
 public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
   return AnnotationVisitorTee.getInstance(
       fv1.visitAnnotation(desc, visible), fv2.visitAnnotation(desc, visible));
 }
 @Override
 public boolean equals(Object other) {
   return this == other
       || !(other == null || getClass() != other.getClass())
           && fieldVisitor.equals(((OnField) other).fieldVisitor);
 }
Example #23
0
 public void visitEnd() {
   fv1.visitEnd();
   fv2.visitEnd();
 }
Example #24
0
 public void accept(FieldVisitor fv) {
   AnnotationVisitor av = fv.visitAnnotation(type, visible);
   accept(items, av);
   av.visitEnd();
 }