I would like to execute an OQL query in VisualVM (v1.4.4) to retrieve the (non-static) field names for an object.
The OQL documentation describes heap.findClass(className)
. This returns an object which includes a fields
property (an array of field names).
When I execute the following OQL...
heap.findClass('java.io.ByteArrayInputStream').fields;
... it returns an array of 4 field objects (ByteArrayInputStream
has 4 fields - buf
, count
, mark
, and pos
- I am assuming these are what are being returned):
org.netbeans.lib.profiler.heap.HprofField@56de8c
org.netbeans.lib.profiler.heap.HprofField@56de95
org.netbeans.lib.profiler.heap.HprofField@56de9e
org.netbeans.lib.profiler.heap.HprofField@56dea7
If I then try to manipulate this array, for example to access each field's name
and signature
properties (as described in the OQL docs), I get no results. I can't even get the length of the array. For example:
heap.findClass('java.io.ByteArrayInputStream').fields.length;
and:
heap.findClass('java.io.ByteArrayInputStream').fields[0];
Both of the above statements return <no results>
.
What am I doing wrong? Probably something basic. I not very familiar with JavaScript - or with how data is displayed in VisualVM, for that matter.
You need to use map() function. The following OQL retrieves the field names of ByteArrayInputStream
class:
select map(heap.findClass('java.io.ByteArrayInputStream').fields, 'it.name')