Search code examples
visualvmheap-dumpoql

Formatting the result of oql in VisualVM


I have the following oql query running on visualvm against a heap dump and would like the creationTime field formatted as a date time field (its stored as Long).

select { id: s.id.toString(), createdAt: new Date(s.creationTime) }
from org.apache.catalina.session.StandardSession s

The above query lists the following output (snipped)

{
 id = 1010827848,
 createdAt = sun.org.mozilla.javascript.internal.NativeDate@66106135
}
...

So clearly its been "converted" into a Date but does not display it a human readable format. Doing a toString() on the date object just results in the field being displayed as Invalid Date.

  1. Is it possible to format the the Long field as a Date field?
  2. The id field's value also is off when queried using VisualVM. When I query the same heap dump using Eclipse Analyser I see the right value (which is BE27C51E8BF185A2FB3AA9164EC0C647). What could be happening to that?

Solution

    1. The output shows that you are creating JavaScript Date object. The correct part of you OQL should be: createdAt: new java.util.Date(s.creationTime)
    2. There is a known problem with a field, which is named id. See Retrieve "id" field values via VisualVM OQL query for more details. As a workaround you can use s["wrapped-object"].getValueOfField("id") instead of s.id.toString()

    With above changes your query should be:

    select { id: s["wrapped-object"].getValueOfField("id"),
    createdAt: new java.util.Date(s.creationTime).toString() }
    from org.apache.catalina.session.StandardSession s