1.1 --- a/src/share/vm/gc_implementation/g1/heapRegionSet.cpp Tue Aug 19 10:50:27 2014 +0200 1.2 +++ b/src/share/vm/gc_implementation/g1/heapRegionSet.cpp Thu Aug 21 11:47:10 2014 +0200 1.3 @@ -403,3 +403,41 @@ 1.4 "master humongous set MT safety protocol outside a safepoint"); 1.5 } 1.6 } 1.7 + 1.8 +void FreeRegionList_test() { 1.9 + FreeRegionList l("test"); 1.10 + 1.11 + const uint num_regions_in_test = 5; 1.12 + // Create a fake heap. It does not need to be valid, as the HeapRegion constructor 1.13 + // does not access it. 1.14 + MemRegion heap(NULL, num_regions_in_test * HeapRegion::GrainWords); 1.15 + // Allocate a fake BOT because the HeapRegion constructor initializes 1.16 + // the BOT. 1.17 + size_t bot_size = G1BlockOffsetSharedArray::compute_size(heap.word_size()); 1.18 + HeapWord* bot_data = NEW_C_HEAP_ARRAY(HeapWord, bot_size, mtGC); 1.19 + ReservedSpace bot_rs(G1BlockOffsetSharedArray::compute_size(heap.word_size())); 1.20 + G1RegionToSpaceMapper* bot_storage = 1.21 + G1RegionToSpaceMapper::create_mapper(bot_rs, 1.22 + os::vm_page_size(), 1.23 + HeapRegion::GrainBytes, 1.24 + G1BlockOffsetSharedArray::N_bytes, 1.25 + mtGC); 1.26 + G1BlockOffsetSharedArray oa(heap, bot_storage); 1.27 + bot_storage->commit_regions(0, num_regions_in_test); 1.28 + HeapRegion hr0(0, &oa, heap); 1.29 + HeapRegion hr1(1, &oa, heap); 1.30 + HeapRegion hr2(2, &oa, heap); 1.31 + HeapRegion hr3(3, &oa, heap); 1.32 + HeapRegion hr4(4, &oa, heap); 1.33 + l.add_ordered(&hr1); 1.34 + l.add_ordered(&hr0); 1.35 + l.add_ordered(&hr3); 1.36 + l.add_ordered(&hr4); 1.37 + l.add_ordered(&hr2); 1.38 + assert(l.length() == num_regions_in_test, "wrong length"); 1.39 + l.verify_list(); 1.40 + 1.41 + bot_storage->uncommit_regions(0, num_regions_in_test); 1.42 + delete bot_storage; 1.43 + FREE_C_HEAP_ARRAY(HeapWord, bot_data, mtGC); 1.44 +}