简体   繁体   English

如何从正在运行的应用程序的堆转储中提取java类定义?

[英]How to extract java class definitions from a heap dump of a running application?

The need for extracting class definitions from a heap dump comes from the way some classes are loaded dynamically, not from static lib jars, but compiled dynamically or loaded over the network. 从堆转储中提取类定义的需要来自动态加载某些类的方式,而不是来自静态lib jar,而是动态编译或通过网络加载。 The heap dump has the same size as the actually heap so I assume all the classes are there, possibly in the permgen. 堆转储具有与实际堆相同的大小,因此我假设所有类都在那里,可能在permgen中。 The objective is to extract the definitions in the form of .class files for further examination. 目标是以.class文件的形式提取定义以供进一步检查。

There do not seem to be any tools that readily allow you to retrieve the class bits from a VM, let alone from a heap dump. 似乎没有任何工具可以让您从VM中检索类位,更不用说从堆转储中检索。 Nor is it clear that the class definition is even available in the exact same format as the contents of the .class in the VM. 也不清楚类定义是否以与VM中.class的内容完全相同的格式提供。

But there are multiple options for saving the class definition before it is loaded in the VM. 但是在将类定义加载到VM之前,有多种选项可用于保存类定义。 You could have an agent which can store the class definition, either in heap or external storage. 您可以拥有一个可以在堆或外部存储中存储类定义的代理。 This should also be possible with a custom classloader, but it is possible that it is bypassed by some other customer classloader. 这也应该可以使用自定义类加载器,但有可能被其他客户类加载器绕过。

The popular AOP tool AspectJ has an option to save the definition of instrumented class; 流行的AOP工具AspectJ可以选择保存检测类的定义; it can probably be used for your use-case. 它可能可以用于你的用例。

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

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