2008-11-17 18:29:00 -05:00
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
/*******************************************************************/
|
|
|
|
/* WARNING */
|
|
|
|
/* This file should be identical in the Bartok and Singularity */
|
|
|
|
/* depots. Master copy resides in Bartok Depot. Changes should be */
|
|
|
|
/* made to Bartok Depot and propagated to Singularity Depot. */
|
|
|
|
/*******************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
namespace System.GCs {
|
|
|
|
|
|
|
|
using Microsoft.Bartok.Runtime;
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
using System.Threading;
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
//[NoBarriers]
|
|
|
|
internal unsafe class AllCardsWriteBarrier : RefWriteBarrier
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
internal static AllCardsWriteBarrier instance;
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
[NoBarriers]
|
2008-03-05 09:52:00 -05:00
|
|
|
internal static new void Initialize() {
|
|
|
|
AllCardsWriteBarrier.instance = (AllCardsWriteBarrier)
|
|
|
|
BootstrapMemory.Allocate(typeof(AllCardsWriteBarrier));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Inline]
|
2008-11-17 18:29:00 -05:00
|
|
|
[NoBarriers]
|
2008-03-05 09:52:00 -05:00
|
|
|
protected override void StoreStaticFieldImpl(ref Object staticField,
|
2008-11-17 18:29:00 -05:00
|
|
|
Object value,
|
|
|
|
int mask)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
|
|
|
// No need to mark the card for a static field.
|
2008-11-17 18:29:00 -05:00
|
|
|
staticField = value;
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
protected override void CopyStructImpl(Object srcObj,
|
|
|
|
Object dstObj,
|
|
|
|
VTable vtable,
|
2008-03-05 09:52:00 -05:00
|
|
|
UIntPtr srcPtr,
|
|
|
|
UIntPtr dstPtr)
|
|
|
|
{
|
|
|
|
CopyStructWithBarrier(vtable, srcPtr, dstPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Inline]
|
|
|
|
protected override Object AtomicSwapImpl(ref Object reference,
|
2008-11-17 18:29:00 -05:00
|
|
|
Object value,
|
|
|
|
int mask)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
|
|
|
UIntPtr resultAddr =
|
|
|
|
Interlocked.Exchange(Magic.toPointer(ref reference),
|
|
|
|
Magic.addressOf(value));
|
2008-11-17 18:29:00 -05:00
|
|
|
RecordReference(Magic.toPointer(ref reference), value);
|
2008-03-05 09:52:00 -05:00
|
|
|
return Magic.fromAddress(resultAddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Inline]
|
|
|
|
protected override
|
|
|
|
Object AtomicCompareAndSwapImpl(ref Object reference,
|
|
|
|
Object newValue,
|
2008-11-17 18:29:00 -05:00
|
|
|
Object comparand,
|
|
|
|
int mask)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
|
|
|
UIntPtr resultAddr =
|
|
|
|
Interlocked.CompareExchange(Magic.toPointer(ref reference),
|
|
|
|
Magic.addressOf(newValue),
|
|
|
|
Magic.addressOf(comparand));
|
2008-11-17 18:29:00 -05:00
|
|
|
RecordReference(Magic.toPointer(ref reference), newValue);
|
2008-03-05 09:52:00 -05:00
|
|
|
return Magic.fromAddress(resultAddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Inline]
|
|
|
|
protected override void CloneImpl(Object srcObject, Object dstObject)
|
|
|
|
{
|
|
|
|
CloneNoBarrier(srcObject, dstObject);
|
|
|
|
RecordClone(dstObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 'offset' is not relative to the lower bound, but is a count
|
|
|
|
// of elements from the first element in the array.
|
|
|
|
protected override void ArrayZeroImpl(Array array,
|
|
|
|
int offset,
|
|
|
|
int length)
|
|
|
|
{
|
|
|
|
ArrayZeroNoBarrier(array, offset, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 'offset' is not relative to the lower bound, but is a count
|
|
|
|
// of elements from the first element in the array.
|
|
|
|
protected override void ArrayCopyImpl(Array srcArray, int srcOffset,
|
|
|
|
Array dstArray, int dstOffset,
|
|
|
|
int length)
|
|
|
|
{
|
|
|
|
if ((length > 1000) || ((length << 2) >= dstArray.Length)) {
|
|
|
|
ArrayCopyNoBarrier(srcArray, srcOffset,
|
|
|
|
dstArray, dstOffset,
|
|
|
|
length);
|
|
|
|
RecordClone(dstArray);
|
|
|
|
} else {
|
|
|
|
ArrayCopyWithBarrier(srcArray, srcOffset,
|
|
|
|
dstArray, dstOffset,
|
|
|
|
length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Inline]
|
2008-11-17 18:29:00 -05:00
|
|
|
protected override void WriteImpl(UIntPtr *location,
|
|
|
|
Object value,
|
|
|
|
int mask)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
|
|
|
*location = Magic.addressOf(value);
|
|
|
|
RecordReference(location, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Inline]
|
2008-11-17 18:29:00 -05:00
|
|
|
protected override void WriteImplByRef(ref Object location,
|
|
|
|
Object value,
|
|
|
|
int mask)
|
|
|
|
{
|
|
|
|
WriteImpl(Magic.toPointer(ref location), value, mask);
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
[Inline]
|
2008-11-17 18:29:00 -05:00
|
|
|
private static void RecordClone(Object clone) {
|
|
|
|
GenerationalGCData.installedRemSet.RecordClonedObject(clone);
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
[Inline]
|
|
|
|
private static void RecordReference(UIntPtr *location,
|
|
|
|
Object value)
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
GenerationalGCData.
|
2008-03-05 09:52:00 -05:00
|
|
|
installedRemSet.RecordReference(location, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|