src/hotspot/share/gc/g1/ptrQueue.hpp
author tschatzl
Thu, 03 May 2018 14:10:08 +0200
changeset 49967 672ded60a082
parent 49392 2956d0ece7a9
child 51332 c25572739e7c
permissions -rw-r--r--
8202021: Improve variable naming in ReferenceProcesso Reviewed-by: sangheki, sjohanss
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
/*
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
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
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 28507
diff changeset
    25
#ifndef SHARE_VM_GC_G1_PTRQUEUE_HPP
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 28507
diff changeset
    26
#define SHARE_VM_GC_G1_PTRQUEUE_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
    27
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    28
#include "utilities/align.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
    29
#include "utilities/sizes.hpp"
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
// There are various techniques that require threads to be able to log
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    32
// addresses.  For example, a generational write barrier might log
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    33
// the addresses of modified old-generation objects.  This type supports
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    34
// this operation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    35
37065
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
    36
class BufferNode;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    37
class PtrQueueSet;
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 47216
diff changeset
    38
class PtrQueue {
20011
d74937287461 8024760: add more types, fields and constants to VMStructs
twisti
parents: 11455
diff changeset
    39
  friend class VMStructs;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    40
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    41
  // Noncopyable - not defined.
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    42
  PtrQueue(const PtrQueue&);
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    43
  PtrQueue& operator=(const PtrQueue&);
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    44
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    45
  // The ptr queue set to which this queue belongs.
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    46
  PtrQueueSet* const _qset;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    47
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    48
  // Whether updates should be logged.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    49
  bool _active;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    50
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    51
  // If true, the queue is permanent, and doesn't need to deallocate
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    52
  // its buffer in the destructor (since that obtains a lock which may not
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    53
  // be legally locked by then.
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    54
  const bool _permanent;
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    55
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    56
  // The (byte) index at which an object was last enqueued.  Starts at
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    57
  // capacity_in_bytes (indicating an empty buffer) and goes towards zero.
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    58
  // Value is always pointer-size aligned.
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    59
  size_t _index;
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    60
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    61
  // Size of the current buffer, in bytes.
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    62
  // Value is always pointer-size aligned.
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    63
  size_t _capacity_in_bytes;
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    64
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    65
  static const size_t _element_size = sizeof(void*);
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    66
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    67
  // Get the capacity, in bytes.  The capacity must have been set.
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    68
  size_t capacity_in_bytes() const {
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    69
    assert(_capacity_in_bytes > 0, "capacity not set");
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    70
    return _capacity_in_bytes;
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    71
  }
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    72
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    73
  void set_capacity(size_t entries) {
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    74
    size_t byte_capacity = index_to_byte_index(entries);
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    75
    assert(_capacity_in_bytes == 0 || _capacity_in_bytes == byte_capacity,
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    76
           "changing capacity " SIZE_FORMAT " -> " SIZE_FORMAT,
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    77
           _capacity_in_bytes, byte_capacity);
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    78
    _capacity_in_bytes = byte_capacity;
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    79
  }
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    80
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    81
  static size_t byte_index_to_index(size_t ind) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46443
diff changeset
    82
    assert(is_aligned(ind, _element_size), "precondition");
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    83
    return ind / _element_size;
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    84
  }
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    85
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    86
  static size_t index_to_byte_index(size_t ind) {
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    87
    return ind * _element_size;
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    88
  }
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    89
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    90
protected:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    91
  // The buffer.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    92
  void** _buf;
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    93
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    94
  size_t index() const {
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    95
    return byte_index_to_index(_index);
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    96
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    97
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    98
  void set_index(size_t new_index) {
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
    99
    size_t byte_index = index_to_byte_index(new_index);
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   100
    assert(byte_index <= capacity_in_bytes(), "precondition");
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   101
    _index = byte_index;
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   102
  }
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   103
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   104
  size_t capacity() const {
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   105
    return byte_index_to_index(capacity_in_bytes());
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   106
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   107
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   108
  // If there is a lock associated with this buffer, this is that lock.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   109
  Mutex* _lock;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   110
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   111
  PtrQueueSet* qset() { return _qset; }
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   112
  bool is_permanent() const { return _permanent; }
28507
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 22234
diff changeset
   113
46305
bff6d23aa1e3 8175221: Cleanup DirtyCardQueueSet::concatenate_log
kbarrett
parents: 37065
diff changeset
   114
  // Process queue entries and release resources.
28507
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 22234
diff changeset
   115
  void flush_impl();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   116
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   117
  // Initialize this queue to contain a null buffer, and be part of the
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   118
  // given PtrQueueSet.
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   119
  PtrQueue(PtrQueueSet* qset, bool permanent = false, bool active = false);
28507
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 22234
diff changeset
   120
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 22234
diff changeset
   121
  // Requires queue flushed or permanent.
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 22234
diff changeset
   122
  ~PtrQueue();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   123
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   124
public:
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   125
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   126
  // Associate a lock with a ptr queue.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   127
  void set_lock(Mutex* lock) { _lock = lock; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   128
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   129
  // Forcibly set empty.
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   130
  void reset() {
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   131
    if (_buf != NULL) {
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   132
      _index = capacity_in_bytes();
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   133
    }
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   134
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   135
20403
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20011
diff changeset
   136
  void enqueue(volatile void* ptr) {
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20011
diff changeset
   137
    enqueue((void*)(ptr));
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20011
diff changeset
   138
  }
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20011
diff changeset
   139
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   140
  // Enqueues the given "obj".
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   141
  void enqueue(void* ptr) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   142
    if (!_active) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   143
    else enqueue_known_active(ptr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   144
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   145
7920
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
   146
  // This method is called when we're doing the zero index handling
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
   147
  // and gives a chance to the queues to do any pre-enqueueing
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
   148
  // processing they might want to do on the buffer. It should return
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
   149
  // true if the buffer should be enqueued, or false if enough
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
   150
  // entries were cleared from it so that it can be re-used. It should
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
   151
  // not return false if the buffer is still full (otherwise we can
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
   152
  // get into an infinite loop).
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
   153
  virtual bool should_enqueue_buffer() { return true; }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   154
  void handle_zero_index();
37065
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   155
  void locking_enqueue_completed_buffer(BufferNode* node);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   156
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   157
  void enqueue_known_active(void* ptr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   158
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   159
  // Return the size of the in-use region.
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   160
  size_t size() const {
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   161
    size_t result = 0;
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   162
    if (_buf != NULL) {
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   163
      assert(_index <= capacity_in_bytes(), "Invariant");
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   164
      result = byte_index_to_index(capacity_in_bytes() - _index);
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   165
    }
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   166
    return result;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   167
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   168
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   169
  bool is_empty() const {
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   170
    return _buf == NULL || capacity_in_bytes() == _index;
6768
71338ecb7813 6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents: 5547
diff changeset
   171
  }
71338ecb7813 6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents: 5547
diff changeset
   172
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   173
  // Set the "active" property of the queue to "b".  An enqueue to an
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   174
  // inactive thread is a no-op.  Setting a queue to inactive resets its
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   175
  // log to the empty state.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   176
  void set_active(bool b) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   177
    _active = b;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   178
    if (!b && _buf != NULL) {
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   179
      reset();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   180
    } else if (b && _buf != NULL) {
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   181
      assert(index() == capacity(),
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   182
             "invariant: queues are empty when activated.");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   183
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   184
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   185
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   186
  bool is_active() const { return _active; }
37065
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   187
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   188
  // To support compiler.
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   189
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   190
protected:
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   191
  template<typename Derived>
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   192
  static ByteSize byte_offset_of_index() {
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   193
    return byte_offset_of(Derived, _index);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   194
  }
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   195
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   196
  static ByteSize byte_width_of_index() { return in_ByteSize(sizeof(size_t)); }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   197
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   198
  template<typename Derived>
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   199
  static ByteSize byte_offset_of_buf() {
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   200
    return byte_offset_of(Derived, _buf);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   201
  }
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   202
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   203
  static ByteSize byte_width_of_buf() { return in_ByteSize(_element_size); }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   204
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   205
  template<typename Derived>
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   206
  static ByteSize byte_offset_of_active() {
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   207
    return byte_offset_of(Derived, _active);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   208
  }
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   209
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   210
  static ByteSize byte_width_of_active() { return in_ByteSize(sizeof(bool)); }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   211
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   212
};
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   213
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   214
class BufferNode {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   215
  size_t _index;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   216
  BufferNode* _next;
36354
28bbe66a0498 8150419: Cleanup BufferNode API
kbarrett
parents: 34148
diff changeset
   217
  void* _buffer[1];             // Pseudo flexible array member.
28bbe66a0498 8150419: Cleanup BufferNode API
kbarrett
parents: 34148
diff changeset
   218
28bbe66a0498 8150419: Cleanup BufferNode API
kbarrett
parents: 34148
diff changeset
   219
  BufferNode() : _index(0), _next(NULL) { }
28bbe66a0498 8150419: Cleanup BufferNode API
kbarrett
parents: 34148
diff changeset
   220
  ~BufferNode() { }
28bbe66a0498 8150419: Cleanup BufferNode API
kbarrett
parents: 34148
diff changeset
   221
28bbe66a0498 8150419: Cleanup BufferNode API
kbarrett
parents: 34148
diff changeset
   222
  static size_t buffer_offset() {
28bbe66a0498 8150419: Cleanup BufferNode API
kbarrett
parents: 34148
diff changeset
   223
    return offset_of(BufferNode, _buffer);
28bbe66a0498 8150419: Cleanup BufferNode API
kbarrett
parents: 34148
diff changeset
   224
  }
28bbe66a0498 8150419: Cleanup BufferNode API
kbarrett
parents: 34148
diff changeset
   225
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   226
public:
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   227
  BufferNode* next() const     { return _next;  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   228
  void set_next(BufferNode* n) { _next = n;     }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   229
  size_t index() const         { return _index; }
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   230
  void set_index(size_t i)     { _index = i; }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   231
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   232
  // Allocate a new BufferNode with the "buffer" having size elements.
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   233
  static BufferNode* allocate(size_t size);
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   234
36354
28bbe66a0498 8150419: Cleanup BufferNode API
kbarrett
parents: 34148
diff changeset
   235
  // Free a BufferNode.
28bbe66a0498 8150419: Cleanup BufferNode API
kbarrett
parents: 34148
diff changeset
   236
  static void deallocate(BufferNode* node);
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   237
37065
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   238
  // Return the BufferNode containing the buffer, after setting its index.
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   239
  static BufferNode* make_node_from_buffer(void** buffer, size_t index) {
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   240
    BufferNode* node =
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   241
      reinterpret_cast<BufferNode*>(
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   242
        reinterpret_cast<char*>(buffer) - buffer_offset());
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   243
    node->set_index(index);
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   244
    return node;
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   245
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   246
36354
28bbe66a0498 8150419: Cleanup BufferNode API
kbarrett
parents: 34148
diff changeset
   247
  // Return the buffer for node.
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   248
  static void** make_buffer_from_node(BufferNode *node) {
36354
28bbe66a0498 8150419: Cleanup BufferNode API
kbarrett
parents: 34148
diff changeset
   249
    // &_buffer[0] might lead to index out of bounds warnings.
28bbe66a0498 8150419: Cleanup BufferNode API
kbarrett
parents: 34148
diff changeset
   250
    return reinterpret_cast<void**>(
28bbe66a0498 8150419: Cleanup BufferNode API
kbarrett
parents: 34148
diff changeset
   251
      reinterpret_cast<char*>(node) + buffer_offset());
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   252
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   253
};
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   254
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   255
// A PtrQueueSet represents resources common to a set of pointer queues.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   256
// In particular, the individual queues allocate buffers from this shared
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   257
// set, and return completed buffers to the set.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   258
// All these variables are are protected by the TLOQ_CBL_mon. XXX ???
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 47216
diff changeset
   259
class PtrQueueSet {
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   260
private:
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   261
  // The size of all buffers in the set.
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   262
  size_t _buffer_size;
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   263
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   264
protected:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   265
  Monitor* _cbl_mon;  // Protects the fields below.
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   266
  BufferNode* _completed_buffers_head;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   267
  BufferNode* _completed_buffers_tail;
36371
fd81a4f0ea00 8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents: 36354
diff changeset
   268
  size_t _n_completed_buffers;
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   269
  int _process_completed_threshold;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   270
  volatile bool _process_completed;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   271
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   272
  // This (and the interpretation of the first element as a "next"
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   273
  // pointer) are protected by the TLOQ_FL_lock.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   274
  Mutex* _fl_lock;
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   275
  BufferNode* _buf_free_list;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   276
  size_t _buf_free_list_sz;
2142
032f4652700c 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 2013
diff changeset
   277
  // Queue set can share a freelist. The _fl_owner variable
032f4652700c 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 2013
diff changeset
   278
  // specifies the owner. It is set to "this" by default.
032f4652700c 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 2013
diff changeset
   279
  PtrQueueSet* _fl_owner;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   280
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   281
  bool _all_active;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   282
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   283
  // If true, notify_all on _cbl_mon when the threshold is reached.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   284
  bool _notify_when_complete;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   285
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   286
  // Maximum number of elements allowed on completed queue: after that,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   287
  // enqueuer does the work itself.  Zero indicates no maximum.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   288
  int _max_completed_queue;
36371
fd81a4f0ea00 8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents: 36354
diff changeset
   289
  size_t _completed_queue_padding;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   290
36371
fd81a4f0ea00 8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents: 36354
diff changeset
   291
  size_t completed_buffers_list_length();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   292
  void assert_completed_buffer_list_len_correct_locked();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   293
  void assert_completed_buffer_list_len_correct();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   294
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   295
protected:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   296
  // A mutator thread does the the work of processing a buffer.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   297
  // Returns "true" iff the work is complete (and the buffer may be
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   298
  // deallocated).
37065
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   299
  virtual bool mut_process_buffer(BufferNode* node) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   300
    ShouldNotReachHere();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   301
    return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   302
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   303
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   304
  // Create an empty ptr queue set.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   305
  PtrQueueSet(bool notify_when_complete = false);
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   306
  ~PtrQueueSet();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   307
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   308
  // Because of init-order concerns, we can't pass these as constructor
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   309
  // arguments.
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   310
  void initialize(Monitor* cbl_mon,
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   311
                  Mutex* fl_lock,
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   312
                  int process_completed_threshold,
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   313
                  int max_completed_queue,
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   314
                  PtrQueueSet *fl_owner = NULL);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   315
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   316
public:
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   317
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   318
  // Return the buffer for a BufferNode of size buffer_size().
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   319
  void** allocate_buffer();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   320
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   321
  // Return an empty buffer to the free list.  The node is required
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   322
  // to have been allocated with a size of buffer_size().
37065
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   323
  void deallocate_buffer(BufferNode* node);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   324
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   325
  // Declares that "buf" is a complete buffer.
37065
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   326
  void enqueue_complete_buffer(BufferNode* node);
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   327
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   328
  // To be invoked by the mutator.
37065
c00d1c2ffb7c 8150676: Use BufferNode index
kbarrett
parents: 36371
diff changeset
   329
  bool process_or_enqueue_complete_buffer(BufferNode* node);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   330
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   331
  bool completed_buffers_exist_dirty() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   332
    return _n_completed_buffers > 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   333
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   334
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   335
  bool process_completed_buffers() { return _process_completed; }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   336
  void set_process_completed(bool x) { _process_completed = x; }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   337
5082
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   338
  bool is_active() { return _all_active; }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   339
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   340
  // Set the buffer size.  Should be called before any "enqueue" operation
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   341
  // can be called.  And should only be called once.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   342
  void set_buffer_size(size_t sz);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   343
46443
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   344
  // Get the buffer size.  Must have been set.
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   345
  size_t buffer_size() const {
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   346
    assert(_buffer_size > 0, "buffer size not set");
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   347
    return _buffer_size;
cdb638b5ec53 8178836: Improve PtrQueue index abstraction
kbarrett
parents: 46305
diff changeset
   348
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   349
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   350
  // Get/Set the number of completed buffers that triggers log processing.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   351
  void set_process_completed_threshold(int sz) { _process_completed_threshold = sz; }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   352
  int process_completed_threshold() const { return _process_completed_threshold; }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   353
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   354
  // Must only be called at a safe point.  Indicates that the buffer free
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   355
  // list size may be reduced, if that is deemed desirable.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   356
  void reduce_free_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   357
36371
fd81a4f0ea00 8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents: 36354
diff changeset
   358
  size_t completed_buffers_num() { return _n_completed_buffers; }
2142
032f4652700c 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 2013
diff changeset
   359
032f4652700c 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 2013
diff changeset
   360
  void merge_bufferlists(PtrQueueSet* src);
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   361
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   362
  void set_max_completed_queue(int m) { _max_completed_queue = m; }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   363
  int max_completed_queue() { return _max_completed_queue; }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   364
36371
fd81a4f0ea00 8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents: 36354
diff changeset
   365
  void set_completed_queue_padding(size_t padding) { _completed_queue_padding = padding; }
fd81a4f0ea00 8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents: 36354
diff changeset
   366
  size_t completed_queue_padding() { return _completed_queue_padding; }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   367
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   368
  // Notify the consumer if the number of buffers crossed the threshold
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   369
  void notify_if_necessary();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   370
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
   371
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 28507
diff changeset
   372
#endif // SHARE_VM_GC_G1_PTRQUEUE_HPP