diff -r 78e99b030d5f -r 19cd3b995de9 hotspot/src/os/windows/vm/os_windows.cpp --- a/hotspot/src/os/windows/vm/os_windows.cpp Fri Jun 24 15:09:00 2016 -0700 +++ b/hotspot/src/os/windows/vm/os_windows.cpp Sun Jun 26 20:00:45 2016 -0700 @@ -5250,6 +5250,12 @@ static int mallocDebugIntervalCounter = 0; static int mallocDebugCounter = 0; + +// For debugging possible bugs inside HeapWalk (a ring buffer) +#define SAVE_COUNT 8 +static PROCESS_HEAP_ENTRY saved_heap_entries[SAVE_COUNT]; +static int saved_heap_entry_index; + bool os::check_heap(bool force) { if (++mallocDebugCounter < MallocVerifyStart && !force) return true; if (++mallocDebugIntervalCounter >= MallocVerifyInterval || force) { @@ -5270,13 +5276,28 @@ if (HeapLock(heap) != 0) { PROCESS_HEAP_ENTRY phe; phe.lpData = NULL; + memset(saved_heap_entries, 0, sizeof(saved_heap_entries)); + saved_heap_entry_index = 0; + int count = 0; + while (HeapWalk(heap, &phe) != 0) { + count ++; if ((phe.wFlags & PROCESS_HEAP_ENTRY_BUSY) && !HeapValidate(heap, 0, phe.lpData)) { tty->print_cr("C heap has been corrupted (time: %d allocations)", mallocDebugCounter); - tty->print_cr("corrupted block near address %#x, length %d", phe.lpData, phe.cbData); + tty->print_cr("corrupted block near address %#x, length %d, count %d", phe.lpData, phe.cbData, count); HeapUnlock(heap); fatal("corrupted C heap"); + } else { + // Save previous seen entries in a ring buffer. We have seen strange + // heap corruption fatal errors that produced mdmp files, but when we load + // these mdmp files in WinDBG, "!heap -triage" shows no error. + // We can examine the saved_heap_entries[] array in the mdmp file to + // diagnose such seemingly spurious errors reported by HeapWalk. + saved_heap_entries[saved_heap_entry_index++] = phe; + if (saved_heap_entry_index >= SAVE_COUNT) { + saved_heap_entry_index = 0; + } } } DWORD err = GetLastError();