Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

[local gc] refactor apis for threading and suspension to avoid redundant calls in to the runtime - #16765

Merged
davmason merged 11 commits into
dotnet:masterfrom
davmason:gc_threading
Mar 13, 2018
Merged

davmason merged 11 commits into
dotnet:masterfrom
davmason:gc_threading

Conversation

@davmason

@davmason davmason commented Mar 5, 2018

Copy link
Copy Markdown

This starts with the work from #14907 and continues with the following:

  • GCToEEInterface::EnablePreemptiveGC now returns a bool indicating whether the thread mode was changed
  • Callback apis for the GC to be notified when the runtime is trapping threads
  • Changing allow_fgc to check if the runtime is trapping threads rather than if the current thread is at a safe point
  • Removing CatchAtSafepoint from the EE interface
  • Refactoring WaitLongerNoInstru and WaitLonger to only call in to the runtime to set preemptive/cooperative mode

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.

@davmason davmason added this to the 2.1.0 milestone Mar 5, 2018
@davmason davmason self-assigned this Mar 5, 2018
@davmason
davmason requested review from Maoni0 and jkotas March 5, 2018 22:18
Comment thread src/gc/gcinterface.ee.h
// Queries whether or not the current thread has preemptive GC disabled.
virtual
bool IsPreemptiveGCDisabled(Thread * pThread) = 0;
bool IsPreemptiveGCDisabled() = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I always found the double negations like this very hard to reason about. Would it make sense to call this IsPreemptiveGCModeEnable ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/gc/gcinterface.ee.h Outdated
bool IsPreemptiveGCDisabled() = 0;

// Enables preemptive GC on the given thread.
// Enables preemptive GC on the current thread.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add comment on what this returns?

Comment thread src/gc/gcinterface.ee.h Outdated
@@ -245,13 +245,9 @@ class IGCToCLR {
virtual
bool TrapReturningThreads() = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not need TrapReturningThreads now that the GC is keeping a mirror.

Comment thread src/vm/gcenv.ee.cpp Outdated
pThread->EnablePreemptiveGC();

Thread* pThread = ::GetThread();
bool bToggleGC = GCToEEInterface::IsPreemptiveGCDisabled();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just call the method on pThread. Not go through GCToEEInterface

Comment thread src/gc/sample/gcenv.ee.cpp Outdated
{
return pThread->EnablePreemptiveGC();
Thread* pThread = ::GetThread();
bool bToggleGC = GCToEEInterface::IsPreemptiveGCDisabled();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment thread src/gc/gc.cpp Outdated
BOOL reset_mm_p = TRUE;

bool g_fFinalizerRunOnShutDown = false;
VOLATILE(int32_t) g_fSuspensionPending = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@davmason

davmason commented Mar 8, 2018

Copy link
Copy Markdown
Author

@jkotas I just added a commit that addresses all your feedback except the IsPreemptiveGCDisabled for the reasons I stated above. PTAL

Comment thread src/gc/gcinterface.ee.h Outdated

// 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: therad

Comment thread src/gc/gcee.cpp Outdated
@@ -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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call to GetThread() and check for null is unnecessary. GCToEEInterface::EnablePreemptiveGC does the same check already.

Comment thread src/gc/gcee.cpp Outdated

dwWaitResult = event->Wait(time_out_ms, FALSE);

if (!no_mode_change && mode)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This condition can be simplified to if (mode)

Comment thread src/gc/gc.cpp Outdated
enable_preemptive ();
GCToOSInterface::Sleep (1);
disable_preemptive (current_thread, TRUE);
disable_preemptive (TRUE);

@Maoni0 Maoni0 Mar 12, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TRUE [](start = 24, length = 4)

nit - true instead of TRUE, same with other places where disable is called

Comment thread src/gc/gc.cpp Outdated
#ifdef BACKGROUND_GC
Thread* current_thread = GCToEEInterface::GetThread();
BOOL cooperative_mode = TRUE;
bool cooperative_mode = TRUE;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TRUE [](start = 32, length = 4)

nit - true

@Maoni0 Maoni0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants