--- a/src/hotspot/share/gc/g1/g1SATBMarkQueueSet.cpp Tue Aug 14 10:42:00 2018 +0800
+++ b/src/hotspot/share/gc/g1/g1SATBMarkQueueSet.cpp Tue Aug 14 00:15:56 2018 -0400
@@ -23,8 +23,24 @@
*/
#include "precompiled.hpp"
+#include "gc/g1/g1CollectedHeap.inline.hpp"
#include "gc/g1/g1SATBMarkQueueSet.hpp"
#include "gc/g1/g1ThreadLocalData.hpp"
+#include "gc/g1/heapRegion.hpp"
+#include "gc/g1/satbMarkQueue.hpp"
+#include "oops/oop.hpp"
+#include "utilities/debug.hpp"
+#include "utilities/globalDefinitions.hpp"
+
+G1SATBMarkQueueSet::G1SATBMarkQueueSet() : _g1h(NULL) {}
+
+void G1SATBMarkQueueSet::initialize(G1CollectedHeap* g1h,
+ Monitor* cbl_mon, Mutex* fl_lock,
+ int process_completed_threshold,
+ Mutex* lock) {
+ SATBMarkQueueSet::initialize(cbl_mon, fl_lock, process_completed_threshold, lock);
+ _g1h = g1h;
+}
void G1SATBMarkQueueSet::handle_zero_index_for_thread(JavaThread* t) {
G1ThreadLocalData::satb_mark_queue(t).handle_zero_index();
@@ -33,3 +49,77 @@
SATBMarkQueue& G1SATBMarkQueueSet::satb_queue_for_thread(JavaThread* const t) const{
return G1ThreadLocalData::satb_mark_queue(t);
}
+
+// Return true if a SATB buffer entry refers to an object that
+// requires marking.
+//
+// The entry must point into the G1 heap. In particular, it must not
+// be a NULL pointer. NULL pointers are pre-filtered and never
+// inserted into a SATB buffer.
+//
+// An entry that is below the NTAMS pointer for the containing heap
+// region requires marking. Such an entry must point to a valid object.
+//
+// An entry that is at least the NTAMS pointer for the containing heap
+// region might be any of the following, none of which should be marked.
+//
+// * A reference to an object allocated since marking started.
+// According to SATB, such objects are implicitly kept live and do
+// not need to be dealt with via SATB buffer processing.
+//
+// * A reference to a young generation object. Young objects are
+// handled separately and are not marked by concurrent marking.
+//
+// * A stale reference to a young generation object. If a young
+// generation object reference is recorded and not filtered out
+// before being moved by a young collection, the reference becomes
+// stale.
+//
+// * A stale reference to an eagerly reclaimed humongous object. If a
+// humongous object is recorded and then reclaimed, the reference
+// becomes stale.
+//
+// The stale reference cases are implicitly handled by the NTAMS
+// comparison. Because of the possibility of stale references, buffer
+// processing must be somewhat circumspect and not assume entries
+// in an unfiltered buffer refer to valid objects.
+
+static inline bool requires_marking(const void* entry, G1CollectedHeap* g1h) {
+ // Includes rejection of NULL pointers.
+ assert(g1h->is_in_reserved(entry),
+ "Non-heap pointer in SATB buffer: " PTR_FORMAT, p2i(entry));
+
+ HeapRegion* region = g1h->heap_region_containing(entry);
+ assert(region != NULL, "No region for " PTR_FORMAT, p2i(entry));
+ if (entry >= region->next_top_at_mark_start()) {
+ return false;
+ }
+
+ assert(oopDesc::is_oop(oop(entry), true /* ignore mark word */),
+ "Invalid oop in SATB buffer: " PTR_FORMAT, p2i(entry));
+
+ return true;
+}
+
+static inline bool discard_entry(const void* entry, G1CollectedHeap* g1h) {
+ return !requires_marking(entry, g1h) || g1h->is_marked_next((oop)entry);
+}
+
+// Workaround for not yet having std::bind.
+class G1SATBMarkQueueFilterFn {
+ G1CollectedHeap* _g1h;
+
+public:
+ G1SATBMarkQueueFilterFn(G1CollectedHeap* g1h) : _g1h(g1h) {}
+
+ // Return true if entry should be filtered out (removed), false if
+ // it should be retained.
+ bool operator()(const void* entry) const {
+ return discard_entry(entry, _g1h);
+ }
+};
+
+void G1SATBMarkQueueSet::filter(SATBMarkQueue* queue) {
+ assert(_g1h != NULL, "SATB queue set not initialized");
+ apply_filter(G1SATBMarkQueueFilterFn(_g1h), queue);
+}