001 package edu.rice.cs.cunit.record.graph;
002
003 import com.sun.jdi.AbsentInformationException;
004 import com.sun.jdi.ObjectReference;
005 import com.sun.jdi.StackFrame;
006
007 /**
008 * Information about a state frame.
009 *
010 * @author Mathias Ricken
011 */
012 public class StackFrameInfo {
013 /**
014 * Unique ID of the thread this state frame belongs to.
015 */
016 long _threadId;
017
018 /**
019 * Unique ID of the object that is currently "this"..
020 */
021 Long _thisId;
022
023 /**
024 * Path of the source file.
025 */
026 String _sourcePath;
027
028 /**
029 * Line number.
030 */
031 int _lineNumber;
032
033 /**
034 * Index in the byte code.
035 */
036 long _codeIndex;
037
038 /**
039 * Constructor for StackFrameInfo.
040 * @param threadId ID of the thead
041 * @param thisId ID of this
042 * @param sourcePath path to source
043 * @param lineNumber line number
044 * @param codeIndex index in byte code
045 */
046 public StackFrameInfo(long threadId, Long thisId, String sourcePath, int lineNumber, long codeIndex) {
047 _threadId = threadId;
048 _thisId = thisId;
049 _sourcePath = sourcePath;
050 _lineNumber = lineNumber;
051 _codeIndex = codeIndex;
052 }
053
054 /**
055 * Constructor for StackFrameInfo.
056 * @param sf state frame
057 */
058 public StackFrameInfo(StackFrame sf) {
059 _threadId = sf.thread().uniqueID();
060 ObjectReference objectReference = sf.thisObject();
061 if (objectReference!=null) {
062 _thisId = objectReference.uniqueID();
063 }
064 else {
065 _thisId = null;
066 }
067 _lineNumber = sf.location().lineNumber();
068 _codeIndex = sf.location().codeIndex();
069 try {
070 _sourcePath = sf.location().sourcePath();
071 }
072 catch(AbsentInformationException e) {
073 _sourcePath = "?";
074 }
075 }
076
077 /**
078 * Returns the thread ID.
079 * @return thread ID.
080 */
081 public long getThreadId() {
082 return _threadId;
083 }
084
085 /**
086 * Returns ID of this, or null if static or native.
087 * @return this ID, or null if static or native
088 */
089 public Long getThisId() {
090 return _thisId;
091 }
092
093 /**
094 * Returns path to source.
095 * @return path to source
096 */
097 public String getSourcePath() {
098 return _sourcePath;
099 }
100
101 /**
102 * Returns line number.
103 * @return line number
104 */
105 public int getLineNumber() {
106 return _lineNumber;
107 }
108
109 /**
110 * Returns the index in the byte code
111 * @return byte code index
112 */
113 public long getCodeIndex() {
114 return _codeIndex;
115 }
116
117 /**
118 * Returns a string representation of the object.
119 * @return a string representation of the object.
120 */
121 public String toString() {
122 StringBuilder sb = new StringBuilder();
123 sb.append(_sourcePath);
124 sb.append(":");
125 sb.append(_lineNumber);
126 sb.append(" (thread id=");
127 sb.append(_threadId);
128 sb.append(", this id=");
129 if (_thisId!=null) {
130 sb.append(_thisId);
131 }
132 else {
133 sb.append("?");
134 }
135 sb.append(")");
136 return sb.toString();
137 }
138 }