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

Mon, 04 Aug 2014 10:48:10 -0700

author
jmasa
date
Mon, 04 Aug 2014 10:48:10 -0700
changeset 7031
ee019285a52c
parent 6680
78bbf4d43a14
child 7535
7ae4e26cb1e0
child 9858
b985cbb00e68
permissions
-rw-r--r--

8031323: Optionally align objects copied to survivor spaces
Reviewed-by: brutisso, tschatzl

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

mercurial