Java Object Map Traversal

from EclipseIde -- Is my terminology correct for this page title?

Can eclipse or its plug-ins give a view of all instances of a given class, or all instances of all classes in a given package or similar? The variables view is great but (quite reasonably) only shows the variable of the instance you are looking at. Something like a grid showing the values of the variables of all instances of the class feels like it would be a very useful view and let you see the state of play at a glance.

Are you referring to all instances in a running vm visible through a debugger, or all references to a class in the source code? If the latter, then yes you can. -- ChanningWalton

If you're talking about the former - it might be possible to implement something like that through the java profiling apis, but I'd think it would have a huge impact on the speed of running code. Can you give an example of a situation in which such information would be useful? (ie. why would you care about the state of variables not accessible in the current scope while debugging?)

I am indeed referring to the former: the ability to see all instances of a given class in a running vm.

I cant give a good concrete example, I simply 'feel' it’s useful, which by definition is a weak argument especially when everyone else in the world is getting along happily without it. The reason I feel it would be useful is because it would give the big picture of the current state of play of data in memory. Its true that you can see each instance individually but you have to arrange to stop in the right place and find them. Its not that it’s difficult to arrange to do this, but by watching instances of a class you would not have to do this.

Here’s a made up and tenuous example: say I am using something like Hibernate to transparently persist my objects. It would be simple for the developer to see what is going to be committed if he breaks just before the commit and looks at all the instances of the persistable class(es) he has in memory. The current alternatives are presumably to (1) arrange to look at each instance each time its altered, which I would have thought was a more time consuming process for the developer, or to (2) only break before the commit and rely on being able to get to all the objects of interest by inspecting the different layers of the stack etc.

Consider also: when debugging a database application its normal to look at a grid of selected rows from a given table, perhaps even to see related rows from other tables. One could argue that this is not essential since you could look at any given row as it was read or committed by the application. However its very useful to be able to examine an interesting set of data in a single view. I was asking if there is a similar facility for the objects in memory.

Java itself is lacking any ability to traverse the entire graph of objects, Ruby (and I believe Python) allow access to the object graph - though I've never felt the need to use it. The answer for java is, it's almost definitely possible, and it's also definitely a lot of work. I'm sure many people have felt that it would be vaguely useful, but unless a severe bout of boredom strikes, the effort isn't worth the outcome.

JavaSpider is close to what you're after. When running the debugger, you can right click a variable and select "Explore", which opens the java spider view. You can then inspect the object graph is a graph view. -- ChanningWalton

I tried javaspider briefly but was under the impression that it was created specifically to work when creating eclipse plugins and would not work for general projects.

I think that the eclipse ide does indeed have the required information to get at all the objects. However, as you say, the pain of not having such a viewer appears less than the pain of creating one.

JavaSpider does work in the debugger although it took me an age to see how

The JavaSpider view will open on the object.


EditText of this page (last edited February 18, 2004) or FindPage with title or text search