author | jwilhelm |
Thu, 03 Oct 2013 21:36:29 +0200 | |
changeset 20398 | b206c580c45f |
parent 19994 | ca520adcee02 |
child 24424 | 2658d7834c6e |
permissions | -rw-r--r-- |
17327 | 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 |
// Table to track the number of times a card has been refined. Once |
|
37 |
// a card has been refined a certain number of times, it is |
|
38 |
// considered 'hot' and its refinement is delayed by inserting the |
|
39 |
// card into the hot card cache. The card will then be refined when |
|
40 |
// it is evicted from the hot card cache, or when the hot card cache |
|
41 |
// is 'drained' during the next evacuation pause. |
|
42 |
||
43 |
class G1CardCounts: public CHeapObj<mtGC> { |
|
44 |
G1CollectedHeap* _g1h; |
|
45 |
||
46 |
// The table of counts |
|
47 |
jubyte* _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 |
// Returns true if the card counts table has been reserved. |
|
68 |
bool has_reserved_count_table() { return _card_counts != NULL; } |
|
69 |
||
70 |
// Returns true if the card counts table has been reserved and committed. |
|
71 |
bool has_count_table() { |
|
72 |
return has_reserved_count_table() && _committed_max_card_num > 0; |
|
73 |
} |
|
74 |
||
75 |
size_t ptr_2_card_num(const jbyte* card_ptr) { |
|
76 |
assert(card_ptr >= _ct_bot, |
|
19994
ca520adcee02
8024671: G1 generates assert error messages in product builds
shade
parents:
17394
diff
changeset
|
77 |
err_msg("Invalid card pointer: " |
17327 | 78 |
"card_ptr: " PTR_FORMAT ", " |
79 |
"_ct_bot: " PTR_FORMAT, |
|
80 |
card_ptr, _ct_bot)); |
|
81 |
size_t card_num = pointer_delta(card_ptr, _ct_bot, sizeof(jbyte)); |
|
19994
ca520adcee02
8024671: G1 generates assert error messages in product builds
shade
parents:
17394
diff
changeset
|
82 |
assert(card_num >= 0 && card_num < _committed_max_card_num, |
ca520adcee02
8024671: G1 generates assert error messages in product builds
shade
parents:
17394
diff
changeset
|
83 |
err_msg("card pointer out of range: " PTR_FORMAT, card_ptr)); |
17327 | 84 |
return card_num; |
85 |
} |
|
86 |
||
87 |
jbyte* card_num_2_ptr(size_t card_num) { |
|
19994
ca520adcee02
8024671: G1 generates assert error messages in product builds
shade
parents:
17394
diff
changeset
|
88 |
assert(card_num >= 0 && card_num < _committed_max_card_num, |
ca520adcee02
8024671: G1 generates assert error messages in product builds
shade
parents:
17394
diff
changeset
|
89 |
err_msg("card num out of range: "SIZE_FORMAT, card_num)); |
17327 | 90 |
return (jbyte*) (_ct_bot + card_num); |
91 |
} |
|
92 |
||
17394
156f30e1d09a
8014408: G1: crashes with assert assert(prev_committed_card_num == _committed_max_card_num) failed
johnc
parents:
17327
diff
changeset
|
93 |
// Helper routine. |
156f30e1d09a
8014408: G1: crashes with assert assert(prev_committed_card_num == _committed_max_card_num) failed
johnc
parents:
17327
diff
changeset
|
94 |
// Returns the number of cards that can be counted by the given committed |
156f30e1d09a
8014408: G1: crashes with assert assert(prev_committed_card_num == _committed_max_card_num) failed
johnc
parents:
17327
diff
changeset
|
95 |
// table size, with a maximum of the number of cards spanned by the max |
156f30e1d09a
8014408: G1: crashes with assert assert(prev_committed_card_num == _committed_max_card_num) failed
johnc
parents:
17327
diff
changeset
|
96 |
// capacity of the heap. |
156f30e1d09a
8014408: G1: crashes with assert assert(prev_committed_card_num == _committed_max_card_num) failed
johnc
parents:
17327
diff
changeset
|
97 |
size_t committed_to_card_num(size_t committed_size) { |
156f30e1d09a
8014408: G1: crashes with assert assert(prev_committed_card_num == _committed_max_card_num) failed
johnc
parents:
17327
diff
changeset
|
98 |
return MIN2(_reserved_max_card_num, committed_size / sizeof(jbyte)); |
156f30e1d09a
8014408: G1: crashes with assert assert(prev_committed_card_num == _committed_max_card_num) failed
johnc
parents:
17327
diff
changeset
|
99 |
} |
156f30e1d09a
8014408: G1: crashes with assert assert(prev_committed_card_num == _committed_max_card_num) failed
johnc
parents:
17327
diff
changeset
|
100 |
|
17327 | 101 |
// Clear the counts table for the given (exclusive) index range. |
102 |
void clear_range(size_t from_card_num, size_t to_card_num); |
|
103 |
||
104 |
public: |
|
105 |
G1CardCounts(G1CollectedHeap* g1h); |
|
106 |
~G1CardCounts(); |
|
107 |
||
108 |
void initialize(); |
|
109 |
||
110 |
// Resize the committed space for the card counts table in |
|
111 |
// response to a resize of the committed space for the heap. |
|
112 |
void resize(size_t heap_capacity); |
|
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 |
// Clear the entire card counts table during GC. |
|
126 |
// Updates the policy stats with the duration. |
|
127 |
void clear_all(); |
|
128 |
}; |
|
129 |
||
130 |
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1CARDCOUNTS_HPP |