2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package gov.nasa.jpf.listener;
20 import gov.nasa.jpf.Config;
21 import gov.nasa.jpf.JPF;
22 import gov.nasa.jpf.ListenerAdapter;
23 import gov.nasa.jpf.jvm.bytecode.INVOKESPECIAL;
24 import gov.nasa.jpf.jvm.bytecode.JVMInvokeInstruction;
25 import gov.nasa.jpf.jvm.bytecode.VirtualInvocation;
26 import gov.nasa.jpf.search.Search;
27 import gov.nasa.jpf.vm.Instruction;
28 import gov.nasa.jpf.vm.VM;
29 import gov.nasa.jpf.vm.MethodInfo;
30 import gov.nasa.jpf.vm.ThreadInfo;
32 import java.io.PrintWriter;
35 * simple tool to log stack invocations
37 * at this point, it doesn't do fancy things yet, but gives a more high
38 * level idea of what got executed by JPF than the ExecTracker
40 public class StackTracker extends ListenerAdapter {
42 static final String INDENT = " ";
49 public StackTracker (Config conf, JPF jpf) {
50 out = new PrintWriter(System.out, true);
51 logPeriod = conf.getInt("jpf.stack_tracker.log_period", 5000);
54 void logStack(ThreadInfo ti) {
55 long time = System.currentTimeMillis();
61 nextLog = time + logPeriod;
64 out.print("Thread: ");
65 out.print(ti.getId());
68 out.println(ti.getStackTrace());
73 public void executeInstruction (VM vm, ThreadInfo ti, Instruction insnToExecute) {
74 MethodInfo mi = insnToExecute.getMethodInfo();
80 } else if (insnToExecute instanceof JVMInvokeInstruction) {
83 // that's the only little gist of it - if this is a VirtualInvocation,
84 // we have to dig the callee out by ourselves (it's not known
87 if (insnToExecute instanceof VirtualInvocation) {
88 VirtualInvocation callInsn = (VirtualInvocation)insnToExecute;
89 int objref = callInsn.getCalleeThis(ti);
90 callee = callInsn.getInvokedMethod(ti, objref);
92 } else if (insnToExecute instanceof INVOKESPECIAL) {
93 INVOKESPECIAL callInsn = (INVOKESPECIAL)insnToExecute;
94 callee = callInsn.getInvokedMethod(ti);
97 JVMInvokeInstruction callInsn = (JVMInvokeInstruction)insnToExecute;
98 callee = callInsn.getInvokedMethod(ti);
101 if (callee != null) {
102 if (callee.isMJI()) {
106 out.println("ERROR: unknown callee of: " + insnToExecute);
112 public void stateAdvanced(Search search) {
117 public void stateBacktracked(Search search) {