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

Wed, 13 Mar 2013 15:15:56 -0400

author
coleenp
date
Wed, 13 Mar 2013 15:15:56 -0400
changeset 4718
0ede345ec7c9
parent 4301
c24f778e9401
child 5237
f2110083203d
permissions
-rw-r--r--

8009829: CDS: JDK JPRT test fails crash in Symbol::equals()
Summary: -Xshare:dump was creating a Symbol in C_heap. There's an assert there that jdk jprt wasn't hitting because it was only done in product
Reviewed-by: dholmes, hseigel, iklam

duke@435 1 /*
brutisso@3675 2 * Copyright (c) 2001, 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_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@4299 34 #include "runtime/thread.inline.hpp"
stefank@2314 35 #include "services/lowMemoryDetector.hpp"
stefank@2314 36 #include "utilities/copy.hpp"
stefank@2314 37
duke@435 38 // Inline allocation implementations.
duke@435 39
duke@435 40 void CollectedHeap::post_allocation_setup_common(KlassHandle klass,
brutisso@3675 41 HeapWord* obj) {
brutisso@3675 42 post_allocation_setup_no_klass_install(klass, obj);
brutisso@3675 43 post_allocation_install_obj_klass(klass, oop(obj));
duke@435 44 }
duke@435 45
duke@435 46 void CollectedHeap::post_allocation_setup_no_klass_install(KlassHandle klass,
brutisso@3675 47 HeapWord* objPtr) {
duke@435 48 oop obj = (oop)objPtr;
duke@435 49
duke@435 50 assert(obj != NULL, "NULL object pointer");
duke@435 51 if (UseBiasedLocking && (klass() != NULL)) {
duke@435 52 obj->set_mark(klass->prototype_header());
duke@435 53 } else {
duke@435 54 // May be bootstrapping
duke@435 55 obj->set_mark(markOopDesc::prototype());
duke@435 56 }
duke@435 57 }
duke@435 58
duke@435 59 void CollectedHeap::post_allocation_install_obj_klass(KlassHandle klass,
brutisso@3675 60 oop obj) {
duke@435 61 // These asserts are kind of complicated because of klassKlass
duke@435 62 // and the beginning of the world.
duke@435 63 assert(klass() != NULL || !Universe::is_fully_initialized(), "NULL klass");
duke@435 64 assert(klass() == NULL || klass()->is_klass(), "not a klass");
duke@435 65 assert(obj != NULL, "NULL object pointer");
duke@435 66 obj->set_klass(klass());
coleenp@4037 67 assert(!Universe::is_fully_initialized() || obj->klass() != NULL,
coleenp@4037 68 "missing klass");
coleenp@548 69 }
duke@435 70
coleenp@548 71 // Support for jvmti and dtrace
coleenp@548 72 inline void post_allocation_notify(KlassHandle klass, oop obj) {
jcoomes@916 73 // support low memory notifications (no-op if not enabled)
jcoomes@916 74 LowMemoryDetector::detect_low_memory_for_collected_pools();
jcoomes@916 75
duke@435 76 // support for JVMTI VMObjectAlloc event (no-op if not enabled)
duke@435 77 JvmtiExport::vm_object_alloc_event_collector(obj);
duke@435 78
duke@435 79 if (DTraceAllocProbes) {
duke@435 80 // support for Dtrace object alloc event (no-op most of the time)
coleenp@4037 81 if (klass() != NULL && klass()->name() != NULL) {
duke@435 82 SharedRuntime::dtrace_object_alloc(obj);
duke@435 83 }
duke@435 84 }
duke@435 85 }
duke@435 86
duke@435 87 void CollectedHeap::post_allocation_setup_obj(KlassHandle klass,
brutisso@3675 88 HeapWord* obj) {
brutisso@3675 89 post_allocation_setup_common(klass, obj);
duke@435 90 assert(Universe::is_bootstrapping() ||
coleenp@4037 91 !((oop)obj)->is_array(), "must not be an array");
coleenp@548 92 // notify jvmti and dtrace
coleenp@548 93 post_allocation_notify(klass, (oop)obj);
duke@435 94 }
duke@435 95
duke@435 96 void CollectedHeap::post_allocation_setup_array(KlassHandle klass,
duke@435 97 HeapWord* obj,
duke@435 98 int length) {
coleenp@602 99 // Set array length before setting the _klass field
coleenp@602 100 // in post_allocation_setup_common() because the klass field
coleenp@602 101 // indicates that the object is parsable by concurrent GC.
duke@435 102 assert(length >= 0, "length should be non-negative");
coleenp@602 103 ((arrayOop)obj)->set_length(length);
brutisso@3675 104 post_allocation_setup_common(klass, obj);
coleenp@4037 105 assert(((oop)obj)->is_array(), "must be an array");
coleenp@548 106 // notify jvmti and dtrace (must be after length is set for dtrace)
coleenp@548 107 post_allocation_notify(klass, (oop)obj);
duke@435 108 }
duke@435 109
tonyp@2971 110 HeapWord* CollectedHeap::common_mem_allocate_noinit(size_t size, TRAPS) {
duke@435 111
duke@435 112 // Clear unhandled oops for memory allocation. Memory allocation might
duke@435 113 // not take out a lock if from tlab, so clear here.
duke@435 114 CHECK_UNHANDLED_OOPS_ONLY(THREAD->clear_unhandled_oops();)
duke@435 115
duke@435 116 if (HAS_PENDING_EXCEPTION) {
duke@435 117 NOT_PRODUCT(guarantee(false, "Should not allocate with exception pending"));
duke@435 118 return NULL; // caller does a CHECK_0 too
duke@435 119 }
duke@435 120
duke@435 121 HeapWord* result = NULL;
duke@435 122 if (UseTLAB) {
duke@435 123 result = CollectedHeap::allocate_from_tlab(THREAD, size);
duke@435 124 if (result != NULL) {
duke@435 125 assert(!HAS_PENDING_EXCEPTION,
duke@435 126 "Unexpected exception, will result in uninitialized storage");
duke@435 127 return result;
duke@435 128 }
duke@435 129 }
ysr@777 130 bool gc_overhead_limit_was_exceeded = false;
duke@435 131 result = Universe::heap()->mem_allocate(size,
duke@435 132 &gc_overhead_limit_was_exceeded);
duke@435 133 if (result != NULL) {
duke@435 134 NOT_PRODUCT(Universe::heap()->
duke@435 135 check_for_non_bad_heap_word_value(result, size));
duke@435 136 assert(!HAS_PENDING_EXCEPTION,
duke@435 137 "Unexpected exception, will result in uninitialized storage");
phh@2423 138 THREAD->incr_allocated_bytes(size * HeapWordSize);
duke@435 139 return result;
duke@435 140 }
duke@435 141
duke@435 142
duke@435 143 if (!gc_overhead_limit_was_exceeded) {
duke@435 144 // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
duke@435 145 report_java_out_of_memory("Java heap space");
duke@435 146
duke@435 147 if (JvmtiExport::should_post_resource_exhausted()) {
duke@435 148 JvmtiExport::post_resource_exhausted(
duke@435 149 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP,
duke@435 150 "Java heap space");
duke@435 151 }
duke@435 152
duke@435 153 THROW_OOP_0(Universe::out_of_memory_error_java_heap());
duke@435 154 } else {
duke@435 155 // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
duke@435 156 report_java_out_of_memory("GC overhead limit exceeded");
duke@435 157
duke@435 158 if (JvmtiExport::should_post_resource_exhausted()) {
duke@435 159 JvmtiExport::post_resource_exhausted(
duke@435 160 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP,
duke@435 161 "GC overhead limit exceeded");
duke@435 162 }
duke@435 163
duke@435 164 THROW_OOP_0(Universe::out_of_memory_error_gc_overhead_limit());
duke@435 165 }
duke@435 166 }
duke@435 167
tonyp@2971 168 HeapWord* CollectedHeap::common_mem_allocate_init(size_t size, TRAPS) {
tonyp@2971 169 HeapWord* obj = common_mem_allocate_noinit(size, CHECK_NULL);
duke@435 170 init_obj(obj, size);
duke@435 171 return obj;
duke@435 172 }
duke@435 173
duke@435 174 HeapWord* CollectedHeap::allocate_from_tlab(Thread* thread, size_t size) {
duke@435 175 assert(UseTLAB, "should use UseTLAB");
duke@435 176
duke@435 177 HeapWord* obj = thread->tlab().allocate(size);
duke@435 178 if (obj != NULL) {
duke@435 179 return obj;
duke@435 180 }
duke@435 181 // Otherwise...
duke@435 182 return allocate_from_tlab_slow(thread, size);
duke@435 183 }
duke@435 184
duke@435 185 void CollectedHeap::init_obj(HeapWord* obj, size_t size) {
duke@435 186 assert(obj != NULL, "cannot initialize NULL object");
duke@435 187 const size_t hs = oopDesc::header_size();
duke@435 188 assert(size >= hs, "unexpected object size");
coleenp@602 189 ((oop)obj)->set_klass_gap(0);
duke@435 190 Copy::fill_to_aligned_words(obj + hs, size - hs);
duke@435 191 }
duke@435 192
duke@435 193 oop CollectedHeap::obj_allocate(KlassHandle klass, int size, TRAPS) {
duke@435 194 debug_only(check_for_valid_allocation_state());
duke@435 195 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
duke@435 196 assert(size >= 0, "int won't convert to size_t");
tonyp@2971 197 HeapWord* obj = common_mem_allocate_init(size, CHECK_NULL);
brutisso@3675 198 post_allocation_setup_obj(klass, obj);
duke@435 199 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size));
duke@435 200 return (oop)obj;
duke@435 201 }
duke@435 202
duke@435 203 oop CollectedHeap::array_allocate(KlassHandle klass,
duke@435 204 int size,
duke@435 205 int length,
duke@435 206 TRAPS) {
duke@435 207 debug_only(check_for_valid_allocation_state());
duke@435 208 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
duke@435 209 assert(size >= 0, "int won't convert to size_t");
tonyp@2971 210 HeapWord* obj = common_mem_allocate_init(size, CHECK_NULL);
brutisso@3675 211 post_allocation_setup_array(klass, obj, length);
duke@435 212 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size));
duke@435 213 return (oop)obj;
duke@435 214 }
duke@435 215
kvn@3157 216 oop CollectedHeap::array_allocate_nozero(KlassHandle klass,
kvn@3157 217 int size,
kvn@3157 218 int length,
kvn@3157 219 TRAPS) {
kvn@3157 220 debug_only(check_for_valid_allocation_state());
kvn@3157 221 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
kvn@3157 222 assert(size >= 0, "int won't convert to size_t");
kvn@3157 223 HeapWord* obj = common_mem_allocate_noinit(size, CHECK_NULL);
kvn@3157 224 ((oop)obj)->set_klass_gap(0);
brutisso@3675 225 post_allocation_setup_array(klass, obj, length);
kvn@3157 226 #ifndef PRODUCT
kvn@3157 227 const size_t hs = oopDesc::header_size()+1;
kvn@3157 228 Universe::heap()->check_for_non_bad_heap_word_value(obj+hs, size-hs);
kvn@3157 229 #endif
kvn@3157 230 return (oop)obj;
kvn@3157 231 }
kvn@3157 232
coleenp@4037 233 inline void CollectedHeap::oop_iterate_no_header(OopClosure* cl) {
coleenp@4037 234 NoHeaderExtendedOopClosure no_header_cl(cl);
coleenp@4037 235 oop_iterate(&no_header_cl);
coleenp@4037 236 }
duke@435 237
duke@435 238 #ifndef PRODUCT
duke@435 239
duke@435 240 inline bool
duke@435 241 CollectedHeap::promotion_should_fail(volatile size_t* count) {
duke@435 242 // Access to count is not atomic; the value does not have to be exact.
duke@435 243 if (PromotionFailureALot) {
duke@435 244 const size_t gc_num = total_collections();
duke@435 245 const size_t elapsed_gcs = gc_num - _promotion_failure_alot_gc_number;
duke@435 246 if (elapsed_gcs >= PromotionFailureALotInterval) {
duke@435 247 // Test for unsigned arithmetic wrap-around.
duke@435 248 if (++*count >= PromotionFailureALotCount) {
duke@435 249 *count = 0;
duke@435 250 return true;
duke@435 251 }
duke@435 252 }
duke@435 253 }
duke@435 254 return false;
duke@435 255 }
duke@435 256
duke@435 257 inline bool CollectedHeap::promotion_should_fail() {
duke@435 258 return promotion_should_fail(&_promotion_failure_alot_count);
duke@435 259 }
duke@435 260
duke@435 261 inline void CollectedHeap::reset_promotion_should_fail(volatile size_t* count) {
duke@435 262 if (PromotionFailureALot) {
duke@435 263 _promotion_failure_alot_gc_number = total_collections();
duke@435 264 *count = 0;
duke@435 265 }
duke@435 266 }
duke@435 267
duke@435 268 inline void CollectedHeap::reset_promotion_should_fail() {
duke@435 269 reset_promotion_should_fail(&_promotion_failure_alot_count);
duke@435 270 }
duke@435 271 #endif // #ifndef PRODUCT
stefank@2314 272
stefank@2314 273 #endif // SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_INLINE_HPP

mercurial