Package org.deuce.objectweb.asm

Examples of org.deuce.objectweb.asm.Type


    this.className = className;
    this.methodName = methodName;
    this.newMethod = newMethod;
    this.isStatic = isStatic;

    Type returnType = Type.getReturnType(descriptor);
    Type[] argumentTypes = Type.getArgumentTypes(descriptor);

    returnReolver = TypeCodeResolverFactory.getReolver(returnType);
    argumentReolvers = new TypeCodeResolver[ argumentTypes.length];
    for( int i=0; i< argumentTypes.length ; ++i) {
View Full Code Here


   
    //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);
      }
View Full Code Here

    mv.visitLdcInsn(method);
    mv.visitVarInsn(Opcodes.ALOAD, offset);

//    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, ITypeInternalName.REMOTE_CALLER, "execute", "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;");
   
    Type type = Type.getReturnType(desc);
    switch( type.getSort()) {
      case Type.VOID:
        mv.visitInsn(Opcodes.POP);
        mv.visitInsn(Opcodes.RETURN);
        break;
      case Type.BOOLEAN:
        mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Boolean");
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z");
        mv.visitInsn(Opcodes.IRETURN);
        break;
      case Type.BYTE:
        mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Byte");
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Byte", "byteValue", "()B");
        mv.visitInsn(Opcodes.IRETURN);
        break;
      case Type.CHAR:
        mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Char");
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Char", "charValue", "()C");
        mv.visitInsn(Opcodes.IRETURN);
        break;
      case Type.SHORT:
        mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Short");
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Short", "shortValue", "()S");
        mv.visitInsn(Opcodes.IRETURN);
        break;
      case Type.INT:
        mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Integer");
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I");
        mv.visitInsn(Opcodes.IRETURN);
        break;
      case Type.LONG:
        mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Long");
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J");
        mv.visitInsn(Opcodes.LRETURN);
        break;
      case Type.FLOAT:
        mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Float");
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Float", "floatValue", "()F");
        mv.visitInsn(Opcodes.FRETURN);
        break;
      case Type.DOUBLE:
        mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Double");
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D");
        mv.visitInsn(Opcodes.DRETURN);
        break;
      default:
        mv.visitTypeInsn(Opcodes.CHECKCAST, type.getInternalName());
        mv.visitInsn(Opcodes.ARETURN);
      break;
    }
   
    mv.visitLabel(l1);
View Full Code Here

      return null;
    }
    for(Object md: rmdtl){
      MethodDetails mD = (MethodDetails) md;
      Type[] src = Type.getArgumentTypes(mD.desc);
      Type rType = Type.getReturnType(mD.desc);
      //For Remote Method
      Type[] rmdesc = new Type[src.length + 2];
      rmdesc[0] = Type.getType(Object.class);
      rmdesc[1] = Type.getType(ControlContext.class);
      System.arraycopy(src, 0, rmdesc, 2, src.length);
View Full Code Here

        Frame handler = newFrame(m.maxLocals, m.maxStack);
        current.setReturn(interpreter.newValue(Type.getReturnType(m.desc)));
        Type[] args = Type.getArgumentTypes(m.desc);
        int local = 0;
        if ((m.access & ACC_STATIC) == 0) {
            Type ctype = Type.getObjectType(owner);
            current.setLocal(local++, interpreter.newValue(ctype));
        }
        for (int i = 0; i < args.length; ++i) {
            current.setLocal(local++, interpreter.newValue(args[i]));
            if (args[i].getSize() == 2) {
                current.setLocal(local++, interpreter.newValue(null));
            }
        }
        while (local < m.maxLocals) {
            current.setLocal(local++, interpreter.newValue(null));
        }
        merge(0, current, null);

        // control flow analysis
        while (top > 0) {
            int insn = queue[--top];
            Frame f = frames[insn];
            Subroutine subroutine = subroutines[insn];
            queued[insn] = false;

            AbstractInsnNode insnNode = null;
            try {
                insnNode = m.instructions.get(insn);
                int insnOpcode = insnNode.getOpcode();
                int insnType = insnNode.getType();

                if (insnType == AbstractInsnNode.LABEL
                        || insnType == AbstractInsnNode.LINE
                        || insnType == AbstractInsnNode.FRAME)
                {
                    merge(insn + 1, f, subroutine);
                    newControlFlowEdge(insn, insn + 1);
                } else {
                    current.init(f).execute(insnNode, interpreter);
                    subroutine = subroutine == null ? null : subroutine.copy();

                    if (insnNode instanceof JumpInsnNode) {
                        JumpInsnNode j = (JumpInsnNode) insnNode;
                        if (insnOpcode != GOTO && insnOpcode != JSR) {
                            merge(insn + 1, current, subroutine);
                            newControlFlowEdge(insn, insn + 1);
                        }
                        int jump = insns.indexOf(j.label);
                        if (insnOpcode == JSR) {
                            merge(jump, current, new Subroutine(j.label,
                                    m.maxLocals,
                                    j));
                        } else {
                            merge(jump, current, subroutine);
                        }
                        newControlFlowEdge(insn, jump);
                    } else if (insnNode instanceof LookupSwitchInsnNode) {
                        LookupSwitchInsnNode lsi = (LookupSwitchInsnNode) insnNode;
                        int jump = insns.indexOf(lsi.dflt);
                        merge(jump, current, subroutine);
                        newControlFlowEdge(insn, jump);
                        for (int j = 0; j < lsi.labels.size(); ++j) {
                            LabelNode label = (LabelNode) lsi.labels.get(j);
                            jump = insns.indexOf(label);
                            merge(jump, current, subroutine);
                            newControlFlowEdge(insn, jump);
                        }
                    } else if (insnNode instanceof TableSwitchInsnNode) {
                        TableSwitchInsnNode tsi = (TableSwitchInsnNode) insnNode;
                        int jump = insns.indexOf(tsi.dflt);
                        merge(jump, current, subroutine);
                        newControlFlowEdge(insn, jump);
                        for (int j = 0; j < tsi.labels.size(); ++j) {
                            LabelNode label = (LabelNode) tsi.labels.get(j);
                            jump = insns.indexOf(label);
                            merge(jump, current, subroutine);
                            newControlFlowEdge(insn, jump);
                        }
                    } else if (insnOpcode == RET) {
                        if (subroutine == null) {
                            throw new AnalyzerException(insnNode, "RET instruction outside of a sub routine");
                        }
                        for (int i = 0; i < subroutine.callers.size(); ++i) {
                            Object caller = subroutine.callers.get(i);
                            int call = insns.indexOf((AbstractInsnNode) caller);
                            if (frames[call] != null) {
                                merge(call + 1,
                                        frames[call],
                                        current,
                                        subroutines[call],
                                        subroutine.access);
                                newControlFlowEdge(insn, call + 1);
                            }
                        }
                    } else if (insnOpcode != ATHROW
                            && (insnOpcode < IRETURN || insnOpcode > RETURN))
                    {
                        if (subroutine != null) {
                            if (insnNode instanceof VarInsnNode) {
                                int var = ((VarInsnNode) insnNode).var;
                                subroutine.access[var] = true;
                                if (insnOpcode == LLOAD || insnOpcode == DLOAD
                                        || insnOpcode == LSTORE
                                        || insnOpcode == DSTORE)
                                {
                                    subroutine.access[var + 1] = true;
                                }
                            } else if (insnNode instanceof IincInsnNode) {
                                int var = ((IincInsnNode) insnNode).var;
                                subroutine.access[var] = true;
                            }
                        }
                        merge(insn + 1, current, subroutine);
                        newControlFlowEdge(insn, insn + 1);
                    }
                }

                List insnHandlers = handlers[insn];
                if (insnHandlers != null) {
                    for (int i = 0; i < insnHandlers.size(); ++i) {
                        TryCatchBlockNode tcb = (TryCatchBlockNode) insnHandlers.get(i);
                        Type type;
                        if (tcb.type == null) {
                            type = Type.getObjectType("java/lang/Throwable");
                        } else {
                            type = Type.getObjectType(tcb.type);
                        }
View Full Code Here

        }
        return v;
    }

    protected boolean isArrayValue(final Value value) {
        Type t = ((BasicValue) value).getType();
        return t != null
                && ("Lnull;".equals(t.getDescriptor()) || t.getSort() == Type.ARRAY);
    }
View Full Code Here

    }

    protected Value getElementValue(final Value objectArrayValue)
            throws AnalyzerException
    {
        Type arrayType = ((BasicValue) objectArrayValue).getType();
        if (arrayType != null) {
            if (arrayType.getSort() == Type.ARRAY) {
                return newValue(Type.getType(arrayType.getDescriptor()
                        .substring(1)));
            } else if ("Lnull;".equals(arrayType.getDescriptor())) {
                return objectArrayValue;
            }
        }
        throw new Error("Internal error");
    }
View Full Code Here

        }
        throw new Error("Internal error");
    }

    protected boolean isSubTypeOf(final Value value, final Value expected) {
        Type expectedType = ((BasicValue) expected).getType();
        Type type = ((BasicValue) value).getType();
        switch (expectedType.getSort()) {
            case Type.INT:
            case Type.FLOAT:
            case Type.LONG:
            case Type.DOUBLE:
                return type.equals(expectedType);
            case Type.ARRAY:
            case Type.OBJECT:
                if ("Lnull;".equals(type.getDescriptor())) {
                    return true;
                } else if (type.getSort() == Type.OBJECT
                        || type.getSort() == Type.ARRAY)
                {
                    return isAssignableFrom(expectedType, type);
                } else {
                    return false;
                }
View Full Code Here

        }
    }

    public Value merge(final Value v, final Value w) {
        if (!v.equals(w)) {
            Type t = ((BasicValue) v).getType();
            Type u = ((BasicValue) w).getType();
            if (t != null
                    && (t.getSort() == Type.OBJECT || t.getSort() == Type.ARRAY))
            {
                if (u != null
                        && (u.getSort() == Type.OBJECT || u.getSort() == Type.ARRAY))
                {
                    if ("Lnull;".equals(t.getDescriptor())) {
                        return w;
                    }
                    if ("Lnull;".equals(u.getDescriptor())) {
                        return v;
                    }
                    if (isAssignableFrom(t, u)) {
                        return v;
                    }
View Full Code Here

            if (isAssignableFrom(t, currentSuperClass)) {
                return true;
            }
            if (currentClassInterfaces != null) {
                for (int i = 0; i < currentClassInterfaces.size(); ++i) {
                    Type v = (Type) currentClassInterfaces.get(i);
                    if (isAssignableFrom(t, v)) {
                        return true;
                    }
                }
            }
View Full Code Here

TOP

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

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.