I am working on a JVMTI agent that monitors memory usage of an application. I have managed to monitor memory allocations on the heap using bytecode instrumentation so that a native method gets invoked whenever a new object/array gets allocated. But I am really confused about how to determine the amount of memory allocated on the stack. If you could provide any ideas, tips or links I would greatly appreciate that.

有帮助吗?

解决方案

How much detail are you hoping to get from the JVMTI interface? It looks like it only reports logical Java stack frame information which means you can't find out how much actual runtime stack space is being used, but you can use the jmethodID to figure out the layout of a Java Stack Frame to make a reasonable guess (the number of local variables is fixed for a specific method at compile time, see GetLocalVariableTable). Stack frames for native methods won't be visible. And other JVM state stored on the stack (e.g., debugging information or space used by the JIT, and thread infrastructure) won't be visible either.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top