Path: blob/master/test/hotspot/gtest/gc/shared/test_partialArrayTaskStepper.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/shared/partialArrayTaskStepper.inline.hpp"26#include "memory/allStatic.hpp"27#include "unittest.hpp"2829using Step = PartialArrayTaskStepper::Step;30using Stepper = PartialArrayTaskStepper;3132class PartialArrayTaskStepper::TestSupport : AllStatic {33public:34static Step start(const Stepper* stepper,35int length,36int* to_length_addr,37uint chunk_size) {38return stepper->start_impl(length, to_length_addr, chunk_size);39}4041static Step next(const Stepper* stepper,42int length,43int* to_length_addr,44uint chunk_size) {45return stepper->next_impl(length, to_length_addr, chunk_size);46}47};4849using StepperSupport = PartialArrayTaskStepper::TestSupport;5051static int simulate(const Stepper* stepper,52int length,53int* to_length_addr,54uint chunk_size) {55Step init = StepperSupport::start(stepper, length, to_length_addr, chunk_size);56uint queue_count = init._ncreate;57int task = 0;58for ( ; queue_count > 0; ++task) {59--queue_count;60Step step = StepperSupport::next(stepper, length, to_length_addr, chunk_size);61queue_count += step._ncreate;62}63return task;64}6566static void run_test(int length, int chunk_size, uint n_workers) {67const PartialArrayTaskStepper stepper(n_workers);68int to_length;69int tasks = simulate(&stepper, length, &to_length, chunk_size);70ASSERT_EQ(length, to_length);71ASSERT_EQ(tasks, length / chunk_size);72}7374TEST(PartialArrayTaskStepperTest, doit) {75for (int chunk_size = 50; chunk_size <= 500; chunk_size += 50) {76for (uint n_workers = 1; n_workers <= 256; n_workers = (n_workers * 3 / 2 + 1)) {77for (int length = 0; length <= 1000000; length = (length * 2 + 1)) {78run_test(length, chunk_size, n_workers);79}80// Ensure we hit boundary cases for length % chunk_size == 0.81for (uint i = 0; i < 2 * n_workers; ++i) {82run_test(i * chunk_size, chunk_size, n_workers);83}84}85}86}878889