Skip to content

Commit

Permalink
Non-functional Core SATB Changes
Browse files Browse the repository at this point in the history
Isolated changes part of Core SATB work. These changes are intended for
next few PRs for SATB.

Signed-off-by: Salman Rana <salman.rana@ibm.com>
  • Loading branch information
RSalman committed Nov 9, 2021
1 parent a4b988e commit 7227166
Show file tree
Hide file tree
Showing 14 changed files with 496 additions and 410 deletions.
7 changes: 7 additions & 0 deletions gc/base/EnvironmentBase.cpp
Expand Up @@ -35,6 +35,7 @@
#include "ConcurrentGCStats.hpp"
#include "GCExtensionsBase.hpp"
#include "GlobalAllocationManager.hpp"
#include "GlobalCollector.hpp"
#include "Heap.hpp"
#include "MemorySpace.hpp"
#include "ModronAssertions.h"
Expand Down Expand Up @@ -90,6 +91,12 @@ MM_EnvironmentBase::initialize(MM_GCExtensionsBase *extensions)
setAllocationColor(extensions->newThreadAllocationColor);

if (extensions->isStandardGC() || extensions->isVLHGC()) {
if (GC_MARK == extensions->newThreadAllocationColor) {
/* For a Standard config, thread allocation color can only be set by SATB barrier */
Assert_MM_true(extensions->isSATBBarrierActive());
setThreadScanned(true);
}

/* pass veryLargeObjectThreshold = 0 to initialize limited size of veryLargeEntryPool for thread (to reduce footprint),
* but if the threshold is bigger than maxHeap size, we would pass orignal threshold to indicate no veryLargeEntryPool needed
*/
Expand Down
23 changes: 23 additions & 0 deletions gc/base/GCExtensionsBase.cpp
Expand Up @@ -34,6 +34,11 @@
#include "Scavenger.hpp"
#endif /* OMR_GC_MODRON_SCAVENGER */

#if defined(OMR_GC_REALTIME)
#include "Configuration.hpp"
#include "RememberedSetSATB.hpp"
#endif /* defined(OMR_GC_REALTIME) */

MM_GCExtensionsBase*
MM_GCExtensionsBase::newInstance(MM_EnvironmentBase* env)
{
Expand Down Expand Up @@ -317,3 +322,21 @@ MM_GCExtensionsBase::computeDefaultMaxHeap(MM_EnvironmentBase* env)
/* Initialize Xmx, Xmdx */
memoryMax = MM_Math::roundToFloor(heapAlignment, (uintptr_t)memoryToRequest);
}

bool
MM_GCExtensionsBase::isSATBBarrierActive()
{
#if defined(OMR_GC_REALTIME)
return ((usingSATBBarrier()) && (!sATBBarrierRememberedSet->isGlobalFragmentIndexPreserved()));
#endif /* defined(OMR_GC_REALTIME) */
return false;
}

bool
MM_GCExtensionsBase::usingSATBBarrier()
{
#if defined(OMR_GC_REALTIME)
return (configuration->isSnapshotAtTheBeginningBarrierEnabled());
#endif /* defined(OMR_GC_REALTIME) */
return false;
}
3 changes: 3 additions & 0 deletions gc/base/GCExtensionsBase.hpp
Expand Up @@ -1371,6 +1371,9 @@ class MM_GCExtensionsBase : public MM_BaseVirtual {
return (fvtest_disableInlineAllocation || instrumentableAllocateHookEnabled || disableInlineCacheForAllocationThreshold);
}

bool isSATBBarrierActive();
bool usingSATBBarrier();

MM_GCExtensionsBase()
: MM_BaseVirtual()
#if defined(OMR_GC_MODRON_SCAVENGER)
Expand Down
2 changes: 2 additions & 0 deletions gc/base/GlobalCollector.hpp
Expand Up @@ -100,6 +100,8 @@ class MM_GlobalCollector : public MM_Collector {
*/
virtual void deleteSweepPoolState(MM_EnvironmentBase* env, void* sweepPoolState) = 0;

virtual void checkColorAndMark(MM_EnvironmentBase* env, omrobjectptr_t objectPt) { Assert_MM_unreachable(); }

MM_GlobalCollector()
: MM_Collector()
, _delegate()
Expand Down
2 changes: 1 addition & 1 deletion gc/base/MarkingScheme.cpp
Expand Up @@ -358,7 +358,7 @@ MM_MarkingScheme::markLiveObjectsInit(MM_EnvironmentBase *env, bool initMarkMap)
* @param[in] shouldScan instruct should scanning also be active while roots are marked
*/
void
MM_MarkingScheme::markLiveObjectsRoots(MM_EnvironmentBase *env)
MM_MarkingScheme::markLiveObjectsRoots(MM_EnvironmentBase *env, bool processLists)
{
_delegate.scanRoots(env);
}
Expand Down
2 changes: 1 addition & 1 deletion gc/base/MarkingScheme.hpp
Expand Up @@ -106,7 +106,7 @@ class MM_MarkingScheme : public MM_BaseVirtual
* Create Root Scanner and Mark all roots including classes and classloaders if dynamic class unloading is enabled
* @param[in] env - passed Environment
*/
void markLiveObjectsRoots(MM_EnvironmentBase *env);
void markLiveObjectsRoots(MM_EnvironmentBase *env, bool processLists = true);

/**
* Scan (complete)
Expand Down
1 change: 1 addition & 0 deletions gc/base/Packet.hpp
Expand Up @@ -240,6 +240,7 @@ class MM_Packet : public MM_BaseNonVirtual
friend class MM_PacketList;
friend class MM_PacketSlotIterator;
friend class MM_WorkPackets;
friend class MM_WorkPacketsSATB;
};

#endif /* PACKET_HPP_ */
16 changes: 13 additions & 3 deletions gc/base/ParallelMarkTask.cpp
Expand Up @@ -46,9 +46,19 @@ MM_ParallelMarkTask::run(MM_EnvironmentBase *env)
env->_workStack.prepareForWork(env, (MM_WorkPackets *)(_markingScheme->getWorkPackets()));

_markingScheme->markLiveObjectsInit(env, _initMarkMap);
_markingScheme->markLiveObjectsRoots(env);
_markingScheme->markLiveObjectsScan(env);
_markingScheme->markLiveObjectsComplete(env);

switch (_action) {
case MARK_ALL:
_markingScheme->markLiveObjectsRoots(env, true);
_markingScheme->markLiveObjectsScan(env);
_markingScheme->markLiveObjectsComplete(env);
break;
case MARK_ROOTS:
_markingScheme->markLiveObjectsRoots(env, false);
break;
default:
Assert_MM_unreachable();
}

env->_workStack.flush(env);
}
Expand Down
11 changes: 10 additions & 1 deletion gc/base/ParallelMarkTask.hpp
Expand Up @@ -44,10 +44,17 @@ class MM_ParallelDispatcher;
*/
class MM_ParallelMarkTask : public MM_ParallelTask
{
public:
enum MarkAction {
MARK_ALL = 1,
MARK_ROOTS,
};

private:
MM_MarkingScheme *_markingScheme;
const bool _initMarkMap;
MM_CycleState *_cycleState; /**< Collection cycle state active for the task */
const MarkAction _action;

public:
virtual uintptr_t getVMStateID();
Expand All @@ -69,11 +76,13 @@ class MM_ParallelMarkTask : public MM_ParallelTask
MM_ParallelDispatcher *dispatcher,
MM_MarkingScheme *markingScheme,
bool initMarkMap,
MM_CycleState *cycleState) :
MM_CycleState *cycleState,
MarkAction action = MARK_ALL) :
MM_ParallelTask(env, dispatcher)
,_markingScheme(markingScheme)
,_initMarkMap(initMarkMap)
,_cycleState(cycleState)
,_action(action)
{
_typeId = __FUNCTION__;
};
Expand Down
11 changes: 11 additions & 0 deletions gc/base/standard/ParallelGlobalGC.cpp
Expand Up @@ -1533,6 +1533,17 @@ MM_ParallelGlobalGC::isMarked(void *objectPtr)
return _markingScheme->getMarkMap()->isBitSet(static_cast<omrobjectptr_t>(objectPtr));
}

void
MM_ParallelGlobalGC::checkColorAndMark(MM_EnvironmentBase* env, omrobjectptr_t objectPtr)
{
#if defined(OMR_GC_REALTIME)
if (_extensions->isSATBBarrierActive()) {
Assert_MM_true(GC_MARK == env->getAllocationColor());
_markingScheme->markObject(env, objectPtr, true);
}
#endif /* defined(OMR_GC_REALTIME) */
}

void
MM_ParallelGlobalGC::completeExternalConcurrentCycle(MM_EnvironmentBase *env)
{
Expand Down
2 changes: 2 additions & 0 deletions gc/base/standard/ParallelGlobalGC.hpp
Expand Up @@ -308,6 +308,8 @@ class MM_ParallelGlobalGC : public MM_GlobalCollector

virtual bool isMarked(void *objectPtr);

virtual void checkColorAndMark(MM_EnvironmentBase* env, omrobjectptr_t objectPtr);

/**
* Return reference to Marking Scheme
*/
Expand Down
184 changes: 92 additions & 92 deletions gc/base/standard/RememberedSetSATB.hpp
@@ -1,92 +1,92 @@
/*******************************************************************************
* Copyright (c) 1991, 2019 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
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/


#if !defined(REMEMBEREDSETSATB_HPP_)
#define REMEMBEREDSETSATB_HPP_

#if defined(OMR_GC_REALTIME)

#include "WorkPacketsSATB.hpp"
#include "BaseNonVirtual.hpp"

class EnvironmentModron;

class MM_RememberedSetSATB : public MM_BaseNonVirtual
{
/* Data members & types */
public:
MM_GCRememberedSet _rememberedSetStruct; /**< The VM-readable struct containing the remembered set "global" indexes. */
protected:
private:
MM_WorkPacketsSATB *_workPackets; /**< The workPackets struct used as backing store for the rememberedSet */

/* Methods */
public:
/* Constructors & destructors */
static MM_RememberedSetSATB *newInstance(MM_EnvironmentBase *env, MM_WorkPacketsSATB *workPackets);
void kill(MM_EnvironmentBase *env);
MM_RememberedSetSATB(MM_EnvironmentBase *env, MM_WorkPacketsSATB *workPackets) :
MM_BaseNonVirtual(),
_workPackets(workPackets)
{
_typeId = __FUNCTION__;
/* Initializing the global fragment index to the reserved index means the GC starts
* with the barrier disabled. The preservedGlobalFragmentIndex must be initialized
* to any non-reserved value so that the call to MM_RealtimeGC::enableWriteBarrier which
* in turns restores the globalFragmentIndex from the preservedGlobalFragmentIndex actually
* restores a valid, non-reserved value.
*/
_rememberedSetStruct.globalFragmentIndex = J9GC_REMEMBERED_SET_RESERVED_INDEX;
_rememberedSetStruct.preservedGlobalFragmentIndex = J9GC_REMEMBERED_SET_RESERVED_INDEX + 1;
};
/* New methods */
void initializeFragment(MM_EnvironmentBase* env, MM_GCRememberedSetFragment* fragment); /* "Nulls" out a fragment. */
void storeInFragment(MM_EnvironmentBase* env, MM_GCRememberedSetFragment* fragment, UDATA* value); /* This guarantees the store will occur, but a new fragment may be fetched. */
bool isFragmentValid(MM_EnvironmentBase* env, const MM_GCRememberedSetFragment* fragment);
void preserveLocalFragmentIndex(MM_EnvironmentBase* env, MM_GCRememberedSetFragment* fragment); /* Called by the code that enables the double-barrier. */
void restoreLocalFragmentIndex(MM_EnvironmentBase* env, MM_GCRememberedSetFragment* fragment); /* Called by the root scanner to disable the double-barrier. */
void preserveGlobalFragmentIndex(MM_EnvironmentBase* env); /* Called by the code that disables the barrier. */
void restoreGlobalFragmentIndex(MM_EnvironmentBase* env); /* Called by the code that enables the barrier. */
/* Used to determine if the realtime write barrier is enabled. */
MMINLINE bool
isGlobalFragmentIndexPreserved(MM_EnvironmentBase* env)
{
return (J9GC_REMEMBERED_SET_RESERVED_INDEX == _rememberedSetStruct.globalFragmentIndex);
}
void flushFragments(MM_EnvironmentBase* env); /* Ensures all fragments will be seen as invalid next time they are accessed. */
bool refreshFragment(MM_EnvironmentBase *env, MM_GCRememberedSetFragment* fragment);
protected:
bool initialize(MM_EnvironmentBase *env);
void tearDown(MM_EnvironmentBase *env);
UDATA getLocalFragmentIndex(MM_EnvironmentBase* env, const MM_GCRememberedSetFragment* fragment);
UDATA getGlobalFragmentIndex(MM_EnvironmentBase* env);
private:
void setGlobalIndex(MM_EnvironmentBase* env, UDATA indexValue); /* Increments the appropriate global index (global or preserved). */
};
#endif /* defined(OMR_GC_REALTIME) */
#endif /* REMEMBEREDSETSATB_HPP_ */

/*******************************************************************************
* Copyright (c) 1991, 2019 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
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/


#if !defined(REMEMBEREDSETSATB_HPP_)
#define REMEMBEREDSETSATB_HPP_

#if defined(OMR_GC_REALTIME)

#include "WorkPacketsSATB.hpp"
#include "BaseNonVirtual.hpp"

class EnvironmentModron;

class MM_RememberedSetSATB : public MM_BaseNonVirtual
{
/* Data members & types */
public:
MM_GCRememberedSet _rememberedSetStruct; /**< The VM-readable struct containing the remembered set "global" indexes. */
protected:
private:
MM_WorkPacketsSATB *_workPackets; /**< The workPackets struct used as backing store for the rememberedSet */

/* Methods */
public:
/* Constructors & destructors */
static MM_RememberedSetSATB *newInstance(MM_EnvironmentBase *env, MM_WorkPacketsSATB *workPackets);
void kill(MM_EnvironmentBase *env);

MM_RememberedSetSATB(MM_EnvironmentBase *env, MM_WorkPacketsSATB *workPackets) :
MM_BaseNonVirtual(),
_workPackets(workPackets)
{
_typeId = __FUNCTION__;
/* Initializing the global fragment index to the reserved index means the GC starts
* with the barrier disabled. The preservedGlobalFragmentIndex must be initialized
* to any non-reserved value so that the call to MM_RealtimeGC::enableWriteBarrier which
* in turns restores the globalFragmentIndex from the preservedGlobalFragmentIndex actually
* restores a valid, non-reserved value.
*/
_rememberedSetStruct.globalFragmentIndex = J9GC_REMEMBERED_SET_RESERVED_INDEX;
_rememberedSetStruct.preservedGlobalFragmentIndex = J9GC_REMEMBERED_SET_RESERVED_INDEX + 1;
};

/* New methods */
void initializeFragment(MM_EnvironmentBase* env, MM_GCRememberedSetFragment* fragment); /* "Nulls" out a fragment. */
void storeInFragment(MM_EnvironmentBase* env, MM_GCRememberedSetFragment* fragment, UDATA* value); /* This guarantees the store will occur, but a new fragment may be fetched. */
bool isFragmentValid(MM_EnvironmentBase* env, const MM_GCRememberedSetFragment* fragment);
void preserveLocalFragmentIndex(MM_EnvironmentBase* env, MM_GCRememberedSetFragment* fragment); /* Called by the code that enables the double-barrier. */
void restoreLocalFragmentIndex(MM_EnvironmentBase* env, MM_GCRememberedSetFragment* fragment); /* Called by the root scanner to disable the double-barrier. */
void preserveGlobalFragmentIndex(MM_EnvironmentBase* env); /* Called by the code that disables the barrier. */
void restoreGlobalFragmentIndex(MM_EnvironmentBase* env); /* Called by the code that enables the barrier. */
/* Used to determine if the realtime write barrier is enabled. */
MMINLINE bool
isGlobalFragmentIndexPreserved(MM_EnvironmentBase* env = NULL)
{
return (J9GC_REMEMBERED_SET_RESERVED_INDEX == _rememberedSetStruct.globalFragmentIndex);
}
void flushFragments(MM_EnvironmentBase* env); /* Ensures all fragments will be seen as invalid next time they are accessed. */
bool refreshFragment(MM_EnvironmentBase *env, MM_GCRememberedSetFragment* fragment);

protected:
bool initialize(MM_EnvironmentBase *env);
void tearDown(MM_EnvironmentBase *env);
UDATA getLocalFragmentIndex(MM_EnvironmentBase* env, const MM_GCRememberedSetFragment* fragment);
UDATA getGlobalFragmentIndex(MM_EnvironmentBase* env);

private:
void setGlobalIndex(MM_EnvironmentBase* env, UDATA indexValue); /* Increments the appropriate global index (global or preserved). */
};
#endif /* defined(OMR_GC_REALTIME) */
#endif /* REMEMBEREDSETSATB_HPP_ */

0 comments on commit 7227166

Please sign in to comment.