< prev index next >

src/hotspot/share/gc/parallel/psCompactionManager.cpp

Print this page




  33 #include "gc/shared/taskqueue.inline.hpp"
  34 #include "logging/log.hpp"
  35 #include "memory/iterator.inline.hpp"
  36 #include "oops/access.inline.hpp"
  37 #include "oops/compressedOops.inline.hpp"
  38 #include "oops/instanceKlass.inline.hpp"
  39 #include "oops/instanceMirrorKlass.inline.hpp"
  40 #include "oops/objArrayKlass.inline.hpp"
  41 #include "oops/oop.inline.hpp"
  42 #include "runtime/atomic.hpp"
  43 
  44 PSOldGen*            ParCompactionManager::_old_gen = NULL;
  45 ParCompactionManager**  ParCompactionManager::_manager_array = NULL;
  46 
  47 OopTaskQueueSet*     ParCompactionManager::_stack_array = NULL;
  48 ParCompactionManager::ObjArrayTaskQueueSet*
  49   ParCompactionManager::_objarray_queues = NULL;
  50 ObjectStartArray*    ParCompactionManager::_start_array = NULL;
  51 ParMarkBitMap*       ParCompactionManager::_mark_bitmap = NULL;
  52 RegionTaskQueueSet*  ParCompactionManager::_region_array = NULL;


  53 
  54 ParCompactionManager::ParCompactionManager() :
  55     _action(CopyAndUpdate) {
  56 
  57   ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
  58 
  59   _old_gen = heap->old_gen();
  60   _start_array = old_gen()->start_array();
  61 
  62   marking_stack()->initialize();
  63   _objarray_stack.initialize();
  64   _region_stack.initialize();
  65 
  66   reset_bitmap_query_cache();
  67 }
  68 
  69 void ParCompactionManager::initialize(ParMarkBitMap* mbm) {
  70   assert(ParallelScavengeHeap::heap() != NULL,
  71     "Needed for initialization");
  72 


  83   guarantee(_objarray_queues != NULL, "Could not allocate objarray_queues");
  84   _region_array = new RegionTaskQueueSet(parallel_gc_threads);
  85   guarantee(_region_array != NULL, "Could not allocate region_array");
  86 
  87   // Create and register the ParCompactionManager(s) for the worker threads.
  88   for(uint i=0; i<parallel_gc_threads; i++) {
  89     _manager_array[i] = new ParCompactionManager();
  90     guarantee(_manager_array[i] != NULL, "Could not create ParCompactionManager");
  91     stack_array()->register_queue(i, _manager_array[i]->marking_stack());
  92     _objarray_queues->register_queue(i, &_manager_array[i]->_objarray_stack);
  93     region_array()->register_queue(i, _manager_array[i]->region_stack());
  94   }
  95 
  96   // The VMThread gets its own ParCompactionManager, which is not available
  97   // for work stealing.
  98   _manager_array[parallel_gc_threads] = new ParCompactionManager();
  99   guarantee(_manager_array[parallel_gc_threads] != NULL,
 100     "Could not create ParCompactionManager");
 101   assert(ParallelScavengeHeap::heap()->workers().total_workers() != 0,
 102     "Not initialized?");







 103 }
 104 
 105 void ParCompactionManager::reset_all_bitmap_query_caches() {
 106   uint parallel_gc_threads = ParallelScavengeHeap::heap()->workers().total_workers();
 107   for (uint i=0; i<=parallel_gc_threads; i++) {
 108     _manager_array[i]->reset_bitmap_query_cache();
 109   }
 110 }
 111 
 112 bool ParCompactionManager::should_update() {
 113   assert(action() != NotValid, "Action is not set");
 114   return (action() == ParCompactionManager::Update) ||
 115          (action() == ParCompactionManager::CopyAndUpdate) ||
 116          (action() == ParCompactionManager::UpdateAndCopy);
 117 }
 118 
 119 bool ParCompactionManager::should_copy() {
 120   assert(action() != NotValid, "Action is not set");
 121   return (action() == ParCompactionManager::Copy) ||
 122          (action() == ParCompactionManager::CopyAndUpdate) ||


 147       follow_array((objArrayOop)task.obj(), task.index());
 148     }
 149   } while (!marking_stacks_empty());
 150 
 151   assert(marking_stacks_empty(), "Sanity");
 152 }
 153 
 154 void ParCompactionManager::drain_region_stacks() {
 155   do {
 156     // Drain overflow stack first so other threads can steal.
 157     size_t region_index;
 158     while (region_stack()->pop_overflow(region_index)) {
 159       PSParallelCompact::fill_and_update_region(this, region_index);
 160     }
 161 
 162     while (region_stack()->pop_local(region_index)) {
 163       PSParallelCompact::fill_and_update_region(this, region_index);
 164     }
 165   } while (!region_stack()->is_empty());
 166 }































  33 #include "gc/shared/taskqueue.inline.hpp"
  34 #include "logging/log.hpp"
  35 #include "memory/iterator.inline.hpp"
  36 #include "oops/access.inline.hpp"
  37 #include "oops/compressedOops.inline.hpp"
  38 #include "oops/instanceKlass.inline.hpp"
  39 #include "oops/instanceMirrorKlass.inline.hpp"
  40 #include "oops/objArrayKlass.inline.hpp"
  41 #include "oops/oop.inline.hpp"
  42 #include "runtime/atomic.hpp"
  43 
  44 PSOldGen*            ParCompactionManager::_old_gen = NULL;
  45 ParCompactionManager**  ParCompactionManager::_manager_array = NULL;
  46 
  47 OopTaskQueueSet*     ParCompactionManager::_stack_array = NULL;
  48 ParCompactionManager::ObjArrayTaskQueueSet*
  49   ParCompactionManager::_objarray_queues = NULL;
  50 ObjectStartArray*    ParCompactionManager::_start_array = NULL;
  51 ParMarkBitMap*       ParCompactionManager::_mark_bitmap = NULL;
  52 RegionTaskQueueSet*  ParCompactionManager::_region_array = NULL;
  53 GrowableArray<size_t >* ParCompactionManager::_shadow_region_array = NULL;
  54 Monitor*                ParCompactionManager::_shadow_region_monitor = NULL;
  55 
  56 ParCompactionManager::ParCompactionManager() :
  57     _action(CopyAndUpdate) {
  58 
  59   ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
  60 
  61   _old_gen = heap->old_gen();
  62   _start_array = old_gen()->start_array();
  63 
  64   marking_stack()->initialize();
  65   _objarray_stack.initialize();
  66   _region_stack.initialize();
  67 
  68   reset_bitmap_query_cache();
  69 }
  70 
  71 void ParCompactionManager::initialize(ParMarkBitMap* mbm) {
  72   assert(ParallelScavengeHeap::heap() != NULL,
  73     "Needed for initialization");
  74 


  85   guarantee(_objarray_queues != NULL, "Could not allocate objarray_queues");
  86   _region_array = new RegionTaskQueueSet(parallel_gc_threads);
  87   guarantee(_region_array != NULL, "Could not allocate region_array");
  88 
  89   // Create and register the ParCompactionManager(s) for the worker threads.
  90   for(uint i=0; i<parallel_gc_threads; i++) {
  91     _manager_array[i] = new ParCompactionManager();
  92     guarantee(_manager_array[i] != NULL, "Could not create ParCompactionManager");
  93     stack_array()->register_queue(i, _manager_array[i]->marking_stack());
  94     _objarray_queues->register_queue(i, &_manager_array[i]->_objarray_stack);
  95     region_array()->register_queue(i, _manager_array[i]->region_stack());
  96   }
  97 
  98   // The VMThread gets its own ParCompactionManager, which is not available
  99   // for work stealing.
 100   _manager_array[parallel_gc_threads] = new ParCompactionManager();
 101   guarantee(_manager_array[parallel_gc_threads] != NULL,
 102     "Could not create ParCompactionManager");
 103   assert(ParallelScavengeHeap::heap()->workers().total_workers() != 0,
 104     "Not initialized?");
 105 
 106   _shadow_region_array = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<size_t >(10, true);
 107   guarantee(_shadow_region_array != NULL, "Could not allocate shadow_region_array");
 108 
 109   _shadow_region_monitor = new Monitor(Mutex::barrier, "CompactionManager monitor",
 110                                        Mutex::_allow_vm_block_flag, Monitor::_safepoint_check_never);
 111   guarantee(_shadow_region_monitor != NULL, "Could not allocate shadow_region_monitor");
 112 }
 113 
 114 void ParCompactionManager::reset_all_bitmap_query_caches() {
 115   uint parallel_gc_threads = ParallelScavengeHeap::heap()->workers().total_workers();
 116   for (uint i=0; i<=parallel_gc_threads; i++) {
 117     _manager_array[i]->reset_bitmap_query_cache();
 118   }
 119 }
 120 
 121 bool ParCompactionManager::should_update() {
 122   assert(action() != NotValid, "Action is not set");
 123   return (action() == ParCompactionManager::Update) ||
 124          (action() == ParCompactionManager::CopyAndUpdate) ||
 125          (action() == ParCompactionManager::UpdateAndCopy);
 126 }
 127 
 128 bool ParCompactionManager::should_copy() {
 129   assert(action() != NotValid, "Action is not set");
 130   return (action() == ParCompactionManager::Copy) ||
 131          (action() == ParCompactionManager::CopyAndUpdate) ||


 156       follow_array((objArrayOop)task.obj(), task.index());
 157     }
 158   } while (!marking_stacks_empty());
 159 
 160   assert(marking_stacks_empty(), "Sanity");
 161 }
 162 
 163 void ParCompactionManager::drain_region_stacks() {
 164   do {
 165     // Drain overflow stack first so other threads can steal.
 166     size_t region_index;
 167     while (region_stack()->pop_overflow(region_index)) {
 168       PSParallelCompact::fill_and_update_region(this, region_index);
 169     }
 170 
 171     while (region_stack()->pop_local(region_index)) {
 172       PSParallelCompact::fill_and_update_region(this, region_index);
 173     }
 174   } while (!region_stack()->is_empty());
 175 }
 176 
 177 size_t ParCompactionManager::acquire_shadow_region(PSParallelCompact::RegionData* region_ptr) {
 178   while (true) {
 179     MutexLocker ml(_shadow_region_monitor, Mutex::_no_safepoint_check_flag);
 180     if (_shadow_region_array->is_empty()) {
 181       // The corresponding heap region may be available now,
 182       // so we don't need to acquire a shadow region anymore,
 183       // and we return 0 to indicate this case
 184       if (region_ptr->claimed()) {
 185         return 0;
 186       }
 187     } else {
 188       return _shadow_region_array->pop();
 189     }
 190   }
 191 }
 192 
 193 void ParCompactionManager::release_shadow_region(size_t shadow_region) {
 194   MutexLocker ml(_shadow_region_monitor, Mutex::_no_safepoint_check_flag);
 195   _shadow_region_array->append(shadow_region);
 196 }
 197 
 198 void ParCompactionManager::enqueue_shadow_region(size_t shadow_region) {
 199   _shadow_region_array->append(shadow_region);
 200 }
 201 
 202 void ParCompactionManager::dequeue_shadow_region() {
 203   _shadow_region_array->clear();
 204 }
< prev index next >