Path: blob/master/test/hotspot/gtest/gc/g1/test_stressCommitUncommit.cpp
41149 views
/*1* Copyright (c) 2020, 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*22*/2324#include "precompiled.hpp"25#include "gc/g1/g1BlockOffsetTable.hpp"26#include "gc/g1/g1RegionToSpaceMapper.hpp"27#include "memory/virtualspace.hpp"28#include "gc/shared/workgroup.hpp"29#include "runtime/atomic.hpp"30#include "runtime/os.hpp"31#include "unittest.hpp"3233class G1MapperWorkers : AllStatic {34static WorkGang* _work_gang;35static WorkGang* work_gang() {36if (_work_gang == NULL) {37_work_gang = new WorkGang("G1 Small Workers", MaxWorkers, false, false);38_work_gang->initialize_workers();39_work_gang->update_active_workers(MaxWorkers);40}41return _work_gang;42}4344public:45static const uint MaxWorkers = 4;46static void run_task(AbstractGangTask* task) {47work_gang()->run_task(task);48}49};50WorkGang* G1MapperWorkers::_work_gang = NULL;5152class G1TestCommitUncommit : public AbstractGangTask {53G1RegionToSpaceMapper* _mapper;54uint _claim_id;55public:56G1TestCommitUncommit(G1RegionToSpaceMapper* mapper) :57AbstractGangTask("Stress mapper"),58_mapper(mapper),59_claim_id(0) { }6061void work(uint worker_id) {62uint index = Atomic::fetch_and_add(&_claim_id, 1u);6364for (int i = 0; i < 100000; i++) {65// Stress commit and uncommit of a single region. The same66// will be done for multiple adjacent region to make sure67// we properly handle bitmap updates as well as updates for68// regions sharing the same underlying OS page.69_mapper->commit_regions(index);70_mapper->uncommit_regions(index);71}72}73};7475TEST_VM(G1RegionToSpaceMapper, smallStressAdjacent) {76// Fake a heap with 1m regions and create a BOT like mapper. This77// will give a G1RegionsSmallerThanCommitSizeMapper to stress.78uint num_regions = G1MapperWorkers::MaxWorkers;79size_t region_size = 1*M;80size_t size = G1BlockOffsetTable::compute_size(num_regions * region_size / HeapWordSize);81size_t page_size = os::vm_page_size();8283ReservedSpace rs(size, os::vm_page_size());8485G1RegionToSpaceMapper* small_mapper =86G1RegionToSpaceMapper::create_mapper(rs,87size,88page_size,89region_size,90G1BlockOffsetTable::heap_map_factor(),91mtGC);92939495G1TestCommitUncommit task(small_mapper);96G1MapperWorkers::run_task(&task);97}9899TEST_VM(G1RegionToSpaceMapper, largeStressAdjacent) {100// Fake a heap with 2m regions and create a BOT like mapper. This101// will give a G1RegionsLargerThanCommitSizeMapper to stress.102uint num_regions = G1MapperWorkers::MaxWorkers;103size_t region_size = 2*M;104size_t size = G1BlockOffsetTable::compute_size(num_regions * region_size / HeapWordSize);105size_t page_size = os::vm_page_size();106107ReservedSpace rs(size, page_size);108109G1RegionToSpaceMapper* large_mapper =110G1RegionToSpaceMapper::create_mapper(rs,111size,112page_size,113region_size,114G1BlockOffsetTable::heap_map_factor(),115mtGC);116117G1TestCommitUncommit task(large_mapper);118G1MapperWorkers::run_task(&task);119}120121