--- a/src/hotspot/share/gc/shared/weakProcessorPhases.hpp Wed Aug 21 16:19:17 2019 -0400
+++ b/src/hotspot/share/gc/shared/weakProcessorPhases.hpp Wed Aug 21 18:42:30 2019 -0400
@@ -25,6 +25,7 @@
#ifndef SHARE_GC_SHARED_WEAKPROCESSORPHASES_HPP
#define SHARE_GC_SHARED_WEAKPROCESSORPHASES_HPP
+#include "gc/shared/oopStorageSet.hpp"
#include "memory/allocation.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/macros.hpp"
@@ -35,54 +36,117 @@
class WeakProcessorPhases : AllStatic {
public:
+ class Iterator;
+
typedef void (*Processor)(BoolObjectClosure*, OopClosure*);
enum Phase {
// Serial phases.
- JVMTI_ONLY(jvmti COMMA)
- JFR_ONLY(jfr COMMA)
+ JVMTI_ONLY(jvmti JFR_ONLY(COMMA))
+ JFR_ONLY(jfr)
- // OopStorage phases.
- jni,
- stringtable,
- resolved_method_table,
- vm
+ // Additional implicit phase values follow for oopstorages.
};
static const uint serial_phase_start = 0;
- static const uint serial_phase_count = jni;
- static const uint oop_storage_phase_start = serial_phase_count;
- static const uint oop_storage_phase_count = (vm + 1) - oop_storage_phase_start;
- static const uint phase_count = serial_phase_count + oop_storage_phase_count;
+ static const uint serial_phase_count = 0 JVMTI_ONLY(+ 1) JFR_ONLY(+ 1);
+ static const uint oopstorage_phase_start = serial_phase_count;
+ static const uint oopstorage_phase_count = OopStorageSet::weak_count;
+ static const uint phase_count = serial_phase_count + oopstorage_phase_count;
+
+ // Precondition: value < serial_phase_count
+ static Phase serial_phase(uint value);
- static Phase phase(uint value);
- static uint index(Phase phase);
+ // Precondition: value < oopstorage_phase_count
+ static Phase oopstorage_phase(uint value);
+
// Indexes relative to the corresponding phase_start constant.
+ // Precondition: is_serial(phase) or is_oopstorage(phase) accordingly
static uint serial_index(Phase phase);
- static uint oop_storage_index(Phase phase);
+ static uint oopstorage_index(Phase phase);
static bool is_serial(Phase phase);
- static bool is_oop_storage(Phase phase);
+ static bool is_oopstorage(Phase phase);
+ static Iterator serial_iterator();
+ static Iterator oopstorage_iterator();
+
+ // Precondition: is_serial(phase)
static const char* description(Phase phase);
- static Processor processor(Phase phase); // Precondition: is_serial(phase)
- static OopStorage* oop_storage(Phase phase); // Precondition: is_oop_storage(phase)
- static bool is_stringtable(Phase phase);
- static bool is_resolved_method_table(Phase phase);
+ // Precondition: is_serial(phase)
+ static Processor processor(Phase phase);
};
typedef WeakProcessorPhases::Phase WeakProcessorPhase;
-#define FOR_EACH_WEAK_PROCESSOR_PHASE(P) \
- for (WeakProcessorPhase P = static_cast<WeakProcessorPhase>(0); \
- static_cast<uint>(P) < WeakProcessorPhases::phase_count; \
- P = static_cast<WeakProcessorPhase>(static_cast<uint>(P) + 1))
+class WeakProcessorPhases::Iterator {
+ friend class WeakProcessorPhases;
+
+ uint _index;
+ uint _limit;
+
+ Iterator(uint index, uint limit) : _index(index), _limit(limit) {}
+
+ static const uint singular_value = UINT_MAX;
+ void verify_nonsingular() const NOT_DEBUG_RETURN;
+ void verify_category_match(const Iterator& other) const NOT_DEBUG_RETURN;
+ void verify_dereferenceable() const NOT_DEBUG_RETURN;
+
+public:
+ // Construct a singular iterator for later assignment. The only valid
+ // operations are destruction and assignment.
+ Iterator() : _index(singular_value), _limit(singular_value) {}
+
+ bool is_end() const {
+ verify_nonsingular();
+ return _index == _limit;
+ }
+
+ bool operator==(const Iterator& other) const {
+ verify_category_match(other);
+ return _index == other._index;
+ }
+
+ bool operator!=(const Iterator& other) const {
+ return !operator==(other);
+ }
-#define FOR_EACH_WEAK_PROCESSOR_OOP_STORAGE_PHASE(P) \
- for (WeakProcessorPhase P = static_cast<WeakProcessorPhase>(WeakProcessorPhases::oop_storage_phase_start); \
- static_cast<uint>(P) < (WeakProcessorPhases::oop_storage_phase_start + \
- WeakProcessorPhases::oop_storage_phase_count); \
- P = static_cast<WeakProcessorPhase>(static_cast<uint>(P) + 1))
+ Phase operator*() const {
+ verify_dereferenceable();
+ return static_cast<Phase>(_index);
+ }
+
+ // Phase doesn't have members, so no operator->().
+
+ Iterator& operator++() {
+ verify_dereferenceable();
+ ++_index;
+ return *this;
+ }
+
+ Iterator operator++(int) {
+ verify_dereferenceable();
+ return Iterator(_index++, _limit);
+ }
+
+ Iterator begin() const {
+ verify_nonsingular();
+ return *this;
+ }
+
+ Iterator end() const {
+ verify_nonsingular();
+ return Iterator(_limit, _limit);
+ }
+};
+
+inline WeakProcessorPhases::Iterator WeakProcessorPhases::serial_iterator() {
+ return Iterator(serial_phase_start, serial_phase_start + serial_phase_count);
+}
+
+inline WeakProcessorPhases::Iterator WeakProcessorPhases::oopstorage_iterator() {
+ return Iterator(oopstorage_phase_start, oopstorage_phase_start + oopstorage_phase_count);
+}
#endif // SHARE_GC_SHARED_WEAKPROCESSORPHASES_HPP