annotate src/hotspot/share/gc/shared/satbMarkQueue.hpp @ 52321:31b159f30fb2

8180193: Make marking bitmap code available to other GCs Reviewed-by: shade, stefank
author rkennke
date Wed, 29 Aug 2018 20:15:09 +0200
parents 58113ce90caf
children 6df094be7f58
rev   line source
ysr@1374 1 /*
kbarrett@51970 2 * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
ysr@1374 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@1374 4 *
ysr@1374 5 * This code is free software; you can redistribute it and/or modify it
ysr@1374 6 * under the terms of the GNU General Public License version 2 only, as
ysr@1374 7 * published by the Free Software Foundation.
ysr@1374 8 *
ysr@1374 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@1374 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@1374 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@1374 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@1374 13 * accompanied this code).
ysr@1374 14 *
ysr@1374 15 * You should have received a copy of the GNU General Public License version
ysr@1374 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@1374 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@1374 18 *
trims@5547 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@5547 20 * or visit www.oracle.com if you need additional information or have any
trims@5547 21 * questions.
ysr@1374 22 *
ysr@1374 23 */
ysr@1374 24
kbarrett@52167 25 #ifndef SHARE_GC_SHARED_SATBMARKQUEUE_HPP
kbarrett@52167 26 #define SHARE_GC_SHARED_SATBMARKQUEUE_HPP
stefank@7397 27
kbarrett@52167 28 #include "gc/shared/ptrQueue.hpp"
kbarrett@30577 29 #include "memory/allocation.hpp"
stefank@7397 30
ysr@1374 31 class JavaThread;
tonyp@11455 32 class SATBMarkQueueSet;
ysr@1374 33
kbarrett@30577 34 // Base class for processing the contents of a SATB buffer.
kbarrett@30577 35 class SATBBufferClosure : public StackObj {
kbarrett@30577 36 protected:
kbarrett@30577 37 ~SATBBufferClosure() { }
kbarrett@30577 38
kbarrett@30577 39 public:
kbarrett@30577 40 // Process the SATB entries in the designated buffer range.
kbarrett@30577 41 virtual void do_buffer(void** buffer, size_t size) = 0;
kbarrett@30577 42 };
kbarrett@30577 43
kbarrett@33792 44 // A PtrQueue whose elements are (possibly stale) pointers to object heads.
kbarrett@33792 45 class SATBMarkQueue: public PtrQueue {
tonyp@11455 46 friend class SATBMarkQueueSet;
tonyp@11455 47
tonyp@11455 48 private:
tonyp@11455 49 // Filter out unwanted entries from the buffer.
kbarrett@51970 50 inline void filter();
tonyp@11455 51
kbarrett@51970 52 // Removes entries from the buffer that are no longer needed.
kbarrett@51970 53 template<typename Filter>
kbarrett@51970 54 inline void apply_filter(Filter filter_out);
kbarrett@51970 55
kbarrett@52105 56 public:
kbarrett@52105 57 SATBMarkQueue(SATBMarkQueueSet* qset, bool permanent = false);
kbarrett@52105 58
tschatzl@28507 59 // Process queue entries and free resources.
tschatzl@28507 60 void flush();
tonyp@11455 61
kbarrett@30577 62 // Apply cl to the active part of the buffer.
kbarrett@30577 63 // Prerequisite: Must be at a safepoint.
kbarrett@30577 64 void apply_closure_and_empty(SATBBufferClosure* cl);
kbarrett@30577 65
tonyp@7920 66 // Overrides PtrQueue::should_enqueue_buffer(). See the method's
tonyp@7920 67 // definition for more information.
tonyp@7920 68 virtual bool should_enqueue_buffer();
tonyp@7920 69
tonyp@11455 70 #ifndef PRODUCT
tonyp@11455 71 // Helpful for debugging
tonyp@11455 72 void print(const char* name);
tonyp@11455 73 #endif // PRODUCT
kbarrett@34148 74
kbarrett@34148 75 // Compiler support.
kbarrett@34148 76 static ByteSize byte_offset_of_index() {
kbarrett@34148 77 return PtrQueue::byte_offset_of_index<SATBMarkQueue>();
kbarrett@34148 78 }
kbarrett@34148 79 using PtrQueue::byte_width_of_index;
kbarrett@34148 80
kbarrett@34148 81 static ByteSize byte_offset_of_buf() {
kbarrett@34148 82 return PtrQueue::byte_offset_of_buf<SATBMarkQueue>();
kbarrett@34148 83 }
kbarrett@34148 84 using PtrQueue::byte_width_of_buf;
kbarrett@34148 85
kbarrett@34148 86 static ByteSize byte_offset_of_active() {
kbarrett@34148 87 return PtrQueue::byte_offset_of_active<SATBMarkQueue>();
kbarrett@34148 88 }
kbarrett@34148 89 using PtrQueue::byte_width_of_active;
kbarrett@34148 90
ysr@1374 91 };
ysr@1374 92
ysr@1374 93 class SATBMarkQueueSet: public PtrQueueSet {
kbarrett@33792 94 SATBMarkQueue _shared_satb_queue;
kbarrett@52113 95 size_t _buffer_enqueue_threshold;
ysr@1374 96
tonyp@5082 97 #ifdef ASSERT
pliden@22497 98 void dump_active_states(bool expected_active);
pliden@22497 99 void verify_active_states(bool expected_active);
tonyp@5082 100 #endif // ASSERT
ysr@1374 101
kbarrett@52105 102 protected:
ysr@1374 103 SATBMarkQueueSet();
kbarrett@52105 104 ~SATBMarkQueueSet() {}
ysr@1374 105
kbarrett@52105 106 template<typename Filter>
kbarrett@52105 107 void apply_filter(Filter filter, SATBMarkQueue* queue) {
kbarrett@52105 108 queue->apply_filter(filter);
kbarrett@52105 109 }
kbarrett@52105 110
kbarrett@52105 111 void initialize(Monitor* cbl_mon, Mutex* fl_lock,
iveresov@4481 112 int process_completed_threshold,
kbarrett@52113 113 uint buffer_enqueue_threshold_percentage,
iveresov@4481 114 Mutex* lock);
ysr@1374 115
kbarrett@52105 116 public:
rkennke@52080 117 virtual SATBMarkQueue& satb_queue_for_thread(JavaThread* const t) const = 0;
ysr@1374 118
pliden@22497 119 // Apply "set_active(active)" to all SATB queues in the set. It should be
tonyp@5082 120 // called only with the world stopped. The method will assert that the
tonyp@5082 121 // SATB queues of all threads it visits, as well as the SATB queue
tonyp@5082 122 // set itself, has an active value same as expected_active.
pliden@22497 123 void set_active_all_threads(bool active, bool expected_active);
ysr@1374 124
kbarrett@52113 125 size_t buffer_enqueue_threshold() const { return _buffer_enqueue_threshold; }
kbarrett@52105 126 virtual void filter(SATBMarkQueue* queue) = 0;
kbarrett@51970 127
tonyp@11455 128 // Filter all the currently-active SATB buffers.
tonyp@11455 129 void filter_thread_buffers();
tonyp@11455 130
kbarrett@30577 131 // If there exists some completed buffer, pop and process it, and
kbarrett@30577 132 // return true. Otherwise return false. Processing a buffer
kbarrett@37065 133 // consists of applying the closure to the active range of the
kbarrett@37065 134 // buffer; the leading entries may be excluded due to filtering.
kbarrett@30577 135 bool apply_closure_to_completed_buffer(SATBBufferClosure* cl);
ysr@1374 136
tonyp@11455 137 #ifndef PRODUCT
tonyp@11455 138 // Helpful for debugging
tonyp@11455 139 void print_all(const char* msg);
tonyp@11455 140 #endif // PRODUCT
tonyp@11455 141
kbarrett@33792 142 SATBMarkQueue* shared_satb_queue() { return &_shared_satb_queue; }
ysr@1374 143
ysr@1374 144 // If a marking is being abandoned, reset any unprocessed log buffers.
ysr@1374 145 void abandon_partial_marking();
ysr@1374 146 };
stefank@7397 147
kbarrett@51970 148 inline void SATBMarkQueue::filter() {
kbarrett@51970 149 static_cast<SATBMarkQueueSet*>(qset())->filter(this);
kbarrett@51970 150 }
kbarrett@51970 151
kbarrett@51970 152 // Removes entries from the buffer that are no longer needed, as
kbarrett@51970 153 // determined by filter. If e is a void* entry in the buffer,
kbarrett@51970 154 // filter_out(e) must be a valid expression whose value is convertible
kbarrett@51970 155 // to bool. Entries are removed (filtered out) if the result is true,
kbarrett@51970 156 // retained if false.
kbarrett@51970 157 template<typename Filter>
kbarrett@51970 158 inline void SATBMarkQueue::apply_filter(Filter filter_out) {
kbarrett@51970 159 void** buf = this->_buf;
kbarrett@51970 160
kbarrett@51970 161 if (buf == NULL) {
kbarrett@51970 162 // nothing to do
kbarrett@51970 163 return;
kbarrett@51970 164 }
kbarrett@51970 165
kbarrett@51970 166 // Two-fingered compaction toward the end.
kbarrett@51970 167 void** src = &buf[this->index()];
kbarrett@51970 168 void** dst = &buf[this->capacity()];
kbarrett@51970 169 assert(src <= dst, "invariant");
kbarrett@51970 170 for ( ; src < dst; ++src) {
kbarrett@51970 171 // Search low to high for an entry to keep.
kbarrett@51970 172 void* entry = *src;
kbarrett@51970 173 if (!filter_out(entry)) {
kbarrett@51970 174 // Found keeper. Search high to low for an entry to discard.
kbarrett@51970 175 while (src < --dst) {
kbarrett@51970 176 if (filter_out(*dst)) {
kbarrett@51970 177 *dst = entry; // Replace discard with keeper.
kbarrett@51970 178 break;
kbarrett@51970 179 }
kbarrett@51970 180 }
kbarrett@51970 181 // If discard search failed (src == dst), the outer loop will also end.
kbarrett@51970 182 }
kbarrett@51970 183 }
kbarrett@51970 184 // dst points to the lowest retained entry, or the end of the buffer
kbarrett@51970 185 // if all the entries were filtered out.
kbarrett@51970 186 this->set_index(dst - buf);
kbarrett@51970 187 }
kbarrett@51970 188
kbarrett@52167 189 #endif // SHARE_GC_SHARED_SATBMARKQUEUE_HPP