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 | /* |
phh@2423 | 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 | #ifndef SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_INLINE_HPP |
stefank@2314 | 26 | #define SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_INLINE_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "gc_interface/collectedHeap.hpp" |
stefank@2314 | 29 | #include "memory/threadLocalAllocBuffer.inline.hpp" |
stefank@2314 | 30 | #include "memory/universe.hpp" |
stefank@2314 | 31 | #include "oops/arrayOop.hpp" |
stefank@2314 | 32 | #include "prims/jvmtiExport.hpp" |
stefank@2314 | 33 | #include "runtime/sharedRuntime.hpp" |
stefank@2314 | 34 | #include "runtime/thread.hpp" |
stefank@2314 | 35 | #include "services/lowMemoryDetector.hpp" |
stefank@2314 | 36 | #include "utilities/copy.hpp" |
stefank@2314 | 37 | #ifdef TARGET_OS_FAMILY_linux |
stefank@2314 | 38 | # include "thread_linux.inline.hpp" |
stefank@2314 | 39 | #endif |
stefank@2314 | 40 | #ifdef TARGET_OS_FAMILY_solaris |
stefank@2314 | 41 | # include "thread_solaris.inline.hpp" |
stefank@2314 | 42 | #endif |
stefank@2314 | 43 | #ifdef TARGET_OS_FAMILY_windows |
stefank@2314 | 44 | # include "thread_windows.inline.hpp" |
stefank@2314 | 45 | #endif |
never@3156 | 46 | #ifdef TARGET_OS_FAMILY_bsd |
never@3156 | 47 | # include "thread_bsd.inline.hpp" |
never@3156 | 48 | #endif |
stefank@2314 | 49 | |
duke@435 | 50 | // Inline allocation implementations. |
duke@435 | 51 | |
duke@435 | 52 | void CollectedHeap::post_allocation_setup_common(KlassHandle klass, |
duke@435 | 53 | HeapWord* obj, |
duke@435 | 54 | size_t size) { |
duke@435 | 55 | post_allocation_setup_no_klass_install(klass, obj, size); |
duke@435 | 56 | post_allocation_install_obj_klass(klass, oop(obj), (int) size); |
duke@435 | 57 | } |
duke@435 | 58 | |
duke@435 | 59 | void CollectedHeap::post_allocation_setup_no_klass_install(KlassHandle klass, |
duke@435 | 60 | HeapWord* objPtr, |
duke@435 | 61 | size_t size) { |
duke@435 | 62 | oop obj = (oop)objPtr; |
duke@435 | 63 | |
duke@435 | 64 | assert(obj != NULL, "NULL object pointer"); |
duke@435 | 65 | if (UseBiasedLocking && (klass() != NULL)) { |
duke@435 | 66 | obj->set_mark(klass->prototype_header()); |
duke@435 | 67 | } else { |
duke@435 | 68 | // May be bootstrapping |
duke@435 | 69 | obj->set_mark(markOopDesc::prototype()); |
duke@435 | 70 | } |
duke@435 | 71 | } |
duke@435 | 72 | |
duke@435 | 73 | void CollectedHeap::post_allocation_install_obj_klass(KlassHandle klass, |
duke@435 | 74 | oop obj, |
duke@435 | 75 | int size) { |
duke@435 | 76 | // These asserts are kind of complicated because of klassKlass |
duke@435 | 77 | // and the beginning of the world. |
duke@435 | 78 | assert(klass() != NULL || !Universe::is_fully_initialized(), "NULL klass"); |
duke@435 | 79 | assert(klass() == NULL || klass()->is_klass(), "not a klass"); |
duke@435 | 80 | assert(klass() == NULL || klass()->klass_part() != NULL, "not a klass"); |
duke@435 | 81 | assert(obj != NULL, "NULL object pointer"); |
duke@435 | 82 | obj->set_klass(klass()); |
duke@435 | 83 | assert(!Universe::is_fully_initialized() || obj->blueprint() != NULL, |
duke@435 | 84 | "missing blueprint"); |
coleenp@548 | 85 | } |
duke@435 | 86 | |
coleenp@548 | 87 | // Support for jvmti and dtrace |
coleenp@548 | 88 | inline void post_allocation_notify(KlassHandle klass, oop obj) { |
jcoomes@916 | 89 | // support low memory notifications (no-op if not enabled) |
jcoomes@916 | 90 | LowMemoryDetector::detect_low_memory_for_collected_pools(); |
jcoomes@916 | 91 | |
duke@435 | 92 | // support for JVMTI VMObjectAlloc event (no-op if not enabled) |
duke@435 | 93 | JvmtiExport::vm_object_alloc_event_collector(obj); |
duke@435 | 94 | |
duke@435 | 95 | if (DTraceAllocProbes) { |
duke@435 | 96 | // support for Dtrace object alloc event (no-op most of the time) |
duke@435 | 97 | if (klass() != NULL && klass()->klass_part()->name() != NULL) { |
duke@435 | 98 | SharedRuntime::dtrace_object_alloc(obj); |
duke@435 | 99 | } |
duke@435 | 100 | } |
duke@435 | 101 | } |
duke@435 | 102 | |
duke@435 | 103 | void CollectedHeap::post_allocation_setup_obj(KlassHandle klass, |
duke@435 | 104 | HeapWord* obj, |
duke@435 | 105 | size_t size) { |
duke@435 | 106 | post_allocation_setup_common(klass, obj, size); |
duke@435 | 107 | assert(Universe::is_bootstrapping() || |
duke@435 | 108 | !((oop)obj)->blueprint()->oop_is_array(), "must not be an array"); |
coleenp@548 | 109 | // notify jvmti and dtrace |
coleenp@548 | 110 | post_allocation_notify(klass, (oop)obj); |
duke@435 | 111 | } |
duke@435 | 112 | |
duke@435 | 113 | void CollectedHeap::post_allocation_setup_array(KlassHandle klass, |
duke@435 | 114 | HeapWord* obj, |
duke@435 | 115 | size_t size, |
duke@435 | 116 | int length) { |
coleenp@602 | 117 | // Set array length before setting the _klass field |
coleenp@602 | 118 | // in post_allocation_setup_common() because the klass field |
coleenp@602 | 119 | // indicates that the object is parsable by concurrent GC. |
duke@435 | 120 | assert(length >= 0, "length should be non-negative"); |
coleenp@602 | 121 | ((arrayOop)obj)->set_length(length); |
coleenp@548 | 122 | post_allocation_setup_common(klass, obj, size); |
duke@435 | 123 | assert(((oop)obj)->blueprint()->oop_is_array(), "must be an array"); |
coleenp@548 | 124 | // notify jvmti and dtrace (must be after length is set for dtrace) |
coleenp@548 | 125 | post_allocation_notify(klass, (oop)obj); |
duke@435 | 126 | } |
duke@435 | 127 | |
tonyp@2971 | 128 | HeapWord* CollectedHeap::common_mem_allocate_noinit(size_t size, TRAPS) { |
duke@435 | 129 | |
duke@435 | 130 | // Clear unhandled oops for memory allocation. Memory allocation might |
duke@435 | 131 | // not take out a lock if from tlab, so clear here. |
duke@435 | 132 | CHECK_UNHANDLED_OOPS_ONLY(THREAD->clear_unhandled_oops();) |
duke@435 | 133 | |
duke@435 | 134 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 135 | NOT_PRODUCT(guarantee(false, "Should not allocate with exception pending")); |
duke@435 | 136 | return NULL; // caller does a CHECK_0 too |
duke@435 | 137 | } |
duke@435 | 138 | |
duke@435 | 139 | HeapWord* result = NULL; |
duke@435 | 140 | if (UseTLAB) { |
duke@435 | 141 | result = CollectedHeap::allocate_from_tlab(THREAD, size); |
duke@435 | 142 | if (result != NULL) { |
duke@435 | 143 | assert(!HAS_PENDING_EXCEPTION, |
duke@435 | 144 | "Unexpected exception, will result in uninitialized storage"); |
duke@435 | 145 | return result; |
duke@435 | 146 | } |
duke@435 | 147 | } |
ysr@777 | 148 | bool gc_overhead_limit_was_exceeded = false; |
duke@435 | 149 | result = Universe::heap()->mem_allocate(size, |
duke@435 | 150 | &gc_overhead_limit_was_exceeded); |
duke@435 | 151 | if (result != NULL) { |
duke@435 | 152 | NOT_PRODUCT(Universe::heap()-> |
duke@435 | 153 | check_for_non_bad_heap_word_value(result, size)); |
duke@435 | 154 | assert(!HAS_PENDING_EXCEPTION, |
duke@435 | 155 | "Unexpected exception, will result in uninitialized storage"); |
phh@2423 | 156 | THREAD->incr_allocated_bytes(size * HeapWordSize); |
duke@435 | 157 | return result; |
duke@435 | 158 | } |
duke@435 | 159 | |
duke@435 | 160 | |
duke@435 | 161 | if (!gc_overhead_limit_was_exceeded) { |
duke@435 | 162 | // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support |
duke@435 | 163 | report_java_out_of_memory("Java heap space"); |
duke@435 | 164 | |
duke@435 | 165 | if (JvmtiExport::should_post_resource_exhausted()) { |
duke@435 | 166 | JvmtiExport::post_resource_exhausted( |
duke@435 | 167 | JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP, |
duke@435 | 168 | "Java heap space"); |
duke@435 | 169 | } |
duke@435 | 170 | |
duke@435 | 171 | THROW_OOP_0(Universe::out_of_memory_error_java_heap()); |
duke@435 | 172 | } else { |
duke@435 | 173 | // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support |
duke@435 | 174 | report_java_out_of_memory("GC overhead limit exceeded"); |
duke@435 | 175 | |
duke@435 | 176 | if (JvmtiExport::should_post_resource_exhausted()) { |
duke@435 | 177 | JvmtiExport::post_resource_exhausted( |
duke@435 | 178 | JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP, |
duke@435 | 179 | "GC overhead limit exceeded"); |
duke@435 | 180 | } |
duke@435 | 181 | |
duke@435 | 182 | THROW_OOP_0(Universe::out_of_memory_error_gc_overhead_limit()); |
duke@435 | 183 | } |
duke@435 | 184 | } |
duke@435 | 185 | |
tonyp@2971 | 186 | HeapWord* CollectedHeap::common_mem_allocate_init(size_t size, TRAPS) { |
tonyp@2971 | 187 | HeapWord* obj = common_mem_allocate_noinit(size, CHECK_NULL); |
duke@435 | 188 | init_obj(obj, size); |
duke@435 | 189 | return obj; |
duke@435 | 190 | } |
duke@435 | 191 | |
duke@435 | 192 | // Need to investigate, do we really want to throw OOM exception here? |
duke@435 | 193 | HeapWord* CollectedHeap::common_permanent_mem_allocate_noinit(size_t size, TRAPS) { |
duke@435 | 194 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 195 | NOT_PRODUCT(guarantee(false, "Should not allocate with exception pending")); |
duke@435 | 196 | return NULL; // caller does a CHECK_NULL too |
duke@435 | 197 | } |
duke@435 | 198 | |
duke@435 | 199 | #ifdef ASSERT |
duke@435 | 200 | if (CIFireOOMAt > 0 && THREAD->is_Compiler_thread() && |
duke@435 | 201 | ++_fire_out_of_memory_count >= CIFireOOMAt) { |
duke@435 | 202 | // For testing of OOM handling in the CI throw an OOM and see how |
duke@435 | 203 | // it does. Historically improper handling of these has resulted |
duke@435 | 204 | // in crashes which we really don't want to have in the CI. |
duke@435 | 205 | THROW_OOP_0(Universe::out_of_memory_error_perm_gen()); |
duke@435 | 206 | } |
duke@435 | 207 | #endif |
duke@435 | 208 | |
duke@435 | 209 | HeapWord* result = Universe::heap()->permanent_mem_allocate(size); |
duke@435 | 210 | if (result != NULL) { |
duke@435 | 211 | NOT_PRODUCT(Universe::heap()-> |
duke@435 | 212 | check_for_non_bad_heap_word_value(result, size)); |
duke@435 | 213 | assert(!HAS_PENDING_EXCEPTION, |
duke@435 | 214 | "Unexpected exception, will result in uninitialized storage"); |
duke@435 | 215 | return result; |
duke@435 | 216 | } |
duke@435 | 217 | // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support |
duke@435 | 218 | report_java_out_of_memory("PermGen space"); |
duke@435 | 219 | |
duke@435 | 220 | if (JvmtiExport::should_post_resource_exhausted()) { |
duke@435 | 221 | JvmtiExport::post_resource_exhausted( |
duke@435 | 222 | JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR, |
duke@435 | 223 | "PermGen space"); |
duke@435 | 224 | } |
duke@435 | 225 | |
duke@435 | 226 | THROW_OOP_0(Universe::out_of_memory_error_perm_gen()); |
duke@435 | 227 | } |
duke@435 | 228 | |
duke@435 | 229 | HeapWord* CollectedHeap::common_permanent_mem_allocate_init(size_t size, TRAPS) { |
duke@435 | 230 | HeapWord* obj = common_permanent_mem_allocate_noinit(size, CHECK_NULL); |
duke@435 | 231 | init_obj(obj, size); |
duke@435 | 232 | return obj; |
duke@435 | 233 | } |
duke@435 | 234 | |
duke@435 | 235 | HeapWord* CollectedHeap::allocate_from_tlab(Thread* thread, size_t size) { |
duke@435 | 236 | assert(UseTLAB, "should use UseTLAB"); |
duke@435 | 237 | |
duke@435 | 238 | HeapWord* obj = thread->tlab().allocate(size); |
duke@435 | 239 | if (obj != NULL) { |
duke@435 | 240 | return obj; |
duke@435 | 241 | } |
duke@435 | 242 | // Otherwise... |
duke@435 | 243 | return allocate_from_tlab_slow(thread, size); |
duke@435 | 244 | } |
duke@435 | 245 | |
duke@435 | 246 | void CollectedHeap::init_obj(HeapWord* obj, size_t size) { |
duke@435 | 247 | assert(obj != NULL, "cannot initialize NULL object"); |
duke@435 | 248 | const size_t hs = oopDesc::header_size(); |
duke@435 | 249 | assert(size >= hs, "unexpected object size"); |
coleenp@602 | 250 | ((oop)obj)->set_klass_gap(0); |
duke@435 | 251 | Copy::fill_to_aligned_words(obj + hs, size - hs); |
duke@435 | 252 | } |
duke@435 | 253 | |
duke@435 | 254 | oop CollectedHeap::obj_allocate(KlassHandle klass, int size, TRAPS) { |
duke@435 | 255 | debug_only(check_for_valid_allocation_state()); |
duke@435 | 256 | assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
duke@435 | 257 | assert(size >= 0, "int won't convert to size_t"); |
tonyp@2971 | 258 | HeapWord* obj = common_mem_allocate_init(size, CHECK_NULL); |
duke@435 | 259 | post_allocation_setup_obj(klass, obj, size); |
duke@435 | 260 | NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); |
duke@435 | 261 | return (oop)obj; |
duke@435 | 262 | } |
duke@435 | 263 | |
duke@435 | 264 | oop CollectedHeap::array_allocate(KlassHandle klass, |
duke@435 | 265 | int size, |
duke@435 | 266 | int length, |
duke@435 | 267 | TRAPS) { |
duke@435 | 268 | debug_only(check_for_valid_allocation_state()); |
duke@435 | 269 | assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
duke@435 | 270 | assert(size >= 0, "int won't convert to size_t"); |
tonyp@2971 | 271 | HeapWord* obj = common_mem_allocate_init(size, CHECK_NULL); |
duke@435 | 272 | post_allocation_setup_array(klass, obj, size, length); |
duke@435 | 273 | NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); |
duke@435 | 274 | return (oop)obj; |
duke@435 | 275 | } |
duke@435 | 276 | |
kvn@3157 | 277 | oop CollectedHeap::array_allocate_nozero(KlassHandle klass, |
kvn@3157 | 278 | int size, |
kvn@3157 | 279 | int length, |
kvn@3157 | 280 | TRAPS) { |
kvn@3157 | 281 | debug_only(check_for_valid_allocation_state()); |
kvn@3157 | 282 | assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
kvn@3157 | 283 | assert(size >= 0, "int won't convert to size_t"); |
kvn@3157 | 284 | HeapWord* obj = common_mem_allocate_noinit(size, CHECK_NULL); |
kvn@3157 | 285 | ((oop)obj)->set_klass_gap(0); |
kvn@3157 | 286 | post_allocation_setup_array(klass, obj, size, length); |
kvn@3157 | 287 | #ifndef PRODUCT |
kvn@3157 | 288 | const size_t hs = oopDesc::header_size()+1; |
kvn@3157 | 289 | Universe::heap()->check_for_non_bad_heap_word_value(obj+hs, size-hs); |
kvn@3157 | 290 | #endif |
kvn@3157 | 291 | return (oop)obj; |
kvn@3157 | 292 | } |
kvn@3157 | 293 | |
duke@435 | 294 | oop CollectedHeap::permanent_obj_allocate(KlassHandle klass, int size, TRAPS) { |
duke@435 | 295 | oop obj = permanent_obj_allocate_no_klass_install(klass, size, CHECK_NULL); |
duke@435 | 296 | post_allocation_install_obj_klass(klass, obj, size); |
duke@435 | 297 | NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value((HeapWord*) obj, |
duke@435 | 298 | size)); |
duke@435 | 299 | return obj; |
duke@435 | 300 | } |
duke@435 | 301 | |
duke@435 | 302 | oop CollectedHeap::permanent_obj_allocate_no_klass_install(KlassHandle klass, |
duke@435 | 303 | int size, |
duke@435 | 304 | TRAPS) { |
duke@435 | 305 | debug_only(check_for_valid_allocation_state()); |
duke@435 | 306 | assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
duke@435 | 307 | assert(size >= 0, "int won't convert to size_t"); |
duke@435 | 308 | HeapWord* obj = common_permanent_mem_allocate_init(size, CHECK_NULL); |
duke@435 | 309 | post_allocation_setup_no_klass_install(klass, obj, size); |
kvn@3092 | 310 | #ifndef PRODUCT |
kvn@3092 | 311 | const size_t hs = oopDesc::header_size(); |
kvn@3092 | 312 | Universe::heap()->check_for_bad_heap_word_value(obj+hs, size-hs); |
kvn@3092 | 313 | #endif |
duke@435 | 314 | return (oop)obj; |
duke@435 | 315 | } |
duke@435 | 316 | |
duke@435 | 317 | oop CollectedHeap::permanent_array_allocate(KlassHandle klass, |
duke@435 | 318 | int size, |
duke@435 | 319 | int length, |
duke@435 | 320 | TRAPS) { |
duke@435 | 321 | debug_only(check_for_valid_allocation_state()); |
duke@435 | 322 | assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
duke@435 | 323 | assert(size >= 0, "int won't convert to size_t"); |
duke@435 | 324 | HeapWord* obj = common_permanent_mem_allocate_init(size, CHECK_NULL); |
duke@435 | 325 | post_allocation_setup_array(klass, obj, size, length); |
duke@435 | 326 | NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); |
duke@435 | 327 | return (oop)obj; |
duke@435 | 328 | } |
duke@435 | 329 | |
duke@435 | 330 | // Returns "TRUE" if "p" is a method oop in the |
duke@435 | 331 | // current heap with high probability. NOTE: The main |
duke@435 | 332 | // current consumers of this interface are Forte:: |
duke@435 | 333 | // and ThreadProfiler::. In these cases, the |
duke@435 | 334 | // interpreter frame from which "p" came, may be |
duke@435 | 335 | // under construction when sampled asynchronously, so |
duke@435 | 336 | // the clients want to check that it represents a |
duke@435 | 337 | // valid method before using it. Nonetheless since |
duke@435 | 338 | // the clients do not typically lock out GC, the |
duke@435 | 339 | // predicate is_valid_method() is not stable, so |
duke@435 | 340 | // it is possible that by the time "p" is used, it |
duke@435 | 341 | // is no longer valid. |
duke@435 | 342 | inline bool CollectedHeap::is_valid_method(oop p) const { |
duke@435 | 343 | return |
duke@435 | 344 | p != NULL && |
duke@435 | 345 | |
duke@435 | 346 | // Check whether it is aligned at a HeapWord boundary. |
duke@435 | 347 | Space::is_aligned(p) && |
duke@435 | 348 | |
duke@435 | 349 | // Check whether "method" is in the allocated part of the |
duke@435 | 350 | // permanent generation -- this needs to be checked before |
duke@435 | 351 | // p->klass() below to avoid a SEGV (but see below |
duke@435 | 352 | // for a potential window of vulnerability). |
duke@435 | 353 | is_permanent((void*)p) && |
duke@435 | 354 | |
duke@435 | 355 | // See if GC is active; however, there is still an |
duke@435 | 356 | // apparently unavoidable window after this call |
duke@435 | 357 | // and before the client of this interface uses "p". |
duke@435 | 358 | // If the client chooses not to lock out GC, then |
duke@435 | 359 | // it's a risk the client must accept. |
duke@435 | 360 | !is_gc_active() && |
duke@435 | 361 | |
duke@435 | 362 | // Check that p is a methodOop. |
duke@435 | 363 | p->klass() == Universe::methodKlassObj(); |
duke@435 | 364 | } |
duke@435 | 365 | |
duke@435 | 366 | |
duke@435 | 367 | #ifndef PRODUCT |
duke@435 | 368 | |
duke@435 | 369 | inline bool |
duke@435 | 370 | CollectedHeap::promotion_should_fail(volatile size_t* count) { |
duke@435 | 371 | // Access to count is not atomic; the value does not have to be exact. |
duke@435 | 372 | if (PromotionFailureALot) { |
duke@435 | 373 | const size_t gc_num = total_collections(); |
duke@435 | 374 | const size_t elapsed_gcs = gc_num - _promotion_failure_alot_gc_number; |
duke@435 | 375 | if (elapsed_gcs >= PromotionFailureALotInterval) { |
duke@435 | 376 | // Test for unsigned arithmetic wrap-around. |
duke@435 | 377 | if (++*count >= PromotionFailureALotCount) { |
duke@435 | 378 | *count = 0; |
duke@435 | 379 | return true; |
duke@435 | 380 | } |
duke@435 | 381 | } |
duke@435 | 382 | } |
duke@435 | 383 | return false; |
duke@435 | 384 | } |
duke@435 | 385 | |
duke@435 | 386 | inline bool CollectedHeap::promotion_should_fail() { |
duke@435 | 387 | return promotion_should_fail(&_promotion_failure_alot_count); |
duke@435 | 388 | } |
duke@435 | 389 | |
duke@435 | 390 | inline void CollectedHeap::reset_promotion_should_fail(volatile size_t* count) { |
duke@435 | 391 | if (PromotionFailureALot) { |
duke@435 | 392 | _promotion_failure_alot_gc_number = total_collections(); |
duke@435 | 393 | *count = 0; |
duke@435 | 394 | } |
duke@435 | 395 | } |
duke@435 | 396 | |
duke@435 | 397 | inline void CollectedHeap::reset_promotion_should_fail() { |
duke@435 | 398 | reset_promotion_should_fail(&_promotion_failure_alot_count); |
duke@435 | 399 | } |
duke@435 | 400 | #endif // #ifndef PRODUCT |
stefank@2314 | 401 | |
stefank@2314 | 402 | #endif // SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_INLINE_HPP |