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