Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.hpp
38920 views
/*1* Copyright (c) 2002, 2013, 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#ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_HPP25#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_HPP2627#include "gc_implementation/parallelScavenge/psPromotionLAB.hpp"28#include "gc_implementation/shared/gcTrace.hpp"29#include "gc_implementation/shared/copyFailedInfo.hpp"30#include "memory/allocation.hpp"31#include "memory/padded.hpp"32#include "utilities/globalDefinitions.hpp"33#include "utilities/taskqueue.hpp"3435//36// psPromotionManager is used by a single thread to manage object survival37// during a scavenge. The promotion manager contains thread local data only.38//39// NOTE! Be careful when allocating the stacks on cheap. If you are going40// to use a promotion manager in more than one thread, the stacks MUST be41// on cheap. This can lead to memory leaks, though, as they are not auto42// deallocated.43//44// FIX ME FIX ME Add a destructor, and don't rely on the user to drain/flush/deallocate!45//4647// Move to some global location48#define HAS_BEEN_MOVED 0x1501d01d49// End move to some global location5051class MutableSpace;52class PSOldGen;53class ParCompactionManager;5455class PSPromotionManager VALUE_OBJ_CLASS_SPEC {56friend class PSScavenge;57friend class PSRefProcTaskExecutor;58private:59static PaddedEnd<PSPromotionManager>* _manager_array;60static OopStarTaskQueueSet* _stack_array_depth;61static PSOldGen* _old_gen;62static MutableSpace* _young_space;6364#if TASKQUEUE_STATS65size_t _masked_pushes;66size_t _masked_steals;67size_t _arrays_chunked;68size_t _array_chunks_processed;6970void print_taskqueue_stats(uint i) const;71void print_local_stats(uint i) const;72static void print_stats();7374void reset_stats();75#endif // TASKQUEUE_STATS7677PSYoungPromotionLAB _young_lab;78PSOldPromotionLAB _old_lab;79bool _young_gen_is_full;80bool _old_gen_is_full;8182OopStarTaskQueue _claimed_stack_depth;83OverflowTaskQueue<oop, mtGC> _claimed_stack_breadth;8485bool _totally_drain;86uint _target_stack_size;8788uint _array_chunk_size;89uint _min_array_size_for_chunking;9091PromotionFailedInfo _promotion_failed_info;9293// Accessors94static PSOldGen* old_gen() { return _old_gen; }95static MutableSpace* young_space() { return _young_space; }9697inline static PSPromotionManager* manager_array(int index);98template <class T> inline void claim_or_forward_internal_depth(T* p);99100// On the task queues we push reference locations as well as101// partially-scanned arrays (in the latter case, we push an oop to102// the from-space image of the array and the length on the103// from-space image indicates how many entries on the array we still104// need to scan; this is basically how ParNew does partial array105// scanning too). To be able to distinguish between reference106// locations and partially-scanned array oops we simply mask the107// latter oops with 0x01. The next three methods do the masking,108// unmasking, and checking whether the oop is masked or not. Notice109// that the signature of the mask and unmask methods looks a bit110// strange, as they accept and return different types (oop and111// oop*). This is because of the difference in types between what112// the task queue holds (oop*) and oops to partially-scanned arrays113// (oop). We do all the necessary casting in the mask / unmask114// methods to avoid sprinkling the rest of the code with more casts.115116// These are added to the taskqueue so PS_CHUNKED_ARRAY_OOP_MASK (or any117// future masks) can't conflict with COMPRESSED_OOP_MASK118#define PS_CHUNKED_ARRAY_OOP_MASK 0x2119120bool is_oop_masked(StarTask p) {121// If something is marked chunked it's always treated like wide oop*122return (((intptr_t)(oop*)p) & PS_CHUNKED_ARRAY_OOP_MASK) ==123PS_CHUNKED_ARRAY_OOP_MASK;124}125126oop* mask_chunked_array_oop(oop obj) {127assert(!is_oop_masked((oop*) obj), "invariant");128oop* ret = (oop*) (cast_from_oop<uintptr_t>(obj) | PS_CHUNKED_ARRAY_OOP_MASK);129assert(is_oop_masked(ret), "invariant");130return ret;131}132133oop unmask_chunked_array_oop(StarTask p) {134assert(is_oop_masked(p), "invariant");135assert(!p.is_narrow(), "chunked array oops cannot be narrow");136oop *chunk = (oop*)p; // cast p to oop (uses conversion operator)137oop ret = oop((oop*)((uintptr_t)chunk & ~PS_CHUNKED_ARRAY_OOP_MASK));138assert(!is_oop_masked((oop*) ret), "invariant");139return ret;140}141142template <class T> void process_array_chunk_work(oop obj,143int start, int end);144void process_array_chunk(oop old);145146template <class T> void push_depth(T* p) {147claimed_stack_depth()->push(p);148}149150inline void promotion_trace_event(oop new_obj, oop old_obj, size_t obj_size,151uint age, bool tenured,152const PSPromotionLAB* lab);153154protected:155static OopStarTaskQueueSet* stack_array_depth() { return _stack_array_depth; }156public:157// Static158static void initialize();159160static void pre_scavenge();161static bool post_scavenge(YoungGCTracer& gc_tracer);162163static PSPromotionManager* gc_thread_promotion_manager(int index);164static PSPromotionManager* vm_thread_promotion_manager();165166static bool steal_depth(int queue_num, int* seed, StarTask& t) {167return stack_array_depth()->steal(queue_num, seed, t);168}169170PSPromotionManager();171172// Accessors173OopStarTaskQueue* claimed_stack_depth() {174return &_claimed_stack_depth;175}176177bool young_gen_is_full() { return _young_gen_is_full; }178179bool old_gen_is_full() { return _old_gen_is_full; }180void set_old_gen_is_full(bool state) { _old_gen_is_full = state; }181182// Promotion methods183template<bool promote_immediately> oop copy_to_survivor_space(oop o);184oop oop_promotion_failed(oop obj, markOop obj_mark);185186void reset();187188void flush_labs();189void drain_stacks(bool totally_drain) {190drain_stacks_depth(totally_drain);191}192public:193void drain_stacks_cond_depth() {194if (claimed_stack_depth()->size() > _target_stack_size) {195drain_stacks_depth(false);196}197}198void drain_stacks_depth(bool totally_drain);199200bool stacks_empty() {201return claimed_stack_depth()->is_empty();202}203204inline void process_popped_location_depth(StarTask p);205206template <class T> inline void claim_or_forward_depth(T* p);207208TASKQUEUE_STATS_ONLY(inline void record_steal(StarTask& p);)209};210211#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_HPP212213214