I see that #638 got fancy new feature [1], which reminded me about another, related feature, I meant to ask before:
Will it be possible to freeze the JVM and capture memory snapshot automatically when JVM attempts to throw OutOfMemoryError?
Will it be possible to implement this feature for JDK1.4?
Thanks,
Vadim
[1] New feature: capture memory snapshots automatically, triggered by user preset memory threshold.
Automatic memory snapshot on OOME
-
- Posts: 6172
- Joined: Wed Aug 11, 2004 8:37 am
Unfortunately currently existing JVMs do not allow to correctly capture snapshots in such state.Will it be possible to freeze the JVM and capture memory snapshot automatically when JVM attempts to throw OutOfMemoryError?
Good news are that there will be a built-in support in Java 6.0 (Mustang) for heap dumping on OutOfMemoryError in some binary format. It possibly will be ported to Java 5.0 and even 1.4.2; if it happens, we'll try to support that format.
Please see my answer in http://forums.yourkit.com/viewtopic.php?p=1453#1453Will it be possible to implement this feature for JDK1.4?
-
- Posts: 26
- Joined: Mon Jan 24, 2005 7:29 pm
We can only hope...Anton Katilin wrote:Good news are that there will be a built-in support in Java 6.0 (Mustang) for heap dumping on OutOfMemoryError in some binary format. It possibly will be ported to Java 5.0 and even 1.4.2;
Thanks for the info.if it happens, we'll try to support that format.
Vadim
-
- Posts: 15
- Joined: Fri Feb 11, 2005 6:04 pm
I've implemented something similar in a system I develop: all worker threads catch VirtualMachineError (OOME is a VME), and when one is caught, they do
The problem is, often there's not enough memory to complete the capture. I tried preallocating a 1MB byte array that I free immediately before executing above statement:
I also provided a facility in other threads to check if snapshot is being taken, and wait() until it completes so that they don't snatch this freed up memory from the snapshot capturing thread. I also bump the priority of the capturing thread to MAX_PRIORITY.
Yet, I still often encounter a problem where the snapshot capture dies with OOME. Could you maybe provide some sort of "preallocation" that we could do on as early as system startup I.e. if I write new Controller().preallocate(), it'd make a best effort to preallocate all internal objects it needs (that'd BTW also load all the classes too)
BTW, present JREs can also dump a binary heap snapshot on exit using the hprof module shipped with JDK:
This is however tricky, as it is possible that your software has shutdown hooks that'll execute on JVM exit and "accidentally" cleanup the leak. Mine does, that's why I wrote code to take a snapshot between the time when OOME is detected and before System.exit() kicks in.
Code: Select all
public static void terminateVM(VirtualMachineError e)
{
...
new Controller().captureMemorySnapshot(null, false);
...
}
Code: Select all
private static volatile safetyBuffer = new byte[1024*1024];
...
public static void terminateVM(VirtualMachineError e)
{
...
safetyBuffer = null;
new Controller().captureMemorySnapshot(null, false);
...
}
Yet, I still often encounter a problem where the snapshot capture dies with OOME. Could you maybe provide some sort of "preallocation" that we could do on as early as system startup I.e. if I write new Controller().preallocate(), it'd make a best effort to preallocate all internal objects it needs (that'd BTW also load all the classes too)
BTW, present JREs can also dump a binary heap snapshot on exit using the hprof module shipped with JDK:
Code: Select all
java -Xrunhprof:heap=dump,format=b,file=heapdump.bin,doe=y
-
- Posts: 6172
- Joined: Wed Aug 11, 2004 8:37 am
Hi,
Unfortunately pre-allocation doesn't work, because OOME situation usually means that some actions cannot be successfully performed inside JVM as well as in our agent's code. We can reserve objects, but JVM, that does not do such reservation, will fail, and we cannot affect it of course.
HPROF approach has the same problems as well. It uses JVMTI API, as we do, and JVMTI calls may fail in low resource condition.
As I've said earlier in this thread, there will be a feature in Java 6.0 and possibly in 1.4/1.5, if ported, that dumps heap in HRPOF binary format when OOME happens. The key is that that feature doesn't use common API, instead it performs the dump internally, thus has very low overhead and manages to work in such tricky situations when there are no resources for general JVMTI approach.
Best regards,
Anton
Unfortunately pre-allocation doesn't work, because OOME situation usually means that some actions cannot be successfully performed inside JVM as well as in our agent's code. We can reserve objects, but JVM, that does not do such reservation, will fail, and we cannot affect it of course.
HPROF approach has the same problems as well. It uses JVMTI API, as we do, and JVMTI calls may fail in low resource condition.
As I've said earlier in this thread, there will be a feature in Java 6.0 and possibly in 1.4/1.5, if ported, that dumps heap in HRPOF binary format when OOME happens. The key is that that feature doesn't use common API, instead it performs the dump internally, thus has very low overhead and manages to work in such tricky situations when there are no resources for general JVMTI approach.
Best regards,
Anton
-
- Posts: 6172
- Joined: Wed Aug 11, 2004 8:37 am
-
- Posts: 26
- Joined: Mon Jan 24, 2005 7:29 pm
-
- Posts: 1626
- Joined: Tue Aug 10, 2004 7:52 pm