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

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,378 @@
     1.4 +/*
     1.5 + * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "classfile/systemDictionary.hpp"
    1.30 +#include "code/codeCache.hpp"
    1.31 +#include "gc_implementation/parallelScavenge/pcTasks.hpp"
    1.32 +#include "gc_implementation/parallelScavenge/psParallelCompact.hpp"
    1.33 +#include "gc_implementation/shared/gcTimer.hpp"
    1.34 +#include "gc_implementation/shared/gcTraceTime.hpp"
    1.35 +#include "gc_interface/collectedHeap.hpp"
    1.36 +#include "memory/universe.hpp"
    1.37 +#include "oops/objArrayKlass.inline.hpp"
    1.38 +#include "oops/oop.inline.hpp"
    1.39 +#include "oops/oop.pcgc.inline.hpp"
    1.40 +#include "prims/jvmtiExport.hpp"
    1.41 +#include "runtime/fprofiler.hpp"
    1.42 +#include "runtime/jniHandles.hpp"
    1.43 +#include "runtime/thread.hpp"
    1.44 +#include "runtime/vmThread.hpp"
    1.45 +#include "services/management.hpp"
    1.46 +
    1.47 +PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
    1.48 +
    1.49 +//
    1.50 +// ThreadRootsMarkingTask
    1.51 +//
    1.52 +
    1.53 +void ThreadRootsMarkingTask::do_it(GCTaskManager* manager, uint which) {
    1.54 +  assert(Universe::heap()->is_gc_active(), "called outside gc");
    1.55 +
    1.56 +  ResourceMark rm;
    1.57 +
    1.58 +  NOT_PRODUCT(GCTraceTime tm("ThreadRootsMarkingTask",
    1.59 +    PrintGCDetails && TraceParallelOldGCTasks, true, NULL));
    1.60 +  ParCompactionManager* cm =
    1.61 +    ParCompactionManager::gc_thread_compaction_manager(which);
    1.62 +
    1.63 +  PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
    1.64 +  CLDToOopClosure mark_and_push_from_clds(&mark_and_push_closure, true);
    1.65 +  CodeBlobToOopClosure mark_and_push_in_blobs(&mark_and_push_closure, /*do_marking=*/ true);
    1.66 +
    1.67 +  if (_java_thread != NULL)
    1.68 +    _java_thread->oops_do(
    1.69 +        &mark_and_push_closure,
    1.70 +        &mark_and_push_from_clds,
    1.71 +        &mark_and_push_in_blobs);
    1.72 +
    1.73 +  if (_vm_thread != NULL)
    1.74 +    _vm_thread->oops_do(
    1.75 +        &mark_and_push_closure,
    1.76 +        &mark_and_push_from_clds,
    1.77 +        &mark_and_push_in_blobs);
    1.78 +
    1.79 +  // Do the real work
    1.80 +  cm->follow_marking_stacks();
    1.81 +}
    1.82 +
    1.83 +
    1.84 +void MarkFromRootsTask::do_it(GCTaskManager* manager, uint which) {
    1.85 +  assert(Universe::heap()->is_gc_active(), "called outside gc");
    1.86 +
    1.87 +  NOT_PRODUCT(GCTraceTime tm("MarkFromRootsTask",
    1.88 +    PrintGCDetails && TraceParallelOldGCTasks, true, NULL));
    1.89 +  ParCompactionManager* cm =
    1.90 +    ParCompactionManager::gc_thread_compaction_manager(which);
    1.91 +  PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
    1.92 +  PSParallelCompact::FollowKlassClosure follow_klass_closure(&mark_and_push_closure);
    1.93 +
    1.94 +  switch (_root_type) {
    1.95 +    case universe:
    1.96 +      Universe::oops_do(&mark_and_push_closure);
    1.97 +      break;
    1.98 +
    1.99 +    case jni_handles:
   1.100 +      JNIHandles::oops_do(&mark_and_push_closure);
   1.101 +      break;
   1.102 +
   1.103 +    case threads:
   1.104 +    {
   1.105 +      ResourceMark rm;
   1.106 +      CodeBlobToOopClosure each_active_code_blob(&mark_and_push_closure, /*do_marking=*/ true);
   1.107 +      CLDToOopClosure mark_and_push_from_cld(&mark_and_push_closure);
   1.108 +      Threads::oops_do(&mark_and_push_closure, &mark_and_push_from_cld, &each_active_code_blob);
   1.109 +    }
   1.110 +    break;
   1.111 +
   1.112 +    case object_synchronizer:
   1.113 +      ObjectSynchronizer::oops_do(&mark_and_push_closure);
   1.114 +      break;
   1.115 +
   1.116 +    case flat_profiler:
   1.117 +      FlatProfiler::oops_do(&mark_and_push_closure);
   1.118 +      break;
   1.119 +
   1.120 +    case management:
   1.121 +      Management::oops_do(&mark_and_push_closure);
   1.122 +      break;
   1.123 +
   1.124 +    case jvmti:
   1.125 +      JvmtiExport::oops_do(&mark_and_push_closure);
   1.126 +      break;
   1.127 +
   1.128 +    case system_dictionary:
   1.129 +      SystemDictionary::always_strong_oops_do(&mark_and_push_closure);
   1.130 +      break;
   1.131 +
   1.132 +    case class_loader_data:
   1.133 +      ClassLoaderDataGraph::always_strong_oops_do(&mark_and_push_closure, &follow_klass_closure, true);
   1.134 +      break;
   1.135 +
   1.136 +    case code_cache:
   1.137 +      // Do not treat nmethods as strong roots for mark/sweep, since we can unload them.
   1.138 +      //CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure(&mark_and_push_closure));
   1.139 +      break;
   1.140 +
   1.141 +    default:
   1.142 +      fatal("Unknown root type");
   1.143 +  }
   1.144 +
   1.145 +  // Do the real work
   1.146 +  cm->follow_marking_stacks();
   1.147 +}
   1.148 +
   1.149 +
   1.150 +//
   1.151 +// RefProcTaskProxy
   1.152 +//
   1.153 +
   1.154 +void RefProcTaskProxy::do_it(GCTaskManager* manager, uint which)
   1.155 +{
   1.156 +  assert(Universe::heap()->is_gc_active(), "called outside gc");
   1.157 +
   1.158 +  NOT_PRODUCT(GCTraceTime tm("RefProcTask",
   1.159 +    PrintGCDetails && TraceParallelOldGCTasks, true, NULL));
   1.160 +  ParCompactionManager* cm =
   1.161 +    ParCompactionManager::gc_thread_compaction_manager(which);
   1.162 +  PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
   1.163 +  PSParallelCompact::FollowStackClosure follow_stack_closure(cm);
   1.164 +  _rp_task.work(_work_id, *PSParallelCompact::is_alive_closure(),
   1.165 +                mark_and_push_closure, follow_stack_closure);
   1.166 +}
   1.167 +
   1.168 +//
   1.169 +// RefProcTaskExecutor
   1.170 +//
   1.171 +
   1.172 +void RefProcTaskExecutor::execute(ProcessTask& task)
   1.173 +{
   1.174 +  ParallelScavengeHeap* heap = PSParallelCompact::gc_heap();
   1.175 +  uint parallel_gc_threads = heap->gc_task_manager()->workers();
   1.176 +  uint active_gc_threads = heap->gc_task_manager()->active_workers();
   1.177 +  RegionTaskQueueSet* qset = ParCompactionManager::region_array();
   1.178 +  ParallelTaskTerminator terminator(active_gc_threads, qset);
   1.179 +  GCTaskQueue* q = GCTaskQueue::create();
   1.180 +  for(uint i=0; i<parallel_gc_threads; i++) {
   1.181 +    q->enqueue(new RefProcTaskProxy(task, i));
   1.182 +  }
   1.183 +  if (task.marks_oops_alive()) {
   1.184 +    if (parallel_gc_threads>1) {
   1.185 +      for (uint j=0; j<active_gc_threads; j++) {
   1.186 +        q->enqueue(new StealMarkingTask(&terminator));
   1.187 +      }
   1.188 +    }
   1.189 +  }
   1.190 +  PSParallelCompact::gc_task_manager()->execute_and_wait(q);
   1.191 +}
   1.192 +
   1.193 +void RefProcTaskExecutor::execute(EnqueueTask& task)
   1.194 +{
   1.195 +  ParallelScavengeHeap* heap = PSParallelCompact::gc_heap();
   1.196 +  uint parallel_gc_threads = heap->gc_task_manager()->workers();
   1.197 +  GCTaskQueue* q = GCTaskQueue::create();
   1.198 +  for(uint i=0; i<parallel_gc_threads; i++) {
   1.199 +    q->enqueue(new RefEnqueueTaskProxy(task, i));
   1.200 +  }
   1.201 +  PSParallelCompact::gc_task_manager()->execute_and_wait(q);
   1.202 +}
   1.203 +
   1.204 +//
   1.205 +// StealMarkingTask
   1.206 +//
   1.207 +
   1.208 +StealMarkingTask::StealMarkingTask(ParallelTaskTerminator* t) :
   1.209 +  _terminator(t) {}
   1.210 +
   1.211 +void StealMarkingTask::do_it(GCTaskManager* manager, uint which) {
   1.212 +  assert(Universe::heap()->is_gc_active(), "called outside gc");
   1.213 +
   1.214 +  NOT_PRODUCT(GCTraceTime tm("StealMarkingTask",
   1.215 +    PrintGCDetails && TraceParallelOldGCTasks, true, NULL));
   1.216 +
   1.217 +  ParCompactionManager* cm =
   1.218 +    ParCompactionManager::gc_thread_compaction_manager(which);
   1.219 +  PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
   1.220 +
   1.221 +  oop obj = NULL;
   1.222 +  ObjArrayTask task;
   1.223 +  int random_seed = 17;
   1.224 +  do {
   1.225 +    while (ParCompactionManager::steal_objarray(which, &random_seed, task)) {
   1.226 +      ObjArrayKlass* k = (ObjArrayKlass*)task.obj()->klass();
   1.227 +      k->oop_follow_contents(cm, task.obj(), task.index());
   1.228 +      cm->follow_marking_stacks();
   1.229 +    }
   1.230 +    while (ParCompactionManager::steal(which, &random_seed, obj)) {
   1.231 +      obj->follow_contents(cm);
   1.232 +      cm->follow_marking_stacks();
   1.233 +    }
   1.234 +  } while (!terminator()->offer_termination());
   1.235 +}
   1.236 +
   1.237 +//
   1.238 +// StealRegionCompactionTask
   1.239 +//
   1.240 +
   1.241 +StealRegionCompactionTask::StealRegionCompactionTask(ParallelTaskTerminator* t):
   1.242 +  _terminator(t) {}
   1.243 +
   1.244 +void StealRegionCompactionTask::do_it(GCTaskManager* manager, uint which) {
   1.245 +  assert(Universe::heap()->is_gc_active(), "called outside gc");
   1.246 +
   1.247 +  NOT_PRODUCT(GCTraceTime tm("StealRegionCompactionTask",
   1.248 +    PrintGCDetails && TraceParallelOldGCTasks, true, NULL));
   1.249 +
   1.250 +  ParCompactionManager* cm =
   1.251 +    ParCompactionManager::gc_thread_compaction_manager(which);
   1.252 +
   1.253 +
   1.254 +  // If not all threads are active, get a draining stack
   1.255 +  // from the list.  Else, just use this threads draining stack.
   1.256 +  uint which_stack_index;
   1.257 +  bool use_all_workers = manager->all_workers_active();
   1.258 +  if (use_all_workers) {
   1.259 +    which_stack_index = which;
   1.260 +    assert(manager->active_workers() == ParallelGCThreads,
   1.261 +           err_msg("all_workers_active has been incorrectly set: "
   1.262 +                   " active %d  ParallelGCThreads %d", manager->active_workers(),
   1.263 +                   ParallelGCThreads));
   1.264 +  } else {
   1.265 +    which_stack_index = ParCompactionManager::pop_recycled_stack_index();
   1.266 +  }
   1.267 +
   1.268 +  cm->set_region_stack_index(which_stack_index);
   1.269 +  cm->set_region_stack(ParCompactionManager::region_list(which_stack_index));
   1.270 +  if (TraceDynamicGCThreads) {
   1.271 +    gclog_or_tty->print_cr("StealRegionCompactionTask::do_it "
   1.272 +                           "region_stack_index %d region_stack = 0x%x "
   1.273 +                           " empty (%d) use all workers %d",
   1.274 +    which_stack_index, ParCompactionManager::region_list(which_stack_index),
   1.275 +    cm->region_stack()->is_empty(),
   1.276 +    use_all_workers);
   1.277 +  }
   1.278 +
   1.279 +  // Has to drain stacks first because there may be regions on
   1.280 +  // preloaded onto the stack and this thread may never have
   1.281 +  // done a draining task.  Are the draining tasks needed?
   1.282 +
   1.283 +  cm->drain_region_stacks();
   1.284 +
   1.285 +  size_t region_index = 0;
   1.286 +  int random_seed = 17;
   1.287 +
   1.288 +  // If we're the termination task, try 10 rounds of stealing before
   1.289 +  // setting the termination flag
   1.290 +
   1.291 +  while(true) {
   1.292 +    if (ParCompactionManager::steal(which, &random_seed, region_index)) {
   1.293 +      PSParallelCompact::fill_and_update_region(cm, region_index);
   1.294 +      cm->drain_region_stacks();
   1.295 +    } else {
   1.296 +      if (terminator()->offer_termination()) {
   1.297 +        break;
   1.298 +      }
   1.299 +      // Go around again.
   1.300 +    }
   1.301 +  }
   1.302 +  return;
   1.303 +}
   1.304 +
   1.305 +UpdateDensePrefixTask::UpdateDensePrefixTask(
   1.306 +                                   PSParallelCompact::SpaceId space_id,
   1.307 +                                   size_t region_index_start,
   1.308 +                                   size_t region_index_end) :
   1.309 +  _space_id(space_id), _region_index_start(region_index_start),
   1.310 +  _region_index_end(region_index_end) {}
   1.311 +
   1.312 +void UpdateDensePrefixTask::do_it(GCTaskManager* manager, uint which) {
   1.313 +
   1.314 +  NOT_PRODUCT(GCTraceTime tm("UpdateDensePrefixTask",
   1.315 +    PrintGCDetails && TraceParallelOldGCTasks, true, NULL));
   1.316 +
   1.317 +  ParCompactionManager* cm =
   1.318 +    ParCompactionManager::gc_thread_compaction_manager(which);
   1.319 +
   1.320 +  PSParallelCompact::update_and_deadwood_in_dense_prefix(cm,
   1.321 +                                                         _space_id,
   1.322 +                                                         _region_index_start,
   1.323 +                                                         _region_index_end);
   1.324 +}
   1.325 +
   1.326 +void DrainStacksCompactionTask::do_it(GCTaskManager* manager, uint which) {
   1.327 +  assert(Universe::heap()->is_gc_active(), "called outside gc");
   1.328 +
   1.329 +  NOT_PRODUCT(GCTraceTime tm("DrainStacksCompactionTask",
   1.330 +    PrintGCDetails && TraceParallelOldGCTasks, true, NULL));
   1.331 +
   1.332 +  ParCompactionManager* cm =
   1.333 +    ParCompactionManager::gc_thread_compaction_manager(which);
   1.334 +
   1.335 +  uint which_stack_index;
   1.336 +  bool use_all_workers = manager->all_workers_active();
   1.337 +  if (use_all_workers) {
   1.338 +    which_stack_index = which;
   1.339 +    assert(manager->active_workers() == ParallelGCThreads,
   1.340 +           err_msg("all_workers_active has been incorrectly set: "
   1.341 +                   " active %d  ParallelGCThreads %d", manager->active_workers(),
   1.342 +                   ParallelGCThreads));
   1.343 +  } else {
   1.344 +    which_stack_index = stack_index();
   1.345 +  }
   1.346 +
   1.347 +  cm->set_region_stack(ParCompactionManager::region_list(which_stack_index));
   1.348 +  if (TraceDynamicGCThreads) {
   1.349 +    gclog_or_tty->print_cr("DrainStacksCompactionTask::do_it which = %d "
   1.350 +                           "which_stack_index = %d/empty(%d) "
   1.351 +                           "use all workers %d",
   1.352 +                           which, which_stack_index,
   1.353 +                           cm->region_stack()->is_empty(),
   1.354 +                           use_all_workers);
   1.355 +  }
   1.356 +
   1.357 +  cm->set_region_stack_index(which_stack_index);
   1.358 +
   1.359 +  // Process any regions already in the compaction managers stacks.
   1.360 +  cm->drain_region_stacks();
   1.361 +
   1.362 +  assert(cm->region_stack()->is_empty(), "Not empty");
   1.363 +
   1.364 +  if (!use_all_workers) {
   1.365 +    // Always give up the region stack.
   1.366 +    assert(cm->region_stack() ==
   1.367 +           ParCompactionManager::region_list(cm->region_stack_index()),
   1.368 +           "region_stack and region_stack_index are inconsistent");
   1.369 +    ParCompactionManager::push_recycled_stack_index(cm->region_stack_index());
   1.370 +
   1.371 +    if (TraceDynamicGCThreads) {
   1.372 +      void* old_region_stack = (void*) cm->region_stack();
   1.373 +      int old_region_stack_index = cm->region_stack_index();
   1.374 +      gclog_or_tty->print_cr("Pushing region stack 0x%x/%d",
   1.375 +        old_region_stack, old_region_stack_index);
   1.376 +    }
   1.377 +
   1.378 +    cm->set_region_stack(NULL);
   1.379 +    cm->set_region_stack_index((uint)max_uintx);
   1.380 +  }
   1.381 +}

mercurial