Tue, 11 May 2010 14:35:43 -0700
6931180: Migration to recent versions of MS Platform SDK
6951582: Build problems on win64
Summary: Changes to enable building JDK7 with Microsoft Visual Studio 2010
Reviewed-by: ohair, art, ccheung, dcubed
1 /*
2 * Copyright 2000-2009 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 */
25 # include "incls/_precompiled.incl"
26 # include "incls/_sharedHeap.cpp.incl"
28 SharedHeap* SharedHeap::_sh;
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 };
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 UseG1GC) &&
62 ParallelGCThreads > 0) {
63 _workers = new WorkGang("Parallel GC Threads", ParallelGCThreads,
64 /* are_GC_task_threads */true,
65 /* are_ConcurrentGC_threads */false);
66 if (_workers == NULL) {
67 vm_exit_during_initialization("Failed necessary allocation.");
68 }
69 }
70 }
72 bool SharedHeap::heap_lock_held_for_gc() {
73 Thread* t = Thread::current();
74 return Heap_lock->owned_by_self()
75 || ( (t->is_GC_task_thread() || t->is_VM_thread())
76 && _thread_holds_heap_lock_for_gc);
77 }
79 void SharedHeap::set_par_threads(int t) {
80 _n_par_threads = t;
81 _process_strong_tasks->set_par_threads(t);
82 }
84 class AssertIsPermClosure: public OopClosure {
85 public:
86 virtual void do_oop(oop* p) {
87 assert((*p) == NULL || (*p)->is_perm(), "Referent should be perm.");
88 }
89 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
90 };
91 static AssertIsPermClosure assert_is_perm_closure;
93 void SharedHeap::change_strong_roots_parity() {
94 // Also set the new collection parity.
95 assert(_strong_roots_parity >= 0 && _strong_roots_parity <= 2,
96 "Not in range.");
97 _strong_roots_parity++;
98 if (_strong_roots_parity == 3) _strong_roots_parity = 1;
99 assert(_strong_roots_parity >= 1 && _strong_roots_parity <= 2,
100 "Not in range.");
101 }
103 SharedHeap::StrongRootsScope::StrongRootsScope(SharedHeap* outer, bool activate)
104 : MarkScope(activate)
105 {
106 if (_active) {
107 outer->change_strong_roots_parity();
108 }
109 }
111 SharedHeap::StrongRootsScope::~StrongRootsScope() {
112 // nothing particular
113 }
115 void SharedHeap::process_strong_roots(bool activate_scope,
116 bool collecting_perm_gen,
117 ScanningOption so,
118 OopClosure* roots,
119 CodeBlobClosure* code_roots,
120 OopsInGenClosure* perm_blk) {
121 StrongRootsScope srs(this, activate_scope);
122 // General strong roots.
123 assert(_strong_roots_parity != 0, "must have called prologue code");
124 if (!_process_strong_tasks->is_task_claimed(SH_PS_Universe_oops_do)) {
125 Universe::oops_do(roots);
126 ReferenceProcessor::oops_do(roots);
127 // Consider perm-gen discovered lists to be strong.
128 perm_gen()->ref_processor()->weak_oops_do(roots);
129 }
130 // Global (strong) JNI handles
131 if (!_process_strong_tasks->is_task_claimed(SH_PS_JNIHandles_oops_do))
132 JNIHandles::oops_do(roots);
133 // All threads execute this; the individual threads are task groups.
134 if (ParallelGCThreads > 0) {
135 Threads::possibly_parallel_oops_do(roots, code_roots);
136 } else {
137 Threads::oops_do(roots, code_roots);
138 }
139 if (!_process_strong_tasks-> is_task_claimed(SH_PS_ObjectSynchronizer_oops_do))
140 ObjectSynchronizer::oops_do(roots);
141 if (!_process_strong_tasks->is_task_claimed(SH_PS_FlatProfiler_oops_do))
142 FlatProfiler::oops_do(roots);
143 if (!_process_strong_tasks->is_task_claimed(SH_PS_Management_oops_do))
144 Management::oops_do(roots);
145 if (!_process_strong_tasks->is_task_claimed(SH_PS_jvmti_oops_do))
146 JvmtiExport::oops_do(roots);
148 if (!_process_strong_tasks->is_task_claimed(SH_PS_SystemDictionary_oops_do)) {
149 if (so & SO_AllClasses) {
150 SystemDictionary::oops_do(roots);
151 } else
152 if (so & SO_SystemClasses) {
153 SystemDictionary::always_strong_oops_do(roots);
154 }
155 }
157 if (!_process_strong_tasks->is_task_claimed(SH_PS_SymbolTable_oops_do)) {
158 if (so & SO_Symbols) {
159 SymbolTable::oops_do(roots);
160 }
161 // Verify if the symbol table contents are in the perm gen
162 NOT_PRODUCT(SymbolTable::oops_do(&assert_is_perm_closure));
163 }
165 if (!_process_strong_tasks->is_task_claimed(SH_PS_StringTable_oops_do)) {
166 if (so & SO_Strings) {
167 StringTable::oops_do(roots);
168 }
169 // Verify if the string table contents are in the perm gen
170 NOT_PRODUCT(StringTable::oops_do(&assert_is_perm_closure));
171 }
173 if (!_process_strong_tasks->is_task_claimed(SH_PS_CodeCache_oops_do)) {
174 if (so & SO_CodeCache) {
175 // (Currently, CMSCollector uses this to do intermediate-strength collections.)
176 assert(collecting_perm_gen, "scanning all of code cache");
177 assert(code_roots != NULL, "must supply closure for code cache");
178 if (code_roots != NULL) {
179 CodeCache::blobs_do(code_roots);
180 }
181 } else if (so & (SO_SystemClasses|SO_AllClasses)) {
182 if (!collecting_perm_gen) {
183 // If we are collecting from class statics, but we are not going to
184 // visit all of the CodeCache, collect from the non-perm roots if any.
185 // This makes the code cache function temporarily as a source of strong
186 // roots for oops, until the next major collection.
187 //
188 // If collecting_perm_gen is true, we require that this phase will call
189 // CodeCache::do_unloading. This will kill off nmethods with expired
190 // weak references, such as stale invokedynamic targets.
191 CodeCache::scavenge_root_nmethods_do(code_roots);
192 }
193 }
194 // Verify if the code cache contents are in the perm gen
195 NOT_PRODUCT(CodeBlobToOopClosure assert_code_is_perm(&assert_is_perm_closure, /*do_marking=*/ false));
196 NOT_PRODUCT(CodeCache::asserted_non_scavengable_nmethods_do(&assert_code_is_perm));
197 }
199 // Roots that should point only into permanent generation.
200 {
201 OopClosure* blk = NULL;
202 if (collecting_perm_gen) {
203 blk = roots;
204 } else {
205 debug_only(blk = &assert_is_perm_closure);
206 }
207 if (blk != NULL) {
208 if (!_process_strong_tasks->is_task_claimed(SH_PS_vmSymbols_oops_do))
209 vmSymbols::oops_do(blk);
210 }
211 }
213 if (!collecting_perm_gen) {
214 // All threads perform this; coordination is handled internally.
216 rem_set()->younger_refs_iterate(perm_gen(), perm_blk);
217 }
218 _process_strong_tasks->all_tasks_completed();
219 }
221 class AlwaysTrueClosure: public BoolObjectClosure {
222 public:
223 void do_object(oop p) { ShouldNotReachHere(); }
224 bool do_object_b(oop p) { return true; }
225 };
226 static AlwaysTrueClosure always_true;
228 class SkipAdjustingSharedStrings: public OopClosure {
229 OopClosure* _clo;
230 public:
231 SkipAdjustingSharedStrings(OopClosure* clo) : _clo(clo) {}
233 virtual void do_oop(oop* p) {
234 oop o = (*p);
235 if (!o->is_shared_readwrite()) {
236 _clo->do_oop(p);
237 }
238 }
239 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
240 };
242 // Unmarked shared Strings in the StringTable (which got there due to
243 // being in the constant pools of as-yet unloaded shared classes) were
244 // not marked and therefore did not have their mark words preserved.
245 // These entries are also deliberately not purged from the string
246 // table during unloading of unmarked strings. If an identity hash
247 // code was computed for any of these objects, it will not have been
248 // cleared to zero during the forwarding process or by the
249 // RecursiveAdjustSharedObjectClosure, and will be confused by the
250 // adjusting process as a forwarding pointer. We need to skip
251 // forwarding StringTable entries which contain unmarked shared
252 // Strings. Actually, since shared strings won't be moving, we can
253 // just skip adjusting any shared entries in the string table.
255 void SharedHeap::process_weak_roots(OopClosure* root_closure,
256 CodeBlobClosure* code_roots,
257 OopClosure* non_root_closure) {
258 // Global (weak) JNI handles
259 JNIHandles::weak_oops_do(&always_true, root_closure);
261 CodeCache::blobs_do(code_roots);
262 SymbolTable::oops_do(root_closure);
263 if (UseSharedSpaces && !DumpSharedSpaces) {
264 SkipAdjustingSharedStrings skip_closure(root_closure);
265 StringTable::oops_do(&skip_closure);
266 } else {
267 StringTable::oops_do(root_closure);
268 }
269 }
271 void SharedHeap::set_barrier_set(BarrierSet* bs) {
272 _barrier_set = bs;
273 // Cached barrier set for fast access in oops
274 oopDesc::set_bs(bs);
275 }
277 void SharedHeap::post_initialize() {
278 ref_processing_init();
279 }
281 void SharedHeap::ref_processing_init() {
282 perm_gen()->ref_processor_init();
283 }
285 // Some utilities.
286 void SharedHeap::print_size_transition(outputStream* out,
287 size_t bytes_before,
288 size_t bytes_after,
289 size_t capacity) {
290 out->print(" %d%s->%d%s(%d%s)",
291 byte_size_in_proper_unit(bytes_before),
292 proper_unit_for_byte_size(bytes_before),
293 byte_size_in_proper_unit(bytes_after),
294 proper_unit_for_byte_size(bytes_after),
295 byte_size_in_proper_unit(capacity),
296 proper_unit_for_byte_size(capacity));
297 }