JVM Stack Introspection

Is there a way to check the contents of the stack (both in terms of values ​​and type of values, and from the current point of instructions) programmatically on the JVM (even if it depends on the provider)?

For example, I would like to check the current activation frame and extract the name of the method to which it belongs, as well as the stack variables. In addition, I would like to be able to iterate the activation frames in this way.

Is it possible? At first glance, the JVMTI seems to resolve this, but is intended to be used as an embedded interface. used to implement a Java library that can do these things, apparently - but it seems to be a bit outdated. I was wondering if there is a solution integrated into the JVM api or another cross-platform JVM library that allows this.

+4
source share
4 answers

I believe Java Debugger Architecture (JPDA) is what you are looking for.

+2
source

The closest I found is Javaflow , which saves the stack with local variables as an object. You can also use it to restore the stack to a saved state.

+3
source

What is wrong with Thread.currentThread().getStackTrace() ? as shown here: comment

+1
source

Check out this page: http://download.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/tools.html

They have a jstack utility:

This utility can get information about Java and the native stack from the Java process. On Solaris and Linux, the utility can also get information from the main file or the remote debug server. See 2.11 jstack utility.

I never used it, but I used the Visual VM tool that comes with jdk.

NTN, James

+1
source

All Articles