1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/g1/g1CardCounts.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,130 @@ 1.4 +/* 1.5 + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1CARDCOUNTS_HPP 1.29 +#define SHARE_VM_GC_IMPLEMENTATION_G1_G1CARDCOUNTS_HPP 1.30 + 1.31 +#include "memory/allocation.hpp" 1.32 +#include "runtime/virtualspace.hpp" 1.33 +#include "utilities/globalDefinitions.hpp" 1.34 + 1.35 +class CardTableModRefBS; 1.36 +class G1CollectedHeap; 1.37 +class HeapRegion; 1.38 + 1.39 +// Table to track the number of times a card has been refined. Once 1.40 +// a card has been refined a certain number of times, it is 1.41 +// considered 'hot' and its refinement is delayed by inserting the 1.42 +// card into the hot card cache. The card will then be refined when 1.43 +// it is evicted from the hot card cache, or when the hot card cache 1.44 +// is 'drained' during the next evacuation pause. 1.45 + 1.46 +class G1CardCounts: public CHeapObj<mtGC> { 1.47 + G1CollectedHeap* _g1h; 1.48 + 1.49 + // The table of counts 1.50 + jubyte* _card_counts; 1.51 + 1.52 + // Max capacity of the reserved space for the counts table 1.53 + size_t _reserved_max_card_num; 1.54 + 1.55 + // Max capacity of the committed space for the counts table 1.56 + size_t _committed_max_card_num; 1.57 + 1.58 + // Size of committed space for the counts table 1.59 + size_t _committed_size; 1.60 + 1.61 + // CardTable bottom. 1.62 + const jbyte* _ct_bot; 1.63 + 1.64 + // Barrier set 1.65 + CardTableModRefBS* _ct_bs; 1.66 + 1.67 + // The virtual memory backing the counts table 1.68 + VirtualSpace _card_counts_storage; 1.69 + 1.70 + // Returns true if the card counts table has been reserved. 1.71 + bool has_reserved_count_table() { return _card_counts != NULL; } 1.72 + 1.73 + // Returns true if the card counts table has been reserved and committed. 1.74 + bool has_count_table() { 1.75 + return has_reserved_count_table() && _committed_max_card_num > 0; 1.76 + } 1.77 + 1.78 + size_t ptr_2_card_num(const jbyte* card_ptr) { 1.79 + assert(card_ptr >= _ct_bot, 1.80 + err_msg("Invalid card pointer: " 1.81 + "card_ptr: " PTR_FORMAT ", " 1.82 + "_ct_bot: " PTR_FORMAT, 1.83 + p2i(card_ptr), p2i(_ct_bot))); 1.84 + size_t card_num = pointer_delta(card_ptr, _ct_bot, sizeof(jbyte)); 1.85 + assert(card_num >= 0 && card_num < _committed_max_card_num, 1.86 + err_msg("card pointer out of range: " PTR_FORMAT, p2i(card_ptr))); 1.87 + return card_num; 1.88 + } 1.89 + 1.90 + jbyte* card_num_2_ptr(size_t card_num) { 1.91 + assert(card_num >= 0 && card_num < _committed_max_card_num, 1.92 + err_msg("card num out of range: "SIZE_FORMAT, card_num)); 1.93 + return (jbyte*) (_ct_bot + card_num); 1.94 + } 1.95 + 1.96 + // Helper routine. 1.97 + // Returns the number of cards that can be counted by the given committed 1.98 + // table size, with a maximum of the number of cards spanned by the max 1.99 + // capacity of the heap. 1.100 + size_t committed_to_card_num(size_t committed_size) { 1.101 + return MIN2(_reserved_max_card_num, committed_size / sizeof(jbyte)); 1.102 + } 1.103 + 1.104 + // Clear the counts table for the given (exclusive) index range. 1.105 + void clear_range(size_t from_card_num, size_t to_card_num); 1.106 + 1.107 + public: 1.108 + G1CardCounts(G1CollectedHeap* g1h); 1.109 + ~G1CardCounts(); 1.110 + 1.111 + void initialize(); 1.112 + 1.113 + // Resize the committed space for the card counts table in 1.114 + // response to a resize of the committed space for the heap. 1.115 + void resize(size_t heap_capacity); 1.116 + 1.117 + // Increments the refinement count for the given card. 1.118 + // Returns the pre-increment count value. 1.119 + uint add_card_count(jbyte* card_ptr); 1.120 + 1.121 + // Returns true if the given count is high enough to be considered 1.122 + // 'hot'; false otherwise. 1.123 + bool is_hot(uint count); 1.124 + 1.125 + // Clears the card counts for the cards spanned by the region 1.126 + void clear_region(HeapRegion* hr); 1.127 + 1.128 + // Clear the entire card counts table during GC. 1.129 + // Updates the policy stats with the duration. 1.130 + void clear_all(); 1.131 +}; 1.132 + 1.133 +#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1CARDCOUNTS_HPP