49606
|
1 |
/*
|
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
|
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 |
#include "precompiled.hpp"
|
|
26 |
#include "gc/g1/g1RegionMarkStatsCache.inline.hpp"
|
|
27 |
#include "memory/allocation.inline.hpp"
|
|
28 |
|
|
29 |
G1RegionMarkStatsCache::G1RegionMarkStatsCache(G1RegionMarkStats* target, uint max_regions, uint num_cache_entries) :
|
|
30 |
_num_stats(max_regions),
|
|
31 |
_target(target),
|
|
32 |
_num_cache_entries(num_cache_entries),
|
|
33 |
_cache_hits(0),
|
|
34 |
_cache_misses(0) {
|
|
35 |
|
|
36 |
guarantee(is_power_of_2(num_cache_entries),
|
|
37 |
"Number of cache entries must be power of two, but is %u", num_cache_entries);
|
|
38 |
_cache = NEW_C_HEAP_ARRAY(G1RegionMarkStatsCacheEntry, _num_cache_entries, mtGC);
|
|
39 |
_num_cache_entries_mask = _num_cache_entries - 1;
|
|
40 |
}
|
|
41 |
|
|
42 |
G1RegionMarkStatsCache::~G1RegionMarkStatsCache() {
|
|
43 |
FREE_C_HEAP_ARRAY(G1RegionMarkStatsCacheEntry, _cache);
|
|
44 |
}
|
|
45 |
|
|
46 |
// Evict all remaining statistics, returning cache hits and misses.
|
|
47 |
Pair<size_t, size_t> G1RegionMarkStatsCache::evict_all() {
|
|
48 |
for (uint i = 0; i < _num_cache_entries; i++) {
|
|
49 |
evict(i);
|
|
50 |
}
|
|
51 |
return Pair<size_t,size_t>(_cache_hits, _cache_misses);
|
|
52 |
}
|
|
53 |
|
|
54 |
// Reset all cache entries to their default values.
|
|
55 |
void G1RegionMarkStatsCache::reset() {
|
|
56 |
_cache_hits = 0;
|
|
57 |
_cache_misses = 0;
|
|
58 |
|
|
59 |
for (uint i = 0; i < _num_cache_entries; i++) {
|
|
60 |
_cache[i].clear();
|
|
61 |
}
|
|
62 |
}
|