Skip to content

Commit

Permalink
Refactor copy to use template for concurrent GC
Browse files Browse the repository at this point in the history
Copy is now an inline function which calls copyForVariant, which
performs the previous functionality for copy. copyForVariant is a
template function that is told the variant of template that it is to
use, either CS or STW. This dictates if copyForVariant should
exhibit Concurrent Scavenger behaviour or Stop The World behaviour.

The enum CopyVariant is introduced to represent the different variants
of copyForVariant. The two options are STW for IS_CONCURRENT_ENABLED
== false, and CS for IS_CONCURRENT_ENABLED == true.

Signed-off-by: Oussama Saoudi <oussama.saoudi@ibm.com>
  • Loading branch information
OussamaSaoudi committed Jun 17, 2021
1 parent b7eb963 commit 66e9c45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions gc/base/standard/Scavenger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
#define HOTFIELD_SHOULD_ALIGN(descriptor) (0x1 == (0x1 & (descriptor)))
#define HOTFIELD_ALIGNMENT_BIAS(descriptor, heapObjectAlignment) (((descriptor) >> 1) * (heapObjectAlignment))

enum CopyVariant : bool { STW = false, CS = true };

extern "C" {
uintptr_t allocateMemoryForSublistFragment(void *vmThreadRawPtr, J9VMGC_SublistFragment *fragmentPrimitive);
#if defined(OMR_GC_MODRON_CONCURRENT_MARK)
Expand Down Expand Up @@ -1559,8 +1561,20 @@ MM_Scavenger::forwardingSucceeded(MM_EnvironmentStandard *env, MM_CopyScanCacheS
}
}

omrobjectptr_t
MMINLINE omrobjectptr_t
MM_Scavenger::copy(MM_EnvironmentStandard *env, MM_ForwardedHeader* forwardedHeader)
{
omrobjectptr_t result = NULL;
if (IS_CONCURRENT_ENABLED) {
result = MM_Scavenger::copyForVariant<CS>(env, forwardedHeader);
} else {
result = MM_Scavenger::copyForVariant<STW>(env, forwardedHeader);
}
return result;
}

template <bool variant> omrobjectptr_t
MM_Scavenger::copyForVariant(MM_EnvironmentStandard *env, MM_ForwardedHeader* forwardedHeader)
{
uintptr_t objectCopySizeInBytes, objectReserveSizeInBytes;
uintptr_t hotFieldsDescriptor = 0;
Expand Down Expand Up @@ -1690,7 +1704,7 @@ MM_Scavenger::copy(MM_EnvironmentStandard *env, MM_ForwardedHeader* forwardedHea
bool allowDuplicate = false;
bool allowDuplicateOrConcurrentDisabled = true;

if (IS_CONCURRENT_ENABLED) {
if (CS == variant) {
/* For smaller objects, we allow duplicate (copy first and try to win forwarding).
* For larger objects, there is only one copy (threads setup destination header, one wins, and other participate in copying or wait till copy is complete).
* 1024 is somewhat arbitrary threshold, so that most of time we do not have to go through relatively expensive setup procedure.
Expand Down
1 change: 1 addition & 0 deletions gc/base/standard/Scavenger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class MM_Scavenger : public MM_Collector
MMINLINE void forwardingSucceeded(MM_EnvironmentStandard *env, MM_CopyScanCacheStandard *copyCache, void *newCacheAlloc, uintptr_t oldObjectAge, uintptr_t objectCopySizeInBytes, uintptr_t objectReserveSizeInBytes);

MMINLINE omrobjectptr_t copy(MM_EnvironmentStandard *env, MM_ForwardedHeader* forwardedHeader);
template <bool variant> omrobjectptr_t copyForVariant(MM_EnvironmentStandard *env, MM_ForwardedHeader* forwardedHeader);

/* Flush remaining Copy Scan updates which would otherwise be discarded
* @param majorFlush last thread to flush updates should perform a major flush (push accumulated updates to history record)
Expand Down

0 comments on commit 66e9c45

Please sign in to comment.