|
1 /* |
|
2 * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 * |
|
23 */ |
|
24 |
|
25 // |
|
26 // psPromotionManager is used by a single thread to manage object survival |
|
27 // during a scavenge. The promotion manager contains thread local data only. |
|
28 // |
|
29 // NOTE! Be carefull when allocating the stacks on cheap. If you are going |
|
30 // to use a promotion manager in more than one thread, the stacks MUST be |
|
31 // on cheap. This can lead to memory leaks, though, as they are not auto |
|
32 // deallocated. |
|
33 // |
|
34 // FIX ME FIX ME Add a destructor, and don't rely on the user to drain/flush/deallocate! |
|
35 // |
|
36 |
|
37 // Move to some global location |
|
38 #define HAS_BEEN_MOVED 0x1501d01d |
|
39 // End move to some global location |
|
40 |
|
41 class MutableSpace; |
|
42 class PSOldGen; |
|
43 class ParCompactionManager; |
|
44 |
|
45 #define PS_CHUNKED_ARRAY_OOP_MASK 1 |
|
46 |
|
47 #define PS_PM_STATS 0 |
|
48 |
|
49 class PSPromotionManager : public CHeapObj { |
|
50 friend class PSScavenge; |
|
51 friend class PSRefProcTaskExecutor; |
|
52 private: |
|
53 static PSPromotionManager** _manager_array; |
|
54 static OopStarTaskQueueSet* _stack_array_depth; |
|
55 static OopTaskQueueSet* _stack_array_breadth; |
|
56 static PSOldGen* _old_gen; |
|
57 static MutableSpace* _young_space; |
|
58 |
|
59 #if PS_PM_STATS |
|
60 uint _total_pushes; |
|
61 uint _masked_pushes; |
|
62 |
|
63 uint _overflow_pushes; |
|
64 uint _max_overflow_length; |
|
65 |
|
66 uint _arrays_chunked; |
|
67 uint _array_chunks_processed; |
|
68 |
|
69 uint _total_steals; |
|
70 uint _masked_steals; |
|
71 |
|
72 void print_stats(uint i); |
|
73 static void print_stats(); |
|
74 #endif // PS_PM_STATS |
|
75 |
|
76 PSYoungPromotionLAB _young_lab; |
|
77 PSOldPromotionLAB _old_lab; |
|
78 bool _young_gen_is_full; |
|
79 bool _old_gen_is_full; |
|
80 PrefetchQueue _prefetch_queue; |
|
81 |
|
82 OopStarTaskQueue _claimed_stack_depth; |
|
83 GrowableArray<oop*>* _overflow_stack_depth; |
|
84 OopTaskQueue _claimed_stack_breadth; |
|
85 GrowableArray<oop>* _overflow_stack_breadth; |
|
86 |
|
87 bool _depth_first; |
|
88 bool _totally_drain; |
|
89 uint _target_stack_size; |
|
90 |
|
91 uint _array_chunk_size; |
|
92 uint _min_array_size_for_chunking; |
|
93 |
|
94 // Accessors |
|
95 static PSOldGen* old_gen() { return _old_gen; } |
|
96 static MutableSpace* young_space() { return _young_space; } |
|
97 |
|
98 inline static PSPromotionManager* manager_array(int index); |
|
99 |
|
100 GrowableArray<oop*>* overflow_stack_depth() { return _overflow_stack_depth; } |
|
101 GrowableArray<oop>* overflow_stack_breadth() { return _overflow_stack_breadth; } |
|
102 |
|
103 // On the task queues we push reference locations as well as |
|
104 // partially-scanned arrays (in the latter case, we push an oop to |
|
105 // the from-space image of the array and the length on the |
|
106 // from-space image indicates how many entries on the array we still |
|
107 // need to scan; this is basically how ParNew does partial array |
|
108 // scanning too). To be able to distinguish between reference |
|
109 // locations and partially-scanned array oops we simply mask the |
|
110 // latter oops with 0x01. The next three methods do the masking, |
|
111 // unmasking, and checking whether the oop is masked or not. Notice |
|
112 // that the signature of the mask and unmask methods looks a bit |
|
113 // strange, as they accept and return different types (oop and |
|
114 // oop*). This is because of the difference in types between what |
|
115 // the task queue holds (oop*) and oops to partially-scanned arrays |
|
116 // (oop). We do all the necessary casting in the mask / unmask |
|
117 // methods to avoid sprinkling the rest of the code with more casts. |
|
118 |
|
119 bool is_oop_masked(oop* p) { |
|
120 return ((intptr_t) p & PS_CHUNKED_ARRAY_OOP_MASK) == PS_CHUNKED_ARRAY_OOP_MASK; |
|
121 } |
|
122 |
|
123 oop* mask_chunked_array_oop(oop obj) { |
|
124 assert(!is_oop_masked((oop*) obj), "invariant"); |
|
125 oop* ret = (oop*) ((intptr_t) obj | PS_CHUNKED_ARRAY_OOP_MASK); |
|
126 assert(is_oop_masked(ret), "invariant"); |
|
127 return ret; |
|
128 } |
|
129 |
|
130 oop unmask_chunked_array_oop(oop* p) { |
|
131 assert(is_oop_masked(p), "invariant"); |
|
132 oop ret = oop((intptr_t) p & ~PS_CHUNKED_ARRAY_OOP_MASK); |
|
133 assert(!is_oop_masked((oop*) ret), "invariant"); |
|
134 return ret; |
|
135 } |
|
136 |
|
137 void process_array_chunk(oop old); |
|
138 |
|
139 void push_depth(oop* p) { |
|
140 assert(depth_first(), "pre-condition"); |
|
141 |
|
142 #if PS_PM_STATS |
|
143 ++_total_pushes; |
|
144 #endif // PS_PM_STATS |
|
145 |
|
146 if (!claimed_stack_depth()->push(p)) { |
|
147 overflow_stack_depth()->push(p); |
|
148 #if PS_PM_STATS |
|
149 ++_overflow_pushes; |
|
150 uint stack_length = (uint) overflow_stack_depth()->length(); |
|
151 if (stack_length > _max_overflow_length) { |
|
152 _max_overflow_length = stack_length; |
|
153 } |
|
154 #endif // PS_PM_STATS |
|
155 } |
|
156 } |
|
157 |
|
158 void push_breadth(oop o) { |
|
159 assert(!depth_first(), "pre-condition"); |
|
160 |
|
161 #if PS_PM_STATS |
|
162 ++_total_pushes; |
|
163 #endif // PS_PM_STATS |
|
164 |
|
165 if(!claimed_stack_breadth()->push(o)) { |
|
166 overflow_stack_breadth()->push(o); |
|
167 #if PS_PM_STATS |
|
168 ++_overflow_pushes; |
|
169 uint stack_length = (uint) overflow_stack_breadth()->length(); |
|
170 if (stack_length > _max_overflow_length) { |
|
171 _max_overflow_length = stack_length; |
|
172 } |
|
173 #endif // PS_PM_STATS |
|
174 } |
|
175 } |
|
176 |
|
177 protected: |
|
178 static OopStarTaskQueueSet* stack_array_depth() { return _stack_array_depth; } |
|
179 static OopTaskQueueSet* stack_array_breadth() { return _stack_array_breadth; } |
|
180 |
|
181 public: |
|
182 // Static |
|
183 static void initialize(); |
|
184 |
|
185 static void pre_scavenge(); |
|
186 static void post_scavenge(); |
|
187 |
|
188 static PSPromotionManager* gc_thread_promotion_manager(int index); |
|
189 static PSPromotionManager* vm_thread_promotion_manager(); |
|
190 |
|
191 static bool steal_depth(int queue_num, int* seed, StarTask& t) { |
|
192 assert(stack_array_depth() != NULL, "invariant"); |
|
193 return stack_array_depth()->steal(queue_num, seed, t); |
|
194 } |
|
195 |
|
196 static bool steal_breadth(int queue_num, int* seed, Task& t) { |
|
197 assert(stack_array_breadth() != NULL, "invariant"); |
|
198 return stack_array_breadth()->steal(queue_num, seed, t); |
|
199 } |
|
200 |
|
201 PSPromotionManager(); |
|
202 |
|
203 // Accessors |
|
204 OopStarTaskQueue* claimed_stack_depth() { |
|
205 return &_claimed_stack_depth; |
|
206 } |
|
207 OopTaskQueue* claimed_stack_breadth() { |
|
208 return &_claimed_stack_breadth; |
|
209 } |
|
210 |
|
211 bool young_gen_is_full() { return _young_gen_is_full; } |
|
212 |
|
213 bool old_gen_is_full() { return _old_gen_is_full; } |
|
214 void set_old_gen_is_full(bool state) { _old_gen_is_full = state; } |
|
215 |
|
216 // Promotion methods |
|
217 oop copy_to_survivor_space(oop o, bool depth_first); |
|
218 oop oop_promotion_failed(oop obj, markOop obj_mark); |
|
219 |
|
220 void reset(); |
|
221 |
|
222 void flush_labs(); |
|
223 void drain_stacks(bool totally_drain) { |
|
224 if (depth_first()) { |
|
225 drain_stacks_depth(totally_drain); |
|
226 } else { |
|
227 drain_stacks_breadth(totally_drain); |
|
228 } |
|
229 } |
|
230 void drain_stacks_cond_depth() { |
|
231 if (claimed_stack_depth()->size() > _target_stack_size) { |
|
232 drain_stacks_depth(false); |
|
233 } |
|
234 } |
|
235 void drain_stacks_depth(bool totally_drain); |
|
236 void drain_stacks_breadth(bool totally_drain); |
|
237 |
|
238 bool claimed_stack_empty() { |
|
239 if (depth_first()) { |
|
240 return claimed_stack_depth()->size() <= 0; |
|
241 } else { |
|
242 return claimed_stack_breadth()->size() <= 0; |
|
243 } |
|
244 } |
|
245 bool overflow_stack_empty() { |
|
246 if (depth_first()) { |
|
247 return overflow_stack_depth()->length() <= 0; |
|
248 } else { |
|
249 return overflow_stack_breadth()->length() <= 0; |
|
250 } |
|
251 } |
|
252 bool stacks_empty() { |
|
253 return claimed_stack_empty() && overflow_stack_empty(); |
|
254 } |
|
255 bool depth_first() { |
|
256 return _depth_first; |
|
257 } |
|
258 |
|
259 inline void process_popped_location_depth(oop* p); |
|
260 |
|
261 inline void flush_prefetch_queue(); |
|
262 |
|
263 inline void claim_or_forward_depth(oop* p); |
|
264 inline void claim_or_forward_internal_depth(oop* p); |
|
265 |
|
266 inline void claim_or_forward_breadth(oop* p); |
|
267 inline void claim_or_forward_internal_breadth(oop* p); |
|
268 |
|
269 #if PS_PM_STATS |
|
270 void increment_steals(oop* p = NULL) { |
|
271 _total_steals += 1; |
|
272 if (p != NULL && is_oop_masked(p)) { |
|
273 _masked_steals += 1; |
|
274 } |
|
275 } |
|
276 #endif // PS_PM_STATS |
|
277 }; |