1 /*
2 * Copyright (c) 2005, 2019, 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 *
35 #include "memory/iterator.inline.hpp"
36 #include "oops/access.inline.hpp"
37 #include "oops/compressedOops.inline.hpp"
38 #include "oops/instanceKlass.inline.hpp"
39 #include "oops/instanceMirrorKlass.inline.hpp"
40 #include "oops/objArrayKlass.inline.hpp"
41 #include "oops/oop.inline.hpp"
42
43 PSOldGen* ParCompactionManager::_old_gen = NULL;
44 ParCompactionManager** ParCompactionManager::_manager_array = NULL;
45
46 OopTaskQueueSet* ParCompactionManager::_stack_array = NULL;
47 ParCompactionManager::ObjArrayTaskQueueSet*
48 ParCompactionManager::_objarray_queues = NULL;
49 ObjectStartArray* ParCompactionManager::_start_array = NULL;
50 ParMarkBitMap* ParCompactionManager::_mark_bitmap = NULL;
51 RegionTaskQueueSet* ParCompactionManager::_region_array = NULL;
52 GrowableArray<size_t >* ParCompactionManager::_shadow_region_array = NULL;
53 Monitor* ParCompactionManager::_shadow_region_monitor = NULL;
54
55 ParCompactionManager::ParCompactionManager() :
56 _action(CopyAndUpdate) {
57
58 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
59
60 _old_gen = heap->old_gen();
61 _start_array = old_gen()->start_array();
62
63 marking_stack()->initialize();
64 _objarray_stack.initialize();
65 _region_stack.initialize();
66
67 reset_bitmap_query_cache();
68 }
69
70 void ParCompactionManager::initialize(ParMarkBitMap* mbm) {
71 assert(ParallelScavengeHeap::heap() != NULL,
72 "Needed for initialization");
73
74 _mark_bitmap = mbm;
75
76 uint parallel_gc_threads = ParallelScavengeHeap::heap()->workers().total_workers();
98 // for work stealing.
99 _manager_array[parallel_gc_threads] = new ParCompactionManager();
100 guarantee(_manager_array[parallel_gc_threads] != NULL,
101 "Could not create ParCompactionManager");
102 assert(ParallelScavengeHeap::heap()->workers().total_workers() != 0,
103 "Not initialized?");
104
105 _shadow_region_array = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<size_t >(10, true);
106
107 _shadow_region_monitor = new Monitor(Mutex::barrier, "CompactionManager monitor",
108 Mutex::_allow_vm_block_flag, Monitor::_safepoint_check_never);
109 }
110
111 void ParCompactionManager::reset_all_bitmap_query_caches() {
112 uint parallel_gc_threads = ParallelScavengeHeap::heap()->workers().total_workers();
113 for (uint i=0; i<=parallel_gc_threads; i++) {
114 _manager_array[i]->reset_bitmap_query_cache();
115 }
116 }
117
118 bool ParCompactionManager::should_update() {
119 assert(action() != NotValid, "Action is not set");
120 return (action() == ParCompactionManager::Update) ||
121 (action() == ParCompactionManager::CopyAndUpdate) ||
122 (action() == ParCompactionManager::UpdateAndCopy);
123 }
124
125 bool ParCompactionManager::should_copy() {
126 assert(action() != NotValid, "Action is not set");
127 return (action() == ParCompactionManager::Copy) ||
128 (action() == ParCompactionManager::CopyAndUpdate) ||
129 (action() == ParCompactionManager::UpdateAndCopy);
130 }
131
132 ParCompactionManager*
133 ParCompactionManager::gc_thread_compaction_manager(uint index) {
134 assert(index < ParallelGCThreads, "index out of range");
135 assert(_manager_array != NULL, "Sanity");
136 return _manager_array[index];
137 }
138
139 void ParCompactionManager::follow_marking_stacks() {
140 do {
141 // Drain the overflow stack first, to allow stealing from the marking stack.
142 oop obj;
143 while (marking_stack()->pop_overflow(obj)) {
144 follow_contents(obj);
145 }
146 while (marking_stack()->pop_local(obj)) {
147 follow_contents(obj);
148 }
149
150 // Process ObjArrays one at a time to avoid marking stack bloat.
182 // we return InvalidShadow to indicate such a case.
183 if (region_ptr->claimed()) {
184 return InvalidShadow;
185 }
186 ml.wait(1);
187 }
188 }
189
190 void ParCompactionManager::push_shadow_region_mt_safe(size_t shadow_region) {
191 MonitorLocker ml(_shadow_region_monitor, Mutex::_no_safepoint_check_flag);
192 _shadow_region_array->push(shadow_region);
193 ml.notify();
194 }
195
196 void ParCompactionManager::push_shadow_region(size_t shadow_region) {
197 _shadow_region_array->push(shadow_region);
198 }
199
200 void ParCompactionManager::remove_all_shadow_regions() {
201 _shadow_region_array->clear();
202 }
|
1 /*
2 * Copyright (c) 2005, 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 *
35 #include "memory/iterator.inline.hpp"
36 #include "oops/access.inline.hpp"
37 #include "oops/compressedOops.inline.hpp"
38 #include "oops/instanceKlass.inline.hpp"
39 #include "oops/instanceMirrorKlass.inline.hpp"
40 #include "oops/objArrayKlass.inline.hpp"
41 #include "oops/oop.inline.hpp"
42
43 PSOldGen* ParCompactionManager::_old_gen = NULL;
44 ParCompactionManager** ParCompactionManager::_manager_array = NULL;
45
46 OopTaskQueueSet* ParCompactionManager::_stack_array = NULL;
47 ParCompactionManager::ObjArrayTaskQueueSet*
48 ParCompactionManager::_objarray_queues = NULL;
49 ObjectStartArray* ParCompactionManager::_start_array = NULL;
50 ParMarkBitMap* ParCompactionManager::_mark_bitmap = NULL;
51 RegionTaskQueueSet* ParCompactionManager::_region_array = NULL;
52 GrowableArray<size_t >* ParCompactionManager::_shadow_region_array = NULL;
53 Monitor* ParCompactionManager::_shadow_region_monitor = NULL;
54
55 ParCompactionManager::ParCompactionManager() {
56
57 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
58
59 _old_gen = heap->old_gen();
60 _start_array = old_gen()->start_array();
61
62 marking_stack()->initialize();
63 _objarray_stack.initialize();
64 _region_stack.initialize();
65
66 reset_bitmap_query_cache();
67 }
68
69 void ParCompactionManager::initialize(ParMarkBitMap* mbm) {
70 assert(ParallelScavengeHeap::heap() != NULL,
71 "Needed for initialization");
72
73 _mark_bitmap = mbm;
74
75 uint parallel_gc_threads = ParallelScavengeHeap::heap()->workers().total_workers();
97 // for work stealing.
98 _manager_array[parallel_gc_threads] = new ParCompactionManager();
99 guarantee(_manager_array[parallel_gc_threads] != NULL,
100 "Could not create ParCompactionManager");
101 assert(ParallelScavengeHeap::heap()->workers().total_workers() != 0,
102 "Not initialized?");
103
104 _shadow_region_array = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<size_t >(10, true);
105
106 _shadow_region_monitor = new Monitor(Mutex::barrier, "CompactionManager monitor",
107 Mutex::_allow_vm_block_flag, Monitor::_safepoint_check_never);
108 }
109
110 void ParCompactionManager::reset_all_bitmap_query_caches() {
111 uint parallel_gc_threads = ParallelScavengeHeap::heap()->workers().total_workers();
112 for (uint i=0; i<=parallel_gc_threads; i++) {
113 _manager_array[i]->reset_bitmap_query_cache();
114 }
115 }
116
117
118 ParCompactionManager*
119 ParCompactionManager::gc_thread_compaction_manager(uint index) {
120 assert(index < ParallelGCThreads, "index out of range");
121 assert(_manager_array != NULL, "Sanity");
122 return _manager_array[index];
123 }
124
125 void ParCompactionManager::follow_marking_stacks() {
126 do {
127 // Drain the overflow stack first, to allow stealing from the marking stack.
128 oop obj;
129 while (marking_stack()->pop_overflow(obj)) {
130 follow_contents(obj);
131 }
132 while (marking_stack()->pop_local(obj)) {
133 follow_contents(obj);
134 }
135
136 // Process ObjArrays one at a time to avoid marking stack bloat.
168 // we return InvalidShadow to indicate such a case.
169 if (region_ptr->claimed()) {
170 return InvalidShadow;
171 }
172 ml.wait(1);
173 }
174 }
175
176 void ParCompactionManager::push_shadow_region_mt_safe(size_t shadow_region) {
177 MonitorLocker ml(_shadow_region_monitor, Mutex::_no_safepoint_check_flag);
178 _shadow_region_array->push(shadow_region);
179 ml.notify();
180 }
181
182 void ParCompactionManager::push_shadow_region(size_t shadow_region) {
183 _shadow_region_array->push(shadow_region);
184 }
185
186 void ParCompactionManager::remove_all_shadow_regions() {
187 _shadow_region_array->clear();
188 }
|