7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/g1/dirtyCardQueue.hpp"
27 #include "gc/g1/g1CollectedHeap.inline.hpp"
28 #include "gc/g1/heapRegionRemSet.hpp"
29 #include "gc/shared/workgroup.hpp"
30 #include "runtime/atomic.hpp"
31 #include "runtime/mutexLocker.hpp"
32 #include "runtime/safepoint.hpp"
33 #include "runtime/thread.inline.hpp"
34
35 // Represents a set of free small integer ids.
36 class FreeIdSet : public CHeapObj<mtGC> {
37 enum {
38 end_of_list = UINT_MAX,
39 claimed = UINT_MAX - 1
40 };
41
42 uint _size;
43 Monitor* _mon;
44
45 uint* _ids;
46 uint _hd;
81 _waiters--;
82 }
83 uint res = _hd;
84 _hd = _ids[res];
85 _ids[res] = claimed; // For debugging.
86 _claimed++;
87 return res;
88 }
89
90 void FreeIdSet::release_par_id(uint id) {
91 MutexLockerEx x(_mon, Mutex::_no_safepoint_check_flag);
92 assert(_ids[id] == claimed, "Precondition.");
93 _ids[id] = _hd;
94 _hd = id;
95 _claimed--;
96 if (_waiters > 0) {
97 _mon->notify_all();
98 }
99 }
100
101 DirtyCardQueue::DirtyCardQueue(DirtyCardQueueSet* qset, bool permanent) :
102 // Dirty card queues are always active, so we create them with their
103 // active field set to true.
104 PtrQueue(qset, permanent, true /* active */)
105 { }
106
107 DirtyCardQueue::~DirtyCardQueue() {
108 if (!is_permanent()) {
109 flush();
110 }
111 }
112
113 DirtyCardQueueSet::DirtyCardQueueSet(bool notify_when_complete) :
114 PtrQueueSet(notify_when_complete),
115 _mut_process_closure(NULL),
116 _shared_dirty_card_queue(this, true /* permanent */),
117 _free_ids(NULL),
118 _processed_buffers_mut(0), _processed_buffers_rs_thread(0)
119 {
120 _all_active = true;
121 }
122
123 // Determines how many mutator threads can process the buffers in parallel.
124 uint DirtyCardQueueSet::num_par_ids() {
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/g1/dirtyCardQueue.hpp"
27 #include "gc/g1/g1BarrierSet.hpp"
28 #include "gc/g1/g1CollectedHeap.inline.hpp"
29 #include "gc/g1/heapRegionRemSet.hpp"
30 #include "gc/shared/workgroup.hpp"
31 #include "runtime/atomic.hpp"
32 #include "runtime/mutexLocker.hpp"
33 #include "runtime/safepoint.hpp"
34 #include "runtime/thread.inline.hpp"
35
36 // Represents a set of free small integer ids.
37 class FreeIdSet : public CHeapObj<mtGC> {
38 enum {
39 end_of_list = UINT_MAX,
40 claimed = UINT_MAX - 1
41 };
42
43 uint _size;
44 Monitor* _mon;
45
46 uint* _ids;
47 uint _hd;
82 _waiters--;
83 }
84 uint res = _hd;
85 _hd = _ids[res];
86 _ids[res] = claimed; // For debugging.
87 _claimed++;
88 return res;
89 }
90
91 void FreeIdSet::release_par_id(uint id) {
92 MutexLockerEx x(_mon, Mutex::_no_safepoint_check_flag);
93 assert(_ids[id] == claimed, "Precondition.");
94 _ids[id] = _hd;
95 _hd = id;
96 _claimed--;
97 if (_waiters > 0) {
98 _mon->notify_all();
99 }
100 }
101
102 DirtyCardQueue::DirtyCardQueue(DirtyCardQueueSet* dcqs, bool permanent) :
103 // Dirty card queues are always active, so we create them with their
104 // active field set to true.
105 PtrQueue(dcqs != NULL ? dcqs : &G1BarrierSet::dirty_card_queue_set(), permanent, true /* active */)
106 { }
107
108 DirtyCardQueue::~DirtyCardQueue() {
109 if (!is_permanent()) {
110 flush();
111 }
112 }
113
114 DirtyCardQueueSet::DirtyCardQueueSet(bool notify_when_complete) :
115 PtrQueueSet(notify_when_complete),
116 _mut_process_closure(NULL),
117 _shared_dirty_card_queue(this, true /* permanent */),
118 _free_ids(NULL),
119 _processed_buffers_mut(0), _processed_buffers_rs_thread(0)
120 {
121 _all_active = true;
122 }
123
124 // Determines how many mutator threads can process the buffers in parallel.
125 uint DirtyCardQueueSet::num_par_ids() {
|