Skip to content

Commit 029a036

Browse files
author
Bo Cupp
committed
Pre-process out more precise tracing code when RECYCLER_VISITED_HOST is not defined
1 parent 7961526 commit 029a036

File tree

6 files changed

+60
-2
lines changed

6 files changed

+60
-2
lines changed

bin/GCStress/RecyclerTestObject.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,24 +327,34 @@ class RecyclerVisitedObject : public RecyclerTestObject
327327

328328
// Randomly select the type of object to create
329329
AllocationType allocType = static_cast<AllocationType>(GetRandomInteger(static_cast<unsigned int>(AllocationType::Count)));
330+
wchar_t* allocTypeName;
330331
switch (allocType)
331332
{
332333
case AllocationType::TraceAndFinalized:
333334
mem = RecyclerAllocVisitedHostTracedAndFinalizedZero(recyclerInstance, size);
335+
allocTypeName = L"TraceAndFinalized";
334336
break;
335337
case AllocationType::TraceOnly:
336338
mem = RecyclerAllocVisitedHostTracedZero(recyclerInstance, size);
339+
allocTypeName = L"TraceOnly";
337340
break;
338341
case AllocationType::FinalizeLeaf:
339342
mem = RecyclerAllocVisitedHostFinalizedZero(recyclerInstance, size);
343+
allocTypeName = L"FinalizeLeaf";
340344
break;
341345
default:
342346
Assert(allocType == AllocationType::Leaf);
343347
mem = RecyclerAllocLeafZero(recyclerInstance, size);
348+
allocTypeName = L"Leaf";
344349
}
345350

346351
// Construct the v-table, allocType, and count information for the new object.
347352
RecyclerVisitedObject* obj = new (mem) RecyclerVisitedObject(allocType, count);
353+
354+
wchar_t debugString[1024];
355+
swprintf_s(debugString, L"Allocate 0x%08x%08x : %s\n", ((uintptr_t)mem)>>32, (uintptr_t)mem, allocTypeName);
356+
OutputDebugString(debugString);
357+
348358
return obj;
349359
}
350360

@@ -385,6 +395,10 @@ class RecyclerVisitedObject : public RecyclerTestObject
385395
BOOL success = ::HeapFree(GetProcessHeap(), 0, unmanagedResource);
386396
VerifyCondition(success != FALSE);
387397
unmanagedResource = nullptr;
398+
399+
wchar_t debugString[1024];
400+
swprintf_s(debugString, L"Dispose 0x%08x%08x\n", ((uintptr_t)this) >> 32, (uintptr_t)this);
401+
OutputDebugString(debugString);
388402
}
389403

390404

lib/Common/Memory/MarkContext.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ MarkContext::MarkContext(Recycler * recycler, PagePool * pagePool) :
1414
recycler(recycler),
1515
pagePool(pagePool),
1616
markStack(pagePool),
17+
#ifdef RECYCLER_VISITED_HOST
1718
preciseStack(pagePool),
19+
#endif
1820
trackStack(pagePool)
1921
{
2022
}
@@ -40,21 +42,27 @@ void MarkContext::OnObjectMarked(void* object, void* parent)
4042
void MarkContext::Init(uint reservedPageCount)
4143
{
4244
markStack.Init(reservedPageCount);
45+
#ifdef RECYCLER_VISITED_HOST
4346
preciseStack.Init();
47+
#endif
4448
trackStack.Init();
4549
}
4650

4751
void MarkContext::Clear()
4852
{
4953
markStack.Clear();
54+
#ifdef RECYCLER_VISITED_HOST
5055
preciseStack.Clear();
56+
#endif
5157
trackStack.Clear();
5258
}
5359

5460
void MarkContext::Abort()
5561
{
5662
markStack.Abort();
63+
#ifdef RECYCLER_VISITED_HOST
5764
preciseStack.Abort();
65+
#endif
5866
trackStack.Abort();
5967

6068
pagePool->ReleaseFreePages();
@@ -64,7 +72,9 @@ void MarkContext::Abort()
6472
void MarkContext::Release()
6573
{
6674
markStack.Release();
75+
#ifdef RECYCLER_VISITED_HOST
6776
preciseStack.Release();
77+
#endif
6878
trackStack.Release();
6979

7080
pagePool->ReleaseFreePages();
@@ -78,20 +88,28 @@ uint MarkContext::Split(uint targetCount, __in_ecount(targetCount) MarkContext *
7888
__analysis_assume(targetCount <= PageStack<IRecyclerVisitedObject*>::MaxSplitTargets);
7989

8090
PageStack<MarkCandidate> * targetMarkStacks[PageStack<MarkCandidate>::MaxSplitTargets];
91+
#ifdef RECYCLER_VISITED_HOST
8192
PageStack<IRecyclerVisitedObject*> * targetPreciseStacks[PageStack<IRecyclerVisitedObject*>::MaxSplitTargets];
93+
#endif
8294

8395
for (uint i = 0; i < targetCount; i++)
8496
{
8597
targetMarkStacks[i] = &targetContexts[i]->markStack;
98+
#ifdef RECYCLER_VISITED_HOST
8699
targetPreciseStacks[i] = &targetContexts[i]->preciseStack;
100+
#endif
87101
}
88102

89103
// Return the max count of the two splits - since the stacks have more or less unrelated sizes, they
90104
// could yield different number of splits, but the caller wants to know the max parallelism it
91105
// should use on the results of the split.
92106
const uint markStackSplitCount = this->markStack.Split(targetCount, targetMarkStacks);
107+
#ifdef RECYCLER_VISITED_HOST
93108
const uint preciseStackSplitCount = this->preciseStack.Split(targetCount, targetPreciseStacks);
94109
return max(markStackSplitCount, preciseStackSplitCount);
110+
#else
111+
return markStackSplitCount;
112+
#endif
95113
}
96114

97115

lib/Common/Memory/MarkContext.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class MarkContext
3131
Recycler * GetRecycler() { return this->recycler; }
3232

3333
bool AddMarkedObject(void * obj, size_t byteCount);
34+
#ifdef RECYCLER_VISITED_HOST
3435
bool AddPreciselyTracedObject(IRecyclerVisitedObject *obj);
36+
#endif
3537
#if ENABLE_CONCURRENT_GC
3638
bool AddTrackedObject(FinalizableObject * obj);
3739
#endif
@@ -56,9 +58,17 @@ class MarkContext
5658
void Release();
5759

5860
bool HasPendingMarkObjects() const { return !markStack.IsEmpty(); }
61+
#ifdef RECYCLER_VISITED_HOST
5962
bool HasPendingPreciselyTracedObjects() const { return !preciseStack.IsEmpty(); }
63+
#endif
6064
bool HasPendingTrackObjects() const { return !trackStack.IsEmpty(); }
61-
bool HasPendingObjects() const { return HasPendingMarkObjects() || HasPendingPreciselyTracedObjects() || HasPendingTrackObjects(); }
65+
bool HasPendingObjects() const {
66+
return HasPendingMarkObjects()
67+
#ifdef RECYCLER_VISITED_HOST
68+
|| HasPendingPreciselyTracedObjects()
69+
#endif
70+
|| HasPendingTrackObjects();
71+
}
6272

6373
PageAllocator * GetPageAllocator() { return this->pagePool->GetPageAllocator(); }
6474

@@ -92,7 +102,13 @@ class MarkContext
92102

93103

94104
#ifdef ENABLE_DEBUG_CONFIG_OPTIONS
95-
void SetMaxPageCount(size_t maxPageCount) { markStack.SetMaxPageCount(maxPageCount); preciseStack.SetMaxPageCount(maxPageCount); trackStack.SetMaxPageCount(maxPageCount); }
105+
void SetMaxPageCount(size_t maxPageCount) {
106+
markStack.SetMaxPageCount(maxPageCount);
107+
#ifdef RECYCLER_VISITED_HOST
108+
preciseStack.SetMaxPageCount(maxPageCount);
109+
#endif
110+
trackStack.SetMaxPageCount(maxPageCount);
111+
}
96112
#endif
97113

98114
#ifdef RECYCLER_MARK_TRACK

lib/Common/Memory/MarkContext.inl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ bool MarkContext::AddMarkedObject(void * objectAddress, size_t objectSize)
3434
return markStack.Push(markCandidate);
3535
}
3636

37+
#ifdef RECYCLER_VISITED_HOST
3738
inline bool MarkContext::AddPreciselyTracedObject(IRecyclerVisitedObject* obj)
3839
{
3940
FAULTINJECT_MEMORY_MARK_NOTHROW(_u("AddPreciselyTracedObject"), 0);
4041

4142
return preciseStack.Push(obj);
4243
}
44+
#endif
4345

4446
#if ENABLE_CONCURRENT_GC
4547
inline
@@ -195,11 +197,13 @@ void MarkContext::ProcessMark()
195197
}
196198
#endif
197199

200+
#ifdef RECYCLER_VISITED_HOST
198201
// Flip between processing the generic mark stack (conservatively traced with ScanMemory) and
199202
// the precise stack (precisely traced via IRecyclerVisitedObject::Trace). Each of those
200203
// operations on an object has the potential to add new marked objects to either or both
201204
// stacks so we must loop until they are both empty.
202205
while (!markStack.IsEmpty() || !preciseStack.IsEmpty())
206+
#endif
203207
{
204208
#if defined(_M_IX86) || defined(_M_X64)
205209
MarkCandidate current, next;
@@ -239,6 +243,7 @@ void MarkContext::ProcessMark()
239243

240244
Assert(markStack.IsEmpty());
241245

246+
#ifdef RECYCLER_VISITED_HOST
242247
if (!preciseStack.IsEmpty())
243248
{
244249
MarkContextWrapper<parallel> markContextWrapper(this);
@@ -250,5 +255,6 @@ void MarkContext::ProcessMark()
250255
}
251256

252257
Assert(preciseStack.IsEmpty());
258+
#endif
253259
}
254260
}

lib/Common/Memory/Recycler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,9 @@ class Recycler
15751575
template <bool doSpecialMark>
15761576
void ScanMemory(void ** obj, size_t byteCount) { if (byteCount != 0) { ScanMemoryInline<doSpecialMark>(obj, byteCount); } }
15771577
bool AddMark(void * candidate, size_t byteCount);
1578+
#ifdef RECYCLER_VISITED_HOST
15781579
bool AddPreciselyTracedMark(IRecyclerVisitedObject * candidate);
1580+
#endif
15791581

15801582
// Sweep
15811583
#if ENABLE_PARTIAL_GC

lib/Common/Memory/Recycler.inl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,13 +521,15 @@ Recycler::AddMark(void * candidate, size_t byteCount) throw()
521521
return markContext.AddMarkedObject(candidate, byteCount);
522522
}
523523

524+
#ifdef RECYCLER_VISITED_HOST
524525
inline bool
525526
Recycler::AddPreciselyTracedMark(IRecyclerVisitedObject * candidate) throw()
526527
{
527528
// This API cannot be used for parallel marking as we don't have enough information to determine which MarkingContext to use.
528529
Assert((this->collectionState & Collection_Parallel) == 0);
529530
return markContext.AddPreciselyTracedObject(candidate);
530531
}
532+
#endif
531533

532534
template <typename T>
533535
void

0 commit comments

Comments
 (0)