< prev index next >

src/share/vm/gc/shared/preservedMarks.cpp

Print this page




   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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/parallel/gcTaskManager.hpp"
  27 #include "gc/shared/preservedMarks.inline.hpp"
  28 #include "gc/shared/workgroup.hpp"
  29 #include "memory/allocation.inline.hpp"
  30 #include "memory/resourceArea.hpp"
  31 





  32 void PreservedMarks::restore() {
  33   while (!_stack.is_empty()) {
  34     const OopAndMarkOop elem = _stack.pop();
  35     elem.set_mark();
  36   }
  37   assert_empty();
  38 }
  39 
  40 #ifndef PRODUCT
  41 void PreservedMarks::assert_empty() {
  42   assert(_stack.is_empty(), "stack expected to be empty, size = "SIZE_FORMAT,
  43          _stack.size());
  44   assert(_stack.cache_size() == 0,
  45          "stack expected to have no cached segments, cache size = "SIZE_FORMAT,
  46          _stack.cache_size());
  47 }
  48 #endif // ndef PRODUCT
  49 
  50 void RemoveForwardedPointerClosure::do_object(oop obj) {
  51   if (obj->is_forwarded()) {


  91   }
  92 
  93   ParRestoreTask(uint worker_num,
  94                  PreservedMarksSet* preserved_marks_set,
  95                  volatile size_t* total_size_addr)
  96       : AbstractGangTask("Parallel Preserved Mark Restoration"),
  97         _preserved_marks_set(preserved_marks_set),
  98         _total_size_addr(total_size_addr) {
  99     _sub_tasks.set_n_threads(worker_num);
 100     _sub_tasks.set_n_tasks(preserved_marks_set->num());
 101   }
 102 };
 103 
 104 void PreservedMarksSet::restore_internal(WorkGang* workers,
 105                                          volatile size_t* total_size_addr) {
 106   assert(workers != NULL, "pre-condition");
 107   ParRestoreTask task(workers->active_workers(), this, total_size_addr);
 108   workers->run_task(&task);
 109 }
 110 

 111 class ParRestoreGCTask : public GCTask {
 112 private:
 113   const uint _id;
 114   PreservedMarksSet* const _preserved_marks_set;
 115   volatile size_t* const _total_size_addr;
 116 
 117 public:
 118   virtual char* name() { return (char*) "preserved mark restoration task"; }
 119 
 120   virtual void do_it(GCTaskManager* manager, uint which) {
 121     PreservedMarks* const preserved_marks = _preserved_marks_set->get(_id);
 122     const size_t size = preserved_marks->size();
 123     preserved_marks->restore();
 124     // Only do the atomic add if the size is > 0.
 125     if (size > 0) {
 126       Atomic::add(size, _total_size_addr);
 127     }
 128   }
 129 
 130   ParRestoreGCTask(uint id,
 131                    PreservedMarksSet* preserved_marks_set,
 132                    volatile size_t* total_size_addr)
 133     : _id(id),
 134       _preserved_marks_set(preserved_marks_set),
 135       _total_size_addr(total_size_addr) { }
 136 };
 137 
 138 void PreservedMarksSet::restore_internal(GCTaskManager* gc_task_manager,
 139                                          volatile size_t* total_size_addr) {
 140   // GCTask / GCTaskQueue are ResourceObjs
 141   ResourceMark rm;
 142 
 143   GCTaskQueue* q = GCTaskQueue::create();
 144   for (uint i = 0; i < num(); i += 1) {
 145     q->enqueue(new ParRestoreGCTask(i, this, total_size_addr));
 146   }
 147   gc_task_manager->execute_and_wait(q);
 148 }

 149 
 150 void PreservedMarksSet::reclaim() {
 151   assert_empty();
 152 
 153   for (uint i = 0; i < _num; i += 1) {
 154     _stacks[i].~Padded<PreservedMarks>();
 155   }
 156 
 157   if (_in_c_heap) {
 158     FREE_C_HEAP_ARRAY(Padded<PreservedMarks>, _stacks);
 159   } else {
 160     // the array was resource-allocated, so nothing to do
 161   }
 162   _stacks = NULL;
 163   _num = 0;
 164 }
 165 
 166 #ifndef PRODUCT
 167 void PreservedMarksSet::assert_empty() {
 168   assert(_stacks != NULL && _num > 0, "should have been initialized");


   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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"

  26 #include "gc/shared/preservedMarks.inline.hpp"
  27 #include "gc/shared/workgroup.hpp"
  28 #include "memory/allocation.inline.hpp"
  29 #include "memory/resourceArea.hpp"
  30 
  31 #include "utilities/macros.hpp"
  32 #if INCLUDE_ALL_GCS
  33 #include "gc/parallel/gcTaskManager.hpp"
  34 #endif
  35 
  36 void PreservedMarks::restore() {
  37   while (!_stack.is_empty()) {
  38     const OopAndMarkOop elem = _stack.pop();
  39     elem.set_mark();
  40   }
  41   assert_empty();
  42 }
  43 
  44 #ifndef PRODUCT
  45 void PreservedMarks::assert_empty() {
  46   assert(_stack.is_empty(), "stack expected to be empty, size = "SIZE_FORMAT,
  47          _stack.size());
  48   assert(_stack.cache_size() == 0,
  49          "stack expected to have no cached segments, cache size = "SIZE_FORMAT,
  50          _stack.cache_size());
  51 }
  52 #endif // ndef PRODUCT
  53 
  54 void RemoveForwardedPointerClosure::do_object(oop obj) {
  55   if (obj->is_forwarded()) {


  95   }
  96 
  97   ParRestoreTask(uint worker_num,
  98                  PreservedMarksSet* preserved_marks_set,
  99                  volatile size_t* total_size_addr)
 100       : AbstractGangTask("Parallel Preserved Mark Restoration"),
 101         _preserved_marks_set(preserved_marks_set),
 102         _total_size_addr(total_size_addr) {
 103     _sub_tasks.set_n_threads(worker_num);
 104     _sub_tasks.set_n_tasks(preserved_marks_set->num());
 105   }
 106 };
 107 
 108 void PreservedMarksSet::restore_internal(WorkGang* workers,
 109                                          volatile size_t* total_size_addr) {
 110   assert(workers != NULL, "pre-condition");
 111   ParRestoreTask task(workers->active_workers(), this, total_size_addr);
 112   workers->run_task(&task);
 113 }
 114 
 115 #if INCLUDE_ALL_GCS
 116 class ParRestoreGCTask : public GCTask {
 117 private:
 118   const uint _id;
 119   PreservedMarksSet* const _preserved_marks_set;
 120   volatile size_t* const _total_size_addr;
 121 
 122 public:
 123   virtual char* name() { return (char*) "preserved mark restoration task"; }
 124 
 125   virtual void do_it(GCTaskManager* manager, uint which) {
 126     PreservedMarks* const preserved_marks = _preserved_marks_set->get(_id);
 127     const size_t size = preserved_marks->size();
 128     preserved_marks->restore();
 129     // Only do the atomic add if the size is > 0.
 130     if (size > 0) {
 131       Atomic::add(size, _total_size_addr);
 132     }
 133   }
 134 
 135   ParRestoreGCTask(uint id,
 136                    PreservedMarksSet* preserved_marks_set,
 137                    volatile size_t* total_size_addr)
 138     : _id(id),
 139       _preserved_marks_set(preserved_marks_set),
 140       _total_size_addr(total_size_addr) { }
 141 };
 142 
 143 void PreservedMarksSet::restore_internal(GCTaskManager* gc_task_manager,
 144                                          volatile size_t* total_size_addr) {
 145   // GCTask / GCTaskQueue are ResourceObjs
 146   ResourceMark rm;
 147 
 148   GCTaskQueue* q = GCTaskQueue::create();
 149   for (uint i = 0; i < num(); i += 1) {
 150     q->enqueue(new ParRestoreGCTask(i, this, total_size_addr));
 151   }
 152   gc_task_manager->execute_and_wait(q);
 153 }
 154 #endif
 155 
 156 void PreservedMarksSet::reclaim() {
 157   assert_empty();
 158 
 159   for (uint i = 0; i < _num; i += 1) {
 160     _stacks[i].~Padded<PreservedMarks>();
 161   }
 162 
 163   if (_in_c_heap) {
 164     FREE_C_HEAP_ARRAY(Padded<PreservedMarks>, _stacks);
 165   } else {
 166     // the array was resource-allocated, so nothing to do
 167   }
 168   _stacks = NULL;
 169   _num = 0;
 170 }
 171 
 172 #ifndef PRODUCT
 173 void PreservedMarksSet::assert_empty() {
 174   assert(_stacks != NULL && _num > 0, "should have been initialized");
< prev index next >