Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/gc/g1/g1BarrierSet.cpp
40957 views
1
/*
2
* Copyright (c) 2001, 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
#include "gc/g1/g1BarrierSet.inline.hpp"
27
#include "gc/g1/g1BarrierSetAssembler.hpp"
28
#include "gc/g1/g1CardTable.inline.hpp"
29
#include "gc/g1/g1CollectedHeap.inline.hpp"
30
#include "gc/g1/g1SATBMarkQueueSet.hpp"
31
#include "gc/g1/g1ThreadLocalData.hpp"
32
#include "gc/g1/heapRegion.hpp"
33
#include "gc/shared/satbMarkQueue.hpp"
34
#include "logging/log.hpp"
35
#include "oops/access.inline.hpp"
36
#include "oops/compressedOops.inline.hpp"
37
#include "oops/oop.inline.hpp"
38
#include "runtime/interfaceSupport.inline.hpp"
39
#include "runtime/orderAccess.hpp"
40
#include "runtime/thread.inline.hpp"
41
#include "utilities/macros.hpp"
42
#ifdef COMPILER1
43
#include "gc/g1/c1/g1BarrierSetC1.hpp"
44
#endif
45
#ifdef COMPILER2
46
#include "gc/g1/c2/g1BarrierSetC2.hpp"
47
#endif
48
49
class G1BarrierSetC1;
50
class G1BarrierSetC2;
51
52
G1BarrierSet::G1BarrierSet(G1CardTable* card_table) :
53
CardTableBarrierSet(make_barrier_set_assembler<G1BarrierSetAssembler>(),
54
make_barrier_set_c1<G1BarrierSetC1>(),
55
make_barrier_set_c2<G1BarrierSetC2>(),
56
card_table,
57
BarrierSet::FakeRtti(BarrierSet::G1BarrierSet)),
58
_satb_mark_queue_buffer_allocator("SATB Buffer Allocator", G1SATBBufferSize),
59
_dirty_card_queue_buffer_allocator("DC Buffer Allocator", G1UpdateBufferSize),
60
_satb_mark_queue_set(&_satb_mark_queue_buffer_allocator),
61
_dirty_card_queue_set(&_dirty_card_queue_buffer_allocator),
62
_shared_dirty_card_queue(&_dirty_card_queue_set)
63
{}
64
65
void G1BarrierSet::enqueue(oop pre_val) {
66
// Nulls should have been already filtered.
67
assert(oopDesc::is_oop(pre_val, true), "Error");
68
SATBMarkQueue& queue = G1ThreadLocalData::satb_mark_queue(Thread::current());
69
G1BarrierSet::satb_mark_queue_set().enqueue(queue, pre_val);
70
}
71
72
template <class T> void
73
G1BarrierSet::write_ref_array_pre_work(T* dst, size_t count) {
74
if (!_satb_mark_queue_set.is_active()) return;
75
T* elem_ptr = dst;
76
for (size_t i = 0; i < count; i++, elem_ptr++) {
77
T heap_oop = RawAccess<>::oop_load(elem_ptr);
78
if (!CompressedOops::is_null(heap_oop)) {
79
enqueue(CompressedOops::decode_not_null(heap_oop));
80
}
81
}
82
}
83
84
void G1BarrierSet::write_ref_array_pre(oop* dst, size_t count, bool dest_uninitialized) {
85
if (!dest_uninitialized) {
86
write_ref_array_pre_work(dst, count);
87
}
88
}
89
90
void G1BarrierSet::write_ref_array_pre(narrowOop* dst, size_t count, bool dest_uninitialized) {
91
if (!dest_uninitialized) {
92
write_ref_array_pre_work(dst, count);
93
}
94
}
95
96
void G1BarrierSet::write_ref_field_post_slow(volatile CardValue* byte) {
97
// In the slow path, we know a card is not young
98
assert(*byte != G1CardTable::g1_young_card_val(), "slow path invoked without filtering");
99
OrderAccess::storeload();
100
if (*byte != G1CardTable::dirty_card_val()) {
101
*byte = G1CardTable::dirty_card_val();
102
Thread* thr = Thread::current();
103
G1DirtyCardQueue& queue = G1ThreadLocalData::dirty_card_queue(thr);
104
G1BarrierSet::dirty_card_queue_set().enqueue(queue, byte);
105
}
106
}
107
108
void G1BarrierSet::invalidate(MemRegion mr) {
109
if (mr.is_empty()) {
110
return;
111
}
112
volatile CardValue* byte = _card_table->byte_for(mr.start());
113
CardValue* last_byte = _card_table->byte_for(mr.last());
114
// skip initial young cards
115
for (; byte <= last_byte && *byte == G1CardTable::g1_young_card_val(); byte++);
116
117
if (byte <= last_byte) {
118
OrderAccess::storeload();
119
// Enqueue if necessary.
120
Thread* thr = Thread::current();
121
G1DirtyCardQueueSet& qset = G1BarrierSet::dirty_card_queue_set();
122
G1DirtyCardQueue& queue = G1ThreadLocalData::dirty_card_queue(thr);
123
for (; byte <= last_byte; byte++) {
124
CardValue bv = *byte;
125
if ((bv != G1CardTable::g1_young_card_val()) &&
126
(bv != G1CardTable::dirty_card_val())) {
127
*byte = G1CardTable::dirty_card_val();
128
qset.enqueue(queue, byte);
129
}
130
}
131
}
132
}
133
134
void G1BarrierSet::on_thread_create(Thread* thread) {
135
// Create thread local data
136
G1ThreadLocalData::create(thread);
137
}
138
139
void G1BarrierSet::on_thread_destroy(Thread* thread) {
140
// Destroy thread local data
141
G1ThreadLocalData::destroy(thread);
142
}
143
144
void G1BarrierSet::on_thread_attach(Thread* thread) {
145
SATBMarkQueue& queue = G1ThreadLocalData::satb_mark_queue(thread);
146
assert(!queue.is_active(), "SATB queue should not be active");
147
assert(queue.buffer() == nullptr, "SATB queue should not have a buffer");
148
assert(queue.index() == 0, "SATB queue index should be zero");
149
// Can't assert that the DCQ is empty. There is early execution on
150
// the main thread, before it gets added to the threads list, which
151
// is where this is called. That execution may enqueue dirty cards.
152
153
// If we are creating the thread during a marking cycle, we should
154
// set the active field of the SATB queue to true. That involves
155
// copying the global is_active value to this thread's queue.
156
queue.set_active(_satb_mark_queue_set.is_active());
157
}
158
159
void G1BarrierSet::on_thread_detach(Thread* thread) {
160
// Flush any deferred card marks.
161
CardTableBarrierSet::on_thread_detach(thread);
162
{
163
SATBMarkQueue& queue = G1ThreadLocalData::satb_mark_queue(thread);
164
G1BarrierSet::satb_mark_queue_set().flush_queue(queue);
165
}
166
{
167
G1DirtyCardQueue& queue = G1ThreadLocalData::dirty_card_queue(thread);
168
G1DirtyCardQueueSet& qset = G1BarrierSet::dirty_card_queue_set();
169
qset.flush_queue(queue);
170
qset.record_detached_refinement_stats(queue.refinement_stats());
171
}
172
}
173
174