1 /* 2 * Copyright (c) 2017, 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_G1CARDTABLE_HPP 26 #define SHARE_VM_GC_G1_G1CARDTABLE_HPP 27 28 #include "gc/g1/g1RegionToSpaceMapper.hpp" 29 #include "gc/shared/cardTable.hpp" 30 #include "oops/oopsHierarchy.hpp" 31 #include "utilities/macros.hpp" 32 33 class G1CardTable; 34 class G1RegionToSpaceMapper; 35 36 class G1CardTableChangedListener : public G1MappingChangedListener { 37 private: 38 G1CardTable* _card_table; 39 public: 40 G1CardTableChangedListener() : _card_table(NULL) { } 41 42 void set_card_table(G1CardTable* card_table) { _card_table = card_table; } 43 44 virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled); 45 }; 46 47 class G1CardTable: public CardTable { 48 friend class VMStructs; 49 friend class G1CardTableChangedListener; 50 G1CardTableChangedListener _listener; 51 52 enum G1CardValues { 53 g1_young_gen = CT_MR_BS_last_reserved << 1 54 }; 55 56 public: 57 G1CardTable(MemRegion whole_heap): CardTable(whole_heap, /* scanned concurrently */ true), _listener() { 58 _listener.set_card_table(this); 59 } 60 bool is_card_dirty(size_t card_index) { 61 return _byte_map[card_index] == dirty_card_val(); 62 } 63 64 static jbyte g1_young_card_val() { return g1_young_gen; } 65 66 /* 67 Claimed and deferred bits are used together in G1 during the evacuation 68 pause. These bits can have the following state transitions: 69 1. The claimed bit can be put over any other card state. Except that 70 the "dirty -> dirty and claimed" transition is checked for in 71 G1 code and is not used. 72 2. Deferred bit can be set only if the previous state of the card 73 was either clean or claimed. mark_card_deferred() is wait-free. 74 We do not care if the operation is be successful because if 75 it does not it will only result in duplicate entry in the update 76 buffer because of the "cache-miss". So it's not worth spinning. 77 */ 78 79 bool is_card_claimed(size_t card_index) { 80 jbyte val = _byte_map[card_index]; 81 return (val & (clean_card_mask_val() | claimed_card_val())) == claimed_card_val(); 82 } 83 84 inline void set_card_claimed(size_t card_index); 85 86 void verify_g1_young_region(MemRegion mr) PRODUCT_RETURN; 87 void g1_mark_as_young(const MemRegion& mr); 88 89 bool mark_card_deferred(size_t card_index); 90 91 bool is_card_deferred(size_t card_index) { 92 jbyte val = _byte_map[card_index]; 93 return (val & (clean_card_mask_val() | deferred_card_val())) == deferred_card_val(); 94 } 95 96 static size_t compute_size(size_t mem_region_size_in_words) { 97 size_t number_of_slots = (mem_region_size_in_words / card_size_in_words); 98 return ReservedSpace::allocation_align_size_up(number_of_slots); 99 } 100 101 // Returns how many bytes of the heap a single byte of the Card Table corresponds to. 102 static size_t heap_map_factor() { return card_size; } 103 104 void initialize() {} 105 void initialize(G1RegionToSpaceMapper* mapper); 106 107 virtual void resize_covered_region(MemRegion new_region) { ShouldNotReachHere(); } 108 109 virtual bool is_in_young(void* addr) const; 110 }; 111 112 #endif // SHARE_VM_GC_G1_G1CARDTABLE_HPP