38 // This degrades performance significantly (>10%) on that platform.
39 // Other tested ABIs do not seem to have this problem, and actually tend to
40 // favor smaller types, so we use the smallest usable type there.
41 #ifdef SPARC
42 #define CSETSTATE_FORMAT INTPTR_FORMAT
43 typedef intptr_t in_cset_state_t;
44 #else
45 #define CSETSTATE_FORMAT "%d"
46 typedef int8_t in_cset_state_t;
47 #endif
48 private:
49 in_cset_state_t _value;
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.
56 // The other values are simply encoded in increasing generation order, which
57 // makes getting the next generation fast by a simple increment.
58 Humongous = -1, // The region is humongous
59 NotInCSet = 0, // The region is not in the collection set.
60 Young = 1, // The region is in the collection set and a young region.
61 Old = 2, // The region is in the collection set and an old region.
62 Num
63 };
64
65 InCSetState(in_cset_state_t value = NotInCSet) : _value(value) {
66 assert(is_valid(), "Invalid state %d", _value);
67 }
68
69 in_cset_state_t value() const { return _value; }
70
71 void set_old() { _value = Old; }
72
73 bool is_in_cset_or_humongous() const { return is_in_cset() || is_humongous(); }
74 bool is_in_cset() const { return _value > NotInCSet; }
75
76 bool is_humongous() const { return _value == Humongous; }
77 bool is_young() const { return _value == Young; }
78 bool is_old() const { return _value == Old; }
79
80 #ifdef ASSERT
81 bool is_default() const { return !is_in_cset_or_humongous(); }
82 bool is_valid() const { return (_value >= Humongous) && (_value < Num); }
83 bool is_valid_gen() const { return (_value >= Young && _value <= Old); }
84 #endif
85 };
86
87 // Instances of this class are used for quick tests on whether a reference points
88 // into the collection set and into which generation or is a humongous object
89 //
90 // Each of the array's elements indicates whether the corresponding region is in
91 // the collection set and if so in which generation, or a humongous region.
92 //
93 // We use this to speed up reference processing during young collection and
94 // quickly reclaim humongous objects. For the latter, by making a humongous region
95 // succeed this test, we sort-of add it to the collection set. During the reference
96 // iteration closures, when we see a humongous region, we then simply mark it as
97 // referenced, i.e. live.
98 class G1InCSetStateFastTestBiasedMappedArray : public G1BiasedMappedArray<InCSetState> {
99 protected:
100 InCSetState default_value() const { return InCSetState::NotInCSet; }
101 public:
102 void set_humongous(uintptr_t index) {
103 assert(get_by_index(index).is_default(),
104 "State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value());
105 set_by_index(index, InCSetState::Humongous);
106 }
107
108 void clear_humongous(uintptr_t index) {
109 set_by_index(index, InCSetState::NotInCSet);
110 }
111
112 void set_in_young(uintptr_t index) {
113 assert(get_by_index(index).is_default(),
114 "State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value());
115 set_by_index(index, InCSetState::Young);
116 }
117
118 void set_in_old(uintptr_t index) {
119 assert(get_by_index(index).is_default(),
120 "State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value());
121 set_by_index(index, InCSetState::Old);
122 }
123
124 bool is_in_cset_or_humongous(HeapWord* addr) const { return at(addr).is_in_cset_or_humongous(); }
125 bool is_in_cset(HeapWord* addr) const { return at(addr).is_in_cset(); }
|
38 // This degrades performance significantly (>10%) on that platform.
39 // Other tested ABIs do not seem to have this problem, and actually tend to
40 // favor smaller types, so we use the smallest usable type there.
41 #ifdef SPARC
42 #define CSETSTATE_FORMAT INTPTR_FORMAT
43 typedef intptr_t in_cset_state_t;
44 #else
45 #define CSETSTATE_FORMAT "%d"
46 typedef int8_t in_cset_state_t;
47 #endif
48 private:
49 in_cset_state_t _value;
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.
56 // The other values are simply encoded in increasing generation order, which
57 // makes getting the next generation fast by a simple increment.
58 Ext = -2, // Extension point
59 Humongous = -1, // The region is humongous
60 NotInCSet = 0, // The region is not in the collection set.
61 Young = 1, // The region is in the collection set and a young region.
62 Old = 2, // The region is in the collection set and an old region.
63 Num
64 };
65
66 InCSetState(in_cset_state_t value = NotInCSet) : _value(value) {
67 assert(is_valid(), "Invalid state %d", _value);
68 }
69
70 in_cset_state_t value() const { return _value; }
71
72 void set_old() { _value = Old; }
73
74 bool is_in_cset_or_humongous() const { return is_in_cset() || is_humongous(); }
75 bool is_in_cset() const { return _value > NotInCSet; }
76
77 bool is_humongous() const { return _value == Humongous; }
78 bool is_young() const { return _value == Young; }
79 bool is_old() const { return _value == Old; }
80 bool is_ext() const { return _value == Ext; }
81
82 #ifdef ASSERT
83 bool is_default() const { return _value == NotInCSet; }
84 bool is_valid() const { return (_value >= Ext) && (_value < Num); }
85 bool is_valid_gen() const { return (_value >= Young && _value <= Old); }
86 #endif
87 };
88
89 // Instances of this class are used for quick tests on whether a reference points
90 // into the collection set and into which generation or is a humongous object
91 //
92 // Each of the array's elements indicates whether the corresponding region is in
93 // the collection set and if so in which generation, or a humongous region.
94 //
95 // We use this to speed up reference processing during young collection and
96 // quickly reclaim humongous objects. For the latter, by making a humongous region
97 // succeed this test, we sort-of add it to the collection set. During the reference
98 // iteration closures, when we see a humongous region, we then simply mark it as
99 // referenced, i.e. live.
100 class G1InCSetStateFastTestBiasedMappedArray : public G1BiasedMappedArray<InCSetState> {
101 protected:
102 InCSetState default_value() const { return InCSetState::NotInCSet; }
103 public:
104 void set_humongous(uintptr_t index) {
105 assert(get_by_index(index).is_default(),
106 "State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value());
107 set_by_index(index, InCSetState::Humongous);
108 }
109
110 void set_ext(uintptr_t index) {
111 assert(get_by_index(index).is_default(),
112 "State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value());
113 set_by_index(index, InCSetState::Ext);
114 }
115
116 void clear_humongous(uintptr_t index) {
117 set_by_index(index, InCSetState::NotInCSet);
118 }
119
120 void set_in_young(uintptr_t index) {
121 assert(get_by_index(index).is_default(),
122 "State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value());
123 set_by_index(index, InCSetState::Young);
124 }
125
126 void set_in_old(uintptr_t index) {
127 assert(get_by_index(index).is_default(),
128 "State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value());
129 set_by_index(index, InCSetState::Old);
130 }
131
132 bool is_in_cset_or_humongous(HeapWord* addr) const { return at(addr).is_in_cset_or_humongous(); }
133 bool is_in_cset(HeapWord* addr) const { return at(addr).is_in_cset(); }
|