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/g1CollectorPolicy.cpp
          +++ new/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp
↓ open down ↓ 1892 lines elided ↑ open up ↑
1893 1893        if (_hrSorted->should_add(r) && !_g1h->is_old_gc_alloc_region(r)) {
1894 1894          _hrSorted->add_region(r);
1895 1895        }
1896 1896      }
1897 1897      return false;
1898 1898    }
1899 1899  };
1900 1900  
1901 1901  class ParKnownGarbageHRClosure: public HeapRegionClosure {
1902 1902    G1CollectedHeap* _g1h;
1903      -  CollectionSetChooser* _hrSorted;
1904      -  uint _marked_regions_added;
1905      -  size_t _reclaimable_bytes_added;
1906      -  uint _chunk_size;
1907      -  uint _cur_chunk_idx;
1908      -  uint _cur_chunk_end; // Cur chunk [_cur_chunk_idx, _cur_chunk_end)
1909      -
1910      -  void get_new_chunk() {
1911      -    _cur_chunk_idx = _hrSorted->claim_array_chunk(_chunk_size);
1912      -    _cur_chunk_end = _cur_chunk_idx + _chunk_size;
1913      -  }
1914      -  void add_region(HeapRegion* r) {
1915      -    if (_cur_chunk_idx == _cur_chunk_end) {
1916      -      get_new_chunk();
1917      -    }
1918      -    assert(_cur_chunk_idx < _cur_chunk_end, "postcondition");
1919      -    _hrSorted->set_region(_cur_chunk_idx, r);
1920      -    _marked_regions_added++;
1921      -    _reclaimable_bytes_added += r->reclaimable_bytes();
1922      -    _cur_chunk_idx++;
1923      -  }
     1903 +  CSetChooserParUpdater _cset_updater;
1924 1904  
1925 1905  public:
1926 1906    ParKnownGarbageHRClosure(CollectionSetChooser* hrSorted,
1927 1907                             uint chunk_size) :
1928      -      _g1h(G1CollectedHeap::heap()),
1929      -      _hrSorted(hrSorted), _chunk_size(chunk_size),
1930      -      _marked_regions_added(0), _reclaimable_bytes_added(0),
1931      -      _cur_chunk_idx(0), _cur_chunk_end(0) { }
     1908 +    _g1h(G1CollectedHeap::heap()),
     1909 +    _cset_updater(hrSorted, true /* parallel */, chunk_size) { }
1932 1910  
1933 1911    bool doHeapRegion(HeapRegion* r) {
1934 1912      // Do we have any marking information for this region?
1935 1913      if (r->is_marked()) {
1936 1914        // We will skip any region that's currently used as an old GC
1937 1915        // alloc region (we should not consider those for collection
1938 1916        // before we fill them up).
1939      -      if (_hrSorted->should_add(r) && !_g1h->is_old_gc_alloc_region(r)) {
1940      -        add_region(r);
     1917 +      if (_cset_updater.should_add(r) && !_g1h->is_old_gc_alloc_region(r)) {
     1918 +        _cset_updater.add_region(r);
1941 1919        }
1942 1920      }
1943 1921      return false;
1944 1922    }
1945      -  uint marked_regions_added() { return _marked_regions_added; }
1946      -  size_t reclaimable_bytes_added() { return _reclaimable_bytes_added; }
1947 1923  };
1948 1924  
1949 1925  class ParKnownGarbageTask: public AbstractGangTask {
1950 1926    CollectionSetChooser* _hrSorted;
1951 1927    uint _chunk_size;
1952 1928    G1CollectedHeap* _g1;
1953 1929  public:
1954 1930    ParKnownGarbageTask(CollectionSetChooser* hrSorted, uint chunk_size) :
1955 1931      AbstractGangTask("ParKnownGarbageTask"),
1956 1932      _hrSorted(hrSorted), _chunk_size(chunk_size),
1957 1933      _g1(G1CollectedHeap::heap()) { }
1958 1934  
1959 1935    void work(uint worker_id) {
1960 1936      ParKnownGarbageHRClosure parKnownGarbageCl(_hrSorted, _chunk_size);
1961 1937  
1962 1938      // Back to zero for the claim value.
1963 1939      _g1->heap_region_par_iterate_chunked(&parKnownGarbageCl, worker_id,
1964 1940                                           _g1->workers()->active_workers(),
1965 1941                                           HeapRegion::InitialClaimValue);
1966      -    uint regions_added = parKnownGarbageCl.marked_regions_added();
1967      -    size_t reclaimable_bytes_added =
1968      -                                   parKnownGarbageCl.reclaimable_bytes_added();
1969      -    _hrSorted->update_totals(regions_added, reclaimable_bytes_added);
1970 1942    }
1971 1943  };
1972 1944  
1973 1945  void
1974 1946  G1CollectorPolicy::record_concurrent_mark_cleanup_end(int no_of_gc_threads) {
1975 1947    _collectionSetChooser->clear();
1976 1948  
1977 1949    uint region_num = _g1->n_regions();
1978 1950    if (G1CollectedHeap::use_parallel_gc_threads()) {
1979 1951      const uint OverpartitionFactor = 4;
↓ open down ↓ 595 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX