JVM 堆栈自省

发布于 2024-12-05 08:46:26 字数 436 浏览 0 评论 0原文

有没有办法在 JVM 上以编程方式检查堆栈的内容(包括值和值的类型以及当前指令点)(即使它是特定于供应商的)?

例如,我想检查当前的激活帧并提取它所属的方法名称以及堆栈变量。此外,我希望能够以这种方式迭代激活帧。

这可能吗?乍一看, JVMTI 似乎允许这样做,但它的目的是用作本机接口。它已被用来实现Java库显然,它可以做这些事情——但这似乎有点过时了。我想知道是否有一个解决方案集成到 JVM api 中,或者其他一些跨平台 JVM 库允许这样做。

Is there a way to inspect the contents of the stack (both in terms of the values and the type of the values, and the current instruction point) programmatically on the JVM (even if it's vendor-specific)?

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

Is this possible? At a first glance, the JVMTI seems to allow this, but its meant to be used as a native interface. It has been used to implement a Java library that can do these things, apparently - but this seems to be a bit dated. I was wondering if there is a solution integrated into the JVM api, or some other cross-platform JVM library that allows this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

白龙吟 2024-12-12 08:46:26

我发现的最接近的是 Javaflow 它将带有局部变量的堆栈保存为对象。您还可以使用它将堆栈恢复到已保存的状态。

The closest I have 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.

痴情换悲伤 2024-12-12 08:46:26

我相信 Java 平台调试器架构 (JPDA)就是您正在寻找的。

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

天赋异禀 2024-12-12 08:46:26

有什么问题
Thread.currentThread().getStackTrace()?正如此处指出的: 堆栈溢出评论

What is wrong with
Thread.currentThread().getStackTrace() ? as poiinted out here: stack overflow comment

ぽ尐不点ル 2024-12-12 08:46:26

查看此页面:
http://download.oracle.com /javase/7/docs/webnotes/tsg/TSG-VM/html/tools.html

他们列出了一个 jstack 实用程序:

该实用程序可以从 Java 进程获取 Java 和本机堆栈信息。在 Solaris OS 和 Linux 上,该实用程序还可以从核心文件或远程调试服务器获取信息。请参阅 2.11 jstack 实用程序。

我没用过,不过用过jdk自带的Visual VM工具。

哈特哈,
詹姆斯

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

They have a jstack utility listed:

This utility can obtain Java and native stack information from a Java process. On Solaris OS and Linux the utility can get the information also from a core file or a remote debug server. See 2.11 jstack Utility.

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

HTH,
James

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文