liveBook · Manning

Object Query Language

As explained in Troubleshooting Java, Second Edition

Object Query Language is a query language for retrieving and examining objects and related data in heap dumps.

Object Query Language (OQL) retrieves and examines objects, attributes, and references in a heap dump. It is useful when a crashed or inaccessible application cannot be investigated with a profiler, especially when manual browsing is too slow. section 10.0 section 10.4

Use OQL to answer focused diagnostic questions:

  • Which objects of a given type remain in the heap? section 10.3
  • What values do those objects contain, such as product names or name lengths? section 10.3
  • Which objects refer to them and may prevent garbage collection? section 10.3
  • How do object populations or references differ between heap dumps? section 10.3

Querying retained Product objects

In VisualVM's OQL console, select Product instances with `select p from model.Product p`. Narrow the result with `where p.name.value.length > 15`, project several values as JSON, or inspect unique referrers with `select unique(referrers(p)) from model.Product p`. A single retaining object can reveal why garbage collection cannot remove the instances. section 10.3

Figure 10.9 To switch to the OQL view in VisualVM, choose OQL Console from the drop-down menu in the upper-left corner of the heap dump tab.

Open VisualVM's OQL Console from the heap-dump tab, enter a query, run it, and inspect the returned instances. section 10.3

How Troubleshooting Java, Second Edition covers it

How deep it goes
Demonstrates selection, attribute access, JSON projection, filtering, and referrer counting, but defers more complex syntax and functions.
Examples
Uses Product selections, name projections, length filters, JSON results, unique referrers, and referrer counts.
What it assumes
Assumes access to a heap dump and basic VisualVM navigation while introducing query-based object inspection through concrete examples.
What you can do after
Diagnose memory leaks by querying retained objects, examining their values, and tracing the references that keep them reachable.
How it connects
Connects heap dumps, VisualVM, SQL-like querying, garbage collection, memory leaks, and object references.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java, Second Edition. The section links point to the parts of the book it draws on.