39 // favor smaller types, so we use the smallest usable type there.
40 #ifdef SPARC
41 #define CSETSTATE_FORMAT INTPTR_FORMAT
42 typedef intptr_t in_cset_state_t;
43 #else
44 #define CSETSTATE_FORMAT "%d"
45 typedef int8_t in_cset_state_t;
46 #endif
47 private:
48 in_cset_state_t _value;
49 public:
50 enum {
51 // Selection of the values were driven to micro-optimize the encoding and
52 // frequency of the checks.
53 // The most common check is whether the region is in the collection set or not,
54 // this encoding allows us to use an > 0 check.
55 // The positive values are encoded in increasing generation order, which
56 // makes getting the next generation fast by a simple increment. They are also
57 // used to index into arrays.
58 // The negative values are used for objects requiring various special cases,
59 // for example eager reclamation of humongous objects.
60 Humongous = -1, // The region is humongous
61 NotInCSet = 0, // The region is not in the collection set.
62 Young = 1, // The region is in the collection set and a young region.
63 Old = 2, // The region is in the collection set and an old region.
64 Num
65 };
66
67 InCSetState(in_cset_state_t value = NotInCSet) : _value(value) {
68 assert(is_valid(), "Invalid state %d", _value);
69 }
70
71 in_cset_state_t value() const { return _value; }
72
73 void set_old() { _value = Old; }
74
75 bool is_in_cset_or_humongous() const { return is_in_cset() || is_humongous(); }
76 bool is_in_cset() const { return _value > NotInCSet; }
77
78 bool is_humongous() const { return _value == Humongous; }
79 bool is_young() const { return _value == Young; }
80 bool is_old() const { return _value == Old; }
81
82 #ifdef ASSERT
83 bool is_default() const { return _value == NotInCSet; }
84 bool is_valid() const { return (_value >= Humongous) && (_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 clear_humongous(uintptr_t index) {
111 set_by_index(index, InCSetState::NotInCSet);
112 }
113
114 void set_in_young(uintptr_t index) {
115 assert(get_by_index(index).is_default(),
116 "State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value());
117 set_by_index(index, InCSetState::Young);
118 }
119
120 void set_in_old(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::Old);
|
39 // favor smaller types, so we use the smallest usable type there.
40 #ifdef SPARC
41 #define CSETSTATE_FORMAT INTPTR_FORMAT
42 typedef intptr_t in_cset_state_t;
43 #else
44 #define CSETSTATE_FORMAT "%d"
45 typedef int8_t in_cset_state_t;
46 #endif
47 private:
48 in_cset_state_t _value;
49 public:
50 enum {
51 // Selection of the values were driven to micro-optimize the encoding and
52 // frequency of the checks.
53 // The most common check is whether the region is in the collection set or not,
54 // this encoding allows us to use an > 0 check.
55 // The positive values are encoded in increasing generation order, which
56 // makes getting the next generation fast by a simple increment. They are also
57 // used to index into arrays.
58 // The negative values are used for objects requiring various special cases,
59 // for example eager reclamation of humongous objects or optional regions.
60 Optional = -2, // The region is optional
61 Humongous = -1, // The region is humongous
62 NotInCSet = 0, // The region is not in the collection set.
63 Young = 1, // The region is in the collection set and a young region.
64 Old = 2, // The region is in the collection set and an old region.
65 Num
66 };
67
68 InCSetState(in_cset_state_t value = NotInCSet) : _value(value) {
69 assert(is_valid(), "Invalid state %d", _value);
70 }
71
72 in_cset_state_t value() const { return _value; }
73
74 void set_old() { _value = Old; }
75
76 bool is_in_cset_or_humongous() const { return is_in_cset() || is_humongous(); }
77 bool is_in_cset() const { return _value > NotInCSet; }
78
79 bool is_humongous() const { return _value == Humongous; }
80 bool is_young() const { return _value == Young; }
81 bool is_old() const { return _value == Old; }
82 bool is_optional() const { return _value == Optional; }
83
84 #ifdef ASSERT
85 bool is_default() const { return _value == NotInCSet; }
86 bool is_valid() const { return (_value >= Optional) && (_value < Num); }
87 bool is_valid_gen() const { return (_value >= Young && _value <= Old); }
88 #endif
89 };
90
91 // Instances of this class are used for quick tests on whether a reference points
92 // into the collection set and into which generation or is a humongous object
93 //
94 // Each of the array's elements indicates whether the corresponding region is in
95 // the collection set and if so in which generation, or a humongous region.
96 //
97 // We use this to speed up reference processing during young collection and
98 // quickly reclaim humongous objects. For the latter, by making a humongous region
99 // succeed this test, we sort-of add it to the collection set. During the reference
100 // iteration closures, when we see a humongous region, we then simply mark it as
101 // referenced, i.e. live.
102 class G1InCSetStateFastTestBiasedMappedArray : public G1BiasedMappedArray<InCSetState> {
103 protected:
104 InCSetState default_value() const { return InCSetState::NotInCSet; }
105 public:
106 void set_optional(uintptr_t index) {
107 assert(get_by_index(index).is_default(),
108 "State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value());
109 set_by_index(index, InCSetState::Optional);
110 }
111
112 void set_humongous(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::Humongous);
116 }
117
118 void clear_humongous(uintptr_t index) {
119 set_by_index(index, InCSetState::NotInCSet);
120 }
121
122 void set_in_young(uintptr_t index) {
123 assert(get_by_index(index).is_default(),
124 "State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value());
125 set_by_index(index, InCSetState::Young);
126 }
127
128 void set_in_old(uintptr_t index) {
129 assert(get_by_index(index).is_default(),
130 "State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value());
131 set_by_index(index, InCSetState::Old);
|