Ejemplo n.º 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);
      }
    }
  }
Ejemplo n.º 2
0
  protected MethodInfo createCallStub(String originator, int id) {
    MethodInfo mi = new MethodInfo(id);
    String cname = ci.getName();
    Instruction insn;

    mi.name =
        originator
            + name; // + cname; // could maybe also include the called method, but keep it fast
    mi.signature = "()V";
    mi.maxLocals = isStatic() ? 0 : 1;
    mi.maxStack = getNumberOfCallerStackSlots(); // <2do> cache for optimization
    mi.localVariableNames = EMPTY;
    mi.localVariableTypes = EMPTY;
    mi.lineNumbers = null;
    mi.exceptions = null;
    mi.thrownExceptionClassNames = null;
    mi.uniqueName = mi.name;

    // createAndInitialize the code
    CodeBuilder cb = mi.getCodeBuilder();

    if (isStatic()) {
      mi.modifiers |= Modifier.STATIC;

      if (isClinit()) {
        insn = insnFactory.create(null, INVOKECLINIT.OPCODE);
      } else {
        insn = insnFactory.create(null, Constants.INVOKESTATIC);
      }
    } else if (name.equals("<init>")) {
      insn = insnFactory.create(null, Constants.INVOKESPECIAL);
    } else {
      insn = insnFactory.create(null, Constants.INVOKEVIRTUAL);
    }
    ((InvokeInstruction) insn).setInvokedMethod(cname, name, signature);
    cb.append(insn);

    insn = insnFactory.create(null, Constants.RETURN);
    cb.append(insn);

    cb.setCode();

    return mi;
  }
Ejemplo n.º 3
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();
        }
      }
    }
  }