40 |
package gnu.classpath.jdwp.id; |
package gnu.classpath.jdwp.id; |
41 |
|
|
42 |
import gnu.classpath.jdwp.JdwpConstants; |
import gnu.classpath.jdwp.JdwpConstants; |
43 |
|
import gnu.classpath.jdwp.exception.InvalidObjectException; |
44 |
|
|
45 |
import java.io.DataOutputStream; |
import java.io.DataOutputStream; |
46 |
import java.io.IOException; |
import java.io.IOException; |
47 |
|
|
48 |
/** |
/** |
49 |
* A class which represents a JDWP object id for an object |
* This is a base class for all ObjectID-like entities in JDWP, |
50 |
|
* inculding Objects, ClassObject, ClassLoader, Thread, ThreadGroup, |
51 |
|
* etc. |
52 |
* |
* |
53 |
* @author Keith Seitz <keiths@redhat.com> |
* @author Keith Seitz <keiths@redhat.com> |
54 |
*/ |
*/ |
60 |
*/ |
*/ |
61 |
public static final Class typeClass = Object.class; |
public static final Class typeClass = Object.class; |
62 |
|
|
63 |
|
// Handle to disable garbage collection |
64 |
|
private Object _handle; |
65 |
|
|
66 |
/** |
/** |
67 |
* Constructs a new <code>ObjectId</code> |
* Constructs a new <code>ObjectId</code> |
68 |
*/ |
*/ |
91 |
} |
} |
92 |
|
|
93 |
/** |
/** |
94 |
|
* Returns the object referred to by this ID |
95 |
|
* |
96 |
|
* @returns the object |
97 |
|
* @throws InvalidObjectException if the object was garbage collected |
98 |
|
* or is invalid |
99 |
|
*/ |
100 |
|
public Object getObject () |
101 |
|
throws InvalidObjectException |
102 |
|
{ |
103 |
|
Object obj = _reference.get (); |
104 |
|
if (obj == null) |
105 |
|
throw new InvalidObjectException (_id); |
106 |
|
|
107 |
|
return obj; |
108 |
|
} |
109 |
|
|
110 |
|
/** |
111 |
* Writes the id to the stream |
* Writes the id to the stream |
112 |
* |
* |
113 |
* @param outStream the stream to which to write |
* @param outStream the stream to which to write |
119 |
// All we need to do is write out our id as an 8-byte integer |
// All we need to do is write out our id as an 8-byte integer |
120 |
outStream.writeLong (_id); |
outStream.writeLong (_id); |
121 |
} |
} |
122 |
|
|
123 |
|
/** |
124 |
|
* Disable garbage collection on object |
125 |
|
*/ |
126 |
|
public void disableCollection () |
127 |
|
throws InvalidObjectException |
128 |
|
{ |
129 |
|
_handle = getObject (); |
130 |
|
} |
131 |
|
|
132 |
|
/** |
133 |
|
* Enable garbage collection on object |
134 |
|
*/ |
135 |
|
public void enableCollection () |
136 |
|
{ |
137 |
|
_handle = null; |
138 |
|
} |
139 |
} |
} |