Package org.objectweb.asm.tree.analysis

Examples of org.objectweb.asm.tree.analysis.BasicValue


            int idxPrim = 0;

            if (f != null) {
                stackSlotIndices = new int[f.getStackSize()];
                for (int i = 0; i < f.getStackSize(); i++) {
                    BasicValue v = (BasicValue) f.getStack(i);
                    if (v instanceof NewValue) {
                        NewValue newValue = (NewValue) v;
                        if (db.isDebug()) {
                            db.log(LogLevel.DEBUG, "Omit value from stack idx %d at instruction %d with type %s generated by %s",
                                    i, endInstruction, v, newValue.formatInsn());
                        }
                        if (!newValue.omitted) {
                            newValue.omitted = true;
                            if (db.isDebug()) {
                                // need to log index before replacing instruction
                                db.log(LogLevel.DEBUG, "Omitting instruction %d: %s", insnList.indexOf(newValue.insn), newValue.formatInsn());
                            }
                            insnList.set(newValue.insn, new OmittedInstruction(newValue.insn));
                        }
                        stackSlotIndices[i] = -666; // an invalid index ;)
                    } else if (!isNullType(v)) {
                        if (v.isReference()) {
                            stackSlotIndices[i] = idxObj++;
                        } else {
                            stackSlotIndices[i] = idxPrim++;
                        }
                    } else {
                        stackSlotIndices[i] = -666; // an invalid index ;)
                    }
                }

                localSlotIndices = new int[f.getLocals()];
                for (int i = firstLocal; i < f.getLocals(); i++) {
                    BasicValue v = (BasicValue) f.getLocal(i);
                    if (!isNullType(v)) {
                        if (v.isReference()) {
                            localSlotIndices[i] = idxObj++;
                        } else {
                            localSlotIndices[i] = idxPrim++;
                        }
                    } else {
View Full Code Here


    private void emitNewAndDup(MethodVisitor mv, Frame frame, int stackIndex, MethodInsnNode min) {
        int arguments = frame.getStackSize() - stackIndex - 1;
        int neededLocals = 0;
        for (int i = arguments; i >= 1; i--) {
            BasicValue v = (BasicValue) frame.getStack(stackIndex + i);
            mv.visitVarInsn(v.getType().getOpcode(Opcodes.ISTORE), lvarStack + NUM_LOCALS + neededLocals);
            neededLocals += v.getSize();
        }
        db.log(LogLevel.DEBUG, "Inserting NEW & DUP for constructor call %s%s with %d arguments (%d locals)", min.owner, min.desc, arguments, neededLocals);
        if (additionalLocals < neededLocals) {
            additionalLocals = neededLocals;
        }
        ((NewValue) frame.getStack(stackIndex - 1)).insn.accept(mv);
        ((NewValue) frame.getStack(stackIndex)).insn.accept(mv);
        for (int i = 1; i <= arguments; i++) {
            BasicValue v = (BasicValue) frame.getStack(stackIndex + i);
            neededLocals -= v.getSize();
            mv.visitVarInsn(v.getType().getOpcode(Opcodes.ILOAD), lvarStack + NUM_LOCALS + neededLocals);
        }
    }
View Full Code Here

        emitConst(mv, fi.numSlots);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "pushMethod", "(II)V");

        // store operand stack
        for (int i = f.getStackSize(); i-- > 0;) {
            BasicValue v = (BasicValue) f.getStack(i);
            if (!isOmitted(v)) {
                if (!isNullType(v)) {
                    int slotIdx = fi.stackSlotIndices[i];
                    assert slotIdx >= 0 && slotIdx < fi.numSlots;
                    emitStoreValue(mv, v, lvarStack, slotIdx, -1);
                } else {
                    db.log(LogLevel.DEBUG, "NULL stack entry: type=%s size=%d", v.getType(), v.getSize());
                    mv.visitInsn(Opcodes.POP);
                }
            }
        }

        // store local vars
        for (int i = firstLocal; i < f.getLocals(); i++) {
            BasicValue v = (BasicValue) f.getLocal(i);
            if (!isNullType(v)) {
                mv.visitVarInsn(v.getType().getOpcode(Opcodes.ILOAD), i);
                int slotIdx = fi.localSlotIndices[i];
                assert slotIdx >= 0 && slotIdx < fi.numSlots;
                emitStoreValue(mv, v, lvarStack, slotIdx, i);
            }
        }

        // restore last numArgsToPreserve operands
        for (int i = f.getStackSize() - numArgsToPreserve; i < f.getStackSize(); i++) {
            BasicValue v = (BasicValue) f.getStack(i);
            if (!isOmitted(v)) {
                if (!isNullType(v)) {
                    int slotIdx = fi.stackSlotIndices[i];
                    assert slotIdx >= 0 && slotIdx < fi.numSlots;
                    emitRestoreValue(mv, v, lvarStack, slotIdx, -1);
View Full Code Here

    private void emitRestoreState(MethodVisitor mv, int idx, FrameInfo fi, int numArgsPreserved) {
        Frame f = frames[fi.endInstruction];

        // restore local vars
        for (int i = firstLocal; i < f.getLocals(); i++) {
            BasicValue v = (BasicValue) f.getLocal(i);
            if (!isNullType(v)) {
                int slotIdx = fi.localSlotIndices[i];
                assert slotIdx >= 0 && slotIdx < fi.numSlots;
                emitRestoreValue(mv, v, lvarStack, slotIdx, i);
                mv.visitVarInsn(v.getType().getOpcode(Opcodes.ISTORE), i);
            } else if (v != BasicValue.UNINITIALIZED_VALUE) {
                mv.visitInsn(Opcodes.ACONST_NULL);
                mv.visitVarInsn(Opcodes.ASTORE, i);
            }
        }

        // restore operand stack
        for (int i = 0; i < f.getStackSize() - numArgsPreserved; i++) {
            BasicValue v = (BasicValue) f.getStack(i);
            if (!isOmitted(v)) {
                if (!isNullType(v)) {
                    int slotIdx = fi.stackSlotIndices[i];
                    assert slotIdx >= 0 && slotIdx < fi.numSlots;
                    emitRestoreValue(mv, v, lvarStack, slotIdx, -1);
View Full Code Here

            int idxPrim = 0;

            if (f != null) {
                stackSlotIndices = new int[f.getStackSize()];
                for (int i = 0; i < f.getStackSize(); i++) {
                    BasicValue v = (BasicValue) f.getStack(i);
                    if (v instanceof NewValue) {
                        NewValue newValue = (NewValue) v;
                        if (db.isDebug()) {
                            db.log(LogLevel.DEBUG, "Omit value from stack idx %d at instruction %d with type %s generated by %s",
                                    i, endInstruction, v, newValue.formatInsn());
                        }
                        if (!newValue.omitted) {
                            newValue.omitted = true;
                            if (db.isDebug()) {
                                // need to log index before replacing instruction
                                db.log(LogLevel.DEBUG, "Omitting instruction %d: %s", insnList.indexOf(newValue.insn), newValue.formatInsn());
                            }
                            insnList.set(newValue.insn, new OmittedInstruction(newValue.insn));
                        }
                        stackSlotIndices[i] = -666; // an invalid index ;)
                    } else if (!isNullType(v)) {
                        if (v.isReference()) {
                            stackSlotIndices[i] = idxObj++;
                        } else {
                            stackSlotIndices[i] = idxPrim++;
                        }
                    } else {
                        stackSlotIndices[i] = -666; // an invalid index ;)
                    }
                }

                localSlotIndices = new int[f.getLocals()];
                for (int i = firstLocal; i < f.getLocals(); i++) {
                    BasicValue v = (BasicValue) f.getLocal(i);
                    if (!isNullType(v)) {
                        if (v.isReference()) {
                            localSlotIndices[i] = idxObj++;
                        } else {
                            localSlotIndices[i] = idxPrim++;
                        }
                    } else {
View Full Code Here

      // for each local variable store the value in locals popping it from the stack!
      // locals
      int lsize= frame.getLocals();
      for (int j= lsize - 1; j >= 0; j--)
      {
        BasicValue value= (BasicValue) frame.getLocal(j);
        if (isNull(value))
        {
          mv.visitInsn(ACONST_NULL);
          mv.visitVarInsn(ASTORE, j);
        }
        else if (value == BasicValue.UNINITIALIZED_VALUE)
        {
          // TODO ??
        }
        else if (value == BasicValue.RETURNADDRESS_VALUE)
        {
          // TODO ??
        }
        else
        {
          mv.visitVarInsn(ALOAD, stackRecorderVar);
          Type type= value.getType();
          if (value.isReference())
          {
            mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, POP_METHOD + "Object", "()Ljava/lang/Object;", false);
            Type t= value.getType();
            String desc= t.getDescriptor();
            if (desc.charAt(0) == '[')
            {
              mv.visitTypeInsn(CHECKCAST, desc);
            }
            else
            {
              mv.visitTypeInsn(CHECKCAST, t.getInternalName());
            }
            mv.visitVarInsn(ASTORE, j);

          }
          else
          {
            mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, getPopMethod(type), "()" + type.getDescriptor(), false);
            mv.visitVarInsn(type.getOpcode(ISTORE), j);
          }
        }
      }

      if (frame instanceof MonitoringFrame)
      {
        int[] monitoredLocals= ((MonitoringFrame) frame).getMonitored();
        // System.out.println(System.identityHashCode(frame)+" AMonitored locals "+monitoredLocals.length);
        for (int monitoredLocal : monitoredLocals)
        {
          // System.out.println(System.identityHashCode(frame)+" AMonitored local "+monitoredLocals[j]);
          mv.visitVarInsn(ALOAD, monitoredLocal);
          mv.visitInsn(MONITORENTER);
        }
      }

      // stack
      int argSize= Type.getArgumentTypes(mnode.desc).length;
      int ownerSize= mnode.getOpcode() == INVOKESTATIC ? 0 : 1; // TODO
      int initSize= mnode.name.equals("<init>") ? 2 : 0;
      int ssize= frame.getStackSize();
      for (int j= 0; j < ssize - argSize - ownerSize - initSize; j++)
      {
        BasicValue value= (BasicValue) frame.getStack(j);
        if (isNull(value))
        {
          mv.visitInsn(ACONST_NULL);
        }
        else if (value == BasicValue.UNINITIALIZED_VALUE)
        {
          // TODO ??
        }
        else if (value == BasicValue.RETURNADDRESS_VALUE)
        {
          // TODO ??
        }
        else if (value.isReference())
        {
          mv.visitVarInsn(ALOAD, stackRecorderVar);
          mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, POP_METHOD + "Object", "()Ljava/lang/Object;", false);
          mv.visitTypeInsn(CHECKCAST, value.getType().getInternalName());
        }
        else
        {
          Type type= value.getType();
          mv.visitVarInsn(ALOAD, stackRecorderVar);
          mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, getPopMethod(type), "()" + type.getDescriptor(), false);
        }
      }

      boolean hasMethodRef= false;
      if (mnode.getOpcode() != INVOKESTATIC)
      {
        // Load the object whose method we are calling 
        BasicValue value= ((BasicValue) frame.getStack(ssize - argSize - 1));
        if (isNull(value))
        {
          // If user code causes NPE, then we keep this behavior: load null to get NPE at runtime
          mv.visitInsn(ACONST_NULL);
        }
        else
        {
          hasMethodRef= true;

          mv.visitVarInsn(ALOAD, stackRecorderVar);
          mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, POP_METHOD + "Reference", "()Ljava/lang/Object;", false);
          mv.visitTypeInsn(CHECKCAST, value.getType().getInternalName());
         
        }
      }

      // Create null types for the parameters of the method invocation
View Full Code Here

      int argSize= params.length;
      int ownerSize= opcode == INVOKESTATIC ? 0 : 1; // TODO
      int ssize= currentFrame.getStackSize() - argSize - ownerSize;
      for (int i= ssize - 1; i >= 0; i--)
      {
        BasicValue value= (BasicValue) currentFrame.getStack(i);
        if (isNull(value))
        {
          mv.visitInsn(POP);
        }
        else if (value == BasicValue.UNINITIALIZED_VALUE)
        {
          // TODO ??
        }
        else if (value.isReference())
        {
          mv.visitVarInsn(ALOAD, stackRecorderVar);
          mv.visitInsn(SWAP);
          mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, PUSH_METHOD + "Object", "(Ljava/lang/Object;)V", false);
        }
        else
        {
          Type type= value.getType();
          if (type.getSize() > 1)
          {
            mv.visitInsn(ACONST_NULL); // dummy stack entry
            mv.visitVarInsn(ALOAD, stackRecorderVar);
            mv.visitInsn(DUP2_X2); // swap2 for long/double
            mv.visitInsn(POP2);
            mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, getPushMethod(type), "(" + type.getDescriptor() + ")V", false);
            mv.visitInsn(POP); // remove dummy stack entry
          }
          else
          {
            mv.visitVarInsn(ALOAD, stackRecorderVar);
            mv.visitInsn(SWAP);
            mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, getPushMethod(type), "(" + type.getDescriptor() + ")V", false);
          }
        }
      }

      if (!isStatic)
      {
        //RS:
        if (canalyzer._continueReflection && name.equals("invoke") && owner.startsWith("java/lang/reflect/Method"))
        {
          mv.visitVarInsn(ALOAD, stackRecorderVar);
          ContinuationMethodAnalyzer.MyVariables vars= canalyzer._reflectMapping.get(nodes.get(currentIndex));
//          System.out.println("Class:" + canalyzer.className + "method:" + stackRecorderVar + ":" + name + ":" + owner + ":" + desc + ":" + vars.methodVar());
          mv.visitVarInsn(ALOAD, vars.methodVar());
          //mv.visitVarInsn(ALOAD, 3);
          mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, "replace" + "Reference", "(Ljava/lang/Object;)V", false);
        }
        //RS:
        mv.visitVarInsn(ALOAD, stackRecorderVar);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, PUSH_METHOD + "Reference", "(Ljava/lang/Object;)V", false);
      }

      // save locals
      int fsize= currentFrame.getLocals();
      for (int j= 0; j < fsize; j++)
      {
        BasicValue value= (BasicValue) currentFrame.getLocal(j);
        if (isNull(value))
        {
          // no need to save null
        }
        else if (value == BasicValue.UNINITIALIZED_VALUE)
        {
          // no need to save uninitialized objects
        }
        else if (value.isReference())
        {
          mv.visitVarInsn(ALOAD, stackRecorderVar);
          mv.visitVarInsn(ALOAD, j);
          mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, PUSH_METHOD + "Object", "(Ljava/lang/Object;)V", false);
        }
        else
        {
          mv.visitVarInsn(ALOAD, stackRecorderVar);
          Type type= value.getType();
          mv.visitVarInsn(type.getOpcode(ILOAD), j);
          mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, getPushMethod(type), "(" + type.getDescriptor() + ")V", false);
        }
      }
View Full Code Here

TOP

Related Classes of org.objectweb.asm.tree.analysis.BasicValue

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.