Mon, 20 Sep 2010 14:38:38 -0700
6984287: Regularize how GC parallel workers are specified.
Summary: Associate number of GC workers with the workgang as opposed to the task.
Reviewed-by: johnc, ysr
duke@435 | 1 | /* |
jcoomes@1993 | 2 | * Copyright (c) 2005, 2010, 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 | |
duke@435 | 25 | #include "incls/_precompiled.incl" |
duke@435 | 26 | #include "incls/_psCompactionManager.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | PSOldGen* ParCompactionManager::_old_gen = NULL; |
duke@435 | 29 | ParCompactionManager** ParCompactionManager::_manager_array = NULL; |
duke@435 | 30 | OopTaskQueueSet* ParCompactionManager::_stack_array = NULL; |
jcoomes@1746 | 31 | ParCompactionManager::ObjArrayTaskQueueSet* |
jcoomes@1746 | 32 | ParCompactionManager::_objarray_queues = NULL; |
duke@435 | 33 | ObjectStartArray* ParCompactionManager::_start_array = NULL; |
duke@435 | 34 | ParMarkBitMap* ParCompactionManager::_mark_bitmap = NULL; |
jcoomes@1993 | 35 | RegionTaskQueueSet* ParCompactionManager::_region_array = NULL; |
duke@435 | 36 | |
duke@435 | 37 | ParCompactionManager::ParCompactionManager() : |
duke@435 | 38 | _action(CopyAndUpdate) { |
duke@435 | 39 | |
duke@435 | 40 | ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); |
duke@435 | 41 | assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); |
duke@435 | 42 | |
duke@435 | 43 | _old_gen = heap->old_gen(); |
duke@435 | 44 | _start_array = old_gen()->start_array(); |
duke@435 | 45 | |
duke@435 | 46 | marking_stack()->initialize(); |
jcoomes@1993 | 47 | _objarray_stack.initialize(); |
jcoomes@810 | 48 | region_stack()->initialize(); |
duke@435 | 49 | |
duke@435 | 50 | // Note that _revisit_klass_stack is allocated out of the |
duke@435 | 51 | // C heap (as opposed to out of ResourceArena). |
duke@435 | 52 | int size = |
duke@435 | 53 | (SystemDictionary::number_of_classes() * 2) * 2 / ParallelGCThreads; |
duke@435 | 54 | _revisit_klass_stack = new (ResourceObj::C_HEAP) GrowableArray<Klass*>(size, true); |
ysr@1376 | 55 | // From some experiments (#klass/k)^2 for k = 10 seems a better fit, but this will |
ysr@1376 | 56 | // have to do for now until we are able to investigate a more optimal setting. |
ysr@1376 | 57 | _revisit_mdo_stack = new (ResourceObj::C_HEAP) GrowableArray<DataLayout*>(size*2, true); |
duke@435 | 58 | } |
duke@435 | 59 | |
duke@435 | 60 | ParCompactionManager::~ParCompactionManager() { |
duke@435 | 61 | delete _revisit_klass_stack; |
ysr@1376 | 62 | delete _revisit_mdo_stack; |
duke@435 | 63 | // _manager_array and _stack_array are statics |
duke@435 | 64 | // shared with all instances of ParCompactionManager |
duke@435 | 65 | // should not be deallocated. |
duke@435 | 66 | } |
duke@435 | 67 | |
duke@435 | 68 | void ParCompactionManager::initialize(ParMarkBitMap* mbm) { |
duke@435 | 69 | assert(PSParallelCompact::gc_task_manager() != NULL, |
duke@435 | 70 | "Needed for initialization"); |
duke@435 | 71 | |
duke@435 | 72 | _mark_bitmap = mbm; |
duke@435 | 73 | |
duke@435 | 74 | uint parallel_gc_threads = PSParallelCompact::gc_task_manager()->workers(); |
duke@435 | 75 | |
duke@435 | 76 | assert(_manager_array == NULL, "Attempt to initialize twice"); |
duke@435 | 77 | _manager_array = NEW_C_HEAP_ARRAY(ParCompactionManager*, parallel_gc_threads+1 ); |
jcoomes@1746 | 78 | guarantee(_manager_array != NULL, "Could not allocate manager_array"); |
duke@435 | 79 | |
duke@435 | 80 | _stack_array = new OopTaskQueueSet(parallel_gc_threads); |
jcoomes@1746 | 81 | guarantee(_stack_array != NULL, "Could not allocate stack_array"); |
jcoomes@1746 | 82 | _objarray_queues = new ObjArrayTaskQueueSet(parallel_gc_threads); |
jcoomes@1746 | 83 | guarantee(_objarray_queues != NULL, "Could not allocate objarray_queues"); |
jcoomes@810 | 84 | _region_array = new RegionTaskQueueSet(parallel_gc_threads); |
jcoomes@1746 | 85 | guarantee(_region_array != NULL, "Could not allocate region_array"); |
duke@435 | 86 | |
duke@435 | 87 | // Create and register the ParCompactionManager(s) for the worker threads. |
duke@435 | 88 | for(uint i=0; i<parallel_gc_threads; i++) { |
duke@435 | 89 | _manager_array[i] = new ParCompactionManager(); |
duke@435 | 90 | guarantee(_manager_array[i] != NULL, "Could not create ParCompactionManager"); |
duke@435 | 91 | stack_array()->register_queue(i, _manager_array[i]->marking_stack()); |
jcoomes@1993 | 92 | _objarray_queues->register_queue(i, &_manager_array[i]->_objarray_stack); |
jcoomes@810 | 93 | region_array()->register_queue(i, _manager_array[i]->region_stack()); |
duke@435 | 94 | } |
duke@435 | 95 | |
duke@435 | 96 | // The VMThread gets its own ParCompactionManager, which is not available |
duke@435 | 97 | // for work stealing. |
duke@435 | 98 | _manager_array[parallel_gc_threads] = new ParCompactionManager(); |
duke@435 | 99 | guarantee(_manager_array[parallel_gc_threads] != NULL, |
duke@435 | 100 | "Could not create ParCompactionManager"); |
duke@435 | 101 | assert(PSParallelCompact::gc_task_manager()->workers() != 0, |
duke@435 | 102 | "Not initialized?"); |
duke@435 | 103 | } |
duke@435 | 104 | |
duke@435 | 105 | bool ParCompactionManager::should_update() { |
duke@435 | 106 | assert(action() != NotValid, "Action is not set"); |
duke@435 | 107 | return (action() == ParCompactionManager::Update) || |
duke@435 | 108 | (action() == ParCompactionManager::CopyAndUpdate) || |
duke@435 | 109 | (action() == ParCompactionManager::UpdateAndCopy); |
duke@435 | 110 | } |
duke@435 | 111 | |
duke@435 | 112 | bool ParCompactionManager::should_copy() { |
duke@435 | 113 | assert(action() != NotValid, "Action is not set"); |
duke@435 | 114 | return (action() == ParCompactionManager::Copy) || |
duke@435 | 115 | (action() == ParCompactionManager::CopyAndUpdate) || |
duke@435 | 116 | (action() == ParCompactionManager::UpdateAndCopy); |
duke@435 | 117 | } |
duke@435 | 118 | |
duke@435 | 119 | bool ParCompactionManager::should_verify_only() { |
duke@435 | 120 | assert(action() != NotValid, "Action is not set"); |
duke@435 | 121 | return action() == ParCompactionManager::VerifyUpdate; |
duke@435 | 122 | } |
duke@435 | 123 | |
duke@435 | 124 | bool ParCompactionManager::should_reset_only() { |
duke@435 | 125 | assert(action() != NotValid, "Action is not set"); |
duke@435 | 126 | return action() == ParCompactionManager::ResetObjects; |
duke@435 | 127 | } |
duke@435 | 128 | |
duke@435 | 129 | ParCompactionManager* |
duke@435 | 130 | ParCompactionManager::gc_thread_compaction_manager(int index) { |
duke@435 | 131 | assert(index >= 0 && index < (int)ParallelGCThreads, "index out of range"); |
duke@435 | 132 | assert(_manager_array != NULL, "Sanity"); |
duke@435 | 133 | return _manager_array[index]; |
duke@435 | 134 | } |
duke@435 | 135 | |
duke@435 | 136 | void ParCompactionManager::reset() { |
duke@435 | 137 | for(uint i=0; i<ParallelGCThreads+1; i++) { |
duke@435 | 138 | manager_array(i)->revisit_klass_stack()->clear(); |
ysr@1376 | 139 | manager_array(i)->revisit_mdo_stack()->clear(); |
duke@435 | 140 | } |
duke@435 | 141 | } |
duke@435 | 142 | |
jcoomes@1746 | 143 | void ParCompactionManager::follow_marking_stacks() { |
duke@435 | 144 | do { |
jcoomes@1746 | 145 | // Drain the overflow stack first, to allow stealing from the marking stack. |
jcoomes@1750 | 146 | oop obj; |
jcoomes@1993 | 147 | while (marking_stack()->pop_overflow(obj)) { |
jcoomes@1993 | 148 | obj->follow_contents(this); |
jcoomes@1746 | 149 | } |
jcoomes@1746 | 150 | while (marking_stack()->pop_local(obj)) { |
duke@435 | 151 | obj->follow_contents(this); |
duke@435 | 152 | } |
duke@435 | 153 | |
jcoomes@1750 | 154 | // Process ObjArrays one at a time to avoid marking stack bloat. |
jcoomes@1746 | 155 | ObjArrayTask task; |
jcoomes@1993 | 156 | if (_objarray_stack.pop_overflow(task)) { |
jcoomes@1746 | 157 | objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint(); |
jcoomes@1746 | 158 | k->oop_follow_contents(this, task.obj(), task.index()); |
jcoomes@1993 | 159 | } else if (_objarray_stack.pop_local(task)) { |
jcoomes@1746 | 160 | objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint(); |
jcoomes@1746 | 161 | k->oop_follow_contents(this, task.obj(), task.index()); |
jcoomes@1746 | 162 | } |
jcoomes@1746 | 163 | } while (!marking_stacks_empty()); |
duke@435 | 164 | |
jcoomes@1746 | 165 | assert(marking_stacks_empty(), "Sanity"); |
duke@435 | 166 | } |
duke@435 | 167 | |
jcoomes@810 | 168 | void ParCompactionManager::drain_region_stacks() { |
duke@435 | 169 | do { |
jcoomes@1993 | 170 | // Drain overflow stack first so other threads can steal. |
jcoomes@1993 | 171 | size_t region_index; |
jcoomes@1993 | 172 | while (region_stack()->pop_overflow(region_index)) { |
jcoomes@810 | 173 | PSParallelCompact::fill_and_update_region(this, region_index); |
duke@435 | 174 | } |
duke@435 | 175 | |
jcoomes@1993 | 176 | while (region_stack()->pop_local(region_index)) { |
jcoomes@810 | 177 | PSParallelCompact::fill_and_update_region(this, region_index); |
duke@435 | 178 | } |
jcoomes@810 | 179 | } while (!region_stack()->is_empty()); |
duke@435 | 180 | } |
duke@435 | 181 | |
duke@435 | 182 | #ifdef ASSERT |
duke@435 | 183 | bool ParCompactionManager::stacks_have_been_allocated() { |
ysr@1376 | 184 | return (revisit_klass_stack()->data_addr() != NULL && |
ysr@1376 | 185 | revisit_mdo_stack()->data_addr() != NULL); |
duke@435 | 186 | } |
duke@435 | 187 | #endif |