Tue, 20 Jun 2017 14:59:09 +0800
Rewrite low level concurrency primitives for MIPS.
1 /*
2 * Copyright (c) 2002, 2014, 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 */
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP
26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP
28 #include "gc_implementation/parallelScavenge/psOldGen.hpp"
29 #include "gc_implementation/parallelScavenge/psPromotionManager.hpp"
30 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
31 #include "oops/oop.psgc.inline.hpp"
33 inline PSPromotionManager* PSPromotionManager::manager_array(int index) {
34 assert(_manager_array != NULL, "access of NULL manager_array");
35 assert(index >= 0 && index <= (int)ParallelGCThreads, "out of range manager_array access");
36 return &_manager_array[index];
37 }
39 template <class T>
40 inline void PSPromotionManager::claim_or_forward_internal_depth(T* p) {
41 if (p != NULL) { // XXX: error if p != NULL here
42 oop o = oopDesc::load_decode_heap_oop_not_null(p);
43 if (o->is_forwarded()) {
44 o = o->forwardee();
45 // Card mark
46 if (PSScavenge::is_obj_in_young(o)) {
47 PSScavenge::card_table()->inline_write_ref_field_gc(p, o);
48 }
49 oopDesc::encode_store_heap_oop_not_null(p, o);
50 } else {
51 push_depth(p);
52 }
53 }
54 }
56 template <class T>
57 inline void PSPromotionManager::claim_or_forward_depth(T* p) {
58 assert(PSScavenge::should_scavenge(p, true), "revisiting object?");
59 assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap,
60 "Sanity");
61 assert(Universe::heap()->is_in(p), "pointer outside heap");
63 claim_or_forward_internal_depth(p);
64 }
66 //
67 // This method is pretty bulky. It would be nice to split it up
68 // into smaller submethods, but we need to be careful not to hurt
69 // performance.
70 //
71 template<bool promote_immediately>
72 oop PSPromotionManager::copy_to_survivor_space(oop o) {
73 assert(PSScavenge::should_scavenge(&o), "Sanity");
75 oop new_obj = NULL;
77 #ifdef MIPS64
78 if (Use3A2000) OrderAccess::fence();
79 #endif
81 // NOTE! We must be very careful with any methods that access the mark
82 // in o. There may be multiple threads racing on it, and it may be forwarded
83 // at any time. Do not use oop methods for accessing the mark!
84 markOop test_mark = o->mark();
86 #ifdef MIPS64
87 if (Use3A2000) OrderAccess::fence();
88 #endif
90 // The same test as "o->is_forwarded()"
91 if (!test_mark->is_marked()) {
92 bool new_obj_is_tenured = false;
93 size_t new_obj_size = o->size();
95 if (!promote_immediately) {
96 // Find the objects age, MT safe.
97 uint age = (test_mark->has_displaced_mark_helper() /* o->has_displaced_mark() */) ?
98 test_mark->displaced_mark_helper()->age() : test_mark->age();
100 // Try allocating obj in to-space (unless too old)
101 if (age < PSScavenge::tenuring_threshold()) {
102 new_obj = (oop) _young_lab.allocate(new_obj_size);
103 if (new_obj == NULL && !_young_gen_is_full) {
104 // Do we allocate directly, or flush and refill?
105 if (new_obj_size > (YoungPLABSize / 2)) {
106 // Allocate this object directly
107 new_obj = (oop)young_space()->cas_allocate(new_obj_size);
108 } else {
109 // Flush and fill
110 _young_lab.flush();
112 HeapWord* lab_base = young_space()->cas_allocate(YoungPLABSize);
113 if (lab_base != NULL) {
114 _young_lab.initialize(MemRegion(lab_base, YoungPLABSize));
115 // Try the young lab allocation again.
116 new_obj = (oop) _young_lab.allocate(new_obj_size);
117 } else {
118 _young_gen_is_full = true;
119 }
120 }
121 }
123 #ifdef MIPS64
124 if (Use3A2000) OrderAccess::fence();
125 #endif
126 }
127 }
129 // Otherwise try allocating obj tenured
130 if (new_obj == NULL) {
131 #ifndef PRODUCT
132 if (Universe::heap()->promotion_should_fail()) {
133 return oop_promotion_failed(o, test_mark);
134 }
135 #endif // #ifndef PRODUCT
137 new_obj = (oop) _old_lab.allocate(new_obj_size);
138 new_obj_is_tenured = true;
140 if (new_obj == NULL) {
141 if (!_old_gen_is_full) {
142 // Do we allocate directly, or flush and refill?
143 if (new_obj_size > (OldPLABSize / 2)) {
144 // Allocate this object directly
145 new_obj = (oop)old_gen()->cas_allocate(new_obj_size);
146 } else {
147 // Flush and fill
148 _old_lab.flush();
150 HeapWord* lab_base = old_gen()->cas_allocate(OldPLABSize);
151 if(lab_base != NULL) {
152 #ifdef ASSERT
153 // Delay the initialization of the promotion lab (plab).
154 // This exposes uninitialized plabs to card table processing.
155 if (GCWorkerDelayMillis > 0) {
156 os::sleep(Thread::current(), GCWorkerDelayMillis, false);
157 }
158 #endif
159 _old_lab.initialize(MemRegion(lab_base, OldPLABSize));
160 // Try the old lab allocation again.
161 new_obj = (oop) _old_lab.allocate(new_obj_size);
162 }
163 }
164 }
166 // This is the promotion failed test, and code handling.
167 // The code belongs here for two reasons. It is slightly
168 // different than the code below, and cannot share the
169 // CAS testing code. Keeping the code here also minimizes
170 // the impact on the common case fast path code.
172 if (new_obj == NULL) {
173 _old_gen_is_full = true;
174 return oop_promotion_failed(o, test_mark);
175 }
176 }
177 }
179 assert(new_obj != NULL, "allocation should have succeeded");
181 // Copy obj
182 Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)new_obj, new_obj_size);
183 #ifdef MIPS64
184 if (Use3A2000) OrderAccess::fence();
185 #endif
187 // Now we have to CAS in the header.
188 if (o->cas_forward_to(new_obj, test_mark)) {
189 // We won any races, we "own" this object.
190 assert(new_obj == o->forwardee(), "Sanity");
192 // Increment age if obj still in new generation. Now that
193 // we're dealing with a markOop that cannot change, it is
194 // okay to use the non mt safe oop methods.
195 if (!new_obj_is_tenured) {
196 new_obj->incr_age();
197 assert(young_space()->contains(new_obj), "Attempt to push non-promoted obj");
198 }
200 // Do the size comparison first with new_obj_size, which we
201 // already have. Hopefully, only a few objects are larger than
202 // _min_array_size_for_chunking, and most of them will be arrays.
203 // So, the is->objArray() test would be very infrequent.
204 if (new_obj_size > _min_array_size_for_chunking &&
205 new_obj->is_objArray() &&
206 PSChunkLargeArrays) {
207 // we'll chunk it
208 oop* const masked_o = mask_chunked_array_oop(o);
209 push_depth(masked_o);
210 TASKQUEUE_STATS_ONLY(++_arrays_chunked; ++_masked_pushes);
211 } else {
212 // we'll just push its contents
213 new_obj->push_contents(this);
214 }
215 } else {
216 // We lost, someone else "owns" this object
217 guarantee(o->is_forwarded(), "Object must be forwarded if the cas failed.");
219 // Try to deallocate the space. If it was directly allocated we cannot
220 // deallocate it, so we have to test. If the deallocation fails,
221 // overwrite with a filler object.
222 if (new_obj_is_tenured) {
223 if (!_old_lab.unallocate_object((HeapWord*) new_obj, new_obj_size)) {
224 CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size);
225 }
226 } else if (!_young_lab.unallocate_object((HeapWord*) new_obj, new_obj_size)) {
227 CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size);
228 }
230 // don't update this before the unallocation!
231 new_obj = o->forwardee();
232 }
234 #ifdef MIPS64
235 if (Use3A2000) OrderAccess::fence();
236 #endif
237 } else {
238 assert(o->is_forwarded(), "Sanity");
239 new_obj = o->forwardee();
240 }
242 #ifndef PRODUCT
243 // This code must come after the CAS test, or it will print incorrect
244 // information.
245 if (TraceScavenge) {
246 gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (%d)}",
247 PSScavenge::should_scavenge(&new_obj) ? "copying" : "tenuring",
248 new_obj->klass()->internal_name(), p2i((void *)o), p2i((void *)new_obj), new_obj->size());
249 }
250 #endif
252 return new_obj;
253 }
256 inline void PSPromotionManager::process_popped_location_depth(StarTask p) {
257 if (is_oop_masked(p)) {
258 assert(PSChunkLargeArrays, "invariant");
259 oop const old = unmask_chunked_array_oop(p);
260 process_array_chunk(old);
261 } else {
262 if (p.is_narrow()) {
263 assert(UseCompressedOops, "Error");
264 PSScavenge::copy_and_push_safe_barrier<narrowOop, /*promote_immediately=*/false>(this, p);
265 } else {
266 PSScavenge::copy_and_push_safe_barrier<oop, /*promote_immediately=*/false>(this, p);
267 }
268 }
269 }
271 #if TASKQUEUE_STATS
272 void PSPromotionManager::record_steal(StarTask& p) {
273 if (is_oop_masked(p)) {
274 ++_masked_steals;
275 }
276 }
277 #endif // TASKQUEUE_STATS
279 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP