hotspot/src/share/vm/utilities/taskqueue.cpp
author xlu
Mon, 06 Apr 2009 15:47:39 -0700
changeset 2526 39a58a50be35
parent 2105 347008ce7984
child 3262 30d1c247fc25
permissions -rw-r--r--
6699669: Hotspot server leaves synchronized block with monitor in bad state Summary: Remove usage of _highest_lock field in Thread so that is_lock_owned won't depend on the correct update of that field. Reviewed-by: never, dice, acorn
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
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_taskqueue.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
2010
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    28
#ifdef TRACESPINNING
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    29
uint ParallelTaskTerminator::_total_yields = 0;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    30
uint ParallelTaskTerminator::_total_spins = 0;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    31
uint ParallelTaskTerminator::_total_peeks = 0;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    32
#endif
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
bool TaskQueueSuper::peek() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  return _bottom != _age.top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
int TaskQueueSetSuper::randomParkAndMiller(int *seed0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  const int a =      16807;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  const int m = 2147483647;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  const int q =     127773;  /* m div a */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  const int r =       2836;  /* m mod a */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  assert(sizeof(int) == 4, "I think this relies on that");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  int seed = *seed0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  int hi   = seed / q;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  int lo   = seed % q;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  int test = a * lo - r * hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  if (test > 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    seed = test;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    seed = test + m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  *seed0 = seed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  return seed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
ParallelTaskTerminator::
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
ParallelTaskTerminator(int n_threads, TaskQueueSetSuper* queue_set) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  _n_threads(n_threads),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  _queue_set(queue_set),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  _offered_termination(0) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
bool ParallelTaskTerminator::peek_in_queue_set() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  return _queue_set->peek();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
void ParallelTaskTerminator::yield() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  os::yield();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
void ParallelTaskTerminator::sleep(uint millis) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  os::sleep(Thread::current(), millis, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    74
bool
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    75
ParallelTaskTerminator::offer_termination(TerminatorTerminator* terminator) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  Atomic::inc(&_offered_termination);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
2005
42075507972b 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 1623
diff changeset
    78
  uint yield_count = 0;
2010
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    79
  // Number of hard spin loops done since last yield
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    80
  uint hard_spin_count = 0;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    81
  // Number of iterations in the hard spin loop.
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    82
  uint hard_spin_limit = WorkStealingHardSpins;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    83
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    84
  // If WorkStealingSpinToYieldRatio is 0, no hard spinning is done.
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    85
  // If it is greater than 0, then start with a small number
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    86
  // of spins and increase number with each turn at spinning until
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    87
  // the count of hard spins exceeds WorkStealingSpinToYieldRatio.
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    88
  // Then do a yield() call and start spinning afresh.
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    89
  if (WorkStealingSpinToYieldRatio > 0) {
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    90
    hard_spin_limit = WorkStealingHardSpins >> WorkStealingSpinToYieldRatio;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    91
    hard_spin_limit = MAX2(hard_spin_limit, 1U);
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    92
  }
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    93
  // Remember the initial spin limit.
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    94
  uint hard_spin_start = hard_spin_limit;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    95
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    96
  // Loop waiting for all threads to offer termination or
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    97
  // more work.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  while (true) {
2010
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
    99
    // Are all threads offering termination?
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    if (_offered_termination == _n_threads) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    } else {
2010
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   103
      // Look for more work.
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   104
      // Periodically sleep() instead of yield() to give threads
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   105
      // waiting on the cores the chance to grab this code
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      if (yield_count <= WorkStealingYieldsBeforeSleep) {
2010
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   107
        // Do a yield or hardspin.  For purposes of deciding whether
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   108
        // to sleep, count this as a yield.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
        yield_count++;
2010
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   110
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   111
        // Periodically call yield() instead spinning
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   112
        // After WorkStealingSpinToYieldRatio spins, do a yield() call
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   113
        // and reset the counts and starting limit.
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   114
        if (hard_spin_count > WorkStealingSpinToYieldRatio) {
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   115
          yield();
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   116
          hard_spin_count = 0;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   117
          hard_spin_limit = hard_spin_start;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   118
#ifdef TRACESPINNING
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   119
          _total_yields++;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   120
#endif
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   121
        } else {
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   122
          // Hard spin this time
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   123
          // Increase the hard spinning period but only up to a limit.
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   124
          hard_spin_limit = MIN2(2*hard_spin_limit,
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   125
                                 (uint) WorkStealingHardSpins);
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   126
          for (uint j = 0; j < hard_spin_limit; j++) {
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   127
            SpinPause();
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   128
          }
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   129
          hard_spin_count++;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   130
#ifdef TRACESPINNING
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   131
          _total_spins++;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   132
#endif
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   133
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
        if (PrintGCDetails && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
         gclog_or_tty->print_cr("ParallelTaskTerminator::offer_termination() "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
           "thread %d sleeps after %d yields",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
           Thread::current(), yield_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
        yield_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
        // A sleep will cause this processor to seek work on another processor's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
        // runqueue, if it has nothing else to run (as opposed to the yield
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
        // which may only move the thread to the end of the this processor's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
        // runqueue).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
        sleep(WorkStealingSleepMillis);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
2010
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   148
#ifdef TRACESPINNING
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   149
      _total_peeks++;
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   150
#endif
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   151
      if (peek_in_queue_set() ||
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   152
          (terminator != NULL && terminator->should_exit_termination())) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
        Atomic::dec(&_offered_termination);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
2010
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   160
#ifdef TRACESPINNING
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   161
void ParallelTaskTerminator::print_termination_counts() {
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   162
  gclog_or_tty->print_cr("ParallelTaskTerminator Total yields: %lld  "
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   163
    "Total spins: %lld  Total peeks: %lld",
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   164
    total_yields(),
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   165
    total_spins(),
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   166
    total_peeks());
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   167
}
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   168
#endif
c13462bbad17 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 2005
diff changeset
   169
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
void ParallelTaskTerminator::reset_for_reuse() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  if (_offered_termination != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    assert(_offered_termination == _n_threads,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
           "Terminator may still be in use");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    _offered_termination = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   178
bool RegionTaskQueueWithOverflow::is_empty() {
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   179
  return (_region_queue.size() == 0) &&
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
         (_overflow_stack->length() == 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   183
bool RegionTaskQueueWithOverflow::stealable_is_empty() {
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   184
  return _region_queue.size() == 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   187
bool RegionTaskQueueWithOverflow::overflow_is_empty() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  return _overflow_stack->length() == 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   191
void RegionTaskQueueWithOverflow::initialize() {
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   192
  _region_queue.initialize();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  assert(_overflow_stack == 0, "Creating memory leak");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  _overflow_stack =
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   195
    new (ResourceObj::C_HEAP) GrowableArray<RegionTask>(10, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   198
void RegionTaskQueueWithOverflow::save(RegionTask t) {
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   199
  if (TraceRegionTasksQueuing && Verbose) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    gclog_or_tty->print_cr("CTQ: save " PTR_FORMAT, t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   202
  if(!_region_queue.push(t)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    _overflow_stack->push(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   207
// Note that using this method will retrieve all regions
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
// that have been saved but that it will always check
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
// the overflow stack.  It may be more efficient to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
// check the stealable queue and the overflow stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
// separately.
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   212
bool RegionTaskQueueWithOverflow::retrieve(RegionTask& region_task) {
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   213
  bool result = retrieve_from_overflow(region_task);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  if (!result) {
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   215
    result = retrieve_from_stealable_queue(region_task);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  }
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   217
  if (TraceRegionTasksQueuing && Verbose && result) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    gclog_or_tty->print_cr("  CTQ: retrieve " PTR_FORMAT, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   223
bool RegionTaskQueueWithOverflow::retrieve_from_stealable_queue(
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   224
                                   RegionTask& region_task) {
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   225
  bool result = _region_queue.pop_local(region_task);
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   226
  if (TraceRegionTasksQueuing && Verbose) {
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   227
    gclog_or_tty->print_cr("CTQ: retrieve_stealable " PTR_FORMAT, region_task);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   232
bool
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   233
RegionTaskQueueWithOverflow::retrieve_from_overflow(RegionTask& region_task) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  bool result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  if (!_overflow_stack->is_empty()) {
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   236
    region_task = _overflow_stack->pop();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    result = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  } else {
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   239
    region_task = (RegionTask) NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    result = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  }
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   242
  if (TraceRegionTasksQueuing && Verbose) {
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1374
diff changeset
   243
    gclog_or_tty->print_cr("CTQ: retrieve_stealable " PTR_FORMAT, region_task);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
}