Mon, 23 Jun 2008 16:49:37 -0700
6718086: CMS assert: _concurrent_iteration_safe_limit update missed
Summary: Initialize the field correctly in ContiguousSpace's constructor and initialize() methods, using the latter for the survivor spaces upon initial construction or a subsequent resizing of the young generation. Add some missing Space sub-class constructors.
Reviewed-by: apetrusenko
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 2000-2007 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 | |
duke@435 | 103 | void SharedHeap::process_strong_roots(bool collecting_perm_gen, |
duke@435 | 104 | ScanningOption so, |
duke@435 | 105 | OopClosure* roots, |
duke@435 | 106 | OopsInGenClosure* perm_blk) { |
duke@435 | 107 | // General strong roots. |
duke@435 | 108 | if (n_par_threads() == 0) change_strong_roots_parity(); |
duke@435 | 109 | if (!_process_strong_tasks->is_task_claimed(SH_PS_Universe_oops_do)) { |
duke@435 | 110 | Universe::oops_do(roots); |
duke@435 | 111 | ReferenceProcessor::oops_do(roots); |
duke@435 | 112 | // Consider perm-gen discovered lists to be strong. |
duke@435 | 113 | perm_gen()->ref_processor()->weak_oops_do(roots); |
duke@435 | 114 | } |
duke@435 | 115 | // Global (strong) JNI handles |
duke@435 | 116 | if (!_process_strong_tasks->is_task_claimed(SH_PS_JNIHandles_oops_do)) |
duke@435 | 117 | JNIHandles::oops_do(roots); |
duke@435 | 118 | // All threads execute this; the individual threads are task groups. |
duke@435 | 119 | if (ParallelGCThreads > 0) { |
duke@435 | 120 | Threads::possibly_parallel_oops_do(roots); |
duke@435 | 121 | } else { |
duke@435 | 122 | Threads::oops_do(roots); |
duke@435 | 123 | } |
duke@435 | 124 | if (!_process_strong_tasks-> is_task_claimed(SH_PS_ObjectSynchronizer_oops_do)) |
duke@435 | 125 | ObjectSynchronizer::oops_do(roots); |
duke@435 | 126 | if (!_process_strong_tasks->is_task_claimed(SH_PS_FlatProfiler_oops_do)) |
duke@435 | 127 | FlatProfiler::oops_do(roots); |
duke@435 | 128 | if (!_process_strong_tasks->is_task_claimed(SH_PS_Management_oops_do)) |
duke@435 | 129 | Management::oops_do(roots); |
duke@435 | 130 | if (!_process_strong_tasks->is_task_claimed(SH_PS_jvmti_oops_do)) |
duke@435 | 131 | JvmtiExport::oops_do(roots); |
duke@435 | 132 | |
duke@435 | 133 | if (!_process_strong_tasks->is_task_claimed(SH_PS_SystemDictionary_oops_do)) { |
duke@435 | 134 | if (so & SO_AllClasses) { |
duke@435 | 135 | SystemDictionary::oops_do(roots); |
duke@435 | 136 | } else |
duke@435 | 137 | if (so & SO_SystemClasses) { |
duke@435 | 138 | SystemDictionary::always_strong_oops_do(roots); |
duke@435 | 139 | } |
duke@435 | 140 | } |
duke@435 | 141 | |
duke@435 | 142 | if (!_process_strong_tasks->is_task_claimed(SH_PS_SymbolTable_oops_do)) { |
duke@435 | 143 | if (so & SO_Symbols) { |
duke@435 | 144 | SymbolTable::oops_do(roots); |
duke@435 | 145 | } |
duke@435 | 146 | // Verify if the symbol table contents are in the perm gen |
duke@435 | 147 | NOT_PRODUCT(SymbolTable::oops_do(&assert_is_perm_closure)); |
duke@435 | 148 | } |
duke@435 | 149 | |
duke@435 | 150 | if (!_process_strong_tasks->is_task_claimed(SH_PS_StringTable_oops_do)) { |
duke@435 | 151 | if (so & SO_Strings) { |
duke@435 | 152 | StringTable::oops_do(roots); |
duke@435 | 153 | } |
duke@435 | 154 | // Verify if the string table contents are in the perm gen |
duke@435 | 155 | NOT_PRODUCT(StringTable::oops_do(&assert_is_perm_closure)); |
duke@435 | 156 | } |
duke@435 | 157 | |
duke@435 | 158 | if (!_process_strong_tasks->is_task_claimed(SH_PS_CodeCache_oops_do)) { |
duke@435 | 159 | if (so & SO_CodeCache) { |
duke@435 | 160 | CodeCache::oops_do(roots); |
duke@435 | 161 | } |
duke@435 | 162 | // Verify if the code cache contents are in the perm gen |
duke@435 | 163 | NOT_PRODUCT(CodeCache::oops_do(&assert_is_perm_closure)); |
duke@435 | 164 | } |
duke@435 | 165 | |
duke@435 | 166 | // Roots that should point only into permanent generation. |
duke@435 | 167 | { |
duke@435 | 168 | OopClosure* blk = NULL; |
duke@435 | 169 | if (collecting_perm_gen) { |
duke@435 | 170 | blk = roots; |
duke@435 | 171 | } else { |
duke@435 | 172 | debug_only(blk = &assert_is_perm_closure); |
duke@435 | 173 | } |
duke@435 | 174 | if (blk != NULL) { |
duke@435 | 175 | if (!_process_strong_tasks->is_task_claimed(SH_PS_vmSymbols_oops_do)) |
duke@435 | 176 | vmSymbols::oops_do(blk); |
duke@435 | 177 | } |
duke@435 | 178 | } |
duke@435 | 179 | |
duke@435 | 180 | if (!collecting_perm_gen) { |
duke@435 | 181 | // All threads perform this; coordination is handled internally. |
duke@435 | 182 | |
duke@435 | 183 | rem_set()->younger_refs_iterate(perm_gen(), perm_blk); |
duke@435 | 184 | } |
duke@435 | 185 | _process_strong_tasks->all_tasks_completed(); |
duke@435 | 186 | } |
duke@435 | 187 | |
duke@435 | 188 | class AlwaysTrueClosure: public BoolObjectClosure { |
duke@435 | 189 | public: |
duke@435 | 190 | void do_object(oop p) { ShouldNotReachHere(); } |
duke@435 | 191 | bool do_object_b(oop p) { return true; } |
duke@435 | 192 | }; |
duke@435 | 193 | static AlwaysTrueClosure always_true; |
duke@435 | 194 | |
duke@435 | 195 | class SkipAdjustingSharedStrings: public OopClosure { |
duke@435 | 196 | OopClosure* _clo; |
duke@435 | 197 | public: |
duke@435 | 198 | SkipAdjustingSharedStrings(OopClosure* clo) : _clo(clo) {} |
duke@435 | 199 | |
coleenp@548 | 200 | virtual void do_oop(oop* p) { |
duke@435 | 201 | oop o = (*p); |
duke@435 | 202 | if (!o->is_shared_readwrite()) { |
duke@435 | 203 | _clo->do_oop(p); |
duke@435 | 204 | } |
duke@435 | 205 | } |
coleenp@548 | 206 | virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
duke@435 | 207 | }; |
duke@435 | 208 | |
duke@435 | 209 | // Unmarked shared Strings in the StringTable (which got there due to |
duke@435 | 210 | // being in the constant pools of as-yet unloaded shared classes) were |
duke@435 | 211 | // not marked and therefore did not have their mark words preserved. |
duke@435 | 212 | // These entries are also deliberately not purged from the string |
duke@435 | 213 | // table during unloading of unmarked strings. If an identity hash |
duke@435 | 214 | // code was computed for any of these objects, it will not have been |
duke@435 | 215 | // cleared to zero during the forwarding process or by the |
duke@435 | 216 | // RecursiveAdjustSharedObjectClosure, and will be confused by the |
duke@435 | 217 | // adjusting process as a forwarding pointer. We need to skip |
duke@435 | 218 | // forwarding StringTable entries which contain unmarked shared |
duke@435 | 219 | // Strings. Actually, since shared strings won't be moving, we can |
duke@435 | 220 | // just skip adjusting any shared entries in the string table. |
duke@435 | 221 | |
duke@435 | 222 | void SharedHeap::process_weak_roots(OopClosure* root_closure, |
duke@435 | 223 | OopClosure* non_root_closure) { |
duke@435 | 224 | // Global (weak) JNI handles |
duke@435 | 225 | JNIHandles::weak_oops_do(&always_true, root_closure); |
duke@435 | 226 | |
duke@435 | 227 | CodeCache::oops_do(non_root_closure); |
duke@435 | 228 | SymbolTable::oops_do(root_closure); |
duke@435 | 229 | if (UseSharedSpaces && !DumpSharedSpaces) { |
duke@435 | 230 | SkipAdjustingSharedStrings skip_closure(root_closure); |
duke@435 | 231 | StringTable::oops_do(&skip_closure); |
duke@435 | 232 | } else { |
duke@435 | 233 | StringTable::oops_do(root_closure); |
duke@435 | 234 | } |
duke@435 | 235 | } |
duke@435 | 236 | |
duke@435 | 237 | void SharedHeap::set_barrier_set(BarrierSet* bs) { |
duke@435 | 238 | _barrier_set = bs; |
duke@435 | 239 | // Cached barrier set for fast access in oops |
duke@435 | 240 | oopDesc::set_bs(bs); |
duke@435 | 241 | } |
duke@435 | 242 | |
duke@435 | 243 | void SharedHeap::post_initialize() { |
duke@435 | 244 | ref_processing_init(); |
duke@435 | 245 | } |
duke@435 | 246 | |
duke@435 | 247 | void SharedHeap::ref_processing_init() { |
duke@435 | 248 | perm_gen()->ref_processor_init(); |
duke@435 | 249 | } |
duke@435 | 250 | |
duke@435 | 251 | void SharedHeap::fill_region_with_object(MemRegion mr) { |
duke@435 | 252 | // Disable the posting of JVMTI VMObjectAlloc events as we |
duke@435 | 253 | // don't want the filling of tlabs with filler arrays to be |
duke@435 | 254 | // reported to the profiler. |
duke@435 | 255 | NoJvmtiVMObjectAllocMark njm; |
duke@435 | 256 | |
duke@435 | 257 | // Disable low memory detector because there is no real allocation. |
duke@435 | 258 | LowMemoryDetectorDisabler lmd_dis; |
duke@435 | 259 | |
duke@435 | 260 | // It turns out that post_allocation_setup_array takes a handle, so the |
duke@435 | 261 | // call below contains an implicit conversion. Best to free that handle |
duke@435 | 262 | // as soon as possible. |
duke@435 | 263 | HandleMark hm; |
duke@435 | 264 | |
duke@435 | 265 | size_t word_size = mr.word_size(); |
duke@435 | 266 | size_t aligned_array_header_size = |
duke@435 | 267 | align_object_size(typeArrayOopDesc::header_size(T_INT)); |
duke@435 | 268 | |
duke@435 | 269 | if (word_size >= aligned_array_header_size) { |
duke@435 | 270 | const size_t array_length = |
duke@435 | 271 | pointer_delta(mr.end(), mr.start()) - |
duke@435 | 272 | typeArrayOopDesc::header_size(T_INT); |
duke@435 | 273 | const size_t array_length_words = |
duke@435 | 274 | array_length * (HeapWordSize/sizeof(jint)); |
duke@435 | 275 | post_allocation_setup_array(Universe::intArrayKlassObj(), |
duke@435 | 276 | mr.start(), |
duke@435 | 277 | mr.word_size(), |
duke@435 | 278 | (int)array_length_words); |
duke@435 | 279 | #ifdef ASSERT |
duke@435 | 280 | HeapWord* elt_words = (mr.start() + typeArrayOopDesc::header_size(T_INT)); |
duke@435 | 281 | Copy::fill_to_words(elt_words, array_length, 0xDEAFBABE); |
duke@435 | 282 | #endif |
duke@435 | 283 | } else { |
duke@435 | 284 | assert(word_size == (size_t)oopDesc::header_size(), "Unaligned?"); |
duke@435 | 285 | post_allocation_setup_obj(SystemDictionary::object_klass(), |
duke@435 | 286 | mr.start(), |
duke@435 | 287 | mr.word_size()); |
duke@435 | 288 | } |
duke@435 | 289 | } |
duke@435 | 290 | |
duke@435 | 291 | // Some utilities. |
ysr@777 | 292 | void SharedHeap::print_size_transition(outputStream* out, |
ysr@777 | 293 | size_t bytes_before, |
duke@435 | 294 | size_t bytes_after, |
duke@435 | 295 | size_t capacity) { |
ysr@777 | 296 | out->print(" %d%s->%d%s(%d%s)", |
duke@435 | 297 | byte_size_in_proper_unit(bytes_before), |
duke@435 | 298 | proper_unit_for_byte_size(bytes_before), |
duke@435 | 299 | byte_size_in_proper_unit(bytes_after), |
duke@435 | 300 | proper_unit_for_byte_size(bytes_after), |
duke@435 | 301 | byte_size_in_proper_unit(capacity), |
duke@435 | 302 | proper_unit_for_byte_size(capacity)); |
duke@435 | 303 | } |