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

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 548
ba764ed4b6f2
permissions
-rw-r--r--

Initial load

     1 /*
     2  * Copyright 2002-2006 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 #include "incls/_precompiled.incl"
    26 #include "incls/_psTasks.cpp.incl"
    28 //
    29 // ScavengeRootsTask
    30 //
    32 // Define before use
    33 class PSScavengeRootsClosure: public OopClosure {
    34  private:
    35   PSPromotionManager* _promotion_manager;
    37  public:
    38   PSScavengeRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
    40   virtual void do_oop(oop* p) {
    41     if (PSScavenge::should_scavenge(*p)) {
    42       // We never card mark roots, maybe call a func without test?
    43       PSScavenge::copy_and_push_safe_barrier(_promotion_manager, p);
    44     }
    45   }
    46 };
    48 void ScavengeRootsTask::do_it(GCTaskManager* manager, uint which) {
    49   assert(Universe::heap()->is_gc_active(), "called outside gc");
    51   PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
    52   PSScavengeRootsClosure roots_closure(pm);
    54   switch (_root_type) {
    55     case universe:
    56       Universe::oops_do(&roots_closure);
    57       ReferenceProcessor::oops_do(&roots_closure);
    58       break;
    60     case jni_handles:
    61       JNIHandles::oops_do(&roots_closure);
    62       break;
    64     case threads:
    65     {
    66       ResourceMark rm;
    67       Threads::oops_do(&roots_closure);
    68     }
    69     break;
    71     case object_synchronizer:
    72       ObjectSynchronizer::oops_do(&roots_closure);
    73       break;
    75     case flat_profiler:
    76       FlatProfiler::oops_do(&roots_closure);
    77       break;
    79     case system_dictionary:
    80       SystemDictionary::oops_do(&roots_closure);
    81       break;
    83     case management:
    84       Management::oops_do(&roots_closure);
    85       break;
    87     case jvmti:
    88       JvmtiExport::oops_do(&roots_closure);
    89       break;
    91     default:
    92       fatal("Unknown root type");
    93   }
    95   // Do the real work
    96   pm->drain_stacks(false);
    97 }
    99 //
   100 // ThreadRootsTask
   101 //
   103 void ThreadRootsTask::do_it(GCTaskManager* manager, uint which) {
   104   assert(Universe::heap()->is_gc_active(), "called outside gc");
   106   PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
   107   PSScavengeRootsClosure roots_closure(pm);
   109   if (_java_thread != NULL)
   110     _java_thread->oops_do(&roots_closure);
   112   if (_vm_thread != NULL)
   113     _vm_thread->oops_do(&roots_closure);
   115   // Do the real work
   116   pm->drain_stacks(false);
   117 }
   119 //
   120 // StealTask
   121 //
   123 StealTask::StealTask(ParallelTaskTerminator* t) :
   124   _terminator(t) {}
   126 void StealTask::do_it(GCTaskManager* manager, uint which) {
   127   assert(Universe::heap()->is_gc_active(), "called outside gc");
   129   PSPromotionManager* pm =
   130     PSPromotionManager::gc_thread_promotion_manager(which);
   131   pm->drain_stacks(true);
   132   guarantee(pm->stacks_empty(),
   133             "stacks should be empty at this point");
   135   int random_seed = 17;
   136   if (pm->depth_first()) {
   137     while(true) {
   138       oop* p;
   139       if (PSPromotionManager::steal_depth(which, &random_seed, p)) {
   140 #if PS_PM_STATS
   141         pm->increment_steals(p);
   142 #endif // PS_PM_STATS
   143         pm->process_popped_location_depth(p);
   144         pm->drain_stacks_depth(true);
   145       } else {
   146         if (terminator()->offer_termination()) {
   147           break;
   148         }
   149       }
   150     }
   151   } else {
   152     while(true) {
   153       oop obj;
   154       if (PSPromotionManager::steal_breadth(which, &random_seed, obj)) {
   155 #if PS_PM_STATS
   156         pm->increment_steals();
   157 #endif // PS_PM_STATS
   158         obj->copy_contents(pm);
   159         pm->drain_stacks_breadth(true);
   160       } else {
   161         if (terminator()->offer_termination()) {
   162           break;
   163         }
   164       }
   165     }
   166   }
   167   guarantee(pm->stacks_empty(),
   168             "stacks should be empty at this point");
   169 }
   171 //
   172 // SerialOldToYoungRootsTask
   173 //
   175 void SerialOldToYoungRootsTask::do_it(GCTaskManager* manager, uint which) {
   176   assert(_gen != NULL, "Sanity");
   177   assert(_gen->object_space()->contains(_gen_top) || _gen_top == _gen->object_space()->top(), "Sanity");
   179   {
   180     PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
   182     assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
   183     CardTableExtension* card_table = (CardTableExtension *)Universe::heap()->barrier_set();
   184     // FIX ME! Assert that card_table is the type we believe it to be.
   186     card_table->scavenge_contents(_gen->start_array(),
   187                                   _gen->object_space(),
   188                                   _gen_top,
   189                                   pm);
   191     // Do the real work
   192     pm->drain_stacks(false);
   193   }
   194 }
   196 //
   197 // OldToYoungRootsTask
   198 //
   200 void OldToYoungRootsTask::do_it(GCTaskManager* manager, uint which) {
   201   assert(_gen != NULL, "Sanity");
   202   assert(_gen->object_space()->contains(_gen_top) || _gen_top == _gen->object_space()->top(), "Sanity");
   203   assert(_stripe_number < ParallelGCThreads, "Sanity");
   205   {
   206     PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
   208     assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
   209     CardTableExtension* card_table = (CardTableExtension *)Universe::heap()->barrier_set();
   210     // FIX ME! Assert that card_table is the type we believe it to be.
   212     card_table->scavenge_contents_parallel(_gen->start_array(),
   213                                            _gen->object_space(),
   214                                            _gen_top,
   215                                            pm,
   216                                            _stripe_number);
   218     // Do the real work
   219     pm->drain_stacks(false);
   220   }
   221 }

mercurial