1 /* 2 * Copyright (c) 2001, 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_GC_G1_G1CARDTABLE_INLINE_HPP 26 #define SHARE_GC_G1_G1CARDTABLE_INLINE_HPP 27 28 #include "gc/g1/g1CardTable.hpp" 29 #include "gc/g1/heapRegion.hpp" 30 31 inline uint G1CardTable::region_idx_for(CardValue* p) { 32 size_t const card_idx = pointer_delta(p, _byte_map, sizeof(CardValue)); 33 return (uint)(card_idx >> (HeapRegion::LogOfHRGrainBytes - card_shift)); 34 } 35 36 inline void G1CardTable::mark_clean_as_dirty(size_t card_index) { 37 CardValue value = _byte_map[card_index]; 38 if (value == clean_card_val()) { 39 _byte_map[card_index] = dirty_card_val(); 40 } 41 } 42 43 inline void G1CardTable::mark_region_dirty(size_t start_card_index, size_t num_cards) { 44 assert(is_aligned(start_card_index, sizeof(size_t)), "Start card index must be aligned."); 45 assert(is_aligned(num_cards, sizeof(size_t)), "Number of cards to change must be evenly divisible."); 46 47 size_t const num_chunks = num_cards / sizeof(size_t); 48 49 size_t* cur_word = (size_t*)&_byte_map[start_card_index]; 50 size_t* const end_word_map = cur_word + num_chunks; 51 while (cur_word < end_word_map) { 52 size_t value = *cur_word; 53 if (value == WordAllClean) { 54 *cur_word = WordAllDirty; 55 } else if (value == WordAllDirty) { 56 // do nothing. 57 } else { 58 // There is a mix of cards in there. Tread slowly. 59 CardValue* cur = (CardValue*)cur_word; 60 for (size_t i = 0; i < sizeof(size_t); i++) { 61 CardValue value = *cur; 62 if (value == clean_card_val()) { 63 *cur = dirty_card_val(); 64 } 65 cur++; 66 } 67 } 68 cur_word++; 69 } 70 } 71 72 inline void G1CardTable::mark_as_scanned(size_t start_card_index, size_t num_cards) { 73 CardValue* start = &_byte_map[start_card_index]; 74 CardValue* const end = start + num_cards; 75 while (start < end) { 76 CardValue value = *start; 77 assert(value == dirty_card_val(), 78 "Must have been dirty %d start " PTR_FORMAT " " PTR_FORMAT, value, p2i(start), p2i(end)); 79 *start++ = g1_card_already_scanned; 80 } 81 } 82 83 #endif /* SHARE_GC_G1_G1CARDTABLE_INLINE_HPP */