src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.cpp

Fri, 16 Mar 2012 16:14:04 +0100

author
nloodin
date
Fri, 16 Mar 2012 16:14:04 +0100
changeset 3665
8a729074feae
parent 3298
7913e93dca52
child 3900
d2a62e0f25eb
permissions
-rw-r--r--

7154517: Build error in hotspot-gc without precompiled headers
Reviewed-by: jcoomes, brutisso

duke@435 1 /*
jmasa@3298 2 * Copyright (c) 2005, 2011, 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 "gc_implementation/parallelScavenge/gcTaskManager.hpp"
stefank@2314 28 #include "gc_implementation/parallelScavenge/objectStartArray.hpp"
stefank@2314 29 #include "gc_implementation/parallelScavenge/parMarkBitMap.hpp"
stefank@2314 30 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
stefank@2314 31 #include "gc_implementation/parallelScavenge/psCompactionManager.hpp"
stefank@2314 32 #include "gc_implementation/parallelScavenge/psOldGen.hpp"
stefank@2314 33 #include "gc_implementation/parallelScavenge/psParallelCompact.hpp"
stefank@2314 34 #include "oops/objArrayKlass.inline.hpp"
stefank@2314 35 #include "oops/oop.hpp"
stefank@2314 36 #include "oops/oop.inline.hpp"
stefank@2314 37 #include "oops/oop.pcgc.inline.hpp"
stefank@2314 38 #include "utilities/stack.inline.hpp"
duke@435 39
duke@435 40 PSOldGen* ParCompactionManager::_old_gen = NULL;
duke@435 41 ParCompactionManager** ParCompactionManager::_manager_array = NULL;
jmasa@3294 42
jmasa@3294 43 RegionTaskQueue** ParCompactionManager::_region_list = NULL;
jmasa@3294 44
duke@435 45 OopTaskQueueSet* ParCompactionManager::_stack_array = NULL;
jcoomes@1746 46 ParCompactionManager::ObjArrayTaskQueueSet*
jcoomes@1746 47 ParCompactionManager::_objarray_queues = NULL;
duke@435 48 ObjectStartArray* ParCompactionManager::_start_array = NULL;
duke@435 49 ParMarkBitMap* ParCompactionManager::_mark_bitmap = NULL;
jcoomes@1993 50 RegionTaskQueueSet* ParCompactionManager::_region_array = NULL;
duke@435 51
jmasa@3294 52 uint* ParCompactionManager::_recycled_stack_index = NULL;
jmasa@3294 53 int ParCompactionManager::_recycled_top = -1;
jmasa@3294 54 int ParCompactionManager::_recycled_bottom = -1;
jmasa@3294 55
duke@435 56 ParCompactionManager::ParCompactionManager() :
jmasa@3294 57 _action(CopyAndUpdate),
jmasa@3294 58 _region_stack(NULL),
jmasa@3294 59 _region_stack_index((uint)max_uintx) {
duke@435 60
duke@435 61 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 62 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 63
duke@435 64 _old_gen = heap->old_gen();
duke@435 65 _start_array = old_gen()->start_array();
duke@435 66
duke@435 67 marking_stack()->initialize();
jcoomes@1993 68 _objarray_stack.initialize();
jmasa@3294 69 }
jmasa@3294 70
jmasa@3294 71 ParCompactionManager::~ParCompactionManager() {
jmasa@3294 72 delete _recycled_stack_index;
duke@435 73 }
duke@435 74
duke@435 75 void ParCompactionManager::initialize(ParMarkBitMap* mbm) {
duke@435 76 assert(PSParallelCompact::gc_task_manager() != NULL,
duke@435 77 "Needed for initialization");
duke@435 78
duke@435 79 _mark_bitmap = mbm;
duke@435 80
duke@435 81 uint parallel_gc_threads = PSParallelCompact::gc_task_manager()->workers();
duke@435 82
duke@435 83 assert(_manager_array == NULL, "Attempt to initialize twice");
duke@435 84 _manager_array = NEW_C_HEAP_ARRAY(ParCompactionManager*, parallel_gc_threads+1 );
jcoomes@1746 85 guarantee(_manager_array != NULL, "Could not allocate manager_array");
duke@435 86
jmasa@3294 87 _region_list = NEW_C_HEAP_ARRAY(RegionTaskQueue*,
jmasa@3294 88 parallel_gc_threads+1);
jmasa@3294 89 guarantee(_region_list != NULL, "Could not initialize promotion manager");
jmasa@3294 90
jmasa@3294 91 _recycled_stack_index = NEW_C_HEAP_ARRAY(uint, parallel_gc_threads);
jmasa@3294 92
jmasa@3294 93 // parallel_gc-threads + 1 to be consistent with the number of
jmasa@3294 94 // compaction managers.
jmasa@3294 95 for(uint i=0; i<parallel_gc_threads + 1; i++) {
jmasa@3294 96 _region_list[i] = new RegionTaskQueue();
jmasa@3294 97 region_list(i)->initialize();
jmasa@3294 98 }
jmasa@3294 99
duke@435 100 _stack_array = new OopTaskQueueSet(parallel_gc_threads);
jcoomes@1746 101 guarantee(_stack_array != NULL, "Could not allocate stack_array");
jcoomes@1746 102 _objarray_queues = new ObjArrayTaskQueueSet(parallel_gc_threads);
jcoomes@1746 103 guarantee(_objarray_queues != NULL, "Could not allocate objarray_queues");
jcoomes@810 104 _region_array = new RegionTaskQueueSet(parallel_gc_threads);
jcoomes@1746 105 guarantee(_region_array != NULL, "Could not allocate region_array");
duke@435 106
duke@435 107 // Create and register the ParCompactionManager(s) for the worker threads.
duke@435 108 for(uint i=0; i<parallel_gc_threads; i++) {
duke@435 109 _manager_array[i] = new ParCompactionManager();
duke@435 110 guarantee(_manager_array[i] != NULL, "Could not create ParCompactionManager");
duke@435 111 stack_array()->register_queue(i, _manager_array[i]->marking_stack());
jcoomes@1993 112 _objarray_queues->register_queue(i, &_manager_array[i]->_objarray_stack);
jmasa@3294 113 region_array()->register_queue(i, region_list(i));
duke@435 114 }
duke@435 115
duke@435 116 // The VMThread gets its own ParCompactionManager, which is not available
duke@435 117 // for work stealing.
duke@435 118 _manager_array[parallel_gc_threads] = new ParCompactionManager();
duke@435 119 guarantee(_manager_array[parallel_gc_threads] != NULL,
duke@435 120 "Could not create ParCompactionManager");
duke@435 121 assert(PSParallelCompact::gc_task_manager()->workers() != 0,
duke@435 122 "Not initialized?");
duke@435 123 }
duke@435 124
jmasa@3294 125 int ParCompactionManager::pop_recycled_stack_index() {
jmasa@3294 126 assert(_recycled_bottom <= _recycled_top, "list is empty");
jmasa@3294 127 // Get the next available index
jmasa@3294 128 if (_recycled_bottom < _recycled_top) {
jmasa@3294 129 uint cur, next, last;
jmasa@3294 130 do {
jmasa@3294 131 cur = _recycled_bottom;
jmasa@3294 132 next = cur + 1;
jmasa@3294 133 last = Atomic::cmpxchg(next, &_recycled_bottom, cur);
jmasa@3294 134 } while (cur != last);
jmasa@3294 135 return _recycled_stack_index[next];
jmasa@3294 136 } else {
jmasa@3294 137 return -1;
jmasa@3294 138 }
jmasa@3294 139 }
jmasa@3294 140
jmasa@3294 141 void ParCompactionManager::push_recycled_stack_index(uint v) {
jmasa@3294 142 // Get the next available index
jmasa@3294 143 int cur = Atomic::add(1, &_recycled_top);
jmasa@3294 144 _recycled_stack_index[cur] = v;
jmasa@3294 145 assert(_recycled_bottom <= _recycled_top, "list top and bottom are wrong");
jmasa@3294 146 }
jmasa@3294 147
duke@435 148 bool ParCompactionManager::should_update() {
duke@435 149 assert(action() != NotValid, "Action is not set");
duke@435 150 return (action() == ParCompactionManager::Update) ||
duke@435 151 (action() == ParCompactionManager::CopyAndUpdate) ||
duke@435 152 (action() == ParCompactionManager::UpdateAndCopy);
duke@435 153 }
duke@435 154
duke@435 155 bool ParCompactionManager::should_copy() {
duke@435 156 assert(action() != NotValid, "Action is not set");
duke@435 157 return (action() == ParCompactionManager::Copy) ||
duke@435 158 (action() == ParCompactionManager::CopyAndUpdate) ||
duke@435 159 (action() == ParCompactionManager::UpdateAndCopy);
duke@435 160 }
duke@435 161
jmasa@3294 162 void ParCompactionManager::region_list_push(uint list_index,
jmasa@3294 163 size_t region_index) {
jmasa@3294 164 region_list(list_index)->push(region_index);
jmasa@3294 165 }
jmasa@3294 166
jmasa@3294 167 void ParCompactionManager::verify_region_list_empty(uint list_index) {
jmasa@3294 168 assert(region_list(list_index)->is_empty(), "Not empty");
jmasa@3294 169 }
jmasa@3294 170
duke@435 171 ParCompactionManager*
duke@435 172 ParCompactionManager::gc_thread_compaction_manager(int index) {
duke@435 173 assert(index >= 0 && index < (int)ParallelGCThreads, "index out of range");
duke@435 174 assert(_manager_array != NULL, "Sanity");
duke@435 175 return _manager_array[index];
duke@435 176 }
duke@435 177
duke@435 178 void ParCompactionManager::reset() {
jcoomes@2191 179 for(uint i = 0; i < ParallelGCThreads + 1; i++) {
jcoomes@2191 180 assert(manager_array(i)->revisit_klass_stack()->is_empty(), "sanity");
jcoomes@2191 181 assert(manager_array(i)->revisit_mdo_stack()->is_empty(), "sanity");
duke@435 182 }
duke@435 183 }
duke@435 184
jcoomes@1746 185 void ParCompactionManager::follow_marking_stacks() {
duke@435 186 do {
jcoomes@1746 187 // Drain the overflow stack first, to allow stealing from the marking stack.
jcoomes@1750 188 oop obj;
jcoomes@1993 189 while (marking_stack()->pop_overflow(obj)) {
jcoomes@1993 190 obj->follow_contents(this);
jcoomes@1746 191 }
jcoomes@1746 192 while (marking_stack()->pop_local(obj)) {
duke@435 193 obj->follow_contents(this);
duke@435 194 }
duke@435 195
jcoomes@1750 196 // Process ObjArrays one at a time to avoid marking stack bloat.
jcoomes@1746 197 ObjArrayTask task;
jcoomes@1993 198 if (_objarray_stack.pop_overflow(task)) {
jcoomes@1746 199 objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint();
jcoomes@1746 200 k->oop_follow_contents(this, task.obj(), task.index());
jcoomes@1993 201 } else if (_objarray_stack.pop_local(task)) {
jcoomes@1746 202 objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint();
jcoomes@1746 203 k->oop_follow_contents(this, task.obj(), task.index());
jcoomes@1746 204 }
jcoomes@1746 205 } while (!marking_stacks_empty());
duke@435 206
jcoomes@1746 207 assert(marking_stacks_empty(), "Sanity");
duke@435 208 }
duke@435 209
jcoomes@810 210 void ParCompactionManager::drain_region_stacks() {
duke@435 211 do {
jcoomes@1993 212 // Drain overflow stack first so other threads can steal.
jcoomes@1993 213 size_t region_index;
jcoomes@1993 214 while (region_stack()->pop_overflow(region_index)) {
jcoomes@810 215 PSParallelCompact::fill_and_update_region(this, region_index);
duke@435 216 }
duke@435 217
jcoomes@1993 218 while (region_stack()->pop_local(region_index)) {
jcoomes@810 219 PSParallelCompact::fill_and_update_region(this, region_index);
duke@435 220 }
jcoomes@810 221 } while (!region_stack()->is_empty());
duke@435 222 }

mercurial