src/hotspot/share/gc/g1/g1RegionMarkStatsCache.cpp
author kbarrett
Tue, 12 Jun 2018 18:12:59 -0400
changeset 50532 a18c60527166
parent 50281 bc1336220671
child 51332 c25572739e7c
permissions -rw-r--r--
8204585: Remove IN_ARCHIVE_ROOT from Access API Summary: Replaced Access API with API on heap. Reviewed-by: jiangli, coleenp, tschatzl Contributed-by: stefan.karlsson@oracle.com, kim.barrett@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49606
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
     1
/*
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
     4
 *
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
     8
 *
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    14
 *
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    18
 *
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    21
 * questions.
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    22
 *
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    23
 */
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    24
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    25
#include "precompiled.hpp"
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    26
#include "gc/g1/g1RegionMarkStatsCache.inline.hpp"
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    27
#include "memory/allocation.inline.hpp"
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    28
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    29
G1RegionMarkStatsCache::G1RegionMarkStatsCache(G1RegionMarkStats* target, uint max_regions, uint num_cache_entries) :
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    30
  _num_stats(max_regions),
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    31
  _target(target),
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    32
  _num_cache_entries(num_cache_entries),
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    33
  _cache_hits(0),
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    34
  _cache_misses(0) {
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    35
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    36
  guarantee(is_power_of_2(num_cache_entries),
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    37
            "Number of cache entries must be power of two, but is %u", num_cache_entries);
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    38
  _cache = NEW_C_HEAP_ARRAY(G1RegionMarkStatsCacheEntry, _num_cache_entries, mtGC);
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    39
  _num_cache_entries_mask = _num_cache_entries - 1;
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    40
}
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    41
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    42
G1RegionMarkStatsCache::~G1RegionMarkStatsCache() {
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    43
  FREE_C_HEAP_ARRAY(G1RegionMarkStatsCacheEntry, _cache);
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    44
}
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    45
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    46
// Evict all remaining statistics, returning cache hits and misses.
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    47
Pair<size_t, size_t> G1RegionMarkStatsCache::evict_all() {
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    48
  for (uint i = 0; i < _num_cache_entries; i++) {
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    49
    evict(i);
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    50
  }
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    51
  return Pair<size_t,size_t>(_cache_hits, _cache_misses);
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    52
}
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    53
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    54
// Reset all cache entries to their default values.
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    55
void G1RegionMarkStatsCache::reset() {
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    56
  _cache_hits = 0;
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    57
  _cache_misses = 0;
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    58
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    59
  for (uint i = 0; i < _num_cache_entries; i++) {
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    60
    _cache[i].clear();
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    61
  }
9ae8719efcae 8197850: Calculate liveness in regions during marking
tschatzl
parents:
diff changeset
    62
}