src/share/vm/gc_interface/collectedHeap.inline.hpp

Thu, 16 Jun 2011 15:51:57 -0400

author
tonyp
date
Thu, 16 Jun 2011 15:51:57 -0400
changeset 2971
c9ca3f51cf41
parent 2423
b1a2afa37ec4
child 3092
baf763f388e6
permissions
-rw-r--r--

6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
Summary: Remove two unused parameters from the mem_allocate() method and update its uses accordingly.
Reviewed-by: stefank, johnc

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

mercurial