Skip to content

Commit

Permalink
Use addAtomic for incrementing counters of OMRMemCategory
Browse files Browse the repository at this point in the history
Use addAtomic for incrementing counters of OMRMemCategory instead of
spinning with compareAndSwapUDATA.
Similarly, use subtractAtomic for decrementing counters.

Because this change simply makes omrmemcategories.c to use existing
implementation of atomic add/sub in AtomicSupport.hpp and they are identical
to replaced implementation in omrmemcategories.c, this commit should introduce
no functional or performance change, but this will enable us to optimize
implementation of atomic add/sub in a single file in the future.

Signed-off-by: Akira Saitoh <saiaki@jp.ibm.com>
  • Loading branch information
Akira Saitoh committed May 31, 2021
1 parent 0174f25 commit 85f6038
Showing 1 changed file with 6 additions and 28 deletions.
34 changes: 6 additions & 28 deletions port/common/omrmemcategories.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010, 2015 IBM Corp. and others
* Copyright (c) 2010, 2021 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -39,15 +39,9 @@
#include "omrport.h"
#include "omrportpriv.h"
#include "omrportpg.h"
#include "omrutilbase.h"
#include "ut_omrport.h"

/* J9VMAtomicFunctions*/
#ifndef _J9VMATOMICFUNCTIONS_
#define _J9VMATOMICFUNCTIONS_
extern uintptr_t compareAndSwapUDATA(uintptr_t *location, uintptr_t oldValue, uintptr_t newValue);
#endif /* _J9VMATOMICFUNCTIONS_ */


/* Templates for categories that are copied into malloc'd memory in omrmem_startup_categories */
OMRMEM_CATEGORY_NO_CHILDREN("Unknown", OMRMEM_CATEGORY_UNKNOWN);

Expand All @@ -67,14 +61,10 @@ OMRMEM_CATEGORY_NO_CHILDREN("Port Library", OMRMEM_CATEGORY_PORT_LIBRARY);
void
omrmem_categories_increment_counters(OMRMemCategory *category, uintptr_t size)
{
uintptr_t oldValue;

Trc_Assert_PTR_mem_categories_increment_counters_NULL_category(NULL != category);

/* Increment block count */
do {
oldValue = category->liveAllocations;
} while (compareAndSwapUDATA(&category->liveAllocations, oldValue, oldValue + 1) != oldValue);
addAtomic(&category->liveAllocations, 1);

omrmem_categories_increment_bytes(category, size);
}
Expand All @@ -87,14 +77,10 @@ omrmem_categories_increment_counters(OMRMemCategory *category, uintptr_t size)
void
omrmem_categories_increment_bytes(OMRMemCategory *category, uintptr_t size)
{
uintptr_t oldValue;

Trc_Assert_PTR_mem_categories_increment_bytes_NULL_category(NULL != category);

/* Increment bytes */
do {
oldValue = category->liveBytes;
} while (compareAndSwapUDATA(&category->liveBytes, oldValue, oldValue + size) != oldValue);
addAtomic(&category->liveBytes, size);
}

/**
Expand All @@ -105,14 +91,10 @@ omrmem_categories_increment_bytes(OMRMemCategory *category, uintptr_t size)
void
omrmem_categories_decrement_counters(OMRMemCategory *category, uintptr_t size)
{
uintptr_t oldValue;

Trc_Assert_PTR_mem_categories_decrement_counters_NULL_category(NULL != category);

/* Decrement block count */
do {
oldValue = category->liveAllocations;
} while (compareAndSwapUDATA(&category->liveAllocations, oldValue, oldValue - 1) != oldValue);
subtractAtomic(&category->liveAllocations, 1);

omrmem_categories_decrement_bytes(category, size);
}
Expand All @@ -125,14 +107,10 @@ omrmem_categories_decrement_counters(OMRMemCategory *category, uintptr_t size)
void
omrmem_categories_decrement_bytes(OMRMemCategory *category, uintptr_t size)
{
uintptr_t oldValue;

Trc_Assert_PTR_mem_categories_decrement_bytes_NULL_category(NULL != category);

/* Decrement size */
do {
oldValue = category->liveBytes;
} while (compareAndSwapUDATA(&category->liveBytes, oldValue, oldValue - size) != oldValue);
subtractAtomic(&category->liveBytes, size);
}

/**
Expand Down

0 comments on commit 85f6038

Please sign in to comment.