# HG changeset patch # User tschatzl # Date 1369128614 -7200 # Node ID 17992863b0ab2e07078dc2cb27caf372f5314a89 # Parent 10a659a730ea34b1b1da467bf322949ec8a711ea 8014405: G1: PerRegionTable::fl_mem_size() calculates size of the free list using wrong element sizes Summary: Instead of using a simple sizeof(), ask the PerRegionTable class about its size when iterating over the free list. Reviewed-by: jwilhelm, brutisso diff -r 10a659a730ea -r 17992863b0ab hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp Tue May 21 10:39:09 2013 +0200 +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp Tue May 21 11:30:14 2013 +0200 @@ -242,11 +242,13 @@ PerRegionTable* cur = _free_list; size_t res = 0; while (cur != NULL) { - res += sizeof(PerRegionTable); + res += cur->mem_size(); cur = cur->next(); } return res; } + + static void test_fl_mem_size(); }; PerRegionTable* PerRegionTable::_free_list = NULL; @@ -1149,6 +1151,19 @@ } #ifndef PRODUCT +void PerRegionTable::test_fl_mem_size() { + PerRegionTable* dummy = alloc(NULL); + free(dummy); + guarantee(dummy->mem_size() == fl_mem_size(), "fl_mem_size() does not return the correct element size"); + // try to reset the state + _free_list = NULL; + delete dummy; +} + +void HeapRegionRemSet::test_prt() { + PerRegionTable::test_fl_mem_size(); +} + void HeapRegionRemSet::test() { os::sleep(Thread::current(), (jlong)5000, false); G1CollectedHeap* g1h = G1CollectedHeap::heap(); diff -r 10a659a730ea -r 17992863b0ab hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.hpp --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.hpp Tue May 21 10:39:09 2013 +0200 +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.hpp Tue May 21 11:30:14 2013 +0200 @@ -338,6 +338,7 @@ // Run unit tests. #ifndef PRODUCT + static void test_prt(); static void test(); #endif }; diff -r 10a659a730ea -r 17992863b0ab hotspot/src/share/vm/prims/jni.cpp --- a/hotspot/src/share/vm/prims/jni.cpp Tue May 21 10:39:09 2013 +0200 +++ b/hotspot/src/share/vm/prims/jni.cpp Tue May 21 11:30:14 2013 +0200 @@ -5015,6 +5015,9 @@ #ifndef PRODUCT #include "gc_interface/collectedHeap.hpp" +#if INCLUDE_ALL_GCS +#include "gc_implementation/g1/heapRegionRemSet.hpp" +#endif #include "utilities/quickSort.hpp" #if INCLUDE_VM_STRUCTS #include "runtime/vmStructs.hpp" @@ -5035,6 +5038,9 @@ #if INCLUDE_VM_STRUCTS run_unit_test(VMStructs::test()); #endif +#if INCLUDE_ALL_GCS + run_unit_test(HeapRegionRemSet::test_prt()); +#endif tty->print_cr("All internal VM tests passed"); } }