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.ListenerAdapter;
21 import gov.nasa.jpf.search.Search;
22 import gov.nasa.jpf.vm.Instruction;
23 import gov.nasa.jpf.vm.ThreadInfo;
24 import gov.nasa.jpf.vm.VM;
27 * simple tools to gather statistics about instructions executed by JPF.
28 * InsnCounter is mostly a VMListener that observes 'instructionExecuted'
30 public class InsnCounter extends ListenerAdapter {
32 String[] opCodes = new String[500];
33 int[] counts = new int[500];
36 //----------------------------------------- SearchKistener interface
38 public void searchFinished(Search search) {
42 //----------------------------------------------------- VMListener interface
44 public void instructionExecuted(VM vm, ThreadInfo ti, Instruction nextInsn, Instruction executedInsn) {
45 int bc = executedInsn.getByteCode();
47 if (opCodes[bc] == null) {
48 opCodes[bc] = executedInsn.getMnemonic();
55 //----------------------------------------------------- internal stuff
56 void reportStatistics () {
57 int[] sorted = getSortedCounts();
62 for (i=0; i<sorted.length; i++) {
64 String opc = opCodes[idx];
66 if (counts[idx] > 0) {
68 System.out.print( " ");
69 System.out.print( opc);
70 System.out.print( " : ");
71 System.out.println( counts[idx]);
80 System.out.println("total number of executed instructions: " + total);
83 int[] getSortedCounts () {
84 int[] sorted = new int[256];
88 for (i=0; i<256; i++) {
91 for (j=0; j<last; j++) {
92 if (counts[sorted[j]] < c) {
93 System.arraycopy(sorted, j, sorted, j+1, (last-j));
105 void filterArgs (String[] args) {
106 // we don't have any yet