src/hotspot/share/gc/g1/heapRegionRemSet.inline.hpp
author tschatzl
Wed, 17 Jul 2019 16:33:19 +0200
changeset 55722 5ee183a90e65
parent 55510 3e31a8beaae4
child 58552 906a9dd5d8e8
permissions -rw-r--r--
8227084: Add timing information for merge heap root preparation Reviewed-by: sangheki, kbarrett

/*
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

#ifndef SHARE_VM_GC_G1_HEAPREGIONREMSET_INLINE_HPP
#define SHARE_VM_GC_G1_HEAPREGIONREMSET_INLINE_HPP

#include "gc/g1/heapRegion.inline.hpp"
#include "gc/g1/heapRegionRemSet.hpp"
#include "gc/g1/sparsePRT.hpp"
#include "utilities/bitMap.inline.hpp"

template <class Closure>
inline void HeapRegionRemSet::iterate_prts(Closure& cl) {
  _other_regions.iterate(cl);
}

inline void PerRegionTable::add_card_work(CardIdx_t from_card, bool par) {
  if (!_bm.at(from_card)) {
    if (par) {
      if (_bm.par_set_bit(from_card)) {
        Atomic::inc(&_occupied);
      }
    } else {
      _bm.set_bit(from_card);
      _occupied++;
    }
  }
}

inline void PerRegionTable::add_reference_work(OopOrNarrowOopStar from, bool par) {
  // Must make this robust in case "from" is not in "_hr", because of
  // concurrency.

  HeapRegion* loc_hr = hr();
  // If the test below fails, then this table was reused concurrently
  // with this operation.  This is OK, since the old table was coarsened,
  // and adding a bit to the new table is never incorrect.
  if (loc_hr->is_in_reserved(from)) {
    CardIdx_t from_card = OtherRegionsTable::card_within_region(from, loc_hr);
    add_card_work(from_card, par);
  }
}

inline void PerRegionTable::add_card(CardIdx_t from_card_index) {
  add_card_work(from_card_index, /*parallel*/ true);
}

inline void PerRegionTable::seq_add_card(CardIdx_t from_card_index) {
  add_card_work(from_card_index, /*parallel*/ false);
}

inline void PerRegionTable::add_reference(OopOrNarrowOopStar from) {
  add_reference_work(from, /*parallel*/ true);
}

inline void PerRegionTable::seq_add_reference(OopOrNarrowOopStar from) {
  add_reference_work(from, /*parallel*/ false);
}

inline void PerRegionTable::init(HeapRegion* hr, bool clear_links_to_all_list) {
  if (clear_links_to_all_list) {
    set_next(NULL);
    set_prev(NULL);
  }
  _collision_list_next = NULL;
  _occupied = 0;
  _bm.clear();
  // Make sure that the bitmap clearing above has been finished before publishing
  // this PRT to concurrent threads.
  OrderAccess::release_store(&_hr, hr);
}

template <class Closure>
void OtherRegionsTable::iterate(Closure& cl) {
  if (_n_coarse_entries > 0) {
    BitMap::idx_t cur = _coarse_map.get_next_one_offset(0);
    while (cur != _coarse_map.size()) {
      cl.next_coarse_prt((uint)cur);
      cur = _coarse_map.get_next_one_offset(cur + 1);
    }
  }
  {
    PerRegionTable* cur = _first_all_fine_prts;
    while (cur != NULL) {
      cl.next_fine_prt(cur->hr()->hrm_index(), cur->bm());
      cur = cur->next();
    }
  }
  {
    SparsePRTBucketIter iter(&_sparse_table);
    SparsePRTEntry* cur;
    while (iter.has_next(cur)) {
      cl.next_sparse_prt(cur->r_ind(), cur->cards(), cur->num_valid_cards());
    }
  }
}

#endif // SHARE_VM_GC_G1_HEAPREGIONREMSET_INLINE_HPP