src/hotspot/share/gc/parallel/psCompactionManager.cpp
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58083 9046db64ca39
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
57773
5cbc3bd9fdfd 8224665: Parallel GC: Use WorkGang (7: remove task manager)
lkorinth
parents: 52118
diff changeset
     2
 * Copyright (c) 2005, 2019, 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
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 "classfile/systemDictionary.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30566
diff changeset
    27
#include "gc/parallel/objectStartArray.hpp"
46502
116a09d8f142 8180755: Remove use of bitMap.inline.hpp include from instanceKlass.hpp and c1_ValueSet.hpp
tschatzl
parents: 40655
diff changeset
    28
#include "gc/parallel/parMarkBitMap.inline.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30566
diff changeset
    29
#include "gc/parallel/parallelScavengeHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30566
diff changeset
    30
#include "gc/parallel/psCompactionManager.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30566
diff changeset
    31
#include "gc/parallel/psOldGen.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30566
diff changeset
    32
#include "gc/parallel/psParallelCompact.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30566
diff changeset
    33
#include "gc/shared/taskqueue.inline.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33611
diff changeset
    34
#include "logging/log.hpp"
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29792
diff changeset
    35
#include "memory/iterator.inline.hpp"
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49041
diff changeset
    36
#include "oops/access.inline.hpp"
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49041
diff changeset
    37
#include "oops/compressedOops.inline.hpp"
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29792
diff changeset
    38
#include "oops/instanceKlass.inline.hpp"
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29792
diff changeset
    39
#include "oops/instanceMirrorKlass.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    40
#include "oops/objArrayKlass.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    41
#include "oops/oop.inline.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 38170
diff changeset
    42
#include "runtime/atomic.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
PSOldGen*            ParCompactionManager::_old_gen = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
ParCompactionManager**  ParCompactionManager::_manager_array = NULL;
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
    46
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
OopTaskQueueSet*     ParCompactionManager::_stack_array = NULL;
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
    48
ParCompactionManager::ObjArrayTaskQueueSet*
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
    49
  ParCompactionManager::_objarray_queues = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
ObjectStartArray*    ParCompactionManager::_start_array = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
ParMarkBitMap*       ParCompactionManager::_mark_bitmap = NULL;
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
    52
RegionTaskQueueSet*  ParCompactionManager::_region_array = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
ParCompactionManager::ParCompactionManager() :
38170
ff88a25a7799 8150994: UseParallelGC fails with UseDynamicNumberOfGCThreads with specjbb2005
jmasa
parents: 35877
diff changeset
    55
    _action(CopyAndUpdate) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 30151
diff changeset
    57
  ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  _old_gen = heap->old_gen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  _start_array = old_gen()->start_array();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  marking_stack()->initialize();
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
    63
  _objarray_stack.initialize();
38170
ff88a25a7799 8150994: UseParallelGC fails with UseDynamicNumberOfGCThreads with specjbb2005
jmasa
parents: 35877
diff changeset
    64
  _region_stack.initialize();
35877
a2a62511d0f8 8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents: 35061
diff changeset
    65
a2a62511d0f8 8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents: 35061
diff changeset
    66
  reset_bitmap_query_cache();
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
    67
}
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
    68
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
void ParCompactionManager::initialize(ParMarkBitMap* mbm) {
57773
5cbc3bd9fdfd 8224665: Parallel GC: Use WorkGang (7: remove task manager)
lkorinth
parents: 52118
diff changeset
    70
  assert(ParallelScavengeHeap::heap() != NULL,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    "Needed for initialization");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  _mark_bitmap = mbm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
57773
5cbc3bd9fdfd 8224665: Parallel GC: Use WorkGang (7: remove task manager)
lkorinth
parents: 52118
diff changeset
    75
  uint parallel_gc_threads = ParallelScavengeHeap::heap()->workers().total_workers();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  assert(_manager_array == NULL, "Attempt to initialize twice");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11178
diff changeset
    78
  _manager_array = NEW_C_HEAP_ARRAY(ParCompactionManager*, parallel_gc_threads+1, mtGC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  _stack_array = new OopTaskQueueSet(parallel_gc_threads);
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
    81
  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
    82
  _objarray_queues = new ObjArrayTaskQueueSet(parallel_gc_threads);
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
    83
  guarantee(_objarray_queues != NULL, "Could not allocate objarray_queues");
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1
diff changeset
    84
  _region_array = new RegionTaskQueueSet(parallel_gc_threads);
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
    85
  guarantee(_region_array != NULL, "Could not allocate region_array");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // Create and register the ParCompactionManager(s) for the worker threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  for(uint i=0; i<parallel_gc_threads; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    _manager_array[i] = new ParCompactionManager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    guarantee(_manager_array[i] != NULL, "Could not create ParCompactionManager");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    stack_array()->register_queue(i, _manager_array[i]->marking_stack());
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
    92
    _objarray_queues->register_queue(i, &_manager_array[i]->_objarray_stack);
38170
ff88a25a7799 8150994: UseParallelGC fails with UseDynamicNumberOfGCThreads with specjbb2005
jmasa
parents: 35877
diff changeset
    93
    region_array()->register_queue(i, _manager_array[i]->region_stack());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // The VMThread gets its own ParCompactionManager, which is not available
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // for work stealing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  _manager_array[parallel_gc_threads] = new ParCompactionManager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  guarantee(_manager_array[parallel_gc_threads] != NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    "Could not create ParCompactionManager");
57773
5cbc3bd9fdfd 8224665: Parallel GC: Use WorkGang (7: remove task manager)
lkorinth
parents: 52118
diff changeset
   101
  assert(ParallelScavengeHeap::heap()->workers().total_workers() != 0,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    "Not initialized?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
35877
a2a62511d0f8 8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents: 35061
diff changeset
   105
void ParCompactionManager::reset_all_bitmap_query_caches() {
57773
5cbc3bd9fdfd 8224665: Parallel GC: Use WorkGang (7: remove task manager)
lkorinth
parents: 52118
diff changeset
   106
  uint parallel_gc_threads = ParallelScavengeHeap::heap()->workers().total_workers();
35877
a2a62511d0f8 8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents: 35061
diff changeset
   107
  for (uint i=0; i<=parallel_gc_threads; i++) {
a2a62511d0f8 8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents: 35061
diff changeset
   108
    _manager_array[i]->reset_bitmap_query_cache();
a2a62511d0f8 8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents: 35061
diff changeset
   109
  }
a2a62511d0f8 8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents: 35061
diff changeset
   110
}
a2a62511d0f8 8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents: 35061
diff changeset
   111
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
bool ParCompactionManager::should_update() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  assert(action() != NotValid, "Action is not set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  return (action() == ParCompactionManager::Update) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
         (action() == ParCompactionManager::CopyAndUpdate) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
         (action() == ParCompactionManager::UpdateAndCopy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
bool ParCompactionManager::should_copy() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  assert(action() != NotValid, "Action is not set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  return (action() == ParCompactionManager::Copy) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
         (action() == ParCompactionManager::CopyAndUpdate) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
         (action() == ParCompactionManager::UpdateAndCopy);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
ParCompactionManager*
31330
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30764
diff changeset
   127
ParCompactionManager::gc_thread_compaction_manager(uint index) {
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30764
diff changeset
   128
  assert(index < ParallelGCThreads, "index out of range");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  assert(_manager_array != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  return _manager_array[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   133
void ParCompactionManager::follow_marking_stacks() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  do {
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   135
    // 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
   136
    oop obj;
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   137
    while (marking_stack()->pop_overflow(obj)) {
29792
8c6fa07f0869 8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents: 25351
diff changeset
   138
      follow_contents(obj);
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   139
    }
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   140
    while (marking_stack()->pop_local(obj)) {
29792
8c6fa07f0869 8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents: 25351
diff changeset
   141
      follow_contents(obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
5080
eff0cc882603 6935839: excessive marking stack growth during full gcs
jcoomes
parents: 5076
diff changeset
   144
    // 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
   145
    ObjArrayTask task;
17370
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 13952
diff changeset
   146
    if (_objarray_stack.pop_overflow(task) || _objarray_stack.pop_local(task)) {
52118
49f627781c2a 8211446: Replace oop_pc_follow_contents with oop_iterate and closure
lkorinth
parents: 51698
diff changeset
   147
      follow_array((objArrayOop)task.obj(), task.index());
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   148
    }
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   149
  } while (!marking_stacks_empty());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3795
diff changeset
   151
  assert(marking_stacks_empty(), "Sanity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1
diff changeset
   154
void ParCompactionManager::drain_region_stacks() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  do {
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   156
    // Drain overflow stack first so other threads can steal.
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   157
    size_t region_index;
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   158
    while (region_stack()->pop_overflow(region_index)) {
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1
diff changeset
   159
      PSParallelCompact::fill_and_update_region(this, region_index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
5918
73b96456819a 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 5547
diff changeset
   162
    while (region_stack()->pop_local(region_index)) {
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1
diff changeset
   163
      PSParallelCompact::fill_and_update_region(this, region_index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    }
1407
9006b01ba3fd 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 1
diff changeset
   165
  } while (!region_stack()->is_empty());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
}