1 /*
   2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   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 #ifndef SHARE_VM_GC_G1_HEAPREGIONREMSET_INLINE_HPP
  26 #define SHARE_VM_GC_G1_HEAPREGIONREMSET_INLINE_HPP
  27 
  28 #include "gc/g1/heapRegion.inline.hpp"
  29 #include "gc/g1/heapRegionRemSet.hpp"
  30 #include "gc/g1/sparsePRT.hpp"
  31 #include "utilities/bitMap.inline.hpp"
  32 
  33 template <class Closure>
  34 inline void HeapRegionRemSet::iterate_prts(Closure& cl) {
  35   _other_regions.iterate(cl);
  36 }
  37 
  38 inline void PerRegionTable::add_card(CardIdx_t from_card_index) {
  39   if (_bm.par_set_bit(from_card_index)) {
  40     Atomic::inc(&_occupied);
  41   }
  42 }
  43 
  44 inline void PerRegionTable::add_reference(OopOrNarrowOopStar from) {
  45   // Must make this robust in case "from" is not in "_hr", because of
  46   // concurrency.
  47 
  48   HeapRegion* loc_hr = hr();
  49   // If the test below fails, then this table was reused concurrently
  50   // with this operation.  This is OK, since the old table was coarsened,
  51   // and adding a bit to the new table is never incorrect.
  52   if (loc_hr->is_in_reserved(from)) {
  53     CardIdx_t from_card = OtherRegionsTable::card_within_region(from, loc_hr);
  54     add_card(from_card);
  55   }
  56 }
  57 
  58 inline void PerRegionTable::init(HeapRegion* hr, bool clear_links_to_all_list) {
  59   if (clear_links_to_all_list) {
  60     set_next(NULL);
  61     set_prev(NULL);
  62   }
  63   _collision_list_next = NULL;
  64   _occupied = 0;
  65   _bm.clear();
  66   // Make sure that the bitmap clearing above has been finished before publishing
  67   // this PRT to concurrent threads.
  68   OrderAccess::release_store(&_hr, hr);
  69 }
  70 
  71 template <class Closure>
  72 void OtherRegionsTable::iterate(Closure& cl) {
  73   if (_n_coarse_entries > 0) {
  74     BitMap::idx_t cur = _coarse_map.get_next_one_offset(0);
  75     while (cur != _coarse_map.size()) {
  76       cl.next_coarse_prt((uint)cur);
  77       cur = _coarse_map.get_next_one_offset(cur + 1);
  78     }
  79   }
  80   {
  81     PerRegionTable* cur = _first_all_fine_prts;
  82     while (cur != NULL) {
  83       cl.next_fine_prt(cur->hr()->hrm_index(), cur->bm());
  84       cur = cur->next();
  85     }
  86   }
  87   {
  88     SparsePRTBucketIter iter(&_sparse_table);
  89     SparsePRTEntry* cur;
  90     while (iter.has_next(cur)) {
  91       cl.next_sparse_prt(cur->r_ind(), cur->cards(), cur->num_valid_cards());
  92     }
  93   }
  94 }
  95 
  96 #endif // SHARE_VM_GC_G1_HEAPREGIONREMSET_INLINE_HPP