hotspot/src/share/vm/gc/g1/ptrQueue.hpp
author kbarrett
Tue, 17 Nov 2015 16:40:52 -0500
changeset 34148 6efbc7ffd767
parent 33761 329db4b51480
child 36354 28bbe66a0498
permissions -rw-r--r--
8143014: Access PtrQueue member offsets through derived classes Summary: Moved accessors to derived classes and updated callers. Reviewed-by: tschatzl, jmasa, twisti
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
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 28507
diff changeset
     2
 * Copyright (c) 2001, 2015, 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
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
    28
#include "memory/allocation.hpp"
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
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
    36
// The definition of placement operator new(size_t, void*) in the <new>.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
    37
#include <new>
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
    38
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    39
class PtrQueueSet;
2013
49e915da0905 6700941: G1: allocation spec missing for some G1 classes
apetrusenko
parents: 1623
diff changeset
    40
class PtrQueue VALUE_OBJ_CLASS_SPEC {
20011
d74937287461 8024760: add more types, fields and constants to VMStructs
twisti
parents: 11455
diff changeset
    41
  friend class VMStructs;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    42
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    43
  // Noncopyable - not defined.
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    44
  PtrQueue(const PtrQueue&);
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    45
  PtrQueue& operator=(const PtrQueue&);
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    46
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    47
  // 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
    48
  PtrQueueSet* const _qset;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    49
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    50
  // Whether updates should be logged.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    51
  bool _active;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    52
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    53
  // 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
    54
  // 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
    55
  // be legally locked by then.
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    56
  const bool _permanent;
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    57
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    58
protected:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    59
  // The buffer.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    60
  void** _buf;
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    61
  // The (byte) index at which an object was last enqueued.  Starts at "_sz"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    62
  // (indicating an empty buffer) and goes towards zero.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    63
  size_t _index;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    64
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    65
  // The (byte) size of the buffer.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    66
  size_t _sz;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    67
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    68
  // 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
    69
  Mutex* _lock;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    70
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    71
  PtrQueueSet* qset() { return _qset; }
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    72
  bool is_permanent() const { return _permanent; }
28507
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 22234
diff changeset
    73
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 22234
diff changeset
    74
  // Process queue entries and release resources, if not permanent.
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 22234
diff changeset
    75
  void flush_impl();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    76
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    77
  // 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
    78
  // given PtrQueueSet.
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    79
  PtrQueue(PtrQueueSet* qset, bool permanent = false, bool active = false);
28507
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 22234
diff changeset
    80
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 22234
diff changeset
    81
  // Requires queue flushed or permanent.
354ef83ee258 8048949: Requeue queue implementation
tschatzl
parents: 22234
diff changeset
    82
  ~PtrQueue();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    83
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    84
public:
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
    85
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    86
  // Associate a lock with a ptr queue.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    87
  void set_lock(Mutex* lock) { _lock = lock; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    88
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    89
  void reset() { if (_buf != NULL) _index = _sz; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    90
20403
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20011
diff changeset
    91
  void enqueue(volatile void* ptr) {
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20011
diff changeset
    92
    enqueue((void*)(ptr));
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20011
diff changeset
    93
  }
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20011
diff changeset
    94
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    95
  // Enqueues the given "obj".
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    96
  void enqueue(void* ptr) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    97
    if (!_active) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    98
    else enqueue_known_active(ptr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    99
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   100
7920
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
   101
  // 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
   102
  // 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
   103
  // 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
   104
  // true if the buffer should be enqueued, or false if enough
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
   105
  // 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
   106
  // 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
   107
  // get into an infinite loop).
298df61588a2 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 7397
diff changeset
   108
  virtual bool should_enqueue_buffer() { return true; }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   109
  void handle_zero_index();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   110
  void locking_enqueue_completed_buffer(void** buf);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   111
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   112
  void enqueue_known_active(void* ptr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   113
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   114
  size_t size() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   115
    assert(_sz >= _index, "Invariant.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   116
    return _buf == NULL ? 0 : _sz - _index;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   117
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   118
6768
71338ecb7813 6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents: 5547
diff changeset
   119
  bool is_empty() {
71338ecb7813 6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents: 5547
diff changeset
   120
    return _buf == NULL || _sz == _index;
71338ecb7813 6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents: 5547
diff changeset
   121
  }
71338ecb7813 6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents: 5547
diff changeset
   122
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   123
  // 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
   124
  // 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
   125
  // log to the empty state.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   126
  void set_active(bool b) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   127
    _active = b;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   128
    if (!b && _buf != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   129
      _index = _sz;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   130
    } else if (b && _buf != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   131
      assert(_index == _sz, "invariant: queues are empty when activated.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   132
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   133
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   134
5082
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   135
  bool is_active() { return _active; }
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   136
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   137
  static size_t byte_index_to_index(size_t ind) {
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   138
    assert((ind % sizeof(void*)) == 0, "Invariant.");
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   139
    return ind / sizeof(void*);
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   142
  // To support compiler.
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   143
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   144
protected:
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   145
  template<typename Derived>
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   146
  static ByteSize byte_offset_of_index() {
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   147
    return byte_offset_of(Derived, _index);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   148
  }
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   149
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   150
  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
   151
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   152
  template<typename Derived>
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   153
  static ByteSize byte_offset_of_buf() {
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   154
    return byte_offset_of(Derived, _buf);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   155
  }
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   156
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   157
  static ByteSize byte_width_of_buf() { return in_ByteSize(sizeof(void*)); }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   158
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   159
  template<typename Derived>
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   160
  static ByteSize byte_offset_of_active() {
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   161
    return byte_offset_of(Derived, _active);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   162
  }
34148
6efbc7ffd767 8143014: Access PtrQueue member offsets through derived classes
kbarrett
parents: 33761
diff changeset
   163
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   164
  static ByteSize byte_width_of_active() { return in_ByteSize(sizeof(bool)); }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   165
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   166
};
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   167
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   168
class BufferNode {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   169
  size_t _index;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   170
  BufferNode* _next;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   171
public:
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   172
  BufferNode() : _index(0), _next(NULL) { }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   173
  BufferNode* next() const     { return _next;  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   174
  void set_next(BufferNode* n) { _next = n;     }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   175
  size_t index() const         { return _index; }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   176
  void set_index(size_t i)     { _index = i;    }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   177
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   178
  // Align the size of the structure to the size of the pointer
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   179
  static size_t aligned_size() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   180
    static const size_t alignment = round_to(sizeof(BufferNode), sizeof(void*));
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   181
    return alignment;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   182
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   183
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   184
  // BufferNode is allocated before the buffer.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   185
  // The chunk of memory that holds both of them is a block.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   186
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   187
  // Produce a new BufferNode given a buffer.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   188
  static BufferNode* new_from_buffer(void** buf) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   189
    return new (make_block_from_buffer(buf)) BufferNode;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   190
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   191
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   192
  // The following are the required conversion routines:
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   193
  static BufferNode* make_node_from_buffer(void** buf) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   194
    return (BufferNode*)make_block_from_buffer(buf);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   195
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   196
  static void** make_buffer_from_node(BufferNode *node) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   197
    return make_buffer_from_block(node);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   198
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   199
  static void* make_block_from_node(BufferNode *node) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   200
    return (void*)node;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   201
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   202
  static void** make_buffer_from_block(void* p) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   203
    return (void**)((char*)p + aligned_size());
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   204
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   205
  static void* make_block_from_buffer(void** p) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   206
    return (void*)((char*)p - aligned_size());
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   207
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   208
};
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   209
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   210
// A PtrQueueSet represents resources common to a set of pointer queues.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   211
// In particular, the individual queues allocate buffers from this shared
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   212
// set, and return completed buffers to the set.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   213
// All these variables are are protected by the TLOQ_CBL_mon. XXX ???
2013
49e915da0905 6700941: G1: allocation spec missing for some G1 classes
apetrusenko
parents: 1623
diff changeset
   214
class PtrQueueSet VALUE_OBJ_CLASS_SPEC {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   215
protected:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   216
  Monitor* _cbl_mon;  // Protects the fields below.
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   217
  BufferNode* _completed_buffers_head;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   218
  BufferNode* _completed_buffers_tail;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   219
  int _n_completed_buffers;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   220
  int _process_completed_threshold;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   221
  volatile bool _process_completed;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   222
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   223
  // This (and the interpretation of the first element as a "next"
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   224
  // pointer) are protected by the TLOQ_FL_lock.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   225
  Mutex* _fl_lock;
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   226
  BufferNode* _buf_free_list;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   227
  size_t _buf_free_list_sz;
2142
032f4652700c 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 2013
diff changeset
   228
  // 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
   229
  // 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
   230
  PtrQueueSet* _fl_owner;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   231
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   232
  // The size of all buffers in the set.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   233
  size_t _sz;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   234
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   235
  bool _all_active;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   236
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   237
  // 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
   238
  bool _notify_when_complete;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   239
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   240
  // Maximum number of elements allowed on completed queue: after that,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   241
  // enqueuer does the work itself.  Zero indicates no maximum.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   242
  int _max_completed_queue;
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   243
  int _completed_queue_padding;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   244
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   245
  int completed_buffers_list_length();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   246
  void assert_completed_buffer_list_len_correct_locked();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   247
  void assert_completed_buffer_list_len_correct();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   248
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   249
protected:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   250
  // A mutator thread does the the work of processing a buffer.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   251
  // 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
   252
  // deallocated).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   253
  virtual bool mut_process_buffer(void** buf) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   254
    ShouldNotReachHere();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   255
    return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   256
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   257
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   258
  // Create an empty ptr queue set.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   259
  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
   260
  ~PtrQueueSet();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   261
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   262
  // 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
   263
  // arguments.
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   264
  void initialize(Monitor* cbl_mon,
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   265
                  Mutex* fl_lock,
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   266
                  int process_completed_threshold,
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   267
                  int max_completed_queue,
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   268
                  PtrQueueSet *fl_owner = NULL);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   269
33761
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   270
public:
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   271
329db4b51480 6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents: 30764
diff changeset
   272
  // Return an empty array of size _sz (required to be non-zero).
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   273
  void** allocate_buffer();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   274
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   275
  // Return an empty buffer to the free list.  The "buf" argument is
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   276
  // required to be a pointer to the head of an array of length "_sz".
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   277
  void deallocate_buffer(void** buf);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   278
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   279
  // Declares that "buf" is a complete buffer.
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   280
  void enqueue_complete_buffer(void** buf, size_t index = 0);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   281
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   282
  // To be invoked by the mutator.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   283
  bool process_or_enqueue_complete_buffer(void** buf);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   284
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   285
  bool completed_buffers_exist_dirty() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   286
    return _n_completed_buffers > 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   287
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   288
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   289
  bool process_completed_buffers() { return _process_completed; }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   290
  void set_process_completed(bool x) { _process_completed = x; }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   291
5082
19e725a3d2eb 6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents: 4481
diff changeset
   292
  bool is_active() { return _all_active; }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   293
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   294
  // Set the buffer size.  Should be called before any "enqueue" operation
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   295
  // can be called.  And should only be called once.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   296
  void set_buffer_size(size_t sz);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   297
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   298
  // Get the buffer size.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   299
  size_t buffer_size() { return _sz; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   300
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   301
  // Get/Set the number of completed buffers that triggers log processing.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   302
  void set_process_completed_threshold(int sz) { _process_completed_threshold = sz; }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   303
  int process_completed_threshold() const { return _process_completed_threshold; }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   304
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   305
  // 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
   306
  // list size may be reduced, if that is deemed desirable.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   307
  void reduce_free_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   308
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   309
  int completed_buffers_num() { return _n_completed_buffers; }
2142
032f4652700c 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 2013
diff changeset
   310
032f4652700c 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 2013
diff changeset
   311
  void merge_bufferlists(PtrQueueSet* src);
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   312
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   313
  void set_max_completed_queue(int m) { _max_completed_queue = m; }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   314
  int max_completed_queue() { return _max_completed_queue; }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   315
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   316
  void set_completed_queue_padding(int padding) { _completed_queue_padding = padding; }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   317
  int completed_queue_padding() { return _completed_queue_padding; }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   318
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   319
  // Notify the consumer if the number of buffers crossed the threshold
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 2154
diff changeset
   320
  void notify_if_necessary();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   321
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
   322
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 28507
diff changeset
   323
#endif // SHARE_VM_GC_G1_PTRQUEUE_HPP