Fri, 14 Feb 2014 09:29:56 +0100
8034764: Use process_strong_roots to adjust the StringTable
Reviewed-by: tschatzl, brutisso
duke@435 | 1 | /* |
drchase@6680 | 2 | * Copyright (c) 2000, 2014, Oracle and/or its affiliates. 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 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/symbolTable.hpp" |
stefank@2314 | 27 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 28 | #include "code/codeCache.hpp" |
stefank@2314 | 29 | #include "gc_interface/collectedHeap.inline.hpp" |
stefank@2314 | 30 | #include "memory/sharedHeap.hpp" |
stefank@2314 | 31 | #include "oops/oop.inline.hpp" |
stefank@2314 | 32 | #include "runtime/fprofiler.hpp" |
stefank@2314 | 33 | #include "runtime/java.hpp" |
stefank@2314 | 34 | #include "services/management.hpp" |
stefank@2314 | 35 | #include "utilities/copy.hpp" |
stefank@2314 | 36 | #include "utilities/workgroup.hpp" |
duke@435 | 37 | |
drchase@6680 | 38 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
drchase@6680 | 39 | |
duke@435 | 40 | SharedHeap* SharedHeap::_sh; |
duke@435 | 41 | |
duke@435 | 42 | // The set of potentially parallel tasks in strong root scanning. |
duke@435 | 43 | enum SH_process_strong_roots_tasks { |
duke@435 | 44 | SH_PS_Universe_oops_do, |
duke@435 | 45 | SH_PS_JNIHandles_oops_do, |
duke@435 | 46 | SH_PS_ObjectSynchronizer_oops_do, |
duke@435 | 47 | SH_PS_FlatProfiler_oops_do, |
duke@435 | 48 | SH_PS_Management_oops_do, |
duke@435 | 49 | SH_PS_SystemDictionary_oops_do, |
stefank@5194 | 50 | SH_PS_ClassLoaderDataGraph_oops_do, |
duke@435 | 51 | SH_PS_jvmti_oops_do, |
duke@435 | 52 | SH_PS_CodeCache_oops_do, |
duke@435 | 53 | // Leave this one last. |
duke@435 | 54 | SH_PS_NumElements |
duke@435 | 55 | }; |
duke@435 | 56 | |
duke@435 | 57 | SharedHeap::SharedHeap(CollectorPolicy* policy_) : |
duke@435 | 58 | CollectedHeap(), |
duke@435 | 59 | _collector_policy(policy_), |
coleenp@4037 | 60 | _rem_set(NULL), |
duke@435 | 61 | _strong_roots_parity(0), |
duke@435 | 62 | _process_strong_tasks(new SubTasksDone(SH_PS_NumElements)), |
jmasa@2188 | 63 | _workers(NULL) |
duke@435 | 64 | { |
duke@435 | 65 | if (_process_strong_tasks == NULL || !_process_strong_tasks->valid()) { |
duke@435 | 66 | vm_exit_during_initialization("Failed necessary allocation."); |
duke@435 | 67 | } |
duke@435 | 68 | _sh = this; // ch is static, should be set only once. |
duke@435 | 69 | if ((UseParNewGC || |
jmasa@5461 | 70 | (UseConcMarkSweepGC && (CMSParallelInitialMarkEnabled || |
jmasa@5461 | 71 | CMSParallelRemarkEnabled)) || |
ysr@777 | 72 | UseG1GC) && |
duke@435 | 73 | ParallelGCThreads > 0) { |
jmasa@2188 | 74 | _workers = new FlexibleWorkGang("Parallel GC Threads", ParallelGCThreads, |
ysr@777 | 75 | /* are_GC_task_threads */true, |
ysr@777 | 76 | /* are_ConcurrentGC_threads */false); |
duke@435 | 77 | if (_workers == NULL) { |
duke@435 | 78 | vm_exit_during_initialization("Failed necessary allocation."); |
jmasa@2188 | 79 | } else { |
jmasa@2188 | 80 | _workers->initialize_workers(); |
duke@435 | 81 | } |
duke@435 | 82 | } |
duke@435 | 83 | } |
duke@435 | 84 | |
jmasa@3294 | 85 | int SharedHeap::n_termination() { |
jmasa@3294 | 86 | return _process_strong_tasks->n_threads(); |
jmasa@3294 | 87 | } |
jmasa@3294 | 88 | |
jmasa@3294 | 89 | void SharedHeap::set_n_termination(int t) { |
jmasa@3294 | 90 | _process_strong_tasks->set_n_threads(t); |
jmasa@3294 | 91 | } |
jmasa@3294 | 92 | |
ysr@777 | 93 | bool SharedHeap::heap_lock_held_for_gc() { |
ysr@777 | 94 | Thread* t = Thread::current(); |
ysr@777 | 95 | return Heap_lock->owned_by_self() |
ysr@777 | 96 | || ( (t->is_GC_task_thread() || t->is_VM_thread()) |
ysr@777 | 97 | && _thread_holds_heap_lock_for_gc); |
ysr@777 | 98 | } |
duke@435 | 99 | |
jmasa@3357 | 100 | void SharedHeap::set_par_threads(uint t) { |
jmasa@2188 | 101 | assert(t == 0 || !UseSerialGC, "Cannot have parallel threads"); |
duke@435 | 102 | _n_par_threads = t; |
jmasa@2188 | 103 | _process_strong_tasks->set_n_threads(t); |
duke@435 | 104 | } |
duke@435 | 105 | |
jmasa@2909 | 106 | #ifdef ASSERT |
jmasa@2909 | 107 | class AssertNonScavengableClosure: public OopClosure { |
jmasa@2909 | 108 | public: |
jmasa@2909 | 109 | virtual void do_oop(oop* p) { |
jmasa@2909 | 110 | assert(!Universe::heap()->is_in_partial_collection(*p), |
jmasa@2909 | 111 | "Referent should not be scavengable."); } |
jmasa@2909 | 112 | virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
jmasa@2909 | 113 | }; |
jmasa@2909 | 114 | static AssertNonScavengableClosure assert_is_non_scavengable_closure; |
jmasa@2909 | 115 | #endif |
jmasa@2909 | 116 | |
duke@435 | 117 | void SharedHeap::change_strong_roots_parity() { |
duke@435 | 118 | // Also set the new collection parity. |
duke@435 | 119 | assert(_strong_roots_parity >= 0 && _strong_roots_parity <= 2, |
duke@435 | 120 | "Not in range."); |
duke@435 | 121 | _strong_roots_parity++; |
duke@435 | 122 | if (_strong_roots_parity == 3) _strong_roots_parity = 1; |
duke@435 | 123 | assert(_strong_roots_parity >= 1 && _strong_roots_parity <= 2, |
duke@435 | 124 | "Not in range."); |
duke@435 | 125 | } |
duke@435 | 126 | |
jrose@1424 | 127 | SharedHeap::StrongRootsScope::StrongRootsScope(SharedHeap* outer, bool activate) |
jrose@1424 | 128 | : MarkScope(activate) |
jrose@1424 | 129 | { |
jrose@1424 | 130 | if (_active) { |
jrose@1424 | 131 | outer->change_strong_roots_parity(); |
johnc@5277 | 132 | // Zero the claimed high water mark in the StringTable |
johnc@5277 | 133 | StringTable::clear_parallel_claimed_index(); |
jrose@1424 | 134 | } |
jrose@1424 | 135 | } |
jrose@1424 | 136 | |
jrose@1424 | 137 | SharedHeap::StrongRootsScope::~StrongRootsScope() { |
jrose@1424 | 138 | // nothing particular |
jrose@1424 | 139 | } |
jrose@1424 | 140 | |
jrose@1424 | 141 | void SharedHeap::process_strong_roots(bool activate_scope, |
duke@435 | 142 | ScanningOption so, |
duke@435 | 143 | OopClosure* roots, |
coleenp@4037 | 144 | KlassClosure* klass_closure) { |
jrose@1424 | 145 | StrongRootsScope srs(this, activate_scope); |
coleenp@4037 | 146 | |
duke@435 | 147 | // General strong roots. |
jrose@1424 | 148 | assert(_strong_roots_parity != 0, "must have called prologue code"); |
jmasa@3294 | 149 | // _n_termination for _process_strong_tasks should be set up stream |
jmasa@3294 | 150 | // in a method not running in a GC worker. Otherwise the GC worker |
jmasa@3294 | 151 | // could be trying to change the termination condition while the task |
jmasa@3294 | 152 | // is executing in another GC worker. |
duke@435 | 153 | if (!_process_strong_tasks->is_task_claimed(SH_PS_Universe_oops_do)) { |
duke@435 | 154 | Universe::oops_do(roots); |
duke@435 | 155 | } |
duke@435 | 156 | // Global (strong) JNI handles |
duke@435 | 157 | if (!_process_strong_tasks->is_task_claimed(SH_PS_JNIHandles_oops_do)) |
duke@435 | 158 | JNIHandles::oops_do(roots); |
johnc@5277 | 159 | |
stefank@6971 | 160 | CodeBlobToOopClosure code_roots(roots, true); |
stefank@6971 | 161 | |
mgerdin@6968 | 162 | CLDToOopClosure roots_from_clds(roots); |
mgerdin@6968 | 163 | // If we limit class scanning to SO_SystemClasses we need to apply a CLD closure to |
mgerdin@6968 | 164 | // CLDs which are strongly reachable from the thread stacks. |
mgerdin@6968 | 165 | CLDToOopClosure* roots_from_clds_p = ((so & SO_SystemClasses) ? &roots_from_clds : NULL); |
duke@435 | 166 | // All threads execute this; the individual threads are task groups. |
johnc@5277 | 167 | if (CollectedHeap::use_parallel_gc_threads()) { |
stefank@6971 | 168 | Threads::possibly_parallel_oops_do(roots, roots_from_clds_p, &code_roots); |
duke@435 | 169 | } else { |
stefank@6971 | 170 | Threads::oops_do(roots, roots_from_clds_p, &code_roots); |
duke@435 | 171 | } |
johnc@5277 | 172 | |
duke@435 | 173 | if (!_process_strong_tasks-> is_task_claimed(SH_PS_ObjectSynchronizer_oops_do)) |
duke@435 | 174 | ObjectSynchronizer::oops_do(roots); |
duke@435 | 175 | if (!_process_strong_tasks->is_task_claimed(SH_PS_FlatProfiler_oops_do)) |
duke@435 | 176 | FlatProfiler::oops_do(roots); |
duke@435 | 177 | if (!_process_strong_tasks->is_task_claimed(SH_PS_Management_oops_do)) |
duke@435 | 178 | Management::oops_do(roots); |
duke@435 | 179 | if (!_process_strong_tasks->is_task_claimed(SH_PS_jvmti_oops_do)) |
duke@435 | 180 | JvmtiExport::oops_do(roots); |
duke@435 | 181 | |
duke@435 | 182 | if (!_process_strong_tasks->is_task_claimed(SH_PS_SystemDictionary_oops_do)) { |
duke@435 | 183 | if (so & SO_AllClasses) { |
duke@435 | 184 | SystemDictionary::oops_do(roots); |
stefank@5194 | 185 | } else if (so & SO_SystemClasses) { |
stefank@5194 | 186 | SystemDictionary::always_strong_oops_do(roots); |
stefank@5194 | 187 | } else { |
stefank@5194 | 188 | fatal("We should always have selected either SO_AllClasses or SO_SystemClasses"); |
stefank@5194 | 189 | } |
stefank@5194 | 190 | } |
stefank@5194 | 191 | |
stefank@5194 | 192 | if (!_process_strong_tasks->is_task_claimed(SH_PS_ClassLoaderDataGraph_oops_do)) { |
stefank@5194 | 193 | if (so & SO_AllClasses) { |
mgerdin@6968 | 194 | ClassLoaderDataGraph::oops_do(roots, klass_closure, /* must_claim */ false); |
ysr@2825 | 195 | } else if (so & SO_SystemClasses) { |
mgerdin@6968 | 196 | ClassLoaderDataGraph::always_strong_oops_do(roots, klass_closure, /* must_claim */ true); |
ysr@2825 | 197 | } |
duke@435 | 198 | } |
duke@435 | 199 | |
johnc@5277 | 200 | // All threads execute the following. A specific chunk of buckets |
johnc@5277 | 201 | // from the StringTable are the individual tasks. |
johnc@5277 | 202 | if (so & SO_Strings) { |
johnc@5277 | 203 | if (CollectedHeap::use_parallel_gc_threads()) { |
johnc@5277 | 204 | StringTable::possibly_parallel_oops_do(roots); |
johnc@5277 | 205 | } else { |
jcoomes@2661 | 206 | StringTable::oops_do(roots); |
jcoomes@2661 | 207 | } |
duke@435 | 208 | } |
duke@435 | 209 | |
duke@435 | 210 | if (!_process_strong_tasks->is_task_claimed(SH_PS_CodeCache_oops_do)) { |
mgerdin@6968 | 211 | if (so & SO_ScavengeCodeCache) { |
stefank@6971 | 212 | assert(&code_roots != NULL, "must supply closure for code cache"); |
coleenp@4037 | 213 | |
mgerdin@6968 | 214 | // We only visit parts of the CodeCache when scavenging. |
stefank@6971 | 215 | CodeCache::scavenge_root_nmethods_do(&code_roots); |
mgerdin@6968 | 216 | } |
mgerdin@6968 | 217 | if (so & SO_AllCodeCache) { |
stefank@6971 | 218 | assert(&code_roots != NULL, "must supply closure for code cache"); |
mgerdin@6968 | 219 | |
mgerdin@6968 | 220 | // CMSCollector uses this to do intermediate-strength collections. |
mgerdin@6968 | 221 | // We scan the entire code cache, since CodeCache::do_unloading is not called. |
stefank@6971 | 222 | CodeCache::blobs_do(&code_roots); |
jrose@1424 | 223 | } |
jmasa@2909 | 224 | // Verify that the code cache contents are not subject to |
jmasa@2909 | 225 | // movement by a scavenging collection. |
jmasa@2909 | 226 | DEBUG_ONLY(CodeBlobToOopClosure assert_code_is_non_scavengable(&assert_is_non_scavengable_closure, /*do_marking=*/ false)); |
jmasa@2909 | 227 | DEBUG_ONLY(CodeCache::asserted_non_scavengable_nmethods_do(&assert_code_is_non_scavengable)); |
duke@435 | 228 | } |
duke@435 | 229 | |
duke@435 | 230 | _process_strong_tasks->all_tasks_completed(); |
duke@435 | 231 | } |
duke@435 | 232 | |
duke@435 | 233 | class AlwaysTrueClosure: public BoolObjectClosure { |
duke@435 | 234 | public: |
duke@435 | 235 | bool do_object_b(oop p) { return true; } |
duke@435 | 236 | }; |
duke@435 | 237 | static AlwaysTrueClosure always_true; |
duke@435 | 238 | |
stefank@6971 | 239 | void SharedHeap::process_weak_roots(OopClosure* root_closure) { |
duke@435 | 240 | // Global (weak) JNI handles |
duke@435 | 241 | JNIHandles::weak_oops_do(&always_true, root_closure); |
stefank@5011 | 242 | } |
duke@435 | 243 | |
duke@435 | 244 | void SharedHeap::set_barrier_set(BarrierSet* bs) { |
duke@435 | 245 | _barrier_set = bs; |
duke@435 | 246 | // Cached barrier set for fast access in oops |
duke@435 | 247 | oopDesc::set_bs(bs); |
duke@435 | 248 | } |
duke@435 | 249 | |
duke@435 | 250 | void SharedHeap::post_initialize() { |
jwilhelm@6085 | 251 | CollectedHeap::post_initialize(); |
duke@435 | 252 | ref_processing_init(); |
duke@435 | 253 | } |
duke@435 | 254 | |
coleenp@4037 | 255 | void SharedHeap::ref_processing_init() {} |
duke@435 | 256 | |
duke@435 | 257 | // Some utilities. |
ysr@777 | 258 | void SharedHeap::print_size_transition(outputStream* out, |
ysr@777 | 259 | size_t bytes_before, |
duke@435 | 260 | size_t bytes_after, |
duke@435 | 261 | size_t capacity) { |
ysr@777 | 262 | out->print(" %d%s->%d%s(%d%s)", |
duke@435 | 263 | byte_size_in_proper_unit(bytes_before), |
duke@435 | 264 | proper_unit_for_byte_size(bytes_before), |
duke@435 | 265 | byte_size_in_proper_unit(bytes_after), |
duke@435 | 266 | proper_unit_for_byte_size(bytes_after), |
duke@435 | 267 | byte_size_in_proper_unit(capacity), |
duke@435 | 268 | proper_unit_for_byte_size(capacity)); |
duke@435 | 269 | } |