1 #ifdef USE_PRAGMA_IDENT_SRC
2 #pragma ident "@(#)sharedHeap.cpp 1.59 07/05/17 15:55:10 JVM"
3 #endif
4 /*
5 * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * This code is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 only, as
10 * published by the Free Software Foundation.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
24 * have any questions.
25 *
43 SH_PS_SymbolTable_oops_do,
44 SH_PS_StringTable_oops_do,
45 SH_PS_CodeCache_oops_do,
46 // Leave this one last.
47 SH_PS_NumElements
48 };
49
50 SharedHeap::SharedHeap(CollectorPolicy* policy_) :
51 CollectedHeap(),
52 _collector_policy(policy_),
53 _perm_gen(NULL), _rem_set(NULL),
54 _strong_roots_parity(0),
55 _process_strong_tasks(new SubTasksDone(SH_PS_NumElements)),
56 _workers(NULL), _n_par_threads(0)
57 {
58 if (_process_strong_tasks == NULL || !_process_strong_tasks->valid()) {
59 vm_exit_during_initialization("Failed necessary allocation.");
60 }
61 _sh = this; // ch is static, should be set only once.
62 if ((UseParNewGC ||
63 (UseConcMarkSweepGC && CMSParallelRemarkEnabled)) &&
64 ParallelGCThreads > 0) {
65 _workers = new WorkGang("Parallel GC Threads", ParallelGCThreads, true);
66 if (_workers == NULL) {
67 vm_exit_during_initialization("Failed necessary allocation.");
68 }
69 }
70 }
71
72
73 void SharedHeap::set_par_threads(int t) {
74 _n_par_threads = t;
75 _process_strong_tasks->set_par_threads(t);
76 }
77
78 class AssertIsPermClosure: public OopClosure {
79 public:
80 void do_oop(oop* p) {
81 assert((*p) == NULL || (*p)->is_perm(), "Referent should be perm.");
82 }
83 };
84 static AssertIsPermClosure assert_is_perm_closure;
85
86 void SharedHeap::change_strong_roots_parity() {
87 // Also set the new collection parity.
88 assert(_strong_roots_parity >= 0 && _strong_roots_parity <= 2,
89 "Not in range.");
90 _strong_roots_parity++;
91 if (_strong_roots_parity == 3) _strong_roots_parity = 1;
92 assert(_strong_roots_parity >= 1 && _strong_roots_parity <= 2,
93 "Not in range.");
94 }
95
96 void SharedHeap::process_strong_roots(bool collecting_perm_gen,
97 ScanningOption so,
98 OopClosure* roots,
99 OopsInGenClosure* perm_blk) {
100 // General strong roots.
101 if (n_par_threads() == 0) change_strong_roots_parity();
102 if (!_process_strong_tasks->is_task_claimed(SH_PS_Universe_oops_do)) {
173 if (!collecting_perm_gen) {
174 // All threads perform this; coordination is handled internally.
175
176 rem_set()->younger_refs_iterate(perm_gen(), perm_blk);
177 }
178 _process_strong_tasks->all_tasks_completed();
179 }
180
181 class AlwaysTrueClosure: public BoolObjectClosure {
182 public:
183 void do_object(oop p) { ShouldNotReachHere(); }
184 bool do_object_b(oop p) { return true; }
185 };
186 static AlwaysTrueClosure always_true;
187
188 class SkipAdjustingSharedStrings: public OopClosure {
189 OopClosure* _clo;
190 public:
191 SkipAdjustingSharedStrings(OopClosure* clo) : _clo(clo) {}
192
193 void do_oop(oop* p) {
194 oop o = (*p);
195 if (!o->is_shared_readwrite()) {
196 _clo->do_oop(p);
197 }
198 }
199 };
200
201 // Unmarked shared Strings in the StringTable (which got there due to
202 // being in the constant pools of as-yet unloaded shared classes) were
203 // not marked and therefore did not have their mark words preserved.
204 // These entries are also deliberately not purged from the string
205 // table during unloading of unmarked strings. If an identity hash
206 // code was computed for any of these objects, it will not have been
207 // cleared to zero during the forwarding process or by the
208 // RecursiveAdjustSharedObjectClosure, and will be confused by the
209 // adjusting process as a forwarding pointer. We need to skip
210 // forwarding StringTable entries which contain unmarked shared
211 // Strings. Actually, since shared strings won't be moving, we can
212 // just skip adjusting any shared entries in the string table.
213
214 void SharedHeap::process_weak_roots(OopClosure* root_closure,
215 OopClosure* non_root_closure) {
216 // Global (weak) JNI handles
217 JNIHandles::weak_oops_do(&always_true, root_closure);
218
223 StringTable::oops_do(&skip_closure);
224 } else {
225 StringTable::oops_do(root_closure);
226 }
227 }
228
229 void SharedHeap::set_barrier_set(BarrierSet* bs) {
230 _barrier_set = bs;
231 // Cached barrier set for fast access in oops
232 oopDesc::set_bs(bs);
233 }
234
235 void SharedHeap::post_initialize() {
236 ref_processing_init();
237 }
238
239 void SharedHeap::ref_processing_init() {
240 perm_gen()->ref_processor_init();
241 }
242
243 void SharedHeap::fill_region_with_object(MemRegion mr) {
244 // Disable the posting of JVMTI VMObjectAlloc events as we
245 // don't want the filling of tlabs with filler arrays to be
246 // reported to the profiler.
247 NoJvmtiVMObjectAllocMark njm;
248
249 // Disable low memory detector because there is no real allocation.
250 LowMemoryDetectorDisabler lmd_dis;
251
252 // It turns out that post_allocation_setup_array takes a handle, so the
253 // call below contains an implicit conversion. Best to free that handle
254 // as soon as possible.
255 HandleMark hm;
256
257 size_t word_size = mr.word_size();
258 size_t aligned_array_header_size =
259 align_object_size(typeArrayOopDesc::header_size(T_INT));
260
261 if (word_size >= aligned_array_header_size) {
262 const size_t array_length =
263 pointer_delta(mr.end(), mr.start()) -
264 typeArrayOopDesc::header_size(T_INT);
265 const size_t array_length_words =
266 array_length * (HeapWordSize/sizeof(jint));
267 post_allocation_setup_array(Universe::intArrayKlassObj(),
268 mr.start(),
269 mr.word_size(),
270 (int)array_length_words);
271 #ifdef ASSERT
272 HeapWord* elt_words = (mr.start() + typeArrayOopDesc::header_size(T_INT));
273 Copy::fill_to_words(elt_words, array_length, 0xDEAFBABE);
274 #endif
275 } else {
276 assert(word_size == (size_t)oopDesc::header_size(), "Unaligned?");
277 post_allocation_setup_obj(SystemDictionary::object_klass(),
278 mr.start(),
279 mr.word_size());
280 }
281 }
282
283 // Some utilities.
284 void SharedHeap::print_size_transition(size_t bytes_before,
285 size_t bytes_after,
286 size_t capacity) {
287 tty->print(" %d%s->%d%s(%d%s)",
288 byte_size_in_proper_unit(bytes_before),
289 proper_unit_for_byte_size(bytes_before),
290 byte_size_in_proper_unit(bytes_after),
291 proper_unit_for_byte_size(bytes_after),
292 byte_size_in_proper_unit(capacity),
293 proper_unit_for_byte_size(capacity));
294 }
|
1 #ifdef USE_PRAGMA_IDENT_SRC
2 #pragma ident "@(#)sharedHeap.cpp 1.59 07/05/17 15:55:10 JVM"
3 #endif
4 /*
5 * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved.
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * This code is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 only, as
10 * published by the Free Software Foundation.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
24 * have any questions.
25 *
43 SH_PS_SymbolTable_oops_do,
44 SH_PS_StringTable_oops_do,
45 SH_PS_CodeCache_oops_do,
46 // Leave this one last.
47 SH_PS_NumElements
48 };
49
50 SharedHeap::SharedHeap(CollectorPolicy* policy_) :
51 CollectedHeap(),
52 _collector_policy(policy_),
53 _perm_gen(NULL), _rem_set(NULL),
54 _strong_roots_parity(0),
55 _process_strong_tasks(new SubTasksDone(SH_PS_NumElements)),
56 _workers(NULL), _n_par_threads(0)
57 {
58 if (_process_strong_tasks == NULL || !_process_strong_tasks->valid()) {
59 vm_exit_during_initialization("Failed necessary allocation.");
60 }
61 _sh = this; // ch is static, should be set only once.
62 if ((UseParNewGC ||
63 (UseConcMarkSweepGC && CMSParallelRemarkEnabled) ||
64 UseG1GC) &&
65 ParallelGCThreads > 0) {
66 _workers = new WorkGang("Parallel GC Threads", ParallelGCThreads,
67 /* are_GC_task_threads */true,
68 /* are_ConcurrentGC_threads */false);
69 if (_workers == NULL) {
70 vm_exit_during_initialization("Failed necessary allocation.");
71 }
72 }
73 }
74
75 bool SharedHeap::heap_lock_held_for_gc() {
76 Thread* t = Thread::current();
77 return Heap_lock->owned_by_self()
78 || ( (t->is_GC_task_thread() || t->is_VM_thread())
79 && _thread_holds_heap_lock_for_gc);
80 }
81
82 void SharedHeap::set_par_threads(int t) {
83 _n_par_threads = t;
84 _process_strong_tasks->set_par_threads(t);
85 }
86
87 class AssertIsPermClosure: public OopClosure {
88 public:
89 virtual void do_oop(oop* p) {
90 assert((*p) == NULL || (*p)->is_perm(), "Referent should be perm.");
91 }
92 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
93 };
94 static AssertIsPermClosure assert_is_perm_closure;
95
96 void SharedHeap::change_strong_roots_parity() {
97 // Also set the new collection parity.
98 assert(_strong_roots_parity >= 0 && _strong_roots_parity <= 2,
99 "Not in range.");
100 _strong_roots_parity++;
101 if (_strong_roots_parity == 3) _strong_roots_parity = 1;
102 assert(_strong_roots_parity >= 1 && _strong_roots_parity <= 2,
103 "Not in range.");
104 }
105
106 void SharedHeap::process_strong_roots(bool collecting_perm_gen,
107 ScanningOption so,
108 OopClosure* roots,
109 OopsInGenClosure* perm_blk) {
110 // General strong roots.
111 if (n_par_threads() == 0) change_strong_roots_parity();
112 if (!_process_strong_tasks->is_task_claimed(SH_PS_Universe_oops_do)) {
183 if (!collecting_perm_gen) {
184 // All threads perform this; coordination is handled internally.
185
186 rem_set()->younger_refs_iterate(perm_gen(), perm_blk);
187 }
188 _process_strong_tasks->all_tasks_completed();
189 }
190
191 class AlwaysTrueClosure: public BoolObjectClosure {
192 public:
193 void do_object(oop p) { ShouldNotReachHere(); }
194 bool do_object_b(oop p) { return true; }
195 };
196 static AlwaysTrueClosure always_true;
197
198 class SkipAdjustingSharedStrings: public OopClosure {
199 OopClosure* _clo;
200 public:
201 SkipAdjustingSharedStrings(OopClosure* clo) : _clo(clo) {}
202
203 virtual void do_oop(oop* p) {
204 oop o = (*p);
205 if (!o->is_shared_readwrite()) {
206 _clo->do_oop(p);
207 }
208 }
209 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
210 };
211
212 // Unmarked shared Strings in the StringTable (which got there due to
213 // being in the constant pools of as-yet unloaded shared classes) were
214 // not marked and therefore did not have their mark words preserved.
215 // These entries are also deliberately not purged from the string
216 // table during unloading of unmarked strings. If an identity hash
217 // code was computed for any of these objects, it will not have been
218 // cleared to zero during the forwarding process or by the
219 // RecursiveAdjustSharedObjectClosure, and will be confused by the
220 // adjusting process as a forwarding pointer. We need to skip
221 // forwarding StringTable entries which contain unmarked shared
222 // Strings. Actually, since shared strings won't be moving, we can
223 // just skip adjusting any shared entries in the string table.
224
225 void SharedHeap::process_weak_roots(OopClosure* root_closure,
226 OopClosure* non_root_closure) {
227 // Global (weak) JNI handles
228 JNIHandles::weak_oops_do(&always_true, root_closure);
229
234 StringTable::oops_do(&skip_closure);
235 } else {
236 StringTable::oops_do(root_closure);
237 }
238 }
239
240 void SharedHeap::set_barrier_set(BarrierSet* bs) {
241 _barrier_set = bs;
242 // Cached barrier set for fast access in oops
243 oopDesc::set_bs(bs);
244 }
245
246 void SharedHeap::post_initialize() {
247 ref_processing_init();
248 }
249
250 void SharedHeap::ref_processing_init() {
251 perm_gen()->ref_processor_init();
252 }
253
254 // Some utilities.
255 void SharedHeap::print_size_transition(outputStream* out,
256 size_t bytes_before,
257 size_t bytes_after,
258 size_t capacity) {
259 out->print(" %d%s->%d%s(%d%s)",
260 byte_size_in_proper_unit(bytes_before),
261 proper_unit_for_byte_size(bytes_before),
262 byte_size_in_proper_unit(bytes_after),
263 proper_unit_for_byte_size(bytes_after),
264 byte_size_in_proper_unit(capacity),
265 proper_unit_for_byte_size(capacity));
266 }
|