src/hotspot/share/gc/g1/g1RemSet.cpp
author tschatzl
Wed, 17 Jul 2019 16:33:19 +0200
changeset 55720 dec1d532c000
parent 55607 5919b273def6
child 55722 5ee183a90e65
permissions -rw-r--r--
8226232: Move merge heap roots code out from G1RemSetScanState Reviewed-by: sangheki, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     1
/*
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 52897
diff changeset
     2
 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     4
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     8
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    13
 * accompanied this code).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    14
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5033
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5033
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: 5033
diff changeset
    21
 * questions.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    22
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    23
 */
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7385
diff changeset
    25
#include "precompiled.hpp"
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 49634
diff changeset
    26
#include "gc/g1/g1BarrierSet.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30175
diff changeset
    27
#include "gc/g1/g1BlockOffsetTable.inline.hpp"
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
    28
#include "gc/g1/g1CardTable.inline.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30175
diff changeset
    29
#include "gc/g1/g1CollectedHeap.inline.hpp"
47789
a77a7d3bc4f6 8149127: Rename g1/concurrentMarkThread.* to g1/g1ConcurrentMarkThread.*
tschatzl
parents: 47647
diff changeset
    30
#include "gc/g1/g1ConcurrentRefine.hpp"
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 52897
diff changeset
    31
#include "gc/g1/g1DirtyCardQueue.hpp"
35210
eb1d5c68bf64 8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet
tschatzl
parents: 35198
diff changeset
    32
#include "gc/g1/g1FromCardCache.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30175
diff changeset
    33
#include "gc/g1/g1GCPhaseTimes.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30175
diff changeset
    34
#include "gc/g1/g1HotCardCache.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30175
diff changeset
    35
#include "gc/g1/g1OopClosures.inline.hpp"
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
    36
#include "gc/g1/g1RootClosures.hpp"
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47789
diff changeset
    37
#include "gc/g1/g1RemSet.hpp"
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
    38
#include "gc/g1/g1SharedDirtyCardQueue.hpp"
35198
1365be812a7d 8145674: Fix includes and forward declarations in g1Remset files
tschatzl
parents: 35068
diff changeset
    39
#include "gc/g1/heapRegion.inline.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30175
diff changeset
    40
#include "gc/g1/heapRegionManager.inline.hpp"
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    41
#include "gc/g1/heapRegionRemSet.inline.hpp"
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    42
#include "gc/g1/sparsePRT.hpp"
37414
2672ba9af0dc 8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents: 37248
diff changeset
    43
#include "gc/shared/gcTraceTime.inline.hpp"
47647
64dba69fc528 8189276: Make SuspendibleThreadSet and related code available to other GCs
rkennke
parents: 47216
diff changeset
    44
#include "gc/shared/suspendibleThreadSet.hpp"
51877
5f931e3e7a63 8196341: Add JFR events for parallel phases of G1
lkorinth
parents: 51494
diff changeset
    45
#include "jfr/jfrEvents.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7385
diff changeset
    46
#include "memory/iterator.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 37242
diff changeset
    47
#include "memory/resourceArea.hpp"
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
    48
#include "oops/access.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7385
diff changeset
    49
#include "oops/oop.inline.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49911
diff changeset
    50
#include "runtime/os.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    51
#include "utilities/align.hpp"
24098
48f07e2c74de 8039957: Replace the last few %p usages with PTR_FORMAT in the GC code
stefank
parents: 23858
diff changeset
    52
#include "utilities/globalDefinitions.hpp"
30175
543725014c9d 8076457: Fix includes of inline.hpp in GC code
stefank
parents: 29796
diff changeset
    53
#include "utilities/stack.inline.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49911
diff changeset
    54
#include "utilities/ticks.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    55
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    56
// Collects information about the overall heap root scan progress during an evacuation.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    57
//
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    58
// Scanning the remembered sets works by first merging all sources of cards to be
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    59
// scanned (log buffers, hcc, remembered sets) into a single data structure to remove
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    60
// duplicates and simplify work distribution.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    61
//
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    62
// During the following card scanning we not only scan this combined set of cards, but
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    63
// also remember that these were completely scanned. The following evacuation passes
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    64
// do not scan these cards again, and so need to be preserved across increments.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    65
//
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    66
// The representation for all the cards to scan is the card table: cards can have
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    67
// one of three states during GC:
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    68
// - clean: these cards will not be scanned in this pass
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    69
// - dirty: these cards will be scanned in this pass
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    70
// - scanned: these cards have already been scanned in a previous pass
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    71
//
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    72
// After all evacuation is done, we reset the card table to clean.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    73
//
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    74
// Work distribution occurs on "chunk" basis, i.e. contiguous ranges of cards. As an
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    75
// additional optimization, during card merging we remember which regions and which
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    76
// chunks actually contain cards to be scanned. Threads iterate only across these
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    77
// regions, and only compete for chunks containing any cards.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    78
//
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    79
// Within these chunks, a worker scans the card table on "blocks" of cards, i.e.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    80
// contiguous ranges of dirty cards to be scanned. These blocks are converted to actual
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    81
// memory ranges and then passed on to actual scanning.
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
    82
class G1RemSetScanState : public CHeapObj<mtGC> {
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    83
  class G1DirtyRegions;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    84
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    85
  size_t _max_regions;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    86
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    87
  // Has this region that is part of the regions in the collection set been processed yet.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    88
  typedef bool G1RemsetIterState;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    89
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    90
  G1RemsetIterState volatile* _collection_set_iter_state;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    91
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    92
  // Card table iteration claim for each heap region, from 0 (completely unscanned)
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    93
  // to (>=) HeapRegion::CardsPerRegion (completely scanned).
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    94
  uint volatile* _card_table_scan_state;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    95
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    96
  // Random power of two number of cards we want to claim per thread. This corresponds
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    97
  // to a 64k of memory work chunk area for every thread.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    98
  // We use the same claim size as Parallel GC. No particular measurements have been
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
    99
  // performed to determine an optimal number.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   100
  static const uint CardsPerChunk = 128;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   101
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   102
  uint _scan_chunks_per_region;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   103
  bool* _region_scan_chunks;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   104
  uint8_t _scan_chunks_shift;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   105
public:
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   106
  uint scan_chunk_size() const { return (uint)1 << _scan_chunks_shift; }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   107
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   108
  // Returns whether the chunk corresponding to the given region/card in region contain a
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   109
  // dirty card, i.e. actually needs scanning.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   110
  bool chunk_needs_scan(uint const region_idx, uint const card_in_region) const {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   111
    size_t const idx = (size_t)region_idx * _scan_chunks_per_region + (card_in_region >> _scan_chunks_shift);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   112
    assert(idx < (_max_regions * _scan_chunks_per_region), "Index " SIZE_FORMAT " out of bounds " SIZE_FORMAT,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   113
           idx, _max_regions * _scan_chunks_per_region);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   114
    return _region_scan_chunks[idx];
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   115
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   116
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   117
private:
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   118
  // The complete set of regions which card table needs to be cleared at the end of GC because
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   119
  // we scribbled all over them.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   120
  G1DirtyRegions* _all_dirty_regions;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   121
  // The set of regions which card table needs to be scanned for new dirty cards
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   122
  // in the current evacuation pass.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   123
  G1DirtyRegions* _next_dirty_regions;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   124
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   125
  // Set of (unique) regions that can be added to concurrently.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   126
  class G1DirtyRegions : public CHeapObj<mtGC> {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   127
    uint* _buffer;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   128
    uint _cur_idx;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   129
    size_t _max_regions;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   130
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   131
    bool* _contains;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   132
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   133
  public:
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   134
    G1DirtyRegions(size_t max_regions) :
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   135
      _buffer(NEW_C_HEAP_ARRAY(uint, max_regions, mtGC)),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   136
      _cur_idx(0),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   137
      _max_regions(max_regions),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   138
      _contains(NEW_C_HEAP_ARRAY(bool, max_regions, mtGC)) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   139
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   140
      reset();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   141
    }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   142
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   143
    static size_t chunk_size() { return M; }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   144
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   145
    ~G1DirtyRegions() {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   146
      FREE_C_HEAP_ARRAY(uint, _buffer);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   147
      FREE_C_HEAP_ARRAY(bool, _contains);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   148
    }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   149
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   150
    void reset() {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   151
      _cur_idx = 0;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   152
      ::memset(_contains, false, _max_regions * sizeof(bool));
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   153
    }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   154
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   155
    uint size() const { return _cur_idx; }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   156
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   157
    uint at(uint idx) const {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   158
      assert(idx < _cur_idx, "Index %u beyond valid regions", idx);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   159
      return _buffer[idx];
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   160
    }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   161
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   162
    void add_dirty_region(uint region) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   163
      if (_contains[region]) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   164
        return;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   165
      }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   166
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   167
      bool marked_as_dirty = Atomic::cmpxchg(true, &_contains[region], false) == false;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   168
      if (marked_as_dirty) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   169
        uint allocated = Atomic::add(1u, &_cur_idx) - 1;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   170
        _buffer[allocated] = region;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   171
      }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   172
    }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   173
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   174
    // Creates the union of this and the other G1DirtyRegions.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   175
    void merge(const G1DirtyRegions* other) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   176
      for (uint i = 0; i < other->size(); i++) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   177
        uint region = other->at(i);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   178
        if (!_contains[region]) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   179
          _buffer[_cur_idx++] = region;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   180
          _contains[region] = true;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   181
        }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   182
      }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   183
    }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   184
  };
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   185
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   186
  // Creates a snapshot of the current _top values at the start of collection to
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   187
  // filter out card marks that we do not want to scan.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   188
  class G1ResetScanTopClosure : public HeapRegionClosure {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   189
    G1RemSetScanState* _scan_state;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   190
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   191
  public:
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   192
    G1ResetScanTopClosure(G1RemSetScanState* scan_state) : _scan_state(scan_state) { }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   193
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   194
    virtual bool do_heap_region(HeapRegion* r) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   195
      uint hrm_index = r->hrm_index();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   196
      if (r->in_collection_set()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   197
        // Young regions had their card table marked as young at their allocation;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   198
        // we need to make sure that these marks are cleared at the end of GC, *but*
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   199
        // they should not be scanned for cards.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   200
        // So directly add them to the "all_dirty_regions".
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   201
        // Same for regions in the (initial) collection set: they may contain cards from
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   202
        // the log buffers, make sure they are cleaned.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   203
        _scan_state->add_all_dirty_region(hrm_index);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   204
       } else if (r->is_old_or_humongous_or_archive()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   205
        _scan_state->set_scan_top(hrm_index, r->top());
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   206
       }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   207
       return false;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   208
     }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   209
  };
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   210
  // For each region, contains the maximum top() value to be used during this garbage
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   211
  // collection. Subsumes common checks like filtering out everything but old and
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   212
  // humongous regions outside the collection set.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   213
  // This is valid because we are not interested in scanning stray remembered set
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   214
  // entries from free or archive regions.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   215
  HeapWord** _scan_top;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   216
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   217
  class G1ClearCardTableTask : public AbstractGangTask {
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   218
    G1CollectedHeap* _g1h;
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   219
    G1DirtyRegions* _regions;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   220
    uint _chunk_length;
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   221
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   222
    uint volatile _cur_dirty_regions;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   223
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   224
    G1RemSetScanState* _scan_state;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   225
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   226
  public:
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   227
    G1ClearCardTableTask(G1CollectedHeap* g1h,
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   228
                         G1DirtyRegions* regions,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   229
                         uint chunk_length,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   230
                         G1RemSetScanState* scan_state) :
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   231
      AbstractGangTask("G1 Clear Card Table Task"),
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   232
      _g1h(g1h),
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   233
      _regions(regions),
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   234
      _chunk_length(chunk_length),
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   235
      _cur_dirty_regions(0),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   236
      _scan_state(scan_state) {
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   237
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   238
      assert(chunk_length > 0, "must be");
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   239
    }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   240
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   241
    static uint chunk_size() { return M; }
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   242
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   243
    void work(uint worker_id) {
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   244
      while (_cur_dirty_regions < _regions->size()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   245
        uint next = Atomic::add(_chunk_length, &_cur_dirty_regions) - _chunk_length;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   246
        uint max = MIN2(next + _chunk_length, _regions->size());
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   247
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   248
        for (uint i = next; i < max; i++) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   249
          HeapRegion* r = _g1h->region_at(_regions->at(i));
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   250
          if (!r->is_survivor()) {
49632
64f9ebc85e67 8197573: Remove concurrent cleanup and secondary free list handling
tschatzl
parents: 49607
diff changeset
   251
            r->clear_cardtable();
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   252
          }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   253
        }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   254
      }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   255
    }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   256
  };
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   257
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   258
  // Clear the card table of "dirty" regions.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   259
  void clear_card_table(WorkGang* workers) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   260
    uint num_regions = _all_dirty_regions->size();
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   261
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   262
    if (num_regions == 0) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   263
      return;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   264
    }
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   265
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   266
    uint const num_chunks = (uint)(align_up((size_t)num_regions << HeapRegion::LogCardsPerRegion, G1ClearCardTableTask::chunk_size()) / G1ClearCardTableTask::chunk_size());
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   267
    uint const num_workers = MIN2(num_chunks, workers->active_workers());
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   268
    uint const chunk_length = G1ClearCardTableTask::chunk_size() / (uint)HeapRegion::CardsPerRegion;
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   269
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   270
    // Iterate over the dirty cards region list.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   271
    G1ClearCardTableTask cl(G1CollectedHeap::heap(), _all_dirty_regions, chunk_length, this);
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   272
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   273
    log_debug(gc, ergo)("Running %s using %u workers for %u "
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   274
                        "units of work for %u regions.",
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   275
                        cl.name(), num_workers, num_chunks, num_regions);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   276
    workers->run_task(&cl, num_workers);
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   277
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   278
#ifndef PRODUCT
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   279
    G1CollectedHeap::heap()->verifier()->verify_card_table_cleanup();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   280
#endif
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   281
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   282
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   283
public:
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   284
  G1RemSetScanState() :
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   285
    _max_regions(0),
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   286
    _collection_set_iter_state(NULL),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   287
    _card_table_scan_state(NULL),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   288
    _scan_chunks_per_region((uint)(HeapRegion::CardsPerRegion / CardsPerChunk)),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   289
    _region_scan_chunks(NULL),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   290
    _scan_chunks_shift(0),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   291
    _all_dirty_regions(NULL),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   292
    _next_dirty_regions(NULL),
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   293
    _scan_top(NULL) {
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   294
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   295
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   296
  ~G1RemSetScanState() {
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   297
    FREE_C_HEAP_ARRAY(G1RemsetIterState, _collection_set_iter_state);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   298
    FREE_C_HEAP_ARRAY(uint, _card_table_scan_state);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   299
    FREE_C_HEAP_ARRAY(bool, _region_scan_chunks);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   300
    FREE_C_HEAP_ARRAY(HeapWord*, _scan_top);
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   301
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   302
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   303
  void initialize(size_t max_regions) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   304
    assert(_collection_set_iter_state == NULL, "Must not be initialized twice");
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   305
    _max_regions = max_regions;
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   306
    _collection_set_iter_state = NEW_C_HEAP_ARRAY(G1RemsetIterState, max_regions, mtGC);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   307
    _card_table_scan_state = NEW_C_HEAP_ARRAY(uint, max_regions, mtGC);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   308
    _region_scan_chunks = NEW_C_HEAP_ARRAY(bool, max_regions * _scan_chunks_per_region, mtGC);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   309
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   310
    _scan_chunks_shift = (uint8_t)log2_intptr(HeapRegion::CardsPerRegion / _scan_chunks_per_region);
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   311
    _scan_top = NEW_C_HEAP_ARRAY(HeapWord*, max_regions, mtGC);
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   312
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   313
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   314
  void prepare() {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   315
    for (size_t i = 0; i < _max_regions; i++) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   316
      _collection_set_iter_state[i] = false;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   317
      clear_scan_top((uint)i);
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   318
    }
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   319
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   320
    _all_dirty_regions = new G1DirtyRegions(_max_regions);
55720
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   321
    _next_dirty_regions = new G1DirtyRegions(_max_regions);
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   322
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   323
    G1ResetScanTopClosure cl(this);
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   324
    G1CollectedHeap::heap()->heap_region_iterate(&cl);
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   325
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   326
55720
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   327
  void prepare_for_merge_heap_roots() {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   328
    _all_dirty_regions->merge(_next_dirty_regions);
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   329
55720
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   330
    _next_dirty_regions->reset();
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   331
    for (size_t i = 0; i < _max_regions; i++) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   332
      _card_table_scan_state[i] = 0;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   333
    }
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   334
55720
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   335
    ::memset(_region_scan_chunks, false, _max_regions * _scan_chunks_per_region * sizeof(*_region_scan_chunks));
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   336
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   337
55720
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   338
  // Returns whether the given region contains cards we need to scan. The remembered
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   339
  // set and other sources may contain cards that
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   340
  // - are in uncommitted regions
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   341
  // - are located in the collection set
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   342
  // - are located in free regions
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   343
  // as we do not clean up remembered sets before merging heap roots.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   344
  bool contains_cards_to_process(uint const region_idx) const {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   345
    HeapRegion* hr = G1CollectedHeap::heap()->region_at_or_null(region_idx);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   346
    return (hr != NULL && !hr->in_collection_set() && hr->is_old_or_humongous_or_archive());
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   347
  }
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   348
55720
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   349
  size_t num_visited_cards() const {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   350
    size_t result = 0;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   351
    for (uint i = 0; i < _max_regions * _scan_chunks_per_region; i++) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   352
      if (_region_scan_chunks[i]) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   353
        result++;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   354
      }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   355
    }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   356
    return result * CardsPerChunk;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   357
  }
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   358
55720
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   359
  size_t num_cards_in_dirty_regions() const {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   360
    return _next_dirty_regions->size() * HeapRegion::CardsPerRegion;
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   361
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   362
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   363
  void set_chunk_region_dirty(size_t const region_card_idx) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   364
    size_t chunk_idx = region_card_idx >> _scan_chunks_shift;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   365
    for (uint i = 0; i < _scan_chunks_per_region; i++) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   366
      _region_scan_chunks[chunk_idx++] = true;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   367
    }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   368
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   369
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   370
  void set_chunk_dirty(size_t const card_idx) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   371
    assert((card_idx >> _scan_chunks_shift) < (_max_regions * _scan_chunks_per_region),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   372
           "Trying to access index " SIZE_FORMAT " out of bounds " SIZE_FORMAT,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   373
           card_idx >> _scan_chunks_shift, _max_regions * _scan_chunks_per_region);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   374
    size_t const chunk_idx = card_idx >> _scan_chunks_shift;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   375
    if (!_region_scan_chunks[chunk_idx]) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   376
      _region_scan_chunks[chunk_idx] = true;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   377
    }
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   378
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   379
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   380
  void cleanup(WorkGang* workers) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   381
    _all_dirty_regions->merge(_next_dirty_regions);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   382
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   383
    clear_card_table(workers);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   384
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   385
    delete _all_dirty_regions;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   386
    _all_dirty_regions = NULL;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   387
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   388
    delete _next_dirty_regions;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   389
    _next_dirty_regions = NULL;
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   390
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   391
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   392
  void iterate_dirty_regions_from(HeapRegionClosure* cl, uint worker_id) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   393
    uint num_regions = _next_dirty_regions->size();
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   394
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   395
    if (num_regions == 0) {
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   396
      return;
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   397
    }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   398
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   399
    G1CollectedHeap* g1h = G1CollectedHeap::heap();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   400
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   401
    WorkGang* workers = g1h->workers();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   402
    uint const max_workers = workers->active_workers();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   403
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   404
    uint const start_pos = num_regions * worker_id / max_workers;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   405
    uint cur = start_pos;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   406
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   407
    do {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   408
      bool result = cl->do_heap_region(g1h->region_at(_next_dirty_regions->at(cur)));
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   409
      guarantee(!result, "Not allowed to ask for early termination.");
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   410
      cur++;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   411
      if (cur == _next_dirty_regions->size()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   412
        cur = 0;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   413
      }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   414
    } while (cur != start_pos);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   415
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   416
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   417
  // Attempt to claim the given region in the collection set for iteration. Returns true
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   418
  // if this call caused the transition from Unclaimed to Claimed.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   419
  inline bool claim_collection_set_region(uint region) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   420
    assert(region < _max_regions, "Tried to access invalid region %u", region);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   421
    if (_collection_set_iter_state[region]) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   422
      return false;
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   423
    }
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   424
    return !Atomic::cmpxchg(true, &_collection_set_iter_state[region], false);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   425
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   426
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   427
  bool has_cards_to_scan(uint region) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   428
    assert(region < _max_regions, "Tried to access invalid region %u", region);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   429
    return _card_table_scan_state[region] < HeapRegion::CardsPerRegion;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   430
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   431
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   432
  uint claim_cards_to_scan(uint region, uint increment) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   433
    assert(region < _max_regions, "Tried to access invalid region %u", region);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   434
    return Atomic::add(increment, &_card_table_scan_state[region]) - increment;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   435
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   436
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   437
  void add_dirty_region(uint const region) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   438
#ifdef ASSERT
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   439
   HeapRegion* hr = G1CollectedHeap::heap()->region_at(region);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   440
   assert(!hr->in_collection_set() && hr->is_old_or_humongous_or_archive(),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   441
          "Region %u is not suitable for scanning, is %sin collection set or %s",
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   442
          hr->hrm_index(), hr->in_collection_set() ? "" : "not ", hr->get_short_type_str());
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   443
#endif
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   444
    _next_dirty_regions->add_dirty_region(region);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   445
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   446
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   447
  void add_all_dirty_region(uint region) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   448
#ifdef ASSERT
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   449
    HeapRegion* hr = G1CollectedHeap::heap()->region_at(region);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   450
    assert(hr->in_collection_set(),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   451
           "Only add young regions to all dirty regions directly but %u is %s",
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   452
           hr->hrm_index(), hr->get_short_type_str());
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   453
#endif
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   454
    _all_dirty_regions->add_dirty_region(region);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   455
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   456
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   457
  void set_scan_top(uint region_idx, HeapWord* value) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   458
    _scan_top[region_idx] = value;
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   459
  }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   460
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   461
  HeapWord* scan_top(uint region_idx) const {
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   462
    return _scan_top[region_idx];
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   463
  }
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   464
54934
39814e0a8964 8222492: G1 unnecessarily scans remembered set cards for regions that already have been evacuated
tschatzl
parents: 54844
diff changeset
   465
  void clear_scan_top(uint region_idx) {
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   466
    set_scan_top(region_idx, NULL);
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   467
  }
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   468
};
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   469
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
   470
G1RemSet::G1RemSet(G1CollectedHeap* g1h,
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   471
                   G1CardTable* ct,
38172
90f405aac699 8155524: HotCardCache shouldn't be part of ConcurrentG1Refine
kbarrett
parents: 38160
diff changeset
   472
                   G1HotCardCache* hot_card_cache) :
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 50113
diff changeset
   473
  _scan_state(new G1RemSetScanState()),
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 50113
diff changeset
   474
  _prev_period_summary(),
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
   475
  _g1h(g1h),
46614
ae1105fff9e4 8179677: Let G1Remset::_conc_refined_cards only count number of cards concurrently refined
tschatzl
parents: 46611
diff changeset
   476
  _num_conc_refined_cards(0),
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   477
  _ct(ct),
53985
0da5c17f5e43 8219747: Remove g1_ prefix to g1_remset and g1_policy members in G1CollectedHeap
tschatzl
parents: 53956
diff changeset
   478
  _g1p(_g1h->policy()),
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 50113
diff changeset
   479
  _hot_card_cache(hot_card_cache) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   480
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   481
6958
cfa71cf3564d 6971296: G1: simplify G1RemSet class hierarchy
johnc
parents: 6759
diff changeset
   482
G1RemSet::~G1RemSet() {
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   483
  delete _scan_state;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   484
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   485
35210
eb1d5c68bf64 8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet
tschatzl
parents: 35198
diff changeset
   486
uint G1RemSet::num_par_rem_sets() {
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 52897
diff changeset
   487
  return G1DirtyCardQueueSet::num_par_ids() + G1ConcurrentRefine::max_num_threads() + MAX2(ConcGCThreads, ParallelGCThreads);
35210
eb1d5c68bf64 8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet
tschatzl
parents: 35198
diff changeset
   488
}
eb1d5c68bf64 8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet
tschatzl
parents: 35198
diff changeset
   489
37414
2672ba9af0dc 8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents: 37248
diff changeset
   490
void G1RemSet::initialize(size_t capacity, uint max_regions) {
35210
eb1d5c68bf64 8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet
tschatzl
parents: 35198
diff changeset
   491
  G1FromCardCache::initialize(num_par_rem_sets(), max_regions);
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   492
  _scan_state->initialize(max_regions);
35210
eb1d5c68bf64 8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet
tschatzl
parents: 35198
diff changeset
   493
}
eb1d5c68bf64 8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet
tschatzl
parents: 35198
diff changeset
   494
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   495
// Helper class to scan and detect ranges of cards that need to be scanned on the
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   496
// card table.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   497
class G1CardTableScanner : public StackObj {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   498
public:
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   499
  typedef CardTable::CardValue CardValue;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   500
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   501
private:
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   502
  CardValue* const _base_addr;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   503
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   504
  CardValue* _cur_addr;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   505
  CardValue* const _end_addr;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   506
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   507
  static const size_t ToScanMask = G1CardTable::g1_card_already_scanned;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   508
  static const size_t ExpandedToScanMask = G1CardTable::WordAlreadyScanned;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   509
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   510
  bool cur_addr_aligned() const {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   511
    return ((uintptr_t)_cur_addr) % sizeof(size_t) == 0;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   512
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   513
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   514
  bool cur_card_is_dirty() const {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   515
    CardValue value = *_cur_addr;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   516
    return (value & ToScanMask) == 0;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   517
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   518
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   519
  bool cur_word_of_cards_contains_any_dirty_card() const {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   520
    assert(cur_addr_aligned(), "Current address should be aligned");
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   521
    size_t const value = *(size_t*)_cur_addr;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   522
    return (~value & ExpandedToScanMask) != 0;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   523
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   524
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   525
  bool cur_word_of_cards_all_dirty_cards() const {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   526
    size_t const value = *(size_t*)_cur_addr;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   527
    return value == G1CardTable::WordAllDirty;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   528
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   529
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   530
  size_t get_and_advance_pos() {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   531
    _cur_addr++;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   532
    return pointer_delta(_cur_addr, _base_addr, sizeof(CardValue)) - 1;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   533
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   534
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   535
public:
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   536
  G1CardTableScanner(CardValue* start_card, size_t size) :
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   537
    _base_addr(start_card),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   538
    _cur_addr(start_card),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   539
    _end_addr(start_card + size) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   540
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   541
    assert(is_aligned(start_card, sizeof(size_t)), "Unaligned start addr " PTR_FORMAT, p2i(start_card));
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   542
    assert(is_aligned(size, sizeof(size_t)), "Unaligned size " SIZE_FORMAT, size);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   543
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   544
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   545
  size_t find_next_dirty() {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   546
    while (!cur_addr_aligned()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   547
      if (cur_card_is_dirty()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   548
        return get_and_advance_pos();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   549
      }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   550
      _cur_addr++;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   551
    }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   552
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   553
    assert(cur_addr_aligned(), "Current address should be aligned now.");
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   554
    while (_cur_addr != _end_addr) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   555
      if (cur_word_of_cards_contains_any_dirty_card()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   556
        for (size_t i = 0; i < sizeof(size_t); i++) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   557
          if (cur_card_is_dirty()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   558
            return get_and_advance_pos();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   559
          }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   560
          _cur_addr++;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   561
        }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   562
        assert(false, "Should not reach here given we detected a dirty card in the word.");
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   563
      }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   564
      _cur_addr += sizeof(size_t);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   565
    }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   566
    return get_and_advance_pos();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   567
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   568
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   569
  size_t find_next_non_dirty() {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   570
    assert(_cur_addr <= _end_addr, "Not allowed to search for marks after area.");
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   571
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   572
    while (!cur_addr_aligned()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   573
      if (!cur_card_is_dirty()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   574
        return get_and_advance_pos();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   575
      }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   576
      _cur_addr++;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   577
    }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   578
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   579
    assert(cur_addr_aligned(), "Current address should be aligned now.");
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   580
    while (_cur_addr != _end_addr) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   581
      if (!cur_word_of_cards_all_dirty_cards()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   582
        for (size_t i = 0; i < sizeof(size_t); i++) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   583
          if (!cur_card_is_dirty()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   584
            return get_and_advance_pos();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   585
          }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   586
          _cur_addr++;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   587
        }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   588
        assert(false, "Should not reach here given we detected a non-dirty card in the word.");
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   589
      }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   590
      _cur_addr += sizeof(size_t);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   591
    }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   592
    return get_and_advance_pos();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   593
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   594
};
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   595
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   596
// Helper class to claim dirty chunks within the card table.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   597
class G1CardTableChunkClaimer {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   598
  G1RemSetScanState* _scan_state;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   599
  uint _region_idx;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   600
  uint _cur_claim;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   601
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   602
public:
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   603
  G1CardTableChunkClaimer(G1RemSetScanState* scan_state, uint region_idx) :
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   604
    _scan_state(scan_state),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   605
    _region_idx(region_idx),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   606
    _cur_claim(0) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   607
    guarantee(size() <= HeapRegion::CardsPerRegion, "Should not claim more space than possible.");
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   608
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   609
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   610
  bool has_next() {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   611
    while (true) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   612
      _cur_claim = _scan_state->claim_cards_to_scan(_region_idx, size());
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   613
      if (_cur_claim >= HeapRegion::CardsPerRegion) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   614
        return false;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   615
      }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   616
      if (_scan_state->chunk_needs_scan(_region_idx, _cur_claim)) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   617
        return true;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   618
      }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   619
    }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   620
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   621
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   622
  uint value() const { return _cur_claim; }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   623
  uint size() const { return _scan_state->scan_chunk_size(); }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   624
};
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   625
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   626
// Scans a heap region for dirty cards.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   627
class G1ScanHRForRegionClosure : public HeapRegionClosure {
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   628
  G1CollectedHeap* _g1h;
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   629
  G1CardTable* _ct;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   630
  G1BlockOffsetTable* _bot;
34246
d2c05216f375 8142390: Move ScanRSClosure to header file
ehelin
parents: 34135
diff changeset
   631
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   632
  G1ParScanThreadState* _pss;
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   633
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   634
  G1RemSetScanState* _scan_state;
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   635
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   636
  G1GCPhaseTimes::GCParPhases _phase;
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   637
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   638
  uint   _worker_id;
34246
d2c05216f375 8142390: Move ScanRSClosure to header file
ehelin
parents: 34135
diff changeset
   639
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   640
  size_t _cards_scanned;
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   641
  size_t _blocks_scanned;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   642
  size_t _chunks_claimed;
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   643
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   644
  Tickspan _rem_set_root_scan_time;
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   645
  Tickspan _rem_set_trim_partially_time;
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   646
55607
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   647
  // The address to which this thread already scanned (walked the heap) up to during
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   648
  // card scanning (exclusive).
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   649
  HeapWord* _scanned_to;
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   650
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   651
  HeapWord* scan_memregion(uint region_idx_for_card, MemRegion mr) {
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   652
    HeapRegion* const card_region = _g1h->region_at(region_idx_for_card);
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   653
    G1ScanCardClosure card_cl(_g1h, _pss);
55607
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   654
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   655
    HeapWord* const scanned_to = card_region->oops_on_memregion_seq_iterate_careful<true>(mr, &card_cl);
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   656
    assert(scanned_to != NULL, "Should be able to scan range");
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   657
    assert(scanned_to >= mr.end(), "Scanned to " PTR_FORMAT " less than range " PTR_FORMAT, p2i(scanned_to), p2i(mr.end()));
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   658
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   659
    _pss->trim_queue_partially();
55607
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   660
    return scanned_to;
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   661
  }
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   662
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   663
  void do_claimed_block(uint const region_idx_for_card, size_t const first_card, size_t const num_cards) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   664
    HeapWord* const card_start = _bot->address_for_index_raw(first_card);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   665
#ifdef ASSERT
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   666
    HeapRegion* hr = _g1h->region_at_or_null(region_idx_for_card);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   667
    assert(hr == NULL || hr->is_in_reserved(card_start),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   668
             "Card start " PTR_FORMAT " to scan outside of region %u", p2i(card_start), _g1h->region_at(region_idx_for_card)->hrm_index());
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   669
#endif
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   670
    HeapWord* const top = _scan_state->scan_top(region_idx_for_card);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   671
    if (card_start >= top) {
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   672
      return;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   673
    }
46635
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   674
55607
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   675
    HeapWord* scan_end = MIN2(card_start + (num_cards << BOTConstants::LogN_words), top);
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   676
    if (_scanned_to >= scan_end) {
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   677
      return;
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   678
    }
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   679
    MemRegion mr(MAX2(card_start, _scanned_to), scan_end);
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   680
    _scanned_to = scan_memregion(region_idx_for_card, mr);
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   681
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   682
    _cards_scanned += num_cards;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   683
  }
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   684
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   685
  ALWAYSINLINE void do_card_block(uint const region_idx, size_t const first_card, size_t const num_cards) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   686
    _ct->mark_as_scanned(first_card, num_cards);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   687
    do_claimed_block(region_idx, first_card, num_cards);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   688
    _blocks_scanned++;
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   689
  }
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   690
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   691
   void scan_heap_roots(HeapRegion* r) {
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   692
    EventGCPhaseParallel event;
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   693
    uint const region_idx = r->hrm_index();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   694
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   695
    ResourceMark rm;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   696
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   697
    G1CardTableChunkClaimer claim(_scan_state, region_idx);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   698
55607
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   699
    // Set the current scan "finger" to NULL for every heap region to scan. Since
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   700
    // the claim value is monotonically increasing, the check to not scan below this
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   701
    // will filter out objects spanning chunks within the region too then, as opposed
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   702
    // to resetting this value for every claim.
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   703
    _scanned_to = NULL;
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   704
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   705
    while (claim.has_next()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   706
      size_t const region_card_base_idx = ((size_t)region_idx << HeapRegion::LogCardsPerRegion) + claim.value();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   707
      CardTable::CardValue* const base_addr = _ct->byte_for_index(region_card_base_idx);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   708
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   709
      G1CardTableScanner scan(base_addr, claim.size());
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   710
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   711
      size_t first_scan_idx = scan.find_next_dirty();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   712
      while (first_scan_idx != claim.size()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   713
        assert(*_ct->byte_for_index(region_card_base_idx + first_scan_idx) <= 0x1, "is %d at region %u idx " SIZE_FORMAT, *_ct->byte_for_index(region_card_base_idx + first_scan_idx), region_idx, first_scan_idx);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   714
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   715
        size_t const last_scan_idx = scan.find_next_non_dirty();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   716
        size_t const len = last_scan_idx - first_scan_idx;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   717
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   718
        do_card_block(region_idx, region_card_base_idx + first_scan_idx, len);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   719
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   720
        if (last_scan_idx == claim.size()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   721
          break;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   722
        }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   723
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   724
        first_scan_idx = scan.find_next_dirty();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   725
      }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   726
      _chunks_claimed++;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   727
    }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   728
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   729
    event.commit(GCId::current(), _worker_id, G1GCPhaseTimes::phase_name(G1GCPhaseTimes::ScanHR));
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   730
  }
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   731
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   732
public:
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   733
  G1ScanHRForRegionClosure(G1RemSetScanState* scan_state,
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   734
                           G1ParScanThreadState* pss,
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   735
                           uint worker_id,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   736
                           G1GCPhaseTimes::GCParPhases phase) :
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   737
    _g1h(G1CollectedHeap::heap()),
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   738
    _ct(_g1h->card_table()),
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   739
    _bot(_g1h->bot()),
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   740
    _pss(pss),
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   741
    _scan_state(scan_state),
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   742
    _phase(phase),
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   743
    _worker_id(worker_id),
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   744
    _cards_scanned(0),
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   745
    _blocks_scanned(0),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   746
    _chunks_claimed(0),
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   747
    _rem_set_root_scan_time(),
55607
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   748
    _rem_set_trim_partially_time(),
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
   749
    _scanned_to(NULL) {
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   750
  }
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   751
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   752
  bool do_heap_region(HeapRegion* r) {
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   753
    assert(!r->in_collection_set() && r->is_old_or_humongous_or_archive(),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   754
           "Should only be called on old gen non-collection set regions but region %u is not.",
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   755
           r->hrm_index());
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   756
    uint const region_idx = r->hrm_index();
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   757
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   758
    if (_scan_state->has_cards_to_scan(region_idx)) {
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   759
      G1EvacPhaseWithTrimTimeTracker timer(_pss, _rem_set_root_scan_time, _rem_set_trim_partially_time);
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   760
      scan_heap_roots(r);
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   761
    }
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   762
    return false;
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   763
  }
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   764
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   765
  Tickspan rem_set_root_scan_time() const { return _rem_set_root_scan_time; }
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   766
  Tickspan rem_set_trim_partially_time() const { return _rem_set_trim_partially_time; }
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   767
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   768
  size_t cards_scanned() const { return _cards_scanned; }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   769
  size_t blocks_scanned() const { return _blocks_scanned; }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   770
  size_t chunks_claimed() const { return _chunks_claimed; }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   771
};
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   772
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   773
void G1RemSet::scan_heap_roots(G1ParScanThreadState* pss,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   774
                            uint worker_id,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   775
                            G1GCPhaseTimes::GCParPhases scan_phase,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   776
                            G1GCPhaseTimes::GCParPhases objcopy_phase) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   777
  G1ScanHRForRegionClosure cl(_scan_state, pss, worker_id, scan_phase);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   778
  _scan_state->iterate_dirty_regions_from(&cl, worker_id);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   779
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   780
  G1GCPhaseTimes* p = _g1p->phase_times();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   781
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   782
  p->record_or_add_time_secs(objcopy_phase, worker_id, cl.rem_set_trim_partially_time().seconds());
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   783
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   784
  p->record_or_add_time_secs(scan_phase, worker_id, cl.rem_set_root_scan_time().seconds());
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   785
  p->record_or_add_thread_work_item(scan_phase, worker_id, cl.cards_scanned(), G1GCPhaseTimes::ScanHRScannedCards);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   786
  p->record_or_add_thread_work_item(scan_phase, worker_id, cl.blocks_scanned(), G1GCPhaseTimes::ScanHRScannedBlocks);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   787
  p->record_or_add_thread_work_item(scan_phase, worker_id, cl.chunks_claimed(), G1GCPhaseTimes::ScanHRClaimedChunks);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   788
}
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   789
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   790
// Heap region closure to be applied to all regions in the current collection set
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   791
// increment to fix up non-card related roots.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   792
class G1ScanCollectionSetRegionClosure : public HeapRegionClosure {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   793
  G1ParScanThreadState* _pss;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   794
  G1RemSetScanState* _scan_state;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   795
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   796
  G1GCPhaseTimes::GCParPhases _scan_phase;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   797
  G1GCPhaseTimes::GCParPhases _code_roots_phase;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   798
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   799
  uint _worker_id;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   800
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   801
  size_t _opt_refs_scanned;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   802
  size_t _opt_refs_memory_used;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   803
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   804
  Tickspan _strong_code_root_scan_time;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   805
  Tickspan _strong_code_trim_partially_time;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   806
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   807
  Tickspan _rem_set_opt_root_scan_time;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   808
  Tickspan _rem_set_opt_trim_partially_time;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   809
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   810
  void scan_opt_rem_set_roots(HeapRegion* r) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   811
    EventGCPhaseParallel event;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   812
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   813
    G1OopStarChunkedList* opt_rem_set_list = _pss->oops_into_optional_region(r);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   814
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   815
    G1ScanCardClosure scan_cl(G1CollectedHeap::heap(), _pss);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   816
    G1ScanRSForOptionalClosure cl(G1CollectedHeap::heap(), &scan_cl);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   817
    _opt_refs_scanned += opt_rem_set_list->oops_do(&cl, _pss->closures()->raw_strong_oops());
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   818
    _opt_refs_memory_used += opt_rem_set_list->used_memory();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   819
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   820
    event.commit(GCId::current(), _worker_id, G1GCPhaseTimes::phase_name(_scan_phase));
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   821
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   822
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   823
public:
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   824
  G1ScanCollectionSetRegionClosure(G1RemSetScanState* scan_state,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   825
                                   G1ParScanThreadState* pss,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   826
                                   uint worker_i,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   827
                                   G1GCPhaseTimes::GCParPhases scan_phase,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   828
                                   G1GCPhaseTimes::GCParPhases code_roots_phase) :
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   829
    _pss(pss),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   830
    _scan_state(scan_state),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   831
    _scan_phase(scan_phase),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   832
    _code_roots_phase(code_roots_phase),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   833
    _worker_id(worker_i),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   834
    _opt_refs_scanned(0),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   835
    _opt_refs_memory_used(0),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   836
    _strong_code_root_scan_time(),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   837
    _strong_code_trim_partially_time(),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   838
    _rem_set_opt_root_scan_time(),
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   839
    _rem_set_opt_trim_partially_time() { }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   840
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   841
  bool do_heap_region(HeapRegion* r) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   842
    uint const region_idx = r->hrm_index();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   843
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   844
    // The individual references for the optional remembered set are per-worker, so we
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   845
    // always need to scan them.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   846
    if (r->has_index_in_opt_cset()) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   847
      G1EvacPhaseWithTrimTimeTracker timer(_pss, _rem_set_opt_root_scan_time, _rem_set_opt_trim_partially_time);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   848
      scan_opt_rem_set_roots(r);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   849
    }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   850
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   851
    if (_scan_state->claim_collection_set_region(region_idx)) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   852
      EventGCPhaseParallel event;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   853
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   854
      G1EvacPhaseWithTrimTimeTracker timer(_pss, _strong_code_root_scan_time, _strong_code_trim_partially_time);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   855
      // Scan the strong code root list attached to the current region
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   856
      r->strong_code_roots_do(_pss->closures()->weak_codeblobs());
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   857
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   858
      event.commit(GCId::current(), _worker_id, G1GCPhaseTimes::phase_name(_code_roots_phase));
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   859
    }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   860
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   861
    return false;
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   862
  }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   863
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   864
  Tickspan strong_code_root_scan_time() const { return _strong_code_root_scan_time;  }
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   865
  Tickspan strong_code_root_trim_partially_time() const { return _strong_code_trim_partially_time; }
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   866
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   867
  Tickspan rem_set_opt_root_scan_time() const { return _rem_set_opt_root_scan_time; }
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   868
  Tickspan rem_set_opt_trim_partially_time() const { return _rem_set_opt_trim_partially_time; }
54977
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   869
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   870
  size_t opt_refs_scanned() const { return _opt_refs_scanned; }
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   871
  size_t opt_refs_memory_used() const { return _opt_refs_memory_used; }
ab96027e99ed 8224160: Move G1RemSetScanClosure into g1RemSet.cpp file
tschatzl
parents: 54934
diff changeset
   872
};
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   873
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   874
void G1RemSet::scan_collection_set_regions(G1ParScanThreadState* pss,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   875
                                           uint worker_id,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   876
                                           G1GCPhaseTimes::GCParPhases scan_phase,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   877
                                           G1GCPhaseTimes::GCParPhases coderoots_phase,
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   878
                                           G1GCPhaseTimes::GCParPhases objcopy_phase) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   879
  G1ScanCollectionSetRegionClosure cl(_scan_state, pss, worker_id, scan_phase, coderoots_phase);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   880
  _g1h->collection_set_iterate_increment_from(&cl, worker_id);
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   881
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   882
  G1GCPhaseTimes* p = _g1h->phase_times();
33204
b8a3901ac5b3 8069330: Adjustment of concurrent refinement thresholds does not take hot card cache into account
tschatzl
parents: 33105
diff changeset
   883
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   884
  p->record_or_add_time_secs(scan_phase, worker_id, cl.rem_set_opt_root_scan_time().seconds());
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   885
  p->record_or_add_time_secs(scan_phase, worker_id, cl.rem_set_opt_trim_partially_time().seconds());
6247
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   886
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   887
  p->record_or_add_time_secs(coderoots_phase, worker_id, cl.strong_code_root_scan_time().seconds());
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   888
  p->add_time_secs(objcopy_phase, worker_id, cl.strong_code_root_trim_partially_time().seconds());
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   889
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   890
  // At this time we record some metrics only for the evacuations after the initial one.
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   891
  if (scan_phase == G1GCPhaseTimes::OptScanHR) {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   892
    p->record_or_add_thread_work_item(scan_phase, worker_id, cl.opt_refs_scanned(), G1GCPhaseTimes::ScanHRScannedOptRefs);
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   893
    p->record_or_add_thread_work_item(scan_phase, worker_id, cl.opt_refs_memory_used(), G1GCPhaseTimes::ScanHRUsedMemory);
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   894
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   895
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   896
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   897
void G1RemSet::prepare_for_scan_heap_roots() {
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   898
  G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   899
  dcqs.concatenate_logs();
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   900
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
   901
  _scan_state->prepare();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   902
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   903
55720
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   904
class G1MergeHeapRootsTask : public AbstractGangTask {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   905
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   906
  // Visitor for remembered sets, dropping entries onto the card table.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   907
  class G1MergeCardSetClosure : public HeapRegionClosure {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   908
    G1RemSetScanState* _scan_state;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   909
    G1CardTable* _ct;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   910
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   911
    uint _merged_sparse;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   912
    uint _merged_fine;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   913
    uint _merged_coarse;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   914
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   915
    // Returns if the region contains cards we need to scan. If so, remember that
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   916
    // region in the current set of dirty regions.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   917
    bool remember_if_interesting(uint const region_idx) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   918
      if (!_scan_state->contains_cards_to_process(region_idx)) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   919
        return false;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   920
      }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   921
      _scan_state->add_dirty_region(region_idx);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   922
      return true;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   923
    }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   924
  public:
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   925
    G1MergeCardSetClosure(G1RemSetScanState* scan_state) :
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   926
      _scan_state(scan_state),
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   927
      _ct(G1CollectedHeap::heap()->card_table()),
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   928
      _merged_sparse(0),
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   929
      _merged_fine(0),
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   930
      _merged_coarse(0) { }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   931
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   932
    void next_coarse_prt(uint const region_idx) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   933
      if (!remember_if_interesting(region_idx)) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   934
        return;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   935
      }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   936
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   937
      _merged_coarse++;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   938
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   939
      size_t region_base_idx = (size_t)region_idx << HeapRegion::LogCardsPerRegion;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   940
      _ct->mark_region_dirty(region_base_idx, HeapRegion::CardsPerRegion);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   941
      _scan_state->set_chunk_region_dirty(region_base_idx);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   942
    }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   943
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   944
    void next_fine_prt(uint const region_idx, BitMap* bm) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   945
      if (!remember_if_interesting(region_idx)) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   946
        return;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   947
      }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   948
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   949
      _merged_fine++;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   950
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   951
      size_t const region_base_idx = (size_t)region_idx << HeapRegion::LogCardsPerRegion;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   952
      BitMap::idx_t cur = bm->get_next_one_offset(0);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   953
      while (cur != bm->size()) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   954
        _ct->mark_clean_as_dirty(region_base_idx + cur);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   955
        _scan_state->set_chunk_dirty(region_base_idx + cur);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   956
        cur = bm->get_next_one_offset(cur + 1);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   957
      }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   958
    }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   959
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   960
    void next_sparse_prt(uint const region_idx, SparsePRTEntry::card_elem_t* cards, uint const num_cards) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   961
      if (!remember_if_interesting(region_idx)) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   962
        return;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   963
      }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   964
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   965
      _merged_sparse++;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   966
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   967
      size_t const region_base_idx = (size_t)region_idx << HeapRegion::LogCardsPerRegion;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   968
      for (uint i = 0; i < num_cards; i++) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   969
        size_t card_idx = region_base_idx + cards[i];
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   970
        _ct->mark_clean_as_dirty(card_idx);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   971
        _scan_state->set_chunk_dirty(card_idx);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   972
      }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   973
    }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   974
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   975
    virtual bool do_heap_region(HeapRegion* r) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   976
      assert(r->in_collection_set() || r->is_starts_humongous(), "must be");
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   977
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   978
      HeapRegionRemSet* rem_set = r->rem_set();
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   979
      if (!rem_set->is_empty()) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   980
        rem_set->iterate_prts(*this);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   981
      }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   982
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   983
      return false;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   984
    }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   985
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   986
    size_t merged_sparse() const { return _merged_sparse; }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   987
    size_t merged_fine() const { return _merged_fine; }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   988
    size_t merged_coarse() const { return _merged_coarse; }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   989
  };
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   990
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   991
  // Visitor for the remembered sets of humongous candidate regions to merge their
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   992
  // remembered set into the card table.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   993
  class G1FlushHumongousCandidateRemSets : public HeapRegionClosure {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   994
    G1MergeCardSetClosure _cl;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   995
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   996
  public:
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   997
    G1FlushHumongousCandidateRemSets(G1RemSetScanState* scan_state) : _cl(scan_state) { }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   998
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
   999
    virtual bool do_heap_region(HeapRegion* r) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1000
      G1CollectedHeap* g1h = G1CollectedHeap::heap();
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1001
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1002
      if (!r->is_starts_humongous() ||
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1003
          !g1h->region_attr(r->hrm_index()).is_humongous() ||
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1004
          r->rem_set()->is_empty()) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1005
        return false;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1006
      }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1007
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1008
      guarantee(r->rem_set()->occupancy_less_or_equal_than(G1RSetSparseRegionEntries),
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1009
                "Found a not-small remembered set here. This is inconsistent with previous assumptions.");
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1010
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1011
      _cl.do_heap_region(r);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1012
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1013
      // We should only clear the card based remembered set here as we will not
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1014
      // implicitly rebuild anything else during eager reclaim. Note that at the moment
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1015
      // (and probably never) we do not enter this path if there are other kind of
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1016
      // remembered sets for this region.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1017
      r->rem_set()->clear_locked(true /* only_cardset */);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1018
      // Clear_locked() above sets the state to Empty. However we want to continue
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1019
      // collecting remembered set entries for humongous regions that were not
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1020
      // reclaimed.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1021
      r->rem_set()->set_state_complete();
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1022
#ifdef ASSERT
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1023
      G1HeapRegionAttr region_attr = g1h->region_attr(r->hrm_index());
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1024
      assert(region_attr.needs_remset_update(), "must be");
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1025
#endif
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1026
      assert(r->rem_set()->is_empty(), "At this point any humongous candidate remembered set must be empty.");
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1027
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1028
      return false;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1029
    }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1030
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1031
    size_t merged_sparse() const { return _cl.merged_sparse(); }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1032
    size_t merged_fine() const { return _cl.merged_fine(); }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1033
    size_t merged_coarse() const { return _cl.merged_coarse(); }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1034
  };
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1035
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1036
  // Visitor for the log buffer entries to merge them into the card table.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1037
  class G1MergeLogBufferCardsClosure : public G1CardTableEntryClosure {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1038
    G1RemSetScanState* _scan_state;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1039
    G1CardTable* _ct;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1040
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1041
    size_t _cards_dirty;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1042
    size_t _cards_skipped;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1043
  public:
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1044
    G1MergeLogBufferCardsClosure(G1CollectedHeap* g1h, G1RemSetScanState* scan_state) :
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1045
      _scan_state(scan_state), _ct(g1h->card_table()), _cards_dirty(0), _cards_skipped(0)
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1046
    {}
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1047
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1048
    bool do_card_ptr(CardValue* card_ptr, uint worker_i) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1049
      // The only time we care about recording cards that
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1050
      // contain references that point into the collection set
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1051
      // is during RSet updating within an evacuation pause.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1052
      // In this case worker_id should be the id of a GC worker thread.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1053
      assert(SafepointSynchronize::is_at_safepoint(), "not during an evacuation pause");
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1054
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1055
      uint const region_idx = _ct->region_idx_for(card_ptr);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1056
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1057
      // The second clause must come after - the log buffers might contain cards to uncommited
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1058
      // regions.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1059
      // This code may count duplicate entries in the log buffers (even if rare) multiple
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1060
      // times.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1061
      if (_scan_state->contains_cards_to_process(region_idx) && (*card_ptr == G1CardTable::dirty_card_val())) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1062
        _scan_state->add_dirty_region(region_idx);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1063
        _scan_state->set_chunk_dirty(_ct->index_for_cardvalue(card_ptr));
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1064
        _cards_dirty++;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1065
      } else {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1066
        // We may have had dirty cards in the (initial) collection set (or the
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1067
        // young regions which are always in the initial collection set). We do
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1068
        // not fix their cards here: we already added these regions to the set of
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1069
        // regions to clear the card table at the end during the prepare() phase.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1070
        _cards_skipped++;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1071
      }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1072
      return true;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1073
    }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1074
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1075
    size_t cards_dirty() const { return _cards_dirty; }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1076
    size_t cards_skipped() const { return _cards_skipped; }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1077
  };
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1078
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1079
  HeapRegionClaimer _hr_claimer;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1080
  G1RemSetScanState* _scan_state;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1081
  bool _remembered_set_only;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1082
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1083
  G1GCPhaseTimes::GCParPhases _merge_phase;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1084
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1085
  volatile bool _fast_reclaim_handled;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1086
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1087
public:
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1088
  G1MergeHeapRootsTask(G1RemSetScanState* scan_state, uint num_workers, bool remembered_set_only, G1GCPhaseTimes::GCParPhases merge_phase) :
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1089
    AbstractGangTask("G1 Merge Heap Roots"),
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1090
    _hr_claimer(num_workers),
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1091
    _scan_state(scan_state),
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1092
    _remembered_set_only(remembered_set_only),
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1093
    _merge_phase(merge_phase),
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1094
    _fast_reclaim_handled(false) { }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1095
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1096
  virtual void work(uint worker_id) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1097
    G1CollectedHeap* g1h = G1CollectedHeap::heap();
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1098
    G1GCPhaseTimes* p = g1h->phase_times();
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1099
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1100
    // We schedule flushing the remembered sets of humongous fast reclaim candidates
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1101
    // onto the card table first to allow the remaining parallelized tasks hide it.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1102
    if (!_remembered_set_only &&
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1103
        p->fast_reclaim_humongous_candidates() > 0 &&
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1104
        !_fast_reclaim_handled &&
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1105
        !Atomic::cmpxchg(true, &_fast_reclaim_handled, false)) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1106
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1107
      G1FlushHumongousCandidateRemSets cl(_scan_state);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1108
      g1h->heap_region_iterate(&cl);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1109
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1110
      p->record_or_add_thread_work_item(_merge_phase, worker_id, cl.merged_sparse(), G1GCPhaseTimes::MergeRSMergedSparse);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1111
      p->record_or_add_thread_work_item(_merge_phase, worker_id, cl.merged_fine(), G1GCPhaseTimes::MergeRSMergedFine);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1112
      p->record_or_add_thread_work_item(_merge_phase, worker_id, cl.merged_coarse(), G1GCPhaseTimes::MergeRSMergedCoarse);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1113
    }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1114
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1115
    // Merge remembered sets of current candidates.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1116
    {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1117
      G1GCParPhaseTimesTracker x(p, _merge_phase, worker_id, !_remembered_set_only /* must_record */);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1118
      G1MergeCardSetClosure cl(_scan_state);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1119
      g1h->collection_set_iterate_increment_from(&cl, &_hr_claimer, worker_id);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1120
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1121
      p->record_or_add_thread_work_item(_merge_phase, worker_id, cl.merged_sparse(), G1GCPhaseTimes::MergeRSMergedSparse);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1122
      p->record_or_add_thread_work_item(_merge_phase, worker_id, cl.merged_fine(), G1GCPhaseTimes::MergeRSMergedFine);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1123
      p->record_or_add_thread_work_item(_merge_phase, worker_id, cl.merged_coarse(), G1GCPhaseTimes::MergeRSMergedCoarse);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1124
    }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1125
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1126
    // Apply closure to log entries in the HCC.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1127
    if (!_remembered_set_only && G1HotCardCache::default_use_cache()) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1128
      assert(_merge_phase == G1GCPhaseTimes::MergeRS, "Wrong merge phase");
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1129
      G1GCParPhaseTimesTracker x(p, G1GCPhaseTimes::MergeHCC, worker_id);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1130
      G1MergeLogBufferCardsClosure cl(g1h, _scan_state);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1131
      g1h->iterate_hcc_closure(&cl, worker_id);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1132
    }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1133
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1134
    // Now apply the closure to all remaining log entries.
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1135
    if (!_remembered_set_only) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1136
      assert(_merge_phase == G1GCPhaseTimes::MergeRS, "Wrong merge phase");
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1137
      G1GCParPhaseTimesTracker x(p, G1GCPhaseTimes::MergeLB, worker_id);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1138
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1139
      G1MergeLogBufferCardsClosure cl(g1h, _scan_state);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1140
      g1h->iterate_dirty_card_closure(&cl, worker_id);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1141
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1142
      p->record_thread_work_item(G1GCPhaseTimes::MergeLB, worker_id, cl.cards_dirty(), G1GCPhaseTimes::MergeLBDirtyCards);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1143
      p->record_thread_work_item(G1GCPhaseTimes::MergeLB, worker_id, cl.cards_skipped(), G1GCPhaseTimes::MergeLBSkippedCards);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1144
    }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1145
  }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1146
};
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1147
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1148
void G1RemSet::print_merge_heap_roots_stats() {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1149
  size_t num_visited_cards = _scan_state->num_visited_cards();
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1150
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1151
  size_t total_dirty_region_cards = _scan_state->num_cards_in_dirty_regions();
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1152
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1153
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1154
  size_t total_old_region_cards =
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1155
    (g1h->num_regions() - (g1h->num_free_regions() - g1h->collection_set()->cur_length())) * HeapRegion::CardsPerRegion;
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1156
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1157
  log_debug(gc,remset)("Visited cards " SIZE_FORMAT " Total dirty " SIZE_FORMAT " (%.2lf%%) Total old " SIZE_FORMAT " (%.2lf%%)",
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1158
                       num_visited_cards,
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1159
                       total_dirty_region_cards,
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1160
                       percent_of(num_visited_cards, total_dirty_region_cards),
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1161
                       total_old_region_cards,
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1162
                       percent_of(num_visited_cards, total_old_region_cards));
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1163
}
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1164
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
  1165
void G1RemSet::merge_heap_roots(bool remembered_set_only, G1GCPhaseTimes::GCParPhases merge_phase) {
55720
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1166
  {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1167
    _scan_state->prepare_for_merge_heap_roots();
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1168
  }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1169
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1170
  WorkGang* workers = G1CollectedHeap::heap()->workers();
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1171
  size_t const increment_length = G1CollectedHeap::heap()->collection_set()->increment_length();
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1172
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1173
  uint const num_workers = !remembered_set_only ? workers->active_workers() :
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1174
                                                  MIN2(workers->active_workers(), (uint)increment_length);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1175
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1176
  {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1177
    G1MergeHeapRootsTask cl(_scan_state, num_workers, remembered_set_only, merge_phase);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1178
    log_debug(gc, ergo)("Running %s using %u workers for " SIZE_FORMAT " regions",
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1179
                        cl.name(), num_workers, increment_length);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1180
    workers->run_task(&cl, num_workers);
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1181
  }
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1182
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1183
  if (log_is_enabled(Debug, gc, remset)) {
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1184
    print_merge_heap_roots_stats();
dec1d532c000 8226232: Move merge heap roots code out from G1RemSetScanState
tschatzl
parents: 55607
diff changeset
  1185
  }
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
  1186
}
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
  1187
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
  1188
void G1RemSet::prepare_for_scan_heap_roots(uint region_idx) {
54934
39814e0a8964 8222492: G1 unnecessarily scans remembered set cards for regions that already have been evacuated
tschatzl
parents: 54844
diff changeset
  1189
  _scan_state->clear_scan_top(region_idx);
39814e0a8964 8222492: G1 unnecessarily scans remembered set cards for regions that already have been evacuated
tschatzl
parents: 54844
diff changeset
  1190
}
39814e0a8964 8222492: G1 unnecessarily scans remembered set cards for regions that already have been evacuated
tschatzl
parents: 54844
diff changeset
  1191
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
  1192
void G1RemSet::cleanup_after_scan_heap_roots() {
53986
9ad20fd52b19 8219748: Add and use getter for the timing object in G1
tschatzl
parents: 53985
diff changeset
  1193
  G1GCPhaseTimes* phase_times = _g1h->phase_times();
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
  1194
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1195
  // Set all cards back to clean.
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
  1196
  double start = os::elapsedTime();
55510
3e31a8beaae4 8213108: Improve work distribution during remembered set scan
tschatzl
parents: 54977
diff changeset
  1197
  _scan_state->cleanup(_g1h->workers());
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
  1198
  phase_times->record_clear_ct_time((os::elapsedTime() - start) * 1000.0);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1199
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1200
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53986
diff changeset
  1201
inline void check_card_ptr(CardTable::CardValue* card_ptr, G1CardTable* ct) {
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1202
#ifdef ASSERT
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
  1203
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
  1204
  assert(g1h->is_in_exact(ct->addr_for(card_ptr)),
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1205
         "Card at " PTR_FORMAT " index " SIZE_FORMAT " representing heap at " PTR_FORMAT " (%u) must be in committed heap",
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1206
         p2i(card_ptr),
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
  1207
         ct->index_for(ct->addr_for(card_ptr)),
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
  1208
         p2i(ct->addr_for(card_ptr)),
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
  1209
         g1h->addr_to_region(ct->addr_for(card_ptr)));
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1210
#endif
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1211
}
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1212
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53986
diff changeset
  1213
void G1RemSet::refine_card_concurrently(CardValue* card_ptr,
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1214
                                        uint worker_i) {
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
  1215
  assert(!_g1h->is_gc_active(), "Only call concurrently");
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents: 17108
diff changeset
  1216
52345
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
  1217
  // Construct the region representing the card.
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
  1218
  HeapWord* start = _ct->addr_for(card_ptr);
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
  1219
  // And find the region containing it.
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
  1220
  HeapRegion* r = _g1h->heap_region_containing_or_null(start);
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
  1221
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
  1222
  // If this is a (stale) card into an uncommitted region, exit.
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
  1223
  if (r == NULL) {
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
  1224
    return;
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
  1225
  }
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
  1226
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
  1227
  check_card_ptr(card_ptr, _ct);
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
  1228
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents: 17108
diff changeset
  1229
  // If the card is no longer dirty, nothing to do.
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
  1230
  if (*card_ptr != G1CardTable::dirty_card_val()) {
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1231
    return;
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1232
  }
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1233
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1234
  // This check is needed for some uncommon cases where we should
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1235
  // ignore the card.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1236
  //
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1237
  // The region could be young.  Cards for young regions are
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1238
  // distinctly marked (set to g1_young_gen), so the post-barrier will
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1239
  // filter them out.  However, that marking is performed
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1240
  // concurrently.  A write to a young object could occur before the
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1241
  // card has been marked young, slipping past the filter.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1242
  //
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1243
  // The card could be stale, because the region has been freed since
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1244
  // the card was recorded. In this case the region type could be
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1245
  // anything.  If (still) free or (reallocated) young, just ignore
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1246
  // it.  If (reallocated) old or humongous, the later card trimming
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1247
  // and additional checks in iteration may detect staleness.  At
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1248
  // worst, we end up processing a stale card unnecessarily.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1249
  //
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1250
  // In the normal (non-stale) case, the synchronization between the
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1251
  // enqueueing of the card and processing it here will have ensured
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1252
  // we see the up-to-date region type here.
51494
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 51332
diff changeset
  1253
  if (!r->is_old_or_humongous_or_archive()) {
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1254
    return;
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1255
  }
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1256
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1257
  // The result from the hot card cache insert call is either:
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1258
  //   * pointer to the current card
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1259
  //     (implying that the current card is not 'hot'),
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1260
  //   * null
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1261
  //     (meaning we had inserted the card ptr into the "hot" card cache,
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1262
  //     which had some headroom),
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1263
  //   * a pointer to a "hot" card that was evicted from the "hot" cache.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1264
  //
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1265
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1266
  if (_hot_card_cache->use_cache()) {
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1267
    assert(!SafepointSynchronize::is_at_safepoint(), "sanity");
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1268
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53986
diff changeset
  1269
    const CardValue* orig_card_ptr = card_ptr;
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1270
    card_ptr = _hot_card_cache->insert(card_ptr);
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1271
    if (card_ptr == NULL) {
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1272
      // There was no eviction. Nothing to do.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1273
      return;
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1274
    } else if (card_ptr != orig_card_ptr) {
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1275
      // Original card was inserted and an old card was evicted.
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
  1276
      start = _ct->addr_for(card_ptr);
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
  1277
      r = _g1h->heap_region_containing(start);
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1278
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1279
      // Check whether the region formerly in the cache should be
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1280
      // ignored, as discussed earlier for the original card.  The
49346
14e84a4edb9c 8198546: [Redo] JDK-8196883 G1RemSet::refine_card_concurrently doesn't need to check for cards in collection set
tschatzl
parents: 49194
diff changeset
  1281
      // region could have been freed while in the cache.
51494
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 51332
diff changeset
  1282
      if (!r->is_old_or_humongous_or_archive()) {
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1283
        return;
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1284
      }
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1285
    } // Else we still have the original card.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1286
  }
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1287
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1288
  // Trim the region designated by the card to what's been allocated
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1289
  // in the region.  The card could be stale, or the card could cover
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1290
  // (part of) an object at the end of the allocated space and extend
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1291
  // beyond the end of allocation.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1292
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1293
  // Non-humongous objects are only allocated in the old-gen during
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1294
  // GC, so if region is old then top is stable.  Humongous object
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1295
  // allocation sets top last; if top has not yet been set, this is
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1296
  // a stale card and we'll end up with an empty intersection.  If
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1297
  // this is not a stale card, the synchronization between the
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1298
  // enqueuing of the card and processing it here will have ensured
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1299
  // we see the up-to-date top here.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1300
  HeapWord* scan_limit = r->top();
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1301
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1302
  if (scan_limit <= start) {
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1303
    // If the trimmed region is empty, the card must be stale.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1304
    return;
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1305
  }
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1306
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1307
  // Okay to clean and process the card now.  There are still some
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1308
  // stale card cases that may be detected by iteration and dealt with
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1309
  // as iteration failure.
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53986
diff changeset
  1310
  *const_cast<volatile CardValue*>(card_ptr) = G1CardTable::clean_card_val();
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1311
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1312
  // This fence serves two purposes.  First, the card must be cleaned
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1313
  // before processing the contents.  Second, we can't proceed with
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1314
  // processing until after the read of top, for synchronization with
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1315
  // possibly concurrent humongous object allocation.  It's okay that
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1316
  // reading top and reading type were racy wrto each other.  We need
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1317
  // both set, in any order, to proceed.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1318
  OrderAccess::fence();
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1319
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1320
  // Don't use addr_for(card_ptr + 1) which can ask for
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1321
  // a card beyond the heap.
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
  1322
  HeapWord* end = start + G1CardTable::card_size_in_words;
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1323
  MemRegion dirty_region(start, MIN2(scan_limit, end));
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1324
  assert(!dirty_region.is_empty(), "sanity");
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1325
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
  1326
  G1ConcurrentRefineOopClosure conc_refine_cl(_g1h, worker_i);
55607
5919b273def6 8224741: Optimize the scan area during the Scan Heap Roots phase
tschatzl
parents: 55510
diff changeset
  1327
  if (r->oops_on_memregion_seq_iterate_careful<false>(dirty_region, &conc_refine_cl) != NULL) {
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1328
    _num_conc_refined_cards++; // Unsynchronized update, only used for logging.
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1329
    return;
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1330
  }
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1331
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1332
  // If unable to process the card then we encountered an unparsable
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1333
  // part of the heap (e.g. a partially allocated object, so only
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1334
  // temporarily a problem) while processing a stale card.  Despite
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1335
  // the card being stale, we can't simply ignore it, because we've
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1336
  // already marked the card cleaned, so taken responsibility for
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1337
  // ensuring the card gets scanned.
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1338
  //
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1339
  // However, the card might have gotten re-dirtied and re-enqueued
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1340
  // while we worked.  (In fact, it's pretty likely.)
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1341
  if (*card_ptr == G1CardTable::dirty_card_val()) {
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1342
    return;
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1343
  }
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1344
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1345
  // Re-dirty the card and enqueue in the *shared* queue.  Can't use
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1346
  // the thread-local queue, because that might be the queue that is
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1347
  // being processed by us; we could be a Java thread conscripted to
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1348
  // perform refinement on our queue's current buffer.
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1349
  *card_ptr = G1CardTable::dirty_card_val();
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
  1350
  G1BarrierSet::shared_dirty_card_queue().enqueue(card_ptr);
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1351
}
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
  1352
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
  1353
void G1RemSet::print_periodic_summary_info(const char* header, uint period_count) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
  1354
  if ((G1SummarizeRSetStatsPeriod > 0) && log_is_enabled(Trace, gc, remset) &&
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
  1355
      (period_count % G1SummarizeRSetStatsPeriod == 0)) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
  1356
46652
ab8716d193bb 8183226: Remembered set summarization accesses not fully initialized java thread DCQS
tschatzl
parents: 46635
diff changeset
  1357
    G1RemSetSummary current(this);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
  1358
    _prev_period_summary.subtract_from(&current);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1359
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 36374
diff changeset
  1360
    Log(gc, remset) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
  1361
    log.trace("%s", header);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
  1362
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46676
diff changeset
  1363
    LogStream ls(log.trace());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46676
diff changeset
  1364
    _prev_period_summary.print_on(&ls);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
  1365
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
  1366
    _prev_period_summary.set(&current);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
  1367
  }
17854
d65bc1546091 8013895: G1: G1SummarizeRSetStats output on Linux needs improvemen
tschatzl
parents: 17327
diff changeset
  1368
}
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
  1369
6958
cfa71cf3564d 6971296: G1: simplify G1RemSet class hierarchy
johnc
parents: 6759
diff changeset
  1370
void G1RemSet::print_summary_info() {
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 36374
diff changeset
  1371
  Log(gc, remset, exit) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
  1372
  if (log.is_trace()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
  1373
    log.trace(" Cumulative RS summary");
46653
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46652
diff changeset
  1374
    G1RemSetSummary current(this);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
  1375
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46676
diff changeset
  1376
    LogStream ls(log.trace());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46676
diff changeset
  1377
    current.print_on(&ls);
17854
d65bc1546091 8013895: G1: G1SummarizeRSetStats output on Linux needs improvemen
tschatzl
parents: 17327
diff changeset
  1378
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1379
}
6247
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
  1380
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1381
class G1RebuildRemSetTask: public AbstractGangTask {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1382
  // Aggregate the counting data that was constructed concurrently
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1383
  // with marking.
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1384
  class G1RebuildRemSetHeapRegionClosure : public HeapRegionClosure {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1385
    G1ConcurrentMark* _cm;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1386
    G1RebuildRemSetClosure _update_cl;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1387
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1388
    // Applies _update_cl to the references of the given object, limiting objArrays
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1389
    // to the given MemRegion. Returns the amount of words actually scanned.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1390
    size_t scan_for_references(oop const obj, MemRegion mr) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1391
      size_t const obj_size = obj->size();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1392
      // All non-objArrays and objArrays completely within the mr
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1393
      // can be scanned without passing the mr.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1394
      if (!obj->is_objArray() || mr.contains(MemRegion((HeapWord*)obj, obj_size))) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1395
        obj->oop_iterate(&_update_cl);
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1396
        return obj_size;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1397
      }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1398
      // This path is for objArrays crossing the given MemRegion. Only scan the
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1399
      // area within the MemRegion.
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1400
      obj->oop_iterate(&_update_cl, mr);
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1401
      return mr.intersection(MemRegion((HeapWord*)obj, obj_size)).word_size();
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1402
    }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1403
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1404
    // A humongous object is live (with respect to the scanning) either
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1405
    // a) it is marked on the bitmap as such
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1406
    // b) its TARS is larger than TAMS, i.e. has been allocated during marking.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1407
    bool is_humongous_live(oop const humongous_obj, const G1CMBitMap* const bitmap, HeapWord* tams, HeapWord* tars) const {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1408
      return bitmap->is_marked(humongous_obj) || (tars > tams);
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1409
    }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1410
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1411
    // Iterator over the live objects within the given MemRegion.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1412
    class LiveObjIterator : public StackObj {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1413
      const G1CMBitMap* const _bitmap;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1414
      const HeapWord* _tams;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1415
      const MemRegion _mr;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1416
      HeapWord* _current;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1417
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1418
      bool is_below_tams() const {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1419
        return _current < _tams;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1420
      }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1421
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1422
      bool is_live(HeapWord* obj) const {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1423
        return !is_below_tams() || _bitmap->is_marked(obj);
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1424
      }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1425
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1426
      HeapWord* bitmap_limit() const {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1427
        return MIN2(const_cast<HeapWord*>(_tams), _mr.end());
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1428
      }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1429
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1430
      void move_if_below_tams() {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1431
        if (is_below_tams() && has_next()) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1432
          _current = _bitmap->get_next_marked_addr(_current, bitmap_limit());
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1433
        }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1434
      }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1435
    public:
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1436
      LiveObjIterator(const G1CMBitMap* const bitmap, const HeapWord* tams, const MemRegion mr, HeapWord* first_oop_into_mr) :
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1437
          _bitmap(bitmap),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1438
          _tams(tams),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1439
          _mr(mr),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1440
          _current(first_oop_into_mr) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1441
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1442
        assert(_current <= _mr.start(),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1443
               "First oop " PTR_FORMAT " should extend into mr [" PTR_FORMAT ", " PTR_FORMAT ")",
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1444
               p2i(first_oop_into_mr), p2i(mr.start()), p2i(mr.end()));
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1445
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1446
        // Step to the next live object within the MemRegion if needed.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1447
        if (is_live(_current)) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1448
          // Non-objArrays were scanned by the previous part of that region.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1449
          if (_current < mr.start() && !oop(_current)->is_objArray()) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1450
            _current += oop(_current)->size();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1451
            // We might have positioned _current on a non-live object. Reposition to the next
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1452
            // live one if needed.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1453
            move_if_below_tams();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1454
          }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1455
        } else {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1456
          // The object at _current can only be dead if below TAMS, so we can use the bitmap.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1457
          // immediately.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1458
          _current = _bitmap->get_next_marked_addr(_current, bitmap_limit());
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1459
          assert(_current == _mr.end() || is_live(_current),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1460
                 "Current " PTR_FORMAT " should be live (%s) or beyond the end of the MemRegion (" PTR_FORMAT ")",
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1461
                 p2i(_current), BOOL_TO_STR(is_live(_current)), p2i(_mr.end()));
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1462
        }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1463
      }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1464
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1465
      void move_to_next() {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1466
        _current += next()->size();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1467
        move_if_below_tams();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1468
      }
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1469
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1470
      oop next() const {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1471
        oop result = oop(_current);
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1472
        assert(is_live(_current),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1473
               "Object " PTR_FORMAT " must be live TAMS " PTR_FORMAT " below %d mr " PTR_FORMAT " " PTR_FORMAT " outside %d",
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1474
               p2i(_current), p2i(_tams), _tams > _current, p2i(_mr.start()), p2i(_mr.end()), _mr.contains(result));
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1475
        return result;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1476
      }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1477
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1478
      bool has_next() const {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1479
        return _current < _mr.end();
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1480
      }
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1481
    };
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1482
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1483
    // Rebuild remembered sets in the part of the region specified by mr and hr.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1484
    // Objects between the bottom of the region and the TAMS are checked for liveness
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1485
    // using the given bitmap. Objects between TAMS and TARS are assumed to be live.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1486
    // Returns the number of live words between bottom and TAMS.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1487
    size_t rebuild_rem_set_in_region(const G1CMBitMap* const bitmap,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1488
                                     HeapWord* const top_at_mark_start,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1489
                                     HeapWord* const top_at_rebuild_start,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1490
                                     HeapRegion* hr,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1491
                                     MemRegion mr) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1492
      size_t marked_words = 0;
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1493
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1494
      if (hr->is_humongous()) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1495
        oop const humongous_obj = oop(hr->humongous_start_region()->bottom());
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1496
        if (is_humongous_live(humongous_obj, bitmap, top_at_mark_start, top_at_rebuild_start)) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1497
          // We need to scan both [bottom, TAMS) and [TAMS, top_at_rebuild_start);
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1498
          // however in case of humongous objects it is sufficient to scan the encompassing
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1499
          // area (top_at_rebuild_start is always larger or equal to TAMS) as one of the
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1500
          // two areas will be zero sized. I.e. TAMS is either
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1501
          // the same as bottom or top(_at_rebuild_start). There is no way TAMS has a different
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1502
          // value: this would mean that TAMS points somewhere into the object.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1503
          assert(hr->top() == top_at_mark_start || hr->top() == top_at_rebuild_start,
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1504
                 "More than one object in the humongous region?");
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1505
          humongous_obj->oop_iterate(&_update_cl, mr);
49803
14518ac8df87 8178105: Switch mark bitmaps during Remark
tschatzl
parents: 49751
diff changeset
  1506
          return top_at_mark_start != hr->bottom() ? mr.intersection(MemRegion((HeapWord*)humongous_obj, humongous_obj->size())).byte_size() : 0;
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1507
        } else {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1508
          return 0;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1509
        }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1510
      }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1511
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1512
      for (LiveObjIterator it(bitmap, top_at_mark_start, mr, hr->block_start(mr.start())); it.has_next(); it.move_to_next()) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1513
        oop obj = it.next();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1514
        size_t scanned_size = scan_for_references(obj, mr);
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1515
        if ((HeapWord*)obj < top_at_mark_start) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1516
          marked_words += scanned_size;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1517
        }
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1518
      }
37414
2672ba9af0dc 8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents: 37248
diff changeset
  1519
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1520
      return marked_words * HeapWordSize;
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1521
    }
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1522
public:
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1523
  G1RebuildRemSetHeapRegionClosure(G1CollectedHeap* g1h,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1524
                                   G1ConcurrentMark* cm,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1525
                                   uint worker_id) :
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1526
    HeapRegionClosure(),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1527
    _cm(cm),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1528
    _update_cl(g1h, worker_id) { }
37414
2672ba9af0dc 8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents: 37248
diff changeset
  1529
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1530
    bool do_heap_region(HeapRegion* hr) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1531
      if (_cm->has_aborted()) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1532
        return true;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1533
      }
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1534
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1535
      uint const region_idx = hr->hrm_index();
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1536
      DEBUG_ONLY(HeapWord* const top_at_rebuild_start_check = _cm->top_at_rebuild_start(region_idx);)
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1537
      assert(top_at_rebuild_start_check == NULL ||
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1538
             top_at_rebuild_start_check > hr->bottom(),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1539
             "A TARS (" PTR_FORMAT ") == bottom() (" PTR_FORMAT ") indicates the old region %u is empty (%s)",
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1540
             p2i(top_at_rebuild_start_check), p2i(hr->bottom()),  region_idx, hr->get_type_str());
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1541
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1542
      size_t total_marked_bytes = 0;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1543
      size_t const chunk_size_in_words = G1RebuildRemSetChunkSize / HeapWordSize;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1544
49803
14518ac8df87 8178105: Switch mark bitmaps during Remark
tschatzl
parents: 49751
diff changeset
  1545
      HeapWord* const top_at_mark_start = hr->prev_top_at_mark_start();
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1546
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1547
      HeapWord* cur = hr->bottom();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1548
      while (cur < hr->end()) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1549
        // After every iteration (yield point) we need to check whether the region's
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1550
        // TARS changed due to e.g. eager reclaim.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1551
        HeapWord* const top_at_rebuild_start = _cm->top_at_rebuild_start(region_idx);
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1552
        if (top_at_rebuild_start == NULL) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1553
          return false;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1554
        }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1555
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1556
        MemRegion next_chunk = MemRegion(hr->bottom(), top_at_rebuild_start).intersection(MemRegion(cur, chunk_size_in_words));
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1557
        if (next_chunk.is_empty()) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1558
          break;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1559
        }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1560
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1561
        const Ticks start = Ticks::now();
49803
14518ac8df87 8178105: Switch mark bitmaps during Remark
tschatzl
parents: 49751
diff changeset
  1562
        size_t marked_bytes = rebuild_rem_set_in_region(_cm->prev_mark_bitmap(),
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1563
                                                        top_at_mark_start,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1564
                                                        top_at_rebuild_start,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1565
                                                        hr,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1566
                                                        next_chunk);
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1567
        Tickspan time = Ticks::now() - start;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1568
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1569
        log_trace(gc, remset, tracking)("Rebuilt region %u "
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1570
                                        "live " SIZE_FORMAT " "
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1571
                                        "time %.3fms "
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1572
                                        "marked bytes " SIZE_FORMAT " "
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1573
                                        "bot " PTR_FORMAT " "
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1574
                                        "TAMS " PTR_FORMAT " "
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1575
                                        "TARS " PTR_FORMAT,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1576
                                        region_idx,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1577
                                        _cm->liveness(region_idx) * HeapWordSize,
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49911
diff changeset
  1578
                                        time.seconds() * 1000.0,
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1579
                                        marked_bytes,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1580
                                        p2i(hr->bottom()),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1581
                                        p2i(top_at_mark_start),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1582
                                        p2i(top_at_rebuild_start));
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1583
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1584
        if (marked_bytes > 0) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1585
          total_marked_bytes += marked_bytes;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1586
        }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1587
        cur += chunk_size_in_words;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1588
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1589
        _cm->do_yield_check();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1590
        if (_cm->has_aborted()) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1591
          return true;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1592
        }
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1593
      }
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1594
      // In the final iteration of the loop the region might have been eagerly reclaimed.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1595
      // Simply filter out those regions. We can not just use region type because there
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1596
      // might have already been new allocations into these regions.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1597
      DEBUG_ONLY(HeapWord* const top_at_rebuild_start = _cm->top_at_rebuild_start(region_idx);)
49803
14518ac8df87 8178105: Switch mark bitmaps during Remark
tschatzl
parents: 49751
diff changeset
  1598
      assert(top_at_rebuild_start == NULL ||
14518ac8df87 8178105: Switch mark bitmaps during Remark
tschatzl
parents: 49751
diff changeset
  1599
             total_marked_bytes == hr->marked_bytes(),
14518ac8df87 8178105: Switch mark bitmaps during Remark
tschatzl
parents: 49751
diff changeset
  1600
             "Marked bytes " SIZE_FORMAT " for region %u (%s) in [bottom, TAMS) do not match calculated marked bytes " SIZE_FORMAT " "
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1601
             "(" PTR_FORMAT " " PTR_FORMAT " " PTR_FORMAT ")",
49803
14518ac8df87 8178105: Switch mark bitmaps during Remark
tschatzl
parents: 49751
diff changeset
  1602
             total_marked_bytes, hr->hrm_index(), hr->get_type_str(), hr->marked_bytes(),
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1603
             p2i(hr->bottom()), p2i(top_at_mark_start), p2i(top_at_rebuild_start));
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1604
       // Abort state may have changed after the yield check.
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1605
      return _cm->has_aborted();
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1606
    }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1607
  };
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1608
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1609
  HeapRegionClaimer _hr_claimer;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1610
  G1ConcurrentMark* _cm;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1611
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1612
  uint _worker_id_offset;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1613
public:
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1614
  G1RebuildRemSetTask(G1ConcurrentMark* cm,
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1615
                      uint n_workers,
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1616
                      uint worker_id_offset) :
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1617
      AbstractGangTask("G1 Rebuild Remembered Set"),
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 50113
diff changeset
  1618
      _hr_claimer(n_workers),
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1619
      _cm(cm),
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1620
      _worker_id_offset(worker_id_offset) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1621
  }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1622
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1623
  void work(uint worker_id) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1624
    SuspendibleThreadSetJoiner sts_join;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1625
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1626
    G1CollectedHeap* g1h = G1CollectedHeap::heap();
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1627
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1628
    G1RebuildRemSetHeapRegionClosure cl(g1h, _cm, _worker_id_offset + worker_id);
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1629
    g1h->heap_region_par_iterate_from_worker_offset(&cl, &_hr_claimer, worker_id);
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1630
  }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1631
};
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1632
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1633
void G1RemSet::rebuild_rem_set(G1ConcurrentMark* cm,
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1634
                               WorkGang* workers,
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1635
                               uint worker_id_offset) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1636
  uint num_workers = workers->active_workers();
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1637
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1638
  G1RebuildRemSetTask cl(cm,
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1639
                         num_workers,
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1640
                         worker_id_offset);
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1641
  workers->run_task(&cl, num_workers);
37414
2672ba9af0dc 8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents: 37248
diff changeset
  1642
}