2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2012-03-27 10:29:59 +02:00
|
|
|
* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#ifndef SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_INLINE_HPP
|
|
|
|
#define SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_INLINE_HPP
|
|
|
|
|
|
|
|
#include "gc_interface/collectedHeap.hpp"
|
|
|
|
#include "memory/threadLocalAllocBuffer.inline.hpp"
|
|
|
|
#include "memory/universe.hpp"
|
|
|
|
#include "oops/arrayOop.hpp"
|
|
|
|
#include "prims/jvmtiExport.hpp"
|
|
|
|
#include "runtime/sharedRuntime.hpp"
|
2012-11-27 14:20:21 +01:00
|
|
|
#include "runtime/thread.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "services/lowMemoryDetector.hpp"
|
|
|
|
#include "utilities/copy.hpp"
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Inline allocation implementations.
|
|
|
|
|
|
|
|
void CollectedHeap::post_allocation_setup_common(KlassHandle klass,
|
2012-03-27 10:29:59 +02:00
|
|
|
HeapWord* obj) {
|
|
|
|
post_allocation_setup_no_klass_install(klass, obj);
|
|
|
|
post_allocation_install_obj_klass(klass, oop(obj));
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectedHeap::post_allocation_setup_no_klass_install(KlassHandle klass,
|
2012-03-27 10:29:59 +02:00
|
|
|
HeapWord* objPtr) {
|
2007-12-01 00:00:00 +00:00
|
|
|
oop obj = (oop)objPtr;
|
|
|
|
|
|
|
|
assert(obj != NULL, "NULL object pointer");
|
|
|
|
if (UseBiasedLocking && (klass() != NULL)) {
|
|
|
|
obj->set_mark(klass->prototype_header());
|
|
|
|
} else {
|
|
|
|
// May be bootstrapping
|
|
|
|
obj->set_mark(markOopDesc::prototype());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectedHeap::post_allocation_install_obj_klass(KlassHandle klass,
|
2012-03-27 10:29:59 +02:00
|
|
|
oop obj) {
|
2007-12-01 00:00:00 +00:00
|
|
|
// These asserts are kind of complicated because of klassKlass
|
|
|
|
// and the beginning of the world.
|
|
|
|
assert(klass() != NULL || !Universe::is_fully_initialized(), "NULL klass");
|
|
|
|
assert(klass() == NULL || klass()->is_klass(), "not a klass");
|
|
|
|
assert(obj != NULL, "NULL object pointer");
|
|
|
|
obj->set_klass(klass());
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
assert(!Universe::is_fully_initialized() || obj->klass() != NULL,
|
|
|
|
"missing klass");
|
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
2008-04-13 17:43:42 -04:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
2008-04-13 17:43:42 -04:00
|
|
|
// Support for jvmti and dtrace
|
|
|
|
inline void post_allocation_notify(KlassHandle klass, oop obj) {
|
2008-12-11 12:05:08 -08:00
|
|
|
// support low memory notifications (no-op if not enabled)
|
|
|
|
LowMemoryDetector::detect_low_memory_for_collected_pools();
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// support for JVMTI VMObjectAlloc event (no-op if not enabled)
|
|
|
|
JvmtiExport::vm_object_alloc_event_collector(obj);
|
|
|
|
|
|
|
|
if (DTraceAllocProbes) {
|
|
|
|
// support for Dtrace object alloc event (no-op most of the time)
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
if (klass() != NULL && klass()->name() != NULL) {
|
2007-12-01 00:00:00 +00:00
|
|
|
SharedRuntime::dtrace_object_alloc(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectedHeap::post_allocation_setup_obj(KlassHandle klass,
|
2012-03-27 10:29:59 +02:00
|
|
|
HeapWord* obj) {
|
|
|
|
post_allocation_setup_common(klass, obj);
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(Universe::is_bootstrapping() ||
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
!((oop)obj)->is_array(), "must not be an array");
|
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
2008-04-13 17:43:42 -04:00
|
|
|
// notify jvmti and dtrace
|
|
|
|
post_allocation_notify(klass, (oop)obj);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectedHeap::post_allocation_setup_array(KlassHandle klass,
|
|
|
|
HeapWord* obj,
|
|
|
|
int length) {
|
2008-05-28 21:06:24 -07:00
|
|
|
// Set array length before setting the _klass field
|
|
|
|
// in post_allocation_setup_common() because the klass field
|
|
|
|
// indicates that the object is parsable by concurrent GC.
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(length >= 0, "length should be non-negative");
|
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
2008-04-13 17:43:42 -04:00
|
|
|
((arrayOop)obj)->set_length(length);
|
2012-03-27 10:29:59 +02:00
|
|
|
post_allocation_setup_common(klass, obj);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
assert(((oop)obj)->is_array(), "must be an array");
|
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
2008-04-13 17:43:42 -04:00
|
|
|
// notify jvmti and dtrace (must be after length is set for dtrace)
|
|
|
|
post_allocation_notify(klass, (oop)obj);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 15:51:57 -04:00
|
|
|
HeapWord* CollectedHeap::common_mem_allocate_noinit(size_t size, TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Clear unhandled oops for memory allocation. Memory allocation might
|
|
|
|
// not take out a lock if from tlab, so clear here.
|
|
|
|
CHECK_UNHANDLED_OOPS_ONLY(THREAD->clear_unhandled_oops();)
|
|
|
|
|
|
|
|
if (HAS_PENDING_EXCEPTION) {
|
|
|
|
NOT_PRODUCT(guarantee(false, "Should not allocate with exception pending"));
|
|
|
|
return NULL; // caller does a CHECK_0 too
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapWord* result = NULL;
|
|
|
|
if (UseTLAB) {
|
|
|
|
result = CollectedHeap::allocate_from_tlab(THREAD, size);
|
|
|
|
if (result != NULL) {
|
|
|
|
assert(!HAS_PENDING_EXCEPTION,
|
|
|
|
"Unexpected exception, will result in uninitialized storage");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2008-06-05 15:57:56 -07:00
|
|
|
bool gc_overhead_limit_was_exceeded = false;
|
2007-12-01 00:00:00 +00:00
|
|
|
result = Universe::heap()->mem_allocate(size,
|
|
|
|
&gc_overhead_limit_was_exceeded);
|
|
|
|
if (result != NULL) {
|
|
|
|
NOT_PRODUCT(Universe::heap()->
|
|
|
|
check_for_non_bad_heap_word_value(result, size));
|
|
|
|
assert(!HAS_PENDING_EXCEPTION,
|
|
|
|
"Unexpected exception, will result in uninitialized storage");
|
2011-01-07 10:42:32 -05:00
|
|
|
THREAD->incr_allocated_bytes(size * HeapWordSize);
|
2007-12-01 00:00:00 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!gc_overhead_limit_was_exceeded) {
|
|
|
|
// -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
|
|
|
|
report_java_out_of_memory("Java heap space");
|
|
|
|
|
|
|
|
if (JvmtiExport::should_post_resource_exhausted()) {
|
|
|
|
JvmtiExport::post_resource_exhausted(
|
|
|
|
JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP,
|
|
|
|
"Java heap space");
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_OOP_0(Universe::out_of_memory_error_java_heap());
|
|
|
|
} else {
|
|
|
|
// -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
|
|
|
|
report_java_out_of_memory("GC overhead limit exceeded");
|
|
|
|
|
|
|
|
if (JvmtiExport::should_post_resource_exhausted()) {
|
|
|
|
JvmtiExport::post_resource_exhausted(
|
|
|
|
JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP,
|
|
|
|
"GC overhead limit exceeded");
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_OOP_0(Universe::out_of_memory_error_gc_overhead_limit());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-16 15:51:57 -04:00
|
|
|
HeapWord* CollectedHeap::common_mem_allocate_init(size_t size, TRAPS) {
|
|
|
|
HeapWord* obj = common_mem_allocate_noinit(size, CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
init_obj(obj, size);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapWord* CollectedHeap::allocate_from_tlab(Thread* thread, size_t size) {
|
|
|
|
assert(UseTLAB, "should use UseTLAB");
|
|
|
|
|
|
|
|
HeapWord* obj = thread->tlab().allocate(size);
|
|
|
|
if (obj != NULL) {
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
// Otherwise...
|
|
|
|
return allocate_from_tlab_slow(thread, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectedHeap::init_obj(HeapWord* obj, size_t size) {
|
|
|
|
assert(obj != NULL, "cannot initialize NULL object");
|
|
|
|
const size_t hs = oopDesc::header_size();
|
|
|
|
assert(size >= hs, "unexpected object size");
|
2008-05-28 21:06:24 -07:00
|
|
|
((oop)obj)->set_klass_gap(0);
|
2007-12-01 00:00:00 +00:00
|
|
|
Copy::fill_to_aligned_words(obj + hs, size - hs);
|
|
|
|
}
|
|
|
|
|
|
|
|
oop CollectedHeap::obj_allocate(KlassHandle klass, int size, TRAPS) {
|
|
|
|
debug_only(check_for_valid_allocation_state());
|
|
|
|
assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
|
|
|
|
assert(size >= 0, "int won't convert to size_t");
|
2011-06-16 15:51:57 -04:00
|
|
|
HeapWord* obj = common_mem_allocate_init(size, CHECK_NULL);
|
2012-03-27 10:29:59 +02:00
|
|
|
post_allocation_setup_obj(klass, obj);
|
2007-12-01 00:00:00 +00:00
|
|
|
NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size));
|
|
|
|
return (oop)obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
oop CollectedHeap::array_allocate(KlassHandle klass,
|
|
|
|
int size,
|
|
|
|
int length,
|
|
|
|
TRAPS) {
|
|
|
|
debug_only(check_for_valid_allocation_state());
|
|
|
|
assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
|
|
|
|
assert(size >= 0, "int won't convert to size_t");
|
2011-06-16 15:51:57 -04:00
|
|
|
HeapWord* obj = common_mem_allocate_init(size, CHECK_NULL);
|
2012-03-27 10:29:59 +02:00
|
|
|
post_allocation_setup_array(klass, obj, length);
|
2007-12-01 00:00:00 +00:00
|
|
|
NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size));
|
|
|
|
return (oop)obj;
|
|
|
|
}
|
|
|
|
|
2011-09-26 10:24:05 -07:00
|
|
|
oop CollectedHeap::array_allocate_nozero(KlassHandle klass,
|
|
|
|
int size,
|
|
|
|
int length,
|
|
|
|
TRAPS) {
|
|
|
|
debug_only(check_for_valid_allocation_state());
|
|
|
|
assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
|
|
|
|
assert(size >= 0, "int won't convert to size_t");
|
|
|
|
HeapWord* obj = common_mem_allocate_noinit(size, CHECK_NULL);
|
|
|
|
((oop)obj)->set_klass_gap(0);
|
2012-03-27 10:29:59 +02:00
|
|
|
post_allocation_setup_array(klass, obj, length);
|
2011-09-26 10:24:05 -07:00
|
|
|
#ifndef PRODUCT
|
|
|
|
const size_t hs = oopDesc::header_size()+1;
|
|
|
|
Universe::heap()->check_for_non_bad_heap_word_value(obj+hs, size-hs);
|
|
|
|
#endif
|
|
|
|
return (oop)obj;
|
|
|
|
}
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
inline void CollectedHeap::oop_iterate_no_header(OopClosure* cl) {
|
|
|
|
NoHeaderExtendedOopClosure no_header_cl(cl);
|
|
|
|
oop_iterate(&no_header_cl);
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
#ifndef PRODUCT
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
CollectedHeap::promotion_should_fail(volatile size_t* count) {
|
|
|
|
// Access to count is not atomic; the value does not have to be exact.
|
|
|
|
if (PromotionFailureALot) {
|
|
|
|
const size_t gc_num = total_collections();
|
|
|
|
const size_t elapsed_gcs = gc_num - _promotion_failure_alot_gc_number;
|
|
|
|
if (elapsed_gcs >= PromotionFailureALotInterval) {
|
|
|
|
// Test for unsigned arithmetic wrap-around.
|
|
|
|
if (++*count >= PromotionFailureALotCount) {
|
|
|
|
*count = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool CollectedHeap::promotion_should_fail() {
|
|
|
|
return promotion_should_fail(&_promotion_failure_alot_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void CollectedHeap::reset_promotion_should_fail(volatile size_t* count) {
|
|
|
|
if (PromotionFailureALot) {
|
|
|
|
_promotion_failure_alot_gc_number = total_collections();
|
|
|
|
*count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void CollectedHeap::reset_promotion_should_fail() {
|
|
|
|
reset_promotion_should_fail(&_promotion_failure_alot_count);
|
|
|
|
}
|
|
|
|
#endif // #ifndef PRODUCT
|
2010-11-23 13:22:55 -08:00
|
|
|
|
|
|
|
#endif // SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_INLINE_HPP
|