javajvmheap-dumpfinalizer

Unexpected call to Finalizer::register


Looking at a heap dump of a JVM service (using IntelliJ's Profiler), I see the following in java.lang.ref.Finalizer:

enter image description here

What is this message supposed to mean?

unexpected call to Finalizer::register when finalization is disabled

Most of the referents under Finalizer are Postgres connections. The service makes simple SELECT calls, under low load, but the memory keeps growing monotonously. Does it indeed mean that --finalization=disabled was passed as a JVM option? (I don't control those in this environment.)


Solution

  • Does it indeed mean that --finalization=disabled was passed as a JVM option?

    No. A string you see in the heap dump is just some string in the constant pool of a loaded class. It resides there, because the string exists in the source code of java.lang.ref.Finalizer class:

    static void register(Object finalizee) {
        if (ENABLED) {
            new Finalizer(finalizee);
        } else {
            throw new InternalError("unexpected call to Finalizer::register when finalization is disabled");
        }
    }
    

    and the corresponding constant pool entry was resolved - note <resolved_references> on your screenshot.

    Even if this line of code has never been executed, the string could have been resolved for several reasons, e.g., if Class Data Sharing is enabled, or if the method is hot and has been JIT-compiled.

    Actually, this line is more like an assertion - JVM never calls this method if finalization is disabled.

    So, the presence of this string in a heap dump is irrelevant to a memory leak you observe.