Skip to content
Permalink
Browse files
8276301: G1: Refine implementation of G1CardSetFreePool::memory_sizes()
Reviewed-by: tschatzl, ayang
  • Loading branch information
Hamlin Li committed Nov 4, 2021
1 parent ee49963 commit 7de653e428ee38339ec38533659b23a52e275f3f
Showing 2 changed files with 8 additions and 24 deletions.
@@ -140,13 +140,6 @@ G1CardSetMemoryStats::G1CardSetMemoryStats() {
clear();
}

G1CardSetMemoryStats::G1CardSetMemoryStats(void(*fn)(const void*,uint,size_t&,size_t&), const void* context) {
clear();
for (uint i = 0; i < num_pools(); i++) {
fn(context, i, _num_mem_sizes[i], _num_buffers[i]);
}
}

void G1CardSetMemoryStats::clear() {
for (uint i = 0; i < num_pools(); i++) {
_num_mem_sizes[i] = 0;
@@ -277,17 +270,14 @@ G1CardSetFreePool::~G1CardSetFreePool() {
FREE_C_HEAP_ARRAY(mtGC, _free_lists);
}

static void collect_mem_sizes(const void* context, uint i, size_t& mem_size, size_t& num_buffers) {
((G1CardSetFreePool*)context)->get_size(i, mem_size, num_buffers);
}

void G1CardSetFreePool::get_size(uint i, size_t& mem_size, size_t& num_buffers) const {
mem_size = _free_lists[i].mem_size();
num_buffers = _free_lists[i].num_buffers();
}

G1CardSetMemoryStats G1CardSetFreePool::memory_sizes() const {
return G1CardSetMemoryStats(collect_mem_sizes, this);
G1CardSetMemoryStats free_list_stats;
assert(free_list_stats.num_pools() == num_free_lists(), "must be");
for (uint i = 0; i < num_free_lists(); i++) {
free_list_stats._num_mem_sizes[i] = _free_lists[i].mem_size();
free_list_stats._num_buffers[i] = _free_lists[i].num_buffers();
}
return free_list_stats;
}

size_t G1CardSetFreePool::mem_size() const {
@@ -149,9 +149,6 @@ class G1CardSetMemoryStats {

// Returns all-zero statistics.
G1CardSetMemoryStats();
// For every element in the set (indicated by i), call fn to provide the
// memory size and number of buffers for that i'th buffer list.
G1CardSetMemoryStats(void (*fn)(const void* context, uint i, size_t& mem_size, size_t& num_buffers), const void* context);

void add(G1CardSetMemoryStats const other) {
STATIC_ASSERT(ARRAY_SIZE(_num_buffers) == ARRAY_SIZE(_num_mem_sizes));
@@ -171,7 +168,7 @@ class G1CardSetFreePool {
// The global free pool.
static G1CardSetFreePool _freelist_pool;

uint _num_free_lists;
const uint _num_free_lists;
G1CardSetBufferList* _free_lists;

public:
@@ -193,9 +190,6 @@ class G1CardSetFreePool {

uint num_free_lists() const { return _num_free_lists; }

// Return sizes for free list i in this free list pool.
void get_size(uint i, size_t& mem_size, size_t& num_buffers) const;

G1CardSetMemoryStats memory_sizes() const;
size_t mem_size() const;

1 comment on commit 7de653e

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 7de653e Nov 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.