0
|
1 /*
|
|
2 * Copyright 2000-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 # include "incls/_precompiled.incl"
|
|
26 # include "incls/_sharedHeap.cpp.incl"
|
|
27
|
|
28 SharedHeap* SharedHeap::_sh;
|
|
29
|
|
30 // The set of potentially parallel tasks in strong root scanning.
|
|
31 enum SH_process_strong_roots_tasks {
|
|
32 SH_PS_Universe_oops_do,
|
|
33 SH_PS_JNIHandles_oops_do,
|
|
34 SH_PS_ObjectSynchronizer_oops_do,
|
|
35 SH_PS_FlatProfiler_oops_do,
|
|
36 SH_PS_Management_oops_do,
|
|
37 SH_PS_SystemDictionary_oops_do,
|
|
38 SH_PS_jvmti_oops_do,
|
|
39 SH_PS_vmSymbols_oops_do,
|
|
40 SH_PS_SymbolTable_oops_do,
|
|
41 SH_PS_StringTable_oops_do,
|
|
42 SH_PS_CodeCache_oops_do,
|
|
43 // Leave this one last.
|
|
44 SH_PS_NumElements
|
|
45 };
|
|
46
|
|
47 SharedHeap::SharedHeap(CollectorPolicy* policy_) :
|
|
48 CollectedHeap(),
|
|
49 _collector_policy(policy_),
|
|
50 _perm_gen(NULL), _rem_set(NULL),
|
|
51 _strong_roots_parity(0),
|
|
52 _process_strong_tasks(new SubTasksDone(SH_PS_NumElements)),
|
|
53 _workers(NULL), _n_par_threads(0)
|
|
54 {
|
|
55 if (_process_strong_tasks == NULL || !_process_strong_tasks->valid()) {
|
|
56 vm_exit_during_initialization("Failed necessary allocation.");
|
|
57 }
|
|
58 _sh = this; // ch is static, should be set only once.
|
|
59 if ((UseParNewGC ||
|
|
60 (UseConcMarkSweepGC && CMSParallelRemarkEnabled)) &&
|
|
61 ParallelGCThreads > 0) {
|
|
62 _workers = new WorkGang("Parallel GC Threads", ParallelGCThreads, true);
|
|
63 if (_workers == NULL) {
|
|
64 vm_exit_during_initialization("Failed necessary allocation.");
|
|
65 }
|
|
66 }
|
|
67 }
|
|
68
|
|
69
|
|
70 void SharedHeap::set_par_threads(int t) {
|
|
71 _n_par_threads = t;
|
|
72 _process_strong_tasks->set_par_threads(t);
|
|
73 }
|
|
74
|
|
75 class AssertIsPermClosure: public OopClosure {
|
|
76 public:
|
|
77 void do_oop(oop* p) {
|
|
78 assert((*p) == NULL || (*p)->is_perm(), "Referent should be perm.");
|
|
79 }
|
|
80 };
|
|
81 static AssertIsPermClosure assert_is_perm_closure;
|
|
82
|
|
83 void SharedHeap::change_strong_roots_parity() {
|
|
84 // Also set the new collection parity.
|
|
85 assert(_strong_roots_parity >= 0 && _strong_roots_parity <= 2,
|
|
86 "Not in range.");
|
|
87 _strong_roots_parity++;
|
|
88 if (_strong_roots_parity == 3) _strong_roots_parity = 1;
|
|
89 assert(_strong_roots_parity >= 1 && _strong_roots_parity <= 2,
|
|
90 "Not in range.");
|
|
91 }
|
|
92
|
|
93 void SharedHeap::process_strong_roots(bool collecting_perm_gen,
|
|
94 ScanningOption so,
|
|
95 OopClosure* roots,
|
|
96 OopsInGenClosure* perm_blk) {
|
|
97 // General strong roots.
|
|
98 if (n_par_threads() == 0) change_strong_roots_parity();
|
|
99 if (!_process_strong_tasks->is_task_claimed(SH_PS_Universe_oops_do)) {
|
|
100 Universe::oops_do(roots);
|
|
101 ReferenceProcessor::oops_do(roots);
|
|
102 // Consider perm-gen discovered lists to be strong.
|
|
103 perm_gen()->ref_processor()->weak_oops_do(roots);
|
|
104 }
|
|
105 // Global (strong) JNI handles
|
|
106 if (!_process_strong_tasks->is_task_claimed(SH_PS_JNIHandles_oops_do))
|
|
107 JNIHandles::oops_do(roots);
|
|
108 // All threads execute this; the individual threads are task groups.
|
|
109 if (ParallelGCThreads > 0) {
|
|
110 Threads::possibly_parallel_oops_do(roots);
|
|
111 } else {
|
|
112 Threads::oops_do(roots);
|
|
113 }
|
|
114 if (!_process_strong_tasks-> is_task_claimed(SH_PS_ObjectSynchronizer_oops_do))
|
|
115 ObjectSynchronizer::oops_do(roots);
|
|
116 if (!_process_strong_tasks->is_task_claimed(SH_PS_FlatProfiler_oops_do))
|
|
117 FlatProfiler::oops_do(roots);
|
|
118 if (!_process_strong_tasks->is_task_claimed(SH_PS_Management_oops_do))
|
|
119 Management::oops_do(roots);
|
|
120 if (!_process_strong_tasks->is_task_claimed(SH_PS_jvmti_oops_do))
|
|
121 JvmtiExport::oops_do(roots);
|
|
122
|
|
123 if (!_process_strong_tasks->is_task_claimed(SH_PS_SystemDictionary_oops_do)) {
|
|
124 if (so & SO_AllClasses) {
|
|
125 SystemDictionary::oops_do(roots);
|
|
126 } else
|
|
127 if (so & SO_SystemClasses) {
|
|
128 SystemDictionary::always_strong_oops_do(roots);
|
|
129 }
|
|
130 }
|
|
131
|
|
132 if (!_process_strong_tasks->is_task_claimed(SH_PS_SymbolTable_oops_do)) {
|
|
133 if (so & SO_Symbols) {
|
|
134 SymbolTable::oops_do(roots);
|
|
135 }
|
|
136 // Verify if the symbol table contents are in the perm gen
|
|
137 NOT_PRODUCT(SymbolTable::oops_do(&assert_is_perm_closure));
|
|
138 }
|
|
139
|
|
140 if (!_process_strong_tasks->is_task_claimed(SH_PS_StringTable_oops_do)) {
|
|
141 if (so & SO_Strings) {
|
|
142 StringTable::oops_do(roots);
|
|
143 }
|
|
144 // Verify if the string table contents are in the perm gen
|
|
145 NOT_PRODUCT(StringTable::oops_do(&assert_is_perm_closure));
|
|
146 }
|
|
147
|
|
148 if (!_process_strong_tasks->is_task_claimed(SH_PS_CodeCache_oops_do)) {
|
|
149 if (so & SO_CodeCache) {
|
|
150 CodeCache::oops_do(roots);
|
|
151 }
|
|
152 // Verify if the code cache contents are in the perm gen
|
|
153 NOT_PRODUCT(CodeCache::oops_do(&assert_is_perm_closure));
|
|
154 }
|
|
155
|
|
156 // Roots that should point only into permanent generation.
|
|
157 {
|
|
158 OopClosure* blk = NULL;
|
|
159 if (collecting_perm_gen) {
|
|
160 blk = roots;
|
|
161 } else {
|
|
162 debug_only(blk = &assert_is_perm_closure);
|
|
163 }
|
|
164 if (blk != NULL) {
|
|
165 if (!_process_strong_tasks->is_task_claimed(SH_PS_vmSymbols_oops_do))
|
|
166 vmSymbols::oops_do(blk);
|
|
167 }
|
|
168 }
|
|
169
|
|
170 if (!collecting_perm_gen) {
|
|
171 // All threads perform this; coordination is handled internally.
|
|
172
|
|
173 rem_set()->younger_refs_iterate(perm_gen(), perm_blk);
|
|
174 }
|
|
175 _process_strong_tasks->all_tasks_completed();
|
|
176 }
|
|
177
|
|
178 class AlwaysTrueClosure: public BoolObjectClosure {
|
|
179 public:
|
|
180 void do_object(oop p) { ShouldNotReachHere(); }
|
|
181 bool do_object_b(oop p) { return true; }
|
|
182 };
|
|
183 static AlwaysTrueClosure always_true;
|
|
184
|
|
185 class SkipAdjustingSharedStrings: public OopClosure {
|
|
186 OopClosure* _clo;
|
|
187 public:
|
|
188 SkipAdjustingSharedStrings(OopClosure* clo) : _clo(clo) {}
|
|
189
|
|
190 void do_oop(oop* p) {
|
|
191 oop o = (*p);
|
|
192 if (!o->is_shared_readwrite()) {
|
|
193 _clo->do_oop(p);
|
|
194 }
|
|
195 }
|
|
196 };
|
|
197
|
|
198 // Unmarked shared Strings in the StringTable (which got there due to
|
|
199 // being in the constant pools of as-yet unloaded shared classes) were
|
|
200 // not marked and therefore did not have their mark words preserved.
|
|
201 // These entries are also deliberately not purged from the string
|
|
202 // table during unloading of unmarked strings. If an identity hash
|
|
203 // code was computed for any of these objects, it will not have been
|
|
204 // cleared to zero during the forwarding process or by the
|
|
205 // RecursiveAdjustSharedObjectClosure, and will be confused by the
|
|
206 // adjusting process as a forwarding pointer. We need to skip
|
|
207 // forwarding StringTable entries which contain unmarked shared
|
|
208 // Strings. Actually, since shared strings won't be moving, we can
|
|
209 // just skip adjusting any shared entries in the string table.
|
|
210
|
|
211 void SharedHeap::process_weak_roots(OopClosure* root_closure,
|
|
212 OopClosure* non_root_closure) {
|
|
213 // Global (weak) JNI handles
|
|
214 JNIHandles::weak_oops_do(&always_true, root_closure);
|
|
215
|
|
216 CodeCache::oops_do(non_root_closure);
|
|
217 SymbolTable::oops_do(root_closure);
|
|
218 if (UseSharedSpaces && !DumpSharedSpaces) {
|
|
219 SkipAdjustingSharedStrings skip_closure(root_closure);
|
|
220 StringTable::oops_do(&skip_closure);
|
|
221 } else {
|
|
222 StringTable::oops_do(root_closure);
|
|
223 }
|
|
224 }
|
|
225
|
|
226 void SharedHeap::set_barrier_set(BarrierSet* bs) {
|
|
227 _barrier_set = bs;
|
|
228 // Cached barrier set for fast access in oops
|
|
229 oopDesc::set_bs(bs);
|
|
230 }
|
|
231
|
|
232 void SharedHeap::post_initialize() {
|
|
233 ref_processing_init();
|
|
234 }
|
|
235
|
|
236 void SharedHeap::ref_processing_init() {
|
|
237 perm_gen()->ref_processor_init();
|
|
238 }
|
|
239
|
|
240 void SharedHeap::fill_region_with_object(MemRegion mr) {
|
|
241 // Disable the posting of JVMTI VMObjectAlloc events as we
|
|
242 // don't want the filling of tlabs with filler arrays to be
|
|
243 // reported to the profiler.
|
|
244 NoJvmtiVMObjectAllocMark njm;
|
|
245
|
|
246 // Disable low memory detector because there is no real allocation.
|
|
247 LowMemoryDetectorDisabler lmd_dis;
|
|
248
|
|
249 // It turns out that post_allocation_setup_array takes a handle, so the
|
|
250 // call below contains an implicit conversion. Best to free that handle
|
|
251 // as soon as possible.
|
|
252 HandleMark hm;
|
|
253
|
|
254 size_t word_size = mr.word_size();
|
|
255 size_t aligned_array_header_size =
|
|
256 align_object_size(typeArrayOopDesc::header_size(T_INT));
|
|
257
|
|
258 if (word_size >= aligned_array_header_size) {
|
|
259 const size_t array_length =
|
|
260 pointer_delta(mr.end(), mr.start()) -
|
|
261 typeArrayOopDesc::header_size(T_INT);
|
|
262 const size_t array_length_words =
|
|
263 array_length * (HeapWordSize/sizeof(jint));
|
|
264 post_allocation_setup_array(Universe::intArrayKlassObj(),
|
|
265 mr.start(),
|
|
266 mr.word_size(),
|
|
267 (int)array_length_words);
|
|
268 #ifdef ASSERT
|
|
269 HeapWord* elt_words = (mr.start() + typeArrayOopDesc::header_size(T_INT));
|
|
270 Copy::fill_to_words(elt_words, array_length, 0xDEAFBABE);
|
|
271 #endif
|
|
272 } else {
|
|
273 assert(word_size == (size_t)oopDesc::header_size(), "Unaligned?");
|
|
274 post_allocation_setup_obj(SystemDictionary::object_klass(),
|
|
275 mr.start(),
|
|
276 mr.word_size());
|
|
277 }
|
|
278 }
|
|
279
|
|
280 // Some utilities.
|
|
281 void SharedHeap::print_size_transition(size_t bytes_before,
|
|
282 size_t bytes_after,
|
|
283 size_t capacity) {
|
|
284 tty->print(" %d%s->%d%s(%d%s)",
|
|
285 byte_size_in_proper_unit(bytes_before),
|
|
286 proper_unit_for_byte_size(bytes_before),
|
|
287 byte_size_in_proper_unit(bytes_after),
|
|
288 proper_unit_for_byte_size(bytes_after),
|
|
289 byte_size_in_proper_unit(capacity),
|
|
290 proper_unit_for_byte_size(capacity));
|
|
291 }
|