hotspot/src/share/vm/gc/g1/g1HotCardCache.cpp
author tschatzl
Wed, 25 Nov 2015 14:43:29 +0100
changeset 34300 6075c1e0e913
parent 33204 b8a3901ac5b3
child 36374 613f27cc37b9
permissions -rw-r--r--
8136679: JFR event for adaptive IHOP Reviewed-by: tbenson, mgerdin, sangheki, ehelin
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
/*
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
     2
 * Copyright (c) 2013, 2015, 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"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29203
diff changeset
    26
#include "gc/g1/dirtyCardQueue.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29203
diff changeset
    27
#include "gc/g1/g1CollectedHeap.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29203
diff changeset
    28
#include "gc/g1/g1HotCardCache.hpp"
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 23858
diff changeset
    29
#include "runtime/atomic.inline.hpp"
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    30
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    31
G1HotCardCache::G1HotCardCache(G1CollectedHeap *g1h):
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    32
  _g1h(g1h), _hot_cache(NULL), _use_cache(false), _card_counts(g1h) {}
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    33
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25351
diff changeset
    34
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
    35
  if (default_use_cache()) {
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    36
    _use_cache = true;
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    37
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    38
    _hot_cache_size = (size_t)1 << G1ConcRSLogCacheSize;
29203
5024f7b3322c 8058446: G1 Hot card cache should use ArrayAllocator to allocate the cache array
tschatzl
parents: 28831
diff changeset
    39
    _hot_cache = _hot_cache_memory.allocate(_hot_cache_size);
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    40
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    41
    reset_hot_cache_internal();
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    42
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    43
    // 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
    44
    _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
    45
    _hot_cache_par_claimed_idx = 0;
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    46
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25351
diff changeset
    47
    _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
    48
  }
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    49
}
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    50
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    51
G1HotCardCache::~G1HotCardCache() {
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    52
  if (default_use_cache()) {
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    53
    assert(_hot_cache != NULL, "Logic");
29203
5024f7b3322c 8058446: G1 Hot card cache should use ArrayAllocator to allocate the cache array
tschatzl
parents: 28831
diff changeset
    54
    _hot_cache_memory.free();
5024f7b3322c 8058446: G1 Hot card cache should use ArrayAllocator to allocate the cache array
tschatzl
parents: 28831
diff changeset
    55
    _hot_cache = NULL;
17327
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
}
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    58
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    59
jbyte* G1HotCardCache::insert(jbyte* card_ptr) {
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    60
  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
    61
  if (!_card_counts.is_hot(count)) {
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    62
    // 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
    63
    // return it for immediate refining.
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    64
    return card_ptr;
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    65
  }
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    66
  // Otherwise, the card is hot.
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    67
  size_t index = Atomic::add(1, &_hot_cache_idx) - 1;
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    68
  size_t masked_index = index & (_hot_cache_size - 1);
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    69
  jbyte* 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
    70
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    71
  // 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
    72
  // 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
    73
  // 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
    74
  // 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
    75
  // 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
    76
  // this ever happens.
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    77
  jbyte* previous_ptr = (jbyte*)Atomic::cmpxchg_ptr(card_ptr,
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    78
                                                    &_hot_cache[masked_index],
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    79
                                                    current_ptr);
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    80
  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
    81
}
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    82
33204
b8a3901ac5b3 8069330: Adjustment of concurrent refinement thresholds does not take hot card cache into account
tschatzl
parents: 33105
diff changeset
    83
void G1HotCardCache::drain(CardTableEntryClosure* cl, uint worker_i) {
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    84
  if (!default_use_cache()) {
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    85
    assert(_hot_cache == NULL, "Logic");
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    86
    return;
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    87
  }
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    88
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    89
  assert(_hot_cache != NULL, "Logic");
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
    90
  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
    91
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    92
  while (_hot_cache_par_claimed_idx < _hot_cache_size) {
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    93
    size_t end_idx = Atomic::add(_hot_cache_par_chunk_size,
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    94
                                 &_hot_cache_par_claimed_idx);
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    95
    size_t start_idx = end_idx - _hot_cache_par_chunk_size;
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    96
    // 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
    97
    end_idx = MIN2(end_idx, _hot_cache_size);
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    98
    for (size_t i = start_idx; i < end_idx; i++) {
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
    99
      jbyte* card_ptr = _hot_cache[i];
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
   100
      if (card_ptr != NULL) {
33204
b8a3901ac5b3 8069330: Adjustment of concurrent refinement thresholds does not take hot card cache into account
tschatzl
parents: 33105
diff changeset
   101
        bool result = cl->do_card_ptr(card_ptr, worker_i);
b8a3901ac5b3 8069330: Adjustment of concurrent refinement thresholds does not take hot card cache into account
tschatzl
parents: 33105
diff changeset
   102
        assert(result, "Closure should always return true");
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
   103
      } else {
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
   104
        break;
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   105
      }
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   106
    }
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   107
  }
28831
454224c7e3ba 8069273: Decrease Hot Card Cache Lock contention
redestad
parents: 27880
diff changeset
   108
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   109
  // 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
   110
  // 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
   111
}
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
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
   114
  _card_counts.clear_region(hr);
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   115
}
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   116
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   117
void G1HotCardCache::reset_card_counts() {
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   118
  _card_counts.clear_all();
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents:
diff changeset
   119
}