< prev index next >

src/share/vm/gc/g1/g1ConcurrentMark.inline.hpp

Print this page
rev 12666 : imported patch 8168467-use-taskentry-as-mark-stack-elem
rev 12667 : imported patch 8168467-kim-review


  80 
  81 inline void G1CMBitMap::clear(HeapWord* addr) {
  82   check_mark(addr);
  83   _bm.clear_bit(heapWordToOffset(addr));
  84 }
  85 
  86 inline bool G1CMBitMap::parMark(HeapWord* addr) {
  87   check_mark(addr);
  88   return _bm.par_set_bit(heapWordToOffset(addr));
  89 }
  90 
  91 #undef check_mark
  92 
  93 #ifndef PRODUCT
  94 template<typename Fn>
  95 inline void G1CMMarkStack::iterate(Fn fn) const {
  96   assert_at_safepoint(true);
  97 
  98   size_t num_chunks = 0;
  99 
 100   OopChunk* cur = _chunk_list;
 101   while (cur != NULL) {
 102     guarantee(num_chunks <= _chunks_in_chunk_list, "Found " SIZE_FORMAT " oop chunks which is more than there should be", num_chunks);
 103 
 104     for (size_t i = 0; i < EntriesPerChunk; ++i) {
 105       if (cur->data[i].is_null()) {
 106         break;
 107       }
 108       fn(cur->data[i]);
 109     }
 110     cur = cur->next;
 111     num_chunks++;
 112   }
 113 }
 114 #endif
 115 
 116 // It scans an object and visits its children.
 117 inline void G1CMTask::scan_object(G1TaskQueueEntry task_entry) { process_grey_object<true>(task_entry); }
 118 
 119 inline void G1CMTask::push(G1TaskQueueEntry task_entry) {
 120   assert(task_entry.is_array_slice() || _g1h->is_in_g1_reserved(task_entry.obj()), "invariant");
 121   assert(task_entry.is_array_slice() || !_g1h->is_on_master_free_list(
 122               _g1h->heap_region_containing(task_entry.obj())), "invariant");
 123   assert(task_entry.is_array_slice() || !_g1h->is_obj_ill(task_entry.obj()), "invariant");  // FIXME!!!
 124   assert(task_entry.is_array_slice() || _nextMarkBitMap->isMarked((HeapWord*)task_entry.obj()), "invariant");
 125 
 126   if (!_task_queue->push(task_entry)) {
 127     // The local task queue looks full. We need to push some entries
 128     // to the global stack.
 129     move_entries_to_global_stack();
 130 
 131     // this should succeed since, even if we overflow the global
 132     // stack, we should have definitely removed some entries from the
 133     // local queue. So, there must be space on it.
 134     bool success = _task_queue->push(task_entry);
 135     assert(success, "invariant");
 136   }
 137 }


 150 
 151     // Finger and region values are all NULL or all non-NULL.  We
 152     // use _finger to check since we immediately use its value.
 153     assert(_curr_region != NULL, "invariant");
 154     assert(_region_limit != NULL, "invariant");
 155     assert(_region_limit <= global_finger, "invariant");
 156 
 157     // True if obj is less than the local finger, or is between
 158     // the region limit and the global finger.
 159     if (objAddr < _finger) {
 160       return true;
 161     } else if (objAddr < _region_limit) {
 162       return false;
 163     } // Else check global finger.
 164   }
 165   // Check global finger.
 166   return objAddr < global_finger;
 167 }
 168 
 169 template<bool scan>
 170 inline void G1CMTask::process_grey_object(G1TaskQueueEntry task_entry) {
 171   assert(scan || (task_entry.is_oop() && task_entry.obj()->is_typeArray()), "Skipping scan of grey non-typeArray");
 172   assert(task_entry.is_array_slice() || _nextMarkBitMap->isMarked((HeapWord*)task_entry.obj()),
 173          "Any stolen object should be a slice or marked");
 174 
 175   if (scan) {
 176     if (task_entry.is_array_slice()) {
 177       _words_scanned += _objArray_processor.process_slice(task_entry.slice());
 178     } else {
 179       oop obj = task_entry.obj();
 180       if (G1CMObjArrayProcessor::should_be_sliced(obj)) {
 181         _words_scanned += _objArray_processor.process_obj(obj);
 182       } else {
 183         _words_scanned += obj->oop_iterate_size(_cm_oop_closure);;
 184       }
 185     }
 186   }
 187   check_limits();
 188 }
 189 
 190 inline size_t G1CMTask::scan_objArray(objArrayOop obj, MemRegion mr) {


 195 inline void G1CMTask::make_reference_grey(oop obj) {
 196   if (_cm->par_mark(obj)) {
 197     // No OrderAccess:store_load() is needed. It is implicit in the
 198     // CAS done in G1CMBitMap::parMark() call in the routine above.
 199     HeapWord* global_finger = _cm->finger();
 200 
 201     // We only need to push a newly grey object on the mark
 202     // stack if it is in a section of memory the mark bitmap
 203     // scan has already examined.  Mark bitmap scanning
 204     // maintains progress "fingers" for determining that.
 205     //
 206     // Notice that the global finger might be moving forward
 207     // concurrently. This is not a problem. In the worst case, we
 208     // mark the object while it is above the global finger and, by
 209     // the time we read the global finger, it has moved forward
 210     // past this object. In this case, the object will probably
 211     // be visited when a task is scanning the region and will also
 212     // be pushed on the stack. So, some duplicate work, but no
 213     // correctness problems.
 214     if (is_below_finger(obj, global_finger)) {

 215       if (obj->is_typeArray()) {
 216         // Immediately process arrays of primitive types, rather
 217         // than pushing on the mark stack.  This keeps us from
 218         // adding humongous objects to the mark stack that might
 219         // be reclaimed before the entry is processed - see
 220         // selection of candidates for eager reclaim of humongous
 221         // objects.  The cost of the additional type test is
 222         // mitigated by avoiding a trip through the mark stack,
 223         // by only doing a bookkeeping update and avoiding the
 224         // actual scan of the object - a typeArray contains no
 225         // references, and the metadata is built-in.
 226         process_grey_object<false>(obj);
 227       } else {
 228         push(obj);
 229       }
 230     }
 231   }
 232 }
 233 
 234 inline void G1CMTask::deal_with_reference(oop obj) {
 235   increment_refs_reached();
 236 
 237   HeapWord* objAddr = (HeapWord*) obj;
 238   assert(obj->is_oop_or_null(true /* ignore mark word */), "Expected an oop or NULL at " PTR_FORMAT, p2i(obj));
 239   if (_g1h->is_in_g1_reserved(objAddr)) {
 240     assert(obj != NULL, "null check is implicit");
 241     if (!_nextMarkBitMap->isMarked(objAddr)) {
 242       // Only get the containing region if the object is not marked on the
 243       // bitmap (otherwise, it's a waste of time since we won't do
 244       // anything with it).
 245       HeapRegion* hr = _g1h->heap_region_containing(obj);
 246       if (!hr->obj_allocated_since_next_marking(obj)) {
 247         make_reference_grey(obj);
 248       }




  80 
  81 inline void G1CMBitMap::clear(HeapWord* addr) {
  82   check_mark(addr);
  83   _bm.clear_bit(heapWordToOffset(addr));
  84 }
  85 
  86 inline bool G1CMBitMap::parMark(HeapWord* addr) {
  87   check_mark(addr);
  88   return _bm.par_set_bit(heapWordToOffset(addr));
  89 }
  90 
  91 #undef check_mark
  92 
  93 #ifndef PRODUCT
  94 template<typename Fn>
  95 inline void G1CMMarkStack::iterate(Fn fn) const {
  96   assert_at_safepoint(true);
  97 
  98   size_t num_chunks = 0;
  99 
 100   TaskQueueEntryChunk* cur = _chunk_list;
 101   while (cur != NULL) {
 102     guarantee(num_chunks <= _chunks_in_chunk_list, "Found " SIZE_FORMAT " oop chunks which is more than there should be", num_chunks);
 103 
 104     for (size_t i = 0; i < EntriesPerChunk; ++i) {
 105       if (cur->data[i].is_null()) {
 106         break;
 107       }
 108       fn(cur->data[i]);
 109     }
 110     cur = cur->next;
 111     num_chunks++;
 112   }
 113 }
 114 #endif
 115 
 116 // It scans an object and visits its children.
 117 inline void G1CMTask::scan_task_entry(G1TaskQueueEntry task_entry) { process_grey_task_entry<true>(task_entry); }
 118 
 119 inline void G1CMTask::push(G1TaskQueueEntry task_entry) {
 120   assert(task_entry.is_array_slice() || _g1h->is_in_g1_reserved(task_entry.obj()), "invariant");
 121   assert(task_entry.is_array_slice() || !_g1h->is_on_master_free_list(
 122               _g1h->heap_region_containing(task_entry.obj())), "invariant");
 123   assert(task_entry.is_array_slice() || !_g1h->is_obj_ill(task_entry.obj()), "invariant");  // FIXME!!!
 124   assert(task_entry.is_array_slice() || _nextMarkBitMap->isMarked((HeapWord*)task_entry.obj()), "invariant");
 125 
 126   if (!_task_queue->push(task_entry)) {
 127     // The local task queue looks full. We need to push some entries
 128     // to the global stack.
 129     move_entries_to_global_stack();
 130 
 131     // this should succeed since, even if we overflow the global
 132     // stack, we should have definitely removed some entries from the
 133     // local queue. So, there must be space on it.
 134     bool success = _task_queue->push(task_entry);
 135     assert(success, "invariant");
 136   }
 137 }


 150 
 151     // Finger and region values are all NULL or all non-NULL.  We
 152     // use _finger to check since we immediately use its value.
 153     assert(_curr_region != NULL, "invariant");
 154     assert(_region_limit != NULL, "invariant");
 155     assert(_region_limit <= global_finger, "invariant");
 156 
 157     // True if obj is less than the local finger, or is between
 158     // the region limit and the global finger.
 159     if (objAddr < _finger) {
 160       return true;
 161     } else if (objAddr < _region_limit) {
 162       return false;
 163     } // Else check global finger.
 164   }
 165   // Check global finger.
 166   return objAddr < global_finger;
 167 }
 168 
 169 template<bool scan>
 170 inline void G1CMTask::process_grey_task_entry(G1TaskQueueEntry task_entry) {
 171   assert(scan || (task_entry.is_oop() && task_entry.obj()->is_typeArray()), "Skipping scan of grey non-typeArray");
 172   assert(task_entry.is_array_slice() || _nextMarkBitMap->isMarked((HeapWord*)task_entry.obj()),
 173          "Any stolen object should be a slice or marked");
 174 
 175   if (scan) {
 176     if (task_entry.is_array_slice()) {
 177       _words_scanned += _objArray_processor.process_slice(task_entry.slice());
 178     } else {
 179       oop obj = task_entry.obj();
 180       if (G1CMObjArrayProcessor::should_be_sliced(obj)) {
 181         _words_scanned += _objArray_processor.process_obj(obj);
 182       } else {
 183         _words_scanned += obj->oop_iterate_size(_cm_oop_closure);;
 184       }
 185     }
 186   }
 187   check_limits();
 188 }
 189 
 190 inline size_t G1CMTask::scan_objArray(objArrayOop obj, MemRegion mr) {


 195 inline void G1CMTask::make_reference_grey(oop obj) {
 196   if (_cm->par_mark(obj)) {
 197     // No OrderAccess:store_load() is needed. It is implicit in the
 198     // CAS done in G1CMBitMap::parMark() call in the routine above.
 199     HeapWord* global_finger = _cm->finger();
 200 
 201     // We only need to push a newly grey object on the mark
 202     // stack if it is in a section of memory the mark bitmap
 203     // scan has already examined.  Mark bitmap scanning
 204     // maintains progress "fingers" for determining that.
 205     //
 206     // Notice that the global finger might be moving forward
 207     // concurrently. This is not a problem. In the worst case, we
 208     // mark the object while it is above the global finger and, by
 209     // the time we read the global finger, it has moved forward
 210     // past this object. In this case, the object will probably
 211     // be visited when a task is scanning the region and will also
 212     // be pushed on the stack. So, some duplicate work, but no
 213     // correctness problems.
 214     if (is_below_finger(obj, global_finger)) {
 215       G1TaskQueueEntry entry = G1TaskQueueEntry::from_oop(obj);
 216       if (obj->is_typeArray()) {
 217         // Immediately process arrays of primitive types, rather
 218         // than pushing on the mark stack.  This keeps us from
 219         // adding humongous objects to the mark stack that might
 220         // be reclaimed before the entry is processed - see
 221         // selection of candidates for eager reclaim of humongous
 222         // objects.  The cost of the additional type test is
 223         // mitigated by avoiding a trip through the mark stack,
 224         // by only doing a bookkeeping update and avoiding the
 225         // actual scan of the object - a typeArray contains no
 226         // references, and the metadata is built-in.
 227         process_grey_task_entry<false>(entry);
 228       } else {
 229         push(entry);
 230       }
 231     }
 232   }
 233 }
 234 
 235 inline void G1CMTask::deal_with_reference(oop obj) {
 236   increment_refs_reached();
 237 
 238   HeapWord* objAddr = (HeapWord*) obj;
 239   assert(obj->is_oop_or_null(true /* ignore mark word */), "Expected an oop or NULL at " PTR_FORMAT, p2i(obj));
 240   if (_g1h->is_in_g1_reserved(objAddr)) {
 241     assert(obj != NULL, "null check is implicit");
 242     if (!_nextMarkBitMap->isMarked(objAddr)) {
 243       // Only get the containing region if the object is not marked on the
 244       // bitmap (otherwise, it's a waste of time since we won't do
 245       // anything with it).
 246       HeapRegion* hr = _g1h->heap_region_containing(obj);
 247       if (!hr->obj_allocated_since_next_marking(obj)) {
 248         make_reference_grey(obj);
 249       }


< prev index next >