Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lsof counterpart for a JVM?

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.

like image 345
mindas Avatar asked Jun 22 '11 14:06

mindas


1 Answers

The JVMTI option sounds like it wouldn't be a bad choice. The big issue would be ensuring you wrap everything that may open a file handle: you would basically have to go through the JDK source code and find every native function that did a file open (littered throughout java.io., java.nio., I'd think java.net.* as well if you consider sockets as file handles, and just about everywhere else that a file handle may be opened by a native function) and then wrap them all with the SetNativeMethodPrefix call.

I'm assuming that is what some of the profiling folks do: however if you're not required to do this listing in real time then I'd think it would be WAY easier to use lsof or handle (on Windows platforms) and filter for your JVM's process id.

like image 78
Femi Avatar answered Sep 22 '22 16:09

Femi