Skip to content

Commit f469675

Browse files
committed
[1.10>master] [MERGE #5481 @leirocks] seperate lockdown and closing states
Merge pull request #5481 from leirocks:counters Compact counters on function body is locked when JIT started and then we should never change it afterward (unless redefer and unlock first) however when function body cleanup we do cleanup the counters, at that time we unlock and then lock the counters, in between this, there might be JIT thread accessing the counters hence we Assert that counters should be in locked state. seperating lockdown and closing state to avoid this racing condition
2 parents 607485d + 47df46c commit f469675

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

lib/Runtime/Base/CompactCounters.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace Js
3232
private:
3333
FieldWithBarrier(uint8) fieldSize;
3434
#if DBG
35-
36-
mutable FieldWithBarrier(bool) isLockedDown;
35+
mutable FieldWithBarrier(bool) isLockedDown:1;
36+
mutable FieldWithBarrier(bool) isClosing:1;
3737
#endif
3838
typename FieldWithBarrier(Fields*) fields;
3939

@@ -42,6 +42,7 @@ namespace Js
4242
:fieldSize(0)
4343
#if DBG
4444
, isLockedDown(false)
45+
, isClosing(false)
4546
#endif
4647
{
4748
AllocCounters<uint8>(host);

lib/Runtime/Base/FunctionBody.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,19 +245,22 @@ namespace Js
245245
uint32 FunctionBody::GetCountField(FunctionBody::CounterFields fieldEnum) const
246246
{
247247
#if DBG
248-
Assert(ThreadContext::GetContextForCurrentThread() || counters.isLockedDown
248+
bool isCountersLockedDown = counters.isLockedDown;
249+
Assert(ThreadContext::GetContextForCurrentThread() || isCountersLockedDown
249250
|| (ThreadContext::GetCriticalSection()->IsLocked() && this->m_scriptContext->GetThreadContext()->GetFunctionBodyLock()->IsLocked())); // etw rundown
250251
#endif
251252
return counters.Get(fieldEnum);
252253
}
253254
uint32 FunctionBody::SetCountField(FunctionBody::CounterFields fieldEnum, uint32 val)
254255
{
255-
Assert(!counters.isLockedDown);
256+
DebugOnly(bool isCountersLockedDown = counters.isLockedDown);
257+
Assert(!isCountersLockedDown || counters.isClosing);
256258
return counters.Set(fieldEnum, val, this);
257259
}
258260
uint32 FunctionBody::IncreaseCountField(FunctionBody::CounterFields fieldEnum)
259261
{
260-
Assert(!counters.isLockedDown);
262+
DebugOnly(bool isCountersLockedDown = counters.isLockedDown);
263+
Assert(!isCountersLockedDown || counters.isClosing);
261264
return counters.Increase(fieldEnum, this);
262265
}
263266

@@ -7552,7 +7555,7 @@ namespace Js
75527555
return;
75537556
}
75547557

7555-
DebugOnly(this->UnlockCounters());
7558+
DebugOnly(this->SetIsClosing());
75567559

75577560
CleanupRecyclerData(isScriptContextClosing, false /* capture entry point cleanup stack trace */);
75587561
CleanUpForInCache(isScriptContextClosing);
@@ -7591,8 +7594,6 @@ namespace Js
75917594
#endif
75927595

75937596
this->cleanedUp = true;
7594-
7595-
DebugOnly(this->LockDownCounters());
75967597
}
75977598

75987599

lib/Runtime/Base/FunctionBody.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,7 @@ namespace Js
18941894
#if DBG
18951895
void LockDownCounters() { counters.isLockedDown = true; };
18961896
void UnlockCounters() { counters.isLockedDown = false; };
1897+
void SetIsClosing() { counters.isClosing = true; };
18971898
#endif
18981899

18991900
struct StatementMap

0 commit comments

Comments
 (0)