Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/gc/g1/g1BatchedGangTask.hpp
40961 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
#ifndef SHARE_GC_G1_G1BATCHEDGANGTASK_HPP
26
#define SHARE_GC_G1_G1BATCHEDGANGTASK_HPP
27
28
#include "gc/g1/g1GCPhaseTimes.hpp"
29
#include "gc/shared/workgroup.hpp"
30
#include "memory/allocation.hpp"
31
32
template <typename E, MEMFLAGS F>
33
class GrowableArrayCHeap;
34
35
// G1AbstractSubTask represents a task to be performed either within a
36
// G1BatchedGangTask running on a single worker ("serially") or multiple workers
37
// ("in parallel"). A G1AbstractSubTask is always associated with a phase tag
38
// that is used to automatically store timing information.
39
//
40
// A "serial" task is some piece of work that either can not be parallelized
41
// easily, or is typically so short that parallelization is not worth the effort.
42
// Current examples would be summarizing per worker thread information gathered
43
// during garbage collection (e.g. Merge PSS work).
44
//
45
// A "parallel" task could be some large amount of work that typically naturally
46
// splits across the heap in some way. Current examples would be clearing the
47
// card table.
48
//
49
// See G1BatchedGangTask for information on execution.
50
class G1AbstractSubTask : public CHeapObj<mtGC> {
51
G1GCPhaseTimes::GCParPhases _tag;
52
53
NONCOPYABLE(G1AbstractSubTask);
54
55
protected:
56
// Record work item for this tag in G1GCPhaseTimes.
57
void record_work_item(uint worker_id, uint index, size_t count);
58
59
public:
60
// Worker cost for "almost no work" to be done.
61
static constexpr double AlmostNoWork = 0.01;
62
63
G1AbstractSubTask(G1GCPhaseTimes::GCParPhases tag) : _tag(tag) { }
64
virtual ~G1AbstractSubTask() { }
65
66
// How many workers (threads) would this task be able to keep busy for at least
67
// as long as to amortize worker startup costs.
68
// Called by G1BatchedGangTask to determine total number of workers.
69
virtual double worker_cost() const = 0;
70
71
// Called by G1BatchedGangTask to provide information about the the maximum
72
// number of workers for all subtasks after it has been determined.
73
virtual void set_max_workers(uint max_workers) { }
74
75
// Perform the actual work. Gets the worker id it is run on passed in.
76
virtual void do_work(uint worker_id) = 0;
77
78
// Tag for this G1AbstractSubTask.
79
G1GCPhaseTimes::GCParPhases tag() const { return _tag; }
80
// Human readable name derived from the tag.
81
const char* name() const;
82
};
83
84
// G1BatchedGangTask runs a set of G1AbstractSubTask using a work gang.
85
//
86
// Subclasses of this class add their G1AbstractSubTasks into either the list
87
// of "serial" or the list of "parallel" tasks. They are supposed to be the owners
88
// of the G1AbstractSubTasks.
89
//
90
// Eg. the constructor contains code like the following:
91
//
92
// add_serial_task(new SomeSubTask());
93
// [...]
94
// add_parallel_task(new SomeOtherSubTask());
95
// [...]
96
//
97
// During execution in the work gang, this class will make sure that the "serial"
98
// tasks are executed by a single worker exactly once, but different "serial"
99
// tasks may be executed in parallel using different workers. "Parallel" tasks'
100
// do_work() method may be called by different workers passing a different
101
// worker_id at the same time, but at most once per given worker_id.
102
//
103
// There is also no guarantee that G1AbstractSubTasks::do_work() of different tasks
104
// are actually run in parallel.
105
//
106
// The current implementation assumes that constructors and destructors of the
107
// G1AbstractSubTasks can executed in the constructor/destructor of an instance
108
// of this class.
109
//
110
// The constructor, destructor and the do_work() methods from different
111
// G1AbstractSubTasks may run in any order so they must not have any
112
// dependencies at all.
113
//
114
// For a given G1AbstractSubTask T call order of its methods are as follows:
115
//
116
// 1) T()
117
// 2) T::thread_usage()
118
// 3) T::set_max_workers()
119
// 4) T::do_work() // potentially in parallel with any other registered G1AbstractSubTask
120
// 5) ~T()
121
//
122
class G1BatchedGangTask : public AbstractGangTask {
123
volatile int _num_serial_tasks_done;
124
G1GCPhaseTimes* _phase_times;
125
126
bool try_claim_serial_task(int& task);
127
128
NONCOPYABLE(G1BatchedGangTask);
129
130
GrowableArrayCHeap<G1AbstractSubTask*, mtGC> _serial_tasks;
131
GrowableArrayCHeap<G1AbstractSubTask*, mtGC> _parallel_tasks;
132
133
protected:
134
void add_serial_task(G1AbstractSubTask* task);
135
void add_parallel_task(G1AbstractSubTask* task);
136
137
G1BatchedGangTask(const char* name, G1GCPhaseTimes* phase_times);
138
139
public:
140
void work(uint worker_id) override;
141
142
// How many workers can this gang task keep busy and should be started for
143
// "optimal" performance.
144
uint num_workers_estimate() const;
145
// Informs the G1AbstractSubTasks about that we will start execution with the
146
// given number of workers.
147
void set_max_workers(uint max_workers);
148
149
~G1BatchedGangTask();
150
};
151
152
#endif // SHARE_GC_G1_G1BATCHEDGANGTASK_HPP
153