Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/memory/generation.cpp
32285 views
/*1* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "gc_implementation/shared/gcTimer.hpp"26#include "gc_implementation/shared/gcTrace.hpp"27#include "gc_implementation/shared/spaceDecorator.hpp"28#include "gc_interface/collectedHeap.inline.hpp"29#include "memory/allocation.inline.hpp"30#include "memory/blockOffsetTable.inline.hpp"31#include "memory/cardTableRS.hpp"32#include "memory/gcLocker.inline.hpp"33#include "memory/genCollectedHeap.hpp"34#include "memory/genMarkSweep.hpp"35#include "memory/genOopClosures.hpp"36#include "memory/genOopClosures.inline.hpp"37#include "memory/generation.hpp"38#include "memory/generation.inline.hpp"39#include "memory/space.inline.hpp"40#include "oops/oop.inline.hpp"41#include "runtime/java.hpp"42#include "utilities/copy.hpp"43#include "utilities/events.hpp"4445PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC4647Generation::Generation(ReservedSpace rs, size_t initial_size, int level) :48_level(level),49_ref_processor(NULL) {50if (!_virtual_space.initialize(rs, initial_size)) {51vm_exit_during_initialization("Could not reserve enough space for "52"object heap");53}54// Mangle all of the the initial generation.55if (ZapUnusedHeapArea) {56MemRegion mangle_region((HeapWord*)_virtual_space.low(),57(HeapWord*)_virtual_space.high());58SpaceMangler::mangle_region(mangle_region);59}60_reserved = MemRegion((HeapWord*)_virtual_space.low_boundary(),61(HeapWord*)_virtual_space.high_boundary());62}6364GenerationSpec* Generation::spec() {65GenCollectedHeap* gch = GenCollectedHeap::heap();66assert(0 <= level() && level() < gch->_n_gens, "Bad gen level");67return gch->_gen_specs[level()];68}6970// This is for CMS. It returns stable monotonic used space size.71// Remove this when CMS is removed.72size_t Generation::used_stable() const {73return used();74}7576size_t Generation::max_capacity() const {77return reserved().byte_size();78}7980void Generation::print_heap_change(size_t prev_used) const {81if (PrintGCDetails && Verbose) {82gclog_or_tty->print(" " SIZE_FORMAT83"->" SIZE_FORMAT84"(" SIZE_FORMAT ")",85prev_used, used(), capacity());86} else {87gclog_or_tty->print(" " SIZE_FORMAT "K"88"->" SIZE_FORMAT "K"89"(" SIZE_FORMAT "K)",90prev_used / K, used() / K, capacity() / K);91}92}9394// By default we get a single threaded default reference processor;95// generations needing multi-threaded refs processing or discovery override this method.96void Generation::ref_processor_init() {97assert(_ref_processor == NULL, "a reference processor already exists");98assert(!_reserved.is_empty(), "empty generation?");99_ref_processor = new ReferenceProcessor(_reserved); // a vanilla reference processor100if (_ref_processor == NULL) {101vm_exit_during_initialization("Could not allocate ReferenceProcessor object");102}103}104105void Generation::print() const { print_on(tty); }106107void Generation::print_on(outputStream* st) const {108st->print(" %-20s", name());109st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",110capacity()/K, used()/K);111st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",112_virtual_space.low_boundary(),113_virtual_space.high(),114_virtual_space.high_boundary());115}116117void Generation::print_summary_info() { print_summary_info_on(tty); }118119void Generation::print_summary_info_on(outputStream* st) {120StatRecord* sr = stat_record();121double time = sr->accumulated_time.seconds();122st->print_cr("[Accumulated GC generation %d time %3.7f secs, "123"%d GC's, avg GC time %3.7f]",124level(), time, sr->invocations,125sr->invocations > 0 ? time / sr->invocations : 0.0);126}127128// Utility iterator classes129130class GenerationIsInReservedClosure : public SpaceClosure {131public:132const void* _p;133Space* sp;134virtual void do_space(Space* s) {135if (sp == NULL) {136if (s->is_in_reserved(_p)) sp = s;137}138}139GenerationIsInReservedClosure(const void* p) : _p(p), sp(NULL) {}140};141142class GenerationIsInClosure : public SpaceClosure {143public:144const void* _p;145Space* sp;146virtual void do_space(Space* s) {147if (sp == NULL) {148if (s->is_in(_p)) sp = s;149}150}151GenerationIsInClosure(const void* p) : _p(p), sp(NULL) {}152};153154bool Generation::is_in(const void* p) const {155GenerationIsInClosure blk(p);156((Generation*)this)->space_iterate(&blk);157return blk.sp != NULL;158}159160DefNewGeneration* Generation::as_DefNewGeneration() {161assert((kind() == Generation::DefNew) ||162(kind() == Generation::ParNew) ||163(kind() == Generation::ASParNew),164"Wrong youngest generation type");165return (DefNewGeneration*) this;166}167168Generation* Generation::next_gen() const {169GenCollectedHeap* gch = GenCollectedHeap::heap();170int next = level() + 1;171if (next < gch->_n_gens) {172return gch->_gens[next];173} else {174return NULL;175}176}177178size_t Generation::max_contiguous_available() const {179// The largest number of contiguous free words in this or any higher generation.180size_t max = 0;181for (const Generation* gen = this; gen != NULL; gen = gen->next_gen()) {182size_t avail = gen->contiguous_available();183if (avail > max) {184max = avail;185}186}187return max;188}189190bool Generation::promotion_attempt_is_safe(size_t max_promotion_in_bytes) const {191size_t available = max_contiguous_available();192bool res = (available >= max_promotion_in_bytes);193if (PrintGC && Verbose) {194gclog_or_tty->print_cr(195"Generation: promo attempt is%s safe: available(" SIZE_FORMAT ") %s max_promo(" SIZE_FORMAT ")",196res? "":" not", available, res? ">=":"<",197max_promotion_in_bytes);198}199return res;200}201202// Ignores "ref" and calls allocate().203oop Generation::promote(oop obj, size_t obj_size) {204assert(obj_size == (size_t)obj->size(), "bad obj_size passed in");205206#ifndef PRODUCT207if (Universe::heap()->promotion_should_fail()) {208return NULL;209}210#endif // #ifndef PRODUCT211212HeapWord* result = allocate(obj_size, false);213if (result != NULL) {214Copy::aligned_disjoint_words((HeapWord*)obj, result, obj_size);215return oop(result);216} else {217GenCollectedHeap* gch = GenCollectedHeap::heap();218return gch->handle_failed_promotion(this, obj, obj_size);219}220}221222oop Generation::par_promote(int thread_num,223oop obj, markOop m, size_t word_sz) {224// Could do a bad general impl here that gets a lock. But no.225ShouldNotCallThis();226return NULL;227}228229void Generation::par_promote_alloc_undo(int thread_num,230HeapWord* obj, size_t word_sz) {231// Could do a bad general impl here that gets a lock. But no.232guarantee(false, "No good general implementation.");233}234235Space* Generation::space_containing(const void* p) const {236GenerationIsInReservedClosure blk(p);237// Cast away const238((Generation*)this)->space_iterate(&blk);239return blk.sp;240}241242// Some of these are mediocre general implementations. Should be243// overridden to get better performance.244245class GenerationBlockStartClosure : public SpaceClosure {246public:247const void* _p;248HeapWord* _start;249virtual void do_space(Space* s) {250if (_start == NULL && s->is_in_reserved(_p)) {251_start = s->block_start(_p);252}253}254GenerationBlockStartClosure(const void* p) { _p = p; _start = NULL; }255};256257HeapWord* Generation::block_start(const void* p) const {258GenerationBlockStartClosure blk(p);259// Cast away const260((Generation*)this)->space_iterate(&blk);261return blk._start;262}263264class GenerationBlockSizeClosure : public SpaceClosure {265public:266const HeapWord* _p;267size_t size;268virtual void do_space(Space* s) {269if (size == 0 && s->is_in_reserved(_p)) {270size = s->block_size(_p);271}272}273GenerationBlockSizeClosure(const HeapWord* p) { _p = p; size = 0; }274};275276size_t Generation::block_size(const HeapWord* p) const {277GenerationBlockSizeClosure blk(p);278// Cast away const279((Generation*)this)->space_iterate(&blk);280assert(blk.size > 0, "seems reasonable");281return blk.size;282}283284class GenerationBlockIsObjClosure : public SpaceClosure {285public:286const HeapWord* _p;287bool is_obj;288virtual void do_space(Space* s) {289if (!is_obj && s->is_in_reserved(_p)) {290is_obj |= s->block_is_obj(_p);291}292}293GenerationBlockIsObjClosure(const HeapWord* p) { _p = p; is_obj = false; }294};295296bool Generation::block_is_obj(const HeapWord* p) const {297GenerationBlockIsObjClosure blk(p);298// Cast away const299((Generation*)this)->space_iterate(&blk);300return blk.is_obj;301}302303class GenerationOopIterateClosure : public SpaceClosure {304public:305ExtendedOopClosure* _cl;306virtual void do_space(Space* s) {307s->oop_iterate(_cl);308}309GenerationOopIterateClosure(ExtendedOopClosure* cl) :310_cl(cl) {}311};312313void Generation::oop_iterate(ExtendedOopClosure* cl) {314GenerationOopIterateClosure blk(cl);315space_iterate(&blk);316}317318void Generation::younger_refs_in_space_iterate(Space* sp,319OopsInGenClosure* cl) {320GenRemSet* rs = SharedHeap::heap()->rem_set();321rs->younger_refs_in_space_iterate(sp, cl);322}323324class GenerationObjIterateClosure : public SpaceClosure {325private:326ObjectClosure* _cl;327public:328virtual void do_space(Space* s) {329s->object_iterate(_cl);330}331GenerationObjIterateClosure(ObjectClosure* cl) : _cl(cl) {}332};333334void Generation::object_iterate(ObjectClosure* cl) {335GenerationObjIterateClosure blk(cl);336space_iterate(&blk);337}338339class GenerationSafeObjIterateClosure : public SpaceClosure {340private:341ObjectClosure* _cl;342public:343virtual void do_space(Space* s) {344s->safe_object_iterate(_cl);345}346GenerationSafeObjIterateClosure(ObjectClosure* cl) : _cl(cl) {}347};348349void Generation::safe_object_iterate(ObjectClosure* cl) {350GenerationSafeObjIterateClosure blk(cl);351space_iterate(&blk);352}353354void Generation::prepare_for_compaction(CompactPoint* cp) {355// Generic implementation, can be specialized356CompactibleSpace* space = first_compaction_space();357while (space != NULL) {358space->prepare_for_compaction(cp);359space = space->next_compaction_space();360}361}362363class AdjustPointersClosure: public SpaceClosure {364public:365void do_space(Space* sp) {366sp->adjust_pointers();367}368};369370void Generation::adjust_pointers() {371// Note that this is done over all spaces, not just the compactible372// ones.373AdjustPointersClosure blk;374space_iterate(&blk, true);375}376377void Generation::compact() {378CompactibleSpace* sp = first_compaction_space();379while (sp != NULL) {380sp->compact();381sp = sp->next_compaction_space();382}383}384385CardGeneration::CardGeneration(ReservedSpace rs, size_t initial_byte_size,386int level,387GenRemSet* remset) :388Generation(rs, initial_byte_size, level), _rs(remset),389_shrink_factor(0), _min_heap_delta_bytes(), _capacity_at_prologue(),390_used_at_prologue()391{392HeapWord* start = (HeapWord*)rs.base();393size_t reserved_byte_size = rs.size();394assert((uintptr_t(start) & 3) == 0, "bad alignment");395assert((reserved_byte_size & 3) == 0, "bad alignment");396MemRegion reserved_mr(start, heap_word_size(reserved_byte_size));397_bts = new BlockOffsetSharedArray(reserved_mr,398heap_word_size(initial_byte_size));399MemRegion committed_mr(start, heap_word_size(initial_byte_size));400_rs->resize_covered_region(committed_mr);401if (_bts == NULL)402vm_exit_during_initialization("Could not allocate a BlockOffsetArray");403404// Verify that the start and end of this generation is the start of a card.405// If this wasn't true, a single card could span more than on generation,406// which would cause problems when we commit/uncommit memory, and when we407// clear and dirty cards.408guarantee(_rs->is_aligned(reserved_mr.start()), "generation must be card aligned");409if (reserved_mr.end() != Universe::heap()->reserved_region().end()) {410// Don't check at the very end of the heap as we'll assert that we're probing off411// the end if we try.412guarantee(_rs->is_aligned(reserved_mr.end()), "generation must be card aligned");413}414_min_heap_delta_bytes = MinHeapDeltaBytes;415_capacity_at_prologue = initial_byte_size;416_used_at_prologue = 0;417}418419bool CardGeneration::expand(size_t bytes, size_t expand_bytes) {420assert_locked_or_safepoint(Heap_lock);421if (bytes == 0) {422return true; // That's what grow_by(0) would return423}424size_t aligned_bytes = ReservedSpace::page_align_size_up(bytes);425if (aligned_bytes == 0){426// The alignment caused the number of bytes to wrap. An expand_by(0) will427// return true with the implication that an expansion was done when it428// was not. A call to expand implies a best effort to expand by "bytes"429// but not a guarantee. Align down to give a best effort. This is likely430// the most that the generation can expand since it has some capacity to431// start with.432aligned_bytes = ReservedSpace::page_align_size_down(bytes);433}434size_t aligned_expand_bytes = ReservedSpace::page_align_size_up(expand_bytes);435bool success = false;436if (aligned_expand_bytes > aligned_bytes) {437success = grow_by(aligned_expand_bytes);438}439if (!success) {440success = grow_by(aligned_bytes);441}442if (!success) {443success = grow_to_reserved();444}445if (PrintGC && Verbose) {446if (success && GC_locker::is_active_and_needs_gc()) {447gclog_or_tty->print_cr("Garbage collection disabled, expanded heap instead");448}449}450451return success;452}453454455// No young generation references, clear this generation's cards.456void CardGeneration::clear_remembered_set() {457_rs->clear(reserved());458}459460461// Objects in this generation may have moved, invalidate this462// generation's cards.463void CardGeneration::invalidate_remembered_set() {464_rs->invalidate(used_region());465}466467468void CardGeneration::compute_new_size() {469assert(_shrink_factor <= 100, "invalid shrink factor");470size_t current_shrink_factor = _shrink_factor;471_shrink_factor = 0;472473// We don't have floating point command-line arguments474// Note: argument processing ensures that MinHeapFreeRatio < 100.475const double minimum_free_percentage = MinHeapFreeRatio / 100.0;476const double maximum_used_percentage = 1.0 - minimum_free_percentage;477478// Compute some numbers about the state of the heap.479const size_t used_after_gc = used();480const size_t capacity_after_gc = capacity();481482const double min_tmp = used_after_gc / maximum_used_percentage;483size_t minimum_desired_capacity = (size_t)MIN2(min_tmp, double(max_uintx));484// Don't shrink less than the initial generation size485minimum_desired_capacity = MAX2(minimum_desired_capacity,486spec()->init_size());487assert(used_after_gc <= minimum_desired_capacity, "sanity check");488489if (PrintGC && Verbose) {490const size_t free_after_gc = free();491const double free_percentage = ((double)free_after_gc) / capacity_after_gc;492gclog_or_tty->print_cr("TenuredGeneration::compute_new_size: ");493gclog_or_tty->print_cr(" "494" minimum_free_percentage: %6.2f"495" maximum_used_percentage: %6.2f",496minimum_free_percentage,497maximum_used_percentage);498gclog_or_tty->print_cr(" "499" free_after_gc : %6.1fK"500" used_after_gc : %6.1fK"501" capacity_after_gc : %6.1fK",502free_after_gc / (double) K,503used_after_gc / (double) K,504capacity_after_gc / (double) K);505gclog_or_tty->print_cr(" "506" free_percentage: %6.2f",507free_percentage);508}509510if (capacity_after_gc < minimum_desired_capacity) {511// If we have less free space than we want then expand512size_t expand_bytes = minimum_desired_capacity - capacity_after_gc;513// Don't expand unless it's significant514if (expand_bytes >= _min_heap_delta_bytes) {515expand(expand_bytes, 0); // safe if expansion fails516}517if (PrintGC && Verbose) {518gclog_or_tty->print_cr(" expanding:"519" minimum_desired_capacity: %6.1fK"520" expand_bytes: %6.1fK"521" _min_heap_delta_bytes: %6.1fK",522minimum_desired_capacity / (double) K,523expand_bytes / (double) K,524_min_heap_delta_bytes / (double) K);525}526return;527}528529// No expansion, now see if we want to shrink530size_t shrink_bytes = 0;531// We would never want to shrink more than this532size_t max_shrink_bytes = capacity_after_gc - minimum_desired_capacity;533534if (MaxHeapFreeRatio < 100) {535const double maximum_free_percentage = MaxHeapFreeRatio / 100.0;536const double minimum_used_percentage = 1.0 - maximum_free_percentage;537const double max_tmp = used_after_gc / minimum_used_percentage;538size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx));539maximum_desired_capacity = MAX2(maximum_desired_capacity,540spec()->init_size());541if (PrintGC && Verbose) {542gclog_or_tty->print_cr(" "543" maximum_free_percentage: %6.2f"544" minimum_used_percentage: %6.2f",545maximum_free_percentage,546minimum_used_percentage);547gclog_or_tty->print_cr(" "548" _capacity_at_prologue: %6.1fK"549" minimum_desired_capacity: %6.1fK"550" maximum_desired_capacity: %6.1fK",551_capacity_at_prologue / (double) K,552minimum_desired_capacity / (double) K,553maximum_desired_capacity / (double) K);554}555assert(minimum_desired_capacity <= maximum_desired_capacity,556"sanity check");557558if (capacity_after_gc > maximum_desired_capacity) {559// Capacity too large, compute shrinking size560shrink_bytes = capacity_after_gc - maximum_desired_capacity;561// We don't want shrink all the way back to initSize if people call562// System.gc(), because some programs do that between "phases" and then563// we'd just have to grow the heap up again for the next phase. So we564// damp the shrinking: 0% on the first call, 10% on the second call, 40%565// on the third call, and 100% by the fourth call. But if we recompute566// size without shrinking, it goes back to 0%.567shrink_bytes = shrink_bytes / 100 * current_shrink_factor;568assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size");569if (current_shrink_factor == 0) {570_shrink_factor = 10;571} else {572_shrink_factor = MIN2(current_shrink_factor * 4, (size_t) 100);573}574if (PrintGC && Verbose) {575gclog_or_tty->print_cr(" "576" shrinking:"577" initSize: %.1fK"578" maximum_desired_capacity: %.1fK",579spec()->init_size() / (double) K,580maximum_desired_capacity / (double) K);581gclog_or_tty->print_cr(" "582" shrink_bytes: %.1fK"583" current_shrink_factor: %d"584" new shrink factor: %d"585" _min_heap_delta_bytes: %.1fK",586shrink_bytes / (double) K,587current_shrink_factor,588_shrink_factor,589_min_heap_delta_bytes / (double) K);590}591}592}593594if (capacity_after_gc > _capacity_at_prologue) {595// We might have expanded for promotions, in which case we might want to596// take back that expansion if there's room after GC. That keeps us from597// stretching the heap with promotions when there's plenty of room.598size_t expansion_for_promotion = capacity_after_gc - _capacity_at_prologue;599expansion_for_promotion = MIN2(expansion_for_promotion, max_shrink_bytes);600// We have two shrinking computations, take the largest601shrink_bytes = MAX2(shrink_bytes, expansion_for_promotion);602assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size");603if (PrintGC && Verbose) {604gclog_or_tty->print_cr(" "605" aggressive shrinking:"606" _capacity_at_prologue: %.1fK"607" capacity_after_gc: %.1fK"608" expansion_for_promotion: %.1fK"609" shrink_bytes: %.1fK",610capacity_after_gc / (double) K,611_capacity_at_prologue / (double) K,612expansion_for_promotion / (double) K,613shrink_bytes / (double) K);614}615}616// Don't shrink unless it's significant617if (shrink_bytes >= _min_heap_delta_bytes) {618shrink(shrink_bytes);619}620}621622// Currently nothing to do.623void CardGeneration::prepare_for_verify() {}624625626void OneContigSpaceCardGeneration::collect(bool full,627bool clear_all_soft_refs,628size_t size,629bool is_tlab) {630GenCollectedHeap* gch = GenCollectedHeap::heap();631632SpecializationStats::clear();633// Temporarily expand the span of our ref processor, so634// refs discovery is over the entire heap, not just this generation635ReferenceProcessorSpanMutator636x(ref_processor(), gch->reserved_region());637638STWGCTimer* gc_timer = GenMarkSweep::gc_timer();639gc_timer->register_gc_start();640641SerialOldTracer* gc_tracer = GenMarkSweep::gc_tracer();642gc_tracer->report_gc_start(gch->gc_cause(), gc_timer->gc_start());643644GenMarkSweep::invoke_at_safepoint(_level, ref_processor(), clear_all_soft_refs);645646gc_timer->register_gc_end();647648gc_tracer->report_gc_end(gc_timer->gc_end(), gc_timer->time_partitions());649650SpecializationStats::print();651}652653HeapWord*654OneContigSpaceCardGeneration::expand_and_allocate(size_t word_size,655bool is_tlab,656bool parallel) {657assert(!is_tlab, "OneContigSpaceCardGeneration does not support TLAB allocation");658if (parallel) {659MutexLocker x(ParGCRareEvent_lock);660HeapWord* result = NULL;661size_t byte_size = word_size * HeapWordSize;662while (true) {663expand(byte_size, _min_heap_delta_bytes);664if (GCExpandToAllocateDelayMillis > 0) {665os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false);666}667result = _the_space->par_allocate(word_size);668if ( result != NULL) {669return result;670} else {671// If there's not enough expansion space available, give up.672if (_virtual_space.uncommitted_size() < byte_size) {673return NULL;674}675// else try again676}677}678} else {679expand(word_size*HeapWordSize, _min_heap_delta_bytes);680return _the_space->allocate(word_size);681}682}683684bool OneContigSpaceCardGeneration::expand(size_t bytes, size_t expand_bytes) {685GCMutexLocker x(ExpandHeap_lock);686return CardGeneration::expand(bytes, expand_bytes);687}688689690void OneContigSpaceCardGeneration::shrink(size_t bytes) {691assert_locked_or_safepoint(ExpandHeap_lock);692size_t size = ReservedSpace::page_align_size_down(bytes);693if (size > 0) {694shrink_by(size);695}696}697698699size_t OneContigSpaceCardGeneration::capacity() const {700return _the_space->capacity();701}702703704size_t OneContigSpaceCardGeneration::used() const {705return _the_space->used();706}707708709size_t OneContigSpaceCardGeneration::free() const {710return _the_space->free();711}712713MemRegion OneContigSpaceCardGeneration::used_region() const {714return the_space()->used_region();715}716717size_t OneContigSpaceCardGeneration::unsafe_max_alloc_nogc() const {718return _the_space->free();719}720721size_t OneContigSpaceCardGeneration::contiguous_available() const {722return _the_space->free() + _virtual_space.uncommitted_size();723}724725bool OneContigSpaceCardGeneration::grow_by(size_t bytes) {726assert_locked_or_safepoint(ExpandHeap_lock);727bool result = _virtual_space.expand_by(bytes);728if (result) {729size_t new_word_size =730heap_word_size(_virtual_space.committed_size());731MemRegion mr(_the_space->bottom(), new_word_size);732// Expand card table733Universe::heap()->barrier_set()->resize_covered_region(mr);734// Expand shared block offset array735_bts->resize(new_word_size);736737// Fix for bug #4668531738if (ZapUnusedHeapArea) {739MemRegion mangle_region(_the_space->end(),740(HeapWord*)_virtual_space.high());741SpaceMangler::mangle_region(mangle_region);742}743744// Expand space -- also expands space's BOT745// (which uses (part of) shared array above)746_the_space->set_end((HeapWord*)_virtual_space.high());747748// update the space and generation capacity counters749update_counters();750751if (Verbose && PrintGC) {752size_t new_mem_size = _virtual_space.committed_size();753size_t old_mem_size = new_mem_size - bytes;754gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by "755SIZE_FORMAT "K to " SIZE_FORMAT "K",756name(), old_mem_size/K, bytes/K, new_mem_size/K);757}758}759return result;760}761762763bool OneContigSpaceCardGeneration::grow_to_reserved() {764assert_locked_or_safepoint(ExpandHeap_lock);765bool success = true;766const size_t remaining_bytes = _virtual_space.uncommitted_size();767if (remaining_bytes > 0) {768success = grow_by(remaining_bytes);769DEBUG_ONLY(if (!success) warning("grow to reserved failed");)770}771return success;772}773774void OneContigSpaceCardGeneration::shrink_by(size_t bytes) {775assert_locked_or_safepoint(ExpandHeap_lock);776// Shrink committed space777_virtual_space.shrink_by(bytes);778// Shrink space; this also shrinks the space's BOT779_the_space->set_end((HeapWord*) _virtual_space.high());780size_t new_word_size = heap_word_size(_the_space->capacity());781// Shrink the shared block offset array782_bts->resize(new_word_size);783MemRegion mr(_the_space->bottom(), new_word_size);784// Shrink the card table785Universe::heap()->barrier_set()->resize_covered_region(mr);786787if (Verbose && PrintGC) {788size_t new_mem_size = _virtual_space.committed_size();789size_t old_mem_size = new_mem_size + bytes;790gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K",791name(), old_mem_size/K, new_mem_size/K);792}793}794795// Currently nothing to do.796void OneContigSpaceCardGeneration::prepare_for_verify() {}797798799// Override for a card-table generation with one contiguous800// space. NOTE: For reasons that are lost in the fog of history,801// this code is used when you iterate over perm gen objects,802// even when one uses CDS, where the perm gen has a couple of803// other spaces; this is because CompactingPermGenGen derives804// from OneContigSpaceCardGeneration. This should be cleaned up,805// see CR 6897789..806void OneContigSpaceCardGeneration::object_iterate(ObjectClosure* blk) {807_the_space->object_iterate(blk);808}809810void OneContigSpaceCardGeneration::space_iterate(SpaceClosure* blk,811bool usedOnly) {812blk->do_space(_the_space);813}814815void OneContigSpaceCardGeneration::younger_refs_iterate(OopsInGenClosure* blk) {816blk->set_generation(this);817younger_refs_in_space_iterate(_the_space, blk);818blk->reset_generation();819}820821void OneContigSpaceCardGeneration::save_marks() {822_the_space->set_saved_mark();823}824825826void OneContigSpaceCardGeneration::reset_saved_marks() {827_the_space->reset_saved_mark();828}829830831bool OneContigSpaceCardGeneration::no_allocs_since_save_marks() {832return _the_space->saved_mark_at_top();833}834835#define OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN(OopClosureType, nv_suffix) \836\837void OneContigSpaceCardGeneration:: \838oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk) { \839blk->set_generation(this); \840_the_space->oop_since_save_marks_iterate##nv_suffix(blk); \841blk->reset_generation(); \842save_marks(); \843}844845ALL_SINCE_SAVE_MARKS_CLOSURES(OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN)846847#undef OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN848849850void OneContigSpaceCardGeneration::gc_epilogue(bool full) {851_last_gc = WaterMark(the_space(), the_space()->top());852853// update the generation and space performance counters854update_counters();855if (ZapUnusedHeapArea) {856the_space()->check_mangled_unused_area_complete();857}858}859860void OneContigSpaceCardGeneration::record_spaces_top() {861assert(ZapUnusedHeapArea, "Not mangling unused space");862the_space()->set_top_for_allocations();863}864865void OneContigSpaceCardGeneration::verify() {866the_space()->verify();867}868869void OneContigSpaceCardGeneration::print_on(outputStream* st) const {870Generation::print_on(st);871st->print(" the");872the_space()->print_on(st);873}874875876