Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/gtest/gc/shared/test_partialArrayTaskStepper.cpp
41149 views
1
/*
2
* Copyright (c) 2020, 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 "gc/shared/partialArrayTaskStepper.inline.hpp"
27
#include "memory/allStatic.hpp"
28
#include "unittest.hpp"
29
30
using Step = PartialArrayTaskStepper::Step;
31
using Stepper = PartialArrayTaskStepper;
32
33
class PartialArrayTaskStepper::TestSupport : AllStatic {
34
public:
35
static Step start(const Stepper* stepper,
36
int length,
37
int* to_length_addr,
38
uint chunk_size) {
39
return stepper->start_impl(length, to_length_addr, chunk_size);
40
}
41
42
static Step next(const Stepper* stepper,
43
int length,
44
int* to_length_addr,
45
uint chunk_size) {
46
return stepper->next_impl(length, to_length_addr, chunk_size);
47
}
48
};
49
50
using StepperSupport = PartialArrayTaskStepper::TestSupport;
51
52
static int simulate(const Stepper* stepper,
53
int length,
54
int* to_length_addr,
55
uint chunk_size) {
56
Step init = StepperSupport::start(stepper, length, to_length_addr, chunk_size);
57
uint queue_count = init._ncreate;
58
int task = 0;
59
for ( ; queue_count > 0; ++task) {
60
--queue_count;
61
Step step = StepperSupport::next(stepper, length, to_length_addr, chunk_size);
62
queue_count += step._ncreate;
63
}
64
return task;
65
}
66
67
static void run_test(int length, int chunk_size, uint n_workers) {
68
const PartialArrayTaskStepper stepper(n_workers);
69
int to_length;
70
int tasks = simulate(&stepper, length, &to_length, chunk_size);
71
ASSERT_EQ(length, to_length);
72
ASSERT_EQ(tasks, length / chunk_size);
73
}
74
75
TEST(PartialArrayTaskStepperTest, doit) {
76
for (int chunk_size = 50; chunk_size <= 500; chunk_size += 50) {
77
for (uint n_workers = 1; n_workers <= 256; n_workers = (n_workers * 3 / 2 + 1)) {
78
for (int length = 0; length <= 1000000; length = (length * 2 + 1)) {
79
run_test(length, chunk_size, n_workers);
80
}
81
// Ensure we hit boundary cases for length % chunk_size == 0.
82
for (uint i = 0; i < 2 * n_workers; ++i) {
83
run_test(i * chunk_size, chunk_size, n_workers);
84
}
85
}
86
}
87
}
88
89