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

Wed, 26 Mar 2014 14:15:02 +0100

author
ehelin
date
Wed, 26 Mar 2014 14:15:02 +0100
changeset 6608
fa21c9537e6e
parent 6198
55fb97c4c58d
child 6627
cf9f24de0b93
permissions
-rw-r--r--

8035667: EventMetaspaceSummary doesn't report committed Metaspace memory
Reviewed-by: jmasa, stefank

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

mercurial