00001 package gov.nasa.arc.ase.jpf.jvm.examine;
00002
00003 import gov.nasa.arc.ase.jpf.*;
00004 import gov.nasa.arc.ase.jpf.jvm.*;
00005
00006 import java.util.*;
00007
00008 public class ObjectValue implements iValue {
00009 int objectID = 0;
00010 DynamicArea heap;
00011 String classname;
00012 int lock_count;
00013 int locking_thread;
00014 List waiting_threads;
00015
00016 public ObjectValue(int v, DynamicArea da) {
00017 objectID = v;
00018 if (objectID == -1)
00019 return;
00020 heap = da;
00021 classname = heap.getClass(objectID).getClassName();
00022 lock_count = heap.monitorLockCount(objectID);
00023 waiting_threads = heap.monitorWaitingThreads(objectID);
00024 locking_thread = heap.monitorLockingThread(objectID);
00025 }
00026 public ObjectValue(long v, DynamicArea da) {
00027 objectID = (int)v;
00028 if (objectID == -1)
00029 return;
00030 heap = da;
00031 classname = heap.getClass(objectID).getClassName();
00032 lock_count = heap.monitorLockCount(objectID);
00033 waiting_threads = heap.monitorWaitingThreads(objectID);
00034 locking_thread = heap.monitorLockingThread(objectID);
00035 }
00036
00037
00038
00039
00040
00041 public boolean equals(Object o) {
00042 if (o instanceof ObjectValue) return objectID == ((ObjectValue) o).objectID;
00043 else return false;
00044 }
00045 public iValue getFieldValue(String fieldName) {
00046 long value = heap.getValue(objectID,fieldName);
00047 return State.createValue(heap.getVariableType(objectID, fieldName),
00048 value,
00049 heap);
00050 }
00051
00052
00053 public int getHoldingThread() {
00054 return locking_thread;
00055 }
00056
00057
00058
00059
00060 public String getTypeName() {
00061 return classname;
00062 }
00063
00064 public List getWaitingThreads() {
00065 return waiting_threads;
00066 }
00067
00068
00069
00070
00071 public int hashCode() {
00072 return toString().hashCode();
00073 }
00074 public String toString() {
00075 if (objectID == -1) return null;
00076 String result = "#" + objectID + "\nHolding: ";
00077 if (getHoldingThread() != -1) result += "Thread#" + getHoldingThread();
00078 result += "\nWaiting: ";
00079 for (Iterator i = getWaitingThreads().iterator(); i.hasNext();) {
00080 result += ("Thread#" + i.next() + ", ");
00081 }
00082 if (getWaitingThreads().size() > 0)
00083 return result.substring(0, result.length() - 2);
00084 else return result;
00085 }
00086 }