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.vm;
20 import gov.nasa.jpf.util.Source;
22 import java.util.WeakHashMap;
25 * this corresponds to an executed instruction. Note that we can have a
26 * potentially huge number of Steps, hence we want to save objects here
27 * (e.g. Collection overhead)
31 private static WeakHashMap<Step, String> s_comments = new WeakHashMap<Step, String>(); // Not every Step gets a comment. So save memory and put comments in a global comment HashMap. Make this a WeakHashMap so that old Step objects can be GCed.
33 private final Instruction insn;
36 public Step (Instruction insn) {
38 throw new IllegalArgumentException("insn == null");
43 public Step getNext() {
47 public Instruction getInstruction() {
51 public void setComment (String s) {
52 s_comments.put(this, s);
55 public String getComment () {
56 return s_comments.get(this);
59 public String getLineString () {
60 MethodInfo mi = insn.getMethodInfo();
62 Source source = Source.getSource(mi.getSourceFileName());
64 int line = mi.getLineNumber(insn);
66 return source.getLine(line);
74 public boolean sameSourceLocation (Step other){
77 MethodInfo mi = insn.getMethodInfo();
78 MethodInfo miOther = other.insn.getMethodInfo();
80 return (mi.getLineNumber(insn) == miOther.getLineNumber(other.insn));
87 public String getLocationString() {
88 MethodInfo mi = insn.getMethodInfo();
90 return mi.getSourceFileName() + ':' + mi.getLineNumber(insn);
97 public String toString() {
98 return getLocationString();