Sat, 23 Nov 2013 12:25:13 +0100
8028128: Add a type safe alternative for working with counter based data
Reviewed-by: dholmes, egahlin
duke@435 | 1 | /* |
iveresov@3536 | 2 | * Copyright (c) 2002, 2012, 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/systemDictionary.hpp" |
stefank@2314 | 27 | #include "code/codeCache.hpp" |
stefank@2314 | 28 | #include "gc_implementation/parallelScavenge/cardTableExtension.hpp" |
stefank@2314 | 29 | #include "gc_implementation/parallelScavenge/gcTaskManager.hpp" |
stefank@2314 | 30 | #include "gc_implementation/parallelScavenge/psMarkSweep.hpp" |
stefank@2314 | 31 | #include "gc_implementation/parallelScavenge/psPromotionManager.hpp" |
stefank@2314 | 32 | #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" |
jcoomes@2661 | 33 | #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" |
stefank@2314 | 34 | #include "gc_implementation/parallelScavenge/psTasks.hpp" |
stefank@2314 | 35 | #include "memory/iterator.hpp" |
stefank@2314 | 36 | #include "memory/universe.hpp" |
stefank@2314 | 37 | #include "oops/oop.inline.hpp" |
stefank@2314 | 38 | #include "oops/oop.psgc.inline.hpp" |
stefank@2314 | 39 | #include "runtime/fprofiler.hpp" |
stefank@2314 | 40 | #include "runtime/thread.hpp" |
stefank@2314 | 41 | #include "runtime/vmThread.hpp" |
stefank@2314 | 42 | #include "services/management.hpp" |
stefank@2314 | 43 | #include "utilities/taskqueue.hpp" |
duke@435 | 44 | |
duke@435 | 45 | // |
duke@435 | 46 | // ScavengeRootsTask |
duke@435 | 47 | // |
duke@435 | 48 | |
duke@435 | 49 | void ScavengeRootsTask::do_it(GCTaskManager* manager, uint which) { |
duke@435 | 50 | assert(Universe::heap()->is_gc_active(), "called outside gc"); |
duke@435 | 51 | |
duke@435 | 52 | PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which); |
duke@435 | 53 | PSScavengeRootsClosure roots_closure(pm); |
iveresov@3536 | 54 | PSPromoteRootsClosure roots_to_old_closure(pm); |
duke@435 | 55 | |
duke@435 | 56 | switch (_root_type) { |
duke@435 | 57 | case universe: |
duke@435 | 58 | Universe::oops_do(&roots_closure); |
duke@435 | 59 | break; |
duke@435 | 60 | |
duke@435 | 61 | case jni_handles: |
duke@435 | 62 | JNIHandles::oops_do(&roots_closure); |
duke@435 | 63 | break; |
duke@435 | 64 | |
duke@435 | 65 | case threads: |
duke@435 | 66 | { |
duke@435 | 67 | ResourceMark rm; |
stefank@4298 | 68 | CLDToOopClosure* cld_closure = NULL; // Not needed. All CLDs are already visited. |
stefank@4298 | 69 | Threads::oops_do(&roots_closure, cld_closure, NULL); |
duke@435 | 70 | } |
duke@435 | 71 | break; |
duke@435 | 72 | |
duke@435 | 73 | case object_synchronizer: |
duke@435 | 74 | ObjectSynchronizer::oops_do(&roots_closure); |
duke@435 | 75 | break; |
duke@435 | 76 | |
duke@435 | 77 | case flat_profiler: |
duke@435 | 78 | FlatProfiler::oops_do(&roots_closure); |
duke@435 | 79 | break; |
duke@435 | 80 | |
duke@435 | 81 | case system_dictionary: |
duke@435 | 82 | SystemDictionary::oops_do(&roots_closure); |
stefank@5194 | 83 | break; |
coleenp@4037 | 84 | |
stefank@5194 | 85 | case class_loader_data: |
stefank@5194 | 86 | { |
stefank@5194 | 87 | PSScavengeKlassClosure klass_closure(pm); |
stefank@5194 | 88 | ClassLoaderDataGraph::oops_do(&roots_closure, &klass_closure, false); |
stefank@5194 | 89 | } |
stefank@5194 | 90 | break; |
duke@435 | 91 | |
duke@435 | 92 | case management: |
duke@435 | 93 | Management::oops_do(&roots_closure); |
duke@435 | 94 | break; |
duke@435 | 95 | |
duke@435 | 96 | case jvmti: |
duke@435 | 97 | JvmtiExport::oops_do(&roots_closure); |
duke@435 | 98 | break; |
duke@435 | 99 | |
jrose@1424 | 100 | |
jrose@1424 | 101 | case code_cache: |
jrose@1424 | 102 | { |
iveresov@3536 | 103 | CodeBlobToOopClosure each_scavengable_code_blob(&roots_to_old_closure, /*do_marking=*/ true); |
jrose@1424 | 104 | CodeCache::scavenge_root_nmethods_do(&each_scavengable_code_blob); |
jrose@1424 | 105 | } |
jrose@1424 | 106 | break; |
jrose@1424 | 107 | |
duke@435 | 108 | default: |
duke@435 | 109 | fatal("Unknown root type"); |
duke@435 | 110 | } |
duke@435 | 111 | |
duke@435 | 112 | // Do the real work |
duke@435 | 113 | pm->drain_stacks(false); |
duke@435 | 114 | } |
duke@435 | 115 | |
duke@435 | 116 | // |
duke@435 | 117 | // ThreadRootsTask |
duke@435 | 118 | // |
duke@435 | 119 | |
duke@435 | 120 | void ThreadRootsTask::do_it(GCTaskManager* manager, uint which) { |
duke@435 | 121 | assert(Universe::heap()->is_gc_active(), "called outside gc"); |
duke@435 | 122 | |
duke@435 | 123 | PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which); |
duke@435 | 124 | PSScavengeRootsClosure roots_closure(pm); |
stefank@4298 | 125 | CLDToOopClosure* roots_from_clds = NULL; // Not needed. All CLDs are already visited. |
jrose@1424 | 126 | CodeBlobToOopClosure roots_in_blobs(&roots_closure, /*do_marking=*/ true); |
duke@435 | 127 | |
duke@435 | 128 | if (_java_thread != NULL) |
stefank@4298 | 129 | _java_thread->oops_do(&roots_closure, roots_from_clds, &roots_in_blobs); |
duke@435 | 130 | |
duke@435 | 131 | if (_vm_thread != NULL) |
stefank@4298 | 132 | _vm_thread->oops_do(&roots_closure, roots_from_clds, &roots_in_blobs); |
duke@435 | 133 | |
duke@435 | 134 | // Do the real work |
duke@435 | 135 | pm->drain_stacks(false); |
duke@435 | 136 | } |
duke@435 | 137 | |
duke@435 | 138 | // |
duke@435 | 139 | // StealTask |
duke@435 | 140 | // |
duke@435 | 141 | |
duke@435 | 142 | StealTask::StealTask(ParallelTaskTerminator* t) : |
duke@435 | 143 | _terminator(t) {} |
duke@435 | 144 | |
duke@435 | 145 | void StealTask::do_it(GCTaskManager* manager, uint which) { |
duke@435 | 146 | assert(Universe::heap()->is_gc_active(), "called outside gc"); |
duke@435 | 147 | |
duke@435 | 148 | PSPromotionManager* pm = |
duke@435 | 149 | PSPromotionManager::gc_thread_promotion_manager(which); |
duke@435 | 150 | pm->drain_stacks(true); |
duke@435 | 151 | guarantee(pm->stacks_empty(), |
duke@435 | 152 | "stacks should be empty at this point"); |
duke@435 | 153 | |
duke@435 | 154 | int random_seed = 17; |
tonyp@2061 | 155 | while(true) { |
tonyp@2061 | 156 | StarTask p; |
tonyp@2061 | 157 | if (PSPromotionManager::steal_depth(which, &random_seed, p)) { |
tonyp@2061 | 158 | TASKQUEUE_STATS_ONLY(pm->record_steal(p)); |
tonyp@2061 | 159 | pm->process_popped_location_depth(p); |
tonyp@2061 | 160 | pm->drain_stacks_depth(true); |
tonyp@2061 | 161 | } else { |
tonyp@2061 | 162 | if (terminator()->offer_termination()) { |
tonyp@2061 | 163 | break; |
duke@435 | 164 | } |
duke@435 | 165 | } |
duke@435 | 166 | } |
coleenp@548 | 167 | guarantee(pm->stacks_empty(), "stacks should be empty at this point"); |
duke@435 | 168 | } |
duke@435 | 169 | |
duke@435 | 170 | // |
duke@435 | 171 | // OldToYoungRootsTask |
duke@435 | 172 | // |
duke@435 | 173 | |
duke@435 | 174 | void OldToYoungRootsTask::do_it(GCTaskManager* manager, uint which) { |
jmasa@4128 | 175 | // There are not old-to-young pointers if the old gen is empty. |
jmasa@4128 | 176 | assert(!_gen->object_space()->is_empty(), |
jmasa@4128 | 177 | "Should not be called is there is no work"); |
duke@435 | 178 | assert(_gen != NULL, "Sanity"); |
duke@435 | 179 | assert(_gen->object_space()->contains(_gen_top) || _gen_top == _gen->object_space()->top(), "Sanity"); |
duke@435 | 180 | assert(_stripe_number < ParallelGCThreads, "Sanity"); |
duke@435 | 181 | |
duke@435 | 182 | { |
duke@435 | 183 | PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which); |
duke@435 | 184 | |
duke@435 | 185 | assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); |
duke@435 | 186 | CardTableExtension* card_table = (CardTableExtension *)Universe::heap()->barrier_set(); |
duke@435 | 187 | // FIX ME! Assert that card_table is the type we believe it to be. |
duke@435 | 188 | |
duke@435 | 189 | card_table->scavenge_contents_parallel(_gen->start_array(), |
duke@435 | 190 | _gen->object_space(), |
duke@435 | 191 | _gen_top, |
duke@435 | 192 | pm, |
jmasa@3294 | 193 | _stripe_number, |
jmasa@3294 | 194 | _stripe_total); |
duke@435 | 195 | |
duke@435 | 196 | // Do the real work |
duke@435 | 197 | pm->drain_stacks(false); |
duke@435 | 198 | } |
duke@435 | 199 | } |