JDWP features hidden under JDI

Anton W. Haubner anton.haubner at outlook.de
Tue Nov 23 09:25:41 UTC 2021


Hello!

I am working on a new kind of debugger which extracts information about the
state of Java programs through the JDI to build RDF knowledge graphs.

While working on the project, I noticed that there is certain 
information about
the program state that is accessible through JDWP, but which is hidden 
by the
JDI interfaces (see below for examples).

I am curious, whether this was done to simplify the interface, or if 
there is
a deeper reason behind this, e.g. because the information in question is
unreliable etc.
If there is no such reason, I might try to modify the JDI reference
implementation to provide this information to me.

*First Example: Retrieving Objects by ID*

The ObjectReference JDI interface does allow to retrieve the unique id 
assigned to
an object by the JDWP agent.

However, it seems it is not possible to construct an ObjectReference 
from such
an id. That is, one can not quickly look up an object by its id, but has to
search through all objects to find it again.

Looking at the JDWP specification, it seems that the underlying JDWP 
protocol
does support looking up objects using just their id:
https://docs.oracle.com/en/java/javase/17/docs/specs/jdwp/jdwp-protocol.html#JDWP_ObjectReference

The reference implementation of the `ObjectReference` interface also 
seems to
only require this id to retrieve all required information:
https://github.com/openjdk/jdk/blob/dfacda488bfbe2e11e8d607a6d08527710286982/src/jdk.jdi/share/classes/com/sun/tools/jdi/ObjectReferenceImpl.java#L109

/My question now is:/
Is there a specific reason that there is no public factory method to 
construct
an ObjectReference from an object id?
Or would it be "safe" to create a custom `ObjectReference` 
implementation that
allows this, as long as it deals with the `INVALID_OBJECT` error case of 
JDWP?

*Second Example: Variable Locations*

The JDWP `VariableTable` command reply does contain the code index of 
variables.
Nevertheless, it is neither possible to retrieve the code index of a 
variable
through the `LocalVariable` JDI interface, nor through the `Method` 
interface.

Meanwhile, internally, the `LocalVariable` reference implementation does 
seem
to store the scope of a variable:
https://github.com/openjdk/jdk/blob/dfacda488bfbe2e11e8d607a6d08527710286982/src/jdk.jdi/share/classes/com/sun/tools/jdi/LocalVariableImpl.java#L56

The Eclipse JDI implementation also stores the plain code index value:
https://git.eclipse.org/c/jdt/eclipse.jdt.debug.git/tree/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/LocalVariableImpl.java#n63

Is there a specific reason, why this location information is not exposed 
in the
public interface?




Thank you very much for reading my questions.
Can you help me to answer them?

Best regards,

Anton Haubner

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/serviceability-dev/attachments/20211123/164ae369/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://mail.openjdk.java.net/pipermail/serviceability-dev/attachments/20211123/164ae369/OpenPGP_signature-0001.bin>


More information about the serviceability-dev mailing list