src/hotspot/share/gc/g1/g1FromCardCache.hpp
author tschatzl
Mon, 26 Mar 2018 16:51:43 +0200
changeset 49608 1852b17b0efc
parent 47216 71c04702a3d5
child 50281 bc1336220671
permissions -rw-r--r--
8196485: FromCardCache default card index can cause crashes Summary: The default value of -1 for 32 bit card indices is a regular card value at the border of 2TB heap addresses in the from card cache, so G1 may loose remembered set entries. Extend from card cache entries to 64 bits. Reviewed-by: shade, sjohanss Contributed-by: Thomas Schatzl <thomas.schatzl@oracle.com>, Jarkko Miettinen <jarkko.miettinen@relex.fi>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35199
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     1
/*
37228
25ea8814a824 8148099: Improve memory access to FromCardCache during GC
tschatzl
parents: 35210
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
35199
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     4
 *
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     8
 *
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    14
 *
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    18
 *
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    21
 * questions.
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    22
 *
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    23
 */
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    24
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_G1_G1FROMCARDCACHE_HPP
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    26
#define SHARE_VM_GC_G1_G1FROMCARDCACHE_HPP
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    27
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    28
#include "memory/allocation.hpp"
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    29
#include "utilities/ostream.hpp"
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    30
35200
7802299b31e7 8145671: Rename FromCardCache to G1FromCardCache
tschatzl
parents: 35199
diff changeset
    31
// G1FromCardCache remembers the most recently processed card on the heap on
35199
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    32
// a per-region and per-thread basis.
35200
7802299b31e7 8145671: Rename FromCardCache to G1FromCardCache
tschatzl
parents: 35199
diff changeset
    33
class G1FromCardCache : public AllStatic {
35199
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    34
 private:
37228
25ea8814a824 8148099: Improve memory access to FromCardCache during GC
tschatzl
parents: 35210
diff changeset
    35
  // Array of card indices. Indexed by heap region (rows) and thread (columns) to minimize
35199
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    36
  // thread contention.
37228
25ea8814a824 8148099: Improve memory access to FromCardCache during GC
tschatzl
parents: 35210
diff changeset
    37
  // This order minimizes the time to clear all entries for a given region during region
25ea8814a824 8148099: Improve memory access to FromCardCache during GC
tschatzl
parents: 35210
diff changeset
    38
  // freeing. I.e. a single clear of a single memory area instead of multiple separate
25ea8814a824 8148099: Improve memory access to FromCardCache during GC
tschatzl
parents: 35210
diff changeset
    39
  // accesses with a large stride per region.
49608
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 47216
diff changeset
    40
  static uintptr_t** _cache;
35199
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    41
  static uint _max_regions;
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    42
  static size_t _static_mem_size;
46669
05296a16012a 8184452: Add bounds checking for FromCardCache
tschatzl
parents: 37228
diff changeset
    43
#ifdef ASSERT
05296a16012a 8184452: Add bounds checking for FromCardCache
tschatzl
parents: 37228
diff changeset
    44
  static uint _max_workers;
05296a16012a 8184452: Add bounds checking for FromCardCache
tschatzl
parents: 37228
diff changeset
    45
05296a16012a 8184452: Add bounds checking for FromCardCache
tschatzl
parents: 37228
diff changeset
    46
  static void check_bounds(uint worker_id, uint region_idx) {
05296a16012a 8184452: Add bounds checking for FromCardCache
tschatzl
parents: 37228
diff changeset
    47
    assert(worker_id < _max_workers, "Worker_id %u is larger than maximum %u", worker_id, _max_workers);
05296a16012a 8184452: Add bounds checking for FromCardCache
tschatzl
parents: 37228
diff changeset
    48
    assert(region_idx < _max_regions, "Region_idx %u is larger than maximum %u", region_idx, _max_regions);
05296a16012a 8184452: Add bounds checking for FromCardCache
tschatzl
parents: 37228
diff changeset
    49
  }
05296a16012a 8184452: Add bounds checking for FromCardCache
tschatzl
parents: 37228
diff changeset
    50
#endif
35199
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    51
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    52
 public:
49608
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 47216
diff changeset
    53
  static const uintptr_t InvalidCard = UINTPTR_MAX;
35199
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    54
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    55
  static void clear(uint region_idx);
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    56
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    57
  // Returns true if the given card is in the cache at the given location, or
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    58
  // replaces the card at that location and returns false.
49608
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 47216
diff changeset
    59
  static bool contains_or_replace(uint worker_id, uint region_idx, uintptr_t card) {
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 47216
diff changeset
    60
    uintptr_t card_in_cache = at(worker_id, region_idx);
35199
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    61
    if (card_in_cache == card) {
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    62
      return true;
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    63
    } else {
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    64
      set(worker_id, region_idx, card);
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    65
      return false;
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    66
    }
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    67
  }
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    68
49608
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 47216
diff changeset
    69
  static uintptr_t at(uint worker_id, uint region_idx) {
46669
05296a16012a 8184452: Add bounds checking for FromCardCache
tschatzl
parents: 37228
diff changeset
    70
    DEBUG_ONLY(check_bounds(worker_id, region_idx);)
37228
25ea8814a824 8148099: Improve memory access to FromCardCache during GC
tschatzl
parents: 35210
diff changeset
    71
    return _cache[region_idx][worker_id];
35199
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    72
  }
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    73
49608
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 47216
diff changeset
    74
  static void set(uint worker_id, uint region_idx, uintptr_t val) {
46669
05296a16012a 8184452: Add bounds checking for FromCardCache
tschatzl
parents: 37228
diff changeset
    75
    DEBUG_ONLY(check_bounds(worker_id, region_idx);)
37228
25ea8814a824 8148099: Improve memory access to FromCardCache during GC
tschatzl
parents: 35210
diff changeset
    76
    _cache[region_idx][worker_id] = val;
35199
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    77
  }
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    78
35210
eb1d5c68bf64 8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet
tschatzl
parents: 35200
diff changeset
    79
  static void initialize(uint num_par_rem_sets, uint max_num_regions);
35199
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    80
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    81
  static void invalidate(uint start_idx, size_t num_regions);
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    82
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    83
  static void print(outputStream* out = tty) PRODUCT_RETURN;
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    84
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    85
  static size_t static_mem_size() {
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    86
    return _static_mem_size;
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    87
  }
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    88
};
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    89
a12e8d5aa2f7 8145667: Move FromCardCache into separate files
tschatzl
parents:
diff changeset
    90
#endif // SHARE_VM_GC_G1_G1FROMCARDCACHE_HPP