Package org.deuce.objectweb.asm

Examples of org.deuce.objectweb.asm.MethodVisitor


  }
 
  @Override
  public MethodVisitor visitMethod( int access, String name, String desc,
      String signature, String[] exceptions) {
    MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
    return new MethodTransformer( mv, access, name, desc, signature, exceptions, this);
  }
View Full Code Here


  HashMap<Object, ArrayList<Object>> rmd;

  @Override
  public MethodVisitor visitMethod(int access, String name, String desc,
      String signature, String[] exceptions) {
    MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
    return new JSRInlinerAdapter(mv, access, name, desc, signature, exceptions);
  }
View Full Code Here

  }
 
  @Override
  public MethodVisitor visitMethod(int access, String name, String desc, String signature,
      String[] exceptions) {
    MethodVisitor originalMethod =  super.visitMethod(access, name, desc, signature, exceptions);

    if(!Boolean.getBoolean("instrument"))
      return originalMethod;
   
    if(!distinguishable)
View Full Code Here

      cv.visitInnerClass(name, outerName, innerName, access);
  }

  public MethodVisitor visitMethod(int access, String name, String desc,
      String signature, String[] exceptions) {
    MethodVisitor t = null;
    for (ClassVisitor cv : cvs)
      t = cv.visitMethod(access, name, desc, signature, exceptions);
    return t;
  }
View Full Code Here

   
    //Check if it is a default Constructor
    if(name.equals("<init>") && desc.equals("()V"))   
        defaultConstructor = true;

    MethodVisitor originalMethod =  super.visitMethod(access, name, desc, signature, exceptions);
       
    if( exclude || donotTouch)      //If excluded Class or Immutable Method No Transformation
      return originalMethod;
   
    if(callWriter)
      return originalMethod;
   
    final boolean isNative = (access & Opcodes.ACC_NATIVE) != 0;
    if(isNative){
      createNativeMethod(access, name, desc, signature, exceptions);
      return originalMethod;
    }
   
    if( name.equals("<clinit>") && !mobile) {
      return originalMethod;     
    }else if(name.equals("<clinit>") && mobile){   
      staticMethod = originalMethod;
      visitclinit = true;

      if( isInterface){
        return originalMethod;
      }

      int fieldAccess = Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC;
      fieldsHolder.addField( fieldAccess, StaticMethodTransformer.CLASS_BASE,
          Type.getDescriptor(Object.class), null);
     
      MethodVisitor staticMethodVisitor = fieldsHolder.getStaticMethodVisitor();
      return createStaticMethodTransformer( originalMethod, staticMethodVisitor);
    }
   
    if( name.equals("<init>") && !mobile){
      return originalMethod;
   
    else if( name.equals("<init>") && mobile){      //To add additional Registration block
      int argSize = Type.getArgumentsAndReturnSizes(desc);
      return new RemoteConstructorTransformer(originalMethod, argSize);
    }
   
    //TODO: It is not required, remove it: Code to check the getter and setter methods exist   
    for(GetterSetterDetails fnm: FieldNames){
      if(name.equals("set"+getUpperCaseName(fnm.fD.VarName)))
        fnm.sttrXst = true;
      if(name.equals("get"+getUpperCaseName(fnm.fD.VarName)))
        fnm.gttrXst=true;       
    }
   
    //Add context variable for copy method arguments
    Method newMethod = createNewMethod(name, desc);

    MethodVisitor copyMethod =  super.visitMethod(access | Opcodes.ACC_SYNTHETIC, name, newMethod.getDescriptor(),
        signature, exceptions);

    return new MethodTransformer( originalMethod, copyMethod, className,
        access, name, desc, newMethod, fieldsHolder);
  }
View Full Code Here

   */
  private void createNativeMethod(int access, String name, String desc,
      String signature, String[] exceptions) {
    Method newMethod = createNewMethod(name, desc);
    final int newAccess = access & ~Opcodes.ACC_NATIVE;
    MethodVisitor copyMethod =  super.visitMethod(newAccess | Opcodes.ACC_SYNTHETIC, name, newMethod.getDescriptor(),
        signature, exceptions);
    copyMethod.visitCode();
   
    // load the arguments before calling the original method
    final boolean isStatic = (access & ~Opcodes.ACC_STATIC) != 0;
    int place = 0; // place on the stack
    if(!isStatic){
      copyMethod.visitVarInsn(Opcodes.ALOAD, 0); // load this
      place = 1;
    }
   
    Type[] argumentTypes = newMethod.getArgumentTypes();
    for(int i=0 ; i<(argumentTypes.length-1) ; ++i){
      Type type = argumentTypes[i];
      copyMethod.visitVarInsn(type.getOpcode(Opcodes.ILOAD), place);
      place += type.getSize();
    }
   
    // call the original method
    copyMethod.visitMethodInsn(isStatic ? Opcodes.INVOKESTATIC : Opcodes.INVOKEVIRTUAL, className, name, desc);
    TypeCodeResolver returnReolver = TypeCodeResolverFactory.getReolver(newMethod.getReturnType());
    if( returnReolver == null) {
      copyMethod.visitInsn( Opcodes.RETURN); // return;
    }else {
      copyMethod.visitInsn(returnReolver.returnCode());
    }
    copyMethod.visitMaxs(1, 1);
    copyMethod.visitEnd();
  }
View Full Code Here

      super.visitAnnotation(EXCLUDE_DESC, false);
      if( !visitclinit && fields.size() > 0) { // creates a new <clinit> in case we didn't see one already.

        //TODO avoid creating new static method in case of external fields holder
        visitclinit = true;
        MethodVisitor method = visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null);
        method.visitCode();
        method.visitInsn(Opcodes.RETURN);
        method.visitMaxs(100, 100); // TODO set the right value
        method.visitEnd();

      }
      if(isEnum){ // Build a dummy ordinal() method
        MethodVisitor ordinalMethod =
          super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, "ordinal", "(Lorg/deuce/transaction/Context;)I", null, null);
        ordinalMethod.visitCode();
        ordinalMethod.visitVarInsn(Opcodes.ALOAD, 0);
        ordinalMethod.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, "ordinal", "()I");
        ordinalMethod.visitInsn(Opcodes.IRETURN);
        ordinalMethod.visitMaxs(1, 2);
        ordinalMethod.visitEnd();
      }
    }
   
    //Add Getter and setters
    for (GetterSetterDetails gSD : FieldNames) {
      if (gSD.gttrXst == false){
        MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "get"+gSD.fD.VarName, Type.getMethodDescriptor(Type.getType(gSD.fD.VarDesc), new Type[]{}),
          null, null);
        GetterSetterCode.addGttrCode(gSD, mv,className); // Add super.visitMethod
      }
      if (gSD.sttrXst == false){
        MethodVisitor mv1 = super.visitMethod(Opcodes.ACC_PUBLIC, "set"+gSD.fD.VarName, Type.getMethodDescriptor(Type.VOID_TYPE, new Type[]{Type.getType(gSD.fD.VarDesc)}),
            null, null);
        GetterSetterCode.addSttrCode(gSD, mv1,className);         
      }
    }
   
View Full Code Here

import edu.vt.rt.hyflow.core.tm.control.ControlContext;

public class ProxyInterface implements Opcodes{

  public static void addCode(ArrayList<Object>rmdtl, ClassVisitor cw) {
    MethodVisitor mv;
    if(rmdtl == null){
      System.err.println("Trying to Write the Proxy Remote Method without any Details, Not Supported Currently");
    }
    else{
      for(Object md : rmdtl){
        MethodDetails mD = (MethodDetails) md;
        //Get new Arguments
        Type[] src = Type.getArgumentTypes(mD.desc);
        Type rType = Type.getReturnType(mD.desc);
        Type[] mdesc = new Type[src.length + 2];
        mdesc[0] = Type.getType(Object.class);
        mdesc[1] = Type.getType(ControlContext.class);
        System.arraycopy(src, 0, mdesc, 2, src.length);
       
        //Get new Exceptions
        String[] exceptions;
        if(mD.exceptions != null){
          exceptions = new String[mD.exceptions.length + 1];
          exceptions[0] = "java/rmi/RemoteException";
          System.arraycopy(mD.exceptions, 0, exceptions, 1, mD.exceptions.length);       
        }else{
          String[] exceptions1 = {"java/rmi/RemoteException"};
          exceptions = exceptions1;
        }
       
        String desc = Type.getMethodDescriptor(rType, mdesc);
        mv = cw.visitMethod(ACC_PUBLIC+ACC_ABSTRACT, mD.name, desc, null, exceptions);
        mv.visitEnd();
      }       
    }   
  }
View Full Code Here

    if(urmdtl == null){
      return;
    }
   
    FieldVisitor fv;
    MethodVisitor mv;
   
    //Add Fields
    fv = cw.visitField(ACC_PRIVATE + Opcodes.ACC_FINAL + ACC_STATIC, Names.SerialVersionUID, "J", null, new Long(1L));
    fv.visitEnd();
       
    fv = cw.visitField(0, "locator", Type.getObjectType(Names.AlephDirectoryManager).getDescriptor(), null, null);
    fv.visitEnd();
   
    //Add Constructor
    {
      mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, new String[] { Names.RMIException });
      mv.visitCode();
      Label l0 = new Label();
      Label l1 = new Label();
      Label l2 = new Label();
      mv.visitTryCatchBlock(l0, l1, l2, Names.RMIException);
      Label l3 = new Label();
      Label l4 = new Label();
      Label l5 = new Label();
      mv.visitTryCatchBlock(l3, l4, l5, Names.Exception);
      Label l6 = new Label();
      mv.visitLabel(l6);
      //Call Super Class
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKESPECIAL, Names.UniCastObject, "<init>", "()V");
      Label l7 = new Label();
      mv.visitLabel(l7);
 
      mv.visitMethodInsn(INVOKESTATIC, Names.Hyflow, "getLocator", Type.getMethodDescriptor(Type.getType(DirectoryManager.class), new Type [] {})); //"()Laleph/dir/DirectoryManager;");
      mv.visitTypeInsn(CHECKCAST, Names.ControlFlowDirectory);
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKEVIRTUAL, Names.ControlFlowDirectory, "addProxy", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {Type.getType(Object.class)})); //"(Ljava/lang/Object;)V");
      Label l8 = new Label();
      mv.visitLabel(l8);
 
      mv.visitMethodInsn(INVOKESTATIC, Names.System, "getSecurityManager", Type.getMethodDescriptor(Type.getType(SecurityManager.class), new Type[]{}));//"()Ljava/lang/SecurityManager;");
      Label l9 = new Label();
      mv.visitJumpInsn(IFNONNULL, l9);
      Label l10 = new Label();
      mv.visitLabel(l10);
 
      mv.visitTypeInsn(NEW, Names.RMISecurityManager);
      mv.visitInsn(DUP);
      mv.visitMethodInsn(INVOKESPECIAL, Names.RMISecurityManager, "<init>", "()V");
      mv.visitMethodInsn(INVOKESTATIC, Names.System, "setSecurityManager", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {Type.getType(SecurityManager.class)}));//"(Ljava/lang/SecurityManager;)V");
      mv.visitLabel(l9);
   
      mv.visitFrame(Opcodes.F_FULL, 1, new Object[] {proxyName}, 0, new Object[] {});
      mv.visitMethodInsn(INVOKESTATIC, Names.HyflowNetwork, "getInstance", Type.getMethodDescriptor(Type.getType(Network.class), new Type[]{}));//"()Ledu/vt/rt/hyflow/util/network/Network;");
      mv.visitMethodInsn(INVOKEVIRTUAL, Names.HyflowNetwork, "getPort", "()I");
      mv.visitIntInsn(SIPUSH, 1000);
      mv.visitInsn(IADD);
      mv.visitVarInsn(ISTORE, 1);
      Label l11 = new Label();
      mv.visitLabel(l11);
 
      mv.visitInsn(ACONST_NULL);
      mv.visitVarInsn(ASTORE, 2);
      mv.visitLabel(l0);
 
      mv.visitVarInsn(ILOAD, 1);
      mv.visitMethodInsn(INVOKESTATIC, "java/rmi/registry/LocateRegistry", "createRegistry", "(I)Ljava/rmi/registry/Registry;");
      mv.visitVarInsn(ASTORE, 2);
      mv.visitLabel(l1);
      mv.visitJumpInsn(GOTO, l3);
      mv.visitLabel(l2);

      mv.visitFrame(Opcodes.F_FULL, 3, new Object[] {proxyName, Opcodes.INTEGER, "java/rmi/registry/Registry"}, 1, new Object[] {Names.RMIException});
      mv.visitVarInsn(ASTORE, 3);
      Label l12 = new Label();
      mv.visitLabel(l12);

      mv.visitVarInsn(ALOAD, 3);
      mv.visitMethodInsn(INVOKEVIRTUAL, Names.RMIException, "printStackTrace", "()V");
      mv.visitLabel(l3);

      mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
      mv.visitVarInsn(ALOAD, 0);
      mv.visitInsn(ICONST_1);
      mv.visitMethodInsn(INVOKESTATIC, Names.UniCastObject, "unexportObject", "(Ljava/rmi/Remote;Z)Z");
      mv.visitInsn(POP);
      mv.visitLabel(l4);
      Label l13 = new Label();
      mv.visitJumpInsn(GOTO, l13);
      mv.visitLabel(l5);

      mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"java/lang/Exception"});
      mv.visitVarInsn(ASTORE, 3);
      Label l14 = new Label();
      mv.visitLabel(l14);

      mv.visitLdcInsn("RMI unexporting");
      mv.visitMethodInsn(INVOKESTATIC, "edu/vt/rt/hyflow/util/io/Logger", "error", "(Ljava/lang/String;)V");
      mv.visitLabel(l13);

      mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
      mv.visitVarInsn(ALOAD, 0);
      mv.visitInsn(ICONST_0);
      mv.visitMethodInsn(INVOKESTATIC, "java/rmi/server/UnicastRemoteObject", "exportObject", "(Ljava/rmi/Remote;I)Ljava/rmi/Remote;");
      mv.visitTypeInsn(CHECKCAST, proxyIName);
      mv.visitVarInsn(ASTORE, 3);
      Label l15 = new Label();
      mv.visitLabel(l15);

      mv.visitVarInsn(ALOAD, 2);
      mv.visitLdcInsn(Type.getType("L"+className+";"));
      mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;");
      mv.visitVarInsn(ALOAD, 3);
      mv.visitMethodInsn(INVOKEINTERFACE, "java/rmi/registry/Registry", "rebind", "(Ljava/lang/String;Ljava/rmi/Remote;)V");
      Label l16 = new Label();
      mv.visitLabel(l16);

      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKESTATIC, "edu/vt/rt/hyflow/HyFlow", "getLocator", "()Laleph/dir/DirectoryManager;");
      mv.visitFieldInsn(PUTFIELD, proxyName, "locator", "Laleph/dir/DirectoryManager;");
      Label l17 = new Label();
      mv.visitLabel(l17);

      mv.visitInsn(RETURN);

      mv.visitMaxs(0, 0);
      mv.visitEnd()
    }
   
    //Add Methods
    for(RemoteMethodDetails mD: urmdtl){
      mv = cw.visitMethod(ACC_PUBLIC, mD.rmD.name, mD.rmD.desc, null, null);
      Type[] src = Type.getArgumentTypes(mD.rmD.desc);
      Type returnType = Type.getReturnType(mD.rmD.desc);
      int callerIndex = src.length + 1//1 for this
      mv.visitCode();
      Label l0 = new Label();
      mv.visitLabel(l0);
//      mv.visitLineNumber(56, l0);
      mv.visitVarInsn(ALOAD, 2);
      mv.visitMethodInsn(INVOKEVIRTUAL, Names.ControlflowInterface, "getLastExecuter", "()Laleph/comm/Address;");
      mv.visitVarInsn(ASTORE, callerIndex);
      Label l1 = new Label();
      mv.visitLabel(l1);

      mv.visitInsn(ICONST_1);
      mv.visitVarInsn(ALOAD, callerIndex);
      mv.visitMethodInsn(INVOKESTATIC, "edu/vt/rt/hyflow/util/network/Network", "linkDelay", "(ZLaleph/comm/Address;)V");
      Label l2 = new Label();
      mv.visitLabel(l2);

      mv.visitVarInsn(ALOAD, 2);
      mv.visitMethodInsn(INVOKEVIRTUAL, "edu/vt/rt/hyflow/core/tm/control/ControlContext", "getContextId", "()Ljava/lang/Long;");
      mv.visitMethodInsn(INVOKESTATIC, "edu/vt/rt/hyflow/core/tm/control/ControlContext", "getNeighbors", "(Ljava/lang/Long;)Ljava/util/Set;");
      mv.visitVarInsn(ALOAD, callerIndex);
      mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Set", "add", "(Ljava/lang/Object;)Z");
      mv.visitInsn(POP);
      Label l3 = new Label();
      mv.visitLabel(l3);

      mv.visitVarInsn(ALOAD, 0);
      mv.visitFieldInsn(GETFIELD, proxyName, "locator", "Laleph/dir/DirectoryManager;");
      mv.visitVarInsn(ALOAD, 2);
      mv.visitVarInsn(ALOAD, 1);
      mv.visitLdcInsn(mD.rmD.accessType);
      mv.visitInsn(ICONST_1);
      mv.visitMethodInsn(INVOKEVIRTUAL, "aleph/dir/DirectoryManager", "open", "(Lorg/deuce/transaction/AbstractContext;Ljava/lang/Object;Ljava/lang/String;Z)Ljava/lang/Object;");
      mv.visitTypeInsn(CHECKCAST, className);
      //Load All the remaining variables
      int i=1;   
      for(Type arg : src)
      {
        if(i == 1) ;               //No need to load Id
        else if(i == 2);            //Load Context at last
        else if(i <= src.length){
          if (arg.equals(Type.CHAR_TYPE) || arg.equals(Type.INT_TYPE)
              || arg.equals(Type.SHORT_TYPE)
              || arg.equals(Type.BYTE_TYPE)
              || arg.equals(Type.BOOLEAN_TYPE))
            mv.visitVarInsn(ILOAD, i);
          else if(arg.equals(Type.DOUBLE_TYPE))
            mv.visitVarInsn(DLOAD, i);
          else if(arg.equals(Type.LONG_TYPE))
            mv.visitVarInsn(LLOAD  , i);
          else if(arg.equals(Type.FLOAT_TYPE))
            mv.visitVarInsn(FLOAD, i);
          else
            mv.visitVarInsn(ALOAD, i);           
        }
        i++;
      }
      //Load Context Now
      mv.visitVarInsn(ALOAD, 2);
      mv.visitMethodInsn(INVOKEVIRTUAL, className, mD.dmD.name, mD.dmD.desc);
      //Return Value as Argument
      {
        if (returnType.equals(Type.CHAR_TYPE)
            || returnType.equals(Type.INT_TYPE)
            || returnType.equals(Type.SHORT_TYPE)
            || returnType.equals(Type.BYTE_TYPE)
            || returnType.equals(Type.BOOLEAN_TYPE))
          mv.visitInsn(IRETURN);
        else if(returnType.equals(Type.DOUBLE_TYPE))
          mv.visitInsn(DRETURN);
        else if(returnType.equals(Type.FLOAT_TYPE))
          mv.visitInsn(FRETURN);
        else if(returnType.equals(Type.LONG_TYPE))
          mv.visitInsn(LRETURN);
        else if(returnType.equals(Type.VOID_TYPE))
          mv.visitInsn(RETURN);
        else
          mv.visitInsn(ARETURN);
      }

      mv.visitMaxs(0, 0);
      mv.visitEnd();
    }
  }
View Full Code Here

     * @param cv a class visitor.
     */
    public void accept(final ClassVisitor cv) {
        String[] exceptions = new String[this.exceptions.size()];
        this.exceptions.toArray(exceptions);
        MethodVisitor mv = cv.visitMethod(access,
                name,
                desc,
                signature,
                exceptions);
        if (mv != null) {
View Full Code Here

TOP

Related Classes of org.deuce.objectweb.asm.MethodVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.