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

Wed, 03 Mar 2010 14:48:26 -0800

author
jcoomes
date
Wed, 03 Mar 2010 14:48:26 -0800
changeset 1746
2a1472c30599
parent 1435
a1423fe86a18
child 1907
c18cbe5936b8
permissions
-rw-r--r--

4396719: Mark Sweep stack overflow on deeply nested Object arrays
Summary: Use an explicit stack for object arrays and process them in chunks.
Reviewed-by: iveresov, apetrusenko

duke@435 1 /*
xdono@1383 2 * Copyright 2005-2009 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_pcTasks.cpp.incl"
duke@435 27
duke@435 28 //
duke@435 29 // ThreadRootsMarkingTask
duke@435 30 //
duke@435 31
duke@435 32 void ThreadRootsMarkingTask::do_it(GCTaskManager* manager, uint which) {
duke@435 33 assert(Universe::heap()->is_gc_active(), "called outside gc");
duke@435 34
duke@435 35 ResourceMark rm;
duke@435 36
duke@435 37 NOT_PRODUCT(TraceTime tm("ThreadRootsMarkingTask",
duke@435 38 PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
duke@435 39 ParCompactionManager* cm =
duke@435 40 ParCompactionManager::gc_thread_compaction_manager(which);
duke@435 41 PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
jrose@1424 42 CodeBlobToOopClosure mark_and_push_in_blobs(&mark_and_push_closure, /*do_marking=*/ true);
duke@435 43
duke@435 44 if (_java_thread != NULL)
jrose@1424 45 _java_thread->oops_do(&mark_and_push_closure, &mark_and_push_in_blobs);
duke@435 46
duke@435 47 if (_vm_thread != NULL)
jrose@1424 48 _vm_thread->oops_do(&mark_and_push_closure, &mark_and_push_in_blobs);
duke@435 49
duke@435 50 // Do the real work
jcoomes@1746 51 cm->follow_marking_stacks();
duke@435 52 }
duke@435 53
duke@435 54
duke@435 55 void MarkFromRootsTask::do_it(GCTaskManager* manager, uint which) {
duke@435 56 assert(Universe::heap()->is_gc_active(), "called outside gc");
duke@435 57
duke@435 58 NOT_PRODUCT(TraceTime tm("MarkFromRootsTask",
duke@435 59 PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
duke@435 60 ParCompactionManager* cm =
duke@435 61 ParCompactionManager::gc_thread_compaction_manager(which);
duke@435 62 assert(cm->stacks_have_been_allocated(),
ysr@1376 63 "Stack space has not been allocated");
duke@435 64 PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
duke@435 65
duke@435 66 switch (_root_type) {
duke@435 67 case universe:
duke@435 68 Universe::oops_do(&mark_and_push_closure);
duke@435 69 break;
duke@435 70
duke@435 71 case reference_processing:
duke@435 72 ReferenceProcessor::oops_do(&mark_and_push_closure);
duke@435 73 break;
duke@435 74
duke@435 75 case jni_handles:
duke@435 76 JNIHandles::oops_do(&mark_and_push_closure);
duke@435 77 break;
duke@435 78
duke@435 79 case threads:
duke@435 80 {
duke@435 81 ResourceMark rm;
jrose@1424 82 CodeBlobToOopClosure each_active_code_blob(&mark_and_push_closure, /*do_marking=*/ true);
jrose@1424 83 Threads::oops_do(&mark_and_push_closure, &each_active_code_blob);
duke@435 84 }
duke@435 85 break;
duke@435 86
duke@435 87 case object_synchronizer:
duke@435 88 ObjectSynchronizer::oops_do(&mark_and_push_closure);
duke@435 89 break;
duke@435 90
duke@435 91 case flat_profiler:
duke@435 92 FlatProfiler::oops_do(&mark_and_push_closure);
duke@435 93 break;
duke@435 94
duke@435 95 case management:
duke@435 96 Management::oops_do(&mark_and_push_closure);
duke@435 97 break;
duke@435 98
duke@435 99 case jvmti:
duke@435 100 JvmtiExport::oops_do(&mark_and_push_closure);
duke@435 101 break;
duke@435 102
duke@435 103 case system_dictionary:
duke@435 104 SystemDictionary::always_strong_oops_do(&mark_and_push_closure);
duke@435 105 break;
duke@435 106
duke@435 107 case vm_symbols:
duke@435 108 vmSymbols::oops_do(&mark_and_push_closure);
duke@435 109 break;
duke@435 110
jrose@1424 111 case code_cache:
jrose@1424 112 // Do not treat nmethods as strong roots for mark/sweep, since we can unload them.
jrose@1424 113 //CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure(&mark_and_push_closure));
jrose@1424 114 break;
jrose@1424 115
duke@435 116 default:
duke@435 117 fatal("Unknown root type");
duke@435 118 }
duke@435 119
duke@435 120 // Do the real work
jcoomes@1746 121 cm->follow_marking_stacks();
duke@435 122 // cm->deallocate_stacks();
duke@435 123 }
duke@435 124
duke@435 125
duke@435 126 //
duke@435 127 // RefProcTaskProxy
duke@435 128 //
duke@435 129
duke@435 130 void RefProcTaskProxy::do_it(GCTaskManager* manager, uint which)
duke@435 131 {
duke@435 132 assert(Universe::heap()->is_gc_active(), "called outside gc");
duke@435 133
duke@435 134 NOT_PRODUCT(TraceTime tm("RefProcTask",
duke@435 135 PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
duke@435 136 ParCompactionManager* cm =
duke@435 137 ParCompactionManager::gc_thread_compaction_manager(which);
duke@435 138 assert(cm->stacks_have_been_allocated(),
ysr@1376 139 "Stack space has not been allocated");
duke@435 140 PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
duke@435 141 PSParallelCompact::FollowStackClosure follow_stack_closure(cm);
duke@435 142 _rp_task.work(_work_id, *PSParallelCompact::is_alive_closure(),
duke@435 143 mark_and_push_closure, follow_stack_closure);
duke@435 144 }
duke@435 145
duke@435 146 //
duke@435 147 // RefProcTaskExecutor
duke@435 148 //
duke@435 149
duke@435 150 void RefProcTaskExecutor::execute(ProcessTask& task)
duke@435 151 {
duke@435 152 ParallelScavengeHeap* heap = PSParallelCompact::gc_heap();
duke@435 153 uint parallel_gc_threads = heap->gc_task_manager()->workers();
jcoomes@810 154 RegionTaskQueueSet* qset = ParCompactionManager::region_array();
duke@435 155 ParallelTaskTerminator terminator(parallel_gc_threads, qset);
duke@435 156 GCTaskQueue* q = GCTaskQueue::create();
duke@435 157 for(uint i=0; i<parallel_gc_threads; i++) {
duke@435 158 q->enqueue(new RefProcTaskProxy(task, i));
duke@435 159 }
duke@435 160 if (task.marks_oops_alive()) {
duke@435 161 if (parallel_gc_threads>1) {
duke@435 162 for (uint j=0; j<parallel_gc_threads; j++) {
duke@435 163 q->enqueue(new StealMarkingTask(&terminator));
duke@435 164 }
duke@435 165 }
duke@435 166 }
duke@435 167 PSParallelCompact::gc_task_manager()->execute_and_wait(q);
duke@435 168 }
duke@435 169
duke@435 170 void RefProcTaskExecutor::execute(EnqueueTask& task)
duke@435 171 {
duke@435 172 ParallelScavengeHeap* heap = PSParallelCompact::gc_heap();
duke@435 173 uint parallel_gc_threads = heap->gc_task_manager()->workers();
duke@435 174 GCTaskQueue* q = GCTaskQueue::create();
duke@435 175 for(uint i=0; i<parallel_gc_threads; i++) {
duke@435 176 q->enqueue(new RefEnqueueTaskProxy(task, i));
duke@435 177 }
duke@435 178 PSParallelCompact::gc_task_manager()->execute_and_wait(q);
duke@435 179 }
duke@435 180
duke@435 181 //
duke@435 182 // StealMarkingTask
duke@435 183 //
duke@435 184
duke@435 185 StealMarkingTask::StealMarkingTask(ParallelTaskTerminator* t) :
duke@435 186 _terminator(t) {}
duke@435 187
duke@435 188 void StealMarkingTask::do_it(GCTaskManager* manager, uint which) {
duke@435 189 assert(Universe::heap()->is_gc_active(), "called outside gc");
duke@435 190
duke@435 191 NOT_PRODUCT(TraceTime tm("StealMarkingTask",
duke@435 192 PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
duke@435 193
duke@435 194 ParCompactionManager* cm =
duke@435 195 ParCompactionManager::gc_thread_compaction_manager(which);
duke@435 196 PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
duke@435 197
duke@435 198 oop obj = NULL;
jcoomes@1746 199 ObjArrayTask task;
duke@435 200 int random_seed = 17;
jcoomes@1746 201 do {
jcoomes@1746 202 while (ParCompactionManager::steal_objarray(which, &random_seed, task)) {
jcoomes@1746 203 objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint();
jcoomes@1746 204 k->oop_follow_contents(cm, task.obj(), task.index());
jcoomes@1746 205 cm->follow_marking_stacks();
jcoomes@1746 206 }
jcoomes@1746 207 while (ParCompactionManager::steal(which, &random_seed, obj)) {
duke@435 208 obj->follow_contents(cm);
jcoomes@1746 209 cm->follow_marking_stacks();
duke@435 210 }
jcoomes@1746 211 } while (!terminator()->offer_termination());
duke@435 212 }
duke@435 213
duke@435 214 //
jcoomes@810 215 // StealRegionCompactionTask
duke@435 216 //
duke@435 217
duke@435 218
jcoomes@810 219 StealRegionCompactionTask::StealRegionCompactionTask(ParallelTaskTerminator* t):
jcoomes@810 220 _terminator(t) {}
duke@435 221
jcoomes@810 222 void StealRegionCompactionTask::do_it(GCTaskManager* manager, uint which) {
duke@435 223 assert(Universe::heap()->is_gc_active(), "called outside gc");
duke@435 224
jcoomes@810 225 NOT_PRODUCT(TraceTime tm("StealRegionCompactionTask",
duke@435 226 PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
duke@435 227
duke@435 228 ParCompactionManager* cm =
duke@435 229 ParCompactionManager::gc_thread_compaction_manager(which);
duke@435 230
jcoomes@810 231 // Has to drain stacks first because there may be regions on
duke@435 232 // preloaded onto the stack and this thread may never have
duke@435 233 // done a draining task. Are the draining tasks needed?
duke@435 234
jcoomes@810 235 cm->drain_region_stacks();
duke@435 236
jcoomes@810 237 size_t region_index = 0;
duke@435 238 int random_seed = 17;
duke@435 239
duke@435 240 // If we're the termination task, try 10 rounds of stealing before
duke@435 241 // setting the termination flag
duke@435 242
duke@435 243 while(true) {
jcoomes@810 244 if (ParCompactionManager::steal(which, &random_seed, region_index)) {
jcoomes@810 245 PSParallelCompact::fill_and_update_region(cm, region_index);
jcoomes@810 246 cm->drain_region_stacks();
duke@435 247 } else {
duke@435 248 if (terminator()->offer_termination()) {
duke@435 249 break;
duke@435 250 }
duke@435 251 // Go around again.
duke@435 252 }
duke@435 253 }
duke@435 254 return;
duke@435 255 }
duke@435 256
duke@435 257 UpdateDensePrefixTask::UpdateDensePrefixTask(
duke@435 258 PSParallelCompact::SpaceId space_id,
jcoomes@810 259 size_t region_index_start,
jcoomes@810 260 size_t region_index_end) :
jcoomes@810 261 _space_id(space_id), _region_index_start(region_index_start),
jcoomes@810 262 _region_index_end(region_index_end) {}
duke@435 263
duke@435 264 void UpdateDensePrefixTask::do_it(GCTaskManager* manager, uint which) {
duke@435 265
duke@435 266 NOT_PRODUCT(TraceTime tm("UpdateDensePrefixTask",
duke@435 267 PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
duke@435 268
duke@435 269 ParCompactionManager* cm =
duke@435 270 ParCompactionManager::gc_thread_compaction_manager(which);
duke@435 271
duke@435 272 PSParallelCompact::update_and_deadwood_in_dense_prefix(cm,
duke@435 273 _space_id,
jcoomes@810 274 _region_index_start,
jcoomes@810 275 _region_index_end);
duke@435 276 }
duke@435 277
duke@435 278 void DrainStacksCompactionTask::do_it(GCTaskManager* manager, uint which) {
duke@435 279 assert(Universe::heap()->is_gc_active(), "called outside gc");
duke@435 280
duke@435 281 NOT_PRODUCT(TraceTime tm("DrainStacksCompactionTask",
duke@435 282 PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty));
duke@435 283
duke@435 284 ParCompactionManager* cm =
duke@435 285 ParCompactionManager::gc_thread_compaction_manager(which);
duke@435 286
jcoomes@810 287 // Process any regions already in the compaction managers stacks.
jcoomes@810 288 cm->drain_region_stacks();
duke@435 289 }

mercurial