Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Make a single managed startup method for CoreCLR
A common configuration for coreclr is event source enabled, startup
hooks disabled, so at least one managed call is inevitable.  Since we
have to call into managed no matter what, let the trimmer determine
what happens once we get there.

This is different from mono where published trimmed apps may have both
startup hooks and event source disabled.  In that case we would rather
avoid a managed call to an empty method early in startup.
  • Loading branch information
lambdageek committed Jan 17, 2023
commit 53f042c06ba7bfde26cc40cd139ce9e2e1d77de3
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
<Compile Include="$(BclSourcesRoot)\System\RuntimeType.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Security\DynamicSecurityMethodAttribute.cs" />
<Compile Include="$(BclSourcesRoot)\System\String.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\StartupHookProvider.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\StubHelpers.cs" />
<Compile Include="$(BclSourcesRoot)\System\Text\StringBuilder.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Interlocked.CoreCLR.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using System.Runtime.Loader;

namespace System
{
internal partial static class StartupHookProvider
{
private static void ManagedStartup()
{
#if FEATURE_PERFTRACING
if (EventSource.IsSupported)
RuntimeEventSource.Initialize();
#endif

if (IsSupported)
ProcessStartupHooks();
}
}
}
34 changes: 3 additions & 31 deletions src/coreclr/vm/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,29 +1421,7 @@ static void RunMainPost()
}
}

static void RuntimeEventSourceInitialize()
{
#ifdef FEATURE_PERFTRACING
CONTRACTL
{
THROWS;
GC_TRIGGERS;
MODE_COOPERATIVE;
INJECT_FAULT(COMPlusThrowOM(););
}
CONTRACTL_END;

MethodDescCallSite eventSourceIsSupported(METHOD__EVENT_SOURCE__GET_IS_SUPPORTED);

if (eventSourceIsSupported.Call_RetBool(NULL))
{
MethodDescCallSite runtimeEventSourceInitialize(METHOD__RUNTIME_EVENT_SOURCE__INITIALIZE);
runtimeEventSourceInitialize.Call(NULL);
}
#endif
}

static void RunStartupHooks()
static void RunManagedStartup()
{
CONTRACTL
{
Expand All @@ -1454,14 +1432,8 @@ static void RunStartupHooks()
}
CONTRACTL_END;

MethodDescCallSite processStartupHooks(METHOD__STARTUP_HOOK_PROVIDER__PROCESS_STARTUP_HOOKS);
processStartupHooks.Call(NULL);
}

static void RunManagedStartup()
{
RuntimeEventSourceInitialize();
RunStartupHooks();
MethodDescCallSite managedStartup(METHOD__STARTUP_HOOK_PROVIDER__MANAGED_STARTUP);
managedStartup.Call(NULL);
}

INT32 Assembly::ExecuteMainMethod(PTRARRAYREF *stringArgs, BOOL waitForOtherThreads)
Expand Down
12 changes: 1 addition & 11 deletions src/coreclr/vm/corelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,6 @@ DEFINE_FIELD_U(_xptrs, ExceptionObject, _xptrs)
DEFINE_FIELD_U(_xcode, ExceptionObject, _xcode)
DEFINE_FIELD_U(_HResult, ExceptionObject, _HResult)

BEGIN_ILLINK_FEATURE_SWITCH(System.Diagnostics.Tracing.EventSource.IsSupported, true, true)
DEFINE_CLASS(EVENT_SOURCE, DiagnosticsTracing, EventSource)
DEFINE_STATIC_PROPERTY(EVENT_SOURCE, IS_SUPPORTED, IsSupported, Bool)
END_ILLINK_FEATURE_SWITCH()


DEFINE_CLASS(EXCEPTION, System, Exception)
DEFINE_METHOD(EXCEPTION, INTERNAL_PRESERVE_STACK_TRACE, InternalPreserveStackTrace, IM_RetVoid)
Expand Down Expand Up @@ -696,11 +691,6 @@ DEFINE_METHOD(RUNTIME_HELPERS, ALLOC_TAILCALL_ARG_BUFFER, AllocTailCallArgB
DEFINE_METHOD(RUNTIME_HELPERS, GET_TAILCALL_INFO, GetTailCallInfo, NoSig)
DEFINE_METHOD(RUNTIME_HELPERS, DISPATCH_TAILCALLS, DispatchTailCalls, NoSig)

BEGIN_ILLINK_FEATURE_SWITCH(System.Diagnostics.Tracing.EventSource.IsSupported, true, true)
DEFINE_CLASS(RUNTIME_EVENT_SOURCE, DiagnosticsTracing, RuntimeEventSource)
DEFINE_METHOD(RUNTIME_EVENT_SOURCE, INITIALIZE, Initialize, SM_RetVoid)
END_ILLINK_FEATURE_SWITCH()

DEFINE_CLASS(UNSAFE, CompilerServices, Unsafe)
DEFINE_METHOD(UNSAFE, AS_POINTER, AsPointer, NoSig)
DEFINE_METHOD(UNSAFE, BYREF_IS_NULL, IsNullRef, NoSig)
Expand Down Expand Up @@ -826,7 +816,7 @@ DEFINE_FIELD_U(rgiLastFrameFromForeignExceptionStackTrace, StackFrame
DEFINE_FIELD_U(iFrameCount, StackFrameHelper, iFrameCount)

DEFINE_CLASS(STARTUP_HOOK_PROVIDER, System, StartupHookProvider)
DEFINE_METHOD(STARTUP_HOOK_PROVIDER, PROCESS_STARTUP_HOOKS, ProcessStartupHooks, SM_RetVoid)
DEFINE_METHOD(STARTUP_HOOK_PROVIDER, MANAGED_STARTUP, ManagedStartup, SM_RetVoid)

DEFINE_CLASS(STREAM, IO, Stream)
DEFINE_METHOD(STREAM, BEGIN_READ, BeginRead, IM_ArrByte_Int_Int_AsyncCallback_Object_RetIAsyncResult)
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#define g_CollectionsNS g_SystemNS ".Collections"
#define g_ResourcesNS g_SystemNS ".Resources"
#define g_DiagnosticsNS g_SystemNS ".Diagnostics"
#define g_DiagnosticsTracingNS g_DiagnosticsNS ".Tracing"
#define g_CodeContractsNS g_DiagnosticsNS ".Contracts"
#define g_AssembliesNS g_SystemNS ".Configuration.Assemblies"
#define g_GlobalizationNS g_SystemNS ".Globalization"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace System
{
internal static class StartupHookProvider
internal partial static class StartupHookProvider
{
private const string StartupHookTypeName = "StartupHook";
private const string InitializeMethodName = "Initialize";
Expand Down