0N/A/*
3945N/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#ifndef SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARNEWGENERATION_HPP
1879N/A#define SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARNEWGENERATION_HPP
1879N/A
4302N/A#include "gc_implementation/shared/gcTrace.hpp"
3945N/A#include "gc_implementation/shared/parGCAllocBuffer.hpp"
4309N/A#include "gc_implementation/shared/copyFailedInfo.hpp"
1879N/A#include "memory/defNewGeneration.hpp"
1879N/A#include "utilities/taskqueue.hpp"
1879N/A
0N/Aclass ChunkArray;
0N/Aclass ParScanWithoutBarrierClosure;
0N/Aclass ParScanWithBarrierClosure;
0N/Aclass ParRootScanWithoutBarrierClosure;
0N/Aclass ParRootScanWithBarrierTwoGensClosure;
0N/Aclass ParEvacuateFollowersClosure;
0N/A
0N/A// It would be better if these types could be kept local to the .cpp file,
0N/A// but they must be here to allow ParScanClosure::do_oop_work to be defined
0N/A// in genOopClosures.inline.hpp.
0N/A
1585N/Atypedef Padded<OopTaskQueue> ObjToScanQueue;
3863N/Atypedef GenericTaskQueueSet<ObjToScanQueue, mtGC> ObjToScanQueueSet;
0N/A
0N/Aclass ParKeepAliveClosure: public DefNewGeneration::KeepAliveClosure {
113N/A private:
0N/A ParScanWeakRefClosure* _par_cl;
113N/A protected:
113N/A template <class T> void do_oop_work(T* p);
0N/A public:
0N/A ParKeepAliveClosure(ParScanWeakRefClosure* cl);
113N/A virtual void do_oop(oop* p);
113N/A virtual void do_oop(narrowOop* p);
0N/A};
0N/A
0N/A// The state needed by thread performing parallel young-gen collection.
0N/Aclass ParScanThreadState {
0N/A friend class ParScanThreadStateSet;
113N/A private:
0N/A ObjToScanQueue *_work_queue;
3863N/A Stack<oop, mtGC>* const _overflow_stack;
0N/A
0N/A ParGCAllocBuffer _to_space_alloc_buffer;
0N/A
0N/A ParScanWithoutBarrierClosure _to_space_closure; // scan_without_gc_barrier
0N/A ParScanWithBarrierClosure _old_gen_closure; // scan_with_gc_barrier
0N/A ParRootScanWithoutBarrierClosure _to_space_root_closure; // scan_root_without_gc_barrier
0N/A // One of these two will be passed to process_strong_roots, which will
0N/A // set its generation. The first is for two-gen configs where the
0N/A // old gen collects the perm gen; the second is for arbitrary configs.
0N/A // The second isn't used right now (it used to be used for the train, an
0N/A // incremental collector) but the declaration has been left as a reminder.
0N/A ParRootScanWithBarrierTwoGensClosure _older_gen_closure;
0N/A // This closure will always be bound to the old gen; it will be used
0N/A // in evacuate_followers.
0N/A ParRootScanWithBarrierTwoGensClosure _old_gen_root_closure; // scan_old_root_with_gc_barrier
0N/A ParEvacuateFollowersClosure _evacuate_followers;
0N/A DefNewGeneration::IsAliveClosure _is_alive_closure;
0N/A ParScanWeakRefClosure _scan_weak_ref_closure;
0N/A ParKeepAliveClosure _keep_alive_closure;
0N/A
0N/A
0N/A Space* _to_space;
0N/A Space* to_space() { return _to_space; }
0N/A
679N/A ParNewGeneration* _young_gen;
679N/A ParNewGeneration* young_gen() const { return _young_gen; }
679N/A
0N/A Generation* _old_gen;
0N/A Generation* old_gen() { return _old_gen; }
0N/A
0N/A HeapWord *_young_old_boundary;
0N/A
0N/A int _hash_seed;
0N/A int _thread_num;
0N/A ageTable _ageTable;
0N/A
0N/A bool _to_space_full;
0N/A
1630N/A#if TASKQUEUE_STATS
1630N/A size_t _term_attempts;
1630N/A size_t _overflow_refills;
1630N/A size_t _overflow_refill_objs;
1630N/A#endif // TASKQUEUE_STATS
0N/A
1145N/A // Stats for promotion failure
4302N/A PromotionFailedInfo _promotion_failed_info;
1145N/A
0N/A // Timing numbers.
0N/A double _start;
0N/A double _start_strong_roots;
0N/A double _strong_roots_time;
0N/A double _start_term;
0N/A double _term_time;
0N/A
0N/A // Helper for trim_queues. Scans subset of an array and makes
0N/A // remainder available for work stealing.
0N/A void scan_partial_array_and_push_remainder(oop obj);
0N/A
0N/A // In support of CMS' parallel rescan of survivor space.
0N/A ChunkArray* _survivor_chunk_array;
0N/A ChunkArray* survivor_chunk_array() { return _survivor_chunk_array; }
0N/A
0N/A void record_survivor_plab(HeapWord* plab_start, size_t plab_word_size);
0N/A
0N/A ParScanThreadState(Space* to_space_, ParNewGeneration* gen_,
0N/A Generation* old_gen_, int thread_num_,
695N/A ObjToScanQueueSet* work_queue_set_,
3863N/A Stack<oop, mtGC>* overflow_stacks_,
695N/A size_t desired_plab_sz_,
0N/A ParallelTaskTerminator& term_);
0N/A
113N/A public:
0N/A ageTable* age_table() {return &_ageTable;}
0N/A
0N/A ObjToScanQueue* work_queue() { return _work_queue; }
0N/A
0N/A ParGCAllocBuffer* to_space_alloc_buffer() {
0N/A return &_to_space_alloc_buffer;
0N/A }
0N/A
0N/A ParEvacuateFollowersClosure& evacuate_followers_closure() { return _evacuate_followers; }
0N/A DefNewGeneration::IsAliveClosure& is_alive_closure() { return _is_alive_closure; }
0N/A ParScanWeakRefClosure& scan_weak_ref_closure() { return _scan_weak_ref_closure; }
0N/A ParKeepAliveClosure& keep_alive_closure() { return _keep_alive_closure; }
0N/A ParScanClosure& older_gen_closure() { return _older_gen_closure; }
0N/A ParRootScanWithoutBarrierClosure& to_space_root_closure() { return _to_space_root_closure; };
0N/A
0N/A // Decrease queue size below "max_size".
0N/A void trim_queues(int max_size);
0N/A
679N/A // Private overflow stack usage
3863N/A Stack<oop, mtGC>* overflow_stack() { return _overflow_stack; }
679N/A bool take_from_overflow_stack();
679N/A void push_on_overflow_stack(oop p);
679N/A
0N/A // Is new_obj a candidate for scan_partial_array_and_push_remainder method.
0N/A inline bool should_be_partially_scanned(oop new_obj, oop old_obj) const;
0N/A
0N/A int* hash_seed() { return &_hash_seed; }
0N/A int thread_num() { return _thread_num; }
0N/A
0N/A // Allocate a to-space block of size "sz", or else return NULL.
0N/A HeapWord* alloc_in_to_space_slow(size_t word_sz);
0N/A
0N/A HeapWord* alloc_in_to_space(size_t word_sz) {
0N/A HeapWord* obj = to_space_alloc_buffer()->allocate(word_sz);
0N/A if (obj != NULL) return obj;
0N/A else return alloc_in_to_space_slow(word_sz);
0N/A }
0N/A
0N/A HeapWord* young_old_boundary() { return _young_old_boundary; }
0N/A
0N/A void set_young_old_boundary(HeapWord *boundary) {
0N/A _young_old_boundary = boundary;
0N/A }
0N/A
0N/A // Undo the most recent allocation ("obj", of "word_sz").
0N/A void undo_alloc_in_to_space(HeapWord* obj, size_t word_sz);
0N/A
1145N/A // Promotion failure stats
4302N/A void register_promotion_failure(size_t sz) {
4309N/A _promotion_failed_info.register_copy_failure(sz);
1145N/A }
4302N/A PromotionFailedInfo& promotion_failed_info() {
4302N/A return _promotion_failed_info;
4302N/A }
4302N/A bool promotion_failed() {
4309N/A return _promotion_failed_info.has_failed();
4302N/A }
4302N/A void print_promotion_failure_size();
1145N/A
1630N/A#if TASKQUEUE_STATS
1630N/A TaskQueueStats & taskqueue_stats() const { return _work_queue->stats; }
1630N/A
1630N/A size_t term_attempts() const { return _term_attempts; }
1630N/A size_t overflow_refills() const { return _overflow_refills; }
1630N/A size_t overflow_refill_objs() const { return _overflow_refill_objs; }
0N/A
1630N/A void note_term_attempt() { ++_term_attempts; }
1630N/A void note_overflow_refill(size_t objs) {
1630N/A ++_overflow_refills; _overflow_refill_objs += objs;
0N/A }
0N/A
1630N/A void reset_stats();
1630N/A#endif // TASKQUEUE_STATS
1630N/A
0N/A void start_strong_roots() {
0N/A _start_strong_roots = os::elapsedTime();
0N/A }
0N/A void end_strong_roots() {
0N/A _strong_roots_time += (os::elapsedTime() - _start_strong_roots);
0N/A }
1630N/A double strong_roots_time() const { return _strong_roots_time; }
0N/A void start_term_time() {
1630N/A TASKQUEUE_STATS_ONLY(note_term_attempt());
0N/A _start_term = os::elapsedTime();
0N/A }
0N/A void end_term_time() {
0N/A _term_time += (os::elapsedTime() - _start_term);
0N/A }
1630N/A double term_time() const { return _term_time; }
0N/A
1630N/A double elapsed_time() const {
0N/A return os::elapsedTime() - _start;
0N/A }
0N/A};
0N/A
0N/Aclass ParNewGenTask: public AbstractGangTask {
113N/A private:
113N/A ParNewGeneration* _gen;
113N/A Generation* _next_gen;
113N/A HeapWord* _young_old_boundary;
0N/A class ParScanThreadStateSet* _state_set;
0N/A
0N/Apublic:
0N/A ParNewGenTask(ParNewGeneration* gen,
0N/A Generation* next_gen,
0N/A HeapWord* young_old_boundary,
0N/A ParScanThreadStateSet* state_set);
0N/A
0N/A HeapWord* young_old_boundary() { return _young_old_boundary; }
0N/A
3008N/A void work(uint worker_id);
2941N/A
2941N/A // Reset the terminator in ParScanThreadStateSet for
2941N/A // "active_workers" threads.
2941N/A virtual void set_for_termination(int active_workers);
0N/A};
0N/A
0N/Aclass KeepAliveClosure: public DefNewGeneration::KeepAliveClosure {
113N/A protected:
113N/A template <class T> void do_oop_work(T* p);
0N/A public:
0N/A KeepAliveClosure(ScanWeakRefClosure* cl);
113N/A virtual void do_oop(oop* p);
113N/A virtual void do_oop(narrowOop* p);
0N/A};
0N/A
0N/Aclass EvacuateFollowersClosureGeneral: public VoidClosure {
113N/A private:
113N/A GenCollectedHeap* _gch;
113N/A int _level;
113N/A OopsInGenClosure* _scan_cur_or_nonheap;
113N/A OopsInGenClosure* _scan_older;
113N/A public:
113N/A EvacuateFollowersClosureGeneral(GenCollectedHeap* gch, int level,
113N/A OopsInGenClosure* cur,
113N/A OopsInGenClosure* older);
113N/A virtual void do_void();
0N/A};
0N/A
0N/A// Closure for scanning ParNewGeneration.
0N/A// Same as ScanClosure, except does parallel GC barrier.
0N/Aclass ScanClosureWithParBarrier: public ScanClosure {
113N/A protected:
113N/A template <class T> void do_oop_work(T* p);
113N/A public:
0N/A ScanClosureWithParBarrier(ParNewGeneration* g, bool gc_barrier);
113N/A virtual void do_oop(oop* p);
113N/A virtual void do_oop(narrowOop* p);
0N/A};
0N/A
0N/A// Implements AbstractRefProcTaskExecutor for ParNew.
0N/Aclass ParNewRefProcTaskExecutor: public AbstractRefProcTaskExecutor {
113N/A private:
113N/A ParNewGeneration& _generation;
113N/A ParScanThreadStateSet& _state_set;
113N/A public:
0N/A ParNewRefProcTaskExecutor(ParNewGeneration& generation,
0N/A ParScanThreadStateSet& state_set)
0N/A : _generation(generation), _state_set(state_set)
0N/A { }
0N/A
0N/A // Executes a task using worker threads.
0N/A virtual void execute(ProcessTask& task);
0N/A virtual void execute(EnqueueTask& task);
0N/A // Switch to single threaded mode.
0N/A virtual void set_single_threaded_mode();
0N/A};
0N/A
0N/A
0N/A// A Generation that does parallel young-gen collection.
0N/A
0N/Aclass ParNewGeneration: public DefNewGeneration {
0N/A friend class ParNewGenTask;
0N/A friend class ParNewRefProcTask;
0N/A friend class ParNewRefProcTaskExecutor;
0N/A friend class ParScanThreadStateSet;
534N/A friend class ParEvacuateFollowersClosure;
0N/A
113N/A private:
695N/A // The per-worker-thread work queues
0N/A ObjToScanQueueSet* _task_queues;
0N/A
695N/A // Per-worker-thread local overflow stacks
3863N/A Stack<oop, mtGC>* _overflow_stacks;
695N/A
0N/A // Desired size of survivor space plab's
0N/A PLABStats _plab_stats;
0N/A
0N/A // A list of from-space images of to-be-scanned objects, threaded through
0N/A // klass-pointers (klass information already copied to the forwarded
0N/A // image.) Manipulated with CAS.
0N/A oop _overflow_list;
534N/A NOT_PRODUCT(ssize_t _num_par_pushes;)
0N/A
0N/A // If true, older generation does not support promotion undo, so avoid.
0N/A static bool _avoid_promotion_undo;
0N/A
0N/A // This closure is used by the reference processor to filter out
0N/A // references to live referent.
0N/A DefNewGeneration::IsAliveClosure _is_alive_closure;
0N/A
0N/A static oop real_forwardee_slow(oop obj);
0N/A static void waste_some_time();
0N/A
0N/A // Preserve the mark of "obj", if necessary, in preparation for its mark
0N/A // word being overwritten with a self-forwarding-pointer.
0N/A void preserve_mark_if_necessary(oop obj, markOop m);
0N/A
4302N/A void handle_promotion_failed(GenCollectedHeap* gch, ParScanThreadStateSet& thread_state_set, ParNewTracer& gc_tracer);
4302N/A
0N/A protected:
0N/A
0N/A bool _survivor_overflow;
0N/A
0N/A bool avoid_promotion_undo() { return _avoid_promotion_undo; }
0N/A void set_avoid_promotion_undo(bool v) { _avoid_promotion_undo = v; }
0N/A
0N/A bool survivor_overflow() { return _survivor_overflow; }
0N/A void set_survivor_overflow(bool v) { _survivor_overflow = v; }
0N/A
0N/A // Adjust the tenuring threshold. See the implementation for
0N/A // the details of the policy.
0N/A virtual void adjust_desired_tenuring_threshold();
0N/A
113N/A public:
0N/A ParNewGeneration(ReservedSpace rs, size_t initial_byte_size, int level);
0N/A
0N/A ~ParNewGeneration() {
0N/A for (uint i = 0; i < ParallelGCThreads; i++)
0N/A delete _task_queues->queue(i);
0N/A
0N/A delete _task_queues;
0N/A }
0N/A
1753N/A static bool in_use();
1753N/A
0N/A virtual void ref_processor_init();
0N/A virtual Generation::Name kind() { return Generation::ParNew; }
0N/A virtual const char* name() const;
0N/A virtual const char* short_name() const { return "ParNew"; }
0N/A
0N/A // override
0N/A virtual bool refs_discovery_is_mt() const {
0N/A assert(UseParNewGC, "ParNewGeneration only when UseParNewGC");
0N/A return ParallelGCThreads > 1;
0N/A }
0N/A
0N/A // Make the collection virtual.
0N/A virtual void collect(bool full,
0N/A bool clear_all_soft_refs,
0N/A size_t size,
0N/A bool is_tlab);
0N/A
0N/A // This needs to be visible to the closure function.
0N/A // "obj" is the object to be copied, "m" is a recent value of its mark
0N/A // that must not contain a forwarding pointer (though one might be
0N/A // inserted in "obj"s mark word by a parallel thread).
0N/A inline oop copy_to_survivor_space(ParScanThreadState* par_scan_state,
0N/A oop obj, size_t obj_sz, markOop m) {
0N/A if (_avoid_promotion_undo) {
0N/A return copy_to_survivor_space_avoiding_promotion_undo(par_scan_state,
0N/A obj, obj_sz, m);
0N/A }
0N/A
0N/A return copy_to_survivor_space_with_undo(par_scan_state, obj, obj_sz, m);
0N/A }
0N/A
0N/A oop copy_to_survivor_space_avoiding_promotion_undo(ParScanThreadState* par_scan_state,
0N/A oop obj, size_t obj_sz, markOop m);
0N/A
0N/A oop copy_to_survivor_space_with_undo(ParScanThreadState* par_scan_state,
0N/A oop obj, size_t obj_sz, markOop m);
0N/A
534N/A // in support of testing overflow code
534N/A NOT_PRODUCT(int _overflow_counter;)
534N/A NOT_PRODUCT(bool should_simulate_overflow();)
534N/A
679N/A // Accessor for overflow list
679N/A oop overflow_list() { return _overflow_list; }
679N/A
0N/A // Push the given (from-space) object on the global overflow list.
534N/A void push_on_overflow_list(oop from_space_obj, ParScanThreadState* par_scan_state);
0N/A
0N/A // If the global overflow list is non-empty, move some tasks from it
679N/A // onto "work_q" (which need not be empty). No more than 1/4 of the
679N/A // available space on "work_q" is used.
0N/A bool take_from_overflow_list(ParScanThreadState* par_scan_state);
679N/A bool take_from_overflow_list_work(ParScanThreadState* par_scan_state);
0N/A
0N/A // The task queues to be used by parallel GC threads.
0N/A ObjToScanQueueSet* task_queues() {
0N/A return _task_queues;
0N/A }
0N/A
0N/A PLABStats* plab_stats() {
0N/A return &_plab_stats;
0N/A }
0N/A
0N/A size_t desired_plab_sz() {
0N/A return _plab_stats.desired_plab_sz();
0N/A }
0N/A
0N/A static oop real_forwardee(oop obj);
0N/A
0N/A DEBUG_ONLY(static bool is_legal_forward_ptr(oop p);)
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARNEWGENERATION_HPP