src/hotspot/share/gc/g1/satbMarkQueue.hpp
author kbarrett
Tue, 14 Aug 2018 00:15:56 -0400
changeset 51393 cc8d309cd05a
parent 51368 adcb0bb3d1e9
child 51401 58113ce90caf
permissions -rw-r--r--
8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet Summary: Move filter extension protocol to SATBMarkQueueSet. Reviewed-by: shade, tschatzl, rkennke
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
/*
51278
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
     2
 * Copyright (c) 2001, 2018, 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
33792
2bae5bf9e431 8077571: ObjPtrQueue is poorly named
kbarrett
parents: 33761
diff changeset
    25
#ifndef SHARE_VM_GC_G1_SATBMARKQUEUE_HPP
2bae5bf9e431 8077571: ObjPtrQueue is poorly named
kbarrett
parents: 33761
diff changeset
    26
#define SHARE_VM_GC_G1_SATBMARKQUEUE_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
    27
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30577
diff changeset
    28
#include "gc/g1/ptrQueue.hpp"
30577
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    29
#include "memory/allocation.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
    30
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    31
class JavaThread;
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    32
class SATBMarkQueueSet;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    33
30577
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    34
// Base class for processing the contents of a SATB buffer.
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    35
class SATBBufferClosure : public StackObj {
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    36
protected:
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    37
  ~SATBBufferClosure() { }
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    38
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    39
public:
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    40
  // Process the SATB entries in the designated buffer range.
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    41
  virtual void do_buffer(void** buffer, size_t size) = 0;
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    42
};
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    43
33792
2bae5bf9e431 8077571: ObjPtrQueue is poorly named
kbarrett
parents: 33761
diff changeset
    44
// A PtrQueue whose elements are (possibly stale) pointers to object heads.
2bae5bf9e431 8077571: ObjPtrQueue is poorly named
kbarrett
parents: 33761
diff changeset
    45
class SATBMarkQueue: public PtrQueue {
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    46
  friend class SATBMarkQueueSet;
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    47
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    48
private:
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    49
  // Filter out unwanted entries from the buffer.
51278
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
    50
  inline void filter();
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    51
51278
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
    52
  // 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
    53
  template<typename Filter>
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
    54
  inline void apply_filter(Filter filter_out);
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
    55
51393
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
    56
public:
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
    57
  SATBMarkQueue(SATBMarkQueueSet* qset, bool permanent = false);
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
    58
28507
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 27251
diff changeset
    59
  // Process queue entries and free resources.
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 27251
diff changeset
    60
  void flush();
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    61
30577
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    62
  // Apply cl to the active part of the buffer.
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    63
  // Prerequisite: Must be at a safepoint.
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    64
  void apply_closure_and_empty(SATBBufferClosure* cl);
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
    65
7920
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
    66
  // Overrides PtrQueue::should_enqueue_buffer(). See the method's
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
    67
  // definition for more information.
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
    68
  virtual bool should_enqueue_buffer();
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
    69
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    70
#ifndef PRODUCT
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    71
  // Helpful for debugging
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    72
  void print(const char* name);
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
    73
#endif // PRODUCT
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    74
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    75
  // Compiler support.
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    76
  static ByteSize byte_offset_of_index() {
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    77
    return PtrQueue::byte_offset_of_index<SATBMarkQueue>();
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    78
  }
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    79
  using PtrQueue::byte_width_of_index;
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    80
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    81
  static ByteSize byte_offset_of_buf() {
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    82
    return PtrQueue::byte_offset_of_buf<SATBMarkQueue>();
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
  using PtrQueue::byte_width_of_buf;
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    85
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    86
  static ByteSize byte_offset_of_active() {
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    87
    return PtrQueue::byte_offset_of_active<SATBMarkQueue>();
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
  using PtrQueue::byte_width_of_active;
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33792
diff changeset
    90
1374
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    93
class SATBMarkQueueSet: public PtrQueueSet {
33792
2bae5bf9e431 8077571: ObjPtrQueue is poorly named
kbarrett
parents: 33761
diff changeset
    94
  SATBMarkQueue _shared_satb_queue;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    95
5082
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
    96
#ifdef ASSERT
22497
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 11455
diff changeset
    97
  void dump_active_states(bool expected_active);
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 11455
diff changeset
    98
  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
    99
#endif // ASSERT
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   100
51393
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   101
protected:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   102
  SATBMarkQueueSet();
51393
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   103
  ~SATBMarkQueueSet() {}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   104
51393
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   105
  template<typename Filter>
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   106
  void apply_filter(Filter filter, SATBMarkQueue* queue) {
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   107
    queue->apply_filter(filter);
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   108
  }
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   109
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   110
  void initialize(Monitor* cbl_mon, Mutex* fl_lock,
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 3262
diff changeset
   111
                  int process_completed_threshold,
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 3262
diff changeset
   112
                  Mutex* lock);
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
public:
51368
adcb0bb3d1e9 8209118: Abstract SATBMarkQueueSet's ThreadLocalData access
rkennke
parents: 51278
diff changeset
   115
  virtual SATBMarkQueue& satb_queue_for_thread(JavaThread* const t) const = 0;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   116
22497
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 11455
diff changeset
   117
  // 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
   118
  // 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
   119
  // 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
   120
  // set itself, has an active value same as expected_active.
22497
b2e1896e9616 8029162: G1: Shared SATB queue never enabled
pliden
parents: 11455
diff changeset
   121
  void set_active_all_threads(bool active, bool expected_active);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   122
51393
cc8d309cd05a 8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents: 51368
diff changeset
   123
  virtual void filter(SATBMarkQueue* queue) = 0;
51278
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   124
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
   125
  // Filter all the currently-active SATB buffers.
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
   126
  void filter_thread_buffers();
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
   127
30577
de9fa7ccc1bc 8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents: 30279
diff changeset
   128
  // 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
   129
  // return true.  Otherwise return false.  Processing a buffer
37065
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 34148
diff changeset
   130
  // consists of applying the closure to the active range of the
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 34148
diff changeset
   131
  // 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
   132
  bool apply_closure_to_completed_buffer(SATBBufferClosure* cl);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   133
11455
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
   134
#ifndef PRODUCT
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
   135
  // Helpful for debugging
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
   136
  void print_all(const char* msg);
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
   137
#endif // PRODUCT
a6ab3d8b9a4c 6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents: 7920
diff changeset
   138
33792
2bae5bf9e431 8077571: ObjPtrQueue is poorly named
kbarrett
parents: 33761
diff changeset
   139
  SATBMarkQueue* shared_satb_queue() { return &_shared_satb_queue; }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   140
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   141
  // If a marking is being abandoned, reset any unprocessed log buffers.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   142
  void abandon_partial_marking();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   143
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
   144
51278
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   145
inline void SATBMarkQueue::filter() {
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   146
  static_cast<SATBMarkQueueSet*>(qset())->filter(this);
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   147
}
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   148
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   149
// 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
   150
// 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
   151
// 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
   152
// 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
   153
// retained if false.
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   154
template<typename Filter>
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   155
inline void SATBMarkQueue::apply_filter(Filter filter_out) {
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   156
  void** buf = this->_buf;
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   157
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   158
  if (buf == NULL) {
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   159
    // nothing to do
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   160
    return;
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   161
  }
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   162
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   163
  // Two-fingered compaction toward the end.
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   164
  void** src = &buf[this->index()];
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   165
  void** dst = &buf[this->capacity()];
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   166
  assert(src <= dst, "invariant");
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   167
  for ( ; src < dst; ++src) {
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   168
    // Search low to high for an entry to keep.
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   169
    void* entry = *src;
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   170
    if (!filter_out(entry)) {
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   171
      // 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
   172
      while (src < --dst) {
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   173
        if (filter_out(*dst)) {
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   174
          *dst = entry;         // Replace discard with keeper.
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   175
          break;
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   176
        }
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   177
      }
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   178
      // 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
   179
    }
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   180
  }
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   181
  // 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
   182
  // if all the entries were filtered out.
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   183
  this->set_index(dst - buf);
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   184
}
d56dd9798d54 8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents: 47216
diff changeset
   185
33792
2bae5bf9e431 8077571: ObjPtrQueue is poorly named
kbarrett
parents: 33761
diff changeset
   186
#endif // SHARE_VM_GC_G1_SATBMARKQUEUE_HPP