Sun, 11 Oct 2009 16:19:25 -0700
6888953: some calls to function-like macros are missing semicolons
Reviewed-by: pbk, kvn
duke@435 | 1 | /* |
xdono@1014 | 2 | * Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_sharedHeap.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | SharedHeap* SharedHeap::_sh; |
duke@435 | 29 | |
duke@435 | 30 | // The set of potentially parallel tasks in strong root scanning. |
duke@435 | 31 | enum SH_process_strong_roots_tasks { |
duke@435 | 32 | SH_PS_Universe_oops_do, |
duke@435 | 33 | SH_PS_JNIHandles_oops_do, |
duke@435 | 34 | SH_PS_ObjectSynchronizer_oops_do, |
duke@435 | 35 | SH_PS_FlatProfiler_oops_do, |
duke@435 | 36 | SH_PS_Management_oops_do, |
duke@435 | 37 | SH_PS_SystemDictionary_oops_do, |
duke@435 | 38 | SH_PS_jvmti_oops_do, |
duke@435 | 39 | SH_PS_vmSymbols_oops_do, |
duke@435 | 40 | SH_PS_SymbolTable_oops_do, |
duke@435 | 41 | SH_PS_StringTable_oops_do, |
duke@435 | 42 | SH_PS_CodeCache_oops_do, |
duke@435 | 43 | // Leave this one last. |
duke@435 | 44 | SH_PS_NumElements |
duke@435 | 45 | }; |
duke@435 | 46 | |
duke@435 | 47 | SharedHeap::SharedHeap(CollectorPolicy* policy_) : |
duke@435 | 48 | CollectedHeap(), |
duke@435 | 49 | _collector_policy(policy_), |
duke@435 | 50 | _perm_gen(NULL), _rem_set(NULL), |
duke@435 | 51 | _strong_roots_parity(0), |
duke@435 | 52 | _process_strong_tasks(new SubTasksDone(SH_PS_NumElements)), |
duke@435 | 53 | _workers(NULL), _n_par_threads(0) |
duke@435 | 54 | { |
duke@435 | 55 | if (_process_strong_tasks == NULL || !_process_strong_tasks->valid()) { |
duke@435 | 56 | vm_exit_during_initialization("Failed necessary allocation."); |
duke@435 | 57 | } |
duke@435 | 58 | _sh = this; // ch is static, should be set only once. |
duke@435 | 59 | if ((UseParNewGC || |
ysr@777 | 60 | (UseConcMarkSweepGC && CMSParallelRemarkEnabled) || |
ysr@777 | 61 | UseG1GC) && |
duke@435 | 62 | ParallelGCThreads > 0) { |
ysr@777 | 63 | _workers = new WorkGang("Parallel GC Threads", ParallelGCThreads, |
ysr@777 | 64 | /* are_GC_task_threads */true, |
ysr@777 | 65 | /* are_ConcurrentGC_threads */false); |
duke@435 | 66 | if (_workers == NULL) { |
duke@435 | 67 | vm_exit_during_initialization("Failed necessary allocation."); |
duke@435 | 68 | } |
duke@435 | 69 | } |
duke@435 | 70 | } |
duke@435 | 71 | |
ysr@777 | 72 | bool SharedHeap::heap_lock_held_for_gc() { |
ysr@777 | 73 | Thread* t = Thread::current(); |
ysr@777 | 74 | return Heap_lock->owned_by_self() |
ysr@777 | 75 | || ( (t->is_GC_task_thread() || t->is_VM_thread()) |
ysr@777 | 76 | && _thread_holds_heap_lock_for_gc); |
ysr@777 | 77 | } |
duke@435 | 78 | |
duke@435 | 79 | void SharedHeap::set_par_threads(int t) { |
duke@435 | 80 | _n_par_threads = t; |
duke@435 | 81 | _process_strong_tasks->set_par_threads(t); |
duke@435 | 82 | } |
duke@435 | 83 | |
duke@435 | 84 | class AssertIsPermClosure: public OopClosure { |
duke@435 | 85 | public: |
coleenp@548 | 86 | virtual void do_oop(oop* p) { |
duke@435 | 87 | assert((*p) == NULL || (*p)->is_perm(), "Referent should be perm."); |
duke@435 | 88 | } |
coleenp@548 | 89 | virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
duke@435 | 90 | }; |
duke@435 | 91 | static AssertIsPermClosure assert_is_perm_closure; |
duke@435 | 92 | |
duke@435 | 93 | void SharedHeap::change_strong_roots_parity() { |
duke@435 | 94 | // Also set the new collection parity. |
duke@435 | 95 | assert(_strong_roots_parity >= 0 && _strong_roots_parity <= 2, |
duke@435 | 96 | "Not in range."); |
duke@435 | 97 | _strong_roots_parity++; |
duke@435 | 98 | if (_strong_roots_parity == 3) _strong_roots_parity = 1; |
duke@435 | 99 | assert(_strong_roots_parity >= 1 && _strong_roots_parity <= 2, |
duke@435 | 100 | "Not in range."); |
duke@435 | 101 | } |
duke@435 | 102 | |
jrose@1424 | 103 | SharedHeap::StrongRootsScope::StrongRootsScope(SharedHeap* outer, bool activate) |
jrose@1424 | 104 | : MarkScope(activate) |
jrose@1424 | 105 | { |
jrose@1424 | 106 | if (_active) { |
jrose@1424 | 107 | outer->change_strong_roots_parity(); |
jrose@1424 | 108 | } |
jrose@1424 | 109 | } |
jrose@1424 | 110 | |
jrose@1424 | 111 | SharedHeap::StrongRootsScope::~StrongRootsScope() { |
jrose@1424 | 112 | // nothing particular |
jrose@1424 | 113 | } |
jrose@1424 | 114 | |
jrose@1424 | 115 | void SharedHeap::process_strong_roots(bool activate_scope, |
jrose@1424 | 116 | bool collecting_perm_gen, |
duke@435 | 117 | ScanningOption so, |
duke@435 | 118 | OopClosure* roots, |
jrose@1424 | 119 | CodeBlobClosure* code_roots, |
duke@435 | 120 | OopsInGenClosure* perm_blk) { |
jrose@1424 | 121 | StrongRootsScope srs(this, activate_scope); |
duke@435 | 122 | // General strong roots. |
jrose@1424 | 123 | assert(_strong_roots_parity != 0, "must have called prologue code"); |
duke@435 | 124 | if (!_process_strong_tasks->is_task_claimed(SH_PS_Universe_oops_do)) { |
duke@435 | 125 | Universe::oops_do(roots); |
duke@435 | 126 | ReferenceProcessor::oops_do(roots); |
duke@435 | 127 | // Consider perm-gen discovered lists to be strong. |
duke@435 | 128 | perm_gen()->ref_processor()->weak_oops_do(roots); |
duke@435 | 129 | } |
duke@435 | 130 | // Global (strong) JNI handles |
duke@435 | 131 | if (!_process_strong_tasks->is_task_claimed(SH_PS_JNIHandles_oops_do)) |
duke@435 | 132 | JNIHandles::oops_do(roots); |
duke@435 | 133 | // All threads execute this; the individual threads are task groups. |
duke@435 | 134 | if (ParallelGCThreads > 0) { |
jrose@1424 | 135 | Threads::possibly_parallel_oops_do(roots, code_roots); |
duke@435 | 136 | } else { |
jrose@1424 | 137 | Threads::oops_do(roots, code_roots); |
duke@435 | 138 | } |
duke@435 | 139 | if (!_process_strong_tasks-> is_task_claimed(SH_PS_ObjectSynchronizer_oops_do)) |
duke@435 | 140 | ObjectSynchronizer::oops_do(roots); |
duke@435 | 141 | if (!_process_strong_tasks->is_task_claimed(SH_PS_FlatProfiler_oops_do)) |
duke@435 | 142 | FlatProfiler::oops_do(roots); |
duke@435 | 143 | if (!_process_strong_tasks->is_task_claimed(SH_PS_Management_oops_do)) |
duke@435 | 144 | Management::oops_do(roots); |
duke@435 | 145 | if (!_process_strong_tasks->is_task_claimed(SH_PS_jvmti_oops_do)) |
duke@435 | 146 | JvmtiExport::oops_do(roots); |
duke@435 | 147 | |
duke@435 | 148 | if (!_process_strong_tasks->is_task_claimed(SH_PS_SystemDictionary_oops_do)) { |
duke@435 | 149 | if (so & SO_AllClasses) { |
duke@435 | 150 | SystemDictionary::oops_do(roots); |
duke@435 | 151 | } else |
duke@435 | 152 | if (so & SO_SystemClasses) { |
duke@435 | 153 | SystemDictionary::always_strong_oops_do(roots); |
duke@435 | 154 | } |
duke@435 | 155 | } |
duke@435 | 156 | |
duke@435 | 157 | if (!_process_strong_tasks->is_task_claimed(SH_PS_SymbolTable_oops_do)) { |
duke@435 | 158 | if (so & SO_Symbols) { |
duke@435 | 159 | SymbolTable::oops_do(roots); |
duke@435 | 160 | } |
duke@435 | 161 | // Verify if the symbol table contents are in the perm gen |
duke@435 | 162 | NOT_PRODUCT(SymbolTable::oops_do(&assert_is_perm_closure)); |
duke@435 | 163 | } |
duke@435 | 164 | |
duke@435 | 165 | if (!_process_strong_tasks->is_task_claimed(SH_PS_StringTable_oops_do)) { |
duke@435 | 166 | if (so & SO_Strings) { |
duke@435 | 167 | StringTable::oops_do(roots); |
duke@435 | 168 | } |
duke@435 | 169 | // Verify if the string table contents are in the perm gen |
duke@435 | 170 | NOT_PRODUCT(StringTable::oops_do(&assert_is_perm_closure)); |
duke@435 | 171 | } |
duke@435 | 172 | |
duke@435 | 173 | if (!_process_strong_tasks->is_task_claimed(SH_PS_CodeCache_oops_do)) { |
jrose@1424 | 174 | if (so & SO_CodeCache) { |
jrose@1424 | 175 | // (Currently, CMSCollector uses this to do intermediate-strength collections.) |
jrose@1424 | 176 | assert(collecting_perm_gen, "scanning all of code cache"); |
jrose@1424 | 177 | assert(code_roots != NULL, "must supply closure for code cache"); |
jrose@1424 | 178 | if (code_roots != NULL) { |
jrose@1424 | 179 | CodeCache::blobs_do(code_roots); |
jrose@1424 | 180 | } |
jrose@1424 | 181 | } else if (so & (SO_SystemClasses|SO_AllClasses)) { |
jrose@1424 | 182 | if (!collecting_perm_gen) { |
jrose@1424 | 183 | // If we are collecting from class statics, but we are not going to |
jrose@1424 | 184 | // visit all of the CodeCache, collect from the non-perm roots if any. |
jrose@1424 | 185 | // This makes the code cache function temporarily as a source of strong |
jrose@1424 | 186 | // roots for oops, until the next major collection. |
jrose@1424 | 187 | // |
jrose@1424 | 188 | // If collecting_perm_gen is true, we require that this phase will call |
jrose@1424 | 189 | // CodeCache::do_unloading. This will kill off nmethods with expired |
jrose@1424 | 190 | // weak references, such as stale invokedynamic targets. |
jrose@1424 | 191 | CodeCache::scavenge_root_nmethods_do(code_roots); |
jrose@1424 | 192 | } |
jrose@1424 | 193 | } |
duke@435 | 194 | // Verify if the code cache contents are in the perm gen |
jrose@1424 | 195 | NOT_PRODUCT(CodeBlobToOopClosure assert_code_is_perm(&assert_is_perm_closure, /*do_marking=*/ false)); |
jrose@1424 | 196 | NOT_PRODUCT(CodeCache::asserted_non_scavengable_nmethods_do(&assert_code_is_perm)); |
duke@435 | 197 | } |
duke@435 | 198 | |
duke@435 | 199 | // Roots that should point only into permanent generation. |
duke@435 | 200 | { |
duke@435 | 201 | OopClosure* blk = NULL; |
duke@435 | 202 | if (collecting_perm_gen) { |
duke@435 | 203 | blk = roots; |
duke@435 | 204 | } else { |
duke@435 | 205 | debug_only(blk = &assert_is_perm_closure); |
duke@435 | 206 | } |
duke@435 | 207 | if (blk != NULL) { |
duke@435 | 208 | if (!_process_strong_tasks->is_task_claimed(SH_PS_vmSymbols_oops_do)) |
duke@435 | 209 | vmSymbols::oops_do(blk); |
duke@435 | 210 | } |
duke@435 | 211 | } |
duke@435 | 212 | |
duke@435 | 213 | if (!collecting_perm_gen) { |
duke@435 | 214 | // All threads perform this; coordination is handled internally. |
duke@435 | 215 | |
duke@435 | 216 | rem_set()->younger_refs_iterate(perm_gen(), perm_blk); |
duke@435 | 217 | } |
duke@435 | 218 | _process_strong_tasks->all_tasks_completed(); |
duke@435 | 219 | } |
duke@435 | 220 | |
duke@435 | 221 | class AlwaysTrueClosure: public BoolObjectClosure { |
duke@435 | 222 | public: |
duke@435 | 223 | void do_object(oop p) { ShouldNotReachHere(); } |
duke@435 | 224 | bool do_object_b(oop p) { return true; } |
duke@435 | 225 | }; |
duke@435 | 226 | static AlwaysTrueClosure always_true; |
duke@435 | 227 | |
duke@435 | 228 | class SkipAdjustingSharedStrings: public OopClosure { |
duke@435 | 229 | OopClosure* _clo; |
duke@435 | 230 | public: |
duke@435 | 231 | SkipAdjustingSharedStrings(OopClosure* clo) : _clo(clo) {} |
duke@435 | 232 | |
coleenp@548 | 233 | virtual void do_oop(oop* p) { |
duke@435 | 234 | oop o = (*p); |
duke@435 | 235 | if (!o->is_shared_readwrite()) { |
duke@435 | 236 | _clo->do_oop(p); |
duke@435 | 237 | } |
duke@435 | 238 | } |
coleenp@548 | 239 | virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
duke@435 | 240 | }; |
duke@435 | 241 | |
duke@435 | 242 | // Unmarked shared Strings in the StringTable (which got there due to |
duke@435 | 243 | // being in the constant pools of as-yet unloaded shared classes) were |
duke@435 | 244 | // not marked and therefore did not have their mark words preserved. |
duke@435 | 245 | // These entries are also deliberately not purged from the string |
duke@435 | 246 | // table during unloading of unmarked strings. If an identity hash |
duke@435 | 247 | // code was computed for any of these objects, it will not have been |
duke@435 | 248 | // cleared to zero during the forwarding process or by the |
duke@435 | 249 | // RecursiveAdjustSharedObjectClosure, and will be confused by the |
duke@435 | 250 | // adjusting process as a forwarding pointer. We need to skip |
duke@435 | 251 | // forwarding StringTable entries which contain unmarked shared |
duke@435 | 252 | // Strings. Actually, since shared strings won't be moving, we can |
duke@435 | 253 | // just skip adjusting any shared entries in the string table. |
duke@435 | 254 | |
duke@435 | 255 | void SharedHeap::process_weak_roots(OopClosure* root_closure, |
jrose@1424 | 256 | CodeBlobClosure* code_roots, |
duke@435 | 257 | OopClosure* non_root_closure) { |
duke@435 | 258 | // Global (weak) JNI handles |
duke@435 | 259 | JNIHandles::weak_oops_do(&always_true, root_closure); |
duke@435 | 260 | |
jrose@1424 | 261 | CodeCache::blobs_do(code_roots); |
duke@435 | 262 | SymbolTable::oops_do(root_closure); |
duke@435 | 263 | if (UseSharedSpaces && !DumpSharedSpaces) { |
duke@435 | 264 | SkipAdjustingSharedStrings skip_closure(root_closure); |
duke@435 | 265 | StringTable::oops_do(&skip_closure); |
duke@435 | 266 | } else { |
duke@435 | 267 | StringTable::oops_do(root_closure); |
duke@435 | 268 | } |
duke@435 | 269 | } |
duke@435 | 270 | |
duke@435 | 271 | void SharedHeap::set_barrier_set(BarrierSet* bs) { |
duke@435 | 272 | _barrier_set = bs; |
duke@435 | 273 | // Cached barrier set for fast access in oops |
duke@435 | 274 | oopDesc::set_bs(bs); |
duke@435 | 275 | } |
duke@435 | 276 | |
duke@435 | 277 | void SharedHeap::post_initialize() { |
duke@435 | 278 | ref_processing_init(); |
duke@435 | 279 | } |
duke@435 | 280 | |
duke@435 | 281 | void SharedHeap::ref_processing_init() { |
duke@435 | 282 | perm_gen()->ref_processor_init(); |
duke@435 | 283 | } |
duke@435 | 284 | |
duke@435 | 285 | // Some utilities. |
ysr@777 | 286 | void SharedHeap::print_size_transition(outputStream* out, |
ysr@777 | 287 | size_t bytes_before, |
duke@435 | 288 | size_t bytes_after, |
duke@435 | 289 | size_t capacity) { |
ysr@777 | 290 | out->print(" %d%s->%d%s(%d%s)", |
duke@435 | 291 | byte_size_in_proper_unit(bytes_before), |
duke@435 | 292 | proper_unit_for_byte_size(bytes_before), |
duke@435 | 293 | byte_size_in_proper_unit(bytes_after), |
duke@435 | 294 | proper_unit_for_byte_size(bytes_after), |
duke@435 | 295 | byte_size_in_proper_unit(capacity), |
duke@435 | 296 | proper_unit_for_byte_size(capacity)); |
duke@435 | 297 | } |