Analyzing Finalizer

Finalizers are executed when the internal garbage collection cleans up the objects. Since you have no control over the finalizer execution, it is recommended not to use them. Because the memory can only be released when the finalize method finished, long running tasks in the finalizer can block the garbage collection. To get the finalizers overview select Finalizer Overview Query from the query list:

Finalizer overview menu option and report

This query includes the following subqueries:

Finalizer in Processing

Extract the object currently processed by Finalizer Thread. This query returns the currently processed object by the Finalizer Thread if any. The returned object can be processed for one of the following reasons:

  • it is blocking
  • it is long running
  • the finalizer queue was or is still full.

Use the finalizer queue query to check the queue.

Ready for Finalizer Thread

This query shows the objects ready for finalization in their processing order. Following reasons can cause a full finalizer queue:

  • The currently processed object is blocking or long running (please use our finalizer in processing query to check).
  • The application made use of too many objects with finalize() which are queued up in memory.
Note: On J9 JVM-based dumps (e.g. IBM Java, OpenJ9), as expected, this list shows objects waiting to be finalized. On previous versions of Memory Analyzer (1.10 and earlier) it also showed those which have already been finalized and are waiting to be garbage collected. Those objects where finalization has been completed are not now shown by this query, but might be in the unreachable objects histogram if they are waiting to be reclaimed.

States

  1. Initially objects with a finalize method start in the UNFINALIZED state. With a J9 heap dump this is visible as an inbound <Unfinalized> reference from the java.lang.Runtime object.
  2. Once the object is no longer reachable it goes onto the finalizer queue, visible via this query and with J9 heap dumps as a FINALIZABLE GC root.
  3. Once finalization is completed the object is not seen in either of these two ways. Normally it would be garbage collected, but if the finalizer() code made the object reachable again by storing a reference to it in an ordinary object it might still be strongly reachable.

Additionally a class-level summary of the objects is provided

Finalizer Thread This query shows the daemon thread which performs the object finalizations.
Finalizer Thread Locals

This query shows the thread locals of the daemon thread that performs the object finalizations. If there are any, this indicates misuse in at least one of the processed finalizers ( finalize() implemented wrong) and might cause severe problems (e.g. unreclaimed memory permanently hold by the finalizer thread or finalizer processed under useless thread locals harming application logic)

The component report also includes information about objects belonging to the component which implement the finalize() method and so could be finalized at some point.