We often need to take thread dumps, using jstack or similar tools, and would like to do so without the overhead of safepoints. This is particularly important when the system is under heavy load, as we've seen safepoints take 30+ seconds. Administrators often have the idea to automatically capture a thread dump when the system becomes unhealthy, but this can make the problem worse.
I had the idea to use AsyncGetCallTrace() to implement an asynchronous version of jstack. It works as follows: * Install a signal handler that captures the stack to a global memory location. * Register a ThreadStart event which captures the JNI environment and pthread_t. * Start an agent thread which accepts connections on a socket. * When a client connects, it sends a signal to each thread using pthread_kill() and writes out the stack trace after the signal handler completes. I would love to have feedback on the code: https://github.com/airlift/astack Is this a reasonable approach? Is something like this already available in the JVM?
