Mon, 26 Sep 2011 10:24:05 -0700
7081933: Use zeroing elimination optimization for large array
Summary: Don't zero new typeArray during runtime call if the allocation is followed by arraycopy into it.
Reviewed-by: twisti
duke@435 | 1 | /* |
trims@2708 | 2 | * Copyright (c) 2001, 2011, 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 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 27 | #include "gc_implementation/shared/vmGCOperations.hpp" |
stefank@2314 | 28 | #include "gc_interface/collectedHeap.hpp" |
stefank@2314 | 29 | #include "gc_interface/collectedHeap.inline.hpp" |
stefank@2314 | 30 | #include "oops/oop.inline.hpp" |
stefank@2314 | 31 | #include "runtime/init.hpp" |
stefank@2314 | 32 | #include "services/heapDumper.hpp" |
stefank@2314 | 33 | #ifdef TARGET_OS_FAMILY_linux |
stefank@2314 | 34 | # include "thread_linux.inline.hpp" |
stefank@2314 | 35 | #endif |
stefank@2314 | 36 | #ifdef TARGET_OS_FAMILY_solaris |
stefank@2314 | 37 | # include "thread_solaris.inline.hpp" |
stefank@2314 | 38 | #endif |
stefank@2314 | 39 | #ifdef TARGET_OS_FAMILY_windows |
stefank@2314 | 40 | # include "thread_windows.inline.hpp" |
stefank@2314 | 41 | #endif |
never@3156 | 42 | #ifdef TARGET_OS_FAMILY_bsd |
never@3156 | 43 | # include "thread_bsd.inline.hpp" |
never@3156 | 44 | #endif |
duke@435 | 45 | |
duke@435 | 46 | |
duke@435 | 47 | #ifdef ASSERT |
duke@435 | 48 | int CollectedHeap::_fire_out_of_memory_count = 0; |
duke@435 | 49 | #endif |
duke@435 | 50 | |
jcoomes@916 | 51 | size_t CollectedHeap::_filler_array_max_size = 0; |
jcoomes@916 | 52 | |
duke@435 | 53 | // Memory state functions. |
duke@435 | 54 | |
jmasa@2188 | 55 | |
jmasa@2188 | 56 | CollectedHeap::CollectedHeap() : _n_par_threads(0) |
jmasa@2188 | 57 | |
jcoomes@916 | 58 | { |
jcoomes@916 | 59 | const size_t max_len = size_t(arrayOopDesc::max_array_length(T_INT)); |
jcoomes@916 | 60 | const size_t elements_per_word = HeapWordSize / sizeof(jint); |
jcoomes@916 | 61 | _filler_array_max_size = align_object_size(filler_array_hdr_size() + |
jcoomes@916 | 62 | max_len * elements_per_word); |
jcoomes@916 | 63 | |
jcoomes@916 | 64 | _barrier_set = NULL; |
jcoomes@916 | 65 | _is_gc_active = false; |
jcoomes@916 | 66 | _total_collections = _total_full_collections = 0; |
jcoomes@916 | 67 | _gc_cause = _gc_lastcause = GCCause::_no_gc; |
duke@435 | 68 | NOT_PRODUCT(_promotion_failure_alot_count = 0;) |
duke@435 | 69 | NOT_PRODUCT(_promotion_failure_alot_gc_number = 0;) |
duke@435 | 70 | |
duke@435 | 71 | if (UsePerfData) { |
duke@435 | 72 | EXCEPTION_MARK; |
duke@435 | 73 | |
duke@435 | 74 | // create the gc cause jvmstat counters |
duke@435 | 75 | _perf_gc_cause = PerfDataManager::create_string_variable(SUN_GC, "cause", |
duke@435 | 76 | 80, GCCause::to_string(_gc_cause), CHECK); |
duke@435 | 77 | |
duke@435 | 78 | _perf_gc_lastcause = |
duke@435 | 79 | PerfDataManager::create_string_variable(SUN_GC, "lastCause", |
duke@435 | 80 | 80, GCCause::to_string(_gc_lastcause), CHECK); |
duke@435 | 81 | } |
ysr@1601 | 82 | _defer_initial_card_mark = false; // strengthened by subclass in pre_initialize() below. |
duke@435 | 83 | } |
duke@435 | 84 | |
ysr@1601 | 85 | void CollectedHeap::pre_initialize() { |
ysr@1601 | 86 | // Used for ReduceInitialCardMarks (when COMPILER2 is used); |
ysr@1601 | 87 | // otherwise remains unused. |
ysr@1903 | 88 | #ifdef COMPILER2 |
ysr@1629 | 89 | _defer_initial_card_mark = ReduceInitialCardMarks && can_elide_tlab_store_barriers() |
ysr@1629 | 90 | && (DeferInitialCardMark || card_mark_must_follow_store()); |
ysr@1601 | 91 | #else |
ysr@1601 | 92 | assert(_defer_initial_card_mark == false, "Who would set it?"); |
ysr@1601 | 93 | #endif |
ysr@1601 | 94 | } |
duke@435 | 95 | |
duke@435 | 96 | #ifndef PRODUCT |
duke@435 | 97 | void CollectedHeap::check_for_bad_heap_word_value(HeapWord* addr, size_t size) { |
duke@435 | 98 | if (CheckMemoryInitialization && ZapUnusedHeapArea) { |
duke@435 | 99 | for (size_t slot = 0; slot < size; slot += 1) { |
duke@435 | 100 | assert((*(intptr_t*) (addr + slot)) != ((intptr_t) badHeapWordVal), |
duke@435 | 101 | "Found badHeapWordValue in post-allocation check"); |
duke@435 | 102 | } |
duke@435 | 103 | } |
duke@435 | 104 | } |
duke@435 | 105 | |
ysr@2533 | 106 | void CollectedHeap::check_for_non_bad_heap_word_value(HeapWord* addr, size_t size) { |
duke@435 | 107 | if (CheckMemoryInitialization && ZapUnusedHeapArea) { |
duke@435 | 108 | for (size_t slot = 0; slot < size; slot += 1) { |
duke@435 | 109 | assert((*(intptr_t*) (addr + slot)) == ((intptr_t) badHeapWordVal), |
duke@435 | 110 | "Found non badHeapWordValue in pre-allocation check"); |
duke@435 | 111 | } |
duke@435 | 112 | } |
duke@435 | 113 | } |
duke@435 | 114 | #endif // PRODUCT |
duke@435 | 115 | |
duke@435 | 116 | #ifdef ASSERT |
duke@435 | 117 | void CollectedHeap::check_for_valid_allocation_state() { |
duke@435 | 118 | Thread *thread = Thread::current(); |
duke@435 | 119 | // How to choose between a pending exception and a potential |
duke@435 | 120 | // OutOfMemoryError? Don't allow pending exceptions. |
duke@435 | 121 | // This is a VM policy failure, so how do we exhaustively test it? |
duke@435 | 122 | assert(!thread->has_pending_exception(), |
duke@435 | 123 | "shouldn't be allocating with pending exception"); |
duke@435 | 124 | if (StrictSafepointChecks) { |
duke@435 | 125 | assert(thread->allow_allocation(), |
duke@435 | 126 | "Allocation done by thread for which allocation is blocked " |
duke@435 | 127 | "by No_Allocation_Verifier!"); |
duke@435 | 128 | // Allocation of an oop can always invoke a safepoint, |
duke@435 | 129 | // hence, the true argument |
duke@435 | 130 | thread->check_for_valid_safepoint_state(true); |
duke@435 | 131 | } |
duke@435 | 132 | } |
duke@435 | 133 | #endif |
duke@435 | 134 | |
duke@435 | 135 | HeapWord* CollectedHeap::allocate_from_tlab_slow(Thread* thread, size_t size) { |
duke@435 | 136 | |
duke@435 | 137 | // Retain tlab and allocate object in shared space if |
duke@435 | 138 | // the amount free in the tlab is too large to discard. |
duke@435 | 139 | if (thread->tlab().free() > thread->tlab().refill_waste_limit()) { |
duke@435 | 140 | thread->tlab().record_slow_allocation(size); |
duke@435 | 141 | return NULL; |
duke@435 | 142 | } |
duke@435 | 143 | |
duke@435 | 144 | // Discard tlab and allocate a new one. |
duke@435 | 145 | // To minimize fragmentation, the last TLAB may be smaller than the rest. |
duke@435 | 146 | size_t new_tlab_size = thread->tlab().compute_size(size); |
duke@435 | 147 | |
duke@435 | 148 | thread->tlab().clear_before_allocation(); |
duke@435 | 149 | |
duke@435 | 150 | if (new_tlab_size == 0) { |
duke@435 | 151 | return NULL; |
duke@435 | 152 | } |
duke@435 | 153 | |
duke@435 | 154 | // Allocate a new TLAB... |
duke@435 | 155 | HeapWord* obj = Universe::heap()->allocate_new_tlab(new_tlab_size); |
duke@435 | 156 | if (obj == NULL) { |
duke@435 | 157 | return NULL; |
duke@435 | 158 | } |
duke@435 | 159 | if (ZeroTLAB) { |
duke@435 | 160 | // ..and clear it. |
duke@435 | 161 | Copy::zero_to_words(obj, new_tlab_size); |
duke@435 | 162 | } else { |
kvn@3092 | 163 | // ...and zap just allocated object. |
kvn@3092 | 164 | #ifdef ASSERT |
kvn@3092 | 165 | // Skip mangling the space corresponding to the object header to |
kvn@3092 | 166 | // ensure that the returned space is not considered parsable by |
kvn@3092 | 167 | // any concurrent GC thread. |
kvn@3092 | 168 | size_t hdr_size = oopDesc::header_size(); |
kvn@3092 | 169 | Copy::fill_to_words(obj + hdr_size, new_tlab_size - hdr_size, badHeapWordVal); |
kvn@3092 | 170 | #endif // ASSERT |
duke@435 | 171 | } |
duke@435 | 172 | thread->tlab().fill(obj, obj + size, new_tlab_size); |
duke@435 | 173 | return obj; |
duke@435 | 174 | } |
duke@435 | 175 | |
ysr@1462 | 176 | void CollectedHeap::flush_deferred_store_barrier(JavaThread* thread) { |
ysr@1462 | 177 | MemRegion deferred = thread->deferred_card_mark(); |
ysr@1462 | 178 | if (!deferred.is_empty()) { |
ysr@1601 | 179 | assert(_defer_initial_card_mark, "Otherwise should be empty"); |
ysr@1462 | 180 | { |
ysr@1462 | 181 | // Verify that the storage points to a parsable object in heap |
ysr@1462 | 182 | DEBUG_ONLY(oop old_obj = oop(deferred.start());) |
ysr@1462 | 183 | assert(is_in(old_obj), "Not in allocated heap"); |
ysr@1462 | 184 | assert(!can_elide_initializing_store_barrier(old_obj), |
ysr@1601 | 185 | "Else should have been filtered in new_store_pre_barrier()"); |
ysr@1462 | 186 | assert(!is_in_permanent(old_obj), "Sanity: not expected"); |
ysr@1462 | 187 | assert(old_obj->is_oop(true), "Not an oop"); |
ysr@1462 | 188 | assert(old_obj->is_parsable(), "Will not be concurrently parsable"); |
ysr@1462 | 189 | assert(deferred.word_size() == (size_t)(old_obj->size()), |
ysr@1462 | 190 | "Mismatch: multiple objects?"); |
ysr@1462 | 191 | } |
ysr@1462 | 192 | BarrierSet* bs = barrier_set(); |
ysr@1462 | 193 | assert(bs->has_write_region_opt(), "No write_region() on BarrierSet"); |
ysr@1462 | 194 | bs->write_region(deferred); |
ysr@1462 | 195 | // "Clear" the deferred_card_mark field |
ysr@1462 | 196 | thread->set_deferred_card_mark(MemRegion()); |
ysr@1462 | 197 | } |
ysr@1462 | 198 | assert(thread->deferred_card_mark().is_empty(), "invariant"); |
ysr@1462 | 199 | } |
ysr@1462 | 200 | |
ysr@1462 | 201 | // Helper for ReduceInitialCardMarks. For performance, |
ysr@1462 | 202 | // compiled code may elide card-marks for initializing stores |
ysr@1462 | 203 | // to a newly allocated object along the fast-path. We |
ysr@1462 | 204 | // compensate for such elided card-marks as follows: |
ysr@1462 | 205 | // (a) Generational, non-concurrent collectors, such as |
ysr@1462 | 206 | // GenCollectedHeap(ParNew,DefNew,Tenured) and |
ysr@1462 | 207 | // ParallelScavengeHeap(ParallelGC, ParallelOldGC) |
ysr@1462 | 208 | // need the card-mark if and only if the region is |
ysr@1462 | 209 | // in the old gen, and do not care if the card-mark |
ysr@1462 | 210 | // succeeds or precedes the initializing stores themselves, |
ysr@1462 | 211 | // so long as the card-mark is completed before the next |
ysr@1462 | 212 | // scavenge. For all these cases, we can do a card mark |
ysr@1462 | 213 | // at the point at which we do a slow path allocation |
ysr@1601 | 214 | // in the old gen, i.e. in this call. |
ysr@1462 | 215 | // (b) GenCollectedHeap(ConcurrentMarkSweepGeneration) requires |
ysr@1462 | 216 | // in addition that the card-mark for an old gen allocated |
ysr@1462 | 217 | // object strictly follow any associated initializing stores. |
ysr@1462 | 218 | // In these cases, the memRegion remembered below is |
ysr@1462 | 219 | // used to card-mark the entire region either just before the next |
ysr@1462 | 220 | // slow-path allocation by this thread or just before the next scavenge or |
ysr@1462 | 221 | // CMS-associated safepoint, whichever of these events happens first. |
ysr@1462 | 222 | // (The implicit assumption is that the object has been fully |
ysr@1462 | 223 | // initialized by this point, a fact that we assert when doing the |
ysr@1462 | 224 | // card-mark.) |
ysr@1462 | 225 | // (c) G1CollectedHeap(G1) uses two kinds of write barriers. When a |
ysr@1462 | 226 | // G1 concurrent marking is in progress an SATB (pre-write-)barrier is |
ysr@1462 | 227 | // is used to remember the pre-value of any store. Initializing |
ysr@1462 | 228 | // stores will not need this barrier, so we need not worry about |
ysr@1462 | 229 | // compensating for the missing pre-barrier here. Turning now |
ysr@1462 | 230 | // to the post-barrier, we note that G1 needs a RS update barrier |
ysr@1462 | 231 | // which simply enqueues a (sequence of) dirty cards which may |
ysr@1462 | 232 | // optionally be refined by the concurrent update threads. Note |
ysr@1462 | 233 | // that this barrier need only be applied to a non-young write, |
ysr@1462 | 234 | // but, like in CMS, because of the presence of concurrent refinement |
ysr@1462 | 235 | // (much like CMS' precleaning), must strictly follow the oop-store. |
ysr@1462 | 236 | // Thus, using the same protocol for maintaining the intended |
ysr@1601 | 237 | // invariants turns out, serendepitously, to be the same for both |
ysr@1601 | 238 | // G1 and CMS. |
ysr@1462 | 239 | // |
ysr@1601 | 240 | // For any future collector, this code should be reexamined with |
ysr@1601 | 241 | // that specific collector in mind, and the documentation above suitably |
ysr@1601 | 242 | // extended and updated. |
ysr@1601 | 243 | oop CollectedHeap::new_store_pre_barrier(JavaThread* thread, oop new_obj) { |
ysr@1462 | 244 | // If a previous card-mark was deferred, flush it now. |
ysr@1462 | 245 | flush_deferred_store_barrier(thread); |
ysr@1462 | 246 | if (can_elide_initializing_store_barrier(new_obj)) { |
ysr@1462 | 247 | // The deferred_card_mark region should be empty |
ysr@1462 | 248 | // following the flush above. |
ysr@1462 | 249 | assert(thread->deferred_card_mark().is_empty(), "Error"); |
ysr@1462 | 250 | } else { |
ysr@1601 | 251 | MemRegion mr((HeapWord*)new_obj, new_obj->size()); |
ysr@1601 | 252 | assert(!mr.is_empty(), "Error"); |
ysr@1601 | 253 | if (_defer_initial_card_mark) { |
ysr@1601 | 254 | // Defer the card mark |
ysr@1601 | 255 | thread->set_deferred_card_mark(mr); |
ysr@1601 | 256 | } else { |
ysr@1601 | 257 | // Do the card mark |
ysr@1601 | 258 | BarrierSet* bs = barrier_set(); |
ysr@1601 | 259 | assert(bs->has_write_region_opt(), "No write_region() on BarrierSet"); |
ysr@1601 | 260 | bs->write_region(mr); |
ysr@1601 | 261 | } |
ysr@1462 | 262 | } |
ysr@1462 | 263 | return new_obj; |
ysr@1462 | 264 | } |
ysr@1462 | 265 | |
jcoomes@916 | 266 | size_t CollectedHeap::filler_array_hdr_size() { |
kvn@1926 | 267 | return size_t(align_object_offset(arrayOopDesc::header_size(T_INT))); // align to Long |
jcoomes@916 | 268 | } |
jcoomes@916 | 269 | |
jcoomes@916 | 270 | size_t CollectedHeap::filler_array_min_size() { |
kvn@1926 | 271 | return align_object_size(filler_array_hdr_size()); // align to MinObjAlignment |
jcoomes@916 | 272 | } |
jcoomes@916 | 273 | |
jcoomes@916 | 274 | size_t CollectedHeap::filler_array_max_size() { |
jcoomes@916 | 275 | return _filler_array_max_size; |
jcoomes@916 | 276 | } |
jcoomes@916 | 277 | |
jcoomes@916 | 278 | #ifdef ASSERT |
jcoomes@916 | 279 | void CollectedHeap::fill_args_check(HeapWord* start, size_t words) |
jcoomes@916 | 280 | { |
jcoomes@916 | 281 | assert(words >= min_fill_size(), "too small to fill"); |
jcoomes@916 | 282 | assert(words % MinObjAlignment == 0, "unaligned size"); |
jcoomes@916 | 283 | assert(Universe::heap()->is_in_reserved(start), "not in heap"); |
jcoomes@916 | 284 | assert(Universe::heap()->is_in_reserved(start + words - 1), "not in heap"); |
jcoomes@916 | 285 | } |
jcoomes@916 | 286 | |
johnc@1600 | 287 | void CollectedHeap::zap_filler_array(HeapWord* start, size_t words, bool zap) |
jcoomes@916 | 288 | { |
johnc@1600 | 289 | if (ZapFillerObjects && zap) { |
jcoomes@916 | 290 | Copy::fill_to_words(start + filler_array_hdr_size(), |
jcoomes@916 | 291 | words - filler_array_hdr_size(), 0XDEAFBABE); |
jcoomes@916 | 292 | } |
jcoomes@916 | 293 | } |
jcoomes@916 | 294 | #endif // ASSERT |
jcoomes@916 | 295 | |
jcoomes@916 | 296 | void |
johnc@1600 | 297 | CollectedHeap::fill_with_array(HeapWord* start, size_t words, bool zap) |
jcoomes@916 | 298 | { |
jcoomes@916 | 299 | assert(words >= filler_array_min_size(), "too small for an array"); |
jcoomes@916 | 300 | assert(words <= filler_array_max_size(), "too big for a single object"); |
jcoomes@916 | 301 | |
jcoomes@916 | 302 | const size_t payload_size = words - filler_array_hdr_size(); |
jcoomes@916 | 303 | const size_t len = payload_size * HeapWordSize / sizeof(jint); |
jcoomes@916 | 304 | |
jcoomes@916 | 305 | // Set the length first for concurrent GC. |
jcoomes@916 | 306 | ((arrayOop)start)->set_length((int)len); |
jcoomes@929 | 307 | post_allocation_setup_common(Universe::intArrayKlassObj(), start, words); |
johnc@1600 | 308 | DEBUG_ONLY(zap_filler_array(start, words, zap);) |
jcoomes@916 | 309 | } |
jcoomes@916 | 310 | |
jcoomes@916 | 311 | void |
johnc@1600 | 312 | CollectedHeap::fill_with_object_impl(HeapWord* start, size_t words, bool zap) |
jcoomes@916 | 313 | { |
jcoomes@916 | 314 | assert(words <= filler_array_max_size(), "too big for a single object"); |
jcoomes@916 | 315 | |
jcoomes@916 | 316 | if (words >= filler_array_min_size()) { |
johnc@1600 | 317 | fill_with_array(start, words, zap); |
jcoomes@916 | 318 | } else if (words > 0) { |
jcoomes@916 | 319 | assert(words == min_fill_size(), "unaligned size"); |
never@1577 | 320 | post_allocation_setup_common(SystemDictionary::Object_klass(), start, |
jcoomes@916 | 321 | words); |
jcoomes@916 | 322 | } |
jcoomes@916 | 323 | } |
jcoomes@916 | 324 | |
johnc@1600 | 325 | void CollectedHeap::fill_with_object(HeapWord* start, size_t words, bool zap) |
jcoomes@916 | 326 | { |
jcoomes@916 | 327 | DEBUG_ONLY(fill_args_check(start, words);) |
jcoomes@916 | 328 | HandleMark hm; // Free handles before leaving. |
johnc@1600 | 329 | fill_with_object_impl(start, words, zap); |
jcoomes@916 | 330 | } |
jcoomes@916 | 331 | |
johnc@1600 | 332 | void CollectedHeap::fill_with_objects(HeapWord* start, size_t words, bool zap) |
jcoomes@916 | 333 | { |
jcoomes@916 | 334 | DEBUG_ONLY(fill_args_check(start, words);) |
jcoomes@916 | 335 | HandleMark hm; // Free handles before leaving. |
jcoomes@916 | 336 | |
ysr@1904 | 337 | #ifdef _LP64 |
jcoomes@916 | 338 | // A single array can fill ~8G, so multiple objects are needed only in 64-bit. |
jcoomes@916 | 339 | // First fill with arrays, ensuring that any remaining space is big enough to |
jcoomes@916 | 340 | // fill. The remainder is filled with a single object. |
jcoomes@916 | 341 | const size_t min = min_fill_size(); |
jcoomes@916 | 342 | const size_t max = filler_array_max_size(); |
jcoomes@916 | 343 | while (words > max) { |
jcoomes@916 | 344 | const size_t cur = words - max >= min ? max : max - min; |
johnc@1600 | 345 | fill_with_array(start, cur, zap); |
jcoomes@916 | 346 | start += cur; |
jcoomes@916 | 347 | words -= cur; |
jcoomes@916 | 348 | } |
jcoomes@916 | 349 | #endif |
jcoomes@916 | 350 | |
johnc@1600 | 351 | fill_with_object_impl(start, words, zap); |
jcoomes@916 | 352 | } |
jcoomes@916 | 353 | |
duke@435 | 354 | HeapWord* CollectedHeap::allocate_new_tlab(size_t size) { |
duke@435 | 355 | guarantee(false, "thread-local allocation buffers not supported"); |
duke@435 | 356 | return NULL; |
duke@435 | 357 | } |
duke@435 | 358 | |
duke@435 | 359 | void CollectedHeap::ensure_parsability(bool retire_tlabs) { |
duke@435 | 360 | // The second disjunct in the assertion below makes a concession |
duke@435 | 361 | // for the start-up verification done while the VM is being |
duke@435 | 362 | // created. Callers be careful that you know that mutators |
duke@435 | 363 | // aren't going to interfere -- for instance, this is permissible |
duke@435 | 364 | // if we are still single-threaded and have either not yet |
duke@435 | 365 | // started allocating (nothing much to verify) or we have |
duke@435 | 366 | // started allocating but are now a full-fledged JavaThread |
duke@435 | 367 | // (and have thus made our TLAB's) available for filling. |
duke@435 | 368 | assert(SafepointSynchronize::is_at_safepoint() || |
duke@435 | 369 | !is_init_completed(), |
duke@435 | 370 | "Should only be called at a safepoint or at start-up" |
duke@435 | 371 | " otherwise concurrent mutator activity may make heap " |
duke@435 | 372 | " unparsable again"); |
ysr@1601 | 373 | const bool use_tlab = UseTLAB; |
ysr@1601 | 374 | const bool deferred = _defer_initial_card_mark; |
ysr@1601 | 375 | // The main thread starts allocating via a TLAB even before it |
ysr@1601 | 376 | // has added itself to the threads list at vm boot-up. |
ysr@1601 | 377 | assert(!use_tlab || Threads::first() != NULL, |
ysr@1601 | 378 | "Attempt to fill tlabs before main thread has been added" |
ysr@1601 | 379 | " to threads list is doomed to failure!"); |
ysr@1601 | 380 | for (JavaThread *thread = Threads::first(); thread; thread = thread->next()) { |
ysr@1601 | 381 | if (use_tlab) thread->tlab().make_parsable(retire_tlabs); |
ysr@1601 | 382 | #ifdef COMPILER2 |
ysr@1601 | 383 | // The deferred store barriers must all have been flushed to the |
ysr@1601 | 384 | // card-table (or other remembered set structure) before GC starts |
ysr@1601 | 385 | // processing the card-table (or other remembered set). |
ysr@1601 | 386 | if (deferred) flush_deferred_store_barrier(thread); |
ysr@1601 | 387 | #else |
ysr@1601 | 388 | assert(!deferred, "Should be false"); |
ysr@1601 | 389 | assert(thread->deferred_card_mark().is_empty(), "Should be empty"); |
ysr@1601 | 390 | #endif |
duke@435 | 391 | } |
duke@435 | 392 | } |
duke@435 | 393 | |
duke@435 | 394 | void CollectedHeap::accumulate_statistics_all_tlabs() { |
duke@435 | 395 | if (UseTLAB) { |
duke@435 | 396 | assert(SafepointSynchronize::is_at_safepoint() || |
duke@435 | 397 | !is_init_completed(), |
duke@435 | 398 | "should only accumulate statistics on tlabs at safepoint"); |
duke@435 | 399 | |
duke@435 | 400 | ThreadLocalAllocBuffer::accumulate_statistics_before_gc(); |
duke@435 | 401 | } |
duke@435 | 402 | } |
duke@435 | 403 | |
duke@435 | 404 | void CollectedHeap::resize_all_tlabs() { |
duke@435 | 405 | if (UseTLAB) { |
duke@435 | 406 | assert(SafepointSynchronize::is_at_safepoint() || |
duke@435 | 407 | !is_init_completed(), |
duke@435 | 408 | "should only resize tlabs at safepoint"); |
duke@435 | 409 | |
duke@435 | 410 | ThreadLocalAllocBuffer::resize_all_tlabs(); |
duke@435 | 411 | } |
duke@435 | 412 | } |
ysr@1050 | 413 | |
ysr@1050 | 414 | void CollectedHeap::pre_full_gc_dump() { |
ysr@1050 | 415 | if (HeapDumpBeforeFullGC) { |
ysr@3067 | 416 | TraceTime tt("Heap Dump (before full gc): ", PrintGCDetails, false, gclog_or_tty); |
ysr@1050 | 417 | // We are doing a "major" collection and a heap dump before |
ysr@1050 | 418 | // major collection has been requested. |
ysr@1050 | 419 | HeapDumper::dump_heap(); |
ysr@1050 | 420 | } |
ysr@1050 | 421 | if (PrintClassHistogramBeforeFullGC) { |
ysr@3067 | 422 | TraceTime tt("Class Histogram (before full gc): ", PrintGCDetails, true, gclog_or_tty); |
ysr@1050 | 423 | VM_GC_HeapInspection inspector(gclog_or_tty, false /* ! full gc */, false /* ! prologue */); |
ysr@1050 | 424 | inspector.doit(); |
ysr@1050 | 425 | } |
ysr@1050 | 426 | } |
ysr@1050 | 427 | |
ysr@1050 | 428 | void CollectedHeap::post_full_gc_dump() { |
ysr@1050 | 429 | if (HeapDumpAfterFullGC) { |
ysr@3067 | 430 | TraceTime tt("Heap Dump (after full gc): ", PrintGCDetails, false, gclog_or_tty); |
ysr@1050 | 431 | HeapDumper::dump_heap(); |
ysr@1050 | 432 | } |
ysr@1050 | 433 | if (PrintClassHistogramAfterFullGC) { |
ysr@3067 | 434 | TraceTime tt("Class Histogram (after full gc): ", PrintGCDetails, true, gclog_or_tty); |
ysr@1050 | 435 | VM_GC_HeapInspection inspector(gclog_or_tty, false /* ! full gc */, false /* ! prologue */); |
ysr@1050 | 436 | inspector.doit(); |
ysr@1050 | 437 | } |
ysr@1050 | 438 | } |