2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2015-02-13 14:37:35 +01:00
|
|
|
* Copyright (c) 2001, 2015, 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
|
|
|
#include "precompiled.hpp"
|
|
|
|
#include "classfile/systemDictionary.hpp"
|
2013-06-10 11:30:51 +02:00
|
|
|
#include "gc_implementation/shared/gcHeapSummary.hpp"
|
|
|
|
#include "gc_implementation/shared/gcTrace.hpp"
|
|
|
|
#include "gc_implementation/shared/gcTraceTime.hpp"
|
|
|
|
#include "gc_implementation/shared/gcWhen.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "gc_implementation/shared/vmGCOperations.hpp"
|
2013-06-10 11:30:51 +02:00
|
|
|
#include "gc_interface/allocTracer.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "gc_interface/collectedHeap.hpp"
|
|
|
|
#include "gc_interface/collectedHeap.inline.hpp"
|
2015-02-13 14:37:35 +01:00
|
|
|
#include "memory/barrierSet.inline.hpp"
|
2013-06-10 11:30:51 +02:00
|
|
|
#include "memory/metaspace.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "oops/oop.inline.hpp"
|
2011-10-17 21:38:29 -07:00
|
|
|
#include "oops/instanceMirrorKlass.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/init.hpp"
|
2012-11-27 14:20:21 +01:00
|
|
|
#include "runtime/thread.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "services/heapDumper.hpp"
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef ASSERT
|
|
|
|
int CollectedHeap::_fire_out_of_memory_count = 0;
|
|
|
|
#endif
|
|
|
|
|
2008-12-11 12:05:08 -08:00
|
|
|
size_t CollectedHeap::_filler_array_max_size = 0;
|
|
|
|
|
2012-02-01 07:59:01 -08:00
|
|
|
template <>
|
|
|
|
void EventLogBase<GCMessage>::print(outputStream* st, GCMessage& m) {
|
|
|
|
st->print_cr("GC heap %s", m.is_before ? "before" : "after");
|
|
|
|
st->print_raw(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GCHeapLog::log_heap(bool before) {
|
|
|
|
if (!should_log()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-15 10:12:55 -08:00
|
|
|
double timestamp = fetch_timestamp();
|
2012-02-01 07:59:01 -08:00
|
|
|
MutexLockerEx ml(&_mutex, Mutex::_no_safepoint_check_flag);
|
|
|
|
int index = compute_log_index();
|
|
|
|
_records[index].thread = NULL; // Its the GC thread so it's not that interesting.
|
|
|
|
_records[index].timestamp = timestamp;
|
|
|
|
_records[index].data.is_before = before;
|
|
|
|
stringStream st(_records[index].data.buffer(), _records[index].data.size());
|
|
|
|
if (before) {
|
2012-02-15 10:12:55 -08:00
|
|
|
Universe::print_heap_before_gc(&st, true);
|
2012-02-01 07:59:01 -08:00
|
|
|
} else {
|
2012-02-15 10:12:55 -08:00
|
|
|
Universe::print_heap_after_gc(&st, true);
|
2012-02-01 07:59:01 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-10 11:30:51 +02:00
|
|
|
VirtualSpaceSummary CollectedHeap::create_heap_space_summary() {
|
|
|
|
size_t capacity_in_words = capacity() / HeapWordSize;
|
|
|
|
|
|
|
|
return VirtualSpaceSummary(
|
|
|
|
reserved_region().start(), reserved_region().start() + capacity_in_words, reserved_region().end());
|
|
|
|
}
|
|
|
|
|
|
|
|
GCHeapSummary CollectedHeap::create_heap_summary() {
|
|
|
|
VirtualSpaceSummary heap_space = create_heap_space_summary();
|
|
|
|
return GCHeapSummary(heap_space, used());
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaspaceSummary CollectedHeap::create_metaspace_summary() {
|
|
|
|
const MetaspaceSizes meta_space(
|
2014-03-26 14:15:02 +01:00
|
|
|
MetaspaceAux::committed_bytes(),
|
2014-03-31 17:09:38 +02:00
|
|
|
MetaspaceAux::used_bytes(),
|
2013-09-12 10:15:30 +02:00
|
|
|
MetaspaceAux::reserved_bytes());
|
2013-06-10 11:30:51 +02:00
|
|
|
const MetaspaceSizes data_space(
|
2014-03-26 14:15:02 +01:00
|
|
|
MetaspaceAux::committed_bytes(Metaspace::NonClassType),
|
2014-03-31 17:09:38 +02:00
|
|
|
MetaspaceAux::used_bytes(Metaspace::NonClassType),
|
2013-09-12 10:15:30 +02:00
|
|
|
MetaspaceAux::reserved_bytes(Metaspace::NonClassType));
|
2013-06-10 11:30:51 +02:00
|
|
|
const MetaspaceSizes class_space(
|
2014-03-26 14:15:02 +01:00
|
|
|
MetaspaceAux::committed_bytes(Metaspace::ClassType),
|
2014-03-31 17:09:38 +02:00
|
|
|
MetaspaceAux::used_bytes(Metaspace::ClassType),
|
2013-09-12 10:15:30 +02:00
|
|
|
MetaspaceAux::reserved_bytes(Metaspace::ClassType));
|
2013-06-10 11:30:51 +02:00
|
|
|
|
2014-03-18 09:03:28 +01:00
|
|
|
const MetaspaceChunkFreeListSummary& ms_chunk_free_list_summary =
|
|
|
|
MetaspaceAux::chunk_free_list_summary(Metaspace::NonClassType);
|
|
|
|
const MetaspaceChunkFreeListSummary& class_chunk_free_list_summary =
|
|
|
|
MetaspaceAux::chunk_free_list_summary(Metaspace::ClassType);
|
|
|
|
|
|
|
|
return MetaspaceSummary(MetaspaceGC::capacity_until_GC(), meta_space, data_space, class_space,
|
|
|
|
ms_chunk_free_list_summary, class_chunk_free_list_summary);
|
2013-06-10 11:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectedHeap::print_heap_before_gc() {
|
|
|
|
if (PrintHeapAtGC) {
|
|
|
|
Universe::print_heap_before_gc();
|
|
|
|
}
|
|
|
|
if (_gc_heap_log != NULL) {
|
|
|
|
_gc_heap_log->log_heap_before();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectedHeap::print_heap_after_gc() {
|
|
|
|
if (PrintHeapAtGC) {
|
|
|
|
Universe::print_heap_after_gc();
|
|
|
|
}
|
|
|
|
if (_gc_heap_log != NULL) {
|
|
|
|
_gc_heap_log->log_heap_after();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-13 14:37:35 +01:00
|
|
|
void CollectedHeap::print_on_error(outputStream* st) const {
|
|
|
|
st->print_cr("Heap:");
|
|
|
|
print_extended_on(st);
|
|
|
|
st->cr();
|
|
|
|
|
|
|
|
_barrier_set->print_on(st);
|
|
|
|
}
|
|
|
|
|
2013-08-15 10:52:18 +02:00
|
|
|
void CollectedHeap::register_nmethod(nmethod* nm) {
|
|
|
|
assert_locked_or_safepoint(CodeCache_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectedHeap::unregister_nmethod(nmethod* nm) {
|
|
|
|
assert_locked_or_safepoint(CodeCache_lock);
|
|
|
|
}
|
|
|
|
|
2015-02-11 14:47:21 +01:00
|
|
|
void CollectedHeap::trace_heap(GCWhen::Type when, const GCTracer* gc_tracer) {
|
2013-06-10 11:30:51 +02:00
|
|
|
const GCHeapSummary& heap_summary = create_heap_summary();
|
2014-03-18 09:03:28 +01:00
|
|
|
gc_tracer->report_gc_heap_summary(when, heap_summary);
|
|
|
|
|
2013-06-10 11:30:51 +02:00
|
|
|
const MetaspaceSummary& metaspace_summary = create_metaspace_summary();
|
2014-03-18 09:03:28 +01:00
|
|
|
gc_tracer->report_metaspace_summary(when, metaspace_summary);
|
2013-06-10 11:30:51 +02:00
|
|
|
}
|
|
|
|
|
2015-02-11 14:47:21 +01:00
|
|
|
void CollectedHeap::trace_heap_before_gc(const GCTracer* gc_tracer) {
|
2013-06-10 11:30:51 +02:00
|
|
|
trace_heap(GCWhen::BeforeGC, gc_tracer);
|
|
|
|
}
|
|
|
|
|
2015-02-11 14:47:21 +01:00
|
|
|
void CollectedHeap::trace_heap_after_gc(const GCTracer* gc_tracer) {
|
2013-06-10 11:30:51 +02:00
|
|
|
trace_heap(GCWhen::AfterGC, gc_tracer);
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Memory state functions.
|
|
|
|
|
2010-09-20 14:38:38 -07:00
|
|
|
|
|
|
|
CollectedHeap::CollectedHeap() : _n_par_threads(0)
|
2008-12-11 12:05:08 -08:00
|
|
|
{
|
|
|
|
const size_t max_len = size_t(arrayOopDesc::max_array_length(T_INT));
|
|
|
|
const size_t elements_per_word = HeapWordSize / sizeof(jint);
|
|
|
|
_filler_array_max_size = align_object_size(filler_array_hdr_size() +
|
2012-03-23 15:28:24 +01:00
|
|
|
max_len / elements_per_word);
|
2008-12-11 12:05:08 -08:00
|
|
|
|
|
|
|
_barrier_set = NULL;
|
|
|
|
_is_gc_active = false;
|
|
|
|
_total_collections = _total_full_collections = 0;
|
|
|
|
_gc_cause = _gc_lastcause = GCCause::_no_gc;
|
2007-12-01 00:00:00 +00:00
|
|
|
NOT_PRODUCT(_promotion_failure_alot_count = 0;)
|
|
|
|
NOT_PRODUCT(_promotion_failure_alot_gc_number = 0;)
|
|
|
|
|
|
|
|
if (UsePerfData) {
|
|
|
|
EXCEPTION_MARK;
|
|
|
|
|
|
|
|
// create the gc cause jvmstat counters
|
|
|
|
_perf_gc_cause = PerfDataManager::create_string_variable(SUN_GC, "cause",
|
|
|
|
80, GCCause::to_string(_gc_cause), CHECK);
|
|
|
|
|
|
|
|
_perf_gc_lastcause =
|
|
|
|
PerfDataManager::create_string_variable(SUN_GC, "lastCause",
|
|
|
|
80, GCCause::to_string(_gc_lastcause), CHECK);
|
|
|
|
}
|
2010-01-13 15:26:39 -08:00
|
|
|
_defer_initial_card_mark = false; // strengthened by subclass in pre_initialize() below.
|
2012-02-01 07:59:01 -08:00
|
|
|
// Create the ring log
|
|
|
|
if (LogEvents) {
|
|
|
|
_gc_heap_log = new GCHeapLog();
|
|
|
|
} else {
|
|
|
|
_gc_heap_log = NULL;
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
// This interface assumes that it's being called by the
|
|
|
|
// vm thread. It collects the heap assuming that the
|
|
|
|
// heap lock is already held and that we are executing in
|
|
|
|
// the context of the vm thread.
|
|
|
|
void CollectedHeap::collect_as_vm_thread(GCCause::Cause cause) {
|
|
|
|
assert(Thread::current()->is_VM_thread(), "Precondition#1");
|
|
|
|
assert(Heap_lock->is_locked(), "Precondition#2");
|
|
|
|
GCCauseSetter gcs(this, cause);
|
|
|
|
switch (cause) {
|
|
|
|
case GCCause::_heap_inspection:
|
|
|
|
case GCCause::_heap_dump:
|
|
|
|
case GCCause::_metadata_GC_threshold : {
|
|
|
|
HandleMark hm;
|
|
|
|
do_full_collection(false); // don't clear all soft refs
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GCCause::_last_ditch_collection: {
|
|
|
|
HandleMark hm;
|
|
|
|
do_full_collection(true); // do clear all soft refs
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ShouldNotReachHere(); // Unexpected use of this function
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-13 15:26:39 -08:00
|
|
|
void CollectedHeap::pre_initialize() {
|
|
|
|
// Used for ReduceInitialCardMarks (when COMPILER2 is used);
|
|
|
|
// otherwise remains unused.
|
2010-05-19 10:37:05 -07:00
|
|
|
#ifdef COMPILER2
|
2010-01-26 16:52:29 -08:00
|
|
|
_defer_initial_card_mark = ReduceInitialCardMarks && can_elide_tlab_store_barriers()
|
|
|
|
&& (DeferInitialCardMark || card_mark_must_follow_store());
|
2010-01-13 15:26:39 -08:00
|
|
|
#else
|
|
|
|
assert(_defer_initial_card_mark == false, "Who would set it?");
|
|
|
|
#endif
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
#ifndef PRODUCT
|
|
|
|
void CollectedHeap::check_for_bad_heap_word_value(HeapWord* addr, size_t size) {
|
|
|
|
if (CheckMemoryInitialization && ZapUnusedHeapArea) {
|
|
|
|
for (size_t slot = 0; slot < size; slot += 1) {
|
|
|
|
assert((*(intptr_t*) (addr + slot)) != ((intptr_t) badHeapWordVal),
|
|
|
|
"Found badHeapWordValue in post-allocation check");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-07 22:19:57 -08:00
|
|
|
void CollectedHeap::check_for_non_bad_heap_word_value(HeapWord* addr, size_t size) {
|
2007-12-01 00:00:00 +00:00
|
|
|
if (CheckMemoryInitialization && ZapUnusedHeapArea) {
|
|
|
|
for (size_t slot = 0; slot < size; slot += 1) {
|
|
|
|
assert((*(intptr_t*) (addr + slot)) == ((intptr_t) badHeapWordVal),
|
|
|
|
"Found non badHeapWordValue in pre-allocation check");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // PRODUCT
|
|
|
|
|
|
|
|
#ifdef ASSERT
|
|
|
|
void CollectedHeap::check_for_valid_allocation_state() {
|
|
|
|
Thread *thread = Thread::current();
|
|
|
|
// How to choose between a pending exception and a potential
|
|
|
|
// OutOfMemoryError? Don't allow pending exceptions.
|
|
|
|
// This is a VM policy failure, so how do we exhaustively test it?
|
|
|
|
assert(!thread->has_pending_exception(),
|
|
|
|
"shouldn't be allocating with pending exception");
|
|
|
|
if (StrictSafepointChecks) {
|
|
|
|
assert(thread->allow_allocation(),
|
|
|
|
"Allocation done by thread for which allocation is blocked "
|
|
|
|
"by No_Allocation_Verifier!");
|
|
|
|
// Allocation of an oop can always invoke a safepoint,
|
|
|
|
// hence, the true argument
|
|
|
|
thread->check_for_valid_safepoint_state(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-06-10 11:30:51 +02:00
|
|
|
HeapWord* CollectedHeap::allocate_from_tlab_slow(KlassHandle klass, Thread* thread, size_t size) {
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Retain tlab and allocate object in shared space if
|
|
|
|
// the amount free in the tlab is too large to discard.
|
|
|
|
if (thread->tlab().free() > thread->tlab().refill_waste_limit()) {
|
|
|
|
thread->tlab().record_slow_allocation(size);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Discard tlab and allocate a new one.
|
|
|
|
// To minimize fragmentation, the last TLAB may be smaller than the rest.
|
|
|
|
size_t new_tlab_size = thread->tlab().compute_size(size);
|
|
|
|
|
|
|
|
thread->tlab().clear_before_allocation();
|
|
|
|
|
|
|
|
if (new_tlab_size == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate a new TLAB...
|
|
|
|
HeapWord* obj = Universe::heap()->allocate_new_tlab(new_tlab_size);
|
|
|
|
if (obj == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-06-10 11:30:51 +02:00
|
|
|
|
|
|
|
AllocTracer::send_allocation_in_new_tlab_event(klass, new_tlab_size * HeapWordSize, size * HeapWordSize);
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
if (ZeroTLAB) {
|
|
|
|
// ..and clear it.
|
|
|
|
Copy::zero_to_words(obj, new_tlab_size);
|
|
|
|
} else {
|
2011-08-26 08:52:22 -07:00
|
|
|
// ...and zap just allocated object.
|
|
|
|
#ifdef ASSERT
|
|
|
|
// Skip mangling the space corresponding to the object header to
|
|
|
|
// ensure that the returned space is not considered parsable by
|
|
|
|
// any concurrent GC thread.
|
|
|
|
size_t hdr_size = oopDesc::header_size();
|
|
|
|
Copy::fill_to_words(obj + hdr_size, new_tlab_size - hdr_size, badHeapWordVal);
|
|
|
|
#endif // ASSERT
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
thread->tlab().fill(obj, obj + size, new_tlab_size);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2009-10-16 02:05:46 -07:00
|
|
|
void CollectedHeap::flush_deferred_store_barrier(JavaThread* thread) {
|
|
|
|
MemRegion deferred = thread->deferred_card_mark();
|
|
|
|
if (!deferred.is_empty()) {
|
2010-01-13 15:26:39 -08:00
|
|
|
assert(_defer_initial_card_mark, "Otherwise should be empty");
|
2009-10-16 02:05:46 -07:00
|
|
|
{
|
|
|
|
// Verify that the storage points to a parsable object in heap
|
|
|
|
DEBUG_ONLY(oop old_obj = oop(deferred.start());)
|
|
|
|
assert(is_in(old_obj), "Not in allocated heap");
|
|
|
|
assert(!can_elide_initializing_store_barrier(old_obj),
|
2010-01-13 15:26:39 -08:00
|
|
|
"Else should have been filtered in new_store_pre_barrier()");
|
2009-10-16 02:05:46 -07:00
|
|
|
assert(old_obj->is_oop(true), "Not an oop");
|
|
|
|
assert(deferred.word_size() == (size_t)(old_obj->size()),
|
|
|
|
"Mismatch: multiple objects?");
|
|
|
|
}
|
|
|
|
BarrierSet* bs = barrier_set();
|
|
|
|
assert(bs->has_write_region_opt(), "No write_region() on BarrierSet");
|
|
|
|
bs->write_region(deferred);
|
|
|
|
// "Clear" the deferred_card_mark field
|
|
|
|
thread->set_deferred_card_mark(MemRegion());
|
|
|
|
}
|
|
|
|
assert(thread->deferred_card_mark().is_empty(), "invariant");
|
|
|
|
}
|
|
|
|
|
2014-01-27 13:14:53 +01:00
|
|
|
size_t CollectedHeap::max_tlab_size() const {
|
|
|
|
// TLABs can't be bigger than we can fill with a int[Integer.MAX_VALUE].
|
|
|
|
// This restriction could be removed by enabling filling with multiple arrays.
|
|
|
|
// If we compute that the reasonable way as
|
|
|
|
// header_size + ((sizeof(jint) * max_jint) / HeapWordSize)
|
|
|
|
// we'll overflow on the multiply, so we do the divide first.
|
|
|
|
// We actually lose a little by dividing first,
|
|
|
|
// but that just makes the TLAB somewhat smaller than the biggest array,
|
|
|
|
// which is fine, since we'll be able to fill that.
|
|
|
|
size_t max_int_size = typeArrayOopDesc::header_size(T_INT) +
|
|
|
|
sizeof(jint) *
|
|
|
|
((juint) max_jint / (size_t) HeapWordSize);
|
|
|
|
return align_size_down(max_int_size, MinObjAlignment);
|
|
|
|
}
|
|
|
|
|
2009-10-16 02:05:46 -07:00
|
|
|
// Helper for ReduceInitialCardMarks. For performance,
|
|
|
|
// compiled code may elide card-marks for initializing stores
|
|
|
|
// to a newly allocated object along the fast-path. We
|
|
|
|
// compensate for such elided card-marks as follows:
|
|
|
|
// (a) Generational, non-concurrent collectors, such as
|
|
|
|
// GenCollectedHeap(ParNew,DefNew,Tenured) and
|
|
|
|
// ParallelScavengeHeap(ParallelGC, ParallelOldGC)
|
|
|
|
// need the card-mark if and only if the region is
|
|
|
|
// in the old gen, and do not care if the card-mark
|
|
|
|
// succeeds or precedes the initializing stores themselves,
|
|
|
|
// so long as the card-mark is completed before the next
|
|
|
|
// scavenge. For all these cases, we can do a card mark
|
|
|
|
// at the point at which we do a slow path allocation
|
2010-01-13 15:26:39 -08:00
|
|
|
// in the old gen, i.e. in this call.
|
2009-10-16 02:05:46 -07:00
|
|
|
// (b) GenCollectedHeap(ConcurrentMarkSweepGeneration) requires
|
|
|
|
// in addition that the card-mark for an old gen allocated
|
|
|
|
// object strictly follow any associated initializing stores.
|
|
|
|
// In these cases, the memRegion remembered below is
|
|
|
|
// used to card-mark the entire region either just before the next
|
|
|
|
// slow-path allocation by this thread or just before the next scavenge or
|
|
|
|
// CMS-associated safepoint, whichever of these events happens first.
|
|
|
|
// (The implicit assumption is that the object has been fully
|
|
|
|
// initialized by this point, a fact that we assert when doing the
|
|
|
|
// card-mark.)
|
|
|
|
// (c) G1CollectedHeap(G1) uses two kinds of write barriers. When a
|
|
|
|
// G1 concurrent marking is in progress an SATB (pre-write-)barrier is
|
|
|
|
// is used to remember the pre-value of any store. Initializing
|
|
|
|
// stores will not need this barrier, so we need not worry about
|
|
|
|
// compensating for the missing pre-barrier here. Turning now
|
|
|
|
// to the post-barrier, we note that G1 needs a RS update barrier
|
|
|
|
// which simply enqueues a (sequence of) dirty cards which may
|
|
|
|
// optionally be refined by the concurrent update threads. Note
|
|
|
|
// that this barrier need only be applied to a non-young write,
|
|
|
|
// but, like in CMS, because of the presence of concurrent refinement
|
|
|
|
// (much like CMS' precleaning), must strictly follow the oop-store.
|
|
|
|
// Thus, using the same protocol for maintaining the intended
|
2010-01-13 15:26:39 -08:00
|
|
|
// invariants turns out, serendepitously, to be the same for both
|
|
|
|
// G1 and CMS.
|
2009-10-16 02:05:46 -07:00
|
|
|
//
|
2010-01-13 15:26:39 -08:00
|
|
|
// For any future collector, this code should be reexamined with
|
|
|
|
// that specific collector in mind, and the documentation above suitably
|
|
|
|
// extended and updated.
|
|
|
|
oop CollectedHeap::new_store_pre_barrier(JavaThread* thread, oop new_obj) {
|
2009-10-16 02:05:46 -07:00
|
|
|
// If a previous card-mark was deferred, flush it now.
|
|
|
|
flush_deferred_store_barrier(thread);
|
|
|
|
if (can_elide_initializing_store_barrier(new_obj)) {
|
|
|
|
// The deferred_card_mark region should be empty
|
|
|
|
// following the flush above.
|
|
|
|
assert(thread->deferred_card_mark().is_empty(), "Error");
|
|
|
|
} else {
|
2010-01-13 15:26:39 -08:00
|
|
|
MemRegion mr((HeapWord*)new_obj, new_obj->size());
|
|
|
|
assert(!mr.is_empty(), "Error");
|
|
|
|
if (_defer_initial_card_mark) {
|
|
|
|
// Defer the card mark
|
|
|
|
thread->set_deferred_card_mark(mr);
|
|
|
|
} else {
|
|
|
|
// Do the card mark
|
|
|
|
BarrierSet* bs = barrier_set();
|
|
|
|
assert(bs->has_write_region_opt(), "No write_region() on BarrierSet");
|
|
|
|
bs->write_region(mr);
|
|
|
|
}
|
2009-10-16 02:05:46 -07:00
|
|
|
}
|
|
|
|
return new_obj;
|
|
|
|
}
|
|
|
|
|
2008-12-11 12:05:08 -08:00
|
|
|
size_t CollectedHeap::filler_array_hdr_size() {
|
2010-05-27 18:01:56 -07:00
|
|
|
return size_t(align_object_offset(arrayOopDesc::header_size(T_INT))); // align to Long
|
2008-12-11 12:05:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t CollectedHeap::filler_array_min_size() {
|
2010-05-27 18:01:56 -07:00
|
|
|
return align_object_size(filler_array_hdr_size()); // align to MinObjAlignment
|
2008-12-11 12:05:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ASSERT
|
|
|
|
void CollectedHeap::fill_args_check(HeapWord* start, size_t words)
|
|
|
|
{
|
|
|
|
assert(words >= min_fill_size(), "too small to fill");
|
|
|
|
assert(words % MinObjAlignment == 0, "unaligned size");
|
|
|
|
assert(Universe::heap()->is_in_reserved(start), "not in heap");
|
|
|
|
assert(Universe::heap()->is_in_reserved(start + words - 1), "not in heap");
|
|
|
|
}
|
|
|
|
|
2010-01-12 14:56:46 -08:00
|
|
|
void CollectedHeap::zap_filler_array(HeapWord* start, size_t words, bool zap)
|
2008-12-11 12:05:08 -08:00
|
|
|
{
|
2010-01-12 14:56:46 -08:00
|
|
|
if (ZapFillerObjects && zap) {
|
2008-12-11 12:05:08 -08:00
|
|
|
Copy::fill_to_words(start + filler_array_hdr_size(),
|
|
|
|
words - filler_array_hdr_size(), 0XDEAFBABE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // ASSERT
|
|
|
|
|
|
|
|
void
|
2010-01-12 14:56:46 -08:00
|
|
|
CollectedHeap::fill_with_array(HeapWord* start, size_t words, bool zap)
|
2008-12-11 12:05:08 -08:00
|
|
|
{
|
|
|
|
assert(words >= filler_array_min_size(), "too small for an array");
|
|
|
|
assert(words <= filler_array_max_size(), "too big for a single object");
|
|
|
|
|
|
|
|
const size_t payload_size = words - filler_array_hdr_size();
|
|
|
|
const size_t len = payload_size * HeapWordSize / sizeof(jint);
|
2012-03-23 15:28:24 +01:00
|
|
|
assert((int)len >= 0, err_msg("size too large " SIZE_FORMAT " becomes %d", words, (int)len));
|
2008-12-11 12:05:08 -08:00
|
|
|
|
|
|
|
// Set the length first for concurrent GC.
|
|
|
|
((arrayOop)start)->set_length((int)len);
|
2012-03-27 10:29:59 +02:00
|
|
|
post_allocation_setup_common(Universe::intArrayKlassObj(), start);
|
2010-01-12 14:56:46 -08:00
|
|
|
DEBUG_ONLY(zap_filler_array(start, words, zap);)
|
2008-12-11 12:05:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-12 14:56:46 -08:00
|
|
|
CollectedHeap::fill_with_object_impl(HeapWord* start, size_t words, bool zap)
|
2008-12-11 12:05:08 -08:00
|
|
|
{
|
|
|
|
assert(words <= filler_array_max_size(), "too big for a single object");
|
|
|
|
|
|
|
|
if (words >= filler_array_min_size()) {
|
2010-01-12 14:56:46 -08:00
|
|
|
fill_with_array(start, words, zap);
|
2008-12-11 12:05:08 -08:00
|
|
|
} else if (words > 0) {
|
|
|
|
assert(words == min_fill_size(), "unaligned size");
|
2012-03-27 10:29:59 +02:00
|
|
|
post_allocation_setup_common(SystemDictionary::Object_klass(), start);
|
2008-12-11 12:05:08 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-12 14:56:46 -08:00
|
|
|
void CollectedHeap::fill_with_object(HeapWord* start, size_t words, bool zap)
|
2008-12-11 12:05:08 -08:00
|
|
|
{
|
|
|
|
DEBUG_ONLY(fill_args_check(start, words);)
|
|
|
|
HandleMark hm; // Free handles before leaving.
|
2010-01-12 14:56:46 -08:00
|
|
|
fill_with_object_impl(start, words, zap);
|
2008-12-11 12:05:08 -08:00
|
|
|
}
|
|
|
|
|
2010-01-12 14:56:46 -08:00
|
|
|
void CollectedHeap::fill_with_objects(HeapWord* start, size_t words, bool zap)
|
2008-12-11 12:05:08 -08:00
|
|
|
{
|
|
|
|
DEBUG_ONLY(fill_args_check(start, words);)
|
|
|
|
HandleMark hm; // Free handles before leaving.
|
|
|
|
|
2010-05-19 16:05:47 -07:00
|
|
|
#ifdef _LP64
|
2008-12-11 12:05:08 -08:00
|
|
|
// A single array can fill ~8G, so multiple objects are needed only in 64-bit.
|
|
|
|
// First fill with arrays, ensuring that any remaining space is big enough to
|
|
|
|
// fill. The remainder is filled with a single object.
|
|
|
|
const size_t min = min_fill_size();
|
|
|
|
const size_t max = filler_array_max_size();
|
|
|
|
while (words > max) {
|
|
|
|
const size_t cur = words - max >= min ? max : max - min;
|
2010-01-12 14:56:46 -08:00
|
|
|
fill_with_array(start, cur, zap);
|
2008-12-11 12:05:08 -08:00
|
|
|
start += cur;
|
|
|
|
words -= cur;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-01-12 14:56:46 -08:00
|
|
|
fill_with_object_impl(start, words, zap);
|
2008-12-11 12:05:08 -08:00
|
|
|
}
|
|
|
|
|
2013-11-01 17:09:38 +01:00
|
|
|
void CollectedHeap::post_initialize() {
|
|
|
|
collector_policy()->post_heap_initialize();
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
HeapWord* CollectedHeap::allocate_new_tlab(size_t size) {
|
|
|
|
guarantee(false, "thread-local allocation buffers not supported");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectedHeap::ensure_parsability(bool retire_tlabs) {
|
|
|
|
// The second disjunct in the assertion below makes a concession
|
|
|
|
// for the start-up verification done while the VM is being
|
|
|
|
// created. Callers be careful that you know that mutators
|
|
|
|
// aren't going to interfere -- for instance, this is permissible
|
|
|
|
// if we are still single-threaded and have either not yet
|
|
|
|
// started allocating (nothing much to verify) or we have
|
|
|
|
// started allocating but are now a full-fledged JavaThread
|
|
|
|
// (and have thus made our TLAB's) available for filling.
|
|
|
|
assert(SafepointSynchronize::is_at_safepoint() ||
|
|
|
|
!is_init_completed(),
|
|
|
|
"Should only be called at a safepoint or at start-up"
|
|
|
|
" otherwise concurrent mutator activity may make heap "
|
|
|
|
" unparsable again");
|
2010-01-13 15:26:39 -08:00
|
|
|
const bool use_tlab = UseTLAB;
|
|
|
|
const bool deferred = _defer_initial_card_mark;
|
|
|
|
// The main thread starts allocating via a TLAB even before it
|
|
|
|
// has added itself to the threads list at vm boot-up.
|
|
|
|
assert(!use_tlab || Threads::first() != NULL,
|
|
|
|
"Attempt to fill tlabs before main thread has been added"
|
|
|
|
" to threads list is doomed to failure!");
|
|
|
|
for (JavaThread *thread = Threads::first(); thread; thread = thread->next()) {
|
|
|
|
if (use_tlab) thread->tlab().make_parsable(retire_tlabs);
|
|
|
|
#ifdef COMPILER2
|
|
|
|
// The deferred store barriers must all have been flushed to the
|
|
|
|
// card-table (or other remembered set structure) before GC starts
|
|
|
|
// processing the card-table (or other remembered set).
|
|
|
|
if (deferred) flush_deferred_store_barrier(thread);
|
|
|
|
#else
|
|
|
|
assert(!deferred, "Should be false");
|
|
|
|
assert(thread->deferred_card_mark().is_empty(), "Should be empty");
|
|
|
|
#endif
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectedHeap::accumulate_statistics_all_tlabs() {
|
|
|
|
if (UseTLAB) {
|
|
|
|
assert(SafepointSynchronize::is_at_safepoint() ||
|
|
|
|
!is_init_completed(),
|
|
|
|
"should only accumulate statistics on tlabs at safepoint");
|
|
|
|
|
|
|
|
ThreadLocalAllocBuffer::accumulate_statistics_before_gc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectedHeap::resize_all_tlabs() {
|
|
|
|
if (UseTLAB) {
|
|
|
|
assert(SafepointSynchronize::is_at_safepoint() ||
|
|
|
|
!is_init_completed(),
|
|
|
|
"should only resize tlabs at safepoint");
|
|
|
|
|
|
|
|
ThreadLocalAllocBuffer::resize_all_tlabs();
|
|
|
|
}
|
|
|
|
}
|
2009-03-02 16:37:04 -08:00
|
|
|
|
2013-06-10 11:30:51 +02:00
|
|
|
void CollectedHeap::pre_full_gc_dump(GCTimer* timer) {
|
2009-03-02 16:37:04 -08:00
|
|
|
if (HeapDumpBeforeFullGC) {
|
2014-06-19 13:31:14 +02:00
|
|
|
GCTraceTime tt("Heap Dump (before full gc): ", PrintGCDetails, false, timer, GCId::create());
|
2009-03-02 16:37:04 -08:00
|
|
|
// We are doing a "major" collection and a heap dump before
|
|
|
|
// major collection has been requested.
|
|
|
|
HeapDumper::dump_heap();
|
|
|
|
}
|
|
|
|
if (PrintClassHistogramBeforeFullGC) {
|
2014-06-19 13:31:14 +02:00
|
|
|
GCTraceTime tt("Class Histogram (before full gc): ", PrintGCDetails, true, timer, GCId::create());
|
2013-06-10 11:30:51 +02:00
|
|
|
VM_GC_HeapInspection inspector(gclog_or_tty, false /* ! full gc */);
|
2009-03-02 16:37:04 -08:00
|
|
|
inspector.doit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-10 11:30:51 +02:00
|
|
|
void CollectedHeap::post_full_gc_dump(GCTimer* timer) {
|
2009-03-02 16:37:04 -08:00
|
|
|
if (HeapDumpAfterFullGC) {
|
2014-06-19 13:31:14 +02:00
|
|
|
GCTraceTime tt("Heap Dump (after full gc): ", PrintGCDetails, false, timer, GCId::create());
|
2009-03-02 16:37:04 -08:00
|
|
|
HeapDumper::dump_heap();
|
|
|
|
}
|
|
|
|
if (PrintClassHistogramAfterFullGC) {
|
2014-06-19 13:31:14 +02:00
|
|
|
GCTraceTime tt("Class Histogram (after full gc): ", PrintGCDetails, true, timer, GCId::create());
|
2013-06-10 11:30:51 +02:00
|
|
|
VM_GC_HeapInspection inspector(gclog_or_tty, false /* ! full gc */);
|
2009-03-02 16:37:04 -08:00
|
|
|
inspector.doit();
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 21:38:29 -07:00
|
|
|
|
2014-09-18 12:45:45 +02:00
|
|
|
void CollectedHeap::initialize_reserved_region(HeapWord *start, HeapWord *end) {
|
|
|
|
// It is important to do this in a way such that concurrent readers can't
|
|
|
|
// temporarily think something is in the heap. (Seen this happen in asserts.)
|
|
|
|
_reserved.set_word_size(0);
|
|
|
|
_reserved.set_start(start);
|
|
|
|
_reserved.set_end(end);
|
|
|
|
}
|
|
|
|
|
2011-12-14 12:15:26 +01:00
|
|
|
/////////////// Unit tests ///////////////
|
|
|
|
|
|
|
|
#ifndef PRODUCT
|
|
|
|
void CollectedHeap::test_is_in() {
|
|
|
|
CollectedHeap* heap = Universe::heap();
|
|
|
|
|
2012-01-02 10:01:46 +01:00
|
|
|
uintptr_t epsilon = (uintptr_t) MinObjAlignment;
|
|
|
|
uintptr_t heap_start = (uintptr_t) heap->_reserved.start();
|
|
|
|
uintptr_t heap_end = (uintptr_t) heap->_reserved.end();
|
|
|
|
|
2011-12-14 12:15:26 +01:00
|
|
|
// Test that NULL is not in the heap.
|
|
|
|
assert(!heap->is_in(NULL), "NULL is unexpectedly in the heap");
|
|
|
|
|
|
|
|
// Test that a pointer to before the heap start is reported as outside the heap.
|
2012-01-02 10:01:46 +01:00
|
|
|
assert(heap_start >= ((uintptr_t)NULL + epsilon), "sanity");
|
|
|
|
void* before_heap = (void*)(heap_start - epsilon);
|
2011-12-14 12:15:26 +01:00
|
|
|
assert(!heap->is_in(before_heap),
|
2014-05-09 16:50:54 -04:00
|
|
|
err_msg("before_heap: " PTR_FORMAT " is unexpectedly in the heap", p2i(before_heap)));
|
2011-12-14 12:15:26 +01:00
|
|
|
|
|
|
|
// Test that a pointer to after the heap end is reported as outside the heap.
|
2012-01-02 10:01:46 +01:00
|
|
|
assert(heap_end <= ((uintptr_t)-1 - epsilon), "sanity");
|
|
|
|
void* after_heap = (void*)(heap_end + epsilon);
|
2011-12-14 12:15:26 +01:00
|
|
|
assert(!heap->is_in(after_heap),
|
2014-05-09 16:50:54 -04:00
|
|
|
err_msg("after_heap: " PTR_FORMAT " is unexpectedly in the heap", p2i(after_heap)));
|
2011-12-14 12:15:26 +01:00
|
|
|
}
|
|
|
|
#endif
|