hotspot/src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.cpp
author jcoomes
Tue, 28 Sep 2010 15:56:15 -0700
changeset 6762 f8d1b560700e
parent 5918 73b96456819a
child 7397 5b173b4ca846
permissions -rw-r--r--
6423256: GC stacks should use a better data structure 6942771: SEGV in ParScanThreadState::take_from_overflow_stack Reviewed-by: apetrusenko, ysr, pbk
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) 2005, 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: 5080
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5080
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: 5080
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/_psCompactionManager.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
PSOldGen*            ParCompactionManager::_old_gen = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
ParCompactionManager**  ParCompactionManager::_manager_array = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
OopTaskQueueSet*     ParCompactionManager::_stack_array = NULL;
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
    31
ParCompactionManager::ObjArrayTaskQueueSet*
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
    32
  ParCompactionManager::_objarray_queues = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
ObjectStartArray*    ParCompactionManager::_start_array = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
ParMarkBitMap*       ParCompactionManager::_mark_bitmap = NULL;
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
    35
RegionTaskQueueSet*  ParCompactionManager::_region_array = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
ParCompactionManager::ParCompactionManager() :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    _action(CopyAndUpdate) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  _old_gen = heap->old_gen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  _start_array = old_gen()->start_array();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  marking_stack()->initialize();
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
    47
  _objarray_stack.initialize();
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1
diff changeset
    48
  region_stack()->initialize();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
void ParCompactionManager::initialize(ParMarkBitMap* mbm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  assert(PSParallelCompact::gc_task_manager() != NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    "Needed for initialization");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  _mark_bitmap = mbm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  uint parallel_gc_threads = PSParallelCompact::gc_task_manager()->workers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  assert(_manager_array == NULL, "Attempt to initialize twice");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  _manager_array = NEW_C_HEAP_ARRAY(ParCompactionManager*, parallel_gc_threads+1 );
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
    61
  guarantee(_manager_array != NULL, "Could not allocate manager_array");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  _stack_array = new OopTaskQueueSet(parallel_gc_threads);
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
    64
  guarantee(_stack_array != NULL, "Could not allocate stack_array");
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
    65
  _objarray_queues = new ObjArrayTaskQueueSet(parallel_gc_threads);
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
    66
  guarantee(_objarray_queues != NULL, "Could not allocate objarray_queues");
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1
diff changeset
    67
  _region_array = new RegionTaskQueueSet(parallel_gc_threads);
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
    68
  guarantee(_region_array != NULL, "Could not allocate region_array");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // Create and register the ParCompactionManager(s) for the worker threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  for(uint i=0; i<parallel_gc_threads; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    _manager_array[i] = new ParCompactionManager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    guarantee(_manager_array[i] != NULL, "Could not create ParCompactionManager");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    stack_array()->register_queue(i, _manager_array[i]->marking_stack());
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
    75
    _objarray_queues->register_queue(i, &_manager_array[i]->_objarray_stack);
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1
diff changeset
    76
    region_array()->register_queue(i, _manager_array[i]->region_stack());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // The VMThread gets its own ParCompactionManager, which is not available
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // for work stealing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  _manager_array[parallel_gc_threads] = new ParCompactionManager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  guarantee(_manager_array[parallel_gc_threads] != NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    "Could not create ParCompactionManager");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  assert(PSParallelCompact::gc_task_manager()->workers() != 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    "Not initialized?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
bool ParCompactionManager::should_update() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  assert(action() != NotValid, "Action is not set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  return (action() == ParCompactionManager::Update) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
         (action() == ParCompactionManager::CopyAndUpdate) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
         (action() == ParCompactionManager::UpdateAndCopy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
bool ParCompactionManager::should_copy() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  assert(action() != NotValid, "Action is not set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  return (action() == ParCompactionManager::Copy) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
         (action() == ParCompactionManager::CopyAndUpdate) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
         (action() == ParCompactionManager::UpdateAndCopy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
bool ParCompactionManager::should_verify_only() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  assert(action() != NotValid, "Action is not set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  return action() == ParCompactionManager::VerifyUpdate;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
bool ParCompactionManager::should_reset_only() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  assert(action() != NotValid, "Action is not set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  return action() == ParCompactionManager::ResetObjects;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
ParCompactionManager*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
ParCompactionManager::gc_thread_compaction_manager(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  assert(index >= 0 && index < (int)ParallelGCThreads, "index out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  assert(_manager_array != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  return _manager_array[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
void ParCompactionManager::reset() {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5918
diff changeset
   120
  for(uint i = 0; i < ParallelGCThreads + 1; i++) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5918
diff changeset
   121
    assert(manager_array(i)->revisit_klass_stack()->is_empty(), "sanity");
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5918
diff changeset
   122
    assert(manager_array(i)->revisit_mdo_stack()->is_empty(), "sanity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   126
void ParCompactionManager::follow_marking_stacks() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  do {
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   128
    // Drain the overflow stack first, to allow stealing from the marking stack.
5080
eff0cc882603 6935839: excessive marking stack growth during full gcs
jcoomes
parents: 5076
diff changeset
   129
    oop obj;
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   130
    while (marking_stack()->pop_overflow(obj)) {
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   131
      obj->follow_contents(this);
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   132
    }
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   133
    while (marking_stack()->pop_local(obj)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      obj->follow_contents(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
5080
eff0cc882603 6935839: excessive marking stack growth during full gcs
jcoomes
parents: 5076
diff changeset
   137
    // Process ObjArrays one at a time to avoid marking stack bloat.
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   138
    ObjArrayTask task;
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   139
    if (_objarray_stack.pop_overflow(task)) {
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   140
      objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint();
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   141
      k->oop_follow_contents(this, task.obj(), task.index());
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   142
    } else if (_objarray_stack.pop_local(task)) {
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   143
      objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint();
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   144
      k->oop_follow_contents(this, task.obj(), task.index());
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   145
    }
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   146
  } while (!marking_stacks_empty());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   148
  assert(marking_stacks_empty(), "Sanity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1
diff changeset
   151
void ParCompactionManager::drain_region_stacks() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  do {
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   153
    // Drain overflow stack first so other threads can steal.
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   154
    size_t region_index;
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   155
    while (region_stack()->pop_overflow(region_index)) {
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1
diff changeset
   156
      PSParallelCompact::fill_and_update_region(this, region_index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   159
    while (region_stack()->pop_local(region_index)) {
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1
diff changeset
   160
      PSParallelCompact::fill_and_update_region(this, region_index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    }
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1
diff changeset
   162
  } while (!region_stack()->is_empty());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
}