27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
28 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
29 #include "gc_implementation/g1/g1GCPhaseTimes.hpp"
30 #include "memory/cardTableModRefBS.hpp"
31 #include "services/memTracker.hpp"
32 #include "utilities/copy.hpp"
33
34 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
35
36 void G1CardCountsMappingChangedListener::on_commit(uint start_idx, size_t num_regions, bool zero_filled) {
37 if (zero_filled) {
38 return;
39 }
40 MemRegion mr(G1CollectedHeap::heap()->bottom_addr_for_region(start_idx), num_regions * HeapRegion::GrainWords);
41 _counts->clear_range(mr);
42 }
43
44 void G1CardCounts::clear_range(size_t from_card_num, size_t to_card_num) {
45 if (has_count_table()) {
46 assert(from_card_num < to_card_num,
47 err_msg("Wrong order? from: " SIZE_FORMAT ", to: "SIZE_FORMAT,
48 from_card_num, to_card_num));
49 Copy::fill_to_bytes(&_card_counts[from_card_num], (to_card_num - from_card_num));
50 }
51 }
52
53 G1CardCounts::G1CardCounts(G1CollectedHeap *g1h):
54 _listener(), _g1h(g1h), _card_counts(NULL), _reserved_max_card_num(0) {
55 _listener.set_cardcounts(this);
56 }
57
58 void G1CardCounts::initialize(G1RegionToSpaceMapper* mapper) {
59 assert(_g1h->max_capacity() > 0, "initialization order");
60 assert(_g1h->capacity() == 0, "initialization order");
61
62 if (G1ConcRSHotCardLimit > 0) {
63 // The max value we can store in the counts table is
64 // max_jubyte. Guarantee the value of the hot
65 // threshold limit is no more than this.
66 guarantee(G1ConcRSHotCardLimit <= max_jubyte, "sanity");
67
70
71 _card_counts = (jubyte*) mapper->reserved().start();
72 _reserved_max_card_num = mapper->reserved().byte_size();
73 mapper->set_mapping_changed_listener(&_listener);
74 }
75 }
76
77 uint G1CardCounts::add_card_count(jbyte* card_ptr) {
78 // Returns the number of times the card has been refined.
79 // If we failed to reserve/commit the counts table, return 0.
80 // If card_ptr is beyond the committed end of the counts table,
81 // return 0.
82 // Otherwise return the actual count.
83 // Unless G1ConcRSHotCardLimit has been set appropriately,
84 // returning 0 will result in the card being considered
85 // cold and will be refined immediately.
86 uint count = 0;
87 if (has_count_table()) {
88 size_t card_num = ptr_2_card_num(card_ptr);
89 assert(card_num < _reserved_max_card_num,
90 err_msg("Card "SIZE_FORMAT" outside of card counts table (max size "SIZE_FORMAT")",
91 card_num, _reserved_max_card_num));
92 count = (uint) _card_counts[card_num];
93 if (count < G1ConcRSHotCardLimit) {
94 _card_counts[card_num] =
95 (jubyte)(MIN2((uintx)(_card_counts[card_num] + 1), G1ConcRSHotCardLimit));
96 }
97 }
98 return count;
99 }
100
101 bool G1CardCounts::is_hot(uint count) {
102 return (count >= G1ConcRSHotCardLimit);
103 }
104
105 void G1CardCounts::clear_region(HeapRegion* hr) {
106 MemRegion mr(hr->bottom(), hr->end());
107 clear_range(mr);
108 }
109
110 void G1CardCounts::clear_range(MemRegion mr) {
|
27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
28 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
29 #include "gc_implementation/g1/g1GCPhaseTimes.hpp"
30 #include "memory/cardTableModRefBS.hpp"
31 #include "services/memTracker.hpp"
32 #include "utilities/copy.hpp"
33
34 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
35
36 void G1CardCountsMappingChangedListener::on_commit(uint start_idx, size_t num_regions, bool zero_filled) {
37 if (zero_filled) {
38 return;
39 }
40 MemRegion mr(G1CollectedHeap::heap()->bottom_addr_for_region(start_idx), num_regions * HeapRegion::GrainWords);
41 _counts->clear_range(mr);
42 }
43
44 void G1CardCounts::clear_range(size_t from_card_num, size_t to_card_num) {
45 if (has_count_table()) {
46 assert(from_card_num < to_card_num,
47 err_msg("Wrong order? from: " SIZE_FORMAT ", to: " SIZE_FORMAT,
48 from_card_num, to_card_num));
49 Copy::fill_to_bytes(&_card_counts[from_card_num], (to_card_num - from_card_num));
50 }
51 }
52
53 G1CardCounts::G1CardCounts(G1CollectedHeap *g1h):
54 _listener(), _g1h(g1h), _card_counts(NULL), _reserved_max_card_num(0) {
55 _listener.set_cardcounts(this);
56 }
57
58 void G1CardCounts::initialize(G1RegionToSpaceMapper* mapper) {
59 assert(_g1h->max_capacity() > 0, "initialization order");
60 assert(_g1h->capacity() == 0, "initialization order");
61
62 if (G1ConcRSHotCardLimit > 0) {
63 // The max value we can store in the counts table is
64 // max_jubyte. Guarantee the value of the hot
65 // threshold limit is no more than this.
66 guarantee(G1ConcRSHotCardLimit <= max_jubyte, "sanity");
67
70
71 _card_counts = (jubyte*) mapper->reserved().start();
72 _reserved_max_card_num = mapper->reserved().byte_size();
73 mapper->set_mapping_changed_listener(&_listener);
74 }
75 }
76
77 uint G1CardCounts::add_card_count(jbyte* card_ptr) {
78 // Returns the number of times the card has been refined.
79 // If we failed to reserve/commit the counts table, return 0.
80 // If card_ptr is beyond the committed end of the counts table,
81 // return 0.
82 // Otherwise return the actual count.
83 // Unless G1ConcRSHotCardLimit has been set appropriately,
84 // returning 0 will result in the card being considered
85 // cold and will be refined immediately.
86 uint count = 0;
87 if (has_count_table()) {
88 size_t card_num = ptr_2_card_num(card_ptr);
89 assert(card_num < _reserved_max_card_num,
90 err_msg("Card " SIZE_FORMAT " outside of card counts table (max size " SIZE_FORMAT ")",
91 card_num, _reserved_max_card_num));
92 count = (uint) _card_counts[card_num];
93 if (count < G1ConcRSHotCardLimit) {
94 _card_counts[card_num] =
95 (jubyte)(MIN2((uintx)(_card_counts[card_num] + 1), G1ConcRSHotCardLimit));
96 }
97 }
98 return count;
99 }
100
101 bool G1CardCounts::is_hot(uint count) {
102 return (count >= G1ConcRSHotCardLimit);
103 }
104
105 void G1CardCounts::clear_region(HeapRegion* hr) {
106 MemRegion mr(hr->bottom(), hr->end());
107 clear_range(mr);
108 }
109
110 void G1CardCounts::clear_range(MemRegion mr) {
|