src/hotspot/share/gc/g1/g1RemSet.cpp
author tschatzl
Tue, 14 May 2019 15:36:26 +0200
changeset 54844 571732021d59
parent 54843 25c329958c70
child 54934 39814e0a8964
permissions -rw-r--r--
8223018: Rename G1RemSet::*oops_into_collection_set_do methods Reviewed-by: manc, sangheki
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"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30175
diff changeset
    41
#include "gc/g1/heapRegionRemSet.hpp"
37414
2672ba9af0dc 8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents: 37248
diff changeset
    42
#include "gc/shared/gcTraceTime.inline.hpp"
47647
64dba69fc528 8189276: Make SuspendibleThreadSet and related code available to other GCs
rkennke
parents: 47216
diff changeset
    43
#include "gc/shared/suspendibleThreadSet.hpp"
51877
5f931e3e7a63 8196341: Add JFR events for parallel phases of G1
lkorinth
parents: 51494
diff changeset
    44
#include "jfr/jfrEvents.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7385
diff changeset
    45
#include "memory/iterator.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 37242
diff changeset
    46
#include "memory/resourceArea.hpp"
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
    47
#include "oops/access.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7385
diff changeset
    48
#include "oops/oop.inline.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49911
diff changeset
    49
#include "runtime/os.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    50
#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
    51
#include "utilities/globalDefinitions.hpp"
30175
543725014c9d 8076457: Fix includes of inline.hpp in GC code
stefank
parents: 29796
diff changeset
    52
#include "utilities/stack.inline.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49911
diff changeset
    53
#include "utilities/ticks.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    54
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
    55
// Collects information about the overall remembered set scan progress during an evacuation.
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
    56
class G1RemSetScanState : public CHeapObj<mtGC> {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
    57
private:
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    58
  class G1ClearCardTableTask : public AbstractGangTask {
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    59
    G1CollectedHeap* _g1h;
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    60
    uint* _dirty_region_list;
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    61
    size_t _num_dirty_regions;
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    62
    size_t _chunk_length;
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    63
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    64
    size_t volatile _cur_dirty_regions;
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    65
  public:
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    66
    G1ClearCardTableTask(G1CollectedHeap* g1h,
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    67
                         uint* dirty_region_list,
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    68
                         size_t num_dirty_regions,
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    69
                         size_t chunk_length) :
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    70
      AbstractGangTask("G1 Clear Card Table Task"),
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    71
      _g1h(g1h),
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    72
      _dirty_region_list(dirty_region_list),
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    73
      _num_dirty_regions(num_dirty_regions),
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    74
      _chunk_length(chunk_length),
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    75
      _cur_dirty_regions(0) {
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    76
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    77
      assert(chunk_length > 0, "must be");
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    78
    }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    79
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    80
    static size_t chunk_size() { return M; }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    81
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    82
    void work(uint worker_id) {
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    83
      while (_cur_dirty_regions < _num_dirty_regions) {
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    84
        size_t next = Atomic::add(_chunk_length, &_cur_dirty_regions) - _chunk_length;
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    85
        size_t max = MIN2(next + _chunk_length, _num_dirty_regions);
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    86
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    87
        for (size_t i = next; i < max; i++) {
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    88
          HeapRegion* r = _g1h->region_at(_dirty_region_list[i]);
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    89
          if (!r->is_survivor()) {
49632
64f9ebc85e67 8197573: Remove concurrent cleanup and secondary free list handling
tschatzl
parents: 49607
diff changeset
    90
            r->clear_cardtable();
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    91
          }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    92
        }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    93
      }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    94
    }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    95
  };
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
    96
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
    97
  size_t _max_regions;
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
    98
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
    99
  // Scan progress for the remembered set of a single region. Transitions from
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   100
  // Unclaimed -> Claimed -> Complete.
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   101
  // At each of the transitions the thread that does the transition needs to perform
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   102
  // some special action once. This is the reason for the extra "Claimed" state.
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   103
  typedef jint G1RemsetIterState;
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   104
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   105
  static const G1RemsetIterState Unclaimed = 0; // The remembered set has not been scanned yet.
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   106
  static const G1RemsetIterState Claimed = 1;   // The remembered set is currently being scanned.
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   107
  static const G1RemsetIterState Complete = 2;  // The remembered set has been completely scanned.
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   108
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   109
  G1RemsetIterState volatile* _iter_states;
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   110
  // The current location where the next thread should continue scanning in a region's
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   111
  // remembered set.
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   112
  size_t volatile* _iter_claims;
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   113
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   114
  // Temporary buffer holding the regions we used to store remembered set scan duplicate
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   115
  // information. These are also called "dirty". Valid entries are from [0.._cur_dirty_region)
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   116
  uint* _dirty_region_buffer;
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   117
54111
e8de5d46ecd4 8220345: Use appropriate type for G1RemSetScanState::IsDirtyRegionState
tschatzl
parents: 54110
diff changeset
   118
  // Flag for every region whether it is in the _dirty_region_buffer already
e8de5d46ecd4 8220345: Use appropriate type for G1RemSetScanState::IsDirtyRegionState
tschatzl
parents: 54110
diff changeset
   119
  // to avoid duplicates.
e8de5d46ecd4 8220345: Use appropriate type for G1RemSetScanState::IsDirtyRegionState
tschatzl
parents: 54110
diff changeset
   120
  bool volatile* _in_dirty_region_buffer;
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   121
  size_t _cur_dirty_region;
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   122
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   123
  // Creates a snapshot of the current _top values at the start of collection to
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   124
  // filter out card marks that we do not want to scan.
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   125
  class G1ResetScanTopClosure : public HeapRegionClosure {
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   126
  private:
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   127
    HeapWord** _scan_top;
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   128
  public:
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   129
    G1ResetScanTopClosure(HeapWord** scan_top) : _scan_top(scan_top) { }
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   130
48950
f323537c9b75 8196602: Change HeapRegionClosure to comply to naming conventions
tschatzl
parents: 48103
diff changeset
   131
    virtual bool do_heap_region(HeapRegion* r) {
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   132
      uint hrm_index = r->hrm_index();
52345
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   133
      if (!r->in_collection_set() && r->is_old_or_humongous_or_archive() && !r->is_empty()) {
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   134
        _scan_top[hrm_index] = r->top();
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   135
      } else {
52345
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   136
        _scan_top[hrm_index] = NULL;
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   137
      }
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   138
      return false;
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   139
    }
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   140
  };
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   141
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   142
  // For each region, contains the maximum top() value to be used during this garbage
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   143
  // collection. Subsumes common checks like filtering out everything but old and
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   144
  // humongous regions outside the collection set.
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   145
  // This is valid because we are not interested in scanning stray remembered set
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   146
  // entries from free or archive regions.
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   147
  HeapWord** _scan_top;
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   148
public:
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   149
  G1RemSetScanState() :
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   150
    _max_regions(0),
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   151
    _iter_states(NULL),
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   152
    _iter_claims(NULL),
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   153
    _dirty_region_buffer(NULL),
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   154
    _in_dirty_region_buffer(NULL),
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   155
    _cur_dirty_region(0),
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   156
    _scan_top(NULL) {
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   157
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   158
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   159
  ~G1RemSetScanState() {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   160
    if (_iter_states != NULL) {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   161
      FREE_C_HEAP_ARRAY(G1RemsetIterState, _iter_states);
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   162
    }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   163
    if (_iter_claims != NULL) {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   164
      FREE_C_HEAP_ARRAY(size_t, _iter_claims);
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   165
    }
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   166
    if (_dirty_region_buffer != NULL) {
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   167
      FREE_C_HEAP_ARRAY(uint, _dirty_region_buffer);
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   168
    }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   169
    if (_in_dirty_region_buffer != NULL) {
54111
e8de5d46ecd4 8220345: Use appropriate type for G1RemSetScanState::IsDirtyRegionState
tschatzl
parents: 54110
diff changeset
   170
      FREE_C_HEAP_ARRAY(bool, _in_dirty_region_buffer);
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   171
    }
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   172
    if (_scan_top != NULL) {
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   173
      FREE_C_HEAP_ARRAY(HeapWord*, _scan_top);
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   174
    }
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   175
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   176
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   177
  void initialize(uint max_regions) {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   178
    assert(_iter_states == NULL, "Must not be initialized twice");
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   179
    assert(_iter_claims == NULL, "Must not be initialized twice");
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   180
    _max_regions = max_regions;
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   181
    _iter_states = NEW_C_HEAP_ARRAY(G1RemsetIterState, max_regions, mtGC);
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   182
    _iter_claims = NEW_C_HEAP_ARRAY(size_t, max_regions, mtGC);
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   183
    _dirty_region_buffer = NEW_C_HEAP_ARRAY(uint, max_regions, mtGC);
54111
e8de5d46ecd4 8220345: Use appropriate type for G1RemSetScanState::IsDirtyRegionState
tschatzl
parents: 54110
diff changeset
   184
    _in_dirty_region_buffer = NEW_C_HEAP_ARRAY(bool, max_regions, mtGC);
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   185
    _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
   186
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   187
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   188
  void reset() {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   189
    for (uint i = 0; i < _max_regions; i++) {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   190
      _iter_states[i] = Unclaimed;
52345
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   191
      _scan_top[i] = NULL;
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   192
    }
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   193
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   194
    G1ResetScanTopClosure cl(_scan_top);
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   195
    G1CollectedHeap::heap()->heap_region_iterate(&cl);
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   196
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   197
    memset((void*)_iter_claims, 0, _max_regions * sizeof(size_t));
54111
e8de5d46ecd4 8220345: Use appropriate type for G1RemSetScanState::IsDirtyRegionState
tschatzl
parents: 54110
diff changeset
   198
    memset((void*)_in_dirty_region_buffer, false, _max_regions * sizeof(bool));
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   199
    _cur_dirty_region = 0;
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   200
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   201
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   202
  // Attempt to claim the remembered set of the region for iteration. Returns true
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   203
  // if this call caused the transition from Unclaimed to Claimed.
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   204
  inline bool claim_iter(uint region) {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   205
    assert(region < _max_regions, "Tried to access invalid region %u", region);
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   206
    if (_iter_states[region] != Unclaimed) {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   207
      return false;
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   208
    }
48955
e22914003cf0 8194691: Cleanup unnecessary casts in Atomic/OrderAccess uses
kbarrett
parents: 48954
diff changeset
   209
    G1RemsetIterState res = Atomic::cmpxchg(Claimed, &_iter_states[region], Unclaimed);
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   210
    return (res == Unclaimed);
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   211
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   212
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   213
  // Try to atomically sets the iteration state to "complete". Returns true for the
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   214
  // thread that caused the transition.
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   215
  inline bool set_iter_complete(uint region) {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   216
    if (iter_is_complete(region)) {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   217
      return false;
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   218
    }
48955
e22914003cf0 8194691: Cleanup unnecessary casts in Atomic/OrderAccess uses
kbarrett
parents: 48954
diff changeset
   219
    G1RemsetIterState res = Atomic::cmpxchg(Complete, &_iter_states[region], Claimed);
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   220
    return (res == Claimed);
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   221
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   222
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   223
  // Returns true if the region's iteration is complete.
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   224
  inline bool iter_is_complete(uint region) const {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   225
    assert(region < _max_regions, "Tried to access invalid region %u", region);
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   226
    return _iter_states[region] == Complete;
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   227
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   228
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   229
  // The current position within the remembered set of the given region.
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   230
  inline size_t iter_claimed(uint region) const {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   231
    assert(region < _max_regions, "Tried to access invalid region %u", region);
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   232
    return _iter_claims[region];
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   233
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   234
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   235
  // Claim the next block of cards within the remembered set of the region with
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   236
  // step size.
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   237
  inline size_t iter_claimed_next(uint region, size_t step) {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   238
    return Atomic::add(step, &_iter_claims[region]) - step;
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   239
  }
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   240
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   241
  void add_dirty_region(uint region) {
54111
e8de5d46ecd4 8220345: Use appropriate type for G1RemSetScanState::IsDirtyRegionState
tschatzl
parents: 54110
diff changeset
   242
    if (_in_dirty_region_buffer[region]) {
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   243
      return;
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   244
    }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   245
54111
e8de5d46ecd4 8220345: Use appropriate type for G1RemSetScanState::IsDirtyRegionState
tschatzl
parents: 54110
diff changeset
   246
    if (!Atomic::cmpxchg(true, &_in_dirty_region_buffer[region], false)) {
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46778
diff changeset
   247
      size_t allocated = Atomic::add(1u, &_cur_dirty_region) - 1;
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   248
      _dirty_region_buffer[allocated] = region;
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   249
    }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   250
  }
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   251
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   252
  HeapWord* scan_top(uint region_idx) const {
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   253
    return _scan_top[region_idx];
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   254
  }
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   255
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   256
  // Clear the card table of "dirty" regions.
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   257
  void clear_card_table(WorkGang* workers) {
38160
13a14d5777b0 8155813: Fix indentation in G1RemSetScanState::clear_card_table()
tschatzl
parents: 38154
diff changeset
   258
    if (_cur_dirty_region == 0) {
13a14d5777b0 8155813: Fix indentation in G1RemSetScanState::clear_card_table()
tschatzl
parents: 38154
diff changeset
   259
      return;
13a14d5777b0 8155813: Fix indentation in G1RemSetScanState::clear_card_table()
tschatzl
parents: 38154
diff changeset
   260
    }
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   261
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46614
diff changeset
   262
    size_t const num_chunks = align_up(_cur_dirty_region * HeapRegion::CardsPerRegion, G1ClearCardTableTask::chunk_size()) / G1ClearCardTableTask::chunk_size();
38160
13a14d5777b0 8155813: Fix indentation in G1RemSetScanState::clear_card_table()
tschatzl
parents: 38154
diff changeset
   263
    uint const num_workers = (uint)MIN2(num_chunks, (size_t)workers->active_workers());
13a14d5777b0 8155813: Fix indentation in G1RemSetScanState::clear_card_table()
tschatzl
parents: 38154
diff changeset
   264
    size_t const chunk_length = G1ClearCardTableTask::chunk_size() / HeapRegion::CardsPerRegion;
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   265
38160
13a14d5777b0 8155813: Fix indentation in G1RemSetScanState::clear_card_table()
tschatzl
parents: 38154
diff changeset
   266
    // Iterate over the dirty cards region list.
13a14d5777b0 8155813: Fix indentation in G1RemSetScanState::clear_card_table()
tschatzl
parents: 38154
diff changeset
   267
    G1ClearCardTableTask cl(G1CollectedHeap::heap(), _dirty_region_buffer, _cur_dirty_region, chunk_length);
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   268
38160
13a14d5777b0 8155813: Fix indentation in G1RemSetScanState::clear_card_table()
tschatzl
parents: 38154
diff changeset
   269
    log_debug(gc, ergo)("Running %s using %u workers for " SIZE_FORMAT " "
13a14d5777b0 8155813: Fix indentation in G1RemSetScanState::clear_card_table()
tschatzl
parents: 38154
diff changeset
   270
                        "units of work for " SIZE_FORMAT " regions.",
13a14d5777b0 8155813: Fix indentation in G1RemSetScanState::clear_card_table()
tschatzl
parents: 38154
diff changeset
   271
                        cl.name(), num_workers, num_chunks, _cur_dirty_region);
13a14d5777b0 8155813: Fix indentation in G1RemSetScanState::clear_card_table()
tschatzl
parents: 38154
diff changeset
   272
    workers->run_task(&cl, num_workers);
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   273
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   274
#ifndef PRODUCT
38160
13a14d5777b0 8155813: Fix indentation in G1RemSetScanState::clear_card_table()
tschatzl
parents: 38154
diff changeset
   275
    G1CollectedHeap::heap()->verifier()->verify_card_table_cleanup();
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   276
#endif
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   277
  }
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   278
};
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   279
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
   280
G1RemSet::G1RemSet(G1CollectedHeap* g1h,
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   281
                   G1CardTable* ct,
38172
90f405aac699 8155524: HotCardCache shouldn't be part of ConcurrentG1Refine
kbarrett
parents: 38160
diff changeset
   282
                   G1HotCardCache* hot_card_cache) :
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 50113
diff changeset
   283
  _scan_state(new G1RemSetScanState()),
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 50113
diff changeset
   284
  _prev_period_summary(),
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
   285
  _g1h(g1h),
46614
ae1105fff9e4 8179677: Let G1Remset::_conc_refined_cards only count number of cards concurrently refined
tschatzl
parents: 46611
diff changeset
   286
  _num_conc_refined_cards(0),
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   287
  _ct(ct),
53985
0da5c17f5e43 8219747: Remove g1_ prefix to g1_remset and g1_policy members in G1CollectedHeap
tschatzl
parents: 53956
diff changeset
   288
  _g1p(_g1h->policy()),
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 50113
diff changeset
   289
  _hot_card_cache(hot_card_cache) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   290
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   291
6958
cfa71cf3564d 6971296: G1: simplify G1RemSet class hierarchy
johnc
parents: 6759
diff changeset
   292
G1RemSet::~G1RemSet() {
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   293
  if (_scan_state != NULL) {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   294
    delete _scan_state;
2142
032f4652700c 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 2009
diff changeset
   295
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   296
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   297
35210
eb1d5c68bf64 8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet
tschatzl
parents: 35198
diff changeset
   298
uint G1RemSet::num_par_rem_sets() {
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 52897
diff changeset
   299
  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
   300
}
eb1d5c68bf64 8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet
tschatzl
parents: 35198
diff changeset
   301
37414
2672ba9af0dc 8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents: 37248
diff changeset
   302
void G1RemSet::initialize(size_t capacity, uint max_regions) {
35210
eb1d5c68bf64 8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet
tschatzl
parents: 35198
diff changeset
   303
  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
   304
  _scan_state->initialize(max_regions);
35210
eb1d5c68bf64 8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet
tschatzl
parents: 35198
diff changeset
   305
}
eb1d5c68bf64 8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet
tschatzl
parents: 35198
diff changeset
   306
46575
d6fb8a7a7843 8178151: Clean up G1RemSet files
tschatzl
parents: 46572
diff changeset
   307
G1ScanRSForRegionClosure::G1ScanRSForRegionClosure(G1RemSetScanState* scan_state,
54843
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54465
diff changeset
   308
                                                   G1ScanCardClosure* scan_obj_on_card,
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   309
                                                   G1ParScanThreadState* pss,
52897
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 52716
diff changeset
   310
                                                   G1GCPhaseTimes::GCParPhases phase,
46575
d6fb8a7a7843 8178151: Clean up G1RemSet files
tschatzl
parents: 46572
diff changeset
   311
                                                   uint worker_i) :
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   312
  _g1h(G1CollectedHeap::heap()),
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   313
  _ct(_g1h->card_table()),
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   314
  _pss(pss),
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   315
  _scan_objs_on_card_cl(scan_obj_on_card),
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   316
  _scan_state(scan_state),
52897
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 52716
diff changeset
   317
  _phase(phase),
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   318
  _worker_i(worker_i),
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   319
  _opt_refs_scanned(0),
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   320
  _opt_refs_memory_used(0),
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 50113
diff changeset
   321
  _cards_scanned(0),
46571
c70b36f0730d 8178148: Log more detailed information about scan rs phase
tschatzl
parents: 46520
diff changeset
   322
  _cards_claimed(0),
c70b36f0730d 8178148: Log more detailed information about scan rs phase
tschatzl
parents: 46520
diff changeset
   323
  _cards_skipped(0),
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   324
  _rem_set_root_scan_time(),
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   325
  _rem_set_trim_partially_time(),
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   326
  _strong_code_root_scan_time(),
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   327
  _strong_code_trim_partially_time() {
34246
d2c05216f375 8142390: Move ScanRSClosure to header file
ehelin
parents: 34135
diff changeset
   328
}
d2c05216f375 8142390: Move ScanRSClosure to header file
ehelin
parents: 34135
diff changeset
   329
46635
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   330
void G1ScanRSForRegionClosure::claim_card(size_t card_index, const uint region_idx_for_card){
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   331
  _ct->set_card_claimed(card_index);
46635
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   332
  _scan_state->add_dirty_region(region_idx_for_card);
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   333
}
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   334
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   335
void G1ScanRSForRegionClosure::scan_card(MemRegion mr, uint region_idx_for_card) {
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   336
  HeapRegion* const card_region = _g1h->region_at(region_idx_for_card);
52348
21fdf8d9a8b6 8212911: Unify and micro-optimize handling of non-in-collection set references in oop closures
tschatzl
parents: 52345
diff changeset
   337
  assert(!card_region->is_young(), "Should not scan card in young region %u", region_idx_for_card);
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   338
  card_region->oops_on_card_seq_iterate_careful<true>(mr, _scan_objs_on_card_cl);
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   339
  _scan_objs_on_card_cl->trim_queue_partially();
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   340
  _cards_scanned++;
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   341
}
34246
d2c05216f375 8142390: Move ScanRSClosure to header file
ehelin
parents: 34135
diff changeset
   342
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   343
void G1ScanRSForRegionClosure::scan_opt_rem_set_roots(HeapRegion* r) {
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   344
  EventGCPhaseParallel event;
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   345
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   346
  G1OopStarChunkedList* opt_rem_set_list = _pss->oops_into_optional_region(r);
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   347
54843
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54465
diff changeset
   348
  G1ScanCardClosure scan_cl(_g1h, _pss);
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   349
  G1ScanRSForOptionalClosure cl(&scan_cl);
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   350
  _opt_refs_scanned += opt_rem_set_list->oops_do(&cl, _pss->closures()->raw_strong_oops());
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   351
  _opt_refs_memory_used += opt_rem_set_list->used_memory();
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   352
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   353
  event.commit(GCId::current(), _worker_i, G1GCPhaseTimes::phase_name(_phase));
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   354
}
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   355
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   356
void G1ScanRSForRegionClosure::scan_rem_set_roots(HeapRegion* r) {
51877
5f931e3e7a63 8196341: Add JFR events for parallel phases of G1
lkorinth
parents: 51494
diff changeset
   357
  EventGCPhaseParallel event;
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   358
  uint const region_idx = r->hrm_index();
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   359
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   360
  if (_scan_state->claim_iter(region_idx)) {
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   361
    // If we ever free the collection set concurrently, we should also
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   362
    // clear the card table concurrently therefore we won't need to
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   363
    // add regions of the collection set to the dirty cards region.
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   364
    _scan_state->add_dirty_region(region_idx);
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   365
  }
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   366
52345
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   367
  if (r->rem_set()->cardset_is_empty()) {
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   368
    return;
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   369
  }
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   370
46575
d6fb8a7a7843 8178151: Clean up G1RemSet files
tschatzl
parents: 46572
diff changeset
   371
  // We claim cards in blocks so as to reduce the contention.
d6fb8a7a7843 8178151: Clean up G1RemSet files
tschatzl
parents: 46572
diff changeset
   372
  size_t const block_size = G1RSetScanBlockSize;
d6fb8a7a7843 8178151: Clean up G1RemSet files
tschatzl
parents: 46572
diff changeset
   373
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   374
  HeapRegionRemSetIterator iter(r->rem_set());
34246
d2c05216f375 8142390: Move ScanRSClosure to header file
ehelin
parents: 34135
diff changeset
   375
  size_t card_index;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   376
46575
d6fb8a7a7843 8178151: Clean up G1RemSet files
tschatzl
parents: 46572
diff changeset
   377
  size_t claimed_card_block = _scan_state->iter_claimed_next(region_idx, block_size);
34246
d2c05216f375 8142390: Move ScanRSClosure to header file
ehelin
parents: 34135
diff changeset
   378
  for (size_t current_card = 0; iter.has_next(card_index); current_card++) {
46575
d6fb8a7a7843 8178151: Clean up G1RemSet files
tschatzl
parents: 46572
diff changeset
   379
    if (current_card >= claimed_card_block + block_size) {
d6fb8a7a7843 8178151: Clean up G1RemSet files
tschatzl
parents: 46572
diff changeset
   380
      claimed_card_block = _scan_state->iter_claimed_next(region_idx, block_size);
34246
d2c05216f375 8142390: Move ScanRSClosure to header file
ehelin
parents: 34135
diff changeset
   381
    }
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   382
    if (current_card < claimed_card_block) {
46571
c70b36f0730d 8178148: Log more detailed information about scan rs phase
tschatzl
parents: 46520
diff changeset
   383
      _cards_skipped++;
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   384
      continue;
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   385
    }
46571
c70b36f0730d 8178148: Log more detailed information about scan rs phase
tschatzl
parents: 46520
diff changeset
   386
    _cards_claimed++;
34246
d2c05216f375 8142390: Move ScanRSClosure to header file
ehelin
parents: 34135
diff changeset
   387
52345
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   388
    HeapWord* const card_start = _g1h->bot()->address_for_index_raw(card_index);
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   389
    uint const region_idx_for_card = _g1h->addr_to_region(card_start);
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   390
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   391
#ifdef ASSERT
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   392
    HeapRegion* hr = _g1h->region_at_or_null(region_idx_for_card);
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   393
    assert(hr == NULL || hr->is_in_reserved(card_start),
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   394
           "Card start " PTR_FORMAT " to scan outside of region %u", p2i(card_start), _g1h->region_at(region_idx_for_card)->hrm_index());
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   395
#endif
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   396
    HeapWord* const top = _scan_state->scan_top(region_idx_for_card);
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   397
    if (card_start >= top) {
46635
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   398
      continue;
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   399
    }
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   400
52345
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   401
    // If the card is dirty, then G1 will scan it during Update RS.
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   402
    if (_ct->is_card_claimed(card_index) || _ct->is_card_dirty(card_index)) {
46635
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   403
      continue;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   404
    }
46635
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   405
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   406
    // We claim lazily (so races are possible but they're benign), which reduces the
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   407
    // number of duplicate scans (the rsets of the regions in the cset can intersect).
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   408
    // Claim the card after checking bounds above: the remembered set may contain
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   409
    // random cards into current survivor, and we would then have an incorrectly
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   410
    // claimed card in survivor space. Card table clear does not reset the card table
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   411
    // of survivor space regions.
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   412
    claim_card(card_index, region_idx_for_card);
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   413
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   414
    MemRegion const mr(card_start, MIN2(card_start + BOTConstants::N_words, top));
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   415
ef7cac5de811 8179679: Rearrange filters before card scanning
tschatzl
parents: 46625
diff changeset
   416
    scan_card(mr, region_idx_for_card);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   417
  }
52897
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 52716
diff changeset
   418
  event.commit(GCId::current(), _worker_i, G1GCPhaseTimes::phase_name(_phase));
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   419
}
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   420
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   421
void G1ScanRSForRegionClosure::scan_strong_code_roots(HeapRegion* r) {
51877
5f931e3e7a63 8196341: Add JFR events for parallel phases of G1
lkorinth
parents: 51494
diff changeset
   422
  EventGCPhaseParallel event;
53820
4fb7f7e3e05b 8219097: Move comment about using weak code blobs closure for code root scanning to correct place
tschatzl
parents: 53747
diff changeset
   423
  // We pass a weak code blobs closure to the remembered set scanning because we want to avoid
4fb7f7e3e05b 8219097: Move comment about using weak code blobs closure for code root scanning to correct place
tschatzl
parents: 53747
diff changeset
   424
  // treating the nmethods visited to act as roots for concurrent marking.
4fb7f7e3e05b 8219097: Move comment about using weak code blobs closure for code root scanning to correct place
tschatzl
parents: 53747
diff changeset
   425
  // We only want to make sure that the oops in the nmethods are adjusted with regard to the
4fb7f7e3e05b 8219097: Move comment about using weak code blobs closure for code root scanning to correct place
tschatzl
parents: 53747
diff changeset
   426
  // objects copied by the current evacuation.
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   427
  r->strong_code_roots_do(_pss->closures()->weak_codeblobs());
51877
5f931e3e7a63 8196341: Add JFR events for parallel phases of G1
lkorinth
parents: 51494
diff changeset
   428
  event.commit(GCId::current(), _worker_i, G1GCPhaseTimes::phase_name(G1GCPhaseTimes::CodeRoots));
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   429
}
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   430
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   431
bool G1ScanRSForRegionClosure::do_heap_region(HeapRegion* r) {
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   432
  assert(r->in_collection_set(), "Region %u is not in the collection set.", r->hrm_index());
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   433
  uint const region_idx = r->hrm_index();
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   434
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   435
  // The individual references for the optional remembered set are per-worker, so we
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   436
  // always need to scan them.
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   437
  if (r->has_index_in_opt_cset()) {
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   438
    G1EvacPhaseWithTrimTimeTracker timer(_pss, _rem_set_root_scan_time, _rem_set_trim_partially_time);
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   439
    scan_opt_rem_set_roots(r);
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   440
  }
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   441
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   442
  // Do an early out if we know we are complete.
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   443
  if (_scan_state->iter_is_complete(region_idx)) {
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   444
    return false;
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   445
  }
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   446
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   447
  {
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   448
    G1EvacPhaseWithTrimTimeTracker timer(_pss, _rem_set_root_scan_time, _rem_set_trim_partially_time);
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   449
    scan_rem_set_roots(r);
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   450
  }
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   451
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   452
  if (_scan_state->set_iter_complete(region_idx)) {
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   453
    G1EvacPhaseWithTrimTimeTracker timer(_pss, _strong_code_root_scan_time, _strong_code_trim_partially_time);
34246
d2c05216f375 8142390: Move ScanRSClosure to header file
ehelin
parents: 34135
diff changeset
   454
    // Scan the strong code root list attached to the current region
d2c05216f375 8142390: Move ScanRSClosure to header file
ehelin
parents: 34135
diff changeset
   455
    scan_strong_code_roots(r);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   456
  }
34246
d2c05216f375 8142390: Move ScanRSClosure to header file
ehelin
parents: 34135
diff changeset
   457
  return false;
d2c05216f375 8142390: Move ScanRSClosure to header file
ehelin
parents: 34135
diff changeset
   458
}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   459
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   460
void G1RemSet::scan_rem_set(G1ParScanThreadState* pss,
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   461
                            uint worker_i,
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   462
                            G1GCPhaseTimes::GCParPhases scan_phase,
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   463
                            G1GCPhaseTimes::GCParPhases objcopy_phase,
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   464
                            G1GCPhaseTimes::GCParPhases coderoots_phase) {
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   465
  assert(pss->trim_ticks().value() == 0, "Queues must have been trimmed before entering.");
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   466
54843
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54465
diff changeset
   467
  G1ScanCardClosure scan_cl(_g1h, pss);
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   468
  G1ScanRSForRegionClosure cl(_scan_state, &scan_cl, pss, scan_phase, worker_i);
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   469
  _g1h->collection_set_iterate_increment_from(&cl, worker_i);
10670
4ea0e7d2ffbc 6484982: G1: process references during evacuation pauses
johnc
parents: 10000
diff changeset
   470
46571
c70b36f0730d 8178148: Log more detailed information about scan rs phase
tschatzl
parents: 46520
diff changeset
   471
  G1GCPhaseTimes* p = _g1p->phase_times();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   472
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   473
  p->record_or_add_time_secs(objcopy_phase, worker_i, cl.rem_set_trim_partially_time().seconds());
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   474
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   475
  p->record_or_add_time_secs(scan_phase, worker_i, cl.rem_set_root_scan_time().seconds());
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   476
  p->record_or_add_thread_work_item(scan_phase, worker_i, cl.cards_scanned(), G1GCPhaseTimes::ScanRSScannedCards);
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   477
  p->record_or_add_thread_work_item(scan_phase, worker_i, cl.cards_claimed(), G1GCPhaseTimes::ScanRSClaimedCards);
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   478
  p->record_or_add_thread_work_item(scan_phase, worker_i, cl.cards_skipped(), G1GCPhaseTimes::ScanRSSkippedCards);
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   479
  // At this time we only record some metrics for the optional remembered set.
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   480
  if (scan_phase == G1GCPhaseTimes::OptScanRS) {
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   481
    p->record_or_add_thread_work_item(scan_phase, worker_i, cl.opt_refs_scanned(), G1GCPhaseTimes::ScanRSScannedOptRefs);
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   482
    p->record_or_add_thread_work_item(scan_phase, worker_i, cl.opt_refs_memory_used(), G1GCPhaseTimes::ScanRSUsedMemory);
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   483
  }
32737
f02118695c2f 8135154: Move cards scanned and surviving young words aggregation to G1ParScanThreadStateSet
mgerdin
parents: 32617
diff changeset
   484
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   485
  p->record_or_add_time_secs(coderoots_phase, worker_i, cl.strong_code_root_scan_time().seconds());
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 54255
diff changeset
   486
  p->add_time_secs(objcopy_phase, worker_i, cl.strong_code_root_trim_partially_time().seconds());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   487
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   488
46670
55a3c36b64b2 8183539: Remove G1RemSet::_into_cset_dirty_card_queue_set
ehelin
parents: 46653
diff changeset
   489
// Closure used for updating rem sets. Only called during an evacuation pause.
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 52897
diff changeset
   490
class G1RefineCardClosure: public G1CardTableEntryClosure {
6247
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   491
  G1RemSet* _g1rs;
54843
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54465
diff changeset
   492
  G1ScanCardClosure* _update_rs_cl;
46778
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   493
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   494
  size_t _cards_scanned;
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   495
  size_t _cards_skipped;
6247
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   496
public:
54843
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54465
diff changeset
   497
  G1RefineCardClosure(G1CollectedHeap* g1h, G1ScanCardClosure* update_rs_cl) :
53985
0da5c17f5e43 8219747: Remove g1_ prefix to g1_remset and g1_policy members in G1CollectedHeap
tschatzl
parents: 53956
diff changeset
   498
    _g1rs(g1h->rem_set()), _update_rs_cl(update_rs_cl), _cards_scanned(0), _cards_skipped(0)
6247
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   499
  {}
33204
b8a3901ac5b3 8069330: Adjustment of concurrent refinement thresholds does not take hot card cache into account
tschatzl
parents: 33105
diff changeset
   500
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53986
diff changeset
   501
  bool do_card_ptr(CardValue* card_ptr, uint worker_i) {
6247
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   502
    // The only time we care about recording cards that
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   503
    // contain references that point into the collection set
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   504
    // is during RSet updating within an evacuation pause.
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   505
    // In this case worker_i should be the id of a GC worker thread.
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   506
    assert(SafepointSynchronize::is_at_safepoint(), "not during an evacuation pause");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   507
46778
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   508
    bool card_scanned = _g1rs->refine_card_during_gc(card_ptr, _update_rs_cl);
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   509
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   510
    if (card_scanned) {
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   511
      _update_rs_cl->trim_queue_partially();
46778
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   512
      _cards_scanned++;
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   513
    } else {
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   514
      _cards_skipped++;
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   515
    }
6247
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   516
    return true;
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   517
  }
46778
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   518
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   519
  size_t cards_scanned() const { return _cards_scanned; }
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   520
  size_t cards_skipped() const { return _cards_skipped; }
6247
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   521
};
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   522
46670
55a3c36b64b2 8183539: Remove G1RemSet::_into_cset_dirty_card_queue_set
ehelin
parents: 46653
diff changeset
   523
void G1RemSet::update_rem_set(G1ParScanThreadState* pss, uint worker_i) {
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   524
  G1GCPhaseTimes* p = _g1p->phase_times();
10670
4ea0e7d2ffbc 6484982: G1: process references during evacuation pauses
johnc
parents: 10000
diff changeset
   525
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   526
  // Apply closure to log entries in the HCC.
38172
90f405aac699 8155524: HotCardCache shouldn't be part of ConcurrentG1Refine
kbarrett
parents: 38160
diff changeset
   527
  if (G1HotCardCache::default_use_cache()) {
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   528
    G1EvacPhaseTimesTracker x(p, pss, G1GCPhaseTimes::ScanHCC, worker_i);
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   529
54843
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54465
diff changeset
   530
    G1ScanCardClosure scan_hcc_cl(_g1h, pss);
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   531
    G1RefineCardClosure refine_card_cl(_g1h, &scan_hcc_cl);
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
   532
    _g1h->iterate_hcc_closure(&refine_card_cl, worker_i);
33204
b8a3901ac5b3 8069330: Adjustment of concurrent refinement thresholds does not take hot card cache into account
tschatzl
parents: 33105
diff changeset
   533
  }
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   534
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   535
  // Now apply the closure to all remaining log entries.
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   536
  {
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   537
    G1EvacPhaseTimesTracker x(p, pss, G1GCPhaseTimes::UpdateRS, worker_i);
46778
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   538
54843
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54465
diff changeset
   539
    G1ScanCardClosure update_rs_cl(_g1h, pss);
49911
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   540
    G1RefineCardClosure refine_card_cl(_g1h, &update_rs_cl);
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   541
    _g1h->iterate_dirty_card_closure(&refine_card_cl, worker_i);
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   542
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   543
    p->record_thread_work_item(G1GCPhaseTimes::UpdateRS, worker_i, refine_card_cl.cards_scanned(), G1GCPhaseTimes::UpdateRSScannedCards);
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   544
    p->record_thread_work_item(G1GCPhaseTimes::UpdateRS, worker_i, refine_card_cl.cards_skipped(), G1GCPhaseTimes::UpdateRSSkippedCards);
358be4680d12 6672778: G1 should trim task queues more aggressively during evacuation pauses
tschatzl
parents: 49806
diff changeset
   545
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   546
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   547
54844
571732021d59 8223018: Rename G1RemSet::*oops_into_collection_set_do methods
tschatzl
parents: 54843
diff changeset
   548
void G1RemSet::prepare_for_scan_rem_set() {
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   549
  G1BarrierSet::dirty_card_queue_set().concatenate_logs();
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   550
  _scan_state->reset();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   551
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   552
54844
571732021d59 8223018: Rename G1RemSet::*oops_into_collection_set_do methods
tschatzl
parents: 54843
diff changeset
   553
void G1RemSet::cleanup_after_scan_rem_set() {
53986
9ad20fd52b19 8219748: Add and use getter for the timing object in G1
tschatzl
parents: 53985
diff changeset
   554
  G1GCPhaseTimes* phase_times = _g1h->phase_times();
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   555
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   556
  // Set all cards back to clean.
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   557
  double start = os::elapsedTime();
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
   558
  _scan_state->clear_card_table(_g1h->workers());
38154
4c30333c304e 8153507: Improve Card Table Clear Task
tschatzl
parents: 37988
diff changeset
   559
  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
   560
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   561
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53986
diff changeset
   562
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
   563
#ifdef ASSERT
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
   564
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
   565
  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
   566
         "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
   567
         p2i(card_ptr),
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   568
         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
   569
         p2i(ct->addr_for(card_ptr)),
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
   570
         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
   571
#endif
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   572
}
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   573
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53986
diff changeset
   574
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
   575
                                        uint worker_i) {
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
   576
  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
   577
52345
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   578
  // Construct the region representing the card.
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   579
  HeapWord* start = _ct->addr_for(card_ptr);
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   580
  // And find the region containing it.
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   581
  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
   582
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   583
  // 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
   584
  if (r == NULL) {
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   585
    return;
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   586
  }
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   587
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   588
  check_card_ptr(card_ptr, _ct);
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37985
diff changeset
   589
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents: 17108
diff changeset
   590
  // 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
   591
  if (*card_ptr != G1CardTable::dirty_card_val()) {
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   592
    return;
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   593
  }
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   594
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   595
  // 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
   596
  // ignore the card.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   597
  //
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   598
  // 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
   599
  // 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
   600
  // filter them out.  However, that marking is performed
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   601
  // 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
   602
  // 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
   603
  //
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   604
  // 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
   605
  // 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
   606
  // 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
   607
  // 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
   608
  // 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
   609
  // 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
   610
  //
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   611
  // 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
   612
  // 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
   613
  // 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
   614
  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
   615
    return;
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   616
  }
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   617
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   618
  // 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
   619
  //   * pointer to the current card
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   620
  //     (implying that the current card is not 'hot'),
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   621
  //   * null
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   622
  //     (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
   623
  //     which had some headroom),
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   624
  //   * 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
   625
  //
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   626
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   627
  if (_hot_card_cache->use_cache()) {
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   628
    assert(!SafepointSynchronize::is_at_safepoint(), "sanity");
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   629
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53986
diff changeset
   630
    const CardValue* orig_card_ptr = card_ptr;
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   631
    card_ptr = _hot_card_cache->insert(card_ptr);
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   632
    if (card_ptr == NULL) {
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   633
      // There was no eviction. Nothing to do.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   634
      return;
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   635
    } else if (card_ptr != orig_card_ptr) {
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   636
      // 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
   637
      start = _ct->addr_for(card_ptr);
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
   638
      r = _g1h->heap_region_containing(start);
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   639
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   640
      // 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
   641
      // 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
   642
      // 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
   643
      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
   644
        return;
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   645
      }
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   646
    } // Else we still have the original card.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   647
  }
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   648
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   649
  // 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
   650
  // 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
   651
  // (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
   652
  // beyond the end of allocation.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   653
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   654
  // 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
   655
  // 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
   656
  // 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
   657
  // 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
   658
  // 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
   659
  // 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
   660
  // we see the up-to-date top here.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   661
  HeapWord* scan_limit = r->top();
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   662
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   663
  if (scan_limit <= start) {
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   664
    // 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
   665
    return;
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   666
  }
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   667
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   668
  // 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
   669
  // 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
   670
  // as iteration failure.
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53986
diff changeset
   671
  *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
   672
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   673
  // 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
   674
  // 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
   675
  // 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
   676
  // 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
   677
  // 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
   678
  // both set, in any order, to proceed.
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   679
  OrderAccess::fence();
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   680
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   681
  // 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
   682
  // a card beyond the heap.
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   683
  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
   684
  MemRegion dirty_region(start, MIN2(scan_limit, end));
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   685
  assert(!dirty_region.is_empty(), "sanity");
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   686
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
   687
  G1ConcurrentRefineOopClosure conc_refine_cl(_g1h, worker_i);
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   688
  if (r->oops_on_card_seq_iterate_careful<false>(dirty_region, &conc_refine_cl)) {
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   689
    _num_conc_refined_cards++; // Unsynchronized update, only used for logging.
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   690
    return;
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   691
  }
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   692
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   693
  // If unable to process the card then we encountered an unparsable
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   694
  // part of the heap (e.g. a partially allocated object, so only
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   695
  // temporarily a problem) while processing a stale card.  Despite
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   696
  // 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
   697
  // already marked the card cleaned, so taken responsibility for
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   698
  // ensuring the card gets scanned.
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   699
  //
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   700
  // However, the card might have gotten re-dirtied and re-enqueued
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   701
  // while we worked.  (In fact, it's pretty likely.)
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   702
  if (*card_ptr == G1CardTable::dirty_card_val()) {
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   703
    return;
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   704
  }
54255
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   705
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   706
  // 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
   707
  // the thread-local queue, because that might be the queue that is
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   708
  // being processed by us; we could be a Java thread conscripted to
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   709
  // perform refinement on our queue's current buffer.
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   710
  *card_ptr = G1CardTable::dirty_card_val();
c81fbf340ceb 8220240: Refactor shared dirty card queue
kbarrett
parents: 54111
diff changeset
   711
  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
   712
}
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   713
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53986
diff changeset
   714
bool G1RemSet::refine_card_during_gc(CardValue* card_ptr,
54843
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54465
diff changeset
   715
                                     G1ScanCardClosure* update_rs_cl) {
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
   716
  assert(_g1h->is_gc_active(), "Only call during GC");
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   717
52345
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   718
  // Construct the region representing the card.
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   719
  HeapWord* card_start = _ct->addr_for(card_ptr);
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   720
  // And find the region containing it.
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   721
  uint const card_region_idx = _g1h->addr_to_region(card_start);
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   722
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   723
  HeapWord* scan_limit = _scan_state->scan_top(card_region_idx);
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   724
  if (scan_limit == NULL) {
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   725
    // This is a card into an uncommitted region. We need to bail out early as we
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   726
    // should not access the corresponding card table entry.
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   727
    return false;
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   728
  }
418fb8bb5151 8071913: Filter out entries to free/uncommitted regions during iteration
tschatzl
parents: 51877
diff changeset
   729
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   730
  check_card_ptr(card_ptr, _ct);
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   731
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   732
  // If the card is no longer dirty, nothing to do. This covers cards that were already
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   733
  // scanned as parts of the remembered sets.
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   734
  if (*card_ptr != G1CardTable::dirty_card_val()) {
46778
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   735
    return false;
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents: 17108
diff changeset
   736
  }
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents: 17108
diff changeset
   737
46676
dff06ff9effe 8183538: UpdateRS phase should claim cards
tschatzl
parents: 46670
diff changeset
   738
  // We claim lazily (so races are possible but they're benign), which reduces the
dff06ff9effe 8183538: UpdateRS phase should claim cards
tschatzl
parents: 46670
diff changeset
   739
  // number of potential duplicate scans (multiple threads may enqueue the same card twice).
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   740
  *card_ptr = G1CardTable::clean_card_val() | G1CardTable::claimed_card_val();
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents: 17108
diff changeset
   741
46676
dff06ff9effe 8183538: UpdateRS phase should claim cards
tschatzl
parents: 46670
diff changeset
   742
  _scan_state->add_dirty_region(card_region_idx);
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   743
  if (scan_limit <= card_start) {
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   744
    // If the card starts above the area in the region containing objects to scan, skip it.
46778
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   745
    return false;
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents: 17108
diff changeset
   746
  }
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents: 17108
diff changeset
   747
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13516
diff changeset
   748
  // Don't use addr_for(card_ptr + 1) which can ask for
42589
037b433e8069 8166811: Missing memory fences between memory allocation and refinement
kbarrett
parents: 42588
diff changeset
   749
  // a card beyond the heap.
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48969
diff changeset
   750
  HeapWord* card_end = card_start + G1CardTable::card_size_in_words;
46520
de5cb3eed39b 8177044: Remove _scan_top from HeapRegion
tschatzl
parents: 46519
diff changeset
   751
  MemRegion dirty_region(card_start, MIN2(scan_limit, card_end));
42589
037b433e8069 8166811: Missing memory fences between memory allocation and refinement
kbarrett
parents: 42588
diff changeset
   752
  assert(!dirty_region.is_empty(), "sanity");
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3262
diff changeset
   753
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49803
diff changeset
   754
  HeapRegion* const card_region = _g1h->region_at(card_region_idx);
52348
21fdf8d9a8b6 8212911: Unify and micro-optimize handling of non-in-collection set references in oop closures
tschatzl
parents: 52345
diff changeset
   755
  assert(!card_region->is_young(), "Should not scan card in young region %u", card_region_idx);
46676
dff06ff9effe 8183538: UpdateRS phase should claim cards
tschatzl
parents: 46670
diff changeset
   756
  bool card_processed = card_region->oops_on_card_seq_iterate_careful<true>(dirty_region, update_rs_cl);
46519
40c9c132f961 8177707: Specialize G1RemSet::refine_card for concurrent/during safepoint refinement
tschatzl
parents: 46518
diff changeset
   757
  assert(card_processed, "must be");
46778
f504c6f2eea5 8183121: Add information about scanned and skipped cards during UpdateRS
tschatzl
parents: 46701
diff changeset
   758
  return true;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   759
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   760
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
   761
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
   762
  if ((G1SummarizeRSetStatsPeriod > 0) && log_is_enabled(Trace, gc, remset) &&
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
   763
      (period_count % G1SummarizeRSetStatsPeriod == 0)) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
   764
46652
ab8716d193bb 8183226: Remembered set summarization accesses not fully initialized java thread DCQS
tschatzl
parents: 46635
diff changeset
   765
    G1RemSetSummary current(this);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
   766
    _prev_period_summary.subtract_from(&current);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   767
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 36374
diff changeset
   768
    Log(gc, remset) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
   769
    log.trace("%s", header);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
   770
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46676
diff changeset
   771
    LogStream ls(log.trace());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46676
diff changeset
   772
    _prev_period_summary.print_on(&ls);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
   773
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
   774
    _prev_period_summary.set(&current);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
   775
  }
17854
d65bc1546091 8013895: G1: G1SummarizeRSetStats output on Linux needs improvemen
tschatzl
parents: 17327
diff changeset
   776
}
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   777
6958
cfa71cf3564d 6971296: G1: simplify G1RemSet class hierarchy
johnc
parents: 6759
diff changeset
   778
void G1RemSet::print_summary_info() {
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 36374
diff changeset
   779
  Log(gc, remset, exit) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
   780
  if (log.is_trace()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
   781
    log.trace(" Cumulative RS summary");
46653
d72083d17b19 8183128: Update RefineCardTableEntryClosure
tschatzl
parents: 46652
diff changeset
   782
    G1RemSetSummary current(this);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34246
diff changeset
   783
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46676
diff changeset
   784
    LogStream ls(log.trace());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46676
diff changeset
   785
    current.print_on(&ls);
17854
d65bc1546091 8013895: G1: G1SummarizeRSetStats output on Linux needs improvemen
tschatzl
parents: 17327
diff changeset
   786
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   787
}
6247
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   788
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   789
class G1RebuildRemSetTask: public AbstractGangTask {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   790
  // Aggregate the counting data that was constructed concurrently
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   791
  // with marking.
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   792
  class G1RebuildRemSetHeapRegionClosure : public HeapRegionClosure {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   793
    G1ConcurrentMark* _cm;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   794
    G1RebuildRemSetClosure _update_cl;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   795
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   796
    // 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
   797
    // 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
   798
    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
   799
      size_t const obj_size = obj->size();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   800
      // All non-objArrays and objArrays completely within the mr
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   801
      // can be scanned without passing the mr.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   802
      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
   803
        obj->oop_iterate(&_update_cl);
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   804
        return obj_size;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   805
      }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   806
      // 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
   807
      // area within the MemRegion.
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   808
      obj->oop_iterate(&_update_cl, mr);
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   809
      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
   810
    }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   811
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   812
    // 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
   813
    // 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
   814
    // 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
   815
    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
   816
      return bitmap->is_marked(humongous_obj) || (tars > tams);
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   817
    }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   818
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   819
    // Iterator over the live objects within the given MemRegion.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   820
    class LiveObjIterator : public StackObj {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   821
      const G1CMBitMap* const _bitmap;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   822
      const HeapWord* _tams;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   823
      const MemRegion _mr;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   824
      HeapWord* _current;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   825
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   826
      bool is_below_tams() const {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   827
        return _current < _tams;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   828
      }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   829
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   830
      bool is_live(HeapWord* obj) const {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   831
        return !is_below_tams() || _bitmap->is_marked(obj);
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   832
      }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   833
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   834
      HeapWord* bitmap_limit() const {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   835
        return MIN2(const_cast<HeapWord*>(_tams), _mr.end());
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   836
      }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   837
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   838
      void move_if_below_tams() {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   839
        if (is_below_tams() && has_next()) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   840
          _current = _bitmap->get_next_marked_addr(_current, bitmap_limit());
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   841
        }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   842
      }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   843
    public:
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   844
      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
   845
          _bitmap(bitmap),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   846
          _tams(tams),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   847
          _mr(mr),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   848
          _current(first_oop_into_mr) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   849
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   850
        assert(_current <= _mr.start(),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   851
               "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
   852
               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
   853
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   854
        // 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
   855
        if (is_live(_current)) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   856
          // 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
   857
          if (_current < mr.start() && !oop(_current)->is_objArray()) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   858
            _current += oop(_current)->size();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   859
            // 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
   860
            // live one if needed.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   861
            move_if_below_tams();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   862
          }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   863
        } else {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   864
          // 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
   865
          // immediately.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   866
          _current = _bitmap->get_next_marked_addr(_current, bitmap_limit());
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   867
          assert(_current == _mr.end() || is_live(_current),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   868
                 "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
   869
                 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
   870
        }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   871
      }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   872
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   873
      void move_to_next() {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   874
        _current += next()->size();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   875
        move_if_below_tams();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   876
      }
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   877
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   878
      oop next() const {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   879
        oop result = oop(_current);
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   880
        assert(is_live(_current),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   881
               "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
   882
               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
   883
        return result;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   884
      }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   885
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   886
      bool has_next() const {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   887
        return _current < _mr.end();
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   888
      }
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   889
    };
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   890
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   891
    // 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
   892
    // 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
   893
    // 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
   894
    // 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
   895
    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
   896
                                     HeapWord* const top_at_mark_start,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   897
                                     HeapWord* const top_at_rebuild_start,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   898
                                     HeapRegion* hr,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   899
                                     MemRegion mr) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   900
      size_t marked_words = 0;
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   901
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   902
      if (hr->is_humongous()) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   903
        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
   904
        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
   905
          // 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
   906
          // 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
   907
          // 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
   908
          // 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
   909
          // 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
   910
          // 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
   911
          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
   912
                 "More than one object in the humongous region?");
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   913
          humongous_obj->oop_iterate(&_update_cl, mr);
49803
14518ac8df87 8178105: Switch mark bitmaps during Remark
tschatzl
parents: 49751
diff changeset
   914
          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
   915
        } else {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   916
          return 0;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   917
        }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   918
      }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   919
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   920
      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
   921
        oop obj = it.next();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   922
        size_t scanned_size = scan_for_references(obj, mr);
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   923
        if ((HeapWord*)obj < top_at_mark_start) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   924
          marked_words += scanned_size;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   925
        }
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   926
      }
37414
2672ba9af0dc 8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents: 37248
diff changeset
   927
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   928
      return marked_words * HeapWordSize;
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   929
    }
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   930
public:
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   931
  G1RebuildRemSetHeapRegionClosure(G1CollectedHeap* g1h,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   932
                                   G1ConcurrentMark* cm,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   933
                                   uint worker_id) :
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   934
    HeapRegionClosure(),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   935
    _cm(cm),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   936
    _update_cl(g1h, worker_id) { }
37414
2672ba9af0dc 8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents: 37248
diff changeset
   937
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   938
    bool do_heap_region(HeapRegion* hr) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   939
      if (_cm->has_aborted()) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   940
        return true;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   941
      }
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   942
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
   943
      uint const region_idx = hr->hrm_index();
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   944
      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
   945
      assert(top_at_rebuild_start_check == NULL ||
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   946
             top_at_rebuild_start_check > hr->bottom(),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   947
             "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
   948
             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
   949
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   950
      size_t total_marked_bytes = 0;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   951
      size_t const chunk_size_in_words = G1RebuildRemSetChunkSize / HeapWordSize;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   952
49803
14518ac8df87 8178105: Switch mark bitmaps during Remark
tschatzl
parents: 49751
diff changeset
   953
      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
   954
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   955
      HeapWord* cur = hr->bottom();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   956
      while (cur < hr->end()) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   957
        // 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
   958
        // TARS changed due to e.g. eager reclaim.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   959
        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
   960
        if (top_at_rebuild_start == NULL) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   961
          return false;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   962
        }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   963
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   964
        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
   965
        if (next_chunk.is_empty()) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   966
          break;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   967
        }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   968
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   969
        const Ticks start = Ticks::now();
49803
14518ac8df87 8178105: Switch mark bitmaps during Remark
tschatzl
parents: 49751
diff changeset
   970
        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
   971
                                                        top_at_mark_start,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   972
                                                        top_at_rebuild_start,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   973
                                                        hr,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   974
                                                        next_chunk);
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   975
        Tickspan time = Ticks::now() - start;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   976
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   977
        log_trace(gc, remset, tracking)("Rebuilt region %u "
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   978
                                        "live " SIZE_FORMAT " "
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   979
                                        "time %.3fms "
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   980
                                        "marked bytes " SIZE_FORMAT " "
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   981
                                        "bot " PTR_FORMAT " "
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   982
                                        "TAMS " PTR_FORMAT " "
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   983
                                        "TARS " PTR_FORMAT,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   984
                                        region_idx,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   985
                                        _cm->liveness(region_idx) * HeapWordSize,
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49911
diff changeset
   986
                                        time.seconds() * 1000.0,
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   987
                                        marked_bytes,
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   988
                                        p2i(hr->bottom()),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   989
                                        p2i(top_at_mark_start),
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   990
                                        p2i(top_at_rebuild_start));
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   991
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   992
        if (marked_bytes > 0) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   993
          total_marked_bytes += marked_bytes;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   994
        }
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   995
        cur += chunk_size_in_words;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   996
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   997
        _cm->do_yield_check();
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   998
        if (_cm->has_aborted()) {
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
   999
          return true;
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1000
        }
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1001
      }
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1002
      // 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
  1003
      // 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
  1004
      // might have already been new allocations into these regions.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
  1005
      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
  1006
      assert(top_at_rebuild_start == NULL ||
14518ac8df87 8178105: Switch mark bitmaps during Remark
tschatzl
parents: 49751
diff changeset
  1007
             total_marked_bytes == hr->marked_bytes(),
14518ac8df87 8178105: Switch mark bitmaps during Remark
tschatzl
parents: 49751
diff changeset
  1008
             "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
  1009
             "(" PTR_FORMAT " " PTR_FORMAT " " PTR_FORMAT ")",
49803
14518ac8df87 8178105: Switch mark bitmaps during Remark
tschatzl
parents: 49751
diff changeset
  1010
             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
  1011
             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
  1012
       // Abort state may have changed after the yield check.
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1013
      return _cm->has_aborted();
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1014
    }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1015
  };
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1016
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1017
  HeapRegionClaimer _hr_claimer;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1018
  G1ConcurrentMark* _cm;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1019
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1020
  uint _worker_id_offset;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1021
public:
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1022
  G1RebuildRemSetTask(G1ConcurrentMark* cm,
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1023
                      uint n_workers,
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1024
                      uint worker_id_offset) :
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1025
      AbstractGangTask("G1 Rebuild Remembered Set"),
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 50113
diff changeset
  1026
      _hr_claimer(n_workers),
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1027
      _cm(cm),
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1028
      _worker_id_offset(worker_id_offset) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1029
  }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1030
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1031
  void work(uint worker_id) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1032
    SuspendibleThreadSetJoiner sts_join;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1033
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1034
    G1CollectedHeap* g1h = G1CollectedHeap::heap();
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1035
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1036
    G1RebuildRemSetHeapRegionClosure cl(g1h, _cm, _worker_id_offset + worker_id);
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1037
    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
  1038
  }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1039
};
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1040
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1041
void G1RemSet::rebuild_rem_set(G1ConcurrentMark* cm,
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1042
                               WorkGang* workers,
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1043
                               uint worker_id_offset) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1044
  uint num_workers = workers->active_workers();
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1045
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1046
  G1RebuildRemSetTask cl(cm,
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1047
                         num_workers,
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1048
                         worker_id_offset);
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49347
diff changeset
  1049
  workers->run_task(&cl, num_workers);
37414
2672ba9af0dc 8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents: 37248
diff changeset
  1050
}