Package org.objectweb.asm.tree.analysis

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


            }
        }
    }

    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


    {
      Label frameLabel= labels.get(i);
      mv.visitLabel(restoreLabels[i]);

      MethodInsnNode mnode= nodes.get(i);
      Frame frame= analyzer.getFrames()[canalyzer.getIndex(mnode)];

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

    for (int j= 0; j < methods.size(); j++)
    {
      MethodInsnNode mnode= methods.get(j);
      // require to move NEW instruction
      int n= instructions.indexOf(mnode);
      Frame f= frames[n];
      Type[] args= Type.getArgumentTypes(mnode.desc);

      SourceValue v= (SourceValue) f.getStack(f.getStackSize() - args.length - 1);
      Set<AbstractInsnNode> insns= v.insns;
      for (final AbstractInsnNode ins : insns)
      {
        if (ins.getOpcode() == NEW)
        {
View Full Code Here

TOP

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

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.