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.

trincot
  • 317,000
  • 35
  • 244
  • 286
Joe Kearney
  • 7,397
  • 6
  • 34
  • 45

2 Answers2

10

This is a bit hackish, but works in MAT:

SELECT c.SIZE
FROM INSTANCEOF java.lang.Class c
WHERE c.@displayName.contains("class java.lang.Integer ")
kgibm
  • 852
  • 10
  • 22
  • 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? – haridsv Aug 01 '12 at 17:36
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
Tomas Hurka
  • 6,723
  • 29
  • 38
  • 1
    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. – Joe Kearney Dec 16 '10 at 15:42
  • 2
    Though this wasn't asked for in the question, it's worth noting that this does not execute in Eclipse MAT OQL. – Joe Kearney Dec 16 '10 at 15:49