0N/A/*
3200N/A * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp"
1879N/A#include "gc_implementation/parNew/parNewGeneration.hpp"
1879N/A#include "gc_implementation/parNew/parOopClosures.inline.hpp"
1879N/A#include "gc_implementation/shared/adaptiveSizePolicy.hpp"
1879N/A#include "gc_implementation/shared/ageTable.hpp"
3945N/A#include "gc_implementation/shared/parGCAllocBuffer.hpp"
4141N/A#include "gc_implementation/shared/gcHeapSummary.hpp"
4141N/A#include "gc_implementation/shared/gcTimer.hpp"
4141N/A#include "gc_implementation/shared/gcTrace.hpp"
4141N/A#include "gc_implementation/shared/gcTraceTime.hpp"
4309N/A#include "gc_implementation/shared/copyFailedInfo.hpp"
1879N/A#include "gc_implementation/shared/spaceDecorator.hpp"
1879N/A#include "memory/defNewGeneration.inline.hpp"
1879N/A#include "memory/genCollectedHeap.hpp"
1879N/A#include "memory/genOopClosures.inline.hpp"
1879N/A#include "memory/generation.hpp"
1879N/A#include "memory/generation.inline.hpp"
1879N/A#include "memory/referencePolicy.hpp"
1879N/A#include "memory/resourceArea.hpp"
1879N/A#include "memory/sharedHeap.hpp"
1879N/A#include "memory/space.hpp"
1879N/A#include "oops/objArrayOop.hpp"
1879N/A#include "oops/oop.inline.hpp"
1879N/A#include "oops/oop.pcgc.inline.hpp"
1879N/A#include "runtime/handles.hpp"
1879N/A#include "runtime/handles.inline.hpp"
1879N/A#include "runtime/java.hpp"
1879N/A#include "runtime/thread.hpp"
1879N/A#include "utilities/copy.hpp"
1879N/A#include "utilities/globalDefinitions.hpp"
1879N/A#include "utilities/workgroup.hpp"
0N/A
0N/A#ifdef _MSC_VER
0N/A#pragma warning( push )
0N/A#pragma warning( disable:4355 ) // 'this' : used in base member initializer list
0N/A#endif
0N/AParScanThreadState::ParScanThreadState(Space* to_space_,
0N/A ParNewGeneration* gen_,
0N/A Generation* old_gen_,
0N/A int thread_num_,
0N/A ObjToScanQueueSet* work_queue_set_,
3863N/A Stack<oop, mtGC>* overflow_stacks_,
0N/A size_t desired_plab_sz_,
0N/A ParallelTaskTerminator& term_) :
679N/A _to_space(to_space_), _old_gen(old_gen_), _young_gen(gen_), _thread_num(thread_num_),
0N/A _work_queue(work_queue_set_->queue(thread_num_)), _to_space_full(false),
1756N/A _overflow_stack(overflow_stacks_ ? overflow_stacks_ + thread_num_ : NULL),
0N/A _ageTable(false), // false ==> not the global age table, no perf data.
0N/A _to_space_alloc_buffer(desired_plab_sz_),
0N/A _to_space_closure(gen_, this), _old_gen_closure(gen_, this),
0N/A _to_space_root_closure(gen_, this), _old_gen_root_closure(gen_, this),
0N/A _older_gen_closure(gen_, this),
0N/A _evacuate_followers(this, &_to_space_closure, &_old_gen_closure,
0N/A &_to_space_root_closure, gen_, &_old_gen_root_closure,
0N/A work_queue_set_, &term_),
0N/A _is_alive_closure(gen_), _scan_weak_ref_closure(gen_, this),
0N/A _keep_alive_closure(&_scan_weak_ref_closure),
0N/A _strong_roots_time(0.0), _term_time(0.0)
0N/A{
1630N/A #if TASKQUEUE_STATS
1630N/A _term_attempts = 0;
1630N/A _overflow_refills = 0;
1630N/A _overflow_refill_objs = 0;
1630N/A #endif // TASKQUEUE_STATS
1630N/A
0N/A _survivor_chunk_array =
0N/A (ChunkArray*) old_gen()->get_data_recorder(thread_num());
0N/A _hash_seed = 17; // Might want to take time-based random value.
0N/A _start = os::elapsedTime();
0N/A _old_gen_closure.set_generation(old_gen_);
0N/A _old_gen_root_closure.set_generation(old_gen_);
0N/A}
0N/A#ifdef _MSC_VER
0N/A#pragma warning( pop )
0N/A#endif
0N/A
0N/Avoid ParScanThreadState::record_survivor_plab(HeapWord* plab_start,
0N/A size_t plab_word_size) {
0N/A ChunkArray* sca = survivor_chunk_array();
0N/A if (sca != NULL) {
0N/A // A non-null SCA implies that we want the PLAB data recorded.
0N/A sca->record_sample(plab_start, plab_word_size);
0N/A }
0N/A}
0N/A
0N/Abool ParScanThreadState::should_be_partially_scanned(oop new_obj, oop old_obj) const {
0N/A return new_obj->is_objArray() &&
0N/A arrayOop(new_obj)->length() > ParGCArrayScanChunk &&
0N/A new_obj != old_obj;
0N/A}
0N/A
0N/Avoid ParScanThreadState::scan_partial_array_and_push_remainder(oop old) {
0N/A assert(old->is_objArray(), "must be obj array");
0N/A assert(old->is_forwarded(), "must be forwarded");
0N/A assert(Universe::heap()->is_in_reserved(old), "must be in heap.");
679N/A assert(!old_gen()->is_in(old), "must be in young generation.");
0N/A
0N/A objArrayOop obj = objArrayOop(old->forwardee());
0N/A // Process ParGCArrayScanChunk elements now
0N/A // and push the remainder back onto queue
0N/A int start = arrayOop(old)->length();
0N/A int end = obj->length();
0N/A int remainder = end - start;
0N/A assert(start <= end, "just checking");
0N/A if (remainder > 2 * ParGCArrayScanChunk) {
0N/A // Test above combines last partial chunk with a full chunk
0N/A end = start + ParGCArrayScanChunk;
0N/A arrayOop(old)->set_length(end);
0N/A // Push remainder.
0N/A bool ok = work_queue()->push(old);
0N/A assert(ok, "just popped, push must be okay");
0N/A } else {
0N/A // Restore length so that it can be used if there
0N/A // is a promotion failure and forwarding pointers
0N/A // must be removed.
0N/A arrayOop(old)->set_length(end);
0N/A }
113N/A
0N/A // process our set of indices (include header in first chunk)
113N/A // should make sure end is even (aligned to HeapWord in case of compressed oops)
0N/A if ((HeapWord *)obj < young_old_boundary()) {
0N/A // object is in to_space
113N/A obj->oop_iterate_range(&_to_space_closure, start, end);
0N/A } else {
0N/A // object is in old generation
113N/A obj->oop_iterate_range(&_old_gen_closure, start, end);
0N/A }
0N/A}
0N/A
0N/A
0N/Avoid ParScanThreadState::trim_queues(int max_size) {
0N/A ObjToScanQueue* queue = work_queue();
679N/A do {
679N/A while (queue->size() > (juint)max_size) {
679N/A oop obj_to_scan;
679N/A if (queue->pop_local(obj_to_scan)) {
679N/A if ((HeapWord *)obj_to_scan < young_old_boundary()) {
679N/A if (obj_to_scan->is_objArray() &&
679N/A obj_to_scan->is_forwarded() &&
679N/A obj_to_scan->forwardee() != obj_to_scan) {
679N/A scan_partial_array_and_push_remainder(obj_to_scan);
679N/A } else {
679N/A // object is in to_space
679N/A obj_to_scan->oop_iterate(&_to_space_closure);
679N/A }
0N/A } else {
679N/A // object is in old generation
679N/A obj_to_scan->oop_iterate(&_old_gen_closure);
0N/A }
0N/A }
0N/A }
679N/A // For the case of compressed oops, we have a private, non-shared
679N/A // overflow stack, so we eagerly drain it so as to more evenly
679N/A // distribute load early. Note: this may be good to do in
679N/A // general rather than delay for the final stealing phase.
679N/A // If applicable, we'll transfer a set of objects over to our
679N/A // work queue, allowing them to be stolen and draining our
679N/A // private overflow stack.
679N/A } while (ParGCTrimOverflow && young_gen()->take_from_overflow_list(this));
679N/A}
679N/A
679N/Abool ParScanThreadState::take_from_overflow_stack() {
695N/A assert(ParGCUseLocalOverflow, "Else should not call");
679N/A assert(young_gen()->overflow_list() == NULL, "Error");
679N/A ObjToScanQueue* queue = work_queue();
3863N/A Stack<oop, mtGC>* const of_stack = overflow_stack();
1756N/A const size_t num_overflow_elems = of_stack->size();
1756N/A const size_t space_available = queue->max_elems() - queue->size();
1756N/A const size_t num_take_elems = MIN3(space_available / 4,
1756N/A ParGCDesiredObjsFromOverflowList,
1756N/A num_overflow_elems);
679N/A // Transfer the most recent num_take_elems from the overflow
679N/A // stack to our work queue.
679N/A for (size_t i = 0; i != num_take_elems; i++) {
679N/A oop cur = of_stack->pop();
679N/A oop obj_to_push = cur->forwardee();
679N/A assert(Universe::heap()->is_in_reserved(cur), "Should be in heap");
679N/A assert(!old_gen()->is_in_reserved(cur), "Should be in young gen");
679N/A assert(Universe::heap()->is_in_reserved(obj_to_push), "Should be in heap");
679N/A if (should_be_partially_scanned(obj_to_push, cur)) {
679N/A assert(arrayOop(cur)->length() == 0, "entire array remaining to be scanned");
679N/A obj_to_push = cur;
679N/A }
679N/A bool ok = queue->push(obj_to_push);
679N/A assert(ok, "Should have succeeded");
0N/A }
679N/A assert(young_gen()->overflow_list() == NULL, "Error");
679N/A return num_take_elems > 0; // was something transferred?
679N/A}
679N/A
679N/Avoid ParScanThreadState::push_on_overflow_stack(oop p) {
695N/A assert(ParGCUseLocalOverflow, "Else should not call");
679N/A overflow_stack()->push(p);
679N/A assert(young_gen()->overflow_list() == NULL, "Error");
0N/A}
0N/A
0N/AHeapWord* ParScanThreadState::alloc_in_to_space_slow(size_t word_sz) {
0N/A
0N/A // Otherwise, if the object is small enough, try to reallocate the
0N/A // buffer.
0N/A HeapWord* obj = NULL;
0N/A if (!_to_space_full) {
0N/A ParGCAllocBuffer* const plab = to_space_alloc_buffer();
0N/A Space* const sp = to_space();
0N/A if (word_sz * 100 <
0N/A ParallelGCBufferWastePct * plab->word_sz()) {
0N/A // Is small enough; abandon this buffer and start a new one.
0N/A plab->retire(false, false);
0N/A size_t buf_size = plab->word_sz();
0N/A HeapWord* buf_space = sp->par_allocate(buf_size);
0N/A if (buf_space == NULL) {
0N/A const size_t min_bytes =
0N/A ParGCAllocBuffer::min_size() << LogHeapWordSize;
0N/A size_t free_bytes = sp->free();
0N/A while(buf_space == NULL && free_bytes >= min_bytes) {
0N/A buf_size = free_bytes >> LogHeapWordSize;
0N/A assert(buf_size == (size_t)align_object_size(buf_size),
0N/A "Invariant");
0N/A buf_space = sp->par_allocate(buf_size);
0N/A free_bytes = sp->free();
0N/A }
0N/A }
0N/A if (buf_space != NULL) {
0N/A plab->set_word_size(buf_size);
0N/A plab->set_buf(buf_space);
0N/A record_survivor_plab(buf_space, buf_size);
0N/A obj = plab->allocate(word_sz);
0N/A // Note that we cannot compare buf_size < word_sz below
0N/A // because of AlignmentReserve (see ParGCAllocBuffer::allocate()).
0N/A assert(obj != NULL || plab->words_remaining() < word_sz,
0N/A "Else should have been able to allocate");
0N/A // It's conceivable that we may be able to use the
0N/A // buffer we just grabbed for subsequent small requests
0N/A // even if not for this one.
0N/A } else {
0N/A // We're used up.
0N/A _to_space_full = true;
0N/A }
0N/A
0N/A } else {
0N/A // Too large; allocate the object individually.
0N/A obj = sp->par_allocate(word_sz);
0N/A }
0N/A }
0N/A return obj;
0N/A}
0N/A
0N/A
0N/Avoid ParScanThreadState::undo_alloc_in_to_space(HeapWord* obj,
0N/A size_t word_sz) {
0N/A // Is the alloc in the current alloc buffer?
0N/A if (to_space_alloc_buffer()->contains(obj)) {
0N/A assert(to_space_alloc_buffer()->contains(obj + word_sz - 1),
0N/A "Should contain whole object.");
0N/A to_space_alloc_buffer()->undo_allocation(obj, word_sz);
0N/A } else {
481N/A CollectedHeap::fill_with_object(obj, word_sz);
0N/A }
0N/A}
0N/A
4302N/Avoid ParScanThreadState::print_promotion_failure_size() {
4309N/A if (_promotion_failed_info.has_failed() && PrintPromotionFailure) {
4302N/A gclog_or_tty->print(" (%d: promotion failure size = " SIZE_FORMAT ") ",
4302N/A _thread_num, _promotion_failed_info.first_size());
1145N/A }
1145N/A}
1145N/A
0N/Aclass ParScanThreadStateSet: private ResourceArray {
0N/Apublic:
0N/A // Initializes states for the specified number of threads;
0N/A ParScanThreadStateSet(int num_threads,
0N/A Space& to_space,
0N/A ParNewGeneration& gen,
0N/A Generation& old_gen,
0N/A ObjToScanQueueSet& queue_set,
3863N/A Stack<oop, mtGC>* overflow_stacks_,
0N/A size_t desired_plab_sz,
0N/A ParallelTaskTerminator& term);
1630N/A
1630N/A ~ParScanThreadStateSet() { TASKQUEUE_STATS_ONLY(reset_stats()); }
1630N/A
1145N/A inline ParScanThreadState& thread_state(int i);
1630N/A
4302N/A void trace_promotion_failed(YoungGCTracer& gc_tracer);
2941N/A void reset(int active_workers, bool promotion_failed);
0N/A void flush();
1630N/A
1630N/A #if TASKQUEUE_STATS
1630N/A static void
1630N/A print_termination_stats_hdr(outputStream* const st = gclog_or_tty);
1630N/A void print_termination_stats(outputStream* const st = gclog_or_tty);
1630N/A static void
1630N/A print_taskqueue_stats_hdr(outputStream* const st = gclog_or_tty);
1630N/A void print_taskqueue_stats(outputStream* const st = gclog_or_tty);
1630N/A void reset_stats();
1630N/A #endif // TASKQUEUE_STATS
1630N/A
0N/Aprivate:
0N/A ParallelTaskTerminator& _term;
0N/A ParNewGeneration& _gen;
0N/A Generation& _next_gen;
2941N/A public:
2941N/A bool is_valid(int id) const { return id < length(); }
2941N/A ParallelTaskTerminator* terminator() { return &_term; }
0N/A};
0N/A
0N/A
0N/AParScanThreadStateSet::ParScanThreadStateSet(
0N/A int num_threads, Space& to_space, ParNewGeneration& gen,
0N/A Generation& old_gen, ObjToScanQueueSet& queue_set,
3863N/A Stack<oop, mtGC>* overflow_stacks,
0N/A size_t desired_plab_sz, ParallelTaskTerminator& term)
0N/A : ResourceArray(sizeof(ParScanThreadState), num_threads),
1630N/A _gen(gen), _next_gen(old_gen), _term(term)
0N/A{
0N/A assert(num_threads > 0, "sanity check!");
1756N/A assert(ParGCUseLocalOverflow == (overflow_stacks != NULL),
1756N/A "overflow_stack allocation mismatch");
0N/A // Initialize states.
0N/A for (int i = 0; i < num_threads; ++i) {
0N/A new ((ParScanThreadState*)_data + i)
0N/A ParScanThreadState(&to_space, &gen, &old_gen, i, &queue_set,
1756N/A overflow_stacks, desired_plab_sz, term);
0N/A }
0N/A}
0N/A
1145N/Ainline ParScanThreadState& ParScanThreadStateSet::thread_state(int i)
0N/A{
0N/A assert(i >= 0 && i < length(), "sanity check!");
0N/A return ((ParScanThreadState*)_data)[i];
0N/A}
0N/A
4302N/Avoid ParScanThreadStateSet::trace_promotion_failed(YoungGCTracer& gc_tracer) {
4302N/A for (int i = 0; i < length(); ++i) {
4302N/A if (thread_state(i).promotion_failed()) {
4302N/A gc_tracer.report_promotion_failed(thread_state(i).promotion_failed_info());
4302N/A thread_state(i).promotion_failed_info().reset();
4302N/A }
4302N/A }
4302N/A}
0N/A
2941N/Avoid ParScanThreadStateSet::reset(int active_threads, bool promotion_failed)
0N/A{
2941N/A _term.reset_for_reuse(active_threads);
1145N/A if (promotion_failed) {
1145N/A for (int i = 0; i < length(); ++i) {
4302N/A thread_state(i).print_promotion_failure_size();
1145N/A }
1145N/A }
0N/A}
0N/A
1630N/A#if TASKQUEUE_STATS
1630N/Avoid
1630N/AParScanThreadState::reset_stats()
1630N/A{
1630N/A taskqueue_stats().reset();
1630N/A _term_attempts = 0;
1630N/A _overflow_refills = 0;
1630N/A _overflow_refill_objs = 0;
1630N/A}
1630N/A
1630N/Avoid ParScanThreadStateSet::reset_stats()
1630N/A{
1630N/A for (int i = 0; i < length(); ++i) {
1630N/A thread_state(i).reset_stats();
1630N/A }
1630N/A}
1630N/A
1630N/Avoid
1630N/AParScanThreadStateSet::print_termination_stats_hdr(outputStream* const st)
1630N/A{
1630N/A st->print_raw_cr("GC Termination Stats");
1630N/A st->print_raw_cr(" elapsed --strong roots-- "
1630N/A "-------termination-------");
1630N/A st->print_raw_cr("thr ms ms % "
1630N/A " ms % attempts");
1630N/A st->print_raw_cr("--- --------- --------- ------ "
1630N/A "--------- ------ --------");
1630N/A}
1630N/A
1630N/Avoid ParScanThreadStateSet::print_termination_stats(outputStream* const st)
1630N/A{
1630N/A print_termination_stats_hdr(st);
1630N/A
1630N/A for (int i = 0; i < length(); ++i) {
1630N/A const ParScanThreadState & pss = thread_state(i);
1630N/A const double elapsed_ms = pss.elapsed_time() * 1000.0;
1630N/A const double s_roots_ms = pss.strong_roots_time() * 1000.0;
1630N/A const double term_ms = pss.term_time() * 1000.0;
1630N/A st->print_cr("%3d %9.2f %9.2f %6.2f "
1630N/A "%9.2f %6.2f " SIZE_FORMAT_W(8),
1630N/A i, elapsed_ms, s_roots_ms, s_roots_ms * 100 / elapsed_ms,
1630N/A term_ms, term_ms * 100 / elapsed_ms, pss.term_attempts());
1630N/A }
1630N/A}
1630N/A
1630N/A// Print stats related to work queue activity.
1630N/Avoid ParScanThreadStateSet::print_taskqueue_stats_hdr(outputStream* const st)
1630N/A{
1630N/A st->print_raw_cr("GC Task Stats");
1630N/A st->print_raw("thr "); TaskQueueStats::print_header(1, st); st->cr();
1630N/A st->print_raw("--- "); TaskQueueStats::print_header(2, st); st->cr();
1630N/A}
1630N/A
1630N/Avoid ParScanThreadStateSet::print_taskqueue_stats(outputStream* const st)
1630N/A{
1630N/A print_taskqueue_stats_hdr(st);
1630N/A
1630N/A TaskQueueStats totals;
1630N/A for (int i = 0; i < length(); ++i) {
1630N/A const ParScanThreadState & pss = thread_state(i);
1630N/A const TaskQueueStats & stats = pss.taskqueue_stats();
1630N/A st->print("%3d ", i); stats.print(st); st->cr();
1630N/A totals += stats;
1630N/A
1630N/A if (pss.overflow_refills() > 0) {
1630N/A st->print_cr(" " SIZE_FORMAT_W(10) " overflow refills "
1630N/A SIZE_FORMAT_W(10) " overflow objects",
1630N/A pss.overflow_refills(), pss.overflow_refill_objs());
1630N/A }
1630N/A }
1630N/A st->print("tot "); totals.print(st); st->cr();
1630N/A
1630N/A DEBUG_ONLY(totals.verify());
1630N/A}
1630N/A#endif // TASKQUEUE_STATS
1630N/A
0N/Avoid ParScanThreadStateSet::flush()
0N/A{
1145N/A // Work in this loop should be kept as lightweight as
1145N/A // possible since this might otherwise become a bottleneck
1145N/A // to scaling. Should we add heavy-weight work into this
1145N/A // loop, consider parallelizing the loop into the worker threads.
0N/A for (int i = 0; i < length(); ++i) {
1145N/A ParScanThreadState& par_scan_state = thread_state(i);
0N/A
0N/A // Flush stats related to To-space PLAB activity and
0N/A // retire the last buffer.
0N/A par_scan_state.to_space_alloc_buffer()->
0N/A flush_stats_and_retire(_gen.plab_stats(),
3945N/A true /* end_of_gc */,
3945N/A false /* retain */);
0N/A
0N/A // Every thread has its own age table. We need to merge
0N/A // them all into one.
0N/A ageTable *local_table = par_scan_state.age_table();
0N/A _gen.age_table()->merge(local_table);
0N/A
0N/A // Inform old gen that we're done.
0N/A _next_gen.par_promote_alloc_done(i);
0N/A _next_gen.par_oop_since_save_marks_iterate_done(i);
1630N/A }
0N/A
1145N/A if (UseConcMarkSweepGC && ParallelGCThreads > 0) {
1145N/A // We need to call this even when ResizeOldPLAB is disabled
1145N/A // so as to avoid breaking some asserts. While we may be able
1145N/A // to avoid this by reorganizing the code a bit, I am loathe
1145N/A // to do that unless we find cases where ergo leads to bad
1145N/A // performance.
1145N/A CFLS_LAB::compute_desired_plab_size();
1145N/A }
0N/A}
0N/A
0N/AParScanClosure::ParScanClosure(ParNewGeneration* g,
0N/A ParScanThreadState* par_scan_state) :
0N/A OopsInGenClosure(g), _par_scan_state(par_scan_state), _g(g)
0N/A{
0N/A assert(_g->level() == 0, "Optimized for youngest generation");
0N/A _boundary = _g->reserved().end();
0N/A}
0N/A
113N/Avoid ParScanWithBarrierClosure::do_oop(oop* p) { ParScanClosure::do_oop_work(p, true, false); }
113N/Avoid ParScanWithBarrierClosure::do_oop(narrowOop* p) { ParScanClosure::do_oop_work(p, true, false); }
113N/A
113N/Avoid ParScanWithoutBarrierClosure::do_oop(oop* p) { ParScanClosure::do_oop_work(p, false, false); }
113N/Avoid ParScanWithoutBarrierClosure::do_oop(narrowOop* p) { ParScanClosure::do_oop_work(p, false, false); }
113N/A
113N/Avoid ParRootScanWithBarrierTwoGensClosure::do_oop(oop* p) { ParScanClosure::do_oop_work(p, true, true); }
113N/Avoid ParRootScanWithBarrierTwoGensClosure::do_oop(narrowOop* p) { ParScanClosure::do_oop_work(p, true, true); }
113N/A
113N/Avoid ParRootScanWithoutBarrierClosure::do_oop(oop* p) { ParScanClosure::do_oop_work(p, false, true); }
113N/Avoid ParRootScanWithoutBarrierClosure::do_oop(narrowOop* p) { ParScanClosure::do_oop_work(p, false, true); }
113N/A
0N/AParScanWeakRefClosure::ParScanWeakRefClosure(ParNewGeneration* g,
0N/A ParScanThreadState* par_scan_state)
0N/A : ScanWeakRefClosure(g), _par_scan_state(par_scan_state)
113N/A{}
113N/A
113N/Avoid ParScanWeakRefClosure::do_oop(oop* p) { ParScanWeakRefClosure::do_oop_work(p); }
113N/Avoid ParScanWeakRefClosure::do_oop(narrowOop* p) { ParScanWeakRefClosure::do_oop_work(p); }
0N/A
0N/A#ifdef WIN32
0N/A#pragma warning(disable: 4786) /* identifier was truncated to '255' characters in the browser information */
0N/A#endif
0N/A
0N/AParEvacuateFollowersClosure::ParEvacuateFollowersClosure(
0N/A ParScanThreadState* par_scan_state_,
0N/A ParScanWithoutBarrierClosure* to_space_closure_,
0N/A ParScanWithBarrierClosure* old_gen_closure_,
0N/A ParRootScanWithoutBarrierClosure* to_space_root_closure_,
0N/A ParNewGeneration* par_gen_,
0N/A ParRootScanWithBarrierTwoGensClosure* old_gen_root_closure_,
0N/A ObjToScanQueueSet* task_queues_,
0N/A ParallelTaskTerminator* terminator_) :
0N/A
0N/A _par_scan_state(par_scan_state_),
0N/A _to_space_closure(to_space_closure_),
0N/A _old_gen_closure(old_gen_closure_),
0N/A _to_space_root_closure(to_space_root_closure_),
0N/A _old_gen_root_closure(old_gen_root_closure_),
0N/A _par_gen(par_gen_),
0N/A _task_queues(task_queues_),
0N/A _terminator(terminator_)
0N/A{}
0N/A
0N/Avoid ParEvacuateFollowersClosure::do_void() {
0N/A ObjToScanQueue* work_q = par_scan_state()->work_queue();
0N/A
0N/A while (true) {
0N/A
0N/A // Scan to-space and old-gen objs until we run out of both.
0N/A oop obj_to_scan;
0N/A par_scan_state()->trim_queues(0);
0N/A
0N/A // We have no local work, attempt to steal from other threads.
0N/A
0N/A // attempt to steal work from promoted.
0N/A if (task_queues()->steal(par_scan_state()->thread_num(),
0N/A par_scan_state()->hash_seed(),
0N/A obj_to_scan)) {
0N/A bool res = work_q->push(obj_to_scan);
0N/A assert(res, "Empty queue should have room for a push.");
0N/A
0N/A // if successful, goto Start.
0N/A continue;
0N/A
0N/A // try global overflow list.
0N/A } else if (par_gen()->take_from_overflow_list(par_scan_state())) {
0N/A continue;
0N/A }
0N/A
0N/A // Otherwise, offer termination.
0N/A par_scan_state()->start_term_time();
0N/A if (terminator()->offer_termination()) break;
0N/A par_scan_state()->end_term_time();
0N/A }
534N/A assert(par_gen()->_overflow_list == NULL && par_gen()->_num_par_pushes == 0,
534N/A "Broken overflow list?");
0N/A // Finish the last termination pause.
0N/A par_scan_state()->end_term_time();
0N/A}
0N/A
0N/AParNewGenTask::ParNewGenTask(ParNewGeneration* gen, Generation* next_gen,
0N/A HeapWord* young_old_boundary, ParScanThreadStateSet* state_set) :
0N/A AbstractGangTask("ParNewGeneration collection"),
0N/A _gen(gen), _next_gen(next_gen),
0N/A _young_old_boundary(young_old_boundary),
0N/A _state_set(state_set)
0N/A {}
0N/A
2941N/A// Reset the terminator for the given number of
2941N/A// active threads.
2941N/Avoid ParNewGenTask::set_for_termination(int active_workers) {
2941N/A _state_set->reset(active_workers, _gen->promotion_failed());
2941N/A // Should the heap be passed in? There's only 1 for now so
2941N/A // grab it instead.
2941N/A GenCollectedHeap* gch = GenCollectedHeap::heap();
2941N/A gch->set_n_termination(active_workers);
2941N/A}
2941N/A
2941N/A// The "i" passed to this method is the part of the work for
2941N/A// this thread. It is not the worker ID. The "i" is derived
2941N/A// from _started_workers which is incremented in internal_note_start()
2941N/A// called in GangWorker loop() and which is called under the
2941N/A// which is called under the protection of the gang monitor and is
2941N/A// called after a task is started. So "i" is based on
2941N/A// first-come-first-served.
2941N/A
3008N/Avoid ParNewGenTask::work(uint worker_id) {
0N/A GenCollectedHeap* gch = GenCollectedHeap::heap();
0N/A // Since this is being done in a separate thread, need new resource
0N/A // and handle marks.
0N/A ResourceMark rm;
0N/A HandleMark hm;
0N/A // We would need multiple old-gen queues otherwise.
679N/A assert(gch->n_gens() == 2, "Par young collection currently only works with one older gen.");
0N/A
0N/A Generation* old_gen = gch->next_gen(_gen);
0N/A
3008N/A ParScanThreadState& par_scan_state = _state_set->thread_state(worker_id);
3008N/A assert(_state_set->is_valid(worker_id), "Should not have been called");
2941N/A
0N/A par_scan_state.set_young_old_boundary(_young_old_boundary);
0N/A
0N/A par_scan_state.start_strong_roots();
0N/A gch->gen_process_strong_roots(_gen->level(),
989N/A true, // Process younger gens, if any,
989N/A // as strong roots.
989N/A false, // no scope; this is parallel code
989N/A false, // not collecting perm generation.
0N/A SharedHeap::SO_AllClasses,
989N/A &par_scan_state.to_space_root_closure(),
989N/A true, // walk *all* scavengable nmethods
989N/A &par_scan_state.older_gen_closure());
0N/A par_scan_state.end_strong_roots();
0N/A
0N/A // "evacuate followers".
0N/A par_scan_state.evacuate_followers_closure().do_void();
0N/A}
0N/A
0N/A#ifdef _MSC_VER
0N/A#pragma warning( push )
0N/A#pragma warning( disable:4355 ) // 'this' : used in base member initializer list
0N/A#endif
0N/AParNewGeneration::
0N/AParNewGeneration(ReservedSpace rs, size_t initial_byte_size, int level)
0N/A : DefNewGeneration(rs, initial_byte_size, level, "PCopy"),
0N/A _overflow_list(NULL),
0N/A _is_alive_closure(this),
0N/A _plab_stats(YoungPLABSize, PLABWeight)
0N/A{
534N/A NOT_PRODUCT(_overflow_counter = ParGCWorkQueueOverflowInterval;)
534N/A NOT_PRODUCT(_num_par_pushes = 0;)
0N/A _task_queues = new ObjToScanQueueSet(ParallelGCThreads);
0N/A guarantee(_task_queues != NULL, "task_queues allocation failure.");
0N/A
0N/A for (uint i1 = 0; i1 < ParallelGCThreads; i1++) {
1585N/A ObjToScanQueue *q = new ObjToScanQueue();
1585N/A guarantee(q != NULL, "work_queue Allocation failure.");
1585N/A _task_queues->register_queue(i1, q);
0N/A }
0N/A
0N/A for (uint i2 = 0; i2 < ParallelGCThreads; i2++)
0N/A _task_queues->queue(i2)->initialize();
0N/A
1756N/A _overflow_stacks = NULL;
1756N/A if (ParGCUseLocalOverflow) {
3863N/A
3863N/A // typedef to workaround NEW_C_HEAP_ARRAY macro, which can not deal
3863N/A // with ','
3863N/A typedef Stack<oop, mtGC> GCOopStack;
3863N/A
3863N/A _overflow_stacks = NEW_C_HEAP_ARRAY(GCOopStack, ParallelGCThreads, mtGC);
1756N/A for (size_t i = 0; i < ParallelGCThreads; ++i) {
3863N/A new (_overflow_stacks + i) Stack<oop, mtGC>();
695N/A }
695N/A }
695N/A
0N/A if (UsePerfData) {
0N/A EXCEPTION_MARK;
0N/A ResourceMark rm;
0N/A
0N/A const char* cname =
0N/A PerfDataManager::counter_name(_gen_counters->name_space(), "threads");
0N/A PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None,
0N/A ParallelGCThreads, CHECK);
0N/A }
0N/A}
0N/A#ifdef _MSC_VER
0N/A#pragma warning( pop )
0N/A#endif
0N/A
0N/A// ParNewGeneration::
0N/AParKeepAliveClosure::ParKeepAliveClosure(ParScanWeakRefClosure* cl) :
0N/A DefNewGeneration::KeepAliveClosure(cl), _par_cl(cl) {}
0N/A
113N/Atemplate <class T>
113N/Avoid /*ParNewGeneration::*/ParKeepAliveClosure::do_oop_work(T* p) {
113N/A#ifdef ASSERT
113N/A {
113N/A assert(!oopDesc::is_null(*p), "expected non-null ref");
113N/A oop obj = oopDesc::load_decode_heap_oop_not_null(p);
113N/A // We never expect to see a null reference being processed
113N/A // as a weak reference.
113N/A assert(obj->is_oop(), "expected an oop while scanning weak refs");
113N/A }
113N/A#endif // ASSERT
0N/A
0N/A _par_cl->do_oop_nv(p);
0N/A
0N/A if (Universe::heap()->is_in_reserved(p)) {
113N/A oop obj = oopDesc::load_decode_heap_oop_not_null(p);
113N/A _rs->write_ref_field_gc_par(p, obj);
0N/A }
0N/A}
0N/A
113N/Avoid /*ParNewGeneration::*/ParKeepAliveClosure::do_oop(oop* p) { ParKeepAliveClosure::do_oop_work(p); }
113N/Avoid /*ParNewGeneration::*/ParKeepAliveClosure::do_oop(narrowOop* p) { ParKeepAliveClosure::do_oop_work(p); }
113N/A
0N/A// ParNewGeneration::
0N/AKeepAliveClosure::KeepAliveClosure(ScanWeakRefClosure* cl) :
0N/A DefNewGeneration::KeepAliveClosure(cl) {}
0N/A
113N/Atemplate <class T>
113N/Avoid /*ParNewGeneration::*/KeepAliveClosure::do_oop_work(T* p) {
113N/A#ifdef ASSERT
113N/A {
113N/A assert(!oopDesc::is_null(*p), "expected non-null ref");
113N/A oop obj = oopDesc::load_decode_heap_oop_not_null(p);
113N/A // We never expect to see a null reference being processed
113N/A // as a weak reference.
113N/A assert(obj->is_oop(), "expected an oop while scanning weak refs");
113N/A }
113N/A#endif // ASSERT
0N/A
0N/A _cl->do_oop_nv(p);
0N/A
0N/A if (Universe::heap()->is_in_reserved(p)) {
113N/A oop obj = oopDesc::load_decode_heap_oop_not_null(p);
113N/A _rs->write_ref_field_gc_par(p, obj);
0N/A }
0N/A}
0N/A
113N/Avoid /*ParNewGeneration::*/KeepAliveClosure::do_oop(oop* p) { KeepAliveClosure::do_oop_work(p); }
113N/Avoid /*ParNewGeneration::*/KeepAliveClosure::do_oop(narrowOop* p) { KeepAliveClosure::do_oop_work(p); }
113N/A
113N/Atemplate <class T> void ScanClosureWithParBarrier::do_oop_work(T* p) {
113N/A T heap_oop = oopDesc::load_heap_oop(p);
113N/A if (!oopDesc::is_null(heap_oop)) {
113N/A oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
0N/A if ((HeapWord*)obj < _boundary) {
0N/A assert(!_g->to()->is_in_reserved(obj), "Scanning field twice?");
113N/A oop new_obj = obj->is_forwarded()
113N/A ? obj->forwardee()
113N/A : _g->DefNewGeneration::copy_to_survivor_space(obj);
113N/A oopDesc::encode_store_heap_oop_not_null(p, new_obj);
0N/A }
0N/A if (_gc_barrier) {
0N/A // If p points to a younger generation, mark the card.
0N/A if ((HeapWord*)obj < _gen_boundary) {
0N/A _rs->write_ref_field_gc_par(p, obj);
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
113N/Avoid ScanClosureWithParBarrier::do_oop(oop* p) { ScanClosureWithParBarrier::do_oop_work(p); }
113N/Avoid ScanClosureWithParBarrier::do_oop(narrowOop* p) { ScanClosureWithParBarrier::do_oop_work(p); }
113N/A
0N/Aclass ParNewRefProcTaskProxy: public AbstractGangTask {
0N/A typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask;
0N/Apublic:
0N/A ParNewRefProcTaskProxy(ProcessTask& task, ParNewGeneration& gen,
0N/A Generation& next_gen,
0N/A HeapWord* young_old_boundary,
0N/A ParScanThreadStateSet& state_set);
0N/A
0N/Aprivate:
3008N/A virtual void work(uint worker_id);
2941N/A virtual void set_for_termination(int active_workers) {
2941N/A _state_set.terminator()->reset_for_reuse(active_workers);
2941N/A }
0N/Aprivate:
0N/A ParNewGeneration& _gen;
0N/A ProcessTask& _task;
0N/A Generation& _next_gen;
0N/A HeapWord* _young_old_boundary;
0N/A ParScanThreadStateSet& _state_set;
0N/A};
0N/A
0N/AParNewRefProcTaskProxy::ParNewRefProcTaskProxy(
0N/A ProcessTask& task, ParNewGeneration& gen,
0N/A Generation& next_gen,
0N/A HeapWord* young_old_boundary,
0N/A ParScanThreadStateSet& state_set)
0N/A : AbstractGangTask("ParNewGeneration parallel reference processing"),
0N/A _gen(gen),
0N/A _task(task),
0N/A _next_gen(next_gen),
0N/A _young_old_boundary(young_old_boundary),
0N/A _state_set(state_set)
0N/A{
0N/A}
0N/A
3008N/Avoid ParNewRefProcTaskProxy::work(uint worker_id)
0N/A{
0N/A ResourceMark rm;
0N/A HandleMark hm;
3008N/A ParScanThreadState& par_scan_state = _state_set.thread_state(worker_id);
0N/A par_scan_state.set_young_old_boundary(_young_old_boundary);
3008N/A _task.work(worker_id, par_scan_state.is_alive_closure(),
0N/A par_scan_state.keep_alive_closure(),
0N/A par_scan_state.evacuate_followers_closure());
0N/A}
0N/A
0N/Aclass ParNewRefEnqueueTaskProxy: public AbstractGangTask {
0N/A typedef AbstractRefProcTaskExecutor::EnqueueTask EnqueueTask;
0N/A EnqueueTask& _task;
0N/A
0N/Apublic:
0N/A ParNewRefEnqueueTaskProxy(EnqueueTask& task)
0N/A : AbstractGangTask("ParNewGeneration parallel reference enqueue"),
0N/A _task(task)
0N/A { }
0N/A
3008N/A virtual void work(uint worker_id)
0N/A {
3008N/A _task.work(worker_id);
0N/A }
0N/A};
0N/A
0N/A
0N/Avoid ParNewRefProcTaskExecutor::execute(ProcessTask& task)
0N/A{
0N/A GenCollectedHeap* gch = GenCollectedHeap::heap();
0N/A assert(gch->kind() == CollectedHeap::GenCollectedHeap,
0N/A "not a generational heap");
2941N/A FlexibleWorkGang* workers = gch->workers();
0N/A assert(workers != NULL, "Need parallel worker threads.");
2941N/A _state_set.reset(workers->active_workers(), _generation.promotion_failed());
0N/A ParNewRefProcTaskProxy rp_task(task, _generation, *_generation.next_gen(),
0N/A _generation.reserved().end(), _state_set);
0N/A workers->run_task(&rp_task);
2941N/A _state_set.reset(0 /* bad value in debug if not reset */,
2941N/A _generation.promotion_failed());
0N/A}
0N/A
0N/Avoid ParNewRefProcTaskExecutor::execute(EnqueueTask& task)
0N/A{
0N/A GenCollectedHeap* gch = GenCollectedHeap::heap();
2941N/A FlexibleWorkGang* workers = gch->workers();
0N/A assert(workers != NULL, "Need parallel worker threads.");
0N/A ParNewRefEnqueueTaskProxy enq_task(task);
0N/A workers->run_task(&enq_task);
0N/A}
0N/A
0N/Avoid ParNewRefProcTaskExecutor::set_single_threaded_mode()
0N/A{
0N/A _state_set.flush();
0N/A GenCollectedHeap* gch = GenCollectedHeap::heap();
0N/A gch->set_par_threads(0); // 0 ==> non-parallel.
0N/A gch->save_marks();
0N/A}
0N/A
0N/AScanClosureWithParBarrier::
0N/AScanClosureWithParBarrier(ParNewGeneration* g, bool gc_barrier) :
0N/A ScanClosure(g, gc_barrier) {}
0N/A
0N/AEvacuateFollowersClosureGeneral::
0N/AEvacuateFollowersClosureGeneral(GenCollectedHeap* gch, int level,
0N/A OopsInGenClosure* cur,
0N/A OopsInGenClosure* older) :
0N/A _gch(gch), _level(level),
0N/A _scan_cur_or_nonheap(cur), _scan_older(older)
0N/A{}
0N/A
0N/Avoid EvacuateFollowersClosureGeneral::do_void() {
0N/A do {
0N/A // Beware: this call will lead to closure applications via virtual
0N/A // calls.
0N/A _gch->oop_since_save_marks_iterate(_level,
0N/A _scan_cur_or_nonheap,
0N/A _scan_older);
0N/A } while (!_gch->no_allocs_since_save_marks(_level));
0N/A}
0N/A
0N/A
4302N/A// A Generation that does parallel young-gen collection.
4302N/A
0N/Abool ParNewGeneration::_avoid_promotion_undo = false;
0N/A
0N/Avoid ParNewGeneration::adjust_desired_tenuring_threshold() {
0N/A // Set the desired survivor size to half the real survivor space
0N/A _tenuring_threshold =
0N/A age_table()->compute_tenuring_threshold(to()->capacity()/HeapWordSize);
0N/A}
0N/A
4302N/Avoid ParNewGeneration::handle_promotion_failed(GenCollectedHeap* gch, ParScanThreadStateSet& thread_state_set, ParNewTracer& gc_tracer) {
4302N/A assert(_promo_failure_scan_stack.is_empty(), "post condition");
4302N/A _promo_failure_scan_stack.clear(true); // Clear cached segments.
4302N/A
4302N/A remove_forwarding_pointers();
4302N/A if (PrintGCDetails) {
4302N/A gclog_or_tty->print(" (promotion failed)");
4302N/A }
4302N/A // All the spaces are in play for mark-sweep.
4302N/A swap_spaces(); // Make life simpler for CMS || rescan; see 6483690.
4302N/A from()->set_next_compaction_space(to());
4302N/A gch->set_incremental_collection_failed();
4302N/A // Inform the next generation that a promotion failure occurred.
4302N/A _next_gen->promotion_failure_occurred();
4302N/A
4302N/A // Trace promotion failure in the parallel GC threads
4302N/A thread_state_set.trace_promotion_failed(gc_tracer);
4302N/A // Single threaded code may have reported promotion failure to the global state
4309N/A if (_promotion_failed_info.has_failed()) {
4302N/A gc_tracer.report_promotion_failed(_promotion_failed_info);
4302N/A }
4302N/A // Reset the PromotionFailureALot counters.
4302N/A NOT_PRODUCT(Universe::heap()->reset_promotion_should_fail();)
4302N/A}
0N/A
0N/Avoid ParNewGeneration::collect(bool full,
0N/A bool clear_all_soft_refs,
0N/A size_t size,
0N/A bool is_tlab) {
0N/A assert(full || size > 0, "otherwise we don't want to collect");
4141N/A
0N/A GenCollectedHeap* gch = GenCollectedHeap::heap();
4141N/A
4141N/A _gc_timer->register_gc_start(os::elapsed_counter());
4141N/A
0N/A assert(gch->kind() == CollectedHeap::GenCollectedHeap,
0N/A "not a CMS generational heap");
0N/A AdaptiveSizePolicy* size_policy = gch->gen_policy()->size_policy();
2941N/A FlexibleWorkGang* workers = gch->workers();
2941N/A assert(workers != NULL, "Need workgang for parallel work");
2941N/A int active_workers =
2941N/A AdaptiveSizePolicy::calc_active_workers(workers->total_workers(),
2941N/A workers->active_workers(),
2941N/A Threads::number_of_non_daemon_threads());
2941N/A workers->set_active_workers(active_workers);
0N/A _next_gen = gch->next_gen(this);
0N/A assert(_next_gen != NULL,
0N/A "This must be the youngest gen, and not the only gen");
0N/A assert(gch->n_gens() == 2,
0N/A "Par collection currently only works with single older gen.");
0N/A // Do we have to avoid promotion_undo?
0N/A if (gch->collector_policy()->is_concurrent_mark_sweep_policy()) {
0N/A set_avoid_promotion_undo(true);
0N/A }
0N/A
4302N/A // If the next generation is too full to accommodate worst-case promotion
0N/A // from this generation, pass on collection; let the next generation
0N/A // do it.
0N/A if (!collection_attempt_is_safe()) {
1808N/A gch->set_incremental_collection_failed(); // slight lie, in that we did not even attempt one
0N/A return;
0N/A }
0N/A assert(to()->is_empty(), "Else not collection_attempt_is_safe");
0N/A
4289N/A ParNewTracer gc_tracer;
4289N/A gc_tracer.report_gc_start(gch->gc_cause(), _gc_timer->gc_start());
4289N/A gch->trace_heap_before_gc(&gc_tracer);
4289N/A
0N/A init_assuming_no_promotion_failure();
0N/A
0N/A if (UseAdaptiveSizePolicy) {
0N/A set_survivor_overflow(false);
0N/A size_policy->minor_collection_begin();
0N/A }
0N/A
4141N/A GCTraceTime t1(GCCauseString("GC", gch->gc_cause()), PrintGC && !PrintGCDetails, true, NULL);
0N/A // Capture heap used before collection (for printing).
0N/A size_t gch_prev_used = gch->used();
0N/A
0N/A SpecializationStats::clear();
0N/A
0N/A age_table()->clear();
263N/A to()->clear(SpaceDecorator::Mangle);
0N/A
0N/A gch->save_marks();
0N/A assert(workers != NULL, "Need parallel worker threads.");
2941N/A int n_workers = active_workers;
2941N/A
2941N/A // Set the correct parallelism (number of queues) in the reference processor
2941N/A ref_processor()->set_active_mt_degree(n_workers);
2941N/A
2941N/A // Always set the terminator for the active number of workers
2941N/A // because only those workers go through the termination protocol.
2941N/A ParallelTaskTerminator _term(n_workers, task_queues());
2941N/A ParScanThreadStateSet thread_state_set(workers->active_workers(),
0N/A *to(), *this, *_next_gen, *task_queues(),
695N/A _overflow_stacks, desired_plab_sz(), _term);
0N/A
0N/A ParNewGenTask tsk(this, _next_gen, reserved().end(), &thread_state_set);
0N/A gch->set_par_threads(n_workers);
0N/A gch->rem_set()->prepare_for_younger_refs_iterate(true);
0N/A // It turns out that even when we're using 1 thread, doing the work in a
0N/A // separate thread causes wide variance in run times. We can't help this
0N/A // in the multi-threaded case, but we special-case n=1 here to get
0N/A // repeatable measurements of the 1-thread overhead of the parallel code.
0N/A if (n_workers > 1) {
989N/A GenCollectedHeap::StrongRootsScope srs(gch);
0N/A workers->run_task(&tsk);
0N/A } else {
989N/A GenCollectedHeap::StrongRootsScope srs(gch);
0N/A tsk.work(0);
0N/A }
2941N/A thread_state_set.reset(0 /* Bad value in debug if not reset */,
2941N/A promotion_failed());
0N/A
0N/A // Process (weak) reference objects found during scavenge.
453N/A ReferenceProcessor* rp = ref_processor();
0N/A IsAliveClosure is_alive(this);
0N/A ScanWeakRefClosure scan_weak_ref(this);
0N/A KeepAliveClosure keep_alive(&scan_weak_ref);
0N/A ScanClosure scan_without_gc_barrier(this, false);
0N/A ScanClosureWithParBarrier scan_with_gc_barrier(this, true);
0N/A set_promo_failure_scan_stack_closure(&scan_without_gc_barrier);
0N/A EvacuateFollowersClosureGeneral evacuate_followers(gch, _level,
0N/A &scan_without_gc_barrier, &scan_with_gc_barrier);
457N/A rp->setup_policy(clear_all_soft_refs);
2941N/A // Can the mt_degree be set later (at run_task() time would be best)?
2941N/A rp->set_active_mt_degree(active_workers);
4298N/A ReferenceProcessorStats stats;
453N/A if (rp->processing_is_mt()) {
0N/A ParNewRefProcTaskExecutor task_executor(*this, thread_state_set);
4298N/A stats = rp->process_discovered_references(&is_alive, &keep_alive,
4298N/A &evacuate_followers, &task_executor,
4298N/A _gc_timer);
0N/A } else {
0N/A thread_state_set.flush();
0N/A gch->set_par_threads(0); // 0 ==> non-parallel.
0N/A gch->save_marks();
4298N/A stats = rp->process_discovered_references(&is_alive, &keep_alive,
4298N/A &evacuate_followers, NULL,
4298N/A _gc_timer);
0N/A }
4298N/A gc_tracer.report_gc_reference_stats(stats);
0N/A if (!promotion_failed()) {
0N/A // Swap the survivor spaces.
263N/A eden()->clear(SpaceDecorator::Mangle);
263N/A from()->clear(SpaceDecorator::Mangle);
263N/A if (ZapUnusedHeapArea) {
263N/A // This is now done here because of the piece-meal mangling which
263N/A // can check for valid mangling at intermediate points in the
263N/A // collection(s). When a minor collection fails to collect
263N/A // sufficient space resizing of the young generation can occur
263N/A // an redistribute the spaces in the young generation. Mangle
263N/A // here so that unzapped regions don't get distributed to
263N/A // other spaces.
263N/A to()->mangle_unused_area();
263N/A }
0N/A swap_spaces();
0N/A
1387N/A // A successful scavenge should restart the GC time limit count which is
1387N/A // for full GC's.
1387N/A size_policy->reset_gc_overhead_limit_count();
1387N/A
0N/A assert(to()->is_empty(), "to space should be empty now");
0N/A } else {
4302N/A handle_promotion_failed(gch, thread_state_set, gc_tracer);
0N/A }
0N/A // set new iteration safe limit for the survivor spaces
0N/A from()->set_concurrent_iteration_safe_limit(from()->top());
0N/A to()->set_concurrent_iteration_safe_limit(to()->top());
0N/A
0N/A adjust_desired_tenuring_threshold();
0N/A if (ResizePLAB) {
4007N/A plab_stats()->adjust_desired_plab_sz(n_workers);
0N/A }
0N/A
0N/A if (PrintGC && !PrintGCDetails) {
0N/A gch->print_heap_change(gch_prev_used);
0N/A }
0N/A
1632N/A if (PrintGCDetails && ParallelGCVerbose) {
1632N/A TASKQUEUE_STATS_ONLY(thread_state_set.print_termination_stats());
1632N/A TASKQUEUE_STATS_ONLY(thread_state_set.print_taskqueue_stats());
1632N/A }
1630N/A
0N/A if (UseAdaptiveSizePolicy) {
0N/A size_policy->minor_collection_end(gch->gc_cause());
0N/A size_policy->avg_survived()->sample(from()->used());
0N/A }
0N/A
3200N/A // We need to use a monotonically non-deccreasing time in ms
3200N/A // or we will see time-warp warnings and os::javaTimeMillis()
3200N/A // does not guarantee monotonicity.
3200N/A jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
3200N/A update_time_of_last_gc(now);
0N/A
0N/A SpecializationStats::print();
0N/A
453N/A rp->set_enqueuing_is_done(true);
453N/A if (rp->processing_is_mt()) {
0N/A ParNewRefProcTaskExecutor task_executor(*this, thread_state_set);
453N/A rp->enqueue_discovered_references(&task_executor);
0N/A } else {
453N/A rp->enqueue_discovered_references(NULL);
0N/A }
453N/A rp->verify_no_references_recorded();
4141N/A
4141N/A gch->trace_heap_after_gc(&gc_tracer);
4355N/A gc_tracer.report_tenuring_threshold(tenuring_threshold());
4141N/A
4141N/A _gc_timer->register_gc_end(os::elapsed_counter());
4141N/A
4141N/A gc_tracer.report_gc_end(_gc_timer->gc_end(), _gc_timer->time_partitions());
0N/A}
0N/A
0N/Astatic int sum;
0N/Avoid ParNewGeneration::waste_some_time() {
0N/A for (int i = 0; i < 100; i++) {
0N/A sum += i;
0N/A }
0N/A}
0N/A
0N/Astatic const oop ClaimedForwardPtr = oop(0x4);
0N/A
0N/A// Because of concurrency, there are times where an object for which
0N/A// "is_forwarded()" is true contains an "interim" forwarding pointer
0N/A// value. Such a value will soon be overwritten with a real value.
0N/A// This method requires "obj" to have a forwarding pointer, and waits, if
0N/A// necessary for a real one to be inserted, and returns it.
0N/A
0N/Aoop ParNewGeneration::real_forwardee(oop obj) {
0N/A oop forward_ptr = obj->forwardee();
0N/A if (forward_ptr != ClaimedForwardPtr) {
0N/A return forward_ptr;
0N/A } else {
0N/A return real_forwardee_slow(obj);
0N/A }
0N/A}
0N/A
0N/Aoop ParNewGeneration::real_forwardee_slow(oop obj) {
0N/A // Spin-read if it is claimed but not yet written by another thread.
0N/A oop forward_ptr = obj->forwardee();
0N/A while (forward_ptr == ClaimedForwardPtr) {
0N/A waste_some_time();
0N/A assert(obj->is_forwarded(), "precondition");
0N/A forward_ptr = obj->forwardee();
0N/A }
0N/A return forward_ptr;
0N/A}
0N/A
0N/A#ifdef ASSERT
0N/Abool ParNewGeneration::is_legal_forward_ptr(oop p) {
0N/A return
0N/A (_avoid_promotion_undo && p == ClaimedForwardPtr)
0N/A || Universe::heap()->is_in_reserved(p);
0N/A}
0N/A#endif
0N/A
0N/Avoid ParNewGeneration::preserve_mark_if_necessary(oop obj, markOop m) {
1945N/A if (m->must_be_preserved_for_promotion_failure(obj)) {
1945N/A // We should really have separate per-worker stacks, rather
1945N/A // than use locking of a common pair of stacks.
0N/A MutexLocker ml(ParGCRareEvent_lock);
1945N/A preserve_mark(obj, m);
0N/A }
0N/A}
0N/A
0N/A// Multiple GC threads may try to promote an object. If the object
0N/A// is successfully promoted, a forwarding pointer will be installed in
0N/A// the object in the young generation. This method claims the right
0N/A// to install the forwarding pointer before it copies the object,
0N/A// thus avoiding the need to undo the copy as in
0N/A// copy_to_survivor_space_avoiding_with_undo.
0N/A
0N/Aoop ParNewGeneration::copy_to_survivor_space_avoiding_promotion_undo(
0N/A ParScanThreadState* par_scan_state, oop old, size_t sz, markOop m) {
0N/A // In the sequential version, this assert also says that the object is
0N/A // not forwarded. That might not be the case here. It is the case that
0N/A // the caller observed it to be not forwarded at some time in the past.
0N/A assert(is_in_reserved(old), "shouldn't be scavenging this oop");
0N/A
0N/A // The sequential code read "old->age()" below. That doesn't work here,
0N/A // since the age is in the mark word, and that might be overwritten with
0N/A // a forwarding pointer by a parallel thread. So we must save the mark
0N/A // word in a local and then analyze it.
0N/A oopDesc dummyOld;
0N/A dummyOld.set_mark(m);
0N/A assert(!dummyOld.is_forwarded(),
0N/A "should not be called with forwarding pointer mark word.");
0N/A
0N/A oop new_obj = NULL;
0N/A oop forward_ptr;
0N/A
0N/A // Try allocating obj in to-space (unless too old)
0N/A if (dummyOld.age() < tenuring_threshold()) {
0N/A new_obj = (oop)par_scan_state->alloc_in_to_space(sz);
0N/A if (new_obj == NULL) {
0N/A set_survivor_overflow(true);
0N/A }
0N/A }
0N/A
0N/A if (new_obj == NULL) {
0N/A // Either to-space is full or we decided to promote
0N/A // try allocating obj tenured
0N/A
0N/A // Attempt to install a null forwarding pointer (atomically),
0N/A // to claim the right to install the real forwarding pointer.
0N/A forward_ptr = old->forward_to_atomic(ClaimedForwardPtr);
0N/A if (forward_ptr != NULL) {
0N/A // someone else beat us to it.
0N/A return real_forwardee(old);
0N/A }
0N/A
0N/A new_obj = _next_gen->par_promote(par_scan_state->thread_num(),
0N/A old, m, sz);
0N/A
0N/A if (new_obj == NULL) {
0N/A // promotion failed, forward to self
0N/A _promotion_failed = true;
0N/A new_obj = old;
0N/A
0N/A preserve_mark_if_necessary(old, m);
4302N/A par_scan_state->register_promotion_failure(sz);
0N/A }
0N/A
0N/A old->forward_to(new_obj);
0N/A forward_ptr = NULL;
0N/A } else {
0N/A // Is in to-space; do copying ourselves.
0N/A Copy::aligned_disjoint_words((HeapWord*)old, (HeapWord*)new_obj, sz);
0N/A forward_ptr = old->forward_to_atomic(new_obj);
0N/A // Restore the mark word copied above.
0N/A new_obj->set_mark(m);
0N/A // Increment age if obj still in new generation
0N/A new_obj->incr_age();
0N/A par_scan_state->age_table()->add(new_obj, sz);
0N/A }
0N/A assert(new_obj != NULL, "just checking");
0N/A
0N/A if (forward_ptr == NULL) {
0N/A oop obj_to_push = new_obj;
0N/A if (par_scan_state->should_be_partially_scanned(obj_to_push, old)) {
0N/A // Length field used as index of next element to be scanned.
0N/A // Real length can be obtained from real_forwardee()
0N/A arrayOop(old)->set_length(0);
0N/A obj_to_push = old;
0N/A assert(obj_to_push->is_forwarded() && obj_to_push->forwardee() != obj_to_push,
0N/A "push forwarded object");
0N/A }
0N/A // Push it on one of the queues of to-be-scanned objects.
534N/A bool simulate_overflow = false;
534N/A NOT_PRODUCT(
534N/A if (ParGCWorkQueueOverflowALot && should_simulate_overflow()) {
534N/A // simulate a stack overflow
534N/A simulate_overflow = true;
534N/A }
534N/A )
534N/A if (simulate_overflow || !par_scan_state->work_queue()->push(obj_to_push)) {
0N/A // Add stats for overflow pushes.
0N/A if (Verbose && PrintGCDetails) {
0N/A gclog_or_tty->print("queue overflow!\n");
0N/A }
534N/A push_on_overflow_list(old, par_scan_state);
1630N/A TASKQUEUE_STATS_ONLY(par_scan_state->taskqueue_stats().record_overflow(0));
0N/A }
0N/A
0N/A return new_obj;
0N/A }
0N/A
0N/A // Oops. Someone beat us to it. Undo the allocation. Where did we
0N/A // allocate it?
0N/A if (is_in_reserved(new_obj)) {
0N/A // Must be in to_space.
0N/A assert(to()->is_in_reserved(new_obj), "Checking");
0N/A if (forward_ptr == ClaimedForwardPtr) {
0N/A // Wait to get the real forwarding pointer value.
0N/A forward_ptr = real_forwardee(old);
0N/A }
0N/A par_scan_state->undo_alloc_in_to_space((HeapWord*)new_obj, sz);
0N/A }
0N/A
0N/A return forward_ptr;
0N/A}
0N/A
0N/A
0N/A// Multiple GC threads may try to promote the same object. If two
0N/A// or more GC threads copy the object, only one wins the race to install
0N/A// the forwarding pointer. The other threads have to undo their copy.
0N/A
0N/Aoop ParNewGeneration::copy_to_survivor_space_with_undo(
0N/A ParScanThreadState* par_scan_state, oop old, size_t sz, markOop m) {
0N/A
0N/A // In the sequential version, this assert also says that the object is
0N/A // not forwarded. That might not be the case here. It is the case that
0N/A // the caller observed it to be not forwarded at some time in the past.
0N/A assert(is_in_reserved(old), "shouldn't be scavenging this oop");
0N/A
0N/A // The sequential code read "old->age()" below. That doesn't work here,
0N/A // since the age is in the mark word, and that might be overwritten with
0N/A // a forwarding pointer by a parallel thread. So we must save the mark
0N/A // word here, install it in a local oopDesc, and then analyze it.
0N/A oopDesc dummyOld;
0N/A dummyOld.set_mark(m);
0N/A assert(!dummyOld.is_forwarded(),
0N/A "should not be called with forwarding pointer mark word.");
0N/A
0N/A bool failed_to_promote = false;
0N/A oop new_obj = NULL;
0N/A oop forward_ptr;
0N/A
0N/A // Try allocating obj in to-space (unless too old)
0N/A if (dummyOld.age() < tenuring_threshold()) {
0N/A new_obj = (oop)par_scan_state->alloc_in_to_space(sz);
0N/A if (new_obj == NULL) {
0N/A set_survivor_overflow(true);
0N/A }
0N/A }
0N/A
0N/A if (new_obj == NULL) {
0N/A // Either to-space is full or we decided to promote
0N/A // try allocating obj tenured
0N/A new_obj = _next_gen->par_promote(par_scan_state->thread_num(),
0N/A old, m, sz);
0N/A
0N/A if (new_obj == NULL) {
0N/A // promotion failed, forward to self
0N/A forward_ptr = old->forward_to_atomic(old);
0N/A new_obj = old;
0N/A
0N/A if (forward_ptr != NULL) {
0N/A return forward_ptr; // someone else succeeded
0N/A }
0N/A
0N/A _promotion_failed = true;
0N/A failed_to_promote = true;
0N/A
0N/A preserve_mark_if_necessary(old, m);
4302N/A par_scan_state->register_promotion_failure(sz);
0N/A }
0N/A } else {
0N/A // Is in to-space; do copying ourselves.
0N/A Copy::aligned_disjoint_words((HeapWord*)old, (HeapWord*)new_obj, sz);
0N/A // Restore the mark word copied above.
0N/A new_obj->set_mark(m);
0N/A // Increment age if new_obj still in new generation
0N/A new_obj->incr_age();
0N/A par_scan_state->age_table()->add(new_obj, sz);
0N/A }
0N/A assert(new_obj != NULL, "just checking");
0N/A
0N/A // Now attempt to install the forwarding pointer (atomically).
0N/A // We have to copy the mark word before overwriting with forwarding
0N/A // ptr, so we can restore it below in the copy.
0N/A if (!failed_to_promote) {
0N/A forward_ptr = old->forward_to_atomic(new_obj);
0N/A }
0N/A
0N/A if (forward_ptr == NULL) {
0N/A oop obj_to_push = new_obj;
0N/A if (par_scan_state->should_be_partially_scanned(obj_to_push, old)) {
0N/A // Length field used as index of next element to be scanned.
0N/A // Real length can be obtained from real_forwardee()
0N/A arrayOop(old)->set_length(0);
0N/A obj_to_push = old;
0N/A assert(obj_to_push->is_forwarded() && obj_to_push->forwardee() != obj_to_push,
0N/A "push forwarded object");
0N/A }
0N/A // Push it on one of the queues of to-be-scanned objects.
534N/A bool simulate_overflow = false;
534N/A NOT_PRODUCT(
534N/A if (ParGCWorkQueueOverflowALot && should_simulate_overflow()) {
534N/A // simulate a stack overflow
534N/A simulate_overflow = true;
534N/A }
534N/A )
534N/A if (simulate_overflow || !par_scan_state->work_queue()->push(obj_to_push)) {
0N/A // Add stats for overflow pushes.
534N/A push_on_overflow_list(old, par_scan_state);
1630N/A TASKQUEUE_STATS_ONLY(par_scan_state->taskqueue_stats().record_overflow(0));
0N/A }
0N/A
0N/A return new_obj;
0N/A }
0N/A
0N/A // Oops. Someone beat us to it. Undo the allocation. Where did we
0N/A // allocate it?
0N/A if (is_in_reserved(new_obj)) {
0N/A // Must be in to_space.
0N/A assert(to()->is_in_reserved(new_obj), "Checking");
0N/A par_scan_state->undo_alloc_in_to_space((HeapWord*)new_obj, sz);
0N/A } else {
0N/A assert(!_avoid_promotion_undo, "Should not be here if avoiding.");
0N/A _next_gen->par_promote_alloc_undo(par_scan_state->thread_num(),
0N/A (HeapWord*)new_obj, sz);
0N/A }
0N/A
0N/A return forward_ptr;
0N/A}
0N/A
534N/A#ifndef PRODUCT
534N/A// It's OK to call this multi-threaded; the worst thing
534N/A// that can happen is that we'll get a bunch of closely
534N/A// spaced simulated oveflows, but that's OK, in fact
534N/A// probably good as it would exercise the overflow code
534N/A// under contention.
534N/Abool ParNewGeneration::should_simulate_overflow() {
534N/A if (_overflow_counter-- <= 0) { // just being defensive
534N/A _overflow_counter = ParGCWorkQueueOverflowInterval;
534N/A return true;
534N/A } else {
534N/A return false;
534N/A }
534N/A}
534N/A#endif
534N/A
679N/A// In case we are using compressed oops, we need to be careful.
679N/A// If the object being pushed is an object array, then its length
679N/A// field keeps track of the "grey boundary" at which the next
679N/A// incremental scan will be done (see ParGCArrayScanChunk).
679N/A// When using compressed oops, this length field is kept in the
679N/A// lower 32 bits of the erstwhile klass word and cannot be used
679N/A// for the overflow chaining pointer (OCP below). As such the OCP
679N/A// would itself need to be compressed into the top 32-bits in this
679N/A// case. Unfortunately, see below, in the event that we have a
679N/A// promotion failure, the node to be pushed on the list can be
679N/A// outside of the Java heap, so the heap-based pointer compression
679N/A// would not work (we would have potential aliasing between C-heap
679N/A// and Java-heap pointers). For this reason, when using compressed
679N/A// oops, we simply use a worker-thread-local, non-shared overflow
679N/A// list in the form of a growable array, with a slightly different
679N/A// overflow stack draining strategy. If/when we start using fat
679N/A// stacks here, we can go back to using (fat) pointer chains
679N/A// (although some performance comparisons would be useful since
679N/A// single global lists have their own performance disadvantages
679N/A// as we were made painfully aware not long ago, see 6786503).
534N/A#define BUSY (oop(0x1aff1aff))
534N/Avoid ParNewGeneration::push_on_overflow_list(oop from_space_obj, ParScanThreadState* par_scan_state) {
679N/A assert(is_in_reserved(from_space_obj), "Should be from this generation");
695N/A if (ParGCUseLocalOverflow) {
679N/A // In the case of compressed oops, we use a private, not-shared
679N/A // overflow stack.
679N/A par_scan_state->push_on_overflow_stack(from_space_obj);
679N/A } else {
695N/A assert(!UseCompressedOops, "Error");
679N/A // if the object has been forwarded to itself, then we cannot
679N/A // use the klass pointer for the linked list. Instead we have
679N/A // to allocate an oopDesc in the C-Heap and use that for the linked list.
679N/A // XXX This is horribly inefficient when a promotion failure occurs
679N/A // and should be fixed. XXX FIX ME !!!
534N/A#ifndef PRODUCT
679N/A Atomic::inc_ptr(&_num_par_pushes);
679N/A assert(_num_par_pushes > 0, "Tautology");
534N/A#endif
679N/A if (from_space_obj->forwardee() == from_space_obj) {
3863N/A oopDesc* listhead = NEW_C_HEAP_ARRAY(oopDesc, 1, mtGC);
679N/A listhead->forward_to(from_space_obj);
679N/A from_space_obj = listhead;
679N/A }
679N/A oop observed_overflow_list = _overflow_list;
679N/A oop cur_overflow_list;
679N/A do {
679N/A cur_overflow_list = observed_overflow_list;
679N/A if (cur_overflow_list != BUSY) {
679N/A from_space_obj->set_klass_to_list_ptr(cur_overflow_list);
679N/A } else {
679N/A from_space_obj->set_klass_to_list_ptr(NULL);
679N/A }
679N/A observed_overflow_list =
679N/A (oop)Atomic::cmpxchg_ptr(from_space_obj, &_overflow_list, cur_overflow_list);
679N/A } while (cur_overflow_list != observed_overflow_list);
0N/A }
0N/A}
0N/A
679N/Abool ParNewGeneration::take_from_overflow_list(ParScanThreadState* par_scan_state) {
679N/A bool res;
679N/A
695N/A if (ParGCUseLocalOverflow) {
679N/A res = par_scan_state->take_from_overflow_stack();
679N/A } else {
695N/A assert(!UseCompressedOops, "Error");
679N/A res = take_from_overflow_list_work(par_scan_state);
679N/A }
679N/A return res;
679N/A}
679N/A
679N/A
534N/A// *NOTE*: The overflow list manipulation code here and
534N/A// in CMSCollector:: are very similar in shape,
534N/A// except that in the CMS case we thread the objects
534N/A// directly into the list via their mark word, and do
534N/A// not need to deal with special cases below related
534N/A// to chunking of object arrays and promotion failure
534N/A// handling.
534N/A// CR 6797058 has been filed to attempt consolidation of
534N/A// the common code.
534N/A// Because of the common code, if you make any changes in
534N/A// the code below, please check the CMS version to see if
534N/A// similar changes might be needed.
534N/A// See CMSCollector::par_take_from_overflow_list() for
534N/A// more extensive documentation comments.
679N/Abool ParNewGeneration::take_from_overflow_list_work(ParScanThreadState* par_scan_state) {
0N/A ObjToScanQueue* work_q = par_scan_state->work_queue();
0N/A // How many to take?
679N/A size_t objsFromOverflow = MIN2((size_t)(work_q->max_elems() - work_q->size())/4,
534N/A (size_t)ParGCDesiredObjsFromOverflowList);
0N/A
1756N/A assert(!UseCompressedOops, "Error");
679N/A assert(par_scan_state->overflow_stack() == NULL, "Error");
0N/A if (_overflow_list == NULL) return false;
0N/A
0N/A // Otherwise, there was something there; try claiming the list.
534N/A oop prefix = (oop)Atomic::xchg_ptr(BUSY, &_overflow_list);
534N/A // Trim off a prefix of at most objsFromOverflow items
534N/A Thread* tid = Thread::current();
534N/A size_t spin_count = (size_t)ParallelGCThreads;
534N/A size_t sleep_time_millis = MAX2((size_t)1, objsFromOverflow/100);
534N/A for (size_t spin = 0; prefix == BUSY && spin < spin_count; spin++) {
534N/A // someone grabbed it before we did ...
534N/A // ... we spin for a short while...
534N/A os::sleep(tid, sleep_time_millis, false);
534N/A if (_overflow_list == NULL) {
534N/A // nothing left to take
534N/A return false;
534N/A } else if (_overflow_list != BUSY) {
534N/A // try and grab the prefix
534N/A prefix = (oop)Atomic::xchg_ptr(BUSY, &_overflow_list);
534N/A }
0N/A }
534N/A if (prefix == NULL || prefix == BUSY) {
534N/A // Nothing to take or waited long enough
534N/A if (prefix == NULL) {
534N/A // Write back the NULL in case we overwrote it with BUSY above
534N/A // and it is still the same value.
534N/A (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY);
534N/A }
534N/A return false;
534N/A }
534N/A assert(prefix != NULL && prefix != BUSY, "Error");
534N/A size_t i = 1;
0N/A oop cur = prefix;
167N/A while (i < objsFromOverflow && cur->klass_or_null() != NULL) {
0N/A i++; cur = oop(cur->klass());
0N/A }
0N/A
0N/A // Reattach remaining (suffix) to overflow list
534N/A if (cur->klass_or_null() == NULL) {
534N/A // Write back the NULL in lieu of the BUSY we wrote
534N/A // above and it is still the same value.
534N/A if (_overflow_list == BUSY) {
534N/A (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY);
0N/A }
534N/A } else {
534N/A assert(cur->klass_or_null() != BUSY, "Error");
534N/A oop suffix = oop(cur->klass()); // suffix will be put back on global list
534N/A cur->set_klass_to_list_ptr(NULL); // break off suffix
534N/A // It's possible that the list is still in the empty(busy) state
534N/A // we left it in a short while ago; in that case we may be
534N/A // able to place back the suffix.
534N/A oop observed_overflow_list = _overflow_list;
534N/A oop cur_overflow_list = observed_overflow_list;
534N/A bool attached = false;
534N/A while (observed_overflow_list == BUSY || observed_overflow_list == NULL) {
534N/A observed_overflow_list =
534N/A (oop) Atomic::cmpxchg_ptr(suffix, &_overflow_list, cur_overflow_list);
534N/A if (cur_overflow_list == observed_overflow_list) {
534N/A attached = true;
534N/A break;
534N/A } else cur_overflow_list = observed_overflow_list;
534N/A }
534N/A if (!attached) {
534N/A // Too bad, someone else got in in between; we'll need to do a splice.
534N/A // Find the last item of suffix list
534N/A oop last = suffix;
534N/A while (last->klass_or_null() != NULL) {
534N/A last = oop(last->klass());
534N/A }
534N/A // Atomically prepend suffix to current overflow list
534N/A observed_overflow_list = _overflow_list;
534N/A do {
534N/A cur_overflow_list = observed_overflow_list;
534N/A if (cur_overflow_list != BUSY) {
534N/A // Do the splice ...
534N/A last->set_klass_to_list_ptr(cur_overflow_list);
534N/A } else { // cur_overflow_list == BUSY
534N/A last->set_klass_to_list_ptr(NULL);
534N/A }
534N/A observed_overflow_list =
534N/A (oop)Atomic::cmpxchg_ptr(suffix, &_overflow_list, cur_overflow_list);
534N/A } while (cur_overflow_list != observed_overflow_list);
0N/A }
0N/A }
0N/A
0N/A // Push objects on prefix list onto this thread's work queue
534N/A assert(prefix != NULL && prefix != BUSY, "program logic");
0N/A cur = prefix;
534N/A ssize_t n = 0;
0N/A while (cur != NULL) {
0N/A oop obj_to_push = cur->forwardee();
454N/A oop next = oop(cur->klass_or_null());
0N/A cur->set_klass(obj_to_push->klass());
534N/A // This may be an array object that is self-forwarded. In that case, the list pointer
534N/A // space, cur, is not in the Java heap, but rather in the C-heap and should be freed.
534N/A if (!is_in_reserved(cur)) {
534N/A // This can become a scaling bottleneck when there is work queue overflow coincident
534N/A // with promotion failure.
534N/A oopDesc* f = cur;
3863N/A FREE_C_HEAP_ARRAY(oopDesc, f, mtGC);
534N/A } else if (par_scan_state->should_be_partially_scanned(obj_to_push, cur)) {
0N/A assert(arrayOop(cur)->length() == 0, "entire array remaining to be scanned");
534N/A obj_to_push = cur;
0N/A }
534N/A bool ok = work_q->push(obj_to_push);
534N/A assert(ok, "Should have succeeded");
0N/A cur = next;
0N/A n++;
0N/A }
1630N/A TASKQUEUE_STATS_ONLY(par_scan_state->note_overflow_refill(n));
534N/A#ifndef PRODUCT
534N/A assert(_num_par_pushes >= n, "Too many pops?");
534N/A Atomic::add_ptr(-(intptr_t)n, &_num_par_pushes);
534N/A#endif
0N/A return true;
0N/A}
534N/A#undef BUSY
0N/A
4141N/Avoid ParNewGeneration::ref_processor_init() {
0N/A if (_ref_processor == NULL) {
0N/A // Allocate and initialize a reference processor
2216N/A _ref_processor =
2216N/A new ReferenceProcessor(_reserved, // span
2216N/A ParallelRefProcEnabled && (ParallelGCThreads > 1), // mt processing
2216N/A (int) ParallelGCThreads, // mt processing degree
2216N/A refs_discovery_is_mt(), // mt discovery
2216N/A (int) ParallelGCThreads, // mt discovery degree
2216N/A refs_discovery_is_atomic(), // atomic_discovery
2216N/A NULL, // is_alive_non_header
2216N/A false); // write barrier for next field updates
0N/A }
0N/A}
0N/A
0N/Aconst char* ParNewGeneration::name() const {
0N/A return "par new generation";
0N/A}
1753N/A
1753N/Abool ParNewGeneration::in_use() {
1753N/A return UseParNewGC && ParallelGCThreads > 0;
1753N/A}