Hi Anton,

Thank you for the questions.
I don’t know the history well enough, so will try to guess a little bit.
Please, see my attempts to answer your questions inlined below.


From: serviceability-dev <serviceability-dev-r...@openjdk.java.net> on behalf 
of "Anton W. Haubner" <anton.haub...@outlook.de>
Date: Tuesday, November 23, 2021 at 1:25 AM
To: <serviceability-dev@openjdk.java.net>
Cc: Eduard Kamburjan <edu...@ifi.uio.no>
Subject: JDWP features hidden under JDI


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.
     The project you are working on looks interesting.

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?

   My understanding is that the JDI just provides a way to store/cache the 
ObjectReference uniqueID() value.
   I feel that I understand why you consider custom `ObjectReference` 
implementation API to be useful.
   But as Chris already answered in order to implement it we need a validation 
of such uniqueID values.
   The JDWP protocol ObjectReference#ReferenceType command looks like a good 
candidate to provide this verification.
   But there still is a question if this custom API is really needed and why do 
not cache ObjectReference’s instead.
   My guess is that you want it to save on memory overhead. Is it true?
   If so, is it worth the effort and extra complexity?


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?

   My guess is that nobody was asking for this before or nobody seen reasonable 
use cases for it.
   It should not be difficult to add an API to provide this info.
   But again, the question is if your use cases can justify extra complexity.

   Thanks,
   Serguei

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

Best regards,

Anton Haubner

Reply via email to