src/hotspot/share/gc/shared/satbMarkQueue.cpp
author kbarrett
Wed, 26 Jun 2019 13:18:38 -0400
changeset 55498 e64383344f14
parent 54970 76d3d96a8bc2
child 58059 baa4dd528de0
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
/*
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
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: 5082
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5082
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: 5082
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: 5547
diff changeset
    25
#include "precompiled.hpp"
51441
2e91d927e00c 8154343: Make SATB related code available to other GCs
kbarrett
parents: 51403
diff changeset
    26
#include "gc/shared/satbMarkQueue.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30577
diff changeset
    27
#include "gc/shared/collectedHeap.hpp"
51393
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
    28
#include "logging/log.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/allocation.inline.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    30
#include "oops/oop.inline.hpp"
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
    31
#include "runtime/atomic.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/mutexLocker.hpp"
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
    33
#include "runtime/orderAccess.hpp"
51403
0f3bfea3acf1 8209347: SATBMarkQueue.cpp should not need jvm.h
kbarrett
parents: 51401
diff changeset
    34
#include "runtime/os.hpp"
30577
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    35
#include "runtime/safepoint.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "runtime/thread.hpp"
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47765
diff changeset
    37
#include "runtime/threadSMR.hpp"
10670
4ea0e7d2ffbc 6484982: G1: process references during evacuation pauses
johnc
parents: 7920
diff changeset
    38
#include "runtime/vmThread.hpp"
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
    39
#include "utilities/globalCounter.inline.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    40
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54006
diff changeset
    41
SATBMarkQueue::SATBMarkQueue(SATBMarkQueueSet* qset) :
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 33105
diff changeset
    42
  // SATB queues are only active during marking cycles. We create
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 33105
diff changeset
    43
  // them with their active field set to false. If a thread is
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 33105
diff changeset
    44
  // created during a cycle and its SATB queue needs to be activated
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 33105
diff changeset
    45
  // before the thread starts running, we'll need to set its active
51401
58113ce90caf 8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents: 51393
diff changeset
    46
  // field to true. This must be done in the collector-specific
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
    47
  // BarrierSet thread attachment protocol.
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54006
diff changeset
    48
  PtrQueue(qset, false /* active */)
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 33105
diff changeset
    49
{ }
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 33105
diff changeset
    50
33792
2bae5bf9e431 8077571: ObjPtrQueue is poorly named
kbarrett
parents: 33786
diff changeset
    51
void SATBMarkQueue::flush() {
30255
f43e306ec51e 8075466: SATB queue pre-filter verify found reclaimed humongous object
kbarrett
parents: 30154
diff changeset
    52
  // Filter now to possibly save work later.  If filtering empties the
f43e306ec51e 8075466: SATB queue pre-filter verify found reclaimed humongous object
kbarrett
parents: 30154
diff changeset
    53
  // buffer then flush_impl can deallocate the buffer.
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
    54
  filter();
28507
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 27251
diff changeset
    55
  flush_impl();
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
    56
}
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
    57
51278
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 49752
diff changeset
    58
// This method will first apply filtering to the buffer. If filtering
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 49752
diff changeset
    59
// retains a small enough collection in the buffer, we can continue to
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 49752
diff changeset
    60
// use the buffer as-is, instead of enqueueing and replacing it.
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
    61
54970
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
    62
void SATBMarkQueue::handle_completed_buffer() {
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
    63
  // This method should only be called if there is a non-NULL buffer
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
    64
  // that is full.
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
    65
  assert(index() == 0, "pre-condition");
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
    66
  assert(_buf != NULL, "pre-condition");
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
    67
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
    68
  filter();
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
    69
54970
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
    70
  size_t threshold = satb_qset()->buffer_enqueue_threshold();
51401
58113ce90caf 8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents: 51393
diff changeset
    71
  // Ensure we'll enqueue completely full buffers.
58113ce90caf 8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents: 51393
diff changeset
    72
  assert(threshold > 0, "enqueue threshold = 0");
58113ce90caf 8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents: 51393
diff changeset
    73
  // Ensure we won't enqueue empty buffers.
58113ce90caf 8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents: 51393
diff changeset
    74
  assert(threshold <= capacity(),
58113ce90caf 8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents: 51393
diff changeset
    75
         "enqueue threshold " SIZE_FORMAT " exceeds capacity " SIZE_FORMAT,
58113ce90caf 8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents: 51393
diff changeset
    76
         threshold, capacity());
54970
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
    77
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
    78
  if (index() < threshold) {
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
    79
    // Buffer is sufficiently full; enqueue and allocate a new one.
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
    80
    enqueue_completed_buffer();
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
    81
  } // Else continue to accumulate in buffer.
7920
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
    82
}
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
    83
33792
2bae5bf9e431 8077571: ObjPtrQueue is poorly named
kbarrett
parents: 33786
diff changeset
    84
void SATBMarkQueue::apply_closure_and_empty(SATBBufferClosure* cl) {
30577
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    85
  assert(SafepointSynchronize::is_at_safepoint(),
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    86
         "SATB queues must only be processed at safepoints");
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
    87
  if (_buf != NULL) {
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
    88
    cl->do_buffer(&_buf[index()], size());
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
    89
    reset();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    90
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    91
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    92
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
    93
#ifndef PRODUCT
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
    94
// Helpful for debugging
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
    95
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
    96
static void print_satb_buffer(const char* name,
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
    97
                              void** buf,
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
    98
                              size_t index,
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
    99
                              size_t capacity) {
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
   100
  tty->print_cr("  SATB BUFFER [%s] buf: " PTR_FORMAT " index: " SIZE_FORMAT
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
   101
                " capacity: " SIZE_FORMAT,
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
   102
                name, p2i(buf), index, capacity);
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   103
}
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   104
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
   105
void SATBMarkQueue::print(const char* name) {
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
   106
  print_satb_buffer(name, _buf, index(), capacity());
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   107
}
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
   108
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   109
#endif // PRODUCT
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   110
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   111
SATBMarkQueueSet::SATBMarkQueueSet() :
30268
d28a9aa10804 8078021: SATB apply_closure_to_completed_buffer should have closure argument
kbarrett
parents: 30255
diff changeset
   112
  PtrQueueSet(),
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   113
  _list(),
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   114
  _count_and_process_flag(0),
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   115
  _process_completed_buffers_threshold(SIZE_MAX),
51401
58113ce90caf 8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents: 51393
diff changeset
   116
  _buffer_enqueue_threshold(0)
51278
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 49752
diff changeset
   117
{}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   118
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   119
SATBMarkQueueSet::~SATBMarkQueueSet() {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   120
  abandon_completed_buffers();
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   121
}
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   122
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   123
// _count_and_process_flag has flag in least significant bit, count in
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   124
// remaining bits.  _process_completed_buffers_threshold is scaled
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   125
// accordingly, with the lsbit set, so a _count_and_process_flag value
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   126
// is directly comparable with the recorded threshold value.  The
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   127
// process flag is set whenever the count exceeds the threshold, and
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   128
// remains set until the count is reduced to zero.
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   129
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   130
// Increment count.  If count > threshold, set flag, else maintain flag.
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   131
static void increment_count(volatile size_t* cfptr, size_t threshold) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   132
  size_t old;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   133
  size_t value = Atomic::load(cfptr);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   134
  do {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   135
    old = value;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   136
    value += 2;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   137
    assert(value > old, "overflow");
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   138
    if (value > threshold) value |= 1;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   139
    value = Atomic::cmpxchg(value, cfptr, old);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   140
  } while (value != old);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   141
}
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
// Decrement count.  If count == 0, clear flag, else maintain flag.
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   144
static void decrement_count(volatile size_t* cfptr) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   145
  size_t old;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   146
  size_t value = Atomic::load(cfptr);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   147
  do {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   148
    assert((value >> 1) != 0, "underflow");
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   149
    old = value;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   150
    value -= 2;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   151
    if (value <= 1) value = 0;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   152
    value = Atomic::cmpxchg(value, cfptr, old);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   153
  } while (value != old);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   154
}
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   155
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   156
// Scale requested threshold to align with count field.  If scaling
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   157
// overflows, just use max value.  Set process flag field to make
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   158
// comparison in increment_count exact.
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   159
static size_t scale_threshold(size_t value) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   160
  size_t scaled_value = value << 1;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   161
  if ((scaled_value >> 1) != value) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   162
    scaled_value = SIZE_MAX;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   163
  }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   164
  return scaled_value | 1;
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
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   167
void SATBMarkQueueSet::initialize(BufferNode::Allocator* allocator,
52726
9cfa2e273b77 8214278: Cleanup process_completed_threshold and related state
kbarrett
parents: 52582
diff changeset
   168
                                  size_t process_completed_buffers_threshold,
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   169
                                  uint buffer_enqueue_threshold_percentage) {
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   170
  PtrQueueSet::initialize(allocator);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   171
  _process_completed_buffers_threshold =
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   172
    scale_threshold(process_completed_buffers_threshold);
51401
58113ce90caf 8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents: 51393
diff changeset
   173
  assert(buffer_size() != 0, "buffer size not initialized");
58113ce90caf 8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents: 51393
diff changeset
   174
  // Minimum threshold of 1 ensures enqueuing of completely full buffers.
58113ce90caf 8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents: 51393
diff changeset
   175
  size_t size = buffer_size();
58113ce90caf 8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents: 51393
diff changeset
   176
  size_t enqueue_qty = (size * buffer_enqueue_threshold_percentage) / 100;
58113ce90caf 8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents: 51393
diff changeset
   177
  _buffer_enqueue_threshold = MAX2(size - enqueue_qty, (size_t)1);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   178
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   179
5082
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   180
#ifdef ASSERT
22497
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 13728
diff changeset
   181
void SATBMarkQueueSet::dump_active_states(bool expected_active) {
36090
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35061
diff changeset
   182
  log_error(gc, verify)("Expected SATB active state: %s", expected_active ? "ACTIVE" : "INACTIVE");
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35061
diff changeset
   183
  log_error(gc, verify)("Actual SATB active states:");
cffc1dd98258 8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents: 35061
diff changeset
   184
  log_error(gc, verify)("  Queue set: %s", is_active() ? "ACTIVE" : "INACTIVE");
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   185
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   186
  class DumpThreadStateClosure : public ThreadClosure {
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   187
    SATBMarkQueueSet* _qset;
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   188
  public:
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   189
    DumpThreadStateClosure(SATBMarkQueueSet* qset) : _qset(qset) {}
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   190
    virtual void do_thread(Thread* t) {
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   191
      SATBMarkQueue& queue = _qset->satb_queue_for_thread(t);
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   192
      log_error(gc, verify)("  Thread \"%s\" queue: %s",
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   193
                            t->name(),
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   194
                            queue.is_active() ? "ACTIVE" : "INACTIVE");
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   195
    }
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   196
  } closure(this);
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   197
  Threads::threads_do(&closure);
22497
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 13728
diff changeset
   198
}
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 13728
diff changeset
   199
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 13728
diff changeset
   200
void SATBMarkQueueSet::verify_active_states(bool expected_active) {
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 13728
diff changeset
   201
  // Verify queue set state
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 13728
diff changeset
   202
  if (is_active() != expected_active) {
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 13728
diff changeset
   203
    dump_active_states(expected_active);
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   204
    fatal("SATB queue set has an unexpected active state");
22497
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 13728
diff changeset
   205
  }
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 13728
diff changeset
   206
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 13728
diff changeset
   207
  // Verify thread queue states
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   208
  class VerifyThreadStatesClosure : public ThreadClosure {
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   209
    SATBMarkQueueSet* _qset;
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   210
    bool _expected_active;
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   211
  public:
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   212
    VerifyThreadStatesClosure(SATBMarkQueueSet* qset, bool expected_active) :
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   213
      _qset(qset), _expected_active(expected_active) {}
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   214
    virtual void do_thread(Thread* t) {
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   215
      if (_qset->satb_queue_for_thread(t).is_active() != _expected_active) {
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   216
        _qset->dump_active_states(_expected_active);
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   217
        fatal("Thread SATB queue has an unexpected active state");
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   218
      }
22497
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 13728
diff changeset
   219
    }
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   220
  } closure(this, expected_active);
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   221
  Threads::threads_do(&closure);
5082
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   222
}
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   223
#endif // ASSERT
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   224
22497
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 13728
diff changeset
   225
void SATBMarkQueueSet::set_active_all_threads(bool active, bool expected_active) {
5082
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   226
  assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   227
#ifdef ASSERT
22497
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 13728
diff changeset
   228
  verify_active_states(expected_active);
5082
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   229
#endif // ASSERT
54366
2b48cedce327 8220671: Initialization race for non-JavaThread PtrQueues
kbarrett
parents: 54255
diff changeset
   230
  // Update the global state, synchronized with threads list management.
2b48cedce327 8220671: Initialization race for non-JavaThread PtrQueues
kbarrett
parents: 54255
diff changeset
   231
  {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54366
diff changeset
   232
    MutexLocker ml(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
54366
2b48cedce327 8220671: Initialization race for non-JavaThread PtrQueues
kbarrett
parents: 54255
diff changeset
   233
    _all_active = active;
2b48cedce327 8220671: Initialization race for non-JavaThread PtrQueues
kbarrett
parents: 54255
diff changeset
   234
  }
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   235
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   236
  class SetThreadActiveClosure : public ThreadClosure {
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   237
    SATBMarkQueueSet* _qset;
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   238
    bool _active;
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   239
  public:
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   240
    SetThreadActiveClosure(SATBMarkQueueSet* qset, bool active) :
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   241
      _qset(qset), _active(active) {}
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   242
    virtual void do_thread(Thread* t) {
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   243
      _qset->satb_queue_for_thread(t).set_active(_active);
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   244
    }
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   245
  } closure(this, active);
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   246
  Threads::threads_do(&closure);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   247
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   248
30577
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
   249
bool SATBMarkQueueSet::apply_closure_to_completed_buffer(SATBBufferClosure* cl) {
53102
35530ca3e0b2 8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents: 52726
diff changeset
   250
  BufferNode* nd = get_completed_buffer();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   251
  if (nd != NULL) {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 3262
diff changeset
   252
    void **buf = BufferNode::make_buffer_from_node(nd);
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
   253
    size_t index = nd->index();
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
   254
    size_t size = buffer_size();
37065
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36090
diff changeset
   255
    assert(index <= size, "invariant");
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36090
diff changeset
   256
    cl->do_buffer(buf + index, size - index);
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36090
diff changeset
   257
    deallocate_buffer(nd);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   258
    return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   259
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   260
    return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   261
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   262
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   263
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   264
// SATB buffer life-cycle - Per-thread queues obtain buffers from the
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   265
// qset's buffer allocator, fill them, and push them onto the qset's
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   266
// list.  The GC concurrently pops buffers from the qset, processes
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   267
// them, and returns them to the buffer allocator for re-use.  Both
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   268
// the allocator and the qset use lock-free stacks.  The ABA problem
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   269
// is solved by having both allocation pops and GC pops performed
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   270
// within GlobalCounter critical sections, while the return of buffers
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   271
// to the allocator performs a GlobalCounter synchronize before
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   272
// pushing onto the allocator's list.
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   273
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   274
void SATBMarkQueueSet::enqueue_completed_buffer(BufferNode* node) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   275
  assert(node != NULL, "precondition");
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   276
  // Increment count and update flag appropriately.  Done before
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   277
  // pushing buffer so count is always at least the actual number in
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   278
  // the list, and decrement never underflows.
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   279
  increment_count(&_count_and_process_flag, _process_completed_buffers_threshold);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   280
  _list.push(*node);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   281
}
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   282
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   283
BufferNode* SATBMarkQueueSet::get_completed_buffer() {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   284
  BufferNode* node;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   285
  {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   286
    GlobalCounter::CriticalSection cs(Thread::current());
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   287
    node = _list.pop();
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   288
  }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   289
  if (node != NULL) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   290
    // Got a buffer so decrement count and update flag appropriately.
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   291
    decrement_count(&_count_and_process_flag);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   292
  }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   293
  return node;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   294
}
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   295
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   296
#ifndef PRODUCT
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   297
// Helpful for debugging
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   298
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   299
#define SATB_PRINTER_BUFFER_SIZE 256
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   300
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   301
void SATBMarkQueueSet::print_all(const char* msg) {
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   302
  char buffer[SATB_PRINTER_BUFFER_SIZE];
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   303
  assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   304
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33792
diff changeset
   305
  tty->cr();
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33792
diff changeset
   306
  tty->print_cr("SATB BUFFERS [%s]", msg);
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   307
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   308
  BufferNode* nd = _list.top();
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   309
  int i = 0;
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   310
  while (nd != NULL) {
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   311
    void** buf = BufferNode::make_buffer_from_node(nd);
51403
0f3bfea3acf1 8209347: SATBMarkQueue.cpp should not need jvm.h
kbarrett
parents: 51401
diff changeset
   312
    os::snprintf(buffer, SATB_PRINTER_BUFFER_SIZE, "Enqueued: %d", i);
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 37065
diff changeset
   313
    print_satb_buffer(buffer, buf, nd->index(), buffer_size());
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   314
    nd = nd->next();
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   315
    i += 1;
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   316
  }
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   317
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   318
  class PrintThreadClosure : public ThreadClosure {
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   319
    SATBMarkQueueSet* _qset;
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   320
    char* _buffer;
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   321
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   322
  public:
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   323
    PrintThreadClosure(SATBMarkQueueSet* qset, char* buffer) :
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   324
      _qset(qset), _buffer(buffer) {}
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   325
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   326
    virtual void do_thread(Thread* t) {
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   327
      os::snprintf(_buffer, SATB_PRINTER_BUFFER_SIZE, "Thread: %s", t->name());
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   328
      _qset->satb_queue_for_thread(t).print(_buffer);
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   329
    }
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   330
  } closure(this, buffer);
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   331
  Threads::threads_do(&closure);
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   332
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33792
diff changeset
   333
  tty->cr();
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   334
}
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   335
#endif // PRODUCT
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 10670
diff changeset
   336
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   337
void SATBMarkQueueSet::abandon_completed_buffers() {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   338
  Atomic::store(size_t(0), &_count_and_process_flag);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   339
  BufferNode* buffers_to_delete = _list.pop_all();
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   340
  while (buffers_to_delete != NULL) {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   341
    BufferNode* bn = buffers_to_delete;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   342
    buffers_to_delete = bn->next();
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   343
    bn->set_next(NULL);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   344
    deallocate_buffer(bn);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   345
  }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   346
}
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   347
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   348
void SATBMarkQueueSet::abandon_partial_marking() {
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   349
  assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
53102
35530ca3e0b2 8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents: 52726
diff changeset
   350
  abandon_completed_buffers();
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   351
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   352
  class AbandonThreadQueueClosure : public ThreadClosure {
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   353
    SATBMarkQueueSet* _qset;
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   354
  public:
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   355
    AbandonThreadQueueClosure(SATBMarkQueueSet* qset) : _qset(qset) {}
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   356
    virtual void do_thread(Thread* t) {
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   357
      _qset->satb_queue_for_thread(t).reset();
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   358
    }
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   359
  } closure(this);
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53102
diff changeset
   360
  Threads::threads_do(&closure);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   361
}