Path: blob/master/src/hotspot/share/gc/parallel/psScavenge.cpp
41149 views
/*1* Copyright (c) 2002, 2021, 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 "classfile/classLoaderDataGraph.hpp"26#include "classfile/stringTable.hpp"27#include "code/codeCache.hpp"28#include "compiler/oopMap.hpp"29#include "gc/parallel/parallelScavengeHeap.hpp"30#include "gc/parallel/psAdaptiveSizePolicy.hpp"31#include "gc/parallel/psClosure.inline.hpp"32#include "gc/parallel/psCompactionManager.hpp"33#include "gc/parallel/psParallelCompact.inline.hpp"34#include "gc/parallel/psPromotionManager.inline.hpp"35#include "gc/parallel/psRootType.hpp"36#include "gc/parallel/psScavenge.inline.hpp"37#include "gc/shared/gcCause.hpp"38#include "gc/shared/gcHeapSummary.hpp"39#include "gc/shared/gcId.hpp"40#include "gc/shared/gcLocker.hpp"41#include "gc/shared/gcTimer.hpp"42#include "gc/shared/gcTrace.hpp"43#include "gc/shared/gcTraceTime.inline.hpp"44#include "gc/shared/isGCActiveMark.hpp"45#include "gc/shared/oopStorage.inline.hpp"46#include "gc/shared/oopStorageSetParState.inline.hpp"47#include "gc/shared/oopStorageParState.inline.hpp"48#include "gc/shared/referencePolicy.hpp"49#include "gc/shared/referenceProcessor.hpp"50#include "gc/shared/referenceProcessorPhaseTimes.hpp"51#include "gc/shared/scavengableNMethods.hpp"52#include "gc/shared/spaceDecorator.inline.hpp"53#include "gc/shared/taskTerminator.hpp"54#include "gc/shared/weakProcessor.inline.hpp"55#include "gc/shared/workerPolicy.hpp"56#include "gc/shared/workgroup.hpp"57#include "memory/iterator.hpp"58#include "memory/resourceArea.hpp"59#include "memory/universe.hpp"60#include "logging/log.hpp"61#include "oops/access.inline.hpp"62#include "oops/compressedOops.inline.hpp"63#include "oops/oop.inline.hpp"64#include "runtime/biasedLocking.hpp"65#include "runtime/handles.inline.hpp"66#include "runtime/threadCritical.hpp"67#include "runtime/vmThread.hpp"68#include "runtime/vmOperations.hpp"69#include "services/memoryService.hpp"70#include "utilities/stack.inline.hpp"7172HeapWord* PSScavenge::_to_space_top_before_gc = NULL;73int PSScavenge::_consecutive_skipped_scavenges = 0;74SpanSubjectToDiscoveryClosure PSScavenge::_span_based_discoverer;75ReferenceProcessor* PSScavenge::_ref_processor = NULL;76PSCardTable* PSScavenge::_card_table = NULL;77bool PSScavenge::_survivor_overflow = false;78uint PSScavenge::_tenuring_threshold = 0;79HeapWord* PSScavenge::_young_generation_boundary = NULL;80uintptr_t PSScavenge::_young_generation_boundary_compressed = 0;81elapsedTimer PSScavenge::_accumulated_time;82STWGCTimer PSScavenge::_gc_timer;83ParallelScavengeTracer PSScavenge::_gc_tracer;84CollectorCounters* PSScavenge::_counters = NULL;8586static void scavenge_roots_work(ParallelRootType::Value root_type, uint worker_id) {87assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");8889PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(worker_id);90PSScavengeRootsClosure roots_closure(pm);91PSPromoteRootsClosure roots_to_old_closure(pm);9293switch (root_type) {94case ParallelRootType::class_loader_data:95{96PSScavengeCLDClosure cld_closure(pm);97ClassLoaderDataGraph::cld_do(&cld_closure);98}99break;100101case ParallelRootType::code_cache:102{103MarkingCodeBlobClosure code_closure(&roots_to_old_closure, CodeBlobToOopClosure::FixRelocations);104ScavengableNMethods::nmethods_do(&code_closure);105}106break;107108case ParallelRootType::sentinel:109DEBUG_ONLY(default:) // DEBUG_ONLY hack will create compile error on release builds (-Wswitch) and runtime check on debug builds110fatal("Bad enumeration value: %u", root_type);111break;112}113114// Do the real work115pm->drain_stacks(false);116}117118static void steal_work(TaskTerminator& terminator, uint worker_id) {119assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");120121PSPromotionManager* pm =122PSPromotionManager::gc_thread_promotion_manager(worker_id);123pm->drain_stacks(true);124guarantee(pm->stacks_empty(),125"stacks should be empty at this point");126127while (true) {128ScannerTask task;129if (PSPromotionManager::steal_depth(worker_id, task)) {130TASKQUEUE_STATS_ONLY(pm->record_steal(task));131pm->process_popped_location_depth(task);132pm->drain_stacks_depth(true);133} else {134if (terminator.offer_termination()) {135break;136}137}138}139guarantee(pm->stacks_empty(), "stacks should be empty at this point");140}141142// Define before use143class PSIsAliveClosure: public BoolObjectClosure {144public:145bool do_object_b(oop p) {146return (!PSScavenge::is_obj_in_young(p)) || p->is_forwarded();147}148};149150PSIsAliveClosure PSScavenge::_is_alive_closure;151152class PSKeepAliveClosure: public OopClosure {153protected:154MutableSpace* _to_space;155PSPromotionManager* _promotion_manager;156157public:158PSKeepAliveClosure(PSPromotionManager* pm) : _promotion_manager(pm) {159ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();160_to_space = heap->young_gen()->to_space();161162assert(_promotion_manager != NULL, "Sanity");163}164165template <class T> void do_oop_work(T* p) {166assert (oopDesc::is_oop(RawAccess<IS_NOT_NULL>::oop_load(p)),167"expected an oop while scanning weak refs");168169// Weak refs may be visited more than once.170if (PSScavenge::should_scavenge(p, _to_space)) {171_promotion_manager->copy_and_push_safe_barrier</*promote_immediately=*/false>(p);172}173}174virtual void do_oop(oop* p) { PSKeepAliveClosure::do_oop_work(p); }175virtual void do_oop(narrowOop* p) { PSKeepAliveClosure::do_oop_work(p); }176};177178class PSEvacuateFollowersClosure: public VoidClosure {179private:180PSPromotionManager* _promotion_manager;181TaskTerminator* _terminator;182uint _worker_id;183184public:185PSEvacuateFollowersClosure(PSPromotionManager* pm, TaskTerminator* terminator, uint worker_id)186: _promotion_manager(pm), _terminator(terminator), _worker_id(worker_id) {}187188virtual void do_void() {189assert(_promotion_manager != nullptr, "Sanity");190_promotion_manager->drain_stacks(true);191guarantee(_promotion_manager->stacks_empty(),192"stacks should be empty at this point");193194if (_terminator != nullptr) {195steal_work(*_terminator, _worker_id);196}197}198};199200class ParallelScavengeRefProcProxyTask : public RefProcProxyTask {201TaskTerminator _terminator;202203public:204ParallelScavengeRefProcProxyTask(uint max_workers)205: RefProcProxyTask("ParallelScavengeRefProcProxyTask", max_workers),206_terminator(max_workers, ParCompactionManager::oop_task_queues()) {}207208void work(uint worker_id) override {209assert(worker_id < _max_workers, "sanity");210PSPromotionManager* promotion_manager = (_tm == RefProcThreadModel::Single) ? PSPromotionManager::vm_thread_promotion_manager() : PSPromotionManager::gc_thread_promotion_manager(worker_id);211PSIsAliveClosure is_alive;212PSKeepAliveClosure keep_alive(promotion_manager);;213PSEvacuateFollowersClosure complete_gc(promotion_manager, (_marks_oops_alive && _tm == RefProcThreadModel::Multi) ? &_terminator : nullptr, worker_id);;214_rp_task->rp_work(worker_id, &is_alive, &keep_alive, &complete_gc);215}216217void prepare_run_task_hook() override {218_terminator.reset_for_reuse(_queue_count);219}220};221222// This method contains all heap specific policy for invoking scavenge.223// PSScavenge::invoke_no_policy() will do nothing but attempt to224// scavenge. It will not clean up after failed promotions, bail out if225// we've exceeded policy time limits, or any other special behavior.226// All such policy should be placed here.227//228// Note that this method should only be called from the vm_thread while229// at a safepoint!230bool PSScavenge::invoke() {231assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");232assert(Thread::current() == (Thread*)VMThread::vm_thread(), "should be in vm thread");233assert(!ParallelScavengeHeap::heap()->is_gc_active(), "not reentrant");234235ParallelScavengeHeap* const heap = ParallelScavengeHeap::heap();236PSAdaptiveSizePolicy* policy = heap->size_policy();237IsGCActiveMark mark;238239const bool scavenge_done = PSScavenge::invoke_no_policy();240const bool need_full_gc = !scavenge_done ||241policy->should_full_GC(heap->old_gen()->free_in_bytes());242bool full_gc_done = false;243244if (UsePerfData) {245PSGCAdaptivePolicyCounters* const counters = heap->gc_policy_counters();246const int ffs_val = need_full_gc ? full_follows_scavenge : not_skipped;247counters->update_full_follows_scavenge(ffs_val);248}249250if (need_full_gc) {251GCCauseSetter gccs(heap, GCCause::_adaptive_size_policy);252SoftRefPolicy* srp = heap->soft_ref_policy();253const bool clear_all_softrefs = srp->should_clear_all_soft_refs();254255full_gc_done = PSParallelCompact::invoke_no_policy(clear_all_softrefs);256}257258return full_gc_done;259}260261class PSThreadRootsTaskClosure : public ThreadClosure {262uint _worker_id;263public:264PSThreadRootsTaskClosure(uint worker_id) : _worker_id(worker_id) { }265virtual void do_thread(Thread* thread) {266assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");267268PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(_worker_id);269PSScavengeRootsClosure roots_closure(pm);270MarkingCodeBlobClosure roots_in_blobs(&roots_closure, CodeBlobToOopClosure::FixRelocations);271272thread->oops_do(&roots_closure, &roots_in_blobs);273274// Do the real work275pm->drain_stacks(false);276}277};278279class ScavengeRootsTask : public AbstractGangTask {280StrongRootsScope _strong_roots_scope; // needed for Threads::possibly_parallel_threads_do281OopStorageSetStrongParState<false /* concurrent */, false /* is_const */> _oop_storage_strong_par_state;282SequentialSubTasksDone _subtasks;283PSOldGen* _old_gen;284HeapWord* _gen_top;285uint _active_workers;286bool _is_empty;287TaskTerminator _terminator;288289public:290ScavengeRootsTask(PSOldGen* old_gen,291HeapWord* gen_top,292uint active_workers,293bool is_empty) :294AbstractGangTask("ScavengeRootsTask"),295_strong_roots_scope(active_workers),296_subtasks(ParallelRootType::sentinel),297_old_gen(old_gen),298_gen_top(gen_top),299_active_workers(active_workers),300_is_empty(is_empty),301_terminator(active_workers, PSPromotionManager::vm_thread_promotion_manager()->stack_array_depth()) {302}303304virtual void work(uint worker_id) {305ResourceMark rm;306307if (!_is_empty) {308// There are only old-to-young pointers if there are objects309// in the old gen.310311assert(_old_gen != NULL, "Sanity");312// There are no old-to-young pointers if the old gen is empty.313assert(!_old_gen->object_space()->is_empty(), "Should not be called is there is no work");314assert(_old_gen->object_space()->contains(_gen_top) || _gen_top == _old_gen->object_space()->top(), "Sanity");315assert(worker_id < ParallelGCThreads, "Sanity");316317{318PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(worker_id);319PSCardTable* card_table = ParallelScavengeHeap::heap()->card_table();320321card_table->scavenge_contents_parallel(_old_gen->start_array(),322_old_gen->object_space(),323_gen_top,324pm,325worker_id,326_active_workers);327328// Do the real work329pm->drain_stacks(false);330}331}332333for (uint root_type = 0; _subtasks.try_claim_task(root_type); /* empty */ ) {334scavenge_roots_work(static_cast<ParallelRootType::Value>(root_type), worker_id);335}336337PSThreadRootsTaskClosure closure(worker_id);338Threads::possibly_parallel_threads_do(true /*parallel */, &closure);339340// Scavenge OopStorages341{342PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(worker_id);343PSScavengeRootsClosure closure(pm);344_oop_storage_strong_par_state.oops_do(&closure);345// Do the real work346pm->drain_stacks(false);347}348349// If active_workers can exceed 1, add a steal_work().350// PSPromotionManager::drain_stacks_depth() does not fully drain its351// stacks and expects a steal_work() to complete the draining if352// ParallelGCThreads is > 1.353354if (_active_workers > 1) {355steal_work(_terminator, worker_id);356}357}358};359360// This method contains no policy. You should probably361// be calling invoke() instead.362bool PSScavenge::invoke_no_policy() {363assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");364assert(Thread::current() == (Thread*)VMThread::vm_thread(), "should be in vm thread");365366_gc_timer.register_gc_start();367368TimeStamp scavenge_entry;369TimeStamp scavenge_midpoint;370TimeStamp scavenge_exit;371372scavenge_entry.update();373374if (GCLocker::check_active_before_gc()) {375return false;376}377378ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();379GCCause::Cause gc_cause = heap->gc_cause();380381// Check for potential problems.382if (!should_attempt_scavenge()) {383return false;384}385386GCIdMark gc_id_mark;387_gc_tracer.report_gc_start(heap->gc_cause(), _gc_timer.gc_start());388389bool promotion_failure_occurred = false;390391PSYoungGen* young_gen = heap->young_gen();392PSOldGen* old_gen = heap->old_gen();393PSAdaptiveSizePolicy* size_policy = heap->size_policy();394395heap->increment_total_collections();396397if (AdaptiveSizePolicy::should_update_eden_stats(gc_cause)) {398// Gather the feedback data for eden occupancy.399young_gen->eden_space()->accumulate_statistics();400}401402heap->print_heap_before_gc();403heap->trace_heap_before_gc(&_gc_tracer);404405assert(!NeverTenure || _tenuring_threshold == markWord::max_age + 1, "Sanity");406assert(!AlwaysTenure || _tenuring_threshold == 0, "Sanity");407408// Fill in TLABs409heap->ensure_parsability(true); // retire TLABs410411if (VerifyBeforeGC && heap->total_collections() >= VerifyGCStartAt) {412Universe::verify("Before GC");413}414415{416ResourceMark rm;417418GCTraceCPUTime tcpu;419GCTraceTime(Info, gc) tm("Pause Young", NULL, gc_cause, true);420TraceCollectorStats tcs(counters());421TraceMemoryManagerStats tms(heap->young_gc_manager(), gc_cause);422423if (log_is_enabled(Debug, gc, heap, exit)) {424accumulated_time()->start();425}426427// Let the size policy know we're starting428size_policy->minor_collection_begin();429430// Verify the object start arrays.431if (VerifyObjectStartArray &&432VerifyBeforeGC) {433old_gen->verify_object_start_array();434}435436// Verify no unmarked old->young roots437if (VerifyRememberedSets) {438heap->card_table()->verify_all_young_refs_imprecise();439}440441assert(young_gen->to_space()->is_empty(),442"Attempt to scavenge with live objects in to_space");443young_gen->to_space()->clear(SpaceDecorator::Mangle);444445save_to_space_top_before_gc();446447#if COMPILER2_OR_JVMCI448DerivedPointerTable::clear();449#endif450451reference_processor()->enable_discovery();452reference_processor()->setup_policy(false);453454const PreGenGCValues pre_gc_values = heap->get_pre_gc_values();455456// Reset our survivor overflow.457set_survivor_overflow(false);458459// We need to save the old top values before460// creating the promotion_manager. We pass the top461// values to the card_table, to prevent it from462// straying into the promotion labs.463HeapWord* old_top = old_gen->object_space()->top();464465const uint active_workers =466WorkerPolicy::calc_active_workers(ParallelScavengeHeap::heap()->workers().total_workers(),467ParallelScavengeHeap::heap()->workers().active_workers(),468Threads::number_of_non_daemon_threads());469ParallelScavengeHeap::heap()->workers().update_active_workers(active_workers);470471PSPromotionManager::pre_scavenge();472473// We'll use the promotion manager again later.474PSPromotionManager* promotion_manager = PSPromotionManager::vm_thread_promotion_manager();475{476GCTraceTime(Debug, gc, phases) tm("Scavenge", &_gc_timer);477478ScavengeRootsTask task(old_gen, old_top, active_workers, old_gen->object_space()->is_empty());479ParallelScavengeHeap::heap()->workers().run_task(&task);480}481482scavenge_midpoint.update();483484// Process reference objects discovered during scavenge485{486GCTraceTime(Debug, gc, phases) tm("Reference Processing", &_gc_timer);487488reference_processor()->setup_policy(false); // not always_clear489reference_processor()->set_active_mt_degree(active_workers);490ReferenceProcessorStats stats;491ReferenceProcessorPhaseTimes pt(&_gc_timer, reference_processor()->max_num_queues());492493ParallelScavengeRefProcProxyTask task(reference_processor()->max_num_queues());494stats = reference_processor()->process_discovered_references(task, pt);495496_gc_tracer.report_gc_reference_stats(stats);497pt.print_all_references();498}499500assert(promotion_manager->stacks_empty(),"stacks should be empty at this point");501502{503GCTraceTime(Debug, gc, phases) tm("Weak Processing", &_gc_timer);504PSAdjustWeakRootsClosure root_closure;505WeakProcessor::weak_oops_do(&ParallelScavengeHeap::heap()->workers(), &_is_alive_closure, &root_closure, 1);506}507508// Verify that usage of root_closure didn't copy any objects.509assert(promotion_manager->stacks_empty(),"stacks should be empty at this point");510511// Finally, flush the promotion_manager's labs, and deallocate its stacks.512promotion_failure_occurred = PSPromotionManager::post_scavenge(_gc_tracer);513if (promotion_failure_occurred) {514clean_up_failed_promotion();515log_info(gc, promotion)("Promotion failed");516}517518_gc_tracer.report_tenuring_threshold(tenuring_threshold());519520// Let the size policy know we're done. Note that we count promotion521// failure cleanup time as part of the collection (otherwise, we're522// implicitly saying it's mutator time).523size_policy->minor_collection_end(gc_cause);524525if (!promotion_failure_occurred) {526// Swap the survivor spaces.527young_gen->eden_space()->clear(SpaceDecorator::Mangle);528young_gen->from_space()->clear(SpaceDecorator::Mangle);529young_gen->swap_spaces();530531size_t survived = young_gen->from_space()->used_in_bytes();532size_t promoted = old_gen->used_in_bytes() - pre_gc_values.old_gen_used();533size_policy->update_averages(_survivor_overflow, survived, promoted);534535// A successful scavenge should restart the GC time limit count which is536// for full GC's.537size_policy->reset_gc_overhead_limit_count();538if (UseAdaptiveSizePolicy) {539// Calculate the new survivor size and tenuring threshold540541log_debug(gc, ergo)("AdaptiveSizeStart: collection: %d ", heap->total_collections());542log_trace(gc, ergo)("old_gen_capacity: " SIZE_FORMAT " young_gen_capacity: " SIZE_FORMAT,543old_gen->capacity_in_bytes(), young_gen->capacity_in_bytes());544545if (UsePerfData) {546PSGCAdaptivePolicyCounters* counters = heap->gc_policy_counters();547counters->update_old_eden_size(548size_policy->calculated_eden_size_in_bytes());549counters->update_old_promo_size(550size_policy->calculated_promo_size_in_bytes());551counters->update_old_capacity(old_gen->capacity_in_bytes());552counters->update_young_capacity(young_gen->capacity_in_bytes());553counters->update_survived(survived);554counters->update_promoted(promoted);555counters->update_survivor_overflowed(_survivor_overflow);556}557558size_t max_young_size = young_gen->max_gen_size();559560// Deciding a free ratio in the young generation is tricky, so if561// MinHeapFreeRatio or MaxHeapFreeRatio are in use (implicating562// that the old generation size may have been limited because of them) we563// should then limit our young generation size using NewRatio to have it564// follow the old generation size.565if (MinHeapFreeRatio != 0 || MaxHeapFreeRatio != 100) {566max_young_size = MIN2(old_gen->capacity_in_bytes() / NewRatio,567young_gen->max_gen_size());568}569570size_t survivor_limit =571size_policy->max_survivor_size(max_young_size);572_tenuring_threshold =573size_policy->compute_survivor_space_size_and_threshold(574_survivor_overflow,575_tenuring_threshold,576survivor_limit);577578log_debug(gc, age)("Desired survivor size " SIZE_FORMAT " bytes, new threshold %u (max threshold " UINTX_FORMAT ")",579size_policy->calculated_survivor_size_in_bytes(),580_tenuring_threshold, MaxTenuringThreshold);581582if (UsePerfData) {583PSGCAdaptivePolicyCounters* counters = heap->gc_policy_counters();584counters->update_tenuring_threshold(_tenuring_threshold);585counters->update_survivor_size_counters();586}587588// Do call at minor collections?589// Don't check if the size_policy is ready at this590// level. Let the size_policy check that internally.591if (UseAdaptiveGenerationSizePolicyAtMinorCollection &&592AdaptiveSizePolicy::should_update_eden_stats(gc_cause)) {593// Calculate optimal free space amounts594assert(young_gen->max_gen_size() >595young_gen->from_space()->capacity_in_bytes() +596young_gen->to_space()->capacity_in_bytes(),597"Sizes of space in young gen are out-of-bounds");598599size_t young_live = young_gen->used_in_bytes();600size_t eden_live = young_gen->eden_space()->used_in_bytes();601size_t cur_eden = young_gen->eden_space()->capacity_in_bytes();602size_t max_old_gen_size = old_gen->max_gen_size();603size_t max_eden_size = max_young_size -604young_gen->from_space()->capacity_in_bytes() -605young_gen->to_space()->capacity_in_bytes();606607// Used for diagnostics608size_policy->clear_generation_free_space_flags();609610size_policy->compute_eden_space_size(young_live,611eden_live,612cur_eden,613max_eden_size,614false /* not full gc*/);615616size_policy->check_gc_overhead_limit(eden_live,617max_old_gen_size,618max_eden_size,619false /* not full gc*/,620gc_cause,621heap->soft_ref_policy());622623size_policy->decay_supplemental_growth(false /* not full gc*/);624}625// Resize the young generation at every collection626// even if new sizes have not been calculated. This is627// to allow resizes that may have been inhibited by the628// relative location of the "to" and "from" spaces.629630// Resizing the old gen at young collections can cause increases631// that don't feed back to the generation sizing policy until632// a full collection. Don't resize the old gen here.633634heap->resize_young_gen(size_policy->calculated_eden_size_in_bytes(),635size_policy->calculated_survivor_size_in_bytes());636637log_debug(gc, ergo)("AdaptiveSizeStop: collection: %d ", heap->total_collections());638}639640// Update the structure of the eden. With NUMA-eden CPU hotplugging or offlining can641// cause the change of the heap layout. Make sure eden is reshaped if that's the case.642// Also update() will case adaptive NUMA chunk resizing.643assert(young_gen->eden_space()->is_empty(), "eden space should be empty now");644young_gen->eden_space()->update();645646heap->gc_policy_counters()->update_counters();647648heap->resize_all_tlabs();649650assert(young_gen->to_space()->is_empty(), "to space should be empty now");651}652653#if COMPILER2_OR_JVMCI654DerivedPointerTable::update_pointers();655#endif656657NOT_PRODUCT(reference_processor()->verify_no_references_recorded());658659// Re-verify object start arrays660if (VerifyObjectStartArray &&661VerifyAfterGC) {662old_gen->verify_object_start_array();663}664665// Verify all old -> young cards are now precise666if (VerifyRememberedSets) {667// Precise verification will give false positives. Until this is fixed,668// use imprecise verification.669// heap->card_table()->verify_all_young_refs_precise();670heap->card_table()->verify_all_young_refs_imprecise();671}672673if (log_is_enabled(Debug, gc, heap, exit)) {674accumulated_time()->stop();675}676677heap->print_heap_change(pre_gc_values);678679// Track memory usage and detect low memory680MemoryService::track_memory_usage();681heap->update_counters();682}683684if (VerifyAfterGC && heap->total_collections() >= VerifyGCStartAt) {685Universe::verify("After GC");686}687688heap->print_heap_after_gc();689heap->trace_heap_after_gc(&_gc_tracer);690691scavenge_exit.update();692693log_debug(gc, task, time)("VM-Thread " JLONG_FORMAT " " JLONG_FORMAT " " JLONG_FORMAT,694scavenge_entry.ticks(), scavenge_midpoint.ticks(),695scavenge_exit.ticks());696697AdaptiveSizePolicyOutput::print(size_policy, heap->total_collections());698699_gc_timer.register_gc_end();700701_gc_tracer.report_gc_end(_gc_timer.gc_end(), _gc_timer.time_partitions());702703return !promotion_failure_occurred;704}705706// This method iterates over all objects in the young generation,707// removing all forwarding references. It then restores any preserved marks.708void PSScavenge::clean_up_failed_promotion() {709ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();710PSYoungGen* young_gen = heap->young_gen();711712RemoveForwardedPointerClosure remove_fwd_ptr_closure;713young_gen->object_iterate(&remove_fwd_ptr_closure);714715PSPromotionManager::restore_preserved_marks();716717// Reset the PromotionFailureALot counters.718NOT_PRODUCT(heap->reset_promotion_should_fail();)719}720721bool PSScavenge::should_attempt_scavenge() {722ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();723PSGCAdaptivePolicyCounters* counters = heap->gc_policy_counters();724725if (UsePerfData) {726counters->update_scavenge_skipped(not_skipped);727}728729PSYoungGen* young_gen = heap->young_gen();730PSOldGen* old_gen = heap->old_gen();731732// Do not attempt to promote unless to_space is empty733if (!young_gen->to_space()->is_empty()) {734_consecutive_skipped_scavenges++;735if (UsePerfData) {736counters->update_scavenge_skipped(to_space_not_empty);737}738return false;739}740741// Test to see if the scavenge will likely fail.742PSAdaptiveSizePolicy* policy = heap->size_policy();743744// A similar test is done in the policy's should_full_GC(). If this is745// changed, decide if that test should also be changed.746size_t avg_promoted = (size_t) policy->padded_average_promoted_in_bytes();747size_t promotion_estimate = MIN2(avg_promoted, young_gen->used_in_bytes());748bool result = promotion_estimate < old_gen->free_in_bytes();749750log_trace(ergo)("%s scavenge: average_promoted " SIZE_FORMAT " padded_average_promoted " SIZE_FORMAT " free in old gen " SIZE_FORMAT,751result ? "Do" : "Skip", (size_t) policy->average_promoted_in_bytes(),752(size_t) policy->padded_average_promoted_in_bytes(),753old_gen->free_in_bytes());754if (young_gen->used_in_bytes() < (size_t) policy->padded_average_promoted_in_bytes()) {755log_trace(ergo)(" padded_promoted_average is greater than maximum promotion = " SIZE_FORMAT, young_gen->used_in_bytes());756}757758if (result) {759_consecutive_skipped_scavenges = 0;760} else {761_consecutive_skipped_scavenges++;762if (UsePerfData) {763counters->update_scavenge_skipped(promoted_too_large);764}765}766return result;767}768769// Adaptive size policy support.770void PSScavenge::set_young_generation_boundary(HeapWord* v) {771_young_generation_boundary = v;772if (UseCompressedOops) {773_young_generation_boundary_compressed = (uintptr_t)CompressedOops::encode(cast_to_oop(v));774}775}776777void PSScavenge::initialize() {778// Arguments must have been parsed779780if (AlwaysTenure || NeverTenure) {781assert(MaxTenuringThreshold == 0 || MaxTenuringThreshold == markWord::max_age + 1,782"MaxTenuringThreshold should be 0 or markWord::max_age + 1, but is %d", (int) MaxTenuringThreshold);783_tenuring_threshold = MaxTenuringThreshold;784} else {785// We want to smooth out our startup times for the AdaptiveSizePolicy786_tenuring_threshold = (UseAdaptiveSizePolicy) ? InitialTenuringThreshold :787MaxTenuringThreshold;788}789790ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();791PSYoungGen* young_gen = heap->young_gen();792PSOldGen* old_gen = heap->old_gen();793794// Set boundary between young_gen and old_gen795assert(old_gen->reserved().end() <= young_gen->eden_space()->bottom(),796"old above young");797set_young_generation_boundary(young_gen->eden_space()->bottom());798799// Initialize ref handling object for scavenging.800_span_based_discoverer.set_span(young_gen->reserved());801_ref_processor =802new ReferenceProcessor(&_span_based_discoverer,803ParallelGCThreads, // mt processing degree804true, // mt discovery805ParallelGCThreads, // mt discovery degree806true, // atomic_discovery807NULL, // header provides liveness info808false);809810// Cache the cardtable811_card_table = heap->card_table();812813_counters = new CollectorCounters("Parallel young collection pauses", 0);814}815816817