Path: blob/master/src/hotspot/share/gc/g1/g1CardTable.inline.hpp
40957 views
/*1* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_GC_G1_G1CARDTABLE_INLINE_HPP25#define SHARE_GC_G1_G1CARDTABLE_INLINE_HPP2627#include "gc/g1/g1CardTable.hpp"2829#include "gc/g1/heapRegion.hpp"3031inline uint G1CardTable::region_idx_for(CardValue* p) {32size_t const card_idx = pointer_delta(p, _byte_map, sizeof(CardValue));33return (uint)(card_idx >> (HeapRegion::LogOfHRGrainBytes - card_shift));34}3536inline bool G1CardTable::mark_clean_as_dirty(CardValue* card) {37CardValue value = *card;38if (value == clean_card_val()) {39*card = dirty_card_val();40return true;41}42return false;43}4445inline size_t G1CardTable::mark_region_dirty(size_t start_card_index, size_t num_cards) {46assert(is_aligned(start_card_index, sizeof(size_t)), "Start card index must be aligned.");47assert(is_aligned(num_cards, sizeof(size_t)), "Number of cards to change must be evenly divisible.");4849size_t result = 0;5051size_t const num_chunks = num_cards / sizeof(size_t);5253size_t* cur_word = (size_t*)&_byte_map[start_card_index];54size_t* const end_word_map = cur_word + num_chunks;55while (cur_word < end_word_map) {56size_t value = *cur_word;57if (value == WordAllClean) {58*cur_word = WordAllDirty;59result += sizeof(value);60} else if (value == WordAllDirty) {61// do nothing.62} else {63// There is a mix of cards in there. Tread slowly.64CardValue* cur = (CardValue*)cur_word;65for (size_t i = 0; i < sizeof(size_t); i++) {66CardValue value = *cur;67if (value == clean_card_val()) {68*cur = dirty_card_val();69result++;70}71cur++;72}73}74cur_word++;75}7677return result;78}7980inline void G1CardTable::change_dirty_cards_to(size_t start_card_index, size_t num_cards, CardValue which) {81CardValue* start = &_byte_map[start_card_index];82CardValue* const end = start + num_cards;83while (start < end) {84CardValue value = *start;85assert(value == dirty_card_val(),86"Must have been dirty %d start " PTR_FORMAT " " PTR_FORMAT, value, p2i(start), p2i(end));87*start++ = which;88}89}9091#endif /* SHARE_GC_G1_G1CARDTABLE_INLINE_HPP */929394