1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "utilities/macros.hpp" 27 #include "gc/g1/g1CollectedHeap.inline.hpp" 28 #include "unittest.hpp" 29 30 #if INCLUDE_ALL_GCS 31 32 TEST_OTHER_VM_WITH_FLAGS(g1, freeRegionList, (char*) "-XX:+UseG1GC") { 33 FreeRegionList l("test"); 34 const uint num_regions_in_test = 5; 35 36 // Create a fake heap. It does not need to be valid, as the HeapRegion constructor 37 // does not access it. 38 MemRegion heap(NULL, num_regions_in_test * HeapRegion::GrainWords); 39 40 // Allocate a fake BOT because the HeapRegion constructor initializes 41 // the BOT. 42 size_t bot_size = G1BlockOffsetTable::compute_size(heap.word_size()); 43 HeapWord* bot_data = NEW_C_HEAP_ARRAY(HeapWord, bot_size, mtGC); 44 ReservedSpace bot_rs(G1BlockOffsetTable::compute_size(heap.word_size())); 45 G1RegionToSpaceMapper* bot_storage = 46 G1RegionToSpaceMapper::create_mapper(bot_rs, 47 bot_rs.size(), 48 os::vm_page_size(), 49 HeapRegion::GrainBytes, 50 BOTConstants::N_bytes, 51 mtGC); 52 G1BlockOffsetTable bot(heap, bot_storage); 53 bot_storage->commit_regions(0, num_regions_in_test); 54 55 // Set up memory regions for the heap regions. 56 MemRegion mr0(heap.start(), HeapRegion::GrainWords); 57 MemRegion mr1(mr0.end(), HeapRegion::GrainWords); 58 MemRegion mr2(mr1.end(), HeapRegion::GrainWords); 59 MemRegion mr3(mr2.end(), HeapRegion::GrainWords); 60 MemRegion mr4(mr3.end(), HeapRegion::GrainWords); 61 62 HeapRegion hr0(0, &bot, mr0); 63 HeapRegion hr1(1, &bot, mr1); 64 HeapRegion hr2(2, &bot, mr2); 65 HeapRegion hr3(3, &bot, mr3); 66 HeapRegion hr4(4, &bot, mr4); 67 l.add_ordered(&hr1); 68 l.add_ordered(&hr0); 69 l.add_ordered(&hr3); 70 l.add_ordered(&hr4); 71 l.add_ordered(&hr2); 72 73 ASSERT_EQ(l.length(), num_regions_in_test) << "Wrong free region list length"; 74 l.verify_list(); 75 76 bot_storage->uncommit_regions(0, num_regions_in_test); 77 delete bot_storage; 78 FREE_C_HEAP_ARRAY(HeapWord, bot_data); 79 } 80 #endif