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-03-13 21:01:56 +01:00
|
|
|
#include "gc/shared/cardTable.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-01-25 00:27:51 -05:00
|
|
|
class G1FreeIdSet;
|
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 closure class for processing card table entries. Note that we don't
|
|
|
|
// require these closure objects to be stack-allocated.
|
2019-02-13 17:38:14 -05:00
|
|
|
class G1CardTableEntryClosure: public CHeapObj<mtGC> {
|
2008-06-05 15:57:56 -07:00
|
|
|
public:
|
2019-03-13 21:01:56 +01:00
|
|
|
typedef CardTable::CardValue CardValue;
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
// Process the card whose card table entry is "card_ptr". If returns
|
|
|
|
// "false", terminate the iteration early.
|
2019-03-13 21:01:56 +01:00
|
|
|
virtual bool do_card_ptr(CardValue* card_ptr, uint worker_i) = 0;
|
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 {
|
2016-03-16 00:28:33 -04:00
|
|
|
// Apply the closure to the elements of "node" from it's index to
|
|
|
|
// buffer_size. If all closure applications return true, then
|
|
|
|
// returns true. Stops processing after the first closure
|
|
|
|
// application that returns false, and returns false from this
|
|
|
|
// function. If "consume" is true, the node's index is updated to
|
2016-03-25 15:50:31 -04:00
|
|
|
// exclude the processed elements, e.g. up to the element for which
|
|
|
|
// the closure returned false.
|
2019-02-13 17:38:14 -05:00
|
|
|
bool apply_closure_to_buffer(G1CardTableEntryClosure* cl,
|
2016-03-16 00:28:33 -04:00
|
|
|
BufferNode* node,
|
|
|
|
bool consume,
|
|
|
|
uint worker_i = 0);
|
|
|
|
|
2017-07-12 12:26:57 +02:00
|
|
|
// If there are more than stop_at completed buffers, pop one, apply
|
|
|
|
// the specified closure to its active elements, and return true.
|
|
|
|
// Otherwise return false.
|
|
|
|
//
|
|
|
|
// A completely processed buffer is freed. However, if a closure
|
|
|
|
// invocation returns false, processing is stopped and the partially
|
|
|
|
// processed buffer (with its index updated to exclude the processed
|
|
|
|
// elements, e.g. up to the element for which the closure returned
|
|
|
|
// false) is returned to the completed buffer set.
|
|
|
|
//
|
|
|
|
// If during_pause is true, stop_at must be zero, and the closure
|
|
|
|
// must never return false.
|
2019-02-13 17:38:14 -05:00
|
|
|
bool apply_closure_to_completed_buffer(G1CardTableEntryClosure* cl,
|
2017-07-12 12:26:57 +02:00
|
|
|
uint worker_i,
|
|
|
|
size_t stop_at,
|
|
|
|
bool during_pause);
|
|
|
|
|
2016-03-10 16:21:46 -05:00
|
|
|
bool mut_process_buffer(BufferNode* node);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2019-05-21 19:19:44 -04:00
|
|
|
// If the queue contains more buffers than configured here, the
|
|
|
|
// mutator must start doing some of the concurrent refinement work,
|
|
|
|
size_t _max_completed_buffers;
|
|
|
|
size_t _completed_buffers_padding;
|
|
|
|
static const size_t MaxCompletedBuffersUnlimited = ~size_t(0);
|
|
|
|
|
2019-01-25 00:27:51 -05:00
|
|
|
G1FreeIdSet* _free_ids;
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
// The number of completed buffers processed by mutator and rs thread,
|
|
|
|
// respectively.
|
|
|
|
jint _processed_buffers_mut;
|
|
|
|
jint _processed_buffers_rs_thread;
|
|
|
|
|
2014-04-16 16:46:58 +02:00
|
|
|
// Current buffer node used for parallel iteration.
|
|
|
|
BufferNode* volatile _cur_par_buffer_node;
|
2016-03-10 16:21:46 -05:00
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
public:
|
2019-02-13 17:38:14 -05:00
|
|
|
G1DirtyCardQueueSet(bool notify_when_complete = true);
|
|
|
|
~G1DirtyCardQueueSet();
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2017-07-12 12:26:57 +02:00
|
|
|
void initialize(Monitor* cbl_mon,
|
2018-11-15 19:59:10 -05:00
|
|
|
BufferNode::Allocator* allocator,
|
2016-01-08 15:41:44 -05:00
|
|
|
bool init_free_ids = false);
|
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);
|
|
|
|
|
2017-07-12 12:26:57 +02:00
|
|
|
// Apply G1RefineCardConcurrentlyClosure to completed buffers until there are stop_at
|
|
|
|
// completed buffers remaining.
|
|
|
|
bool refine_completed_buffer_concurrently(uint worker_i, size_t stop_at);
|
|
|
|
|
|
|
|
// Apply the given closure to all completed buffers. The given closure's do_card_ptr
|
|
|
|
// must never return false. Must only be called during GC.
|
2019-02-13 17:38:14 -05:00
|
|
|
bool apply_closure_during_gc(G1CardTableEntryClosure* cl, uint worker_i);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2018-12-26 19:24:00 -05:00
|
|
|
void reset_for_par_iteration() { _cur_par_buffer_node = completed_buffers_head(); }
|
2014-04-16 16:46:58 +02:00
|
|
|
// Applies the current closure to all completed buffers, non-consumptively.
|
2016-03-10 16:21:46 -05:00
|
|
|
// Can be used in parallel, all callers using the iteration state initialized
|
|
|
|
// by reset_for_par_iteration.
|
2019-02-13 17:38:14 -05:00
|
|
|
void par_apply_closure_to_all_completed_buffers(G1CardTableEntryClosure* cl);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
// If a full collection is happening, reset partial logs, and ignore
|
|
|
|
// 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-05-21 19:19:44 -04:00
|
|
|
void set_max_completed_buffers(size_t m) {
|
|
|
|
_max_completed_buffers = m;
|
|
|
|
}
|
|
|
|
size_t max_completed_buffers() const {
|
|
|
|
return _max_completed_buffers;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_completed_buffers_padding(size_t padding) {
|
|
|
|
_completed_buffers_padding = padding;
|
|
|
|
}
|
|
|
|
size_t completed_buffers_padding() const {
|
|
|
|
return _completed_buffers_padding;
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
jint processed_buffers_mut() {
|
|
|
|
return _processed_buffers_mut;
|
|
|
|
}
|
|
|
|
jint processed_buffers_rs_thread() {
|
|
|
|
return _processed_buffers_rs_thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
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
|