author | kbarrett |
Tue, 12 Jun 2018 18:12:59 -0400 | |
changeset 50532 | a18c60527166 |
parent 50281 | bc1336220671 |
child 53244 | 9807daeb47c4 |
permissions | -rw-r--r-- |
35199 | 1 |
/* |
50281 | 2 |
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. |
35199 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#ifndef SHARE_VM_GC_G1_G1FROMCARDCACHE_HPP |
|
26 |
#define SHARE_VM_GC_G1_G1FROMCARDCACHE_HPP |
|
27 |
||
28 |
#include "memory/allocation.hpp" |
|
29 |
#include "utilities/ostream.hpp" |
|
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 | 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 { |
50281 | 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 | 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 | 41 |
static uint _max_regions; |
42 |
static size_t _static_mem_size; |
|
46669 | 43 |
#ifdef ASSERT |
44 |
static uint _max_workers; |
|
45 |
||
46 |
static void check_bounds(uint worker_id, uint region_idx) { |
|
47 |
assert(worker_id < _max_workers, "Worker_id %u is larger than maximum %u", worker_id, _max_workers); |
|
48 |
assert(region_idx < _max_regions, "Region_idx %u is larger than maximum %u", region_idx, _max_regions); |
|
49 |
} |
|
50 |
#endif |
|
35199 | 51 |
|
50281 | 52 |
// This card index indicates "no card for that entry" yet. This allows us to use the OS |
53 |
// lazy backing of memory with zero-filled pages to avoid initial actual memory use. |
|
54 |
// This means that the heap must not contain card zero. |
|
55 |
static const uintptr_t InvalidCard = 0; |
|
35199 | 56 |
|
50281 | 57 |
public: |
35199 | 58 |
static void clear(uint region_idx); |
59 |
||
60 |
// Returns true if the given card is in the cache at the given location, or |
|
61 |
// replaces the card at that location and returns false. |
|
49608
1852b17b0efc
8196485: FromCardCache default card index can cause crashes
tschatzl
parents:
47216
diff
changeset
|
62 |
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
|
63 |
uintptr_t card_in_cache = at(worker_id, region_idx); |
35199 | 64 |
if (card_in_cache == card) { |
65 |
return true; |
|
66 |
} else { |
|
67 |
set(worker_id, region_idx, card); |
|
68 |
return false; |
|
69 |
} |
|
70 |
} |
|
71 |
||
49608
1852b17b0efc
8196485: FromCardCache default card index can cause crashes
tschatzl
parents:
47216
diff
changeset
|
72 |
static uintptr_t at(uint worker_id, uint region_idx) { |
46669 | 73 |
DEBUG_ONLY(check_bounds(worker_id, region_idx);) |
37228
25ea8814a824
8148099: Improve memory access to FromCardCache during GC
tschatzl
parents:
35210
diff
changeset
|
74 |
return _cache[region_idx][worker_id]; |
35199 | 75 |
} |
76 |
||
49608
1852b17b0efc
8196485: FromCardCache default card index can cause crashes
tschatzl
parents:
47216
diff
changeset
|
77 |
static void set(uint worker_id, uint region_idx, uintptr_t val) { |
46669 | 78 |
DEBUG_ONLY(check_bounds(worker_id, region_idx);) |
37228
25ea8814a824
8148099: Improve memory access to FromCardCache during GC
tschatzl
parents:
35210
diff
changeset
|
79 |
_cache[region_idx][worker_id] = val; |
35199 | 80 |
} |
81 |
||
35210
eb1d5c68bf64
8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet
tschatzl
parents:
35200
diff
changeset
|
82 |
static void initialize(uint num_par_rem_sets, uint max_num_regions); |
35199 | 83 |
|
84 |
static void invalidate(uint start_idx, size_t num_regions); |
|
85 |
||
86 |
static void print(outputStream* out = tty) PRODUCT_RETURN; |
|
87 |
||
88 |
static size_t static_mem_size() { |
|
89 |
return _static_mem_size; |
|
90 |
} |
|
91 |
}; |
|
92 |
||
93 |
#endif // SHARE_VM_GC_G1_G1FROMCARDCACHE_HPP |