6

lsof is a nice tool for Unix, showing all currently open file handles.

Does anyone know a similar tool that would show all open files inside a running JVM (via JVMTI or any similar interface)?

In this particular case, it would be sufficient for me to know which class has a handle open. Method/line or even an entire chain to GC root would be fantastic, but handler owner class is already a good start.

I know I could make a heap dump, open it in a profiler and find this out, but this is a tedious task, especially for the big heaps.

4

1 回答 1

1

JVMTI 选项听起来不错。最大的问题是确保您包装可能打开文件句柄的所有内容:您基本上必须通过 JDK 源代码并找到打开文件的每个本机函数(遍布 java.io. 、 java.nio.、我认为 java.net.* 以及如果您将套接字视为文件句柄,并且几乎在其他任何地方都可以通过本机函数打开文件句柄),然后使用SetNativeMethodPrefix调用将它们全部包装起来。

我假设这是一些分析人员所做的:但是,如果您不需要实时执行此列表,那么我认为它会更容易使用lsofhandle(在 Windows 平台上)并为您过滤JVM 的进程 ID。

于 2011-06-22T15:21:14.007 回答