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