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