Repository navigation
[local gc] refactor apis for threading and suspension to avoid redundant calls in to the runtime - #16765
Conversation
…oc contexts to always operate on current thread
…nused call to GetThread
…eturn a bool indicating whether the mode was changed
| // Queries whether or not the current thread has preemptive GC disabled. | ||
| virtual | ||
| bool IsPreemptiveGCDisabled(Thread * pThread) = 0; | ||
| bool IsPreemptiveGCDisabled() = 0; |
There was a problem hiding this comment.
Nit: I always found the double negations like this very hard to reason about. Would it make sense to call this IsPreemptiveGCModeEnable ?
There was a problem hiding this comment.
If we were introducing from scratch I would agree with you, but I don't think it makes sense in this case. It is named after Thread::PreemptiveGCDisabled and makes sense to keep that way.
There was a problem hiding this comment.
Maybe we can replace all of the PreemptiveGCDisabled in the whole runtime and GC in a separate PR. I've also found the naming to make thinking about the state difficult. There are 312 occurences total.
| bool IsPreemptiveGCDisabled() = 0; | ||
|
|
||
| // Enables preemptive GC on the given thread. | ||
| // Enables preemptive GC on the current thread. |
There was a problem hiding this comment.
Could you please add comment on what this returns?
| @@ -245,13 +245,9 @@ class IGCToCLR { | |||
| virtual | |||
| bool TrapReturningThreads() = 0; | |||
There was a problem hiding this comment.
We should not need TrapReturningThreads now that the GC is keeping a mirror.
| pThread->EnablePreemptiveGC(); | ||
|
|
||
| Thread* pThread = ::GetThread(); | ||
| bool bToggleGC = GCToEEInterface::IsPreemptiveGCDisabled(); |
There was a problem hiding this comment.
This should just call the method on pThread. Not go through GCToEEInterface
| { | ||
| return pThread->EnablePreemptiveGC(); | ||
| Thread* pThread = ::GetThread(); | ||
| bool bToggleGC = GCToEEInterface::IsPreemptiveGCDisabled(); |
| BOOL reset_mm_p = TRUE; | ||
|
|
||
| bool g_fFinalizerRunOnShutDown = false; | ||
| VOLATILE(int32_t) g_fSuspensionPending = 0; |
There was a problem hiding this comment.
Nit: This can be in gccommon.cpp. If it is here, it is going to be compiled twice (once for server and once for workstation).
|
@jkotas I just added a commit that addresses all your feedback except the IsPreemptiveGCDisabled for the reasons I stated above. PTAL |
|
|
||
| // Enables preemptive GC on the given thread. | ||
| // Enables preemptive GC on the current thread. Returns true if the thread mode | ||
| // was changed and false if the therad mode wasn't changed or the thread is not |
| @@ -461,18 +461,17 @@ uint32_t gc_heap::user_thread_wait (GCEvent *event, BOOL no_mode_change, int tim | |||
| if (!no_mode_change) | |||
| { | |||
| pCurThread = GCToEEInterface::GetThread(); | |||
There was a problem hiding this comment.
This call to GetThread() and check for null is unnecessary. GCToEEInterface::EnablePreemptiveGC does the same check already.
|
|
||
| dwWaitResult = event->Wait(time_out_ms, FALSE); | ||
|
|
||
| if (!no_mode_change && mode) |
There was a problem hiding this comment.
Nit: This condition can be simplified to if (mode)
| enable_preemptive (); | ||
| GCToOSInterface::Sleep (1); | ||
| disable_preemptive (current_thread, TRUE); | ||
| disable_preemptive (TRUE); |
There was a problem hiding this comment.
TRUE [](start = 24, length = 4)
nit - true instead of TRUE, same with other places where disable is called
| #ifdef BACKGROUND_GC | ||
| Thread* current_thread = GCToEEInterface::GetThread(); | ||
| BOOL cooperative_mode = TRUE; | ||
| bool cooperative_mode = TRUE; |
There was a problem hiding this comment.
TRUE [](start = 32, length = 4)
nit - true
This starts with the work from #14907 and continues with the following:
This became a fairly large PR, let me know if I should separate out the allow_fgc/WaitLongerNoInstru work in to a separate PR. It should be fairly easy.
So far I've run the tests locally and have a GC stress run in progress. It's been about 12 hours with no issues found, I intend to run GC stress for 48 hours.