1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.jdwp
.host
;
12 import cc
.squirreljme
.jdwp
.JDWPCommand
;
13 import cc
.squirreljme
.jdwp
.JDWPCommandSetObjectReference
;
14 import cc
.squirreljme
.jdwp
.JDWPErrorType
;
15 import cc
.squirreljme
.jdwp
.JDWPException
;
16 import cc
.squirreljme
.jdwp
.JDWPHostController
;
17 import cc
.squirreljme
.jdwp
.JDWPPacket
;
18 import cc
.squirreljme
.jdwp
.JDWPValue
;
19 import cc
.squirreljme
.jdwp
.JDWPValueTag
;
20 import cc
.squirreljme
.jdwp
.host
.views
.JDWPViewObject
;
21 import cc
.squirreljme
.jdwp
.host
.views
.JDWPViewType
;
24 * Object reference command set.
28 public enum JDWPHostCommandSetObjectReference
29 implements JDWPCommandHandler
31 /** The type that an object is. */
32 REFERENCE_TYPE(JDWPCommandSetObjectReference
.REFERENCE_TYPE
)
39 public JDWPPacket
execute(JDWPHostController __controller
,
43 // Obtain the object and the type of that object
44 Object object
= __controller
.readObject(__packet
, false);
45 Object type
= (__controller
.viewType().isValid(object
) ?
46 object
: __controller
.viewObject().type(object
));
48 // Register it for future reference
49 __controller
.getState().items
.put(object
);
51 __controller
.getState().items
.put(type
);
53 JDWPPacket rv
= __controller
.reply(
54 __packet
.id(), JDWPErrorType
.NO_ERROR
);
56 // Write the details of this class
57 __controller
.writeTaggedId(rv
, type
);
63 /** Get field values. */
64 GET_VALUES(JDWPCommandSetObjectReference
.GET_VALUES
)
71 public JDWPPacket
execute(JDWPHostController __controller
,
75 JDWPViewObject viewObject
= __controller
.viewObject();
76 JDWPViewType viewType
= __controller
.viewType();
78 // The type is needed to ensure the field class is valid
79 Object object
= __controller
.readObject(__packet
, false);
80 Object type
= viewObject
.type(object
);
82 // Read in all field indexes and check for their validity
83 int numFields
= __packet
.readInt();
84 int[] fields
= new int[numFields
];
85 for (int i
= 0; i
< numFields
; i
++)
87 int fieldDx
= __packet
.readId();
88 if (!viewType
.isValidField(type
, fieldDx
))
89 throw JDWPErrorType
.INVALID_FIELD_ID
.toss(type
, fieldDx
);
94 JDWPPacket rv
= __controller
.reply(
95 __packet
.id(), JDWPErrorType
.NO_ERROR
);
97 // Write field mappings
98 rv
.writeInt(numFields
);
99 for (int i
= 0; i
< numFields
; i
++)
100 try (JDWPValue value
= __controller
.value())
102 // Determine the field type and its tag
103 String fieldSig
= viewType
.fieldSignature(type
, fields
[i
]);
104 JDWPValueTag tag
= JDWPValueTag
.fromSignature(fieldSig
);
106 // Read the field value, fallback if not valid
107 if (!viewObject
.readValue(object
, fields
[i
], value
))
108 value
.set(tag
.defaultValue
);
110 // Always write as tagged value
111 __controller
.writeValue(rv
, value
, tag
, false);
113 // Store object for later use
114 if (value
.get() != null && tag
.isObject
)
115 __controller
.getState().items
.put(value
.get());
122 /** Is this object garbage collected? */
123 IS_COLLECTED(JDWPCommandSetObjectReference
.IS_COLLECTED
)
130 public JDWPPacket
execute(JDWPHostController __controller
,
134 // Read the value but do nothing for it
135 __controller
.readObject(__packet
, false);
137 // If we still know about this object it was not GCed
138 JDWPPacket rv
= __controller
.reply(
139 __packet
.id(), JDWPErrorType
.NO_ERROR
);
140 rv
.writeBoolean(false);
149 /** The base command. */
150 public final JDWPCommand command
;
152 /** The ID of the packet. */
156 * Returns the ID used.
158 * @param __id The ID used.
161 JDWPHostCommandSetObjectReference(JDWPCommand __id
)
164 this.id
= __id
.debuggerId();
172 public final JDWPCommand
command()
182 public final int debuggerId()