Print this page
rev 3463 : 7114678: G1: various small fixes, code cleanup, and refactoring
Summary: Various cleanups as a prelude to introducing iterators for HeapRegions.
Reviewed-by: johnc
Contributed-by: tonyp

Split Close
Expand all
Collapse all
          --- old/src/share/vm/gc_implementation/g1/collectionSetChooser.hpp
          +++ new/src/share/vm/gc_implementation/g1/collectionSetChooser.hpp
↓ open down ↓ 145 lines elided ↑ open up ↑
 146  146  
 147  147    // Return the reclaimable bytes that remain to be collected on
 148  148    // all the candidate regions in the CSet chooser.
 149  149    size_t remaining_reclaimable_bytes() { return _remaining_reclaimable_bytes; }
 150  150  
 151  151    // Returns true if the used portion of "_regions" is properly
 152  152    // sorted, otherwise asserts false.
 153  153    void verify() PRODUCT_RETURN;
 154  154  };
 155  155  
      156 +class CSetChooserParUpdater : public StackObj {
      157 +private:
      158 +  CollectionSetChooser* _chooser;
      159 +  bool _parallel;
      160 +  uint _chunk_size;
      161 +  uint _cur_chunk_idx;
      162 +  uint _cur_chunk_end;
      163 +  uint _regions_added;
      164 +  size_t _reclaimable_bytes_added;
      165 +
      166 +public:
      167 +  CSetChooserParUpdater(CollectionSetChooser* chooser,
      168 +                        bool parallel, uint chunk_size) :
      169 +    _chooser(chooser), _parallel(parallel), _chunk_size(chunk_size),
      170 +    _cur_chunk_idx(0), _cur_chunk_end(0),
      171 +    _regions_added(0), _reclaimable_bytes_added(0) { }
      172 +
      173 +  ~CSetChooserParUpdater() {
      174 +    if (_parallel && _regions_added > 0) {
      175 +      _chooser->update_totals(_regions_added, _reclaimable_bytes_added);
      176 +    }
      177 +  }
      178 +
      179 +  void add_region(HeapRegion* hr) {
      180 +    if (_parallel) {
      181 +      if (_cur_chunk_idx == _cur_chunk_end) {
      182 +        _cur_chunk_idx = _chooser->claim_array_chunk(_chunk_size);
      183 +        _cur_chunk_end = _cur_chunk_idx + _chunk_size;
      184 +      }
      185 +      assert(_cur_chunk_idx < _cur_chunk_end, "invariant");
      186 +      _chooser->set_region(_cur_chunk_idx, hr);
      187 +      _cur_chunk_idx += 1;
      188 +    } else {
      189 +      _chooser->add_region(hr);
      190 +    }
      191 +    _regions_added += 1;
      192 +    _reclaimable_bytes_added += hr->reclaimable_bytes();
      193 +  }
      194 +
      195 +  bool should_add(HeapRegion* hr) { return _chooser->should_add(hr); }
      196 +};
      197 +
 156  198  #endif // SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
      199 +
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX