Lsof for JVM?

lsof is a good Unix tool showing all currently open files.

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

In this particular case, it would be enough for me to know which class is open. A method / line or even a whole chain for GC root would be fantastic, but the handler owner class has already become a good start.

I know that I can create a bunch of heaps, open it in the profiler and find it, but this is a tedious task, especially for large heaps.

+6
source share
1 answer

The JVMTI option sounds like it would not be a bad choice. The big problem would be for you to wrap everything that could open the file descriptor: you would basically have to use the JDK source code and find each function of its own that opens the file (trashy through java.io., java.nio., I I would think that java.net. * And if you consider sockets as files, and almost everywhere where a file descriptor can be opened with your own function), and then wrap them all with SetNativeMethodPrefix .

I assume that some of the profiling people do this: however, if you are not required to do this enumeration in real time, I think it would be easier to use lsof or handle (on Windows platforms) and a filter for your JVM process id.

+1
source

Source: https://habr.com/ru/post/891123/


All Articles