Пример #1
0
 /** Returns the line number for a given position. */
 public int getLineNumber(Instruction pc) {
   if (lineNumbers == null) {
     if (pc == null) return -1;
     else return pc.getPosition();
   }
   int idx = pc.getOffset();
   if (idx < 0) idx = 0;
   return lineNumbers[idx];
 }
Пример #2
0
 void setCGed(ThreadInfo ti, Instruction insn) {
   ti = null; // Remove IDE warning about unused variable.
   // Hmm, we have to store the bb set at this point
   BitSet bb = getBasicBlocks();
   Instruction next = insn.getNext();
   if (next != null) { // insn might be a sync return
     bb.set(next.getInstructionIndex());
   }
 }
Пример #3
0
    public void setConstErrorMessage() {
      MethodInfo mi = insn.getMethodInfo();
      StringBuilder sb = new StringBuilder("@Const method violation: ");
      sb.append(mi.getFullName());
      sb.append("\n\tfield:    ");
      sb.append(((FieldInfo) use).getFullName());
      sb.append("\n\tmethod:   ");
      sb.append(insn.getSourceLocation());

      msg = sb.toString();
    }
Пример #4
0
    public int append(Instruction insn) {

      insns.add(insn);

      insn.setMethodInfo(MethodInfo.this);
      insn.setLocation(off, pos);

      off++;
      pos += insn.getLength();

      return off;
    }
Пример #5
0
    BitSet getHandlerStarts() {
      BitSet b = new BitSet(mi.getInstructions().length);
      ExceptionHandler[] handler = mi.getExceptions();

      if (handler != null) {
        for (int i = 0; i < handler.length; i++) {
          Instruction hs = mi.getInstructionAt(handler[i].getHandler());
          b.set(hs.getInstructionIndex());
        }
      }

      return b;
    }
Пример #6
0
    void setExecuted(ThreadInfo ti, Instruction insn) {
      int idx = ti.getId();

      if (covered == null) {
        covered = new BitSet[idx + 1];
      } else if (idx >= covered.length) {
        BitSet[] a = new BitSet[idx + 1];
        System.arraycopy(covered, 0, a, 0, covered.length);
        covered = a;
      }

      if (covered[idx] == null) {
        covered[idx] = new BitSet(mi.getInstructions().length);
      }

      int off = insn.getInstructionIndex();
      covered[idx].set(off);

      if (showBranchCoverage && (insn instanceof IfInstruction)) {
        if (branchTrue == null) {
          branchTrue = new BitSet(mi.getInstructions().length);
          branchFalse = new BitSet(branchTrue.size());
        }
        if (!((IfInstruction) insn).getConditionValue()) {
          branchTrue.set(off);
        } else {
          branchFalse.set(off);
        }
      }
    }
Пример #7
0
  public void instructionExecuted(JVM vm) {
    Instruction insn = vm.getLastInstruction();
    MethodCoverage mc = getMethodCoverage(vm);

    if (mc != null) {
      mc.setExecuted(vm.getLastThreadInfo(), insn);

      if (showRequirements) {
        if (insn.getPosition() == 0) { // first insn in method, check for Requirements
          AnnotationInfo ai = getRequirementsAnnotation(mc.getMethodInfo());
          if (ai != null) {
            String[] ids = ai.getValueAsStringArray();
            updateRequirementsCoverage(ids, mc);
          }
        }
      }
    }
  }
  public static void $init(MJIEnv env, int objref) {
    ThreadInfo ti = env.getThreadInfo();
    StackFrame caller = ti.getCallerStackFrame();
    Instruction insn = caller.getPC();

    InsnExecCount a = insn.getAttr(InsnExecCount.class);
    if (a == null) {
      a = new InsnExecCount();
      insn.addAttr(a);
    }

    SystemState ss = env.getSystemState();
    if (!ss.hasRestorer(a)) {
      env.getSystemState().putRestorer(a, new InsnCountRestorer(a));
    }

    a.count++;
    env.setIntField(objref, "id", a.count);
  }
Пример #9
0
    public void setSharedErrorMessage() {
      StringBuilder sb = new StringBuilder("@NonShared object violation: ");
      sb.append(rec.ei);
      sb.append("\n\tcreated in thread: ");
      sb.append(rec.tiCreate.getName());
      sb.append("\n\tused in thread:    ");
      sb.append(tiUse.getName());
      sb.append("\n\tmethod:            ");
      sb.append(insn.getSourceLocation());

      msg = sb.toString();
    }
Пример #10
0
  MethodCoverage getMethodCoverage(JVM vm) {
    Instruction insn = vm.getLastInstruction();

    if (!insn.isExtendedInstruction()) {
      MethodInfo mi = insn.getMethodInfo();
      if (mi != lastMi) {
        lastMc = null;
        lastMi = mi;
        ClassInfo ci = mi.getClassInfo();
        if (ci != null) {
          ClassCoverage cc = classes.get(ci.getName());
          if (cc != null) {
            lastMc = cc.getMethodCoverage(mi);
          }
        }
      }

      return lastMc;
    }

    return null;
  }
Пример #11
0
  public void executeInstruction(JVM vm) {
    Instruction insn = vm.getLastInstruction();
    MethodInfo mi = insn.getMethodInfo();
    ThreadInfo ti = vm.getLastThreadInfo();

    if (mi != lastMi) {
      logStack(ti);
      lastMi = mi;

    } else if (insn instanceof InvokeInstruction) {
      MethodInfo callee;

      // that's the only little gist of it - if this is a VirtualInvocation,
      // we have to dig the callee out by ourselves (it's not known
      // before execution)

      if (insn instanceof VirtualInvocation) {
        VirtualInvocation callInsn = (VirtualInvocation) insn;
        int objref = callInsn.getCalleeThis(ti);
        callee = callInsn.getInvokedMethod(ti, objref);

      } else if (insn instanceof INVOKESPECIAL) {
        INVOKESPECIAL callInsn = (INVOKESPECIAL) insn;
        callee = callInsn.getInvokedMethod(ti);

      } else {
        InvokeInstruction callInsn = (InvokeInstruction) insn;
        callee = callInsn.getInvokedMethod(ti);
      }

      if (callee != null) {
        if (callee.isMJI()) {
          logStack(ti);
        }
      } else {
        out.println("ERROR: unknown callee of: " + insn);
      }
    }
  }
Пример #12
0
  boolean checkConst(Record rec, ThreadInfo ti, FieldInfo fi, Instruction insn) {
    if (checkConst) {
      AnnotationInfo ai = insn.getMethodInfo().getAnnotation("gov.nasa.jpf.Const");
      if (ai != null) {
        violation = new Violation(rec, ti, fi, insn);
        violation.setConstErrorMessage();

        ti.breakTransition();
        return false;
      }
    }

    return true;
  }
Пример #13
0
    BitSet getBasicBlocks() {
      if (basicBlocks == null) {
        Instruction[] code = mi.getInstructions();
        BitSet bb = new BitSet(code.length);

        bb.set(0); // first insn is always a bb start

        // first, look at the insn type
        for (int i = 0; i < code.length; i++) {
          Instruction insn = code[i];
          if (insn instanceof IfInstruction) {
            IfInstruction ifInsn = (IfInstruction) insn;

            Instruction tgt = ifInsn.getTarget();
            bb.set(tgt.getInstructionIndex());

            tgt = ifInsn.getNext();
            bb.set(tgt.getInstructionIndex());
          } else if (insn instanceof GOTO) {
            Instruction tgt = ((GOTO) insn).getTarget();
            bb.set(tgt.getInstructionIndex());
          } else if (insn instanceof InvokeInstruction) {
            // hmm, this might be a bit too conservative, but who says we
            // don't jump out of a caller into a handler, or even that we
            // ever return from the call?
            Instruction tgt = insn.getNext();
            bb.set(tgt.getInstructionIndex());
          }
        }

        // and now look at the handlers (every first insn is a bb start)
        ExceptionHandler[] handlers = mi.getExceptions();
        if (handlers != null) {
          for (int i = 0; i < handlers.length; i++) {
            Instruction tgt = mi.getInstructionAt(handlers[i].getHandler());
            bb.set(tgt.getInstructionIndex());
          }
        }

        basicBlocks = bb;

        /** dump
         * System.out.println();
         * System.out.println(mi.getFullName());
         * for (int i=0; i<code.length; i++) {
         * System.out.print(String.format("%1$2d %2$c ",i, bb.get(i) ? '>' : ' '));
         * System.out.println(code[i]);
         * }
         **/
      }

      return basicBlocks;
    }