39 |
|
|
40 |
package gnu.classpath.jdwp.processor; |
package gnu.classpath.jdwp.processor; |
41 |
|
|
|
import gnu.classpath.jdwp.IVirtualMachine; |
|
|
import gnu.classpath.jdwp.Jdwp; |
|
42 |
import gnu.classpath.jdwp.JdwpConstants; |
import gnu.classpath.jdwp.JdwpConstants; |
43 |
|
import gnu.classpath.jdwp.VMVirtualMachine; |
44 |
import gnu.classpath.jdwp.exception.InvalidFieldException; |
import gnu.classpath.jdwp.exception.InvalidFieldException; |
45 |
import gnu.classpath.jdwp.exception.JdwpException; |
import gnu.classpath.jdwp.exception.JdwpException; |
46 |
import gnu.classpath.jdwp.exception.JdwpInternalErrorException; |
import gnu.classpath.jdwp.exception.JdwpInternalErrorException; |
47 |
import gnu.classpath.jdwp.exception.NotImplementedException; |
import gnu.classpath.jdwp.exception.NotImplementedException; |
|
import gnu.classpath.jdwp.id.IdManager; |
|
48 |
import gnu.classpath.jdwp.id.ObjectId; |
import gnu.classpath.jdwp.id.ObjectId; |
49 |
import gnu.classpath.jdwp.id.ReferenceTypeId; |
import gnu.classpath.jdwp.id.ReferenceTypeId; |
50 |
import gnu.classpath.jdwp.util.Value; |
import gnu.classpath.jdwp.util.Value; |
61 |
* |
* |
62 |
* @author Aaron Luchko <aluchko@redhat.com> |
* @author Aaron Luchko <aluchko@redhat.com> |
63 |
*/ |
*/ |
64 |
public class ObjectReferenceCommandSet implements CommandSet |
public class ObjectReferenceCommandSet |
65 |
|
extends CommandSet |
66 |
{ |
{ |
|
// Our hook into the jvm |
|
|
private final IVirtualMachine vm = Jdwp.getIVirtualMachine(); |
|
|
|
|
|
// Manages all the different ids that are assigned by jdwp |
|
|
private final IdManager idMan = Jdwp.getIdManager(); |
|
|
|
|
67 |
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) |
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) |
68 |
throws JdwpException |
throws JdwpException |
69 |
{ |
{ |
112 |
private void executeReferenceType(ByteBuffer bb, DataOutputStream os) |
private void executeReferenceType(ByteBuffer bb, DataOutputStream os) |
113 |
throws JdwpException, IOException |
throws JdwpException, IOException |
114 |
{ |
{ |
115 |
ObjectId oid = idMan.readId(bb); |
ObjectId oid = idMan.readObjectId(bb); |
116 |
Object obj = oid.getObject(); |
Object obj = oid.getObject(); |
117 |
Class clazz = obj.getClass(); |
Class clazz = obj.getClass(); |
118 |
ReferenceTypeId refId = idMan.getReferenceTypeId(clazz); |
ReferenceTypeId refId = idMan.getReferenceTypeId(clazz); |
122 |
private void executeGetValues(ByteBuffer bb, DataOutputStream os) |
private void executeGetValues(ByteBuffer bb, DataOutputStream os) |
123 |
throws JdwpException, IOException |
throws JdwpException, IOException |
124 |
{ |
{ |
125 |
ObjectId oid = idMan.readId(bb); |
ObjectId oid = idMan.readObjectId(bb); |
126 |
Object obj = oid.getObject(); |
Object obj = oid.getObject(); |
127 |
|
|
128 |
int numFields = bb.getInt(); |
int numFields = bb.getInt(); |
131 |
|
|
132 |
for (int i = 0; i < numFields; i++) |
for (int i = 0; i < numFields; i++) |
133 |
{ |
{ |
134 |
Field field = (Field) idMan.readId(bb).getObject(); |
Field field = (Field) idMan.readObjectId(bb).getObject(); |
135 |
try |
try |
136 |
{ |
{ |
137 |
field.setAccessible(true); // Might be a private field |
field.setAccessible(true); // Might be a private field |
154 |
private void executeSetValues(ByteBuffer bb, DataOutputStream os) |
private void executeSetValues(ByteBuffer bb, DataOutputStream os) |
155 |
throws JdwpException, IOException |
throws JdwpException, IOException |
156 |
{ |
{ |
157 |
ObjectId oid = idMan.readId(bb); |
ObjectId oid = idMan.readObjectId(bb); |
158 |
Object obj = oid.getObject(); |
Object obj = oid.getObject(); |
159 |
|
|
160 |
int numFields = bb.getInt(); |
int numFields = bb.getInt(); |
161 |
|
|
162 |
for (int i = 0; i < numFields; i++) |
for (int i = 0; i < numFields; i++) |
163 |
{ |
{ |
164 |
Field field = (Field) idMan.readId(bb).getObject(); |
Field field = (Field) idMan.readObjectId(bb).getObject(); |
165 |
Object value = Value.getUntaggedObj(bb, field.getType()); |
Object value = Value.getUntaggedObj(bb, field.getType()); |
166 |
try |
try |
167 |
{ |
{ |
194 |
private void executeInvokeMethod(ByteBuffer bb, DataOutputStream os) |
private void executeInvokeMethod(ByteBuffer bb, DataOutputStream os) |
195 |
throws JdwpException, IOException |
throws JdwpException, IOException |
196 |
{ |
{ |
197 |
ObjectId oid = idMan.readId(bb); |
ObjectId oid = idMan.readObjectId(bb); |
198 |
Object obj = oid.getObject(); |
Object obj = oid.getObject(); |
199 |
|
|
200 |
ObjectId tid = idMan.readId(bb); |
ObjectId tid = idMan.readObjectId(bb); |
201 |
Thread thread = (Thread) tid.getObject(); |
Thread thread = (Thread) tid.getObject(); |
202 |
|
|
203 |
ReferenceTypeId rid = idMan.readReferenceTypeId(bb); |
ReferenceTypeId rid = idMan.readReferenceTypeId(bb); |
204 |
Class clazz = rid.getType(); |
Class clazz = rid.getType(); |
205 |
|
|
206 |
ObjectId mid = idMan.readId(bb); |
ObjectId mid = idMan.readObjectId(bb); |
207 |
Method method = (Method) mid.getObject(); |
Method method = (Method) mid.getObject(); |
208 |
|
|
209 |
int args = bb.getInt(); |
int args = bb.getInt(); |
215 |
} |
} |
216 |
|
|
217 |
int invokeOptions = bb.getInt(); |
int invokeOptions = bb.getInt(); |
218 |
|
boolean suspend = ((invokeOptions |
219 |
|
& JdwpConstants.InvokeOptions.INVOKE_SINGLE_THREADED) |
220 |
|
!= 0); |
221 |
|
if (suspend) |
222 |
|
{ |
223 |
|
// We must suspend all other running threads first |
224 |
|
VMVirtualMachine.suspendAllThreads (); |
225 |
|
} |
226 |
|
|
227 |
if ((invokeOptions & JdwpConstants.InvokeOptions.INVOKE_SINGLE_THREADED) != 0) |
boolean nonVirtual = ((invokeOptions |
228 |
{ // We must suspend all other running threads first |
& JdwpConstants.InvokeOptions.INVOKE_NONVIRTUAL) |
229 |
vm.suspendAllThreadsExcept(Thread.currentThread().getThreadGroup()); |
!= 0); |
|
} |
|
|
boolean nonVirtual; |
|
|
if ((invokeOptions & JdwpConstants.InvokeOptions.INVOKE_NONVIRTUAL) != 0) |
|
|
nonVirtual = true; |
|
|
else |
|
|
nonVirtual = false; |
|
230 |
|
|
231 |
MethodResult mr = vm.executeMethod(obj, thread, clazz, method, values, nonVirtual); |
MethodResult mr = VMVirtualMachine.executeMethod(obj, thread, |
232 |
|
clazz, method, |
233 |
|
values, nonVirtual); |
234 |
Object value = mr.getReturnedValue(); |
Object value = mr.getReturnedValue(); |
235 |
Exception exception = mr.getThrownException(); |
Exception exception = mr.getThrownException(); |
236 |
|
|
237 |
ObjectId eId = idMan.getId(exception); |
ObjectId eId = idMan.getObjectId(exception); |
238 |
Value.writeTaggedValue(os, value); |
Value.writeTaggedValue(os, value); |
239 |
eId.writeTagged(os); |
eId.writeTagged(os); |
240 |
} |
} |
242 |
private void executeDisableCollection(ByteBuffer bb, DataOutputStream os) |
private void executeDisableCollection(ByteBuffer bb, DataOutputStream os) |
243 |
throws JdwpException, IOException |
throws JdwpException, IOException |
244 |
{ |
{ |
245 |
ObjectId oid = idMan.readId(bb); |
ObjectId oid = idMan.readObjectId(bb); |
246 |
oid.disableCollection(); |
oid.disableCollection(); |
247 |
} |
} |
248 |
|
|
249 |
private void executeEnableCollection(ByteBuffer bb, DataOutputStream os) |
private void executeEnableCollection(ByteBuffer bb, DataOutputStream os) |
250 |
throws JdwpException, IOException |
throws JdwpException, IOException |
251 |
{ |
{ |
252 |
ObjectId oid = idMan.readId(bb); |
ObjectId oid = idMan.readObjectId(bb); |
253 |
oid.enableCollection(); |
oid.enableCollection(); |
254 |
} |
} |
255 |
|
|
256 |
private void executeIsCollected(ByteBuffer bb, DataOutputStream os) |
private void executeIsCollected(ByteBuffer bb, DataOutputStream os) |
257 |
throws JdwpException, IOException |
throws JdwpException, IOException |
258 |
{ |
{ |
259 |
ObjectId oid = idMan.readId(bb); |
ObjectId oid = idMan.readObjectId(bb); |
260 |
boolean collected = oid.isCollected(); |
boolean collected = (oid.getReference().get () == null); |
261 |
os.writeBoolean(collected); |
os.writeBoolean(collected); |
262 |
} |
} |
263 |
} |
} |