src/hotspot/share/gc/g1/g1DirtyCardQueue.cpp
author kbarrett
Wed, 26 Jun 2019 13:18:38 -0400
changeset 55498 e64383344f14
parent 54970 76d3d96a8bc2
child 55752 8ae33203d600
permissions -rw-r--r--
8225255: Make SATB qset lock-free Summary: Refactor PtrQueueSet, use lock-free stack for SATB completed buffers Reviewed-by: tschatzl, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     1
/*
53482
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents: 53102
diff changeset
     2
 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     4
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     8
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    13
 * accompanied this code).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    14
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4481
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4481
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4481
diff changeset
    21
 * questions.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    22
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    23
 */
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6247
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25351
diff changeset
    26
#include "gc/g1/g1CollectedHeap.inline.hpp"
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
    27
#include "gc/g1/g1DirtyCardQueue.hpp"
53482
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents: 53102
diff changeset
    28
#include "gc/g1/g1FreeIdSet.hpp"
46653
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    29
#include "gc/g1/g1RemSet.hpp"
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49333
diff changeset
    30
#include "gc/g1/g1ThreadLocalData.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25351
diff changeset
    31
#include "gc/g1/heapRegionRemSet.hpp"
52576
367ca5f32505 8213829: Remove circular dependency between g1CollectedHeap and g1ConcurrentMark
manc
parents: 49752
diff changeset
    32
#include "gc/shared/suspendibleThreadSet.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25351
diff changeset
    33
#include "gc/shared/workgroup.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 40012
diff changeset
    34
#include "runtime/atomic.hpp"
52726
9cfa2e273b77 8214278: Cleanup process_completed_threshold and related state
kbarrett
parents: 52684
diff changeset
    35
#include "runtime/flags/flagSetting.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6247
diff changeset
    36
#include "runtime/mutexLocker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6247
diff changeset
    37
#include "runtime/safepoint.hpp"
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 10565
diff changeset
    38
#include "runtime/thread.inline.hpp"
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47634
diff changeset
    39
#include "runtime/threadSMR.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    40
46653
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    41
// Closure used for updating remembered sets and recording references that
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    42
// point into the collection set while the mutator is running.
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    43
// Assumed to be only executed concurrently with the mutator. Yields via
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    44
// SuspendibleThreadSet after every card.
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
    45
class G1RefineCardConcurrentlyClosure: public G1CardTableEntryClosure {
46653
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    46
public:
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 54006
diff changeset
    47
  bool do_card_ptr(CardValue* card_ptr, uint worker_i) {
53985
0da5c17f5e43 8219747: Remove g1_ prefix to g1_remset and g1_policy members in G1CollectedHeap
tschatzl
parents: 53747
diff changeset
    48
    G1CollectedHeap::heap()->rem_set()->refine_card_concurrently(card_ptr, worker_i);
46653
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    49
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    50
    if (SuspendibleThreadSet::should_yield()) {
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    51
      // Caller will actually yield.
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    52
      return false;
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    53
    }
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    54
    // Otherwise, we finished successfully; return true.
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    55
    return true;
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    56
  }
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    57
};
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
    58
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54110
diff changeset
    59
G1DirtyCardQueue::G1DirtyCardQueue(G1DirtyCardQueueSet* qset) :
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    60
  // Dirty card queues are always active, so we create them with their
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    61
  // active field set to true.
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54110
diff changeset
    62
  PtrQueue(qset, true /* active */)
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    63
{ }
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    64
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
    65
G1DirtyCardQueue::~G1DirtyCardQueue() {
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54110
diff changeset
    66
  flush();
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    67
}
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    68
54970
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
    69
void G1DirtyCardQueue::handle_completed_buffer() {
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
    70
  assert(_buf != NULL, "precondition");
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
    71
  BufferNode* node = BufferNode::make_node_from_buffer(_buf, index());
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
    72
  G1DirtyCardQueueSet* dcqs = dirty_card_qset();
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
    73
  if (dcqs->process_or_enqueue_completed_buffer(node)) {
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
    74
    reset();                    // Buffer fully processed, reset index.
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
    75
  } else {
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
    76
    allocate_buffer();          // Buffer enqueued, get a new one.
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
    77
  }
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
    78
}
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
    79
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
    80
G1DirtyCardQueueSet::G1DirtyCardQueueSet(bool notify_when_complete) :
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
    81
  PtrQueueSet(),
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
    82
  _cbl_mon(NULL),
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
    83
  _completed_buffers_head(NULL),
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
    84
  _completed_buffers_tail(NULL),
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
    85
  _n_completed_buffers(0),
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
    86
  _process_completed_buffers_threshold(ProcessCompletedBuffersThresholdNever),
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
    87
  _process_completed_buffers(false),
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
    88
  _notify_when_complete(notify_when_complete),
54970
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
    89
  _max_completed_buffers(MaxCompletedBuffersUnlimited),
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
    90
  _completed_buffers_padding(0),
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    91
  _free_ids(NULL),
53034
de99beff5c0e 8214946: G1: Initialize all class members on construction
lkorinth
parents: 52726
diff changeset
    92
  _processed_buffers_mut(0),
de99beff5c0e 8214946: G1: Initialize all class members on construction
lkorinth
parents: 52726
diff changeset
    93
  _processed_buffers_rs_thread(0),
de99beff5c0e 8214946: G1: Initialize all class members on construction
lkorinth
parents: 52726
diff changeset
    94
  _cur_par_buffer_node(NULL)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    95
{
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    96
  _all_active = true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    97
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    98
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
    99
G1DirtyCardQueueSet::~G1DirtyCardQueueSet() {
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   100
  abandon_completed_buffers();
53482
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents: 53102
diff changeset
   101
  delete _free_ids;
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents: 53102
diff changeset
   102
}
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents: 53102
diff changeset
   103
2882
d508a8bac491 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 2881
diff changeset
   104
// Determines how many mutator threads can process the buffers in parallel.
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   105
uint G1DirtyCardQueueSet::num_par_ids() {
40012
f69cfe79fe98 8161993: G1 crashes if active_processor_count changes during startup
tschatzl
parents: 37197
diff changeset
   106
  return (uint)os::initial_active_processor_count();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   107
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   108
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   109
void G1DirtyCardQueueSet::initialize(Monitor* cbl_mon,
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   110
                                     BufferNode::Allocator* allocator,
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   111
                                     bool init_free_ids) {
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   112
  PtrQueueSet::initialize(allocator);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   113
  assert(_cbl_mon == NULL, "Init order issue?");
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   114
  _cbl_mon = cbl_mon;
35465
34ab60aee787 8145037: Clean up FreeIdSet usage
aharlap
parents: 35040
diff changeset
   115
  if (init_free_ids) {
53482
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents: 53102
diff changeset
   116
    _free_ids = new G1FreeIdSet(0, num_par_ids());
35465
34ab60aee787 8145037: Clean up FreeIdSet usage
aharlap
parents: 35040
diff changeset
   117
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   118
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   119
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53985
diff changeset
   120
void G1DirtyCardQueueSet::handle_zero_index_for_thread(Thread* t) {
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49333
diff changeset
   121
  G1ThreadLocalData::dirty_card_queue(t).handle_zero_index();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   122
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   123
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   124
void G1DirtyCardQueueSet::enqueue_completed_buffer(BufferNode* cbn) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   125
  MutexLocker x(_cbl_mon, Mutex::_no_safepoint_check_flag);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   126
  cbn->set_next(NULL);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   127
  if (_completed_buffers_tail == NULL) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   128
    assert(_completed_buffers_head == NULL, "Well-formedness");
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   129
    _completed_buffers_head = cbn;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   130
    _completed_buffers_tail = cbn;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   131
  } else {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   132
    _completed_buffers_tail->set_next(cbn);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   133
    _completed_buffers_tail = cbn;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   134
  }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   135
  _n_completed_buffers++;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   136
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   137
  if (!process_completed_buffers() &&
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   138
      (_n_completed_buffers > process_completed_buffers_threshold())) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   139
    set_process_completed_buffers(true);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   140
    if (_notify_when_complete) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   141
      _cbl_mon->notify_all();
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   142
    }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   143
  }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   144
  assert_completed_buffers_list_len_correct_locked();
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   145
}
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   146
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   147
BufferNode* G1DirtyCardQueueSet::get_completed_buffer(size_t stop_at) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   148
  MutexLocker x(_cbl_mon, Mutex::_no_safepoint_check_flag);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   149
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   150
  if (_n_completed_buffers <= stop_at) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   151
    return NULL;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   152
  }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   153
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   154
  assert(_n_completed_buffers > 0, "invariant");
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   155
  assert(_completed_buffers_head != NULL, "invariant");
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   156
  assert(_completed_buffers_tail != NULL, "invariant");
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   157
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   158
  BufferNode* bn = _completed_buffers_head;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   159
  _n_completed_buffers--;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   160
  _completed_buffers_head = bn->next();
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   161
  if (_completed_buffers_head == NULL) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   162
    assert(_n_completed_buffers == 0, "invariant");
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   163
    _completed_buffers_tail = NULL;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   164
    set_process_completed_buffers(false);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   165
  }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   166
  assert_completed_buffers_list_len_correct_locked();
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   167
  bn->set_next(NULL);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   168
  return bn;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   169
}
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   170
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   171
void G1DirtyCardQueueSet::abandon_completed_buffers() {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   172
  BufferNode* buffers_to_delete = NULL;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   173
  {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   174
    MutexLocker x(_cbl_mon, Mutex::_no_safepoint_check_flag);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   175
    buffers_to_delete = _completed_buffers_head;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   176
    _completed_buffers_head = NULL;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   177
    _completed_buffers_tail = NULL;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   178
    _n_completed_buffers = 0;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   179
    set_process_completed_buffers(false);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   180
  }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   181
  while (buffers_to_delete != NULL) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   182
    BufferNode* bn = buffers_to_delete;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   183
    buffers_to_delete = bn->next();
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   184
    bn->set_next(NULL);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   185
    deallocate_buffer(bn);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   186
  }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   187
}
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   188
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   189
void G1DirtyCardQueueSet::notify_if_necessary() {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   190
  MutexLocker x(_cbl_mon, Mutex::_no_safepoint_check_flag);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   191
  if (_n_completed_buffers > process_completed_buffers_threshold()) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   192
    set_process_completed_buffers(true);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   193
    if (_notify_when_complete)
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   194
      _cbl_mon->notify();
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   195
  }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   196
}
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   197
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   198
#ifdef ASSERT
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   199
void G1DirtyCardQueueSet::assert_completed_buffers_list_len_correct_locked() {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   200
  assert_lock_strong(_cbl_mon);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   201
  size_t n = 0;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   202
  for (BufferNode* bn = _completed_buffers_head; bn != NULL; bn = bn->next()) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   203
    ++n;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   204
  }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   205
  assert(n == _n_completed_buffers,
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   206
         "Completed buffer length is wrong: counted: " SIZE_FORMAT
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   207
         ", expected: " SIZE_FORMAT, n, _n_completed_buffers);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   208
}
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   209
#endif // ASSERT
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   210
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   211
// Merge lists of buffers. Notify the processing threads.
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   212
// The source queue is emptied as a result. The queues
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   213
// must share the monitor.
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   214
void G1DirtyCardQueueSet::merge_bufferlists(G1DirtyCardQueueSet *src) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   215
  assert(_cbl_mon == src->_cbl_mon, "Should share the same lock");
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   216
  MutexLocker x(_cbl_mon, Mutex::_no_safepoint_check_flag);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   217
  if (_completed_buffers_tail == NULL) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   218
    assert(_completed_buffers_head == NULL, "Well-formedness");
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   219
    _completed_buffers_head = src->_completed_buffers_head;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   220
    _completed_buffers_tail = src->_completed_buffers_tail;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   221
  } else {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   222
    assert(_completed_buffers_head != NULL, "Well formedness");
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   223
    if (src->_completed_buffers_head != NULL) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   224
      _completed_buffers_tail->set_next(src->_completed_buffers_head);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   225
      _completed_buffers_tail = src->_completed_buffers_tail;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   226
    }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   227
  }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   228
  _n_completed_buffers += src->_n_completed_buffers;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   229
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   230
  src->_n_completed_buffers = 0;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   231
  src->_completed_buffers_head = NULL;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   232
  src->_completed_buffers_tail = NULL;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   233
  src->set_process_completed_buffers(false);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   234
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   235
  assert(_completed_buffers_head == NULL && _completed_buffers_tail == NULL ||
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   236
         _completed_buffers_head != NULL && _completed_buffers_tail != NULL,
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   237
         "Sanity");
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   238
  assert_completed_buffers_list_len_correct_locked();
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   239
}
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   240
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   241
bool G1DirtyCardQueueSet::apply_closure_to_buffer(G1CardTableEntryClosure* cl,
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   242
                                                  BufferNode* node,
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   243
                                                  bool consume,
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   244
                                                  uint worker_i) {
37112
fe72d1d082ff 8151781: DirtyCardQueue::apply_closure is unused
kbarrett
parents: 37065
diff changeset
   245
  if (cl == NULL) return true;
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   246
  bool result = true;
37112
fe72d1d082ff 8151781: DirtyCardQueue::apply_closure is unused
kbarrett
parents: 37065
diff changeset
   247
  void** buf = BufferNode::make_buffer_from_node(node);
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   248
  size_t i = node->index();
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   249
  size_t limit = buffer_size();
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   250
  for ( ; i < limit; ++i) {
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 54006
diff changeset
   251
    CardTable::CardValue* card_ptr = static_cast<CardTable::CardValue*>(buf[i]);
37112
fe72d1d082ff 8151781: DirtyCardQueue::apply_closure is unused
kbarrett
parents: 37065
diff changeset
   252
    assert(card_ptr != NULL, "invariant");
fe72d1d082ff 8151781: DirtyCardQueue::apply_closure is unused
kbarrett
parents: 37065
diff changeset
   253
    if (!cl->do_card_ptr(card_ptr, worker_i)) {
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   254
      result = false;           // Incomplete processing.
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   255
      break;
37112
fe72d1d082ff 8151781: DirtyCardQueue::apply_closure is unused
kbarrett
parents: 37065
diff changeset
   256
    }
fe72d1d082ff 8151781: DirtyCardQueue::apply_closure is unused
kbarrett
parents: 37065
diff changeset
   257
  }
fe72d1d082ff 8151781: DirtyCardQueue::apply_closure is unused
kbarrett
parents: 37065
diff changeset
   258
  if (consume) {
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   259
    assert(i <= buffer_size(), "invariant");
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   260
    node->set_index(i);
37112
fe72d1d082ff 8151781: DirtyCardQueue::apply_closure is unused
kbarrett
parents: 37065
diff changeset
   261
  }
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   262
  return result;
37112
fe72d1d082ff 8151781: DirtyCardQueue::apply_closure is unused
kbarrett
parents: 37065
diff changeset
   263
}
fe72d1d082ff 8151781: DirtyCardQueue::apply_closure is unused
kbarrett
parents: 37065
diff changeset
   264
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   265
#ifndef ASSERT
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   266
#define assert_fully_consumed(node, buffer_size)
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   267
#else
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   268
#define assert_fully_consumed(node, buffer_size)                \
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   269
  do {                                                          \
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   270
    size_t _afc_index = (node)->index();                        \
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   271
    size_t _afc_size = (buffer_size);                           \
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   272
    assert(_afc_index == _afc_size,                             \
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   273
           "Buffer was not fully consumed as claimed: index: "  \
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   274
           SIZE_FORMAT ", size: " SIZE_FORMAT,                  \
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   275
            _afc_index, _afc_size);                             \
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   276
  } while (0)
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   277
#endif // ASSERT
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   278
54970
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   279
bool G1DirtyCardQueueSet::process_or_enqueue_completed_buffer(BufferNode* node) {
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   280
  if (Thread::current()->is_Java_thread()) {
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   281
    // If the number of buffers exceeds the limit, make this Java
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   282
    // thread do the processing itself.  We don't lock to access
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   283
    // buffer count or padding; it is fine to be imprecise here.  The
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   284
    // add of padding could overflow, which is treated as unlimited.
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   285
    size_t max_buffers = max_completed_buffers();
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   286
    size_t limit = max_buffers + completed_buffers_padding();
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   287
    if ((completed_buffers_num() > limit) && (limit >= max_buffers)) {
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   288
      if (mut_process_buffer(node)) {
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   289
        return true;
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   290
      }
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   291
    }
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   292
  }
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   293
  enqueue_completed_buffer(node);
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   294
  return false;
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   295
}
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54255
diff changeset
   296
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   297
bool G1DirtyCardQueueSet::mut_process_buffer(BufferNode* node) {
35465
34ab60aee787 8145037: Clean up FreeIdSet usage
aharlap
parents: 35040
diff changeset
   298
  guarantee(_free_ids != NULL, "must be");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   299
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   300
  uint worker_i = _free_ids->claim_par_id(); // temporarily claim an id
46653
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
   301
  G1RefineCardConcurrentlyClosure cl;
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
   302
  bool result = apply_closure_to_buffer(&cl, node, true, worker_i);
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   303
  _free_ids->release_par_id(worker_i); // release the id
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   304
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   305
  if (result) {
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   306
    assert_fully_consumed(node, buffer_size());
35481
53825bdb41a0 8145038: Simplify mut_process_buffer worker id management
aharlap
parents: 35465
diff changeset
   307
    Atomic::inc(&_processed_buffers_mut);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   308
  }
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   309
  return result;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   310
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   311
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   312
bool G1DirtyCardQueueSet::refine_completed_buffer_concurrently(uint worker_i, size_t stop_at) {
46653
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
   313
  G1RefineCardConcurrentlyClosure cl;
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
   314
  return apply_closure_to_completed_buffer(&cl, worker_i, stop_at, false);
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
   315
}
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
   316
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   317
bool G1DirtyCardQueueSet::apply_closure_during_gc(G1CardTableEntryClosure* cl, uint worker_i) {
49333
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 48105
diff changeset
   318
  assert_at_safepoint();
46653
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
   319
  return apply_closure_to_completed_buffer(cl, worker_i, 0, true);
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
   320
}
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46443
diff changeset
   321
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   322
bool G1DirtyCardQueueSet::apply_closure_to_completed_buffer(G1CardTableEntryClosure* cl,
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   323
                                                            uint worker_i,
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   324
                                                            size_t stop_at,
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   325
                                                            bool during_pause) {
6247
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 5547
diff changeset
   326
  assert(!during_pause || stop_at == 0, "Should not leave any completed buffers during a pause");
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 5547
diff changeset
   327
  BufferNode* nd = get_completed_buffer(stop_at);
36179
03a0d7b8450f 8149793: DirtyCardQueueSet::apply_closure_to_completed_buffer_helper isn't helpful
kbarrett
parents: 35902
diff changeset
   328
  if (nd == NULL) {
03a0d7b8450f 8149793: DirtyCardQueueSet::apply_closure_to_completed_buffer_helper isn't helpful
kbarrett
parents: 35902
diff changeset
   329
    return false;
03a0d7b8450f 8149793: DirtyCardQueueSet::apply_closure_to_completed_buffer_helper isn't helpful
kbarrett
parents: 35902
diff changeset
   330
  } else {
37112
fe72d1d082ff 8151781: DirtyCardQueue::apply_closure is unused
kbarrett
parents: 37065
diff changeset
   331
    if (apply_closure_to_buffer(cl, nd, true, worker_i)) {
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   332
      assert_fully_consumed(nd, buffer_size());
36179
03a0d7b8450f 8149793: DirtyCardQueueSet::apply_closure_to_completed_buffer_helper isn't helpful
kbarrett
parents: 35902
diff changeset
   333
      // Done with fully processed buffer.
37065
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   334
      deallocate_buffer(nd);
36179
03a0d7b8450f 8149793: DirtyCardQueueSet::apply_closure_to_completed_buffer_helper isn't helpful
kbarrett
parents: 35902
diff changeset
   335
      Atomic::inc(&_processed_buffers_rs_thread);
03a0d7b8450f 8149793: DirtyCardQueueSet::apply_closure_to_completed_buffer_helper isn't helpful
kbarrett
parents: 35902
diff changeset
   336
    } else {
03a0d7b8450f 8149793: DirtyCardQueueSet::apply_closure_to_completed_buffer_helper isn't helpful
kbarrett
parents: 35902
diff changeset
   337
      // Return partially processed buffer to the queue.
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   338
      guarantee(!during_pause, "Should never stop early");
53102
35530ca3e0b2 8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents: 53034
diff changeset
   339
      enqueue_completed_buffer(nd);
36179
03a0d7b8450f 8149793: DirtyCardQueueSet::apply_closure_to_completed_buffer_helper isn't helpful
kbarrett
parents: 35902
diff changeset
   340
    }
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37112
diff changeset
   341
    return true;
36179
03a0d7b8450f 8149793: DirtyCardQueueSet::apply_closure_to_completed_buffer_helper isn't helpful
kbarrett
parents: 35902
diff changeset
   342
  }
6247
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 5547
diff changeset
   343
}
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 5547
diff changeset
   344
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   345
void G1DirtyCardQueueSet::par_apply_closure_to_all_completed_buffers(G1CardTableEntryClosure* cl) {
24104
febf9363fb68 8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents: 23855
diff changeset
   346
  BufferNode* nd = _cur_par_buffer_node;
febf9363fb68 8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents: 23855
diff changeset
   347
  while (nd != NULL) {
37065
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   348
    BufferNode* next = nd->next();
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47216
diff changeset
   349
    BufferNode* actual = Atomic::cmpxchg(next, &_cur_par_buffer_node, nd);
24104
febf9363fb68 8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents: 23855
diff changeset
   350
    if (actual == nd) {
37112
fe72d1d082ff 8151781: DirtyCardQueue::apply_closure is unused
kbarrett
parents: 37065
diff changeset
   351
      bool b = apply_closure_to_buffer(cl, nd, false);
24104
febf9363fb68 8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents: 23855
diff changeset
   352
      guarantee(b, "Should not stop early.");
febf9363fb68 8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents: 23855
diff changeset
   353
      nd = next;
febf9363fb68 8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents: 23855
diff changeset
   354
    } else {
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47216
diff changeset
   355
      nd = actual;
24104
febf9363fb68 8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents: 23855
diff changeset
   356
    }
febf9363fb68 8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents: 23855
diff changeset
   357
  }
febf9363fb68 8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents: 23855
diff changeset
   358
}
febf9363fb68 8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents: 23855
diff changeset
   359
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   360
void G1DirtyCardQueueSet::abandon_logs() {
6247
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 5547
diff changeset
   361
  assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
53102
35530ca3e0b2 8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents: 53034
diff changeset
   362
  abandon_completed_buffers();
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53985
diff changeset
   363
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   364
  // Since abandon is done only at safepoints, we can safely manipulate
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   365
  // these queues.
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53985
diff changeset
   366
  struct AbandonThreadLogClosure : public ThreadClosure {
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53985
diff changeset
   367
    virtual void do_thread(Thread* t) {
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53985
diff changeset
   368
      G1ThreadLocalData::dirty_card_queue(t).reset();
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53985
diff changeset
   369
    }
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53985
diff changeset
   370
  } closure;
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53985
diff changeset
   371
  Threads::threads_do(&closure);
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53985
diff changeset
   372
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54110
diff changeset
   373
  G1BarrierSet::shared_dirty_card_queue().reset();
37065
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   374
}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   375
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 53482
diff changeset
   376
void G1DirtyCardQueueSet::concatenate_logs() {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   377
  // Iterate over all the threads, if we find a partial log add it to
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   378
  // the global list of logs.  Temporarily turn off the limit on the number
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   379
  // of outstanding buffers.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   380
  assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
53102
35530ca3e0b2 8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents: 53034
diff changeset
   381
  size_t old_limit = max_completed_buffers();
35530ca3e0b2 8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents: 53034
diff changeset
   382
  set_max_completed_buffers(MaxCompletedBuffersUnlimited);
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53985
diff changeset
   383
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54110
diff changeset
   384
  struct ConcatenateThreadLogClosure : public ThreadClosure {
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53985
diff changeset
   385
    virtual void do_thread(Thread* t) {
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54110
diff changeset
   386
      G1DirtyCardQueue& dcq = G1ThreadLocalData::dirty_card_queue(t);
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54110
diff changeset
   387
      if (!dcq.is_empty()) {
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54110
diff changeset
   388
        dcq.flush();
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54110
diff changeset
   389
      }
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53985
diff changeset
   390
    }
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54110
diff changeset
   391
  } closure;
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53985
diff changeset
   392
  Threads::threads_do(&closure);
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53985
diff changeset
   393
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54110
diff changeset
   394
  G1BarrierSet::shared_dirty_card_queue().flush();
53102
35530ca3e0b2 8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents: 53034
diff changeset
   395
  set_max_completed_buffers(old_limit);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   396
}