annotate src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.hpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 81cd571500b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 //
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // psPromotionManager is used by a single thread to manage object survival
a61af66fc99e Initial load
duke
parents:
diff changeset
27 // during a scavenge. The promotion manager contains thread local data only.
a61af66fc99e Initial load
duke
parents:
diff changeset
28 //
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // NOTE! Be carefull when allocating the stacks on cheap. If you are going
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // to use a promotion manager in more than one thread, the stacks MUST be
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // on cheap. This can lead to memory leaks, though, as they are not auto
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // deallocated.
a61af66fc99e Initial load
duke
parents:
diff changeset
33 //
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // FIX ME FIX ME Add a destructor, and don't rely on the user to drain/flush/deallocate!
a61af66fc99e Initial load
duke
parents:
diff changeset
35 //
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // Move to some global location
a61af66fc99e Initial load
duke
parents:
diff changeset
38 #define HAS_BEEN_MOVED 0x1501d01d
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // End move to some global location
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 class MutableSpace;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 class PSOldGen;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 class ParCompactionManager;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 class ObjectStartArray;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 class ParallelCompactData;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 class ParMarkBitMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // Move to it's own file if this works out.
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 class ParCompactionManager : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 friend class ParallelTaskTerminator;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 friend class ParMarkBitMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 friend class PSParallelCompact;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 friend class StealChunkCompactionTask;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 friend class UpdateAndFillClosure;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 friend class RefProcTaskExecutor;
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // ------------------------ Don't putback if not needed
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // Actions that the compaction manager should take.
a61af66fc99e Initial load
duke
parents:
diff changeset
63 enum Action {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 Update,
a61af66fc99e Initial load
duke
parents:
diff changeset
65 Copy,
a61af66fc99e Initial load
duke
parents:
diff changeset
66 UpdateAndCopy,
a61af66fc99e Initial load
duke
parents:
diff changeset
67 CopyAndUpdate,
a61af66fc99e Initial load
duke
parents:
diff changeset
68 VerifyUpdate,
a61af66fc99e Initial load
duke
parents:
diff changeset
69 ResetObjects,
a61af66fc99e Initial load
duke
parents:
diff changeset
70 NotValid
a61af66fc99e Initial load
duke
parents:
diff changeset
71 };
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // ------------------------ End don't putback if not needed
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
75 static ParCompactionManager** _manager_array;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 static OopTaskQueueSet* _stack_array;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 static ObjectStartArray* _start_array;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 static ChunkTaskQueueSet* _chunk_array;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 static PSOldGen* _old_gen;
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 OopTaskQueue _marking_stack;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 GrowableArray<oop>* _overflow_stack;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // Is there a way to reuse the _marking_stack for the
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // saving empty chunks? For now just create a different
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // type of TaskQueue.
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 #ifdef USE_ChunkTaskQueueWithOverflow
a61af66fc99e Initial load
duke
parents:
diff changeset
88 ChunkTaskQueueWithOverflow _chunk_stack;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
90 ChunkTaskQueue _chunk_stack;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 GrowableArray<size_t>* _chunk_overflow_stack;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 #if 1 // does this happen enough to need a per thread stack?
a61af66fc99e Initial load
duke
parents:
diff changeset
95 GrowableArray<Klass*>* _revisit_klass_stack;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
97 static ParMarkBitMap* _mark_bitmap;
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 Action _action;
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 static PSOldGen* old_gen() { return _old_gen; }
a61af66fc99e Initial load
duke
parents:
diff changeset
102 static ObjectStartArray* start_array() { return _start_array; }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 static OopTaskQueueSet* stack_array() { return _stack_array; }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 static void initialize(ParMarkBitMap* mbm);
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // Array of tasks. Needed by the ParallelTaskTerminator.
a61af66fc99e Initial load
duke
parents:
diff changeset
109 static ChunkTaskQueueSet* chunk_array() { return _chunk_array; }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 OopTaskQueue* marking_stack() { return &_marking_stack; }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 GrowableArray<oop>* overflow_stack() { return _overflow_stack; }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 #ifdef USE_ChunkTaskQueueWithOverflow
a61af66fc99e Initial load
duke
parents:
diff changeset
114 ChunkTaskQueueWithOverflow* chunk_stack() { return &_chunk_stack; }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
116 ChunkTaskQueue* chunk_stack() { return &_chunk_stack; }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 GrowableArray<size_t>* chunk_overflow_stack() { return _chunk_overflow_stack; }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // Pushes onto the marking stack. If the marking stack is full,
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // pushes onto the overflow stack.
a61af66fc99e Initial load
duke
parents:
diff changeset
122 void stack_push(oop obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // Do not implement an equivalent stack_pop. Deal with the
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // marking stack and overflow stack directly.
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // Pushes onto the chunk stack. If the chunk stack is full,
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // pushes onto the chunk overflow stack.
a61af66fc99e Initial load
duke
parents:
diff changeset
128 void chunk_stack_push(size_t chunk_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
129 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 Action action() { return _action; }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 void set_action(Action v) { _action = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 inline static ParCompactionManager* manager_array(int index);
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 ParCompactionManager();
a61af66fc99e Initial load
duke
parents:
diff changeset
137 ~ParCompactionManager();
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 void allocate_stacks();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 void deallocate_stacks();
a61af66fc99e Initial load
duke
parents:
diff changeset
141 ParMarkBitMap* mark_bitmap() { return _mark_bitmap; }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // Take actions in preparation for a compaction.
a61af66fc99e Initial load
duke
parents:
diff changeset
144 static void reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // void drain_stacks();
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 bool should_update();
a61af66fc99e Initial load
duke
parents:
diff changeset
149 bool should_copy();
a61af66fc99e Initial load
duke
parents:
diff changeset
150 bool should_verify_only();
a61af66fc99e Initial load
duke
parents:
diff changeset
151 bool should_reset_only();
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 #if 1
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // Probably stays as a growable array
a61af66fc99e Initial load
duke
parents:
diff changeset
155 GrowableArray<Klass*>* revisit_klass_stack() { return _revisit_klass_stack; }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // Save oop for later processing. Must not fail.
a61af66fc99e Initial load
duke
parents:
diff changeset
159 void save_for_scanning(oop m);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // Get a oop for scanning. If returns null, no oop were found.
a61af66fc99e Initial load
duke
parents:
diff changeset
161 oop retrieve_for_scanning();
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // Save chunk for later processing. Must not fail.
a61af66fc99e Initial load
duke
parents:
diff changeset
164 void save_for_processing(size_t chunk_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // Get a chunk for processing. If returns null, no chunk were found.
a61af66fc99e Initial load
duke
parents:
diff changeset
166 bool retrieve_for_processing(size_t& chunk_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // Access function for compaction managers
a61af66fc99e Initial load
duke
parents:
diff changeset
169 static ParCompactionManager* gc_thread_compaction_manager(int index);
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 static bool steal(int queue_num, int* seed, Task& t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 return stack_array()->steal(queue_num, seed, t);
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 static bool steal(int queue_num, int* seed, ChunkTask& t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 return chunk_array()->steal(queue_num, seed, t);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // Process tasks remaining on any stack
a61af66fc99e Initial load
duke
parents:
diff changeset
180 void drain_marking_stacks(OopClosure *blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // Process tasks remaining on any stack
a61af66fc99e Initial load
duke
parents:
diff changeset
183 void drain_chunk_stacks();
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // Process tasks remaining on any stack
a61af66fc99e Initial load
duke
parents:
diff changeset
186 void drain_chunk_overflow_stack();
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // Debugging support
a61af66fc99e Initial load
duke
parents:
diff changeset
189 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
190 bool stacks_have_been_allocated();
a61af66fc99e Initial load
duke
parents:
diff changeset
191 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
192 };
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 inline ParCompactionManager* ParCompactionManager::manager_array(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 assert(_manager_array != NULL, "access of NULL manager_array");
a61af66fc99e Initial load
duke
parents:
diff changeset
196 assert(index >= 0 && index <= (int)ParallelGCThreads,
a61af66fc99e Initial load
duke
parents:
diff changeset
197 "out of range manager_array access");
a61af66fc99e Initial load
duke
parents:
diff changeset
198 return _manager_array[index];
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }