hotspot/src/share/vm/utilities/taskqueue.hpp
author jmasa
Wed, 24 Feb 2010 07:00:33 -0800
changeset 5035 0e498c4df637
parent 4028 be6959017765
child 5076 8b74a4b60b31
permissions -rw-r--r--
6928081: G1: rename parameters common with CMS Summary: Rename marking stack sizing flags to be common between G1 and CMS Reviewed-by: ysr, tonyp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
2105
347008ce7984 6814575: Update copyright year
xdono
parents: 2010
diff changeset
     2
 * Copyright 2001-2009 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
class TaskQueueSuper: public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
protected:
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    27
  // Internal type for indexing the queue; also used for the tag.
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    28
  typedef NOT_LP64(uint16_t) LP64_ONLY(uint32_t) idx_t;
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    29
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    30
  // The first free element after the last one pushed (mod N).
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
    31
  volatile uint _bottom;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    33
  enum {
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    34
    N = 1 << NOT_LP64(14) LP64_ONLY(17), // Queue size: 16K or 128K
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    35
    MOD_N_MASK = N - 1                   // To compute x mod N efficiently.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  };
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    37
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    38
  class Age {
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    39
  public:
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    40
    Age(size_t data = 0)         { _data = data; }
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    41
    Age(const Age& age)          { _data = age._data; }
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    42
    Age(idx_t top, idx_t tag)    { _fields._top = top; _fields._tag = tag; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    44
    Age   get()        const volatile { return _data; }
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    45
    void  set(Age age) volatile       { _data = age._data; }
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    46
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    47
    idx_t top()        const volatile { return _fields._top; }
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    48
    idx_t tag()        const volatile { return _fields._tag; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    50
    // Increment top; if it wraps, increment tag also.
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    51
    void increment() {
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    52
      _fields._top = increment_index(_fields._top);
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    53
      if (_fields._top == 0) ++_fields._tag;
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    54
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    56
    Age cmpxchg(const Age new_age, const Age old_age) volatile {
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    57
      return (size_t) Atomic::cmpxchg_ptr((intptr_t)new_age._data,
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    58
                                          (volatile intptr_t *)&_data,
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    59
                                          (intptr_t)old_age._data);
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    60
    }
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    61
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    62
    bool operator ==(const Age& other) const { return _data == other._data; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    64
  private:
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    65
    struct fields {
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    66
      idx_t _top;
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    67
      idx_t _tag;
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    68
    };
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    69
    union {
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    70
      size_t _data;
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    71
      fields _fields;
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    72
    };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  };
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    74
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    75
  volatile Age _age;
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    76
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    77
  // These both operate mod N.
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    78
  static uint increment_index(uint ind) {
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    79
    return (ind + 1) & MOD_N_MASK;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  }
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    81
  static uint decrement_index(uint ind) {
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    82
    return (ind - 1) & MOD_N_MASK;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    85
  // Returns a number in the range [0..N).  If the result is "N-1", it should be
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    86
  // interpreted as 0.
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
    87
  uint dirty_size(uint bot, uint top) {
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    88
    return (bot - top) & MOD_N_MASK;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // Returns the size corresponding to the given "bot" and "top".
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
    92
  uint size(uint bot, uint top) {
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
    93
    uint sz = dirty_size(bot, top);
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    94
    // Has the queue "wrapped", so that bottom is less than top?  There's a
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    95
    // complicated special case here.  A pair of threads could perform pop_local
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    96
    // and pop_global operations concurrently, starting from a state in which
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    97
    // _bottom == _top+1.  The pop_local could succeed in decrementing _bottom,
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    98
    // and the pop_global in incrementing _top (in which case the pop_global
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
    99
    // will be awarded the contested queue element.)  The resulting state must
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   100
    // be interpreted as an empty queue.  (We only need to worry about one such
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   101
    // event: only the queue owner performs pop_local's, and several concurrent
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   102
    // threads attempting to perform the pop_global will all perform the same
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   103
    // CAS, and only one can succeed.)  Any stealing thread that reads after
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   104
    // either the increment or decrement will see an empty queue, and will not
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   105
    // join the competitors.  The "sz == -1 || sz == N-1" state will not be
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   106
    // modified by concurrent queues, so the owner thread can reset the state to
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   107
    // _bottom == top so subsequent pushes will be performed normally.
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   108
    return (sz == N - 1) ? 0 : sz;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  TaskQueueSuper() : _bottom(0), _age() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // Return "true" if the TaskQueue contains any tasks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  bool peek();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // Return an estimate of the number of elements in the queue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // The "careful" version admits the possibility of pop_local/pop_global
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // races.
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   120
  uint size() {
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   121
    return size(_bottom, _age.top());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   124
  uint dirty_size() {
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   125
    return dirty_size(_bottom, _age.top());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   128
  void set_empty() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   129
    _bottom = 0;
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   130
    _age.set(0);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   131
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   132
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // Maximum number of elements allowed in the queue.  This is two less
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  // than the actual queue size, for somewhat complicated reasons.
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   135
  uint max_elems() { return N - 2; }
5035
0e498c4df637 6928081: G1: rename parameters common with CMS
jmasa
parents: 4028
diff changeset
   136
0e498c4df637 6928081: G1: rename parameters common with CMS
jmasa
parents: 4028
diff changeset
   137
  // Total size of queue.
0e498c4df637 6928081: G1: rename parameters common with CMS
jmasa
parents: 4028
diff changeset
   138
  static const uint total_size() { return N; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
template<class E> class GenericTaskQueue: public TaskQueueSuper {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  // Slow paths for push, pop_local.  (pop_global has no fast path.)
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   144
  bool push_slow(E t, uint dirty_n_elems);
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   145
  bool pop_local_slow(uint localBot, Age oldAge);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // Initializes the queue to empty.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  GenericTaskQueue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  void initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Push the task "t" on the queue.  Returns "false" iff the queue is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // full.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  inline bool push(E t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  // If succeeds in claiming a task (from the 'local' end, that is, the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // most recently pushed task), returns "true" and sets "t" to that task.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // Otherwise, the queue is empty and returns false.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  inline bool pop_local(E& t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  // If succeeds in claiming a task (from the 'global' end, that is, the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // least recently pushed task), returns "true" and sets "t" to that task.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  // Otherwise, the queue is empty and returns false.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  bool pop_global(E& t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // Delete any resource associated with the queue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  ~GenericTaskQueue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   170
  // apply the closure to all elements in the task queue
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   171
  void oops_do(OopClosure* f);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   172
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  // Element array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  volatile E* _elems;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
template<class E>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
GenericTaskQueue<E>::GenericTaskQueue():TaskQueueSuper() {
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   180
  assert(sizeof(Age) == sizeof(size_t), "Depends on this.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
template<class E>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
void GenericTaskQueue<E>::initialize() {
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   185
  _elems = NEW_C_HEAP_ARRAY(E, N);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  guarantee(_elems != NULL, "Allocation failed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
template<class E>
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   190
void GenericTaskQueue<E>::oops_do(OopClosure* f) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   191
  // tty->print_cr("START OopTaskQueue::oops_do");
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   192
  uint iters = size();
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   193
  uint index = _bottom;
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   194
  for (uint i = 0; i < iters; ++i) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   195
    index = decrement_index(index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   196
    // tty->print_cr("  doing entry %d," INTPTR_T " -> " INTPTR_T,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   197
    //            index, &_elems[index], _elems[index]);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   198
    E* t = (E*)&_elems[index];      // cast away volatility
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   199
    oop* p = (oop*)t;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   200
    assert((*t)->is_oop_or_null(), "Not an oop or null");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   201
    f->do_oop(p);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   202
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   203
  // tty->print_cr("END OopTaskQueue::oops_do");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   204
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   205
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   206
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   207
template<class E>
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   208
bool GenericTaskQueue<E>::push_slow(E t, uint dirty_n_elems) {
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   209
  if (dirty_n_elems == N - 1) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    // Actually means 0, so do the push.
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   211
    uint localBot = _bottom;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    _elems[localBot] = t;
4027
1c62fbaf6b68 6888847: TaskQueue needs release_store() for correctness on RMO machines
bobv
parents: 3607
diff changeset
   213
    OrderAccess::release_store(&_bottom, increment_index(localBot));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    return true;
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   215
  }
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   216
  return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
template<class E>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
bool GenericTaskQueue<E>::
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   221
pop_local_slow(uint localBot, Age oldAge) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  // This queue was observed to contain exactly one element; either this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  // thread will claim it, or a competing "pop_global".  In either case,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  // the queue will be logically empty afterwards.  Create a new Age value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  // that represents the empty queue for the given value of "_bottom".  (We
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  // must also increment "tag" because of the case where "bottom == 1",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  // "top == 0".  A pop_global could read the queue element in that case,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  // then have the owner thread do a pop followed by another push.  Without
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // the incrementing of "tag", the pop_global's CAS could succeed,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  // allowing it to believe it has claimed the stale element.)
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   231
  Age newAge((idx_t)localBot, oldAge.tag() + 1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // Perhaps a competing pop_global has already incremented "top", in which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  // case it wins the element.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  if (localBot == oldAge.top()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    // No competing pop_global has yet incremented "top"; we'll try to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    // install new_age, thus claiming the element.
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   237
    Age tempAge = _age.cmpxchg(newAge, oldAge);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    if (tempAge == oldAge) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
      // We win.
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   240
      assert(dirty_size(localBot, _age.top()) != N - 1, "sanity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  }
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   244
  // We lose; a completing pop_global gets the element.  But the queue is empty
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   245
  // and top is greater than bottom.  Fix this representation of the empty queue
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   246
  // to become the canonical one.
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   247
  _age.set(newAge);
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   248
  assert(dirty_size(localBot, _age.top()) != N - 1, "sanity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
template<class E>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
bool GenericTaskQueue<E>::pop_global(E& t) {
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   254
  Age oldAge = _age.get();
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   255
  uint localBot = _bottom;
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   256
  uint n_elems = size(localBot, oldAge.top());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  if (n_elems == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  }
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   260
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  t = _elems[oldAge.top()];
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   262
  Age newAge(oldAge);
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   263
  newAge.increment();
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   264
  Age resAge = _age.cmpxchg(newAge, oldAge);
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   265
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  // Note that using "_bottom" here might fail, since a pop_local might
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  // have decremented it.
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   268
  assert(dirty_size(localBot, newAge.top()) != N - 1, "sanity");
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   269
  return resAge == oldAge;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
template<class E>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
GenericTaskQueue<E>::~GenericTaskQueue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  FREE_C_HEAP_ARRAY(E, _elems);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
// Inherits the typedef of "Task" from above.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
class TaskQueueSetSuper: public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  static int randomParkAndMiller(int* seed0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  // Returns "true" if some TaskQueue in the set contains a task.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  virtual bool peek() = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
template<class E> class GenericTaskQueueSet: public TaskQueueSetSuper {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
private:
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   288
  uint _n;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  GenericTaskQueue<E>** _queues;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  GenericTaskQueueSet(int n) : _n(n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    typedef GenericTaskQueue<E>* GenericTaskQueuePtr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    _queues = NEW_C_HEAP_ARRAY(GenericTaskQueuePtr, n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    guarantee(_queues != NULL, "Allocation failure.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    for (int i = 0; i < n; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
      _queues[i] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   301
  bool steal_1_random(uint queue_num, int* seed, E& t);
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   302
  bool steal_best_of_2(uint queue_num, int* seed, E& t);
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   303
  bool steal_best_of_all(uint queue_num, int* seed, E& t);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   305
  void register_queue(uint i, GenericTaskQueue<E>* q);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   307
  GenericTaskQueue<E>* queue(uint n);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  // The thread with queue number "queue_num" (and whose random number seed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  // is at "seed") is trying to steal a task from some other queue.  (It
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  // may try several queues, according to some configuration parameter.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  // If some steal succeeds, returns "true" and sets "t" the stolen task,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  // otherwise returns false.
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   314
  bool steal(uint queue_num, int* seed, E& t);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  bool peek();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
template<class E>
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   320
void GenericTaskQueueSet<E>::register_queue(uint i, GenericTaskQueue<E>* q) {
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   321
  assert(i < _n, "index out of range.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  _queues[i] = q;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
template<class E>
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   326
GenericTaskQueue<E>* GenericTaskQueueSet<E>::queue(uint i) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  return _queues[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
template<class E>
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   331
bool GenericTaskQueueSet<E>::steal(uint queue_num, int* seed, E& t) {
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   332
  for (uint i = 0; i < 2 * _n; i++)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    if (steal_best_of_2(queue_num, seed, t))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
template<class E>
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   339
bool GenericTaskQueueSet<E>::steal_best_of_all(uint queue_num, int* seed, E& t) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  if (_n > 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    int best_k;
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   342
    uint best_sz = 0;
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   343
    for (uint k = 0; k < _n; k++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
      if (k == queue_num) continue;
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   345
      uint sz = _queues[k]->size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
      if (sz > best_sz) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
        best_sz = sz;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
        best_k = k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    return best_sz > 0 && _queues[best_k]->pop_global(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  } else if (_n == 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    // Just try the other one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    int k = (queue_num + 1) % 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    return _queues[k]->pop_global(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    assert(_n == 1, "can't be zero.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
template<class E>
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   363
bool GenericTaskQueueSet<E>::steal_1_random(uint queue_num, int* seed, E& t) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  if (_n > 2) {
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   365
    uint k = queue_num;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    while (k == queue_num) k = randomParkAndMiller(seed) % _n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    return _queues[2]->pop_global(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  } else if (_n == 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    // Just try the other one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    int k = (queue_num + 1) % 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    return _queues[k]->pop_global(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    assert(_n == 1, "can't be zero.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
template<class E>
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   379
bool GenericTaskQueueSet<E>::steal_best_of_2(uint queue_num, int* seed, E& t) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  if (_n > 2) {
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   381
    uint k1 = queue_num;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    while (k1 == queue_num) k1 = randomParkAndMiller(seed) % _n;
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   383
    uint k2 = queue_num;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    while (k2 == queue_num || k2 == k1) k2 = randomParkAndMiller(seed) % _n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    // Sample both and try the larger.
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   386
    uint sz1 = _queues[k1]->size();
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   387
    uint sz2 = _queues[k2]->size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    if (sz2 > sz1) return _queues[k2]->pop_global(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    else return _queues[k1]->pop_global(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  } else if (_n == 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    // Just try the other one.
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   392
    uint k = (queue_num + 1) % 2;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    return _queues[k]->pop_global(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    assert(_n == 1, "can't be zero.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
template<class E>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
bool GenericTaskQueueSet<E>::peek() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  // Try all the queues.
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   403
  for (uint j = 0; j < _n; j++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    if (_queues[j]->peek())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   410
// When to terminate from the termination protocol.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   411
class TerminatorTerminator: public CHeapObj {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   412
public:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   413
  virtual bool should_exit_termination() = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   414
};
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   415
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
// A class to aid in the termination of a set of parallel tasks using
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
// TaskQueueSet's for work stealing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
2010
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   419
#undef TRACESPINNING
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   420
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
class ParallelTaskTerminator: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  int _n_threads;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  TaskQueueSetSuper* _queue_set;
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   425
  int _offered_termination;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
2010
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   427
#ifdef TRACESPINNING
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   428
  static uint _total_yields;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   429
  static uint _total_spins;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   430
  static uint _total_peeks;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   431
#endif
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   432
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  bool peek_in_queue_set();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  virtual void yield();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  void sleep(uint millis);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  // "n_threads" is the number of threads to be terminated.  "queue_set" is a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  // queue sets of work queues of other threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  ParallelTaskTerminator(int n_threads, TaskQueueSetSuper* queue_set);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  // The current thread has no work, and is ready to terminate if everyone
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  // else is.  If returns "true", all threads are terminated.  If returns
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  // "false", available work has been observed in one of the task queues,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  // so the global task is not complete.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   448
  bool offer_termination() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   449
    return offer_termination(NULL);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   450
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   451
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   452
  // As above, but it also terminates if the should_exit_termination()
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   453
  // method of the terminator parameter returns true. If terminator is
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   454
  // NULL, then it is ignored.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   455
  bool offer_termination(TerminatorTerminator* terminator);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  // Reset the terminator, so that it may be reused again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  // The caller is responsible for ensuring that this is done
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  // in an MT-safe manner, once the previous round of use of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  // the terminator is finished.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  void reset_for_reuse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
2010
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   463
#ifdef TRACESPINNING
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   464
  static uint total_yields() { return _total_yields; }
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   465
  static uint total_spins() { return _total_spins; }
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   466
  static uint total_peeks() { return _total_peeks; }
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   467
  static void print_termination_counts();
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   468
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
template<class E> inline bool GenericTaskQueue<E>::push(E t) {
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   472
  uint localBot = _bottom;
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   473
  assert((localBot >= 0) && (localBot < N), "_bottom out of range.");
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   474
  idx_t top = _age.top();
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   475
  uint dirty_n_elems = dirty_size(localBot, top);
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   476
  assert((dirty_n_elems >= 0) && (dirty_n_elems < N), "n_elems out of range.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  if (dirty_n_elems < max_elems()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    _elems[localBot] = t;
4027
1c62fbaf6b68 6888847: TaskQueue needs release_store() for correctness on RMO machines
bobv
parents: 3607
diff changeset
   479
    OrderAccess::release_store(&_bottom, increment_index(localBot));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    return push_slow(t, dirty_n_elems);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
template<class E> inline bool GenericTaskQueue<E>::pop_local(E& t) {
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   487
  uint localBot = _bottom;
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   488
  // This value cannot be N-1.  That can only occur as a result of
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  // the assignment to bottom in this method.  If it does, this method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  // resets the size( to 0 before the next call (which is sequential,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  // since this is pop_local.)
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   492
  uint dirty_n_elems = dirty_size(localBot, _age.top());
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   493
  assert(dirty_n_elems != N - 1, "Shouldn't be possible...");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  if (dirty_n_elems == 0) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  localBot = decrement_index(localBot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  _bottom = localBot;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  // This is necessary to prevent any read below from being reordered
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  // before the store just above.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  OrderAccess::fence();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  t = _elems[localBot];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  // This is a second read of "age"; the "size()" above is the first.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  // If there's still at least one element in the queue, based on the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  // "_bottom" and "age" we've read, then there can be no interference with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  // a "pop_global" operation, and we're done.
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   505
  idx_t tp = _age.top();    // XXX
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  if (size(localBot, tp) > 0) {
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   507
    assert(dirty_size(localBot, tp) != N - 1, "sanity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    // Otherwise, the queue contained exactly one element; we take the slow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
    // path.
3607
fa62293fa65c 6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents: 3262
diff changeset
   512
    return pop_local_slow(localBot, _age.get());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
typedef oop Task;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
typedef GenericTaskQueue<Task>         OopTaskQueue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
typedef GenericTaskQueueSet<Task>      OopTaskQueueSet;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   520
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   521
#define COMPRESSED_OOP_MASK  1
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   522
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   523
// This is a container class for either an oop* or a narrowOop*.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   524
// Both are pushed onto a task queue and the consumer will test is_narrow()
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   525
// to determine which should be processed.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   526
class StarTask {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   527
  void*  _holder;        // either union oop* or narrowOop*
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   528
 public:
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2105
diff changeset
   529
  StarTask(narrowOop* p) {
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2105
diff changeset
   530
    assert(((uintptr_t)p & COMPRESSED_OOP_MASK) == 0, "Information loss!");
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2105
diff changeset
   531
    _holder = (void *)((uintptr_t)p | COMPRESSED_OOP_MASK);
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2105
diff changeset
   532
  }
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2105
diff changeset
   533
  StarTask(oop* p)       {
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2105
diff changeset
   534
    assert(((uintptr_t)p & COMPRESSED_OOP_MASK) == 0, "Information loss!");
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2105
diff changeset
   535
    _holder = (void*)p;
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2105
diff changeset
   536
  }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   537
  StarTask()             { _holder = NULL; }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   538
  operator oop*()        { return (oop*)_holder; }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   539
  operator narrowOop*()  {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   540
    return (narrowOop*)((uintptr_t)_holder & ~COMPRESSED_OOP_MASK);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   541
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   542
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   543
  // Operators to preserve const/volatile in assignments required by gcc
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   544
  void operator=(const volatile StarTask& t) volatile { _holder = t._holder; }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   545
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   546
  bool is_narrow() const {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   547
    return (((uintptr_t)_holder & COMPRESSED_OOP_MASK) != 0);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   548
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   549
};
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   550
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
typedef GenericTaskQueue<StarTask>     OopStarTaskQueue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
typedef GenericTaskQueueSet<StarTask>  OopStarTaskQueueSet;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1388
diff changeset
   554
typedef size_t RegionTask;  // index for region
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1388
diff changeset
   555
typedef GenericTaskQueue<RegionTask>    RegionTaskQueue;
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1388
diff changeset
   556
typedef GenericTaskQueueSet<RegionTask> RegionTaskQueueSet;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1388
diff changeset
   558
class RegionTaskQueueWithOverflow: public CHeapObj {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
 protected:
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1388
diff changeset
   560
  RegionTaskQueue              _region_queue;
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1388
diff changeset
   561
  GrowableArray<RegionTask>*   _overflow_stack;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
 public:
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1388
diff changeset
   564
  RegionTaskQueueWithOverflow() : _overflow_stack(NULL) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  // Initialize both stealable queue and overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  void initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  // Save first to stealable queue and then to overflow
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1388
diff changeset
   568
  void save(RegionTask t);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  // Retrieve first from overflow and then from stealable queue
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1388
diff changeset
   570
  bool retrieve(RegionTask& region_index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  // Retrieve from stealable queue
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1388
diff changeset
   572
  bool retrieve_from_stealable_queue(RegionTask& region_index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  // Retrieve from overflow
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1388
diff changeset
   574
  bool retrieve_from_overflow(RegionTask& region_index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  bool is_empty();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  bool stealable_is_empty();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  bool overflow_is_empty();
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1407
diff changeset
   578
  uint stealable_size() { return _region_queue.size(); }
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1388
diff changeset
   579
  RegionTaskQueue* task_queue() { return &_region_queue; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1388
diff changeset
   582
#define USE_RegionTaskQueueWithOverflow