Skip to content

Commit

Permalink
removed RareEnablePreemptiveGC
Browse files Browse the repository at this point in the history
  • Loading branch information
VSadov committed Apr 27, 2024
1 parent 44102d3 commit f92c36e
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 256 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/debug/ee/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -3807,7 +3807,7 @@ HANDLE OpenWin32EventOrThrow(
// debugger may not be expecting it. Instead, just leave the lock and retry.
// When we leave, we'll enter coop mode first and get suspended if a suspension is in progress.
// Afterwards, we'll transition back into preemptive mode, and we'll block because this thread
// has been suspended by the debugger (see code:Thread::RareEnablePreemptiveGC).
// has been suspended by the debugger (see code:Thread::RareDisablePreemptiveGC).
#define SENDIPCEVENT_BEGIN_EX(pDebugger, thread, gcxStmt) \
{ \
FireEtwDebugIPCEventStart(); \
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/eedbginterfaceimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ void EEDbgInterfaceImpl::EnablePreemptiveGC(void)
CONTRACTL
{
NOTHROW;
DISABLED(GC_TRIGGERS); // Disabled because disabled in RareEnablePreemptiveGC()
GC_NOTRIGGER;
}
CONTRACTL_END;

Expand Down
25 changes: 0 additions & 25 deletions src/coreclr/vm/i386/asmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -126,31 +126,6 @@ LEAF_ENTRY RestoreFPUContext, _TEXT
ret 4
LEAF_END RestoreFPUContext, _TEXT

// -----------------------------------------------------------------------
// The out-of-line portion of the code to enable preemptive GC.
// After the work is done, the code jumps back to the "pRejoinPoint"
// which should be emitted right after the inline part is generated.
//
// Assumptions:
// ebx = Thread
// Preserves
// all registers except ecx.
//
// -----------------------------------------------------------------------
NESTED_ENTRY StubRareEnable, _TEXT, NoHandler
push eax
push edx

push ebx

CHECK_STACK_ALIGNMENT
call C_FUNC(StubRareEnableWorker)

pop edx
pop eax
ret
NESTED_END StubRareEnable, _TEXT

NESTED_ENTRY StubRareDisableTHROW, _TEXT, NoHandler
push eax
push edx
Expand Down
24 changes: 0 additions & 24 deletions src/coreclr/vm/i386/asmhelpers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ EXTERN __imp__RtlUnwind@16:DWORD
ifdef _DEBUG
EXTERN _HelperMethodFrameConfirmState@20:PROC
endif
EXTERN _StubRareEnableWorker@4:PROC
ifdef FEATURE_COMINTEROP
EXTERN _StubRareDisableHRWorker@4:PROC
endif ; FEATURE_COMINTEROP
Expand Down Expand Up @@ -394,29 +393,6 @@ endif
retn 8
_CallJitEHFinallyHelper@8 ENDP

;-----------------------------------------------------------------------
; The out-of-line portion of the code to enable preemptive GC.
; After the work is done, the code jumps back to the "pRejoinPoint"
; which should be emitted right after the inline part is generated.
;
; Assumptions:
; ebx = Thread
; Preserves
; all registers except ecx.
;
;-----------------------------------------------------------------------
_StubRareEnable proc public
push eax
push edx

push ebx
call _StubRareEnableWorker@4

pop edx
pop eax
retn
_StubRareEnable ENDP

ifdef FEATURE_COMINTEROP
_StubRareDisableHR proc public
push edx
Expand Down
12 changes: 0 additions & 12 deletions src/coreclr/vm/i386/cgenx86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,18 +911,6 @@ Stub *GenerateInitPInvokeFrameHelper()
RETURN psl->Link(SystemDomain::GetGlobalLoaderAllocator()->GetExecutableHeap());
}


extern "C" VOID STDCALL StubRareEnableWorker(Thread *pThread)
{
WRAPPER_NO_CONTRACT;

//printf("RareEnable\n");
pThread->RareEnablePreemptiveGC();
}




// Disable when calling into managed code from a place that fails via Exceptions
extern "C" VOID STDCALL StubRareDisableTHROWWorker(Thread *pThread)
{
Expand Down
104 changes: 11 additions & 93 deletions src/coreclr/vm/i386/stublinkerx86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@


#ifndef DACCESS_COMPILE

extern "C" VOID __cdecl StubRareEnable(Thread *pThread);
#ifdef FEATURE_COMINTEROP
extern "C" HRESULT __cdecl StubRareDisableHR(Thread *pThread);
#endif // FEATURE_COMINTEROP
Expand Down Expand Up @@ -2615,6 +2613,8 @@ void StubLinkerCPU::EmitComMethodStubEpilog(TADDR pFrameVptr,
PRECONDITION(rgRareLabels[0] != NULL && rgRareLabels[1] != NULL && rgRareLabels[2] != NULL);
PRECONDITION(rgRejoinLabels != NULL);
PRECONDITION(rgRejoinLabels[0] != NULL && rgRejoinLabels[1] != NULL && rgRejoinLabels[2] != NULL);
PRECONDITION(4 == sizeof( ((Thread*)0)->m_State ));
PRECONDITION(4 == sizeof( ((Thread*)0)->m_fPreemptiveGCDisabled ));
}
CONTRACTL_END;

Expand All @@ -2623,11 +2623,9 @@ void StubLinkerCPU::EmitComMethodStubEpilog(TADDR pFrameVptr,
// mov [ebx + Thread.GetFrame()], edi ;; restore previous frame
X86EmitIndexRegStore(kEBX, Thread::GetOffsetOfCurrentFrame(), kEDI);

//-----------------------------------------------------------------------
// Generate the inline part of disabling preemptive GC
//-----------------------------------------------------------------------
EmitEnable(rgRareLabels[2]); // rare gc
EmitLabel(rgRejoinLabels[2]); // rejoin for rare gc
// move byte ptr [ebx + Thread.m_fPreemptiveGCDisabled],0
X86EmitOffsetModRM(0xc6, (X86Reg)0, kEBX, Thread::GetOffsetOfGCFlag());
Emit8(0);

// add esp, popstack
X86EmitAddEsp(sizeof(GSCookie) + UnmanagedToManagedFrame::GetOffsetOfCalleeSavedRegisters());
Expand All @@ -2651,12 +2649,6 @@ void StubLinkerCPU::EmitComMethodStubEpilog(TADDR pFrameVptr,
// keeps on going past the previous "jmp eax".
X86EmitReturn(0);

//-----------------------------------------------------------------------
// The out-of-line portion of enabling preemptive GC - rarely executed
//-----------------------------------------------------------------------
EmitLabel(rgRareLabels[2]); // label for rare enable gc
EmitRareEnable(rgRejoinLabels[2]); // emit rare enable gc

//-----------------------------------------------------------------------
// The out-of-line portion of disabling preemptive GC - rarely executed
//-----------------------------------------------------------------------
Expand Down Expand Up @@ -2736,6 +2728,8 @@ void StubLinkerCPU::EmitSharedComMethodStubEpilog(TADDR pFrameVptr,
PRECONDITION(rgRareLabels[0] != NULL && rgRareLabels[1] != NULL && rgRareLabels[2] != NULL);
PRECONDITION(rgRejoinLabels != NULL);
PRECONDITION(rgRejoinLabels[0] != NULL && rgRejoinLabels[1] != NULL && rgRejoinLabels[2] != NULL);
PRECONDITION(4 == sizeof( ((Thread*)0)->m_State ));
PRECONDITION(4 == sizeof( ((Thread*)0)->m_fPreemptiveGCDisabled ));
}
CONTRACTL_END;

Expand All @@ -2748,12 +2742,13 @@ void StubLinkerCPU::EmitSharedComMethodStubEpilog(TADDR pFrameVptr,
X86EmitIndexRegStore(kEBX, Thread::GetOffsetOfCurrentFrame(), kEDI);

//-----------------------------------------------------------------------
// Generate the inline part of enabling preemptive GC
// Generate enabling preemptive GC
//-----------------------------------------------------------------------
EmitLabel(NoEntryLabel); // need to enable preemp mode even when we fail the disable as rare disable will return in coop mode

EmitEnable(rgRareLabels[2]); // rare enable gc
EmitLabel(rgRejoinLabels[2]); // rejoin for rare enable gc
// move byte ptr [ebx + Thread.m_fPreemptiveGCDisabled],0
X86EmitOffsetModRM(0xc6, (X86Reg)0, kEBX, Thread::GetOffsetOfGCFlag());
Emit8(0);

#ifdef PROFILING_SUPPORTED
// If profiling is active, emit code to notify profiler of transition
Expand Down Expand Up @@ -2800,12 +2795,6 @@ void StubLinkerCPU::EmitSharedComMethodStubEpilog(TADDR pFrameVptr,
// keeps on going past the previous "jmp ecx".
X86EmitReturn(0);

//-----------------------------------------------------------------------
// The out-of-line portion of enabling preemptive GC - rarely executed
//-----------------------------------------------------------------------
EmitLabel(rgRareLabels[2]); // label for rare enable gc
EmitRareEnable(rgRejoinLabels[2]); // emit rare enable gc

//-----------------------------------------------------------------------
// The out-of-line portion of disabling preemptive GC - rarely executed
//-----------------------------------------------------------------------
Expand Down Expand Up @@ -3335,77 +3324,6 @@ VOID StubLinkerCPU::EmitUnwindInfoCheckSubfunction()

#if defined(FEATURE_COMINTEROP) && defined(TARGET_X86)

//-----------------------------------------------------------------------
// Generates the inline portion of the code to enable preemptive GC. Hopefully,
// the inline code is all that will execute most of the time. If this code
// path is entered at certain times, however, it will need to jump out to
// a separate out-of-line path which is more expensive. The "pForwardRef"
// label indicates the start of the out-of-line path.
//
// Assumptions:
// ebx = Thread
// Preserves
// all registers except ecx.
//
//-----------------------------------------------------------------------
VOID StubLinkerCPU::EmitEnable(CodeLabel *pForwardRef)
{
CONTRACTL
{
STANDARD_VM_CHECK;

PRECONDITION(4 == sizeof( ((Thread*)0)->m_State ));
PRECONDITION(4 == sizeof( ((Thread*)0)->m_fPreemptiveGCDisabled ));
}
CONTRACTL_END;

// move byte ptr [ebx + Thread.m_fPreemptiveGCDisabled],0
X86EmitOffsetModRM(0xc6, (X86Reg)0, kEBX, Thread::GetOffsetOfGCFlag());
Emit8(0);

_ASSERTE(FitsInI1(Thread::TS_CatchAtSafePoint));

// test byte ptr [ebx + Thread.m_State], TS_CatchAtSafePoint
X86EmitOffsetModRM(0xf6, (X86Reg)0, kEBX, Thread::GetOffsetOfState());
Emit8(Thread::TS_CatchAtSafePoint);

// jnz RarePath
X86EmitCondJump(pForwardRef, X86CondCode::kJNZ);

#ifdef _DEBUG
X86EmitDebugTrashReg(kECX);
#endif

}


//-----------------------------------------------------------------------
// Generates the out-of-line portion of the code to enable preemptive GC.
// After the work is done, the code jumps back to the "pRejoinPoint"
// which should be emitted right after the inline part is generated.
//
// Assumptions:
// ebx = Thread
// Preserves
// all registers except ecx.
//
//-----------------------------------------------------------------------
VOID StubLinkerCPU::EmitRareEnable(CodeLabel *pRejoinPoint)
{
STANDARD_VM_CONTRACT;

X86EmitCall(NewExternalCodeLabel((LPVOID) StubRareEnable), 0);
#ifdef _DEBUG
X86EmitDebugTrashReg(kECX);
#endif
if (pRejoinPoint)
{
X86EmitNearJump(pRejoinPoint);
}

}


//-----------------------------------------------------------------------
// Generates the inline portion of the code to disable preemptive GC. Hopefully,
// the inline code is all that will execute most of the time. If this code
Expand Down
3 changes: 0 additions & 3 deletions src/coreclr/vm/i386/stublinkerx86.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,6 @@ class StubLinkerCPU : public StubLinker
}

#if defined(FEATURE_COMINTEROP) && defined(TARGET_X86)
VOID EmitEnable(CodeLabel *pForwardRef);
VOID EmitRareEnable(CodeLabel *pRejoinPoint);

VOID EmitDisable(CodeLabel *pForwardRef, BOOL fCallIn, X86Reg ThreadReg);
VOID EmitRareDisable(CodeLabel *pRejoinPoint);
VOID EmitRareDisableHRESULT(CodeLabel *pRejoinPoint, CodeLabel *pExitPoint);
Expand Down
7 changes: 0 additions & 7 deletions src/coreclr/vm/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1399,13 +1399,6 @@ Thread::Thread()
#ifdef _DEBUG
m_ulForbidTypeLoad = 0;
m_GCOnTransitionsOK = TRUE;
#endif

#ifdef ENABLE_CONTRACTS
m_ulEnablePreemptiveGCCount = 0;
#endif

#ifdef _DEBUG
dbg_m_cSuspendedThreads = 0;
dbg_m_cSuspendedThreadsWithoutOSLock = 0;
m_Creator.Clear();
Expand Down
19 changes: 0 additions & 19 deletions src/coreclr/vm/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -1397,11 +1397,6 @@ class Thread
// holding a spin lock in coop mode and transit to preemp mode will cause deadlock on GC
_ASSERTE ((m_StateNC & Thread::TSNC_OwnsSpinLock) == 0);

#ifdef ENABLE_CONTRACTS_IMPL
_ASSERTE(!GCForbidden());
TriggersGC(this);
#endif

// ------------------------------------------------------------------------
// ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** WARNING ** |
// ------------------------------------------------------------------------
Expand All @@ -1414,21 +1409,12 @@ class Thread
// ------------------------------------------------------------------------

m_fPreemptiveGCDisabled.StoreWithoutBarrier(0);
#ifdef ENABLE_CONTRACTS
m_ulEnablePreemptiveGCCount ++;
#endif // _DEBUG

// TODO: VS remove this. no polling on going to preemptive
// Delete RareEnablePreemptiveGC as well.
if (CatchAtSafePointOpportunistic())
RareEnablePreemptiveGC();
#endif
}

#if defined(STRESS_HEAP) && defined(_DEBUG)
void PerformPreemptiveGC();
#endif
void RareEnablePreemptiveGC();
void PulseGCMode();

//--------------------------------------------------------------
Expand Down Expand Up @@ -2804,11 +2790,6 @@ class Thread

#endif // TRACK_SYNC

private:
#ifdef ENABLE_CONTRACTS_DATA
ULONG m_ulEnablePreemptiveGCCount;
#endif // _DEBUG

private:
// For suspends:
CLREvent m_DebugSuspendEvent;
Expand Down
Loading

0 comments on commit f92c36e

Please sign in to comment.