Mon, 20 Sep 2010 14:38:38 -0700
6984287: Regularize how GC parallel workers are specified.
Summary: Associate number of GC workers with the workgang as opposed to the task.
Reviewed-by: johnc, ysr
duke@435 | 1 | /* |
jcoomes@1993 | 2 | * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // |
duke@435 | 26 | // psPromotionManager is used by a single thread to manage object survival |
duke@435 | 27 | // during a scavenge. The promotion manager contains thread local data only. |
duke@435 | 28 | // |
duke@435 | 29 | // NOTE! Be carefull when allocating the stacks on cheap. If you are going |
duke@435 | 30 | // to use a promotion manager in more than one thread, the stacks MUST be |
duke@435 | 31 | // on cheap. This can lead to memory leaks, though, as they are not auto |
duke@435 | 32 | // deallocated. |
duke@435 | 33 | // |
duke@435 | 34 | // FIX ME FIX ME Add a destructor, and don't rely on the user to drain/flush/deallocate! |
duke@435 | 35 | // |
duke@435 | 36 | |
duke@435 | 37 | // Move to some global location |
duke@435 | 38 | #define HAS_BEEN_MOVED 0x1501d01d |
duke@435 | 39 | // End move to some global location |
duke@435 | 40 | |
duke@435 | 41 | class MutableSpace; |
duke@435 | 42 | class PSOldGen; |
duke@435 | 43 | class ParCompactionManager; |
duke@435 | 44 | |
duke@435 | 45 | class PSPromotionManager : public CHeapObj { |
duke@435 | 46 | friend class PSScavenge; |
duke@435 | 47 | friend class PSRefProcTaskExecutor; |
duke@435 | 48 | private: |
duke@435 | 49 | static PSPromotionManager** _manager_array; |
duke@435 | 50 | static OopStarTaskQueueSet* _stack_array_depth; |
duke@435 | 51 | static PSOldGen* _old_gen; |
duke@435 | 52 | static MutableSpace* _young_space; |
duke@435 | 53 | |
jcoomes@2020 | 54 | #if TASKQUEUE_STATS |
jcoomes@2020 | 55 | size_t _masked_pushes; |
jcoomes@2020 | 56 | size_t _masked_steals; |
jcoomes@2020 | 57 | size_t _arrays_chunked; |
jcoomes@2020 | 58 | size_t _array_chunks_processed; |
duke@435 | 59 | |
jcoomes@2020 | 60 | void print_taskqueue_stats(uint i) const; |
jcoomes@2020 | 61 | void print_local_stats(uint i) const; |
jcoomes@2020 | 62 | static void print_stats(); |
duke@435 | 63 | |
jcoomes@2020 | 64 | void reset_stats(); |
jcoomes@2020 | 65 | #endif // TASKQUEUE_STATS |
duke@435 | 66 | |
duke@435 | 67 | PSYoungPromotionLAB _young_lab; |
duke@435 | 68 | PSOldPromotionLAB _old_lab; |
duke@435 | 69 | bool _young_gen_is_full; |
duke@435 | 70 | bool _old_gen_is_full; |
duke@435 | 71 | |
duke@435 | 72 | OopStarTaskQueue _claimed_stack_depth; |
jcoomes@1993 | 73 | OverflowTaskQueue<oop> _claimed_stack_breadth; |
duke@435 | 74 | |
duke@435 | 75 | bool _totally_drain; |
duke@435 | 76 | uint _target_stack_size; |
duke@435 | 77 | |
duke@435 | 78 | uint _array_chunk_size; |
duke@435 | 79 | uint _min_array_size_for_chunking; |
duke@435 | 80 | |
duke@435 | 81 | // Accessors |
coleenp@548 | 82 | static PSOldGen* old_gen() { return _old_gen; } |
coleenp@548 | 83 | static MutableSpace* young_space() { return _young_space; } |
duke@435 | 84 | |
duke@435 | 85 | inline static PSPromotionManager* manager_array(int index); |
coleenp@548 | 86 | template <class T> inline void claim_or_forward_internal_depth(T* p); |
duke@435 | 87 | |
duke@435 | 88 | // On the task queues we push reference locations as well as |
duke@435 | 89 | // partially-scanned arrays (in the latter case, we push an oop to |
duke@435 | 90 | // the from-space image of the array and the length on the |
duke@435 | 91 | // from-space image indicates how many entries on the array we still |
duke@435 | 92 | // need to scan; this is basically how ParNew does partial array |
duke@435 | 93 | // scanning too). To be able to distinguish between reference |
duke@435 | 94 | // locations and partially-scanned array oops we simply mask the |
duke@435 | 95 | // latter oops with 0x01. The next three methods do the masking, |
duke@435 | 96 | // unmasking, and checking whether the oop is masked or not. Notice |
duke@435 | 97 | // that the signature of the mask and unmask methods looks a bit |
duke@435 | 98 | // strange, as they accept and return different types (oop and |
duke@435 | 99 | // oop*). This is because of the difference in types between what |
duke@435 | 100 | // the task queue holds (oop*) and oops to partially-scanned arrays |
duke@435 | 101 | // (oop). We do all the necessary casting in the mask / unmask |
duke@435 | 102 | // methods to avoid sprinkling the rest of the code with more casts. |
duke@435 | 103 | |
coleenp@548 | 104 | // These are added to the taskqueue so PS_CHUNKED_ARRAY_OOP_MASK (or any |
coleenp@548 | 105 | // future masks) can't conflict with COMPRESSED_OOP_MASK |
coleenp@548 | 106 | #define PS_CHUNKED_ARRAY_OOP_MASK 0x2 |
coleenp@548 | 107 | |
coleenp@548 | 108 | bool is_oop_masked(StarTask p) { |
coleenp@548 | 109 | // If something is marked chunked it's always treated like wide oop* |
coleenp@548 | 110 | return (((intptr_t)(oop*)p) & PS_CHUNKED_ARRAY_OOP_MASK) == |
coleenp@548 | 111 | PS_CHUNKED_ARRAY_OOP_MASK; |
duke@435 | 112 | } |
duke@435 | 113 | |
duke@435 | 114 | oop* mask_chunked_array_oop(oop obj) { |
duke@435 | 115 | assert(!is_oop_masked((oop*) obj), "invariant"); |
coleenp@548 | 116 | oop* ret = (oop*) ((uintptr_t)obj | PS_CHUNKED_ARRAY_OOP_MASK); |
duke@435 | 117 | assert(is_oop_masked(ret), "invariant"); |
duke@435 | 118 | return ret; |
duke@435 | 119 | } |
duke@435 | 120 | |
coleenp@548 | 121 | oop unmask_chunked_array_oop(StarTask p) { |
duke@435 | 122 | assert(is_oop_masked(p), "invariant"); |
coleenp@548 | 123 | assert(!p.is_narrow(), "chunked array oops cannot be narrow"); |
coleenp@548 | 124 | oop *chunk = (oop*)p; // cast p to oop (uses conversion operator) |
coleenp@548 | 125 | oop ret = oop((oop*)((uintptr_t)chunk & ~PS_CHUNKED_ARRAY_OOP_MASK)); |
duke@435 | 126 | assert(!is_oop_masked((oop*) ret), "invariant"); |
duke@435 | 127 | return ret; |
duke@435 | 128 | } |
duke@435 | 129 | |
coleenp@548 | 130 | template <class T> void process_array_chunk_work(oop obj, |
coleenp@548 | 131 | int start, int end); |
duke@435 | 132 | void process_array_chunk(oop old); |
duke@435 | 133 | |
coleenp@548 | 134 | template <class T> void push_depth(T* p) { |
jcoomes@1993 | 135 | claimed_stack_depth()->push(p); |
duke@435 | 136 | } |
duke@435 | 137 | |
duke@435 | 138 | protected: |
coleenp@548 | 139 | static OopStarTaskQueueSet* stack_array_depth() { return _stack_array_depth; } |
duke@435 | 140 | public: |
duke@435 | 141 | // Static |
duke@435 | 142 | static void initialize(); |
duke@435 | 143 | |
duke@435 | 144 | static void pre_scavenge(); |
duke@435 | 145 | static void post_scavenge(); |
duke@435 | 146 | |
duke@435 | 147 | static PSPromotionManager* gc_thread_promotion_manager(int index); |
duke@435 | 148 | static PSPromotionManager* vm_thread_promotion_manager(); |
duke@435 | 149 | |
duke@435 | 150 | static bool steal_depth(int queue_num, int* seed, StarTask& t) { |
duke@435 | 151 | return stack_array_depth()->steal(queue_num, seed, t); |
duke@435 | 152 | } |
duke@435 | 153 | |
duke@435 | 154 | PSPromotionManager(); |
duke@435 | 155 | |
duke@435 | 156 | // Accessors |
duke@435 | 157 | OopStarTaskQueue* claimed_stack_depth() { |
duke@435 | 158 | return &_claimed_stack_depth; |
duke@435 | 159 | } |
duke@435 | 160 | |
duke@435 | 161 | bool young_gen_is_full() { return _young_gen_is_full; } |
duke@435 | 162 | |
duke@435 | 163 | bool old_gen_is_full() { return _old_gen_is_full; } |
duke@435 | 164 | void set_old_gen_is_full(bool state) { _old_gen_is_full = state; } |
duke@435 | 165 | |
duke@435 | 166 | // Promotion methods |
tonyp@2061 | 167 | oop copy_to_survivor_space(oop o); |
duke@435 | 168 | oop oop_promotion_failed(oop obj, markOop obj_mark); |
duke@435 | 169 | |
duke@435 | 170 | void reset(); |
duke@435 | 171 | |
duke@435 | 172 | void flush_labs(); |
duke@435 | 173 | void drain_stacks(bool totally_drain) { |
tonyp@2061 | 174 | drain_stacks_depth(totally_drain); |
duke@435 | 175 | } |
coleenp@548 | 176 | public: |
duke@435 | 177 | void drain_stacks_cond_depth() { |
duke@435 | 178 | if (claimed_stack_depth()->size() > _target_stack_size) { |
duke@435 | 179 | drain_stacks_depth(false); |
duke@435 | 180 | } |
duke@435 | 181 | } |
duke@435 | 182 | void drain_stacks_depth(bool totally_drain); |
duke@435 | 183 | |
duke@435 | 184 | bool stacks_empty() { |
tonyp@2061 | 185 | return claimed_stack_depth()->is_empty(); |
duke@435 | 186 | } |
duke@435 | 187 | |
coleenp@548 | 188 | inline void process_popped_location_depth(StarTask p); |
duke@435 | 189 | |
coleenp@548 | 190 | template <class T> inline void claim_or_forward_depth(T* p); |
duke@435 | 191 | |
jcoomes@2020 | 192 | TASKQUEUE_STATS_ONLY(inline void record_steal(StarTask& p);) |
duke@435 | 193 | }; |