Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSAutoreleasePool instance should be added to all threads. #52023

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
52680ba
Platform scripts now respect the MSBuild RuntimeHostConfigurationOption
AaronRobinsonMSFT Apr 28, 2021
5e79a7f
Add an NSAutoreleasePool to all runtime related threads.
AaronRobinsonMSFT Apr 28, 2021
66110bc
Build issues.
AaronRobinsonMSFT Apr 29, 2021
4b2e859
Remove unnecessary new native export for allocating an NSAutoreleaseP…
AaronRobinsonMSFT Apr 29, 2021
b34e3f3
Update header.
AaronRobinsonMSFT Apr 29, 2021
97be019
Initialize for platform prior to transferring control.
AaronRobinsonMSFT Apr 30, 2021
9827a3d
Address Linker issues by defining a throwing version of the API the
AaronRobinsonMSFT Apr 30, 2021
543ed7a
Update files for building based on their names.
AaronRobinsonMSFT Apr 30, 2021
83ae701
TargetsUnix is also set for OSX - sigh.
AaronRobinsonMSFT Apr 30, 2021
81c532a
Update src/coreclr/vm/threads.cpp
AaronRobinsonMSFT May 1, 2021
6258fc6
Handle other cases where specific platform initialization isn't
AaronRobinsonMSFT May 2, 2021
17d10bd
Remove the high level ThreadStoreLock flag and instead associate it
AaronRobinsonMSFT May 2, 2021
ffd77fb
Remove unused enum.
AaronRobinsonMSFT May 3, 2021
9fcbfcc
Rename m_Creater to m_Creator.
AaronRobinsonMSFT May 3, 2021
c1d674e
Merge remote-tracking branch 'upstream/main' into autoreleasepool_per…
AaronRobinsonMSFT May 4, 2021
d70d385
Root the AllocateThreadlocalAutoreleasePool function.
AaronRobinsonMSFT May 4, 2021
00578eb
The eventpipe streaming thread shouldn't init plaform.
AaronRobinsonMSFT May 4, 2021
b49109d
Add explicit drain call during managed thread termination.
AaronRobinsonMSFT May 4, 2021
f70c57b
Move rooting of CreateAutoreleasePool to coreclr XML files.
AaronRobinsonMSFT May 5, 2021
4f772b0
Revert "Update files for building based on their names."
AaronRobinsonMSFT May 5, 2021
2b7597a
rough_revert
AaronRobinsonMSFT May 5, 2021
4e221d8
Move CreateAutoreleasePool to CoreCLR specific cs file.
AaronRobinsonMSFT May 5, 2021
6cf9a21
CreateAutoreleasePool should always exist on coreclr.
AaronRobinsonMSFT May 5, 2021
8d814a0
Create new FEATURE_ define for NSAutoreleasePool support in CoreCLR.
AaronRobinsonMSFT May 5, 2021
1a22984
Redesign to make code shareable with Mono.
AaronRobinsonMSFT May 6, 2021
17892d1
Remove unnecessary rooting in XML.
AaronRobinsonMSFT May 6, 2021
f29e9fe
Conditionally clean up from platform initialization.
AaronRobinsonMSFT May 6, 2021
8e6d93d
Add support in Mono
AaronRobinsonMSFT May 6, 2021
6291c53
Review feedback for Mono.
AaronRobinsonMSFT May 7, 2021
cb601b0
Move linker root options to XML
AaronRobinsonMSFT May 7, 2021
e032245
Move NSAutoreleasePool alloc to managed code for managed Threads.
AaronRobinsonMSFT May 8, 2021
13b6bdc
Revert unnecessary changes.
AaronRobinsonMSFT May 8, 2021
6d6257e
Review feedback.
AaronRobinsonMSFT May 8, 2021
b42024e
Add cleanup code to Finalizer.
AaronRobinsonMSFT May 8, 2021
3030488
Add Descriptors file for OSX.
AaronRobinsonMSFT May 8, 2021
14f97d9
Fix contract for new managed thread initialization from native.
AaronRobinsonMSFT May 8, 2021
c6c0f5e
Remove local mainThread.
AaronRobinsonMSFT May 9, 2021
2b814dd
Revert additional public API changes.
AaronRobinsonMSFT May 9, 2021
b5afad6
Revert comment changes.
AaronRobinsonMSFT May 9, 2021
48f71dc
Review feedback.
AaronRobinsonMSFT May 9, 2021
57e567b
Update the feature name to FEATURE_OBJCMARSHAL which is what it will
AaronRobinsonMSFT May 9, 2021
86e3c7f
Remove boolean member in Thread.
AaronRobinsonMSFT May 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/workflow/trimming/feature-switches.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ configurations but their defaults might vary as any SDK can set the defaults dif
| HttpActivityPropagationSupport | System.Net.Http.EnableActivityPropagation | Any dependency related to diagnostics support for System.Net.Http is trimmed when set to false |
| HttpNativeHandler | System.Net.Http.UseNativeHttpHandler | HttpClient uses by default platform native implementation of HttpMessageHandler if set to true. |
| StartupHookSupport | System.StartupHookProvider.IsSupported | Startup hooks are disabled when set to false. Startup hook related functionality can be trimmed. |
| TBD | System.Threading.ThreadPool.EnableDispatchAutoreleasePool | When set to true, creates an NSAutoreleasePool around each thread pool work item on applicable platforms. |
| TBD | System.Threading.Thread.EnableAutoreleasePool | When set to true, creates an NSAutoreleasePool for each thread and thread pool work item on applicable platforms. |
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
| CustomResourceTypesSupport | System.Resources.ResourceManager.AllowCustomResourceTypes | Use of custom resource types is disabled when set to false. ResourceManager code paths that use reflection for custom types can be trimmed. |
| EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization | System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization | BinaryFormatter serialization support is trimmed when set to false. |

Expand Down
11 changes: 7 additions & 4 deletions src/coreclr/vm/ceemain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ void EEStartupHelper()
static ConfigDWORD breakOnEELoad;
EX_TRY
{
Thread* mainThread = NULL;
g_fEEInit = true;

#ifndef CROSSGEN_COMPILE
Expand Down Expand Up @@ -917,13 +918,13 @@ void EEStartupHelper()
}

// throws on error
SetupThread();
mainThread = SetupMainThread();
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved

#ifdef DEBUGGING_SUPPORTED
// Notify debugger once the first thread is created to finish initialization.
if (g_pDebugInterface != NULL)
{
g_pDebugInterface->StartupPhase2(GetThread());
g_pDebugInterface->StartupPhase2(mainThread);
}
#endif

Expand Down Expand Up @@ -1030,7 +1031,10 @@ void EEStartupHelper()
g_MiniMetaDataBuffMaxSize, MEM_COMMIT, PAGE_READWRITE);
#endif // FEATURE_MINIMETADATA_IN_TRIAGEDUMPS

#endif // CROSSGEN_COMPILE
// Initialize the platform specific context.
mainThread->InitPlatformContext();

#endif // !CROSSGEN_COMPILE

g_fEEStarted = TRUE;
g_EEStartupStatus = S_OK;
Expand All @@ -1056,7 +1060,6 @@ void EEStartupHelper()

// Perform CoreLib consistency check if requested
g_CoreLib.CheckExtended();

#endif // _DEBUG

#endif // !CROSSGEN_COMPILE
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/vm/corelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,9 @@ DEFINE_FIELD_U(_priority, ThreadBaseObject, m_Priority)
DEFINE_CLASS(THREAD, Threading, Thread)
DEFINE_METHOD(THREAD, INTERNAL_GET_CURRENT_THREAD, InternalGetCurrentThread, SM_RetIntPtr)
DEFINE_METHOD(THREAD, START_CALLBACK, StartCallback, IM_RetVoid)
#if defined(TARGET_OSX) || defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS)
DEFINE_METHOD(THREAD, ALLOCATETHREADLOCALAUTORELEASEPOOL, AllocateThreadlocalAutoreleasePool, SM_RetVoid)
#endif // defined(TARGET_OSX) || defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS)

DEFINE_CLASS(IOCB_HELPER, Threading, _IOCompletionCallback)
DEFINE_METHOD(IOCB_HELPER, PERFORM_IOCOMPLETION_CALLBACK, PerformIOCompletionCallback, SM_UInt_UInt_PtrNativeOverlapped_RetVoid)
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/vm/finalizerthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ void FinalizerThread::WaitForFinalizerEvent (CLREvent *event)
}

static BOOL s_FinalizerThreadOK = FALSE;
static BOOL s_InitializedFinalizerThreadForPlatform = FALSE;

VOID FinalizerThread::FinalizerThreadWorker(void *args)
{
Expand Down Expand Up @@ -289,6 +290,15 @@ VOID FinalizerThread::FinalizerThreadWorker(void *args)
bPriorityBoosted = TRUE;
}

// The Finalizer thread is started very early in EE startup. We defered
// initialization until a point we are sure the EE is up and running. At
// this point we make a single attempt and if it fails won't try again.
if (!s_InitializedFinalizerThreadForPlatform)
{
s_InitializedFinalizerThreadForPlatform = TRUE;
GetFinalizerThread()->InitPlatformContext();
}

JitHost::Reclaim();

GetFinalizerThread()->DisablePreemptiveGC();
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/gcenv.ee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ namespace
ClrFlsSetThreadType(ThreadType_GC);
args->Thread->SetGCSpecial(true);
STRESS_LOG_RESERVE_MEM(GC_STRESSLOG_MULTIPLY);
args->HasStarted = !!args->Thread->HasStarted(false);
args->HasStarted = !!args->Thread->HasStarted();

Thread* thread = args->Thread;
auto threadStart = args->ThreadStart;
Expand All @@ -1407,7 +1407,7 @@ namespace
return false;
}

args.Thread->SetBackground(TRUE, FALSE);
args.Thread->SetBackground(TRUE);
args.Thread->StartThread();

// Wait for the thread to be in its main loop
Expand Down
Loading