0N/A/*
3198N/A * Copyright (c) 2002, 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_PARALLELSCAVENGE_PSPROMOTIONMANAGER_HPP
1879N/A#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_HPP
1879N/A
1879N/A#include "gc_implementation/parallelScavenge/psPromotionLAB.hpp"
4302N/A#include "gc_implementation/shared/gcTrace.hpp"
4309N/A#include "gc_implementation/shared/copyFailedInfo.hpp"
1879N/A#include "memory/allocation.hpp"
1879N/A#include "utilities/taskqueue.hpp"
1879N/A
0N/A//
0N/A// psPromotionManager is used by a single thread to manage object survival
0N/A// during a scavenge. The promotion manager contains thread local data only.
0N/A//
4141N/A// NOTE! Be careful when allocating the stacks on cheap. If you are going
0N/A// to use a promotion manager in more than one thread, the stacks MUST be
0N/A// on cheap. This can lead to memory leaks, though, as they are not auto
0N/A// deallocated.
0N/A//
0N/A// FIX ME FIX ME Add a destructor, and don't rely on the user to drain/flush/deallocate!
0N/A//
0N/A
0N/A// Move to some global location
0N/A#define HAS_BEEN_MOVED 0x1501d01d
0N/A// End move to some global location
0N/A
0N/Aclass MutableSpace;
0N/Aclass PSOldGen;
0N/Aclass ParCompactionManager;
0N/A
3863N/Aclass PSPromotionManager : public CHeapObj<mtGC> {
0N/A friend class PSScavenge;
0N/A friend class PSRefProcTaskExecutor;
0N/A private:
0N/A static PSPromotionManager** _manager_array;
0N/A static OopStarTaskQueueSet* _stack_array_depth;
0N/A static PSOldGen* _old_gen;
0N/A static MutableSpace* _young_space;
0N/A
1585N/A#if TASKQUEUE_STATS
1585N/A size_t _masked_pushes;
1585N/A size_t _masked_steals;
1585N/A size_t _arrays_chunked;
1585N/A size_t _array_chunks_processed;
0N/A
1585N/A void print_taskqueue_stats(uint i) const;
1585N/A void print_local_stats(uint i) const;
1585N/A static void print_stats();
0N/A
1585N/A void reset_stats();
1585N/A#endif // TASKQUEUE_STATS
0N/A
0N/A PSYoungPromotionLAB _young_lab;
0N/A PSOldPromotionLAB _old_lab;
0N/A bool _young_gen_is_full;
0N/A bool _old_gen_is_full;
0N/A
0N/A OopStarTaskQueue _claimed_stack_depth;
3863N/A OverflowTaskQueue<oop, mtGC> _claimed_stack_breadth;
0N/A
0N/A bool _totally_drain;
0N/A uint _target_stack_size;
0N/A
0N/A uint _array_chunk_size;
0N/A uint _min_array_size_for_chunking;
0N/A
4141N/A PromotionFailedInfo _promotion_failed_info;
4141N/A
0N/A // Accessors
113N/A static PSOldGen* old_gen() { return _old_gen; }
113N/A static MutableSpace* young_space() { return _young_space; }
0N/A
0N/A inline static PSPromotionManager* manager_array(int index);
113N/A template <class T> inline void claim_or_forward_internal_depth(T* p);
0N/A
0N/A // On the task queues we push reference locations as well as
0N/A // partially-scanned arrays (in the latter case, we push an oop to
0N/A // the from-space image of the array and the length on the
0N/A // from-space image indicates how many entries on the array we still
0N/A // need to scan; this is basically how ParNew does partial array
0N/A // scanning too). To be able to distinguish between reference
0N/A // locations and partially-scanned array oops we simply mask the
0N/A // latter oops with 0x01. The next three methods do the masking,
0N/A // unmasking, and checking whether the oop is masked or not. Notice
0N/A // that the signature of the mask and unmask methods looks a bit
0N/A // strange, as they accept and return different types (oop and
0N/A // oop*). This is because of the difference in types between what
0N/A // the task queue holds (oop*) and oops to partially-scanned arrays
0N/A // (oop). We do all the necessary casting in the mask / unmask
0N/A // methods to avoid sprinkling the rest of the code with more casts.
0N/A
113N/A // These are added to the taskqueue so PS_CHUNKED_ARRAY_OOP_MASK (or any
113N/A // future masks) can't conflict with COMPRESSED_OOP_MASK
113N/A#define PS_CHUNKED_ARRAY_OOP_MASK 0x2
113N/A
113N/A bool is_oop_masked(StarTask p) {
113N/A // If something is marked chunked it's always treated like wide oop*
113N/A return (((intptr_t)(oop*)p) & PS_CHUNKED_ARRAY_OOP_MASK) ==
113N/A PS_CHUNKED_ARRAY_OOP_MASK;
0N/A }
0N/A
0N/A oop* mask_chunked_array_oop(oop obj) {
0N/A assert(!is_oop_masked((oop*) obj), "invariant");
113N/A oop* ret = (oop*) ((uintptr_t)obj | PS_CHUNKED_ARRAY_OOP_MASK);
0N/A assert(is_oop_masked(ret), "invariant");
0N/A return ret;
0N/A }
0N/A
113N/A oop unmask_chunked_array_oop(StarTask p) {
0N/A assert(is_oop_masked(p), "invariant");
113N/A assert(!p.is_narrow(), "chunked array oops cannot be narrow");
113N/A oop *chunk = (oop*)p; // cast p to oop (uses conversion operator)
113N/A oop ret = oop((oop*)((uintptr_t)chunk & ~PS_CHUNKED_ARRAY_OOP_MASK));
0N/A assert(!is_oop_masked((oop*) ret), "invariant");
0N/A return ret;
0N/A }
0N/A
113N/A template <class T> void process_array_chunk_work(oop obj,
113N/A int start, int end);
0N/A void process_array_chunk(oop old);
0N/A
113N/A template <class T> void push_depth(T* p) {
1558N/A claimed_stack_depth()->push(p);
0N/A }
0N/A
0N/A protected:
113N/A static OopStarTaskQueueSet* stack_array_depth() { return _stack_array_depth; }
0N/A public:
0N/A // Static
0N/A static void initialize();
0N/A
0N/A static void pre_scavenge();
4302N/A static bool post_scavenge(YoungGCTracer& gc_tracer);
0N/A
0N/A static PSPromotionManager* gc_thread_promotion_manager(int index);
0N/A static PSPromotionManager* vm_thread_promotion_manager();
0N/A
0N/A static bool steal_depth(int queue_num, int* seed, StarTask& t) {
0N/A return stack_array_depth()->steal(queue_num, seed, t);
0N/A }
0N/A
0N/A PSPromotionManager();
0N/A
0N/A // Accessors
0N/A OopStarTaskQueue* claimed_stack_depth() {
0N/A return &_claimed_stack_depth;
0N/A }
0N/A
0N/A bool young_gen_is_full() { return _young_gen_is_full; }
0N/A
0N/A bool old_gen_is_full() { return _old_gen_is_full; }
0N/A void set_old_gen_is_full(bool state) { _old_gen_is_full = state; }
0N/A
0N/A // Promotion methods
3198N/A template<bool promote_immediately> oop copy_to_survivor_space(oop o);
0N/A oop oop_promotion_failed(oop obj, markOop obj_mark);
0N/A
0N/A void reset();
0N/A
0N/A void flush_labs();
0N/A void drain_stacks(bool totally_drain) {
1626N/A drain_stacks_depth(totally_drain);
0N/A }
113N/A public:
0N/A void drain_stacks_cond_depth() {
0N/A if (claimed_stack_depth()->size() > _target_stack_size) {
0N/A drain_stacks_depth(false);
0N/A }
0N/A }
0N/A void drain_stacks_depth(bool totally_drain);
0N/A
0N/A bool stacks_empty() {
1626N/A return claimed_stack_depth()->is_empty();
0N/A }
0N/A
113N/A inline void process_popped_location_depth(StarTask p);
0N/A
113N/A template <class T> inline void claim_or_forward_depth(T* p);
0N/A
1585N/A TASKQUEUE_STATS_ONLY(inline void record_steal(StarTask& p);)
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_HPP