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.
19 package gov.nasa.jpf.report;
21 import gov.nasa.jpf.ListenerAdapter;
22 import gov.nasa.jpf.jvm.bytecode.EXECUTENATIVE;
23 import gov.nasa.jpf.jvm.bytecode.JVMFieldInstruction;
24 import gov.nasa.jpf.jvm.bytecode.JVMInvokeInstruction;
25 import gov.nasa.jpf.jvm.bytecode.LockInstruction;
26 import gov.nasa.jpf.search.Search;
27 import gov.nasa.jpf.vm.ChoiceGenerator;
28 import gov.nasa.jpf.vm.ClassInfo;
29 import gov.nasa.jpf.vm.ElementInfo;
30 import gov.nasa.jpf.vm.Instruction;
31 import gov.nasa.jpf.vm.ThreadInfo;
32 import gov.nasa.jpf.vm.VM;
33 import gov.nasa.jpf.vm.MethodInfo;
34 import gov.nasa.jpf.vm.ThreadChoiceGenerator;
37 * simple structure to hold statistics info created by Reporters/Publishers
38 * this is kind of a second tier SearchListener, which does not
39 * explicitly have to be registered
41 * <2do> this should get generic and accessible enough to replace all the
42 * other statistics collectors, otherwise there is too much redundancy.
43 * If users have special requirements, they should subclass Statistics
44 * and set jpf.report.statistics.class accordingly
46 * Note that Statistics might be accessed by a background thread
47 * reporting JPF progress, hence we have to synchronize
49 public class Statistics extends ListenerAdapter implements Cloneable {
51 // we make these public since we don't want to add a gazillion of
52 // getters for these purely informal numbers
54 public long maxUsed = 0;
55 public long newStates = 0;
56 public long backtracked = 0;
57 public long restored = 0;
58 public int processed = 0;
59 public int constraints = 0;
60 public long visitedStates = 0;
61 public long endStates = 0;
62 public int maxDepth = 0;
64 public int gcCycles = 0;
65 public long insns = 0;
66 public int threadCGs = 0;
67 public int sharedAccessCGs = 0;
68 public int monitorCGs = 0;
69 public int signalCGs = 0;
70 public int threadApiCGs = 0;
71 public int breakTransitionCGs = 0;
72 public int dataCGs = 0;
73 public long nNewObjects = 0;
74 public long nReleasedObjects = 0;
75 public int maxLiveObjects = 0;
78 public Statistics clone() {
80 return (Statistics)super.clone();
81 } catch (CloneNotSupportedException e) {
82 return null; // can't happen
87 public void gcBegin (VM vm) {
88 int heapSize = vm.getHeap().size();
89 if (heapSize > maxLiveObjects){
90 maxLiveObjects = heapSize;
97 public void instructionExecuted (VM vm, ThreadInfo ti, Instruction nextInsn, Instruction executedInsn){
102 public void choiceGeneratorSet (VM vm, ChoiceGenerator<?> newCG){
103 ChoiceGenerator<?> cg = VM.getVM().getChoiceGenerator();
104 if (cg instanceof ThreadChoiceGenerator){
107 Instruction insn = cg.getInsn();
108 if (insn instanceof JVMFieldInstruction) {
110 } else if (insn instanceof LockInstruction || insn instanceof JVMInvokeInstruction) {
112 } else if (insn instanceof EXECUTENATIVE) {
113 MethodInfo mi = insn.getMethodInfo();
115 ClassInfo ci = mi.getClassInfo();
117 if (ci.isObjectClassInfo()) {
118 // its got to be either a wait or a notify since we know the java.lang.Object methods
120 } else if (ci.isThreadClassInfo()) {
124 // Hmm - a CG from a synthetic method?
127 // even more Hmmm - a GC from a synthesized instruction
130 breakTransitionCGs++; // e.g. max_transition_length or idleLoop breakers
138 public void objectCreated (VM vm, ThreadInfo ti, ElementInfo ei){
143 public void objectReleased (VM vm, ThreadInfo ti, ElementInfo ei){
148 public void stateAdvanced (Search search){
149 long m = Runtime.getRuntime().totalMemory();
154 if (search.isNewState()){
156 int depth = search.getDepth();
157 if (depth > maxDepth){
163 if (search.isEndState()){
169 public void stateBacktracked (Search search){
174 public void stateProcessed (Search search){
179 public void stateRestored (Search search){
184 public void searchConstraintHit (Search search){