简体   繁体   English

如何调试JVM资源加载?

[英]How to debug JVM resources loading?

要在JVM中调试类加载,我们可以使用param -verbose:class ,但是......任何人都知道如何调试资源加载(例如属性文件)?

I suppose you need to look at using a profiler. 我想你需要看一下使用分析器。 Or something that uses the instrumentation interface. 或者使用仪器界面的东西。

Not sure how stable it is, but there is BTrace , which is kind of a Java version of DTrace. 不确定它有多稳定,但有BTrace ,这是一种Java版本的DTrace。

BTrace is a safe, dynamic tracing tool for the Java platform. BTrace是Java平台的安全,动态跟踪工具。 BTrace can be used to dynamically trace a running Java program. BTrace可用于动态跟踪正在运行的Java程序。 BTrace dynamically instruments the classes of the target application to inject tracing code ("bytecode tracing"). BTrace动态检测目标应用程序的类以注入跟踪代码(“字节码跟踪”)。 Tracing code is expressed in Java programming language. 跟踪代码用Java编程语言表示。

If you are doing this on a development machine, and the number of events (resources being loaded) is not too frequent, you could also just set a breakpoint in the debugger. 如果您在开发计算机上执行此操作,并且事件数(正在加载的资源)不是太频繁,您也可以在调试器中设置断点。

You could use InTrace to instrument the Classloader classes which do the loading. 您可以使用InTrace来检测执行加载的Classloader类。

For the Sun JVM, I would suggest using the following Include patterns to trace appropriate classes: 对于Sun JVM,我建议使用以下Include模式来跟踪适当的类:

  • ClassLoader 类加载器
  • URLClassPath URLClassPath
  • Loader 装载机

Resources are provided as URL s. 资源以URL的形式提供。 So, I guess to do it in "pure" Java: Install a custom ClassLoader that copies URL s into a version with a custom URLStreamHandler . 所以,我想用“纯”Java来做:安装一个自定义的ClassLoader ,它将URL复制到一个带有自定义URLStreamHandler的版本中。 Put your monitoring code in the stream handler and forward to the original. 将监控代码放在流处理程序中并转发到原始代码。

There exist a couple of techniques to debug classloading problems . 存在一些调试类加载问题的技术。 Here are good slides from the JRebel creators summarizing those techniques: Do you really get class loaders? 以下是来自JRebel创作者的好幻灯片,总结了这些技巧: 你真的得到了类加载器吗?

In a Linux environment you can try: 在Linux环境中,您可以尝试:

lsof -p <jvm pid>

It will give you a list with the descriptors used by the program associated with the specified pid. 它将为您提供一个列表,其中包含与指定pid关联的程序使用的描述符。

More Info 更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM