Mercurial > hg > Members > kono > jpf-core
comparison src/main/gov/nasa/jpf/vm/Step.java @ 0:61d41facf527
initial v8 import (history reset)
author | Peter Mehlitz <Peter.C.Mehlitz@nasa.gov> |
---|---|
date | Fri, 23 Jan 2015 10:14:01 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:61d41facf527 |
---|---|
1 /* | |
2 * Copyright (C) 2014, United States Government, as represented by the | |
3 * Administrator of the National Aeronautics and Space Administration. | |
4 * All rights reserved. | |
5 * | |
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 | |
9 * | |
10 * http://www.apache.org/licenses/LICENSE-2.0. | |
11 * | |
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. | |
17 */ | |
18 package gov.nasa.jpf.vm; | |
19 | |
20 import gov.nasa.jpf.util.Source; | |
21 | |
22 import java.util.WeakHashMap; | |
23 | |
24 /** | |
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) | |
28 */ | |
29 public class Step { | |
30 | |
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. | |
32 | |
33 private final Instruction insn; | |
34 Step next; | |
35 | |
36 public Step (Instruction insn) { | |
37 if (insn == null) | |
38 throw new IllegalArgumentException("insn == null"); | |
39 | |
40 this.insn = insn; | |
41 } | |
42 | |
43 public Step getNext() { | |
44 return next; | |
45 } | |
46 | |
47 public Instruction getInstruction() { | |
48 return insn; | |
49 } | |
50 | |
51 public void setComment (String s) { | |
52 s_comments.put(this, s); | |
53 } | |
54 | |
55 public String getComment () { | |
56 return s_comments.get(this); | |
57 } | |
58 | |
59 public String getLineString () { | |
60 MethodInfo mi = insn.getMethodInfo(); | |
61 if (mi != null) { | |
62 Source source = Source.getSource(mi.getSourceFileName()); | |
63 if (source != null) { | |
64 int line = mi.getLineNumber(insn); | |
65 if (line > 0) { | |
66 return source.getLine(line); | |
67 } | |
68 } | |
69 } | |
70 | |
71 return null; | |
72 } | |
73 | |
74 public boolean sameSourceLocation (Step other){ | |
75 | |
76 if (other != null){ | |
77 MethodInfo mi = insn.getMethodInfo(); | |
78 MethodInfo miOther = other.insn.getMethodInfo(); | |
79 if (mi == miOther){ | |
80 return (mi.getLineNumber(insn) == miOther.getLineNumber(other.insn)); | |
81 } | |
82 } | |
83 | |
84 return false; | |
85 } | |
86 | |
87 public String getLocationString() { | |
88 MethodInfo mi = insn.getMethodInfo(); | |
89 if (mi != null) { | |
90 return mi.getSourceFileName() + ':' + mi.getLineNumber(insn); | |
91 } | |
92 | |
93 return "?:?"; | |
94 } | |
95 | |
96 @Override | |
97 public String toString() { | |
98 return getLocationString(); | |
99 } | |
100 } |