Full dump of a stream (GC, JNI streams, etc.) Programmatically

I have some code that generates a thread dump based on ThreadMXBean

, but these are just thread statistics along with their stack trace, is there a way to get other parts of the complete Java thread dump generated with kill -SIGQUIT

?

Here I am dealing with the following parts: -

GC Themes

"GC task thread#0 (ParallelGC)" prio=3 tid=0x0000000100120000 nid=0x3 runnable
"GC task thread#1 (ParallelGC)" prio=3 tid=0x0000000100131000 nid=0x4 runnable

      

VM Thread

"VM Periodic Task Thread" prio=3 tid=0x0000000101238800 nid=0x19 waiting on condition

      

JNI Global Reference Reference Count

JNI global references: 1925

      

Java heap usage representation

1 Heap
2 PSYoungGen      total 466944K, used 178734K [0xffffffff45c00000, 0xffffffff70800000, 0xffffffff70800000)
3 eden space 233472K, 76% used [0xffffffff45c00000,0xffffffff50ab7c50,0xffffffff54000000)
4 from space 233472K, 0% used [0xffffffff62400000,0xffffffff62400000,0xffffffff70800000)
5 to   space 233472K, 0% used [0xffffffff54000000,0xffffffff54000000,0xffffffff62400000)
6 PSOldGen        total 1400832K, used 1400831K [0xfffffffef0400000, 0xffffffff45c00000, 0xffffffff45c00000)
7 object space 1400832K, 99% used [0xfffffffef0400000,0xffffffff45bfffb8,0xffffffff45c00000)
8 PSPermGen       total 262144K, used 248475K [0xfffffffed0400000, 0xfffffffee0400000, 0xfffffffef0400000)
9 object space 262144K, 94% used [0xfffffffed0400000,0xfffffffedf6a6f08,0xfffffffee0400000)

      

My code:

public static String threadDump() {
    String s = "";
    ThreadMXBean bean = ManagementFactory.getThreadMXBean();
    ThreadInfo[] theadDumps = bean.dumpAllThreads(true, true);
    s += "Number threads: " + theadDumps.length + "\n";

    s += "========= Threads ===========\n";
    for (ThreadInfo threadInfo : theadDumps) {
        String t = threadInfo.toString();
        t = t.substring(0, t.indexOf("\n"));
        s += t + "\n";
        for (StackTraceElement stackTraceElement : threadInfo.getStackTrace()) {
            s += "   " + stackTraceElement + "\n";
        }
        s += "======\n";
    }
    return s;
}

      

+3


source to share


1 answer


The thread replicas generated by kill-3 give you a dump of the "application" and "vm" threads. The vm topics you are linking to and the GC statistics are not part of the ThreadMXBean. You can get the data you need for GC statistics using GarbageCollectorMXBean. The only use of VM threads I've come across is to determine if we are out of memory (i.e. Busy GC threads). But you can still do it with the data you get from GarbageCollectorMXBean. I didn't come across the need for "JNI global references", mainly because I didn't have anything that used JNI directly.



0


source







All Articles