hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp
author jcoomes
Fri, 16 Jul 2010 21:33:21 -0700
changeset 6067 8bfddf73fc04
parent 5918 73b96456819a
child 6248 2e661807cef0
permissions -rw-r--r--
6962947: shared TaskQueue statistics Reviewed-by: tonyp, ysr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
     2
 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. 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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    21
 * questions.
1
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/_psPromotionManager.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
PSPromotionManager**         PSPromotionManager::_manager_array = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
OopStarTaskQueueSet*         PSPromotionManager::_stack_array_depth = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
OopTaskQueueSet*             PSPromotionManager::_stack_array_breadth = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
PSOldGen*                    PSPromotionManager::_old_gen = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
MutableSpace*                PSPromotionManager::_young_space = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
void PSPromotionManager::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  _old_gen = heap->old_gen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  _young_space = heap->young_gen()->to_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  assert(_manager_array == NULL, "Attempt to initialize twice");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  _manager_array = NEW_C_HEAP_ARRAY(PSPromotionManager*, ParallelGCThreads+1 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  guarantee(_manager_array != NULL, "Could not initialize promotion manager");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  if (UseDepthFirstScavengeOrder) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    _stack_array_depth = new OopStarTaskQueueSet(ParallelGCThreads);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    guarantee(_stack_array_depth != NULL, "Count not initialize promotion manager");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    _stack_array_breadth = new OopTaskQueueSet(ParallelGCThreads);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    guarantee(_stack_array_breadth != NULL, "Count not initialize promotion manager");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // Create and register the PSPromotionManager(s) for the worker threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  for(uint i=0; i<ParallelGCThreads; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    _manager_array[i] = new PSPromotionManager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    guarantee(_manager_array[i] != NULL, "Could not create PSPromotionManager");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    if (UseDepthFirstScavengeOrder) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
      stack_array_depth()->register_queue(i, _manager_array[i]->claimed_stack_depth());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      stack_array_breadth()->register_queue(i, _manager_array[i]->claimed_stack_breadth());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // The VMThread gets its own PSPromotionManager, which is not available
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // for work stealing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  _manager_array[ParallelGCThreads] = new PSPromotionManager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  guarantee(_manager_array[ParallelGCThreads] != NULL, "Could not create PSPromotionManager");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
PSPromotionManager* PSPromotionManager::gc_thread_promotion_manager(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  assert(index >= 0 && index < (int)ParallelGCThreads, "index out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  assert(_manager_array != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  return _manager_array[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
PSPromotionManager* PSPromotionManager::vm_thread_promotion_manager() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  assert(_manager_array != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  return _manager_array[ParallelGCThreads];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
void PSPromotionManager::pre_scavenge() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  _young_space = heap->young_gen()->to_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  for(uint i=0; i<ParallelGCThreads+1; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    manager_array(i)->reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
void PSPromotionManager::post_scavenge() {
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
    93
  TASKQUEUE_STATS_ONLY(if (PrintGCDetails && ParallelGCVerbose) print_stats());
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
    94
  for (uint i = 0; i < ParallelGCThreads + 1; i++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    PSPromotionManager* manager = manager_array(i);
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
    96
    if (UseDepthFirstScavengeOrder) {
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
    97
      assert(manager->claimed_stack_depth()->is_empty(), "should be empty");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    } else {
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
    99
      assert(manager->claimed_stack_breadth()->is_empty(), "should be empty");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    manager->flush_labs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   105
#if TASKQUEUE_STATS
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
void
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   107
PSPromotionManager::print_taskqueue_stats(uint i) const {
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   108
  const TaskQueueStats& stats = depth_first() ?
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   109
    _claimed_stack_depth.stats : _claimed_stack_breadth.stats;
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   110
  tty->print("%3u ", i);
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   111
  stats.print();
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   112
  tty->cr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
void
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   116
PSPromotionManager::print_local_stats(uint i) const {
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   117
  #define FMT " " SIZE_FORMAT_W(10)
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   118
  tty->print_cr("%3u" FMT FMT FMT FMT, i, _masked_pushes, _masked_steals,
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   119
                _arrays_chunked, _array_chunks_processed);
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   120
  #undef FMT
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   121
}
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   122
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   123
static const char* const pm_stats_hdr[] = {
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   124
  "    --------masked-------     arrays      array",
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   125
  "thr       push      steal    chunked     chunks",
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   126
  "--- ---------- ---------- ---------- ----------"
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   127
};
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   128
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   129
void
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
PSPromotionManager::print_stats() {
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   131
  const bool df = UseDepthFirstScavengeOrder;
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   132
  tty->print_cr("== GC Task Stats (%s-First), GC %3d", df ? "Depth" : "Breadth",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
                Universe::heap()->total_collections());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   135
  tty->print("thr "); TaskQueueStats::print_header(1); tty->cr();
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   136
  tty->print("--- "); TaskQueueStats::print_header(2); tty->cr();
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   137
  for (uint i = 0; i < ParallelGCThreads + 1; ++i) {
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   138
    manager_array(i)->print_taskqueue_stats(i);
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   139
  }
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   140
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   141
  const uint hlines = sizeof(pm_stats_hdr) / sizeof(pm_stats_hdr[0]);
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   142
  for (uint i = 0; i < hlines; ++i) tty->print_cr(pm_stats_hdr[i]);
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   143
  for (uint i = 0; i < ParallelGCThreads + 1; ++i) {
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   144
    manager_array(i)->print_local_stats(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   148
void
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   149
PSPromotionManager::reset_stats() {
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   150
  TaskQueueStats& stats = depth_first() ?
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   151
    claimed_stack_depth()->stats : claimed_stack_breadth()->stats;
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   152
  stats.reset();
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   153
  _masked_pushes = _masked_steals = 0;
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   154
  _arrays_chunked = _array_chunks_processed = 0;
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   155
}
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   156
#endif // TASKQUEUE_STATS
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
PSPromotionManager::PSPromotionManager() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  _depth_first = UseDepthFirstScavengeOrder;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // We set the old lab's start array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  _old_lab.set_start_array(old_gen()->start_array());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  uint queue_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  if (depth_first()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    claimed_stack_depth()->initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    queue_size = claimed_stack_depth()->max_elems();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    claimed_stack_breadth()->initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    queue_size = claimed_stack_breadth()->max_elems();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  _totally_drain = (ParallelGCThreads == 1) || (GCDrainStackTargetSize == 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  if (_totally_drain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    _target_stack_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    // don't let the target stack size to be more than 1/4 of the entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    _target_stack_size = (uint) MIN2((uint) GCDrainStackTargetSize,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
                                     (uint) (queue_size / 4));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  _array_chunk_size = ParGCArrayScanChunk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // let's choose 1.5x the chunk size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  _min_array_size_for_chunking = 3 * _array_chunk_size / 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
void PSPromotionManager::reset() {
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   192
  assert(stacks_empty(), "reset of non-empty stack");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  // We need to get an assert in here to make sure the labs are always flushed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  // Do not prefill the LAB's, save heap wastage!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  HeapWord* lab_base = young_space()->top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  _young_lab.initialize(MemRegion(lab_base, (size_t)0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  _young_gen_is_full = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  lab_base = old_gen()->object_space()->top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  _old_lab.initialize(MemRegion(lab_base, (size_t)0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  _old_gen_is_full = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  _prefetch_queue.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   210
  TASKQUEUE_STATS_ONLY(reset_stats());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   213
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
void PSPromotionManager::drain_stacks_depth(bool totally_drain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  assert(depth_first(), "invariant");
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   216
  assert(claimed_stack_depth()->overflow_stack() != NULL, "invariant");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  totally_drain = totally_drain || _totally_drain;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  MutableSpace* to_space = heap->young_gen()->to_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  MutableSpace* old_space = heap->old_gen()->object_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  MutableSpace* perm_space = heap->perm_gen()->object_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
#endif /* ASSERT */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   227
  OopStarTaskQueue* const tq = claimed_stack_depth();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  do {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   229
    StarTask p;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    // Drain overflow stack first, so other threads can steal from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    // claimed stack while we work.
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   233
    while (tq->pop_overflow(p)) {
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   234
      process_popped_location_depth(p);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    if (totally_drain) {
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   238
      while (tq->pop_local(p)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
        process_popped_location_depth(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    } else {
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   242
      while (tq->size() > _target_stack_size && tq->pop_local(p)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
        process_popped_location_depth(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    }
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   246
  } while (totally_drain && !tq->taskqueue_empty() || !tq->overflow_empty());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   248
  assert(!totally_drain || tq->taskqueue_empty(), "Sanity");
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   249
  assert(totally_drain || tq->size() <= _target_stack_size, "Sanity");
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   250
  assert(tq->overflow_empty(), "Sanity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
void PSPromotionManager::drain_stacks_breadth(bool totally_drain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  assert(!depth_first(), "invariant");
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   255
  assert(claimed_stack_breadth()->overflow_stack() != NULL, "invariant");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  totally_drain = totally_drain || _totally_drain;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  MutableSpace* to_space = heap->young_gen()->to_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  MutableSpace* old_space = heap->old_gen()->object_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  MutableSpace* perm_space = heap->perm_gen()->object_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
#endif /* ASSERT */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   266
  OverflowTaskQueue<oop>* const tq = claimed_stack_breadth();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    oop obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    // Drain overflow stack first, so other threads can steal from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    // claimed stack while we work.
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   272
    while (tq->pop_overflow(obj)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
      obj->copy_contents(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    if (totally_drain) {
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   277
      while (tq->pop_local(obj)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
        obj->copy_contents(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    } else {
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   281
      while (tq->size() > _target_stack_size && tq->pop_local(obj)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
        obj->copy_contents(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    // If we could not find any other work, flush the prefetch queue
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   287
    if (tq->is_empty()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      flush_prefetch_queue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    }
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   290
  } while (totally_drain && !tq->taskqueue_empty() || !tq->overflow_empty());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   292
  assert(!totally_drain || tq->taskqueue_empty(), "Sanity");
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   293
  assert(totally_drain || tq->size() <= _target_stack_size, "Sanity");
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   294
  assert(tq->overflow_empty(), "Sanity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
void PSPromotionManager::flush_labs() {
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   298
  assert(stacks_empty(), "Attempt to flush lab with live stack");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  // If either promotion lab fills up, we can flush the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  // lab but not refill it, so check first.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  assert(!_young_lab.is_flushed() || _young_gen_is_full, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  if (!_young_lab.is_flushed())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    _young_lab.flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  assert(!_old_lab.is_flushed() || _old_gen_is_full, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  if (!_old_lab.is_flushed())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    _old_lab.flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  // Let PSScavenge know if we overflowed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  if (_young_gen_is_full) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    PSScavenge::set_survivor_overflow(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
// This method is pretty bulky. It would be nice to split it up
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
// into smaller submethods, but we need to be careful not to hurt
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
// performance.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
oop PSPromotionManager::copy_to_survivor_space(oop o, bool depth_first) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   323
  assert(PSScavenge::should_scavenge(&o), "Sanity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  oop new_obj = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  // NOTE! We must be very careful with any methods that access the mark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  // in o. There may be multiple threads racing on it, and it may be forwarded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  // at any time. Do not use oop methods for accessing the mark!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  markOop test_mark = o->mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  // The same test as "o->is_forwarded()"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  if (!test_mark->is_marked()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    bool new_obj_is_tenured = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    size_t new_obj_size = o->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    // Find the objects age, MT safe.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    int age = (test_mark->has_displaced_mark_helper() /* o->has_displaced_mark() */) ?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
      test_mark->displaced_mark_helper()->age() : test_mark->age();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    // Try allocating obj in to-space (unless too old)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    if (age < PSScavenge::tenuring_threshold()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
      new_obj = (oop) _young_lab.allocate(new_obj_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
      if (new_obj == NULL && !_young_gen_is_full) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
        // Do we allocate directly, or flush and refill?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
        if (new_obj_size > (YoungPLABSize / 2)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
          // Allocate this object directly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
          new_obj = (oop)young_space()->cas_allocate(new_obj_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
          // Flush and fill
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
          _young_lab.flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
          HeapWord* lab_base = young_space()->cas_allocate(YoungPLABSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
          if (lab_base != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
            _young_lab.initialize(MemRegion(lab_base, YoungPLABSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
            // Try the young lab allocation again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
            new_obj = (oop) _young_lab.allocate(new_obj_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
            _young_gen_is_full = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    // Otherwise try allocating obj tenured
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    if (new_obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
      if (Universe::heap()->promotion_should_fail()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
        return oop_promotion_failed(o, test_mark);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
#endif  // #ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
      new_obj = (oop) _old_lab.allocate(new_obj_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      new_obj_is_tenured = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
      if (new_obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
        if (!_old_gen_is_full) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
          // Do we allocate directly, or flush and refill?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
          if (new_obj_size > (OldPLABSize / 2)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
            // Allocate this object directly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
            new_obj = (oop)old_gen()->cas_allocate(new_obj_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
            // Flush and fill
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
            _old_lab.flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
            HeapWord* lab_base = old_gen()->cas_allocate(OldPLABSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
            if(lab_base != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
              _old_lab.initialize(MemRegion(lab_base, OldPLABSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
              // Try the old lab allocation again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
              new_obj = (oop) _old_lab.allocate(new_obj_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
        // This is the promotion failed test, and code handling.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
        // The code belongs here for two reasons. It is slightly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
        // different thatn the code below, and cannot share the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
        // CAS testing code. Keeping the code here also minimizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
        // the impact on the common case fast path code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
        if (new_obj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
          _old_gen_is_full = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
          return oop_promotion_failed(o, test_mark);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    assert(new_obj != NULL, "allocation should have succeeded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
    // Copy obj
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)new_obj, new_obj_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    // Now we have to CAS in the header.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    if (o->cas_forward_to(new_obj, test_mark)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
      // We won any races, we "own" this object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
      assert(new_obj == o->forwardee(), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
      // Increment age if obj still in new generation. Now that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
      // we're dealing with a markOop that cannot change, it is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
      // okay to use the non mt safe oop methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
      if (!new_obj_is_tenured) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
        new_obj->incr_age();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
        assert(young_space()->contains(new_obj), "Attempt to push non-promoted obj");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
      if (depth_first) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
        // Do the size comparison first with new_obj_size, which we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
        // already have. Hopefully, only a few objects are larger than
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
        // _min_array_size_for_chunking, and most of them will be arrays.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
        // So, the is->objArray() test would be very infrequent.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
        if (new_obj_size > _min_array_size_for_chunking &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
            new_obj->is_objArray() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
            PSChunkLargeArrays) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
          // we'll chunk it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
          oop* const masked_o = mask_chunked_array_oop(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
          push_depth(masked_o);
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   437
          TASKQUEUE_STATS_ONLY(++_arrays_chunked; ++_masked_pushes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
          // we'll just push its contents
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
          new_obj->push_contents(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
        push_breadth(new_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    }  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
      // We lost, someone else "owns" this object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
      guarantee(o->is_forwarded(), "Object must be forwarded if the cas failed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
1668
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 670
diff changeset
   449
      // Try to deallocate the space.  If it was directly allocated we cannot
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 670
diff changeset
   450
      // deallocate it, so we have to test.  If the deallocation fails,
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 670
diff changeset
   451
      // overwrite with a filler object.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
      if (new_obj_is_tenured) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
        if (!_old_lab.unallocate_object(new_obj)) {
1668
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 670
diff changeset
   454
          CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
        }
1668
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 670
diff changeset
   456
      } else if (!_young_lab.unallocate_object(new_obj)) {
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 670
diff changeset
   457
        CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
      // don't update this before the unallocation!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
      new_obj = o->forwardee();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    assert(o->is_forwarded(), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    new_obj = o->forwardee();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
#ifdef DEBUG
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  // This code must come after the CAS test, or it will print incorrect
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  // information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  if (TraceScavenge) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   472
    gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (" SIZE_FORMAT ")}",
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   473
       PSScavenge::should_scavenge(&new_obj) ? "copying" : "tenuring",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
       new_obj->blueprint()->internal_name(), o, new_obj, new_obj->size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  return new_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   481
template <class T> void PSPromotionManager::process_array_chunk_work(
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   482
                                                 oop obj,
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   483
                                                 int start, int end) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   484
  assert(start < end, "invariant");
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   485
  T* const base      = (T*)objArrayOop(obj)->base();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   486
  T* p               = base + start;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   487
  T* const chunk_end = base + end;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   488
  while (p < chunk_end) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   489
    if (PSScavenge::should_scavenge(p)) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   490
      claim_or_forward_depth(p);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   491
    }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   492
    ++p;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   493
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   494
}
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   495
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
void PSPromotionManager::process_array_chunk(oop old) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  assert(PSChunkLargeArrays, "invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  assert(old->is_objArray(), "invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  assert(old->is_forwarded(), "invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   501
  TASKQUEUE_STATS_ONLY(++_array_chunks_processed);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  oop const obj = old->forwardee();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  int start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  int const end = arrayOop(old)->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  if (end > (int) _min_array_size_for_chunking) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    // we'll chunk more
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    start = end - _array_chunk_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    assert(start > 0, "invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
    arrayOop(old)->set_length(start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
    push_depth(mask_chunked_array_oop(old));
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   513
    TASKQUEUE_STATS_ONLY(++_masked_pushes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    // this is the final chunk for this array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
    start = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    int const actual_length = arrayOop(obj)->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    arrayOop(old)->set_length(actual_length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   521
  if (UseCompressedOops) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   522
    process_array_chunk_work<narrowOop>(obj, start, end);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   523
  } else {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   524
    process_array_chunk_work<oop>(obj, start, end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
oop PSPromotionManager::oop_promotion_failed(oop obj, markOop obj_mark) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  assert(_old_gen_is_full || PromotionFailureALot, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  // Attempt to CAS in the header.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  // This tests if the header is still the same as when
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  // this started.  If it is the same (i.e., no forwarding
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  // pointer has been installed), then this thread owns
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  // it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  if (obj->cas_forward_to(obj, obj_mark)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    // We won any races, we "own" this object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
    assert(obj == obj->forwardee(), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    if (depth_first()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
      obj->push_contents(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
      // Don't bother incrementing the age, just push
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
      // onto the claimed_stack..
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
      push_breadth(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    // Save the mark if needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
    PSScavenge::oop_promotion_failed(obj, obj_mark);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  }  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
    // We lost, someone else "owns" this object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
    guarantee(obj->is_forwarded(), "Object must be forwarded if the cas failed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
    // No unallocation to worry about.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
    obj = obj->forwardee();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
#ifdef DEBUG
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  if (TraceScavenge) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    gclog_or_tty->print_cr("{%s %s 0x%x (%d)}",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
                           "promotion-failure",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
                           obj->blueprint()->internal_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
                           obj, obj->size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  return obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
}