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

Fri, 10 Feb 2012 17:40:20 -0800

author
iveresov
date
Fri, 10 Feb 2012 17:40:20 -0800
changeset 3536
95f6641e38e0
parent 2314
f95d63e2154a
child 3665
8a729074feae
permissions
-rw-r--r--

7144296: PS: Optimize nmethods processing
Summary: Prunes scavenge roots in code list every young GC, promote objects directly pointed by the code immediately
Reviewed-by: johnc, jcoomes

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

mercurial