Path: blob/master/test/hotspot/gtest/gc/g1/test_freeRegionList.cpp
41149 views
/*1* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "gc/g1/g1CollectedHeap.inline.hpp"25#include "unittest.hpp"2627// @requires UseG1GC28TEST_VM(FreeRegionList, length) {29if (!UseG1GC) {30return;31}3233FreeRegionList l("test");34const uint num_regions_in_test = 5;3536// Create a fake heap. It does not need to be valid, as the HeapRegion constructor37// does not access it.38MemRegion heap(NULL, num_regions_in_test * HeapRegion::GrainWords);3940// Allocate a fake BOT because the HeapRegion constructor initializes41// the BOT.42size_t bot_size = G1BlockOffsetTable::compute_size(heap.word_size());43HeapWord* bot_data = NEW_C_HEAP_ARRAY(HeapWord, bot_size, mtGC);44ReservedSpace bot_rs(G1BlockOffsetTable::compute_size(heap.word_size()));45G1RegionToSpaceMapper* bot_storage =46G1RegionToSpaceMapper::create_mapper(bot_rs,47bot_rs.size(),48os::vm_page_size(),49HeapRegion::GrainBytes,50BOTConstants::N_bytes,51mtGC);52G1BlockOffsetTable bot(heap, bot_storage);53bot_storage->commit_regions(0, num_regions_in_test);5455// Set up memory regions for the heap regions.56MemRegion mr0(heap.start(), HeapRegion::GrainWords);57MemRegion mr1(mr0.end(), HeapRegion::GrainWords);58MemRegion mr2(mr1.end(), HeapRegion::GrainWords);59MemRegion mr3(mr2.end(), HeapRegion::GrainWords);60MemRegion mr4(mr3.end(), HeapRegion::GrainWords);6162HeapRegion hr0(0, &bot, mr0);63HeapRegion hr1(1, &bot, mr1);64HeapRegion hr2(2, &bot, mr2);65HeapRegion hr3(3, &bot, mr3);66HeapRegion hr4(4, &bot, mr4);67l.add_ordered(&hr1);68l.add_ordered(&hr0);69l.add_ordered(&hr3);70l.add_ordered(&hr4);71l.add_ordered(&hr2);7273EXPECT_EQ(l.length(), num_regions_in_test) << "Wrong free region list length";74l.verify_list();7576bot_storage->uncommit_regions(0, num_regions_in_test);77delete bot_storage;78FREE_C_HEAP_ARRAY(HeapWord, bot_data);79}808182