47
48 // Table to track the number of times a card has been refined. Once
49 // a card has been refined a certain number of times, it is
50 // considered 'hot' and its refinement is delayed by inserting the
51 // card into the hot card cache. The card will then be refined when
52 // it is evicted from the hot card cache, or when the hot card cache
53 // is 'drained' during the next evacuation pause.
54
55 class G1CardCounts: public CHeapObj<mtGC> {
56 G1CardCountsMappingChangedListener _listener;
57
58 G1CollectedHeap* _g1h;
59
60 // The table of counts
61 jubyte* _card_counts;
62
63 // Max capacity of the reserved space for the counts table
64 size_t _reserved_max_card_num;
65
66 // CardTable bottom.
67 const jbyte* _ct_bot;
68
69 // Barrier set
70 CardTableModRefBS* _ct_bs;
71
72 // Returns true if the card counts table has been reserved.
73 bool has_reserved_count_table() { return _card_counts != NULL; }
74
75 // Returns true if the card counts table has been reserved and committed.
76 bool has_count_table() {
77 return has_reserved_count_table();
78 }
79
80 size_t ptr_2_card_num(const jbyte* card_ptr) {
81 assert(card_ptr >= _ct_bot,
82 "Invalid card pointer: "
83 "card_ptr: " PTR_FORMAT ", "
84 "_ct_bot: " PTR_FORMAT,
85 p2i(card_ptr), p2i(_ct_bot));
86 size_t card_num = pointer_delta(card_ptr, _ct_bot, sizeof(jbyte));
87 assert(card_num < _reserved_max_card_num,
88 "card pointer out of range: " PTR_FORMAT, p2i(card_ptr));
89 return card_num;
90 }
91
92 jbyte* card_num_2_ptr(size_t card_num) {
93 assert(card_num < _reserved_max_card_num,
94 "card num out of range: " SIZE_FORMAT, card_num);
95 return (jbyte*) (_ct_bot + card_num);
96 }
97
98 // Clear the counts table for the given (exclusive) index range.
99 void clear_range(size_t from_card_num, size_t to_card_num);
100
101 public:
102 G1CardCounts(G1CollectedHeap* g1h);
103
104 // Return the number of slots needed for a card counts table
105 // that covers mem_region_words words.
106 static size_t compute_size(size_t mem_region_size_in_words);
107
108 // Returns how many bytes of the heap a single byte of the card counts table
109 // corresponds to.
110 static size_t heap_map_factor();
111
112 void initialize(G1RegionToSpaceMapper* mapper);
113
114 // Increments the refinement count for the given card.
115 // Returns the pre-increment count value.
116 uint add_card_count(jbyte* card_ptr);
117
118 // Returns true if the given count is high enough to be considered
119 // 'hot'; false otherwise.
120 bool is_hot(uint count);
121
122 // Clears the card counts for the cards spanned by the region
123 void clear_region(HeapRegion* hr);
124
125 // Clears the card counts for the cards spanned by the MemRegion
126 void clear_range(MemRegion mr);
127
128 // Clear the entire card counts table during GC.
129 void clear_all();
130 };
131
132 #endif // SHARE_VM_GC_G1_G1CARDCOUNTS_HPP
|
47
48 // Table to track the number of times a card has been refined. Once
49 // a card has been refined a certain number of times, it is
50 // considered 'hot' and its refinement is delayed by inserting the
51 // card into the hot card cache. The card will then be refined when
52 // it is evicted from the hot card cache, or when the hot card cache
53 // is 'drained' during the next evacuation pause.
54
55 class G1CardCounts: public CHeapObj<mtGC> {
56 G1CardCountsMappingChangedListener _listener;
57
58 G1CollectedHeap* _g1h;
59
60 // The table of counts
61 jubyte* _card_counts;
62
63 // Max capacity of the reserved space for the counts table
64 size_t _reserved_max_card_num;
65
66 // CardTable bottom.
67 const volatile jbyte* _ct_bot;
68
69 // Barrier set
70 CardTableModRefBS* _ct_bs;
71
72 // Returns true if the card counts table has been reserved.
73 bool has_reserved_count_table() { return _card_counts != NULL; }
74
75 // Returns true if the card counts table has been reserved and committed.
76 bool has_count_table() {
77 return has_reserved_count_table();
78 }
79
80 size_t ptr_2_card_num(const volatile jbyte* card_ptr) {
81 assert(card_ptr >= _ct_bot,
82 "Invalid card pointer: "
83 "card_ptr: " PTR_FORMAT ", "
84 "_ct_bot: " PTR_FORMAT,
85 p2i((jbyte*)card_ptr), p2i((jbyte*)_ct_bot));
86 size_t card_num = pointer_delta((void*)card_ptr, (jbyte*)_ct_bot, sizeof(jbyte));
87 assert(card_num < _reserved_max_card_num,
88 "card pointer out of range: " PTR_FORMAT, p2i((jbyte*)card_ptr));
89 return card_num;
90 }
91
92 volatile jbyte* card_num_2_ptr(size_t card_num) {
93 assert(card_num < _reserved_max_card_num,
94 "card num out of range: " SIZE_FORMAT, card_num);
95 return (volatile jbyte*) (_ct_bot + card_num);
96 }
97
98 // Clear the counts table for the given (exclusive) index range.
99 void clear_range(size_t from_card_num, size_t to_card_num);
100
101 public:
102 G1CardCounts(G1CollectedHeap* g1h);
103
104 // Return the number of slots needed for a card counts table
105 // that covers mem_region_words words.
106 static size_t compute_size(size_t mem_region_size_in_words);
107
108 // Returns how many bytes of the heap a single byte of the card counts table
109 // corresponds to.
110 static size_t heap_map_factor();
111
112 void initialize(G1RegionToSpaceMapper* mapper);
113
114 // Increments the refinement count for the given card.
115 // Returns the pre-increment count value.
116 uint add_card_count(volatile jbyte* card_ptr);
117
118 // Returns true if the given count is high enough to be considered
119 // 'hot'; false otherwise.
120 bool is_hot(uint count);
121
122 // Clears the card counts for the cards spanned by the region
123 void clear_region(HeapRegion* hr);
124
125 // Clears the card counts for the cards spanned by the MemRegion
126 void clear_range(MemRegion mr);
127
128 // Clear the entire card counts table during GC.
129 void clear_all();
130 };
131
132 #endif // SHARE_VM_GC_G1_G1CARDCOUNTS_HPP
|