src/hotspot/share/gc/shared/satbMarkQueue.hpp
author kbarrett
Mon, 09 Sep 2019 16:54:48 -0400
changeset 58059 baa4dd528de0
parent 55498 e64383344f14
child 58679 9c3209ff7550
permissions -rw-r--r--
8221361: Eliminate two-phase initialization for PtrQueueSet classes Summary: Move allocator and CBL monitor init to constructor. 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
/*
53149
259c36ef27df 8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents: 52726
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
51441
2e91d927e00c 8154343: Make SATB related code available to other GCs
kbarrett
parents: 51401
diff changeset
    25
#ifndef SHARE_GC_SHARED_SATBMARKQUEUE_HPP
2e91d927e00c 8154343: Make SATB related code available to other GCs
kbarrett
parents: 51401
diff changeset
    26
#define SHARE_GC_SHARED_SATBMARKQUEUE_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
    27
51441
2e91d927e00c 8154343: Make SATB related code available to other GCs
kbarrett
parents: 51401
diff changeset
    28
#include "gc/shared/ptrQueue.hpp"
30577
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    29
#include "memory/allocation.hpp"
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
    30
#include "memory/padded.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
    31
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53149
diff changeset
    32
class Thread;
53149
259c36ef27df 8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents: 52726
diff changeset
    33
class Monitor;
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    34
class SATBMarkQueueSet;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    35
30577
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    36
// Base class for processing the contents of a SATB buffer.
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    37
class SATBBufferClosure : public StackObj {
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    38
protected:
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    39
  ~SATBBufferClosure() { }
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    40
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    41
public:
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    42
  // Process the SATB entries in the designated buffer range.
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    43
  virtual void do_buffer(void** buffer, size_t size) = 0;
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    44
};
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    45
33792
2bae5bf9e431 8077571: ObjPtrQueue is poorly named
kbarrett
parents: 33761
diff changeset
    46
// A PtrQueue whose elements are (possibly stale) pointers to object heads.
2bae5bf9e431 8077571: ObjPtrQueue is poorly named
kbarrett
parents: 33761
diff changeset
    47
class SATBMarkQueue: public PtrQueue {
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    48
  friend class SATBMarkQueueSet;
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    49
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    50
private:
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    51
  // Filter out unwanted entries from the buffer.
51278
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
    52
  inline void filter();
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    53
51278
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
    54
  // Removes entries from the buffer that are no longer needed.
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
    55
  template<typename Filter>
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
    56
  inline void apply_filter(Filter filter_out);
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
    57
54970
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
    58
protected:
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
    59
  virtual void handle_completed_buffer();
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
    60
51393
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
    61
public:
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54006
diff changeset
    62
  SATBMarkQueue(SATBMarkQueueSet* qset);
51393
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
    63
28507
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 27251
diff changeset
    64
  // Process queue entries and free resources.
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 27251
diff changeset
    65
  void flush();
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    66
54970
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
    67
  inline SATBMarkQueueSet* satb_qset() const;
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
    68
30577
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    69
  // Apply cl to the active part of the buffer.
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    70
  // Prerequisite: Must be at a safepoint.
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    71
  void apply_closure_and_empty(SATBBufferClosure* cl);
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    72
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    73
#ifndef PRODUCT
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    74
  // Helpful for debugging
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    75
  void print(const char* name);
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    76
#endif // PRODUCT
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    77
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    78
  // Compiler support.
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    79
  static ByteSize byte_offset_of_index() {
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    80
    return PtrQueue::byte_offset_of_index<SATBMarkQueue>();
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    81
  }
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    82
  using PtrQueue::byte_width_of_index;
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    83
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    84
  static ByteSize byte_offset_of_buf() {
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    85
    return PtrQueue::byte_offset_of_buf<SATBMarkQueue>();
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    86
  }
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    87
  using PtrQueue::byte_width_of_buf;
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    88
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    89
  static ByteSize byte_offset_of_active() {
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    90
    return PtrQueue::byte_offset_of_active<SATBMarkQueue>();
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    91
  }
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    92
  using PtrQueue::byte_width_of_active;
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    93
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    94
};
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
class SATBMarkQueueSet: public PtrQueueSet {
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
    97
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
    98
  DEFINE_PAD_MINUS_SIZE(1, DEFAULT_CACHE_LINE_SIZE, 0);
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
    99
  PaddedEnd<BufferNode::Stack> _list;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   100
  volatile size_t _count_and_process_flag;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   101
  // These are rarely (if ever) changed, so same cache line as count.
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   102
  size_t _process_completed_buffers_threshold;
51401
58113ce90caf 8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents: 51393
diff changeset
   103
  size_t _buffer_enqueue_threshold;
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   104
  DEFINE_PAD_MINUS_SIZE(2, DEFAULT_CACHE_LINE_SIZE, 3 * sizeof(size_t));
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   105
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   106
  BufferNode* get_completed_buffer();
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   107
  void abandon_completed_buffers();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   108
5082
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   109
#ifdef ASSERT
22497
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 11455
diff changeset
   110
  void dump_active_states(bool expected_active);
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 11455
diff changeset
   111
  void verify_active_states(bool expected_active);
5082
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   112
#endif // ASSERT
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   113
51393
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   114
protected:
58059
baa4dd528de0 8221361: Eliminate two-phase initialization for PtrQueueSet classes
kbarrett
parents: 55498
diff changeset
   115
  SATBMarkQueueSet(BufferNode::Allocator* allocator);
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   116
  ~SATBMarkQueueSet();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   117
51393
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   118
  template<typename Filter>
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   119
  void apply_filter(Filter filter, SATBMarkQueue* queue) {
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   120
    queue->apply_filter(filter);
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   121
  }
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   122
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   123
public:
54006
a421bdf22394 8219613: Use NonJavaThread PtrQueues
kbarrett
parents: 53149
diff changeset
   124
  virtual SATBMarkQueue& satb_queue_for_thread(Thread* const t) const = 0;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   125
22497
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 11455
diff changeset
   126
  // Apply "set_active(active)" to all SATB queues in the set. It should be
5082
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   127
  // called only with the world stopped. The method will assert that the
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   128
  // SATB queues of all threads it visits, as well as the SATB queue
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   129
  // set itself, has an active value same as expected_active.
22497
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 11455
diff changeset
   130
  void set_active_all_threads(bool active, bool expected_active);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   131
58059
baa4dd528de0 8221361: Eliminate two-phase initialization for PtrQueueSet classes
kbarrett
parents: 55498
diff changeset
   132
  void set_process_completed_buffers_threshold(size_t value);
baa4dd528de0 8221361: Eliminate two-phase initialization for PtrQueueSet classes
kbarrett
parents: 55498
diff changeset
   133
51401
58113ce90caf 8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents: 51393
diff changeset
   134
  size_t buffer_enqueue_threshold() const { return _buffer_enqueue_threshold; }
58059
baa4dd528de0 8221361: Eliminate two-phase initialization for PtrQueueSet classes
kbarrett
parents: 55498
diff changeset
   135
  void set_buffer_enqueue_threshold_percentage(uint value);
baa4dd528de0 8221361: Eliminate two-phase initialization for PtrQueueSet classes
kbarrett
parents: 55498
diff changeset
   136
51393
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   137
  virtual void filter(SATBMarkQueue* queue) = 0;
51278
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   138
30577
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
   139
  // If there exists some completed buffer, pop and process it, and
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
   140
  // return true.  Otherwise return false.  Processing a buffer
37065
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 34148
diff changeset
   141
  // consists of applying the closure to the active range of the
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 34148
diff changeset
   142
  // buffer; the leading entries may be excluded due to filtering.
30577
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
   143
  bool apply_closure_to_completed_buffer(SATBBufferClosure* cl);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   144
55498
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   145
  virtual void enqueue_completed_buffer(BufferNode* node);
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
  // The number of buffers in the list.  Racy and not updated atomically
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   148
  // with the set of completed buffers.
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   149
  size_t completed_buffers_num() const {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   150
    return _count_and_process_flag >> 1;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   151
  }
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
  // Return true if completed buffers should be processed.
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   154
  bool process_completed_buffers() const {
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   155
    return (_count_and_process_flag & 1) != 0;
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   156
  }
e64383344f14 8225255: Make SATB qset lock-free
kbarrett
parents: 54970
diff changeset
   157
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
   158
#ifndef PRODUCT
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
   159
  // Helpful for debugging
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
   160
  void print_all(const char* msg);
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
   161
#endif // PRODUCT
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
   162
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   163
  // If a marking is being abandoned, reset any unprocessed log buffers.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   164
  void abandon_partial_marking();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   165
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
   166
54970
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
   167
inline SATBMarkQueueSet* SATBMarkQueue::satb_qset() const {
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
   168
  return static_cast<SATBMarkQueueSet*>(qset());
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
   169
}
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
   170
51278
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   171
inline void SATBMarkQueue::filter() {
54970
76d3d96a8bc2 8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents: 54713
diff changeset
   172
  satb_qset()->filter(this);
51278
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   173
}
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   174
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   175
// Removes entries from the buffer that are no longer needed, as
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   176
// determined by filter. If e is a void* entry in the buffer,
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   177
// filter_out(e) must be a valid expression whose value is convertible
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   178
// to bool. Entries are removed (filtered out) if the result is true,
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   179
// retained if false.
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   180
template<typename Filter>
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   181
inline void SATBMarkQueue::apply_filter(Filter filter_out) {
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   182
  void** buf = this->_buf;
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   183
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   184
  if (buf == NULL) {
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   185
    // nothing to do
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   186
    return;
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   187
  }
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   188
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   189
  // Two-fingered compaction toward the end.
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   190
  void** src = &buf[this->index()];
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   191
  void** dst = &buf[this->capacity()];
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   192
  assert(src <= dst, "invariant");
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   193
  for ( ; src < dst; ++src) {
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   194
    // Search low to high for an entry to keep.
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   195
    void* entry = *src;
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   196
    if (!filter_out(entry)) {
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   197
      // Found keeper.  Search high to low for an entry to discard.
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   198
      while (src < --dst) {
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   199
        if (filter_out(*dst)) {
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   200
          *dst = entry;         // Replace discard with keeper.
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   201
          break;
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   202
        }
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   203
      }
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   204
      // If discard search failed (src == dst), the outer loop will also end.
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   205
    }
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   206
  }
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   207
  // dst points to the lowest retained entry, or the end of the buffer
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   208
  // if all the entries were filtered out.
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   209
  this->set_index(dst - buf);
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   210
}
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   211
51441
2e91d927e00c 8154343: Make SATB related code available to other GCs
kbarrett
parents: 51401
diff changeset
   212
#endif // SHARE_GC_SHARED_SATBMARKQUEUE_HPP