< prev index next >
src/share/vm/gc_implementation/g1/g1InCSetState.hpp
Print this page
@@ -28,19 +28,25 @@
#include "gc_implementation/g1/g1BiasedArray.hpp"
#include "memory/allocation.hpp"
// Per-region state during garbage collection.
struct InCSetState {
+ public:
// We use different types to represent the state value. Particularly SPARC puts
// values in structs from "left to right", i.e. MSB to LSB. This results in many
// unnecessary shift operations when loading and storing values of this type.
// This degrades performance significantly (>10%) on that platform.
// Other tested ABIs do not seem to have this problem, and actually tend to
// favor smaller types, so we use the smallest usable type there.
- SPARC_ONLY(typedef intptr_t in_cset_state_t;)
- NOT_SPARC(typedef int8_t in_cset_state_t;)
-
+#ifdef SPARC
+ #define CSETSTATE_FORMAT INTPTR_FORMAT
+ typedef intptr_t in_cset_state_t;
+#else
+ #define CSETSTATE_FORMAT "%d"
+ typedef int8_t in_cset_state_t;
+#endif
+ private:
in_cset_state_t _value;
public:
enum {
// Selection of the values were driven to micro-optimize the encoding and
// frequency of the checks.
@@ -57,27 +63,27 @@
Young = 1, // The region is in the collection set and a young region.
Old = 2, // The region is in the collection set and an old region.
Num
};
- InCSetState() { _value = NotInCSet; }
- InCSetState(in_cset_state_t value) { _value = value; }
+ InCSetState(in_cset_state_t value = NotInCSet) : _value(value) {
+ assert(is_valid(), err_msg("Invalid state %d", _value));
+ }
in_cset_state_t value() const { return _value; }
void set_old() { _value = Old; }
- bool is_not_in_cset() const { return _value == NotInCSet; }
bool is_in_cset_or_humongous() const { return _value != NotInCSet; }
bool is_in_cset() const { return _value > NotInCSet; }
bool is_humongous() const { return _value < NotInCSet; }
bool is_young() const { return _value == Young; }
bool is_old() const { return _value == Old; }
#ifdef ASSERT
- bool is_default() const { return is_not_in_cset(); }
- bool is_valid() const { return _value < Num; }
+ bool is_default() const { return !is_in_cset_or_humongous(); }
+ bool is_valid() const { return (_value >= Humongous) && (_value < Num); }
bool is_valid_gen() const { return (_value >= Young && _value <= Old); }
#endif
};
// Instances of this class are used for quick tests on whether a reference points
@@ -95,27 +101,27 @@
protected:
InCSetState default_value() const { return InCSetState::NotInCSet; }
public:
void set_humongous(uintptr_t index) {
assert(get_by_index(index).is_default(),
- err_msg("State at index " INTPTR_FORMAT" should be default but is %d", index, get_by_index(index).value()));
+ err_msg("State at index " INTPTR_FORMAT" should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value()));
set_by_index(index, InCSetState::Humongous);
}
void clear_humongous(uintptr_t index) {
set_by_index(index, InCSetState::NotInCSet);
}
void set_in_young(uintptr_t index) {
assert(get_by_index(index).is_default(),
- err_msg("State at index " INTPTR_FORMAT" should be default but is %d", index, get_by_index(index).value()));
+ err_msg("State at index " INTPTR_FORMAT" should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value()));
set_by_index(index, InCSetState::Young);
}
void set_in_old(uintptr_t index) {
assert(get_by_index(index).is_default(),
- err_msg("State at index " INTPTR_FORMAT" should be default but is %d", index, get_by_index(index).value()));
+ err_msg("State at index " INTPTR_FORMAT" should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value()));
set_by_index(index, InCSetState::Old);
}
bool is_in_cset_or_humongous(HeapWord* addr) const { return at(addr).is_in_cset_or_humongous(); }
bool is_in_cset(HeapWord* addr) const { return at(addr).is_in_cset(); }
< prev index next >