50 public:
51 enum {
52 // Selection of the values were driven to micro-optimize the encoding and
53 // frequency of the checks.
54 // The most common check is whether the region is in the collection set or not.
55 // This encoding allows us to use an != 0 check which in some architectures
56 // (x86*) can be encoded slightly more efficently than a normal comparison
57 // against zero.
58 // The same situation occurs when checking whether the region is humongous
59 // or not, which is encoded by values < 0.
60 // The other values are simply encoded in increasing generation order, which
61 // makes getting the next generation fast by a simple increment.
62 Humongous = -1, // The region is humongous - note that actually any value < 0 would be possible here.
63 NotInCSet = 0, // The region is not in the collection set.
64 Young = 1, // The region is in the collection set and a young region.
65 Old = 2, // The region is in the collection set and an old region.
66 Num
67 };
68
69 InCSetState(in_cset_state_t value = NotInCSet) : _value(value) {
70 assert(is_valid(), err_msg("Invalid state %d", _value));
71 }
72
73 in_cset_state_t value() const { return _value; }
74
75 void set_old() { _value = Old; }
76
77 bool is_in_cset_or_humongous() const { return _value != NotInCSet; }
78 bool is_in_cset() const { return _value > NotInCSet; }
79 bool is_humongous() const { return _value < NotInCSet; }
80 bool is_young() const { return _value == Young; }
81 bool is_old() const { return _value == Old; }
82
83 #ifdef ASSERT
84 bool is_default() const { return !is_in_cset_or_humongous(); }
85 bool is_valid() const { return (_value >= Humongous) && (_value < Num); }
86 bool is_valid_gen() const { return (_value >= Young && _value <= Old); }
87 #endif
88 };
89
90 // Instances of this class are used for quick tests on whether a reference points
91 // into the collection set and into which generation or is a humongous object
92 //
93 // Each of the array's elements indicates whether the corresponding region is in
94 // the collection set and if so in which generation, or a humongous region.
95 //
96 // We use this to speed up reference processing during young collection and
97 // quickly reclaim humongous objects. For the latter, by making a humongous region
98 // succeed this test, we sort-of add it to the collection set. During the reference
99 // iteration closures, when we see a humongous region, we then simply mark it as
100 // referenced, i.e. live.
101 class G1InCSetStateFastTestBiasedMappedArray : public G1BiasedMappedArray<InCSetState> {
102 protected:
103 InCSetState default_value() const { return InCSetState::NotInCSet; }
104 public:
105 void set_humongous(uintptr_t index) {
106 assert(get_by_index(index).is_default(),
107 err_msg("State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value()));
108 set_by_index(index, InCSetState::Humongous);
109 }
110
111 void clear_humongous(uintptr_t index) {
112 set_by_index(index, InCSetState::NotInCSet);
113 }
114
115 void set_in_young(uintptr_t index) {
116 assert(get_by_index(index).is_default(),
117 err_msg("State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value()));
118 set_by_index(index, InCSetState::Young);
119 }
120
121 void set_in_old(uintptr_t index) {
122 assert(get_by_index(index).is_default(),
123 err_msg("State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value()));
124 set_by_index(index, InCSetState::Old);
125 }
126
127 bool is_in_cset_or_humongous(HeapWord* addr) const { return at(addr).is_in_cset_or_humongous(); }
128 bool is_in_cset(HeapWord* addr) const { return at(addr).is_in_cset(); }
129 bool is_in_cset(const HeapRegion* hr) const { return get_by_index(hr->hrm_index()).is_in_cset(); }
130 InCSetState at(HeapWord* addr) const { return get_by_address(addr); }
131 void clear() { G1BiasedMappedArray<InCSetState>::clear(); }
132 void clear(const HeapRegion* hr) { return set_by_index(hr->hrm_index(), InCSetState::NotInCSet); }
133 };
134
135 #endif // SHARE_VM_GC_G1_G1INCSETSTATE_HPP
|
50 public:
51 enum {
52 // Selection of the values were driven to micro-optimize the encoding and
53 // frequency of the checks.
54 // The most common check is whether the region is in the collection set or not.
55 // This encoding allows us to use an != 0 check which in some architectures
56 // (x86*) can be encoded slightly more efficently than a normal comparison
57 // against zero.
58 // The same situation occurs when checking whether the region is humongous
59 // or not, which is encoded by values < 0.
60 // The other values are simply encoded in increasing generation order, which
61 // makes getting the next generation fast by a simple increment.
62 Humongous = -1, // The region is humongous - note that actually any value < 0 would be possible here.
63 NotInCSet = 0, // The region is not in the collection set.
64 Young = 1, // The region is in the collection set and a young region.
65 Old = 2, // The region is in the collection set and an old region.
66 Num
67 };
68
69 InCSetState(in_cset_state_t value = NotInCSet) : _value(value) {
70 assert(is_valid(), "Invalid state %d", _value);
71 }
72
73 in_cset_state_t value() const { return _value; }
74
75 void set_old() { _value = Old; }
76
77 bool is_in_cset_or_humongous() const { return _value != NotInCSet; }
78 bool is_in_cset() const { return _value > NotInCSet; }
79 bool is_humongous() const { return _value < NotInCSet; }
80 bool is_young() const { return _value == Young; }
81 bool is_old() const { return _value == Old; }
82
83 #ifdef ASSERT
84 bool is_default() const { return !is_in_cset_or_humongous(); }
85 bool is_valid() const { return (_value >= Humongous) && (_value < Num); }
86 bool is_valid_gen() const { return (_value >= Young && _value <= Old); }
87 #endif
88 };
89
90 // Instances of this class are used for quick tests on whether a reference points
91 // into the collection set and into which generation or is a humongous object
92 //
93 // Each of the array's elements indicates whether the corresponding region is in
94 // the collection set and if so in which generation, or a humongous region.
95 //
96 // We use this to speed up reference processing during young collection and
97 // quickly reclaim humongous objects. For the latter, by making a humongous region
98 // succeed this test, we sort-of add it to the collection set. During the reference
99 // iteration closures, when we see a humongous region, we then simply mark it as
100 // referenced, i.e. live.
101 class G1InCSetStateFastTestBiasedMappedArray : public G1BiasedMappedArray<InCSetState> {
102 protected:
103 InCSetState default_value() const { return InCSetState::NotInCSet; }
104 public:
105 void set_humongous(uintptr_t index) {
106 assert(get_by_index(index).is_default(),
107 "State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value());
108 set_by_index(index, InCSetState::Humongous);
109 }
110
111 void clear_humongous(uintptr_t index) {
112 set_by_index(index, InCSetState::NotInCSet);
113 }
114
115 void set_in_young(uintptr_t index) {
116 assert(get_by_index(index).is_default(),
117 "State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value());
118 set_by_index(index, InCSetState::Young);
119 }
120
121 void set_in_old(uintptr_t index) {
122 assert(get_by_index(index).is_default(),
123 "State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value());
124 set_by_index(index, InCSetState::Old);
125 }
126
127 bool is_in_cset_or_humongous(HeapWord* addr) const { return at(addr).is_in_cset_or_humongous(); }
128 bool is_in_cset(HeapWord* addr) const { return at(addr).is_in_cset(); }
129 bool is_in_cset(const HeapRegion* hr) const { return get_by_index(hr->hrm_index()).is_in_cset(); }
130 InCSetState at(HeapWord* addr) const { return get_by_address(addr); }
131 void clear() { G1BiasedMappedArray<InCSetState>::clear(); }
132 void clear(const HeapRegion* hr) { return set_by_index(hr->hrm_index(), InCSetState::NotInCSet); }
133 };
134
135 #endif // SHARE_VM_GC_G1_G1INCSETSTATE_HPP
|