1 /* 2 * Copyright (c) 2013, 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_IMPLEMENTATION_G1_G1CARDCOUNTS_HPP 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1CARDCOUNTS_HPP 27 28 #include "memory/allocation.hpp" 29 #include "runtime/virtualspace.hpp" 30 #include "utilities/globalDefinitions.hpp" 31 32 class CardTableModRefBS; 33 class G1CollectedHeap; 34 class HeapRegion; 35 36 class G1CardCounts: public CHeapObj<mtGC> { 37 // Table to track the number of times a card has been refined. 38 // Once a card has been refined a certain number of times, it 39 // is considered 'hot' and its refinement is delayed by inserting 40 // the card into the hot card cache. The card will then be refined 41 // when it is evicted from the hot card cache, or when the 42 // hot card cache is 'drained' during the next evacuation pause. 43 44 G1CollectedHeap* _g1h; 45 46 // The table of counts 47 jbyte* _card_counts; 48 49 // Max capacity of the reserved space for the counts table 50 size_t _reserved_max_card_num; 51 52 // Max capacity of the committed space for the counts table 53 size_t _committed_max_card_num; 54 55 // Size of committed space for the counts table 56 size_t _committed_size; 57 58 // CardTable bottom. 59 const jbyte* _ct_bot; 60 61 // Barrier set 62 CardTableModRefBS* _ct_bs; 63 64 // The virtual memory backing the counts table 65 VirtualSpace _card_counts_storage; 66 67 void check_card_num(size_t card_num, const char* msg) { 68 assert(card_num >= 0 && card_num < _committed_max_card_num, msg); 69 } 70 71 size_t ptr_2_card_num(jbyte* card_ptr) { 72 size_t card_num = (size_t) (card_ptr - _ct_bot); 73 check_card_num(card_num, 74 err_msg("card pointer out of range: "PTR_FORMAT, card_ptr)); 75 return card_num; 76 } 77 78 jbyte* card_num_2_ptr(size_t card_num) { 79 check_card_num(card_num, 80 err_msg("card num out of range: "SIZE_FORMAT, card_num)); 81 return (jbyte*) (_ct_bot + card_num); 82 } 83 84 // Clear the counts table for the given (exclusive) index range. 85 void clear_range(size_t from_card_num, size_t to_card_num); 86 87 // Returns the count of this card after incrementing it. 88 int add_card_count(jbyte* card_ptr); 89 90 public: 91 G1CardCounts(G1CollectedHeap* g1h); 92 ~G1CardCounts(); 93 94 void initialize(); 95 96 // Resize the committed space for the card counts table in 97 // response to a resize of the committed space for the heap. 98 void resize(size_t heap_capacity); 99 100 // Updates the refinment count for the given card. 101 // Returns true if the card is considered 'hot'; false otherwise. 102 bool is_hot(jbyte* card_ptr); 103 104 // Clears the card counts for the cards spanned by the region 105 void clear_region(HeapRegion* hr); 106 107 // Clear the entire card counts table during GC. 108 // Updates the policy stats with the duration. 109 void clear_all(); 110 }; 111 112 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1CARDCOUNTS_HPP