src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.inline.hpp

Tue, 05 Nov 2013 17:38:04 -0800

author
kvn
date
Tue, 05 Nov 2013 17:38:04 -0800
changeset 6472
2b8e28fdf503
parent 6462
e2722a66aba7
parent 5784
190899198332
child 6680
78bbf4d43a14
permissions
-rw-r--r--

Merge

duke@435 1 /*
sla@5237 2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP
stefank@2314 26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP
stefank@2314 27
nloodin@3665 28 #include "gc_implementation/parallelScavenge/psOldGen.hpp"
stefank@2314 29 #include "gc_implementation/parallelScavenge/psPromotionManager.hpp"
stefank@2314 30 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
goetz@6441 31 #include "oops/oop.psgc.inline.hpp"
stefank@2314 32
duke@435 33 inline PSPromotionManager* PSPromotionManager::manager_array(int index) {
duke@435 34 assert(_manager_array != NULL, "access of NULL manager_array");
duke@435 35 assert(index >= 0 && index <= (int)ParallelGCThreads, "out of range manager_array access");
stefank@5515 36 return &_manager_array[index];
duke@435 37 }
duke@435 38
coleenp@548 39 template <class T>
coleenp@548 40 inline void PSPromotionManager::claim_or_forward_internal_depth(T* p) {
coleenp@548 41 if (p != NULL) { // XXX: error if p != NULL here
coleenp@548 42 oop o = oopDesc::load_decode_heap_oop_not_null(p);
duke@435 43 if (o->is_forwarded()) {
duke@435 44 o = o->forwardee();
duke@435 45 // Card mark
stefank@5202 46 if (PSScavenge::is_obj_in_young(o)) {
duke@435 47 PSScavenge::card_table()->inline_write_ref_field_gc(p, o);
duke@435 48 }
coleenp@548 49 oopDesc::encode_store_heap_oop_not_null(p, o);
duke@435 50 } else {
duke@435 51 push_depth(p);
duke@435 52 }
duke@435 53 }
duke@435 54 }
duke@435 55
coleenp@548 56 template <class T>
coleenp@548 57 inline void PSPromotionManager::claim_or_forward_depth(T* p) {
coleenp@548 58 assert(PSScavenge::should_scavenge(p, true), "revisiting object?");
coleenp@548 59 assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap,
coleenp@548 60 "Sanity");
duke@435 61 assert(Universe::heap()->is_in(p), "pointer outside heap");
duke@435 62
duke@435 63 claim_or_forward_internal_depth(p);
duke@435 64 }
duke@435 65
iveresov@3536 66 //
iveresov@3536 67 // This method is pretty bulky. It would be nice to split it up
iveresov@3536 68 // into smaller submethods, but we need to be careful not to hurt
iveresov@3536 69 // performance.
iveresov@3536 70 //
iveresov@3536 71 template<bool promote_immediately>
iveresov@3536 72 oop PSPromotionManager::copy_to_survivor_space(oop o) {
iveresov@3536 73 assert(PSScavenge::should_scavenge(&o), "Sanity");
iveresov@3536 74
iveresov@3536 75 oop new_obj = NULL;
iveresov@3536 76
iveresov@3536 77 // NOTE! We must be very careful with any methods that access the mark
iveresov@3536 78 // in o. There may be multiple threads racing on it, and it may be forwarded
iveresov@3536 79 // at any time. Do not use oop methods for accessing the mark!
iveresov@3536 80 markOop test_mark = o->mark();
iveresov@3536 81
iveresov@3536 82 // The same test as "o->is_forwarded()"
iveresov@3536 83 if (!test_mark->is_marked()) {
iveresov@3536 84 bool new_obj_is_tenured = false;
iveresov@3536 85 size_t new_obj_size = o->size();
iveresov@3536 86
iveresov@3536 87 if (!promote_immediately) {
iveresov@3536 88 // Find the objects age, MT safe.
jwilhelm@4129 89 uint age = (test_mark->has_displaced_mark_helper() /* o->has_displaced_mark() */) ?
iveresov@3536 90 test_mark->displaced_mark_helper()->age() : test_mark->age();
iveresov@3536 91
iveresov@3536 92 // Try allocating obj in to-space (unless too old)
iveresov@3536 93 if (age < PSScavenge::tenuring_threshold()) {
iveresov@3536 94 new_obj = (oop) _young_lab.allocate(new_obj_size);
iveresov@3536 95 if (new_obj == NULL && !_young_gen_is_full) {
iveresov@3536 96 // Do we allocate directly, or flush and refill?
iveresov@3536 97 if (new_obj_size > (YoungPLABSize / 2)) {
iveresov@3536 98 // Allocate this object directly
iveresov@3536 99 new_obj = (oop)young_space()->cas_allocate(new_obj_size);
iveresov@3536 100 } else {
iveresov@3536 101 // Flush and fill
iveresov@3536 102 _young_lab.flush();
iveresov@3536 103
iveresov@3536 104 HeapWord* lab_base = young_space()->cas_allocate(YoungPLABSize);
iveresov@3536 105 if (lab_base != NULL) {
iveresov@3536 106 _young_lab.initialize(MemRegion(lab_base, YoungPLABSize));
iveresov@3536 107 // Try the young lab allocation again.
iveresov@3536 108 new_obj = (oop) _young_lab.allocate(new_obj_size);
iveresov@3536 109 } else {
iveresov@3536 110 _young_gen_is_full = true;
iveresov@3536 111 }
iveresov@3536 112 }
iveresov@3536 113 }
iveresov@3536 114 }
iveresov@3536 115 }
iveresov@3536 116
iveresov@3536 117 // Otherwise try allocating obj tenured
iveresov@3536 118 if (new_obj == NULL) {
iveresov@3536 119 #ifndef PRODUCT
iveresov@3536 120 if (Universe::heap()->promotion_should_fail()) {
iveresov@3536 121 return oop_promotion_failed(o, test_mark);
iveresov@3536 122 }
iveresov@3536 123 #endif // #ifndef PRODUCT
iveresov@3536 124
iveresov@3536 125 new_obj = (oop) _old_lab.allocate(new_obj_size);
iveresov@3536 126 new_obj_is_tenured = true;
iveresov@3536 127
iveresov@3536 128 if (new_obj == NULL) {
iveresov@3536 129 if (!_old_gen_is_full) {
iveresov@3536 130 // Do we allocate directly, or flush and refill?
iveresov@3536 131 if (new_obj_size > (OldPLABSize / 2)) {
iveresov@3536 132 // Allocate this object directly
iveresov@3536 133 new_obj = (oop)old_gen()->cas_allocate(new_obj_size);
iveresov@3536 134 } else {
iveresov@3536 135 // Flush and fill
iveresov@3536 136 _old_lab.flush();
iveresov@3536 137
iveresov@3536 138 HeapWord* lab_base = old_gen()->cas_allocate(OldPLABSize);
iveresov@3536 139 if(lab_base != NULL) {
jmasa@4128 140 #ifdef ASSERT
jmasa@4128 141 // Delay the initialization of the promotion lab (plab).
jmasa@4128 142 // This exposes uninitialized plabs to card table processing.
jmasa@4128 143 if (GCWorkerDelayMillis > 0) {
jmasa@4128 144 os::sleep(Thread::current(), GCWorkerDelayMillis, false);
jmasa@4128 145 }
jmasa@4128 146 #endif
iveresov@3536 147 _old_lab.initialize(MemRegion(lab_base, OldPLABSize));
iveresov@3536 148 // Try the old lab allocation again.
iveresov@3536 149 new_obj = (oop) _old_lab.allocate(new_obj_size);
iveresov@3536 150 }
iveresov@3536 151 }
iveresov@3536 152 }
iveresov@3536 153
iveresov@3536 154 // This is the promotion failed test, and code handling.
iveresov@3536 155 // The code belongs here for two reasons. It is slightly
sla@5237 156 // different than the code below, and cannot share the
iveresov@3536 157 // CAS testing code. Keeping the code here also minimizes
iveresov@3536 158 // the impact on the common case fast path code.
iveresov@3536 159
iveresov@3536 160 if (new_obj == NULL) {
iveresov@3536 161 _old_gen_is_full = true;
iveresov@3536 162 return oop_promotion_failed(o, test_mark);
iveresov@3536 163 }
iveresov@3536 164 }
iveresov@3536 165 }
iveresov@3536 166
iveresov@3536 167 assert(new_obj != NULL, "allocation should have succeeded");
iveresov@3536 168
iveresov@3536 169 // Copy obj
iveresov@3536 170 Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)new_obj, new_obj_size);
iveresov@3536 171
iveresov@3536 172 // Now we have to CAS in the header.
iveresov@3536 173 if (o->cas_forward_to(new_obj, test_mark)) {
iveresov@3536 174 // We won any races, we "own" this object.
iveresov@3536 175 assert(new_obj == o->forwardee(), "Sanity");
iveresov@3536 176
iveresov@3536 177 // Increment age if obj still in new generation. Now that
iveresov@3536 178 // we're dealing with a markOop that cannot change, it is
iveresov@3536 179 // okay to use the non mt safe oop methods.
iveresov@3536 180 if (!new_obj_is_tenured) {
iveresov@3536 181 new_obj->incr_age();
iveresov@3536 182 assert(young_space()->contains(new_obj), "Attempt to push non-promoted obj");
iveresov@3536 183 }
iveresov@3536 184
iveresov@3536 185 // Do the size comparison first with new_obj_size, which we
iveresov@3536 186 // already have. Hopefully, only a few objects are larger than
iveresov@3536 187 // _min_array_size_for_chunking, and most of them will be arrays.
iveresov@3536 188 // So, the is->objArray() test would be very infrequent.
iveresov@3536 189 if (new_obj_size > _min_array_size_for_chunking &&
iveresov@3536 190 new_obj->is_objArray() &&
iveresov@3536 191 PSChunkLargeArrays) {
iveresov@3536 192 // we'll chunk it
iveresov@3536 193 oop* const masked_o = mask_chunked_array_oop(o);
iveresov@3536 194 push_depth(masked_o);
iveresov@3536 195 TASKQUEUE_STATS_ONLY(++_arrays_chunked; ++_masked_pushes);
iveresov@3536 196 } else {
iveresov@3536 197 // we'll just push its contents
iveresov@3536 198 new_obj->push_contents(this);
iveresov@3536 199 }
iveresov@3536 200 } else {
iveresov@3536 201 // We lost, someone else "owns" this object
iveresov@3536 202 guarantee(o->is_forwarded(), "Object must be forwarded if the cas failed.");
iveresov@3536 203
iveresov@3536 204 // Try to deallocate the space. If it was directly allocated we cannot
iveresov@3536 205 // deallocate it, so we have to test. If the deallocation fails,
iveresov@3536 206 // overwrite with a filler object.
iveresov@3536 207 if (new_obj_is_tenured) {
iveresov@3536 208 if (!_old_lab.unallocate_object((HeapWord*) new_obj, new_obj_size)) {
iveresov@3536 209 CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size);
iveresov@3536 210 }
iveresov@3536 211 } else if (!_young_lab.unallocate_object((HeapWord*) new_obj, new_obj_size)) {
iveresov@3536 212 CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size);
iveresov@3536 213 }
iveresov@3536 214
iveresov@3536 215 // don't update this before the unallocation!
iveresov@3536 216 new_obj = o->forwardee();
iveresov@3536 217 }
iveresov@3536 218 } else {
iveresov@3536 219 assert(o->is_forwarded(), "Sanity");
iveresov@3536 220 new_obj = o->forwardee();
iveresov@3536 221 }
iveresov@3536 222
coleenp@4037 223 #ifndef PRODUCT
iveresov@3536 224 // This code must come after the CAS test, or it will print incorrect
iveresov@3536 225 // information.
iveresov@3536 226 if (TraceScavenge) {
coleenp@4037 227 gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (%d)}",
iveresov@3536 228 PSScavenge::should_scavenge(&new_obj) ? "copying" : "tenuring",
hseigel@5784 229 new_obj->klass()->internal_name(), (void *)o, (void *)new_obj, new_obj->size());
iveresov@3536 230 }
iveresov@3536 231 #endif
iveresov@3536 232
iveresov@3536 233 return new_obj;
iveresov@3536 234 }
iveresov@3536 235
iveresov@3536 236
coleenp@548 237 inline void PSPromotionManager::process_popped_location_depth(StarTask p) {
duke@435 238 if (is_oop_masked(p)) {
duke@435 239 assert(PSChunkLargeArrays, "invariant");
duke@435 240 oop const old = unmask_chunked_array_oop(p);
duke@435 241 process_array_chunk(old);
duke@435 242 } else {
coleenp@548 243 if (p.is_narrow()) {
ysr@1280 244 assert(UseCompressedOops, "Error");
iveresov@3536 245 PSScavenge::copy_and_push_safe_barrier<narrowOop, /*promote_immediately=*/false>(this, p);
coleenp@548 246 } else {
iveresov@3536 247 PSScavenge::copy_and_push_safe_barrier<oop, /*promote_immediately=*/false>(this, p);
coleenp@548 248 }
duke@435 249 }
duke@435 250 }
jcoomes@2020 251
jcoomes@2020 252 #if TASKQUEUE_STATS
jcoomes@2020 253 void PSPromotionManager::record_steal(StarTask& p) {
jcoomes@2020 254 if (is_oop_masked(p)) {
jcoomes@2020 255 ++_masked_steals;
jcoomes@2020 256 }
jcoomes@2020 257 }
jcoomes@2020 258 #endif // TASKQUEUE_STATS
stefank@2314 259
stefank@2314 260 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP

mercurial