hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp
author sla
Mon, 10 Jun 2013 11:30:51 +0200
changeset 18025 b7bcf7497f93
parent 13728 882756847a04
child 19285 0a3b3f115402
permissions -rw-r--r--
8005849: JEP 167: Event-Based JVM Tracing Reviewed-by: acorn, coleenp, sla Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 13728
diff changeset
     2
 * Copyright (c) 2002, 2013, 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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    26
#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    27
#include "gc_implementation/parallelScavenge/psOldGen.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    28
#include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    29
#include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 13728
diff changeset
    30
#include "gc_implementation/shared/gcTrace.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    31
#include "gc_implementation/shared/mutableSpace.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    32
#include "memory/memRegion.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    33
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    34
#include "oops/oop.psgc.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
PSPromotionManager**         PSPromotionManager::_manager_array = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
OopStarTaskQueueSet*         PSPromotionManager::_stack_array_depth = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
PSOldGen*                    PSPromotionManager::_old_gen = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
MutableSpace*                PSPromotionManager::_young_space = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
void PSPromotionManager::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  _old_gen = heap->old_gen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  _young_space = heap->young_gen()->to_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  assert(_manager_array == NULL, "Attempt to initialize twice");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11753
diff changeset
    49
  _manager_array = NEW_C_HEAP_ARRAY(PSPromotionManager*, ParallelGCThreads+1, mtGC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  guarantee(_manager_array != NULL, "Could not initialize promotion manager");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
6248
2e661807cef0 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 6067
diff changeset
    52
  _stack_array_depth = new OopStarTaskQueueSet(ParallelGCThreads);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 13728
diff changeset
    53
  guarantee(_stack_array_depth != NULL, "Could not initialize promotion manager");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // Create and register the PSPromotionManager(s) for the worker threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  for(uint i=0; i<ParallelGCThreads; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    _manager_array[i] = new PSPromotionManager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    guarantee(_manager_array[i] != NULL, "Could not create PSPromotionManager");
6248
2e661807cef0 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 6067
diff changeset
    59
    stack_array_depth()->register_queue(i, _manager_array[i]->claimed_stack_depth());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // The VMThread gets its own PSPromotionManager, which is not available
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // for work stealing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  _manager_array[ParallelGCThreads] = new PSPromotionManager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  guarantee(_manager_array[ParallelGCThreads] != NULL, "Could not create PSPromotionManager");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
PSPromotionManager* PSPromotionManager::gc_thread_promotion_manager(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  assert(index >= 0 && index < (int)ParallelGCThreads, "index out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  assert(_manager_array != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  return _manager_array[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
PSPromotionManager* PSPromotionManager::vm_thread_promotion_manager() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  assert(_manager_array != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  return _manager_array[ParallelGCThreads];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
void PSPromotionManager::pre_scavenge() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  _young_space = heap->young_gen()->to_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  for(uint i=0; i<ParallelGCThreads+1; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    manager_array(i)->reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 13728
diff changeset
    90
bool PSPromotionManager::post_scavenge(YoungGCTracer& gc_tracer) {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 13728
diff changeset
    91
  bool promotion_failure_occurred = false;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 13728
diff changeset
    92
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);
6248
2e661807cef0 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 6067
diff changeset
    96
    assert(manager->claimed_stack_depth()->is_empty(), "should be empty");
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 13728
diff changeset
    97
    if (manager->_promotion_failed_info.has_failed()) {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 13728
diff changeset
    98
      gc_tracer.report_promotion_failed(manager->_promotion_failed_info);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 13728
diff changeset
    99
      promotion_failure_occurred = true;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 13728
diff changeset
   100
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    manager->flush_labs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 13728
diff changeset
   103
  return promotion_failure_occurred;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   106
#if TASKQUEUE_STATS
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
void
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   108
PSPromotionManager::print_taskqueue_stats(uint i) const {
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   109
  tty->print("%3u ", i);
6248
2e661807cef0 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 6067
diff changeset
   110
  _claimed_stack_depth.stats.print();
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   111
  tty->cr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
void
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   115
PSPromotionManager::print_local_stats(uint i) const {
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   116
  #define FMT " " SIZE_FORMAT_W(10)
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   117
  tty->print_cr("%3u" FMT FMT FMT FMT, i, _masked_pushes, _masked_steals,
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   118
                _arrays_chunked, _array_chunks_processed);
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   119
  #undef FMT
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   120
}
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   121
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   122
static const char* const pm_stats_hdr[] = {
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   123
  "    --------masked-------     arrays      array",
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   124
  "thr       push      steal    chunked     chunks",
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   125
  "--- ---------- ---------- ---------- ----------"
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
void
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
PSPromotionManager::print_stats() {
6248
2e661807cef0 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 6067
diff changeset
   130
  tty->print_cr("== GC Tasks Stats, GC %3d",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
                Universe::heap()->total_collections());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   133
  tty->print("thr "); TaskQueueStats::print_header(1); tty->cr();
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   134
  tty->print("--- "); TaskQueueStats::print_header(2); tty->cr();
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   135
  for (uint i = 0; i < ParallelGCThreads + 1; ++i) {
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   136
    manager_array(i)->print_taskqueue_stats(i);
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   137
  }
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   138
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   139
  const uint hlines = sizeof(pm_stats_hdr) / sizeof(pm_stats_hdr[0]);
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   140
  for (uint i = 0; i < hlines; ++i) tty->print_cr(pm_stats_hdr[i]);
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   141
  for (uint i = 0; i < ParallelGCThreads + 1; ++i) {
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   142
    manager_array(i)->print_local_stats(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   146
void
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   147
PSPromotionManager::reset_stats() {
6248
2e661807cef0 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 6067
diff changeset
   148
  claimed_stack_depth()->stats.reset();
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   149
  _masked_pushes = _masked_steals = 0;
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   150
  _arrays_chunked = _array_chunks_processed = 0;
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   151
}
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   152
#endif // TASKQUEUE_STATS
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
PSPromotionManager::PSPromotionManager() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // We set the old lab's start array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  _old_lab.set_start_array(old_gen()->start_array());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  uint queue_size;
6248
2e661807cef0 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 6067
diff changeset
   162
  claimed_stack_depth()->initialize();
2e661807cef0 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 6067
diff changeset
   163
  queue_size = claimed_stack_depth()->max_elems();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  _totally_drain = (ParallelGCThreads == 1) || (GCDrainStackTargetSize == 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  if (_totally_drain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    _target_stack_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    // don't let the target stack size to be more than 1/4 of the entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    _target_stack_size = (uint) MIN2((uint) GCDrainStackTargetSize,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
                                     (uint) (queue_size / 4));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  _array_chunk_size = ParGCArrayScanChunk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  // let's choose 1.5x the chunk size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  _min_array_size_for_chunking = 3 * _array_chunk_size / 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
void PSPromotionManager::reset() {
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   182
  assert(stacks_empty(), "reset of non-empty stack");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  // We need to get an assert in here to make sure the labs are always flushed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  // Do not prefill the LAB's, save heap wastage!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  HeapWord* lab_base = young_space()->top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  _young_lab.initialize(MemRegion(lab_base, (size_t)0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  _young_gen_is_full = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  lab_base = old_gen()->object_space()->top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  _old_lab.initialize(MemRegion(lab_base, (size_t)0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  _old_gen_is_full = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 13728
diff changeset
   198
  _promotion_failed_info.reset();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 13728
diff changeset
   199
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   200
  TASKQUEUE_STATS_ONLY(reset_stats());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   203
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
void PSPromotionManager::drain_stacks_depth(bool totally_drain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  totally_drain = totally_drain || _totally_drain;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  MutableSpace* to_space = heap->young_gen()->to_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  MutableSpace* old_space = heap->old_gen()->object_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
#endif /* ASSERT */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   214
  OopStarTaskQueue* const tq = claimed_stack_depth();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  do {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   216
    StarTask p;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    // Drain overflow stack first, so other threads can steal from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    // claimed stack while we work.
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   220
    while (tq->pop_overflow(p)) {
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   221
      process_popped_location_depth(p);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    if (totally_drain) {
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   225
      while (tq->pop_local(p)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
        process_popped_location_depth(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    } else {
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   229
      while (tq->size() > _target_stack_size && tq->pop_local(p)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
        process_popped_location_depth(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    }
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   233
  } while (totally_drain && !tq->taskqueue_empty() || !tq->overflow_empty());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   235
  assert(!totally_drain || tq->taskqueue_empty(), "Sanity");
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   236
  assert(totally_drain || tq->size() <= _target_stack_size, "Sanity");
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   237
  assert(tq->overflow_empty(), "Sanity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
void PSPromotionManager::flush_labs() {
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   241
  assert(stacks_empty(), "Attempt to flush lab with live stack");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  // If either promotion lab fills up, we can flush the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  // lab but not refill it, so check first.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  assert(!_young_lab.is_flushed() || _young_gen_is_full, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  if (!_young_lab.is_flushed())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    _young_lab.flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  assert(!_old_lab.is_flushed() || _old_gen_is_full, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  if (!_old_lab.is_flushed())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    _old_lab.flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  // Let PSScavenge know if we overflowed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  if (_young_gen_is_full) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    PSScavenge::set_survivor_overflow(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   259
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
   260
                                                 oop obj,
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   261
                                                 int start, int end) {
8685
f8edcc58cca7 6820066: Check that -XX:ParGCArrayScanChunk has a value larger than zero.
jwilhelm
parents: 7397
diff changeset
   262
  assert(start <= end, "invariant");
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   263
  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
   264
  T* p               = base + start;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   265
  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
   266
  while (p < chunk_end) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   267
    if (PSScavenge::should_scavenge(p)) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   268
      claim_or_forward_depth(p);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   269
    }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   270
    ++p;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   271
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   272
}
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   273
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
void PSPromotionManager::process_array_chunk(oop old) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  assert(PSChunkLargeArrays, "invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  assert(old->is_objArray(), "invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  assert(old->is_forwarded(), "invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   279
  TASKQUEUE_STATS_ONLY(++_array_chunks_processed);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  oop const obj = old->forwardee();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  int start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  int const end = arrayOop(old)->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  if (end > (int) _min_array_size_for_chunking) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    // we'll chunk more
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    start = end - _array_chunk_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    assert(start > 0, "invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    arrayOop(old)->set_length(start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    push_depth(mask_chunked_array_oop(old));
6067
8bfddf73fc04 6962947: shared TaskQueue statistics
jcoomes
parents: 5918
diff changeset
   291
    TASKQUEUE_STATS_ONLY(++_masked_pushes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    // this is the final chunk for this array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    start = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    int const actual_length = arrayOop(obj)->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    arrayOop(old)->set_length(actual_length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   299
  if (UseCompressedOops) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   300
    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
   301
  } else {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   302
    process_array_chunk_work<oop>(obj, start, end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
oop PSPromotionManager::oop_promotion_failed(oop obj, markOop obj_mark) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  assert(_old_gen_is_full || PromotionFailureALot, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  // Attempt to CAS in the header.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  // This tests if the header is still the same as when
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  // this started.  If it is the same (i.e., no forwarding
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  // pointer has been installed), then this thread owns
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  // it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  if (obj->cas_forward_to(obj, obj_mark)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    // We won any races, we "own" this object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    assert(obj == obj->forwardee(), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 13728
diff changeset
   318
    _promotion_failed_info.register_copy_failure(obj->size());
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 13728
diff changeset
   319
6248
2e661807cef0 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 6067
diff changeset
   320
    obj->push_contents(this);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    // Save the mark if needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    PSScavenge::oop_promotion_failed(obj, obj_mark);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  }  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    // We lost, someone else "owns" this object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    guarantee(obj->is_forwarded(), "Object must be forwarded if the cas failed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    // No unallocation to worry about.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    obj = obj->forwardee();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   332
#ifndef PRODUCT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  if (TraceScavenge) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    gclog_or_tty->print_cr("{%s %s 0x%x (%d)}",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
                           "promotion-failure",
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   336
                           obj->klass()->internal_name(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
                           obj, obj->size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  return obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
}