Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/gc/g1/g1BatchedGangTask.cpp
40957 views
1
/*
2
* Copyright (c) 2021, 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
27
#include "gc/g1/g1BatchedGangTask.hpp"
28
#include "gc/g1/g1CollectedHeap.inline.hpp"
29
#include "gc/g1/g1GCParPhaseTimesTracker.hpp"
30
#include "runtime/atomic.hpp"
31
#include "utilities/growableArray.hpp"
32
33
void G1AbstractSubTask::record_work_item(uint worker_id, uint index, size_t count) {
34
G1CollectedHeap* g1h = G1CollectedHeap::heap();
35
g1h->phase_times()->record_thread_work_item(_tag, worker_id, count, index);
36
}
37
38
const char* G1AbstractSubTask::name() const {
39
G1CollectedHeap* g1h = G1CollectedHeap::heap();
40
return g1h->phase_times()->phase_name(_tag);
41
}
42
43
bool G1BatchedGangTask::try_claim_serial_task(int& task) {
44
task = Atomic::fetch_and_add(&_num_serial_tasks_done, 1);
45
return task < _serial_tasks.length();
46
}
47
48
void G1BatchedGangTask::add_serial_task(G1AbstractSubTask* task) {
49
assert(task != nullptr, "must be");
50
_serial_tasks.push(task);
51
}
52
53
void G1BatchedGangTask::add_parallel_task(G1AbstractSubTask* task) {
54
assert(task != nullptr, "must be");
55
_parallel_tasks.push(task);
56
}
57
58
G1BatchedGangTask::G1BatchedGangTask(const char* name, G1GCPhaseTimes* phase_times) :
59
AbstractGangTask(name),
60
_num_serial_tasks_done(0),
61
_phase_times(phase_times),
62
_serial_tasks(),
63
_parallel_tasks() {
64
}
65
66
uint G1BatchedGangTask::num_workers_estimate() const {
67
double sum = 0.0;
68
for (G1AbstractSubTask* task : _serial_tasks) {
69
sum += task->worker_cost();
70
}
71
for (G1AbstractSubTask* task : _parallel_tasks) {
72
sum += task->worker_cost();
73
}
74
return ceil(sum);
75
}
76
77
void G1BatchedGangTask::set_max_workers(uint max_workers) {
78
for (G1AbstractSubTask* task : _serial_tasks) {
79
task->set_max_workers(max_workers);
80
}
81
for (G1AbstractSubTask* task : _parallel_tasks) {
82
task->set_max_workers(max_workers);
83
}
84
}
85
86
void G1BatchedGangTask::work(uint worker_id) {
87
int t = 0;
88
while (try_claim_serial_task(t)) {
89
G1AbstractSubTask* task = _serial_tasks.at(t);
90
G1GCParPhaseTimesTracker x(_phase_times, task->tag(), worker_id);
91
task->do_work(worker_id);
92
}
93
for (G1AbstractSubTask* task : _parallel_tasks) {
94
G1GCParPhaseTimesTracker x(_phase_times, task->tag(), worker_id);
95
task->do_work(worker_id);
96
}
97
}
98
99
G1BatchedGangTask::~G1BatchedGangTask() {
100
assert(Atomic::load(&_num_serial_tasks_done) >= _serial_tasks.length(),
101
"Only %d tasks of %d claimed", Atomic::load(&_num_serial_tasks_done), _serial_tasks.length());
102
103
for (G1AbstractSubTask* task : _parallel_tasks) {
104
delete task;
105
}
106
for (G1AbstractSubTask* task : _serial_tasks) {
107
delete task;
108
}
109
}
110
111