自动异常处理

发布于 2024-07-10 15:01:34 字数 1534 浏览 4 评论 0原文

我想知道是否存在(在 Java 世界中)能够拍摄 JVM 当前状态快照并具有以下功能的东西:

  • 在抛出异常时执行此操作。
  • 捕获局部变量、方法的参数等。
  • 将其放入一个方便的文件中,该文件可用于在 IDE 中提取或重现源代码中的情况。

前两个功能是必需的(第三个功能就很棒了)。 而且它必须适合生产使用(因此,调试器是没有办法的)。

在问这个问题之前,我已经搜索了 WWW(尽可能长的时间),并找到了一些指示:

  • Cajoon Interceptor :正如 Dzone 帖子中所述,它是一个被动 JVM 代理,满足三个要求! 但是,它有两个缺点:您必须付费并且该网站已关闭(也许没有机会支付任何费用)。
  • AviCode Intercept Studio:Cajoon 的 .NET 等效项。 只是为了提供一些见解。
  • JavaFrame:好的,这是一条推文,但它指向一个可用的 SVN 存储库,其中包含源代码JVM 代理的代码(根据 MIT 许可)看起来不错(我将尝试一下)。

那么,也许我正在寻找一个不存在的解决方案? 这并不紧急,但我有一个项目的想法,探索这条“未知”(?)路径并得到一些真实的东西会很棒。

似乎很清楚,它将是一个 JVM 代理(来自 JVMTI 的异常事件,对于 示例)。

最后,我要强调维基百科的异常处理文章中的以下段落:

在运行时引擎环境中,例如 Java 或 .NET,有一些工具可以 附加到运行时引擎和每个 兴趣异常的时间 发生时,他们记录调试 内存中存在的信息 抛出异常的时间 (调用堆栈和堆值)。 这些 工具称为自动异常 处理或错误拦截工具 并提供“根本原因”信息 对于例外情况。

就是这个想法。 我希望有人能给我一些见解,或者也许将来有人会从这篇不起眼的帖子中得到启发:)

谢谢!

I was wondering if something exists (in Java world) able to take an snapshot of the JVM current state with the following features:

  • Do it while an exception is being thrown.
  • Capture local variables, method's arguments, etc.
  • Put it in a handy file which can be used to extract or reproduce in a IDE the situation in your source code.

The two first features are required (third would be awesome). And it must be suitable for production use (so, there is no way about debuggers).

Before asking this I've searched through the WWW (as long as possible) and I found some pointers:

  • Cajoon Interceptor: As said in Dzone post, it's a passive JVM agent which fulfill the three requirements! But, it has two downsides: you must pay for it and the site is down (maybe there is no chance to pay anything).
  • AviCode Intercept Studio: Cajoon's .NET equivalent. Just to give some insight about.
  • JavaFrame: Ok, it's a tweet, but it points to a available SVN repo which have the source code (under MIT license) of a JVM agent which looks fine (I'm going to give a try to it).

So, maybe I'm looking for a non existent solution? It's not urgent, but I had this idea for a project and it would be great to explore this "unknown" (?) path and get something real.

It seems to be clear that it would be a JVM agent (exception event from JVMTI, for example).

At last, I would highlight the followin paragraph from Wikipedia's Exception Handling article:

In runtime engine environments such as
Java or .NET, there exist tools that
attach to the runtime engine and every
time that an exception of interest
occurs, they record debugging
information that existed in memory at
the time the exception was thrown
(call stack and heap values). These
tools are called Automated Exception
Handling or Error Interception tools
and provide 'root-cause' information
for exceptions.

That's the idea. I hope somebody can give me some insight or maybe, in the future, somebody get inspired by this humble post :)

Thanks!

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

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

发布评论

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

评论(4

云仙小弟 2024-07-17 15:01:34

我查看了 JavaFrame ,它似乎是一个很好的起点。 只需安装 Apache Ant,在 javaframe 目录中执行 ant 并启动测试套件(在 test 目录内):

LD_LIBRARY_PATH=../build/native/ java -agentlib:frameintrospect -classpath ../build/classes/:. org.thobe.frame.Test

它不会获取任何局部变量,但会尝试。 因此,正如我所说,这可以作为一个起点。 我希望进一步了解它的用法,但是没有时间和没有文档(有很多名为 JavaFrame 的项目)是很糟糕的情况。

也许有一天可以再次这样做。 是的,再来一次。 还有 Cajoon,它看起来很有前途而且很闪亮,但它的网站已经关闭,并且没有任何可下载的 jar 可供尝试。

谢谢大家!

PD.:仅供参考,我在研究时发现的一些链接:

I give a look to JavaFrame and it seems a good starting point. Just install Apache Ant, do ant in the javaframe directory and launch the test suite (inside test directory) with:

LD_LIBRARY_PATH=../build/native/ java -agentlib:frameintrospect -classpath ../build/classes/:. org.thobe.frame.Test

It does not get any local variable but it tries. So, as I said, it can be an starting point. I hope to get further about its usage, but no time and no documentation (there are lots of projects named JavaFrame) are bad circumstances.

Maybe some day it can be done again. Yes, again. There was Cajoon, it looked promising and shiny but its website is down and there is no trace of any downloadable jar to try.

Thanks to everybody!

PD.: Just for reference, some links I found while researching:

不乱于心 2024-07-17 15:01:34

您可能想了解 NetBeans 在自动使用日志记录方面所做的工作:http://wiki.netbeans.org /使用记录规范

至于转储局部变量,我想您可以简单地使用调试器,例如 bajafresh4life 提到的调试器。

You may want to look into the work that NetBeans has done regarding automated use logging: http://wiki.netbeans.org/UsageLoggingSpecification.

As for dumping out local variables, I would imagine that you could simply use a debugger, such as the one that bajafresh4life mentioned.

-小熊_ 2024-07-17 15:01:34

也许可以用 AspectJ 来完成?

Maybe it could be done with AspectJ?

涫野音 2024-07-17 15:01:34

不确定这在生产环境中是否可行,但有 Omniscient 调试器:

如果你的调试器可以“时间倒退”怎么办? 这会让调试更容易吗? 通过简单地记录所有变量分配,基本上可以做到这一点。 这是全知调试的基本思想。 令人惊奇的是,可以用这种方式调试非常大的程序——Ant、JUnit、调试器本身。

http://www.lambdacs.com/debugger/

Not sure if this is viable in a production environment, but there's the Omniscient debugger:

What if your debugger could go "go backwards in time?" Would that make debugging easier? By simply recording all variable assignments, it is possible to do essentially this. This is the underlying idea for omniscient debugging. The amazing part is that significantly large programs can be debugged in this fashion -- Ant, JUnit, the debugger itself.

http://www.lambdacs.com/debugger/

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