src/hotspot/share/gc/g1/g1HotCardCache.cpp
author tschatzl
Fri, 29 Nov 2019 10:20:14 +0100
changeset 59319 9ee940f1de90
parent 59252 623722a6aeb9
permissions -rw-r--r--
8227739: Merge cost predictions for scanning cards and log buffer entries Summary: Revamp the cost predictions for the changes in JDK-8200545 and JDK-8213108. Reviewed-by: sjohanss, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
     1
/*
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 51332
diff changeset
     2
 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
     4
 *
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
     8
 *
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    13
 * accompanied this code).
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    14
 *
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    18
 *
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    21
 * questions.
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    22
 *
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    23
 */
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    24
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    25
#include "precompiled.hpp"
55752
8ae33203d600 8162929: Enqueuing dirty cards into a single DCQS during GC does not scale
kbarrett
parents: 54110
diff changeset
    26
#include "gc/g1/g1CardTableEntryClosure.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29203
diff changeset
    27
#include "gc/g1/g1CollectedHeap.inline.hpp"
53747
13acc8e38a29 8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents: 51332
diff changeset
    28
#include "gc/g1/g1DirtyCardQueue.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29203
diff changeset
    29
#include "gc/g1/g1HotCardCache.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 37057
diff changeset
    30
#include "runtime/atomic.hpp"
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    31
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    32
G1HotCardCache::G1HotCardCache(G1CollectedHeap *g1h):
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 47885
diff changeset
    33
  _g1h(g1h), _use_cache(false), _card_counts(g1h),
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 47885
diff changeset
    34
  _hot_cache(NULL), _hot_cache_size(0), _hot_cache_par_chunk_size(0),
59319
9ee940f1de90 8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents: 59252
diff changeset
    35
  _hot_cache_idx(0), _hot_cache_par_claimed_idx(0), _cache_wrapped_around(false)
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 47885
diff changeset
    36
{}
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    37
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25351
diff changeset
    38
void G1HotCardCache::initialize(G1RegionToSpaceMapper* card_counts_storage) {
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    39
  if (default_use_cache()) {
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    40
    _use_cache = true;
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    41
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    42
    _hot_cache_size = (size_t)1 << G1ConcRSLogCacheSize;
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53747
diff changeset
    43
    _hot_cache = ArrayAllocator<CardValue*>::allocate(_hot_cache_size, mtGC);
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    44
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    45
    reset_hot_cache_internal();
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    46
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    47
    // For refining the cards in the hot cache in parallel
27251
7d667f91ec8d 6979279: remove special-case code for ParallelGCThreads==0
mlarsson
parents: 26830
diff changeset
    48
    _hot_cache_par_chunk_size = ClaimChunkSize;
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    49
    _hot_cache_par_claimed_idx = 0;
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    50
59319
9ee940f1de90 8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents: 59252
diff changeset
    51
    _cache_wrapped_around = false;
9ee940f1de90 8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents: 59252
diff changeset
    52
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25351
diff changeset
    53
    _card_counts.initialize(card_counts_storage);
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    54
  }
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    55
}
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    56
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    57
G1HotCardCache::~G1HotCardCache() {
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    58
  if (default_use_cache()) {
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    59
    assert(_hot_cache != NULL, "Logic");
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53747
diff changeset
    60
    ArrayAllocator<CardValue*>::free(_hot_cache, _hot_cache_size);
29203
5024f7b3322c 8058446: G1 Hot card cache should use ArrayAllocator to allocate the cache array
tschatzl
parents: 28831
diff changeset
    61
    _hot_cache = NULL;
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    62
  }
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    63
}
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    64
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53747
diff changeset
    65
CardTable::CardValue* G1HotCardCache::insert(CardValue* card_ptr) {
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    66
  uint count = _card_counts.add_card_count(card_ptr);
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    67
  if (!_card_counts.is_hot(count)) {
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    68
    // The card is not hot so do not store it in the cache;
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    69
    // return it for immediate refining.
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    70
    return card_ptr;
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    71
  }
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    72
  // Otherwise, the card is hot.
59249
29b0d0b61615 8234737: Harmonize parameter order in Atomic - add
stefank
parents: 58264
diff changeset
    73
  size_t index = Atomic::add(&_hot_cache_idx, 1u) - 1;
59319
9ee940f1de90 8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents: 59252
diff changeset
    74
  if (index == _hot_cache_size) {
9ee940f1de90 8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents: 59252
diff changeset
    75
    // Can use relaxed store because all racing threads are writing the same
9ee940f1de90 8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents: 59252
diff changeset
    76
    // value and there aren't any concurrent readers.
9ee940f1de90 8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents: 59252
diff changeset
    77
    Atomic::store(&_cache_wrapped_around, true);
9ee940f1de90 8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents: 59252
diff changeset
    78
  }
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    79
  size_t masked_index = index & (_hot_cache_size - 1);
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53747
diff changeset
    80
  CardValue* current_ptr = _hot_cache[masked_index];
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    81
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    82
  // Try to store the new card pointer into the cache. Compare-and-swap to guard
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    83
  // against the unlikely event of a race resulting in another card pointer to
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    84
  // have already been written to the cache. In this case we will return
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    85
  // card_ptr in favor of the other option, which would be starting over. This
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    86
  // should be OK since card_ptr will likely be the older card already when/if
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    87
  // this ever happens.
59252
623722a6aeb9 8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents: 59249
diff changeset
    88
  CardValue* previous_ptr = Atomic::cmpxchg(&_hot_cache[masked_index],
623722a6aeb9 8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents: 59249
diff changeset
    89
                                            current_ptr,
623722a6aeb9 8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents: 59249
diff changeset
    90
                                            card_ptr);
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    91
  return (previous_ptr == current_ptr) ? previous_ptr : card_ptr;
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    92
}
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    93
58264
4e96939a5746 8231189: Rename worker_i parameters to worker_id
tschatzl
parents: 58033
diff changeset
    94
void G1HotCardCache::drain(G1CardTableEntryClosure* cl, uint worker_id) {
36374
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 33204
diff changeset
    95
  assert(default_use_cache(), "Drain only necessary if we use the hot card cache.");
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    96
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    97
  assert(_hot_cache != NULL, "Logic");
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    98
  assert(!use_cache(), "cache should be disabled");
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    99
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
   100
  while (_hot_cache_par_claimed_idx < _hot_cache_size) {
59249
29b0d0b61615 8234737: Harmonize parameter order in Atomic - add
stefank
parents: 58264
diff changeset
   101
    size_t end_idx = Atomic::add(&_hot_cache_par_claimed_idx,
29b0d0b61615 8234737: Harmonize parameter order in Atomic - add
stefank
parents: 58264
diff changeset
   102
                                 _hot_cache_par_chunk_size);
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
   103
    size_t start_idx = end_idx - _hot_cache_par_chunk_size;
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
   104
    // The current worker has successfully claimed the chunk [start_idx..end_idx)
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
   105
    end_idx = MIN2(end_idx, _hot_cache_size);
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
   106
    for (size_t i = start_idx; i < end_idx; i++) {
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53747
diff changeset
   107
      CardValue* card_ptr = _hot_cache[i];
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
   108
      if (card_ptr != NULL) {
58264
4e96939a5746 8231189: Rename worker_i parameters to worker_id
tschatzl
parents: 58033
diff changeset
   109
        cl->do_card_ptr(card_ptr, worker_id);
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
   110
      } else {
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
   111
        break;
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   112
      }
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   113
    }
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   114
  }
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
   115
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   116
  // The existing entries in the hot card cache, which were just refined
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   117
  // above, are discarded prior to re-enabling the cache near the end of the GC.
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   118
}
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   119
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   120
void G1HotCardCache::reset_card_counts(HeapRegion* hr) {
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   121
  _card_counts.clear_region(hr);
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   122
}