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

Mon, 09 Mar 2009 13:28:46 -0700

author
xdono
date
Mon, 09 Mar 2009 13:28:46 -0700
changeset 1014
0fbdb4381b99
parent 905
ad8c8ca4ab0f
child 1376
8b46c4d82093
permissions
-rw-r--r--

6814575: Update copyright year
Summary: Update copyright for files that have been modified in 2009, up to 03/09
Reviewed-by: katleman, tbell, ohair

     1 /*
     2  * Copyright 2005-2008 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/_psCompactionManager.cpp.incl"
    28 PSOldGen*            ParCompactionManager::_old_gen = NULL;
    29 ParCompactionManager**  ParCompactionManager::_manager_array = NULL;
    30 OopTaskQueueSet*     ParCompactionManager::_stack_array = NULL;
    31 ObjectStartArray*    ParCompactionManager::_start_array = NULL;
    32 ParMarkBitMap*       ParCompactionManager::_mark_bitmap = NULL;
    33 RegionTaskQueueSet*   ParCompactionManager::_region_array = NULL;
    35 ParCompactionManager::ParCompactionManager() :
    36     _action(CopyAndUpdate) {
    38   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
    39   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
    41   _old_gen = heap->old_gen();
    42   _start_array = old_gen()->start_array();
    45   marking_stack()->initialize();
    47   // We want the overflow stack to be permanent
    48   _overflow_stack = new (ResourceObj::C_HEAP) GrowableArray<oop>(10, true);
    49 #ifdef USE_RegionTaskQueueWithOverflow
    50   region_stack()->initialize();
    51 #else
    52   region_stack()->initialize();
    54   // We want the overflow stack to be permanent
    55   _region_overflow_stack =
    56     new (ResourceObj::C_HEAP) GrowableArray<size_t>(10, true);
    57 #endif
    59   // Note that _revisit_klass_stack is allocated out of the
    60   // C heap (as opposed to out of ResourceArena).
    61   int size =
    62     (SystemDictionary::number_of_classes() * 2) * 2 / ParallelGCThreads;
    63   _revisit_klass_stack = new (ResourceObj::C_HEAP) GrowableArray<Klass*>(size, true);
    65 }
    67 ParCompactionManager::~ParCompactionManager() {
    68   delete _overflow_stack;
    69   delete _revisit_klass_stack;
    70   // _manager_array and _stack_array are statics
    71   // shared with all instances of ParCompactionManager
    72   // should not be deallocated.
    73 }
    75 void ParCompactionManager::initialize(ParMarkBitMap* mbm) {
    76   assert(PSParallelCompact::gc_task_manager() != NULL,
    77     "Needed for initialization");
    79   _mark_bitmap = mbm;
    81   uint parallel_gc_threads = PSParallelCompact::gc_task_manager()->workers();
    83   assert(_manager_array == NULL, "Attempt to initialize twice");
    84   _manager_array = NEW_C_HEAP_ARRAY(ParCompactionManager*, parallel_gc_threads+1 );
    85   guarantee(_manager_array != NULL, "Could not initialize promotion manager");
    87   _stack_array = new OopTaskQueueSet(parallel_gc_threads);
    88   guarantee(_stack_array != NULL, "Count not initialize promotion manager");
    89   _region_array = new RegionTaskQueueSet(parallel_gc_threads);
    90   guarantee(_region_array != NULL, "Count not initialize promotion manager");
    92   // Create and register the ParCompactionManager(s) for the worker threads.
    93   for(uint i=0; i<parallel_gc_threads; i++) {
    94     _manager_array[i] = new ParCompactionManager();
    95     guarantee(_manager_array[i] != NULL, "Could not create ParCompactionManager");
    96     stack_array()->register_queue(i, _manager_array[i]->marking_stack());
    97 #ifdef USE_RegionTaskQueueWithOverflow
    98     region_array()->register_queue(i, _manager_array[i]->region_stack()->task_queue());
    99 #else
   100     region_array()->register_queue(i, _manager_array[i]->region_stack());
   101 #endif
   102   }
   104   // The VMThread gets its own ParCompactionManager, which is not available
   105   // for work stealing.
   106   _manager_array[parallel_gc_threads] = new ParCompactionManager();
   107   guarantee(_manager_array[parallel_gc_threads] != NULL,
   108     "Could not create ParCompactionManager");
   109   assert(PSParallelCompact::gc_task_manager()->workers() != 0,
   110     "Not initialized?");
   111 }
   113 bool ParCompactionManager::should_update() {
   114   assert(action() != NotValid, "Action is not set");
   115   return (action() == ParCompactionManager::Update) ||
   116          (action() == ParCompactionManager::CopyAndUpdate) ||
   117          (action() == ParCompactionManager::UpdateAndCopy);
   118 }
   120 bool ParCompactionManager::should_copy() {
   121   assert(action() != NotValid, "Action is not set");
   122   return (action() == ParCompactionManager::Copy) ||
   123          (action() == ParCompactionManager::CopyAndUpdate) ||
   124          (action() == ParCompactionManager::UpdateAndCopy);
   125 }
   127 bool ParCompactionManager::should_verify_only() {
   128   assert(action() != NotValid, "Action is not set");
   129   return action() == ParCompactionManager::VerifyUpdate;
   130 }
   132 bool ParCompactionManager::should_reset_only() {
   133   assert(action() != NotValid, "Action is not set");
   134   return action() == ParCompactionManager::ResetObjects;
   135 }
   137 // For now save on a stack
   138 void ParCompactionManager::save_for_scanning(oop m) {
   139   stack_push(m);
   140 }
   142 void ParCompactionManager::stack_push(oop obj) {
   144   if(!marking_stack()->push(obj)) {
   145     overflow_stack()->push(obj);
   146   }
   147 }
   149 oop ParCompactionManager::retrieve_for_scanning() {
   151   // Should not be used in the parallel case
   152   ShouldNotReachHere();
   153   return NULL;
   154 }
   156 // Save region on a stack
   157 void ParCompactionManager::save_for_processing(size_t region_index) {
   158 #ifdef ASSERT
   159   const ParallelCompactData& sd = PSParallelCompact::summary_data();
   160   ParallelCompactData::RegionData* const region_ptr = sd.region(region_index);
   161   assert(region_ptr->claimed(), "must be claimed");
   162   assert(region_ptr->_pushed++ == 0, "should only be pushed once");
   163 #endif
   164   region_stack_push(region_index);
   165 }
   167 void ParCompactionManager::region_stack_push(size_t region_index) {
   169 #ifdef USE_RegionTaskQueueWithOverflow
   170   region_stack()->save(region_index);
   171 #else
   172   if(!region_stack()->push(region_index)) {
   173     region_overflow_stack()->push(region_index);
   174   }
   175 #endif
   176 }
   178 bool ParCompactionManager::retrieve_for_processing(size_t& region_index) {
   179 #ifdef USE_RegionTaskQueueWithOverflow
   180   return region_stack()->retrieve(region_index);
   181 #else
   182   // Should not be used in the parallel case
   183   ShouldNotReachHere();
   184   return false;
   185 #endif
   186 }
   188 ParCompactionManager*
   189 ParCompactionManager::gc_thread_compaction_manager(int index) {
   190   assert(index >= 0 && index < (int)ParallelGCThreads, "index out of range");
   191   assert(_manager_array != NULL, "Sanity");
   192   return _manager_array[index];
   193 }
   195 void ParCompactionManager::reset() {
   196   for(uint i=0; i<ParallelGCThreads+1; i++) {
   197     manager_array(i)->revisit_klass_stack()->clear();
   198   }
   199 }
   201 void ParCompactionManager::drain_marking_stacks(OopClosure* blk) {
   202 #ifdef ASSERT
   203   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
   204   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
   205   MutableSpace* to_space = heap->young_gen()->to_space();
   206   MutableSpace* old_space = heap->old_gen()->object_space();
   207   MutableSpace* perm_space = heap->perm_gen()->object_space();
   208 #endif /* ASSERT */
   211   do {
   213     // Drain overflow stack first, so other threads can steal from
   214     // claimed stack while we work.
   215     while(!overflow_stack()->is_empty()) {
   216       oop obj = overflow_stack()->pop();
   217       obj->follow_contents(this);
   218     }
   220     oop obj;
   221     // obj is a reference!!!
   222     while (marking_stack()->pop_local(obj)) {
   223       // It would be nice to assert about the type of objects we might
   224       // pop, but they can come from anywhere, unfortunately.
   225       obj->follow_contents(this);
   226     }
   227   } while((marking_stack()->size() != 0) || (overflow_stack()->length() != 0));
   229   assert(marking_stack()->size() == 0, "Sanity");
   230   assert(overflow_stack()->length() == 0, "Sanity");
   231 }
   233 void ParCompactionManager::drain_region_overflow_stack() {
   234   size_t region_index = (size_t) -1;
   235   while(region_stack()->retrieve_from_overflow(region_index)) {
   236     PSParallelCompact::fill_and_update_region(this, region_index);
   237   }
   238 }
   240 void ParCompactionManager::drain_region_stacks() {
   241 #ifdef ASSERT
   242   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
   243   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
   244   MutableSpace* to_space = heap->young_gen()->to_space();
   245   MutableSpace* old_space = heap->old_gen()->object_space();
   246   MutableSpace* perm_space = heap->perm_gen()->object_space();
   247 #endif /* ASSERT */
   249 #if 1 // def DO_PARALLEL - the serial code hasn't been updated
   250   do {
   252 #ifdef USE_RegionTaskQueueWithOverflow
   253     // Drain overflow stack first, so other threads can steal from
   254     // claimed stack while we work.
   255     size_t region_index = (size_t) -1;
   256     while(region_stack()->retrieve_from_overflow(region_index)) {
   257       PSParallelCompact::fill_and_update_region(this, region_index);
   258     }
   260     while (region_stack()->retrieve_from_stealable_queue(region_index)) {
   261       PSParallelCompact::fill_and_update_region(this, region_index);
   262     }
   263   } while (!region_stack()->is_empty());
   264 #else
   265     // Drain overflow stack first, so other threads can steal from
   266     // claimed stack while we work.
   267     while(!region_overflow_stack()->is_empty()) {
   268       size_t region_index = region_overflow_stack()->pop();
   269       PSParallelCompact::fill_and_update_region(this, region_index);
   270     }
   272     size_t region_index = -1;
   273     // obj is a reference!!!
   274     while (region_stack()->pop_local(region_index)) {
   275       // It would be nice to assert about the type of objects we might
   276       // pop, but they can come from anywhere, unfortunately.
   277       PSParallelCompact::fill_and_update_region(this, region_index);
   278     }
   279   } while((region_stack()->size() != 0) ||
   280           (region_overflow_stack()->length() != 0));
   281 #endif
   283 #ifdef USE_RegionTaskQueueWithOverflow
   284   assert(region_stack()->is_empty(), "Sanity");
   285 #else
   286   assert(region_stack()->size() == 0, "Sanity");
   287   assert(region_overflow_stack()->length() == 0, "Sanity");
   288 #endif
   289 #else
   290   oop obj;
   291   while (obj = retrieve_for_scanning()) {
   292     obj->follow_contents(this);
   293   }
   294 #endif
   295 }
   297 #ifdef ASSERT
   298 bool ParCompactionManager::stacks_have_been_allocated() {
   299   return (revisit_klass_stack()->data_addr() != NULL);
   300 }
   301 #endif

mercurial