javamemory-leakseclipse-memory-analyzereclipse-mat

Eclipse MAT shows no stack for many threads


I have a leak in my code, and I've got a memory dump that I'm looking at with the awesome Eclipse Memory Analyzer tool.

Using the Thread_Overview, I can see that I have too many threads. However, only a few show stacks. The bulk of them (which are probably my leaks) show a status of 2 (BLOCKED), yet have no stacks.

Any idea what it means when there's no stack in the dump? Perhaps the thread is dead, but the reference is still kept in memory (ie. a leak)?

(Java 6 on Windows 2K if if makes any difference)


Solution

  • It means the thread has terminated. That's why no stack.

    What threw me was this: the status of 2 is NOT blocked, but terminated. This is because the field threadStatus is a bit field that's decoded by sun.misc.VM.toThreadState(). I thought threadStatus was the thread state enum, but it's not. You have to read that method to see what the real state is. On windows, it's this:

    public static Thread.State toThreadState(int paramInt)
    {
     if ((paramInt & 0x4) != 0)
       return Thread.State.RUNNABLE;
     if ((paramInt & 0x400) != 0)
       return Thread.State.BLOCKED;
     if ((paramInt & 0x10) != 0)
       return Thread.State.WAITING;
     if ((paramInt & 0x20) != 0)
       return Thread.State.TIMED_WAITING;
     if ((paramInt & 0x2) != 0)
       return Thread.State.TERMINATED;
     if ((paramInt & 0x1) == 0) {
       return Thread.State.NEW;
     }
     return Thread.State.RUNNABLE;
    }
    

    So, the when threadStatus is 2, it means the thread's been terminated.