get static fields of a class in a heap dump in OQL
Asked Answered
A

2

8

I have a heap dump and I'm using Eclipse MAT, though I suppose this should work through visualvm or whatever OQL client.

We can select fields of all instances of a class by doing something like

select s.field1, s.field2 from org.me.MyClass

... but this is restricted to member variables, and to types with instances.

How can select the static fields of a class with no instances?

This is somewhat related to this other question.

Autry answered 20/10, 2010 at 9:38 Comment(0)
C
7

To access static field 'props' of class java.lang.System you can use (in VisualVM)

select heap.findClass("java.lang.System").statics.props
select heap.findClass("java.lang.System").props
Cimmerian answered 15/12, 2010 at 20:9 Comment(2)
Excellent, thanks. Both of these work. select heap.findClass("java.lang.System").statics gives something like a map from field name to value, which is handy.Autry
Though this wasn't asked for in the question, it's worth noting that this does not execute in Eclipse MAT OQL.Autry
R
10

This is a bit hackish, but works in MAT:

SELECT c.SIZE
FROM INSTANCEOF java.lang.Class c
WHERE [email protected]("class java.lang.Integer ")
Remove answered 26/3, 2012 at 17:56 Comment(1)
Very clever, worked for me, except that it selected the inner classes also. I tried using c.@name, which worked in the select list, but not in where clause. It seems like c is IClass (the MAT representation of Class) in where clause while it is java.lang.Class in select list, how does it work?Intellectuality
C
7

To access static field 'props' of class java.lang.System you can use (in VisualVM)

select heap.findClass("java.lang.System").statics.props
select heap.findClass("java.lang.System").props
Cimmerian answered 15/12, 2010 at 20:9 Comment(2)
Excellent, thanks. Both of these work. select heap.findClass("java.lang.System").statics gives something like a map from field name to value, which is handy.Autry
Though this wasn't asked for in the question, it's worth noting that this does not execute in Eclipse MAT OQL.Autry

© 2022 - 2024 — McMap. All rights reserved.