Пример #1
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);
      }
    }
  }
Пример #2
0
  /** @see gov.nasa.jpf.ListenerAdapter#instructionExecuted(gov.nasa.jpf.jvm.JVM) */
  public void instructionExecuted(JVM vm) {
    Instruction instr = vm.getLastInstruction();
    ThreadInfo ti = vm.getLastThreadInfo();

    if (instr instanceof InvokeInstruction) {
      InvokeInstruction invInstr = ((InvokeInstruction) instr);

      String method = invInstr.toString();
      // if(method.contains("Test"))
      // System.out.println(method);

      MethodInfo mi = ((InvokeInstruction) instr).getInvokedMethod();
      if (this.traceDefFilter != null && this.traceDefFilter.accept(mi)) {
        // Callee
        ElementInfo calleeElement = ti.getThisElementInfo();
        MethodInfo calleeMethod = invInstr.getInvokedMethod();
        ClassInfo calleeClass = null;
        int calleeID = -1;
        if (calleeMethod.isStatic()) {
          // static method: method declared in class
          calleeClass = calleeMethod.getClassInfo();
          // static methods do not have a instance
          calleeID = -1;
        } else {
          // non static method: method is maybe overridden. get the current class
          // instead of the class the method is declared in.
          calleeClass = calleeElement.getClassInfo();
          // get the current instance
          calleeID = calleeElement.getThisReference();
        }
        assert (calleeClass != null);

        // Caller
        ElementInfo callerElement = ti.getElementInfo(ti.getCallerStackFrame().getThis());
        if (callerElement != null) {
          MethodInfo callerMethod = invInstr.getMethodInfo();
          ClassInfo callerClass = null;
          int callerID = -1;
          if (callerMethod.isStatic()) {
            // see above
            callerClass = callerMethod.getClassInfo();
            callerID = -1;
          } else {
            // see above
            callerClass = callerElement.getClassInfo();
            callerID = callerElement.getThisReference();
          }

          // Arguments
          Object[] argumentValues = invInstr.getArgumentValues(ti);
          Object[] arguments = new Object[argumentValues.length];
          for (int i = 0; i < arguments.length; i++) {
            if (this.argumentValues) {
              if (argumentValues[i] instanceof ElementInfo)
                arguments[i] = ((ElementInfo) argumentValues[i]).getThisReference();
              else arguments[i] = argumentValues[i];
            } else arguments[i] = null;
          }

          MethodEntry methodEntry =
              new MethodEntry(
                  callerID,
                  callerMethod,
                  callerClass,
                  calleeID,
                  calleeMethod,
                  calleeClass,
                  arguments,
                  ti.getName());

          this.currentStateNode.methods.add(methodEntry);

          if (this.timeStamps) methodEntry.time = new Date().getTime();
        }
      }
    }
  }