2008-06-05 15:57:56 -07:00
|
|
|
/*
|
2019-01-04 15:06:01 -05:00
|
|
|
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
|
2008-06-05 15:57:56 -07:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2008-06-05 15:57:56 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-02-13 17:38:14 -05:00
|
|
|
#ifndef SHARE_GC_G1_G1DIRTYCARDQUEUE_HPP
|
|
|
|
#define SHARE_GC_G1_G1DIRTYCARDQUEUE_HPP
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2019-09-06 13:38:55 -04:00
|
|
|
#include "gc/g1/g1BufferNodeList.hpp"
|
2019-08-30 14:05:00 -04:00
|
|
|
#include "gc/g1/g1FreeIdSet.hpp"
|
2018-08-18 13:59:25 -04:00
|
|
|
#include "gc/shared/ptrQueue.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "memory/allocation.hpp"
|
|
|
|
|
2019-02-13 17:38:14 -05:00
|
|
|
class G1DirtyCardQueueSet;
|
2019-07-19 16:47:11 -04:00
|
|
|
class G1RedirtyCardsQueueSet;
|
2019-03-05 19:54:33 -05:00
|
|
|
class Thread;
|
2019-01-04 15:06:01 -05:00
|
|
|
class Monitor;
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
// A ptrQueue whose elements are "oops", pointers to object heads.
|
2019-02-13 17:38:14 -05:00
|
|
|
class G1DirtyCardQueue: public PtrQueue {
|
2019-05-21 19:19:44 -04:00
|
|
|
protected:
|
|
|
|
virtual void handle_completed_buffer();
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
public:
|
2019-03-22 15:42:43 -04:00
|
|
|
G1DirtyCardQueue(G1DirtyCardQueueSet* qset);
|
2010-10-01 16:43:05 -04:00
|
|
|
|
2014-07-31 11:10:02 +02:00
|
|
|
// Flush before destroying; queue may be used to capture pending work while
|
|
|
|
// doing something else, with auto-flush on completion.
|
2019-02-13 17:38:14 -05:00
|
|
|
~G1DirtyCardQueue();
|
2014-07-31 11:10:02 +02:00
|
|
|
|
|
|
|
// Process queue entries and release resources.
|
|
|
|
void flush() { flush_impl(); }
|
|
|
|
|
2019-05-21 19:19:44 -04:00
|
|
|
inline G1DirtyCardQueueSet* dirty_card_qset() const;
|
|
|
|
|
2015-11-17 16:40:52 -05:00
|
|
|
// Compiler support.
|
|
|
|
static ByteSize byte_offset_of_index() {
|
2019-02-13 17:38:14 -05:00
|
|
|
return PtrQueue::byte_offset_of_index<G1DirtyCardQueue>();
|
2015-11-17 16:40:52 -05:00
|
|
|
}
|
|
|
|
using PtrQueue::byte_width_of_index;
|
|
|
|
|
|
|
|
static ByteSize byte_offset_of_buf() {
|
2019-02-13 17:38:14 -05:00
|
|
|
return PtrQueue::byte_offset_of_buf<G1DirtyCardQueue>();
|
2015-11-17 16:40:52 -05:00
|
|
|
}
|
|
|
|
using PtrQueue::byte_width_of_buf;
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
};
|
|
|
|
|
2019-02-13 17:38:14 -05:00
|
|
|
class G1DirtyCardQueueSet: public PtrQueueSet {
|
2019-08-29 18:35:52 -04:00
|
|
|
Monitor* _cbl_mon; // Protects the list and count members.
|
2019-06-26 13:18:38 -04:00
|
|
|
BufferNode* _completed_buffers_head;
|
|
|
|
BufferNode* _completed_buffers_tail;
|
2019-07-24 11:49:39 +02:00
|
|
|
|
2019-08-29 18:35:52 -04:00
|
|
|
// Number of actual cards in the list of completed buffers.
|
|
|
|
volatile size_t _num_cards;
|
2019-06-26 13:18:38 -04:00
|
|
|
|
2019-08-29 18:35:52 -04:00
|
|
|
size_t _process_cards_threshold;
|
2019-06-26 13:18:38 -04:00
|
|
|
volatile bool _process_completed_buffers;
|
|
|
|
|
|
|
|
void abandon_completed_buffers();
|
|
|
|
|
2019-10-08 15:15:50 -04:00
|
|
|
// Refine the cards in "node" from its index to buffer_size.
|
2019-09-06 13:38:55 -04:00
|
|
|
// Stops processing if SuspendibleThreadSet::should_yield() is true.
|
|
|
|
// Returns true if the entire buffer was processed, false if there
|
|
|
|
// is a pending yield request. The node's index is updated to exclude
|
|
|
|
// the processed elements, e.g. up to the element before processing
|
|
|
|
// stopped, or one past the last element if the entire buffer was
|
2019-10-08 15:15:50 -04:00
|
|
|
// processed. Increments *total_refined_cards by the number of cards
|
|
|
|
// processed and removed from the buffer.
|
|
|
|
bool refine_buffer(BufferNode* node, uint worker_id, size_t* total_refined_cards);
|
2017-07-12 12:26:57 +02:00
|
|
|
|
2016-03-10 16:21:46 -05:00
|
|
|
bool mut_process_buffer(BufferNode* node);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2019-08-29 18:35:52 -04:00
|
|
|
// If the queue contains more cards than configured here, the
|
|
|
|
// mutator must start doing some of the concurrent refinement work.
|
|
|
|
size_t _max_cards;
|
|
|
|
size_t _max_cards_padding;
|
|
|
|
static const size_t MaxCardsUnlimited = SIZE_MAX;
|
2019-05-21 19:19:44 -04:00
|
|
|
|
2019-08-30 14:05:00 -04:00
|
|
|
G1FreeIdSet _free_ids;
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2019-10-08 15:15:50 -04:00
|
|
|
// Array of cumulative dirty cards refined by mutator threads.
|
|
|
|
// Array has an entry per id in _free_ids.
|
|
|
|
size_t* _mutator_refined_cards_counters;
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
public:
|
2019-09-09 16:54:48 -04:00
|
|
|
G1DirtyCardQueueSet(Monitor* cbl_mon, BufferNode::Allocator* allocator);
|
2019-02-13 17:38:14 -05:00
|
|
|
~G1DirtyCardQueueSet();
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
// The number of parallel ids that can be claimed to allow collector or
|
|
|
|
// mutator threads to do card-processing work.
|
2014-04-03 17:49:31 +04:00
|
|
|
static uint num_par_ids();
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2019-03-05 19:54:33 -05:00
|
|
|
static void handle_zero_index_for_thread(Thread* t);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2019-05-21 19:19:44 -04:00
|
|
|
// Either process the entire buffer and return true, or enqueue the
|
|
|
|
// buffer and return false. If the buffer is completely processed,
|
|
|
|
// it can be reused in place.
|
|
|
|
bool process_or_enqueue_completed_buffer(BufferNode* node);
|
|
|
|
|
2019-06-26 13:18:38 -04:00
|
|
|
virtual void enqueue_completed_buffer(BufferNode* node);
|
|
|
|
|
|
|
|
// If the number of completed buffers is > stop_at, then remove and
|
|
|
|
// return a completed buffer from the list. Otherwise, return NULL.
|
|
|
|
BufferNode* get_completed_buffer(size_t stop_at = 0);
|
|
|
|
|
2019-08-29 18:35:52 -04:00
|
|
|
// The number of cards in completed buffers. Read without synchronization.
|
|
|
|
size_t num_cards() const { return _num_cards; }
|
2019-07-24 11:49:39 +02:00
|
|
|
|
2019-08-29 18:35:52 -04:00
|
|
|
// Verify that _num_cards is equal to the sum of actual cards
|
2019-07-24 11:49:39 +02:00
|
|
|
// in the completed buffers.
|
2019-08-29 18:35:52 -04:00
|
|
|
void verify_num_cards() const NOT_DEBUG_RETURN;
|
2019-06-26 13:18:38 -04:00
|
|
|
|
|
|
|
bool process_completed_buffers() { return _process_completed_buffers; }
|
|
|
|
void set_process_completed_buffers(bool x) { _process_completed_buffers = x; }
|
|
|
|
|
2019-08-29 18:35:52 -04:00
|
|
|
// Get/Set the number of cards that triggers log processing.
|
|
|
|
// Log processing should be done when the number of cards exceeds the
|
2019-06-26 13:18:38 -04:00
|
|
|
// threshold.
|
2019-08-29 18:35:52 -04:00
|
|
|
void set_process_cards_threshold(size_t sz) {
|
|
|
|
_process_cards_threshold = sz;
|
2019-06-26 13:18:38 -04:00
|
|
|
}
|
2019-08-29 18:35:52 -04:00
|
|
|
size_t process_cards_threshold() const {
|
|
|
|
return _process_cards_threshold;
|
2019-06-26 13:18:38 -04:00
|
|
|
}
|
2019-08-29 18:35:52 -04:00
|
|
|
static const size_t ProcessCardsThresholdNever = SIZE_MAX;
|
2019-06-26 13:18:38 -04:00
|
|
|
|
|
|
|
// Notify the consumer if the number of buffers crossed the threshold
|
|
|
|
void notify_if_necessary();
|
|
|
|
|
2019-07-19 16:47:11 -04:00
|
|
|
void merge_bufferlists(G1RedirtyCardsQueueSet* src);
|
2019-06-26 13:18:38 -04:00
|
|
|
|
2019-09-06 13:38:55 -04:00
|
|
|
G1BufferNodeList take_all_completed_buffers();
|
2017-07-12 12:26:57 +02:00
|
|
|
|
2019-09-06 13:38:55 -04:00
|
|
|
// If there are more than stop_at cards in the completed buffers, pop
|
|
|
|
// a buffer, refine its contents, and return true. Otherwise return
|
|
|
|
// false.
|
|
|
|
//
|
|
|
|
// Stops processing a buffer if SuspendibleThreadSet::should_yield(),
|
|
|
|
// returning the incompletely processed buffer to the completed buffer
|
|
|
|
// list, for later processing of the remainder.
|
2019-10-08 15:15:50 -04:00
|
|
|
//
|
|
|
|
// Increments *total_refined_cards by the number of cards processed and
|
|
|
|
// removed from the buffer.
|
|
|
|
bool refine_completed_buffer_concurrently(uint worker_id,
|
|
|
|
size_t stop_at,
|
|
|
|
size_t* total_refined_cards);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2019-06-26 13:18:38 -04:00
|
|
|
// If a full collection is happening, reset partial logs, and release
|
2008-06-05 15:57:56 -07:00
|
|
|
// completed ones: the full collection will make them all irrelevant.
|
|
|
|
void abandon_logs();
|
|
|
|
|
|
|
|
// If any threads have partial logs, add them to the global list of logs.
|
|
|
|
void concatenate_logs();
|
|
|
|
|
2019-08-29 18:35:52 -04:00
|
|
|
void set_max_cards(size_t m) {
|
|
|
|
_max_cards = m;
|
2019-05-21 19:19:44 -04:00
|
|
|
}
|
2019-08-29 18:35:52 -04:00
|
|
|
size_t max_cards() const {
|
|
|
|
return _max_cards;
|
2019-05-21 19:19:44 -04:00
|
|
|
}
|
|
|
|
|
2019-08-29 18:35:52 -04:00
|
|
|
void set_max_cards_padding(size_t padding) {
|
|
|
|
_max_cards_padding = padding;
|
2019-05-21 19:19:44 -04:00
|
|
|
}
|
2019-08-29 18:35:52 -04:00
|
|
|
size_t max_cards_padding() const {
|
|
|
|
return _max_cards_padding;
|
2019-05-21 19:19:44 -04:00
|
|
|
}
|
|
|
|
|
2019-10-08 15:15:50 -04:00
|
|
|
// Total dirty cards refined by mutator threads.
|
|
|
|
size_t total_mutator_refined_cards() const;
|
2008-06-05 15:57:56 -07:00
|
|
|
};
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2019-05-21 19:19:44 -04:00
|
|
|
inline G1DirtyCardQueueSet* G1DirtyCardQueue::dirty_card_qset() const {
|
|
|
|
return static_cast<G1DirtyCardQueueSet*>(qset());
|
|
|
|
}
|
|
|
|
|
2019-02-13 17:38:14 -05:00
|
|
|
#endif // SHARE_GC_G1_G1DIRTYCARDQUEUE_HPP
|