-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Implement Startup hooks support in Mono #80391
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
04bae4a
Implement startup hooks support in Mono
lambdageek c5ecf6a
Keep StartupHookProvider.ProcessStartupHooks under feature flag
lambdageek b1f9182
Don't catch/cleanup the exceptions from startup hooks.
lambdageek 05a7392
Add an ios simulator startup hook functional test
lambdageek c8e2c3b
Only initialize RuntimeEventSource if perftracing is supported
lambdageek bd46541
Actually implement the ios startup hook test
lambdageek 27cc89b
Implement Android functional test
lambdageek df74740
Add WASM functional test
lambdageek a889f7d
Make RuntimeEventSource.Initialize safe to call multiple times
lambdageek 9f41c60
Revert "Make RuntimeEventSource.Initialize safe to call multiple times"
lambdageek 2cf970e
coreclr: Call RuntimeEventSource.Initialize from EventPipeAdapter::Fi…
lambdageek 664f901
Call RuntimeEventSource.Initialize only if EventSource.IsSupported
lambdageek 7d830fa
fix line damage
lambdageek a02cf40
more whitespace
lambdageek 53f042c
Make a single managed startup method for CoreCLR
lambdageek b9d869e
fix build and line damage
lambdageek 3fddf4f
fixup
lambdageek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Suppressions.LibraryBuild.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/coreclr/System.Private.CoreLib/src/System/StartupHookProvider.CoreCLR.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 static partial class StartupHookProvider | ||
| { | ||
| private static void ManagedStartup() | ||
| { | ||
| #if FEATURE_PERFTRACING | ||
| if (EventSource.IsSupported) | ||
| RuntimeEventSource.Initialize(); | ||
| #endif | ||
|
|
||
| if (IsSupported) | ||
| ProcessStartupHooks(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...Tests/Android/Device_Emulator/StartupHook/Android.Device_Emulator.StartupHook.Test.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TestRuntime>true</TestRuntime> | ||
| <TargetFramework>$(NetCoreAppCurrent)</TargetFramework> | ||
| <MainLibraryFileName>Android.Device_Emulator.StartupHook.Test.dll</MainLibraryFileName> | ||
| <IncludesTestRunner>false</IncludesTestRunner> | ||
| <ExpectedExitCode>42</ExpectedExitCode> | ||
| <StartupHookSupport>true</StartupHookSupport> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="Program.cs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\TestAssets\StartupHookForFunctionalTest\StartupHookForFunctionalTest.csproj" /> | ||
| </ItemGroup> | ||
| </Project> |
23 changes: 23 additions & 0 deletions
23
src/tests/FunctionalTests/Android/Device_Emulator/StartupHook/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // 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.Threading; | ||
| using System.Threading.Tasks; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| public static class Program | ||
| { | ||
| public static int Main() | ||
| { | ||
| string appContextKey = "Test.StartupHookForFunctionalTest.DidRun"; | ||
| var data = (string) AppContext.GetData (appContextKey); | ||
|
|
||
| if (data != "Yes") { | ||
| string msg = $"Expected startup hook to set {appContextKey} to 'Yes', got '{data}'"; | ||
| Console.Error.WriteLine(msg); | ||
| return 104; | ||
| } | ||
| return 42; | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
src/tests/FunctionalTests/Android/Device_Emulator/StartupHook/runtimeconfig.template.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "configProperties": { | ||
| "STARTUP_HOOKS": "StartupHookForFunctionalTest" | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
...s/FunctionalTests/TestAssets/StartupHookForFunctionalTest/StartupHookForFunctionalTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| using System; | ||
|
|
||
| internal class StartupHook | ||
| { | ||
| public static void Initialize() | ||
| { | ||
| AppContext.SetData("Test.StartupHookForFunctionalTest.DidRun", "Yes"); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...nctionalTests/TestAssets/StartupHookForFunctionalTest/StartupHookForFunctionalTest.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <OutputType>Library</OutputType> | ||
| <TargetFramework>$(NetCoreAppCurrent)</TargetFramework> | ||
| <IsTestProject>false</IsTestProject> | ||
| <IsFunctionalTest>false</IsFunctionalTest> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="StartupHookForFunctionalTest.cs" /> | ||
| </ItemGroup> | ||
| </Project> |
30 changes: 30 additions & 0 deletions
30
src/tests/FunctionalTests/WebAssembly/Browser/StartupHook/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // 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.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices.JavaScript; | ||
|
|
||
| namespace Sample | ||
| { | ||
| public partial class Test | ||
| { | ||
| public static void Main() | ||
| { | ||
| } | ||
|
|
||
| [JSExport] | ||
| public static int TestMeaning() | ||
| { | ||
| string appContextKey = "Test.StartupHookForFunctionalTest.DidRun"; | ||
| var data = (string) AppContext.GetData (appContextKey); | ||
|
|
||
| if (data != "Yes") { | ||
| string msg = $"Expected startup hook to set {appContextKey} to 'Yes', got '{data}'"; | ||
| Console.Error.WriteLine(msg); | ||
| return 104; | ||
| } | ||
| return 42; | ||
| } | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
...nctionalTests/WebAssembly/Browser/StartupHook/WebAssembly.Browser.StartupHook.Test.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TestRuntime>true</TestRuntime> | ||
| <Scenario>WasmTestOnBrowser</Scenario> | ||
| <TestArchiveTestsRoot>$(TestArchiveRoot)browseronly/</TestArchiveTestsRoot> | ||
| <TestArchiveTestsDir>$(TestArchiveTestsRoot)$(OSPlatformConfig)/</TestArchiveTestsDir> | ||
| <DefineConstants>$(DefineConstants);TARGET_BROWSER</DefineConstants> | ||
| <ExpectedExitCode>42</ExpectedExitCode> | ||
| <WasmMainJSPath>main.js</WasmMainJSPath> | ||
| <StartupHookSupport>true</StartupHookSupport> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="Program.cs" /> | ||
| <WasmExtraFilesToDeploy Include="index.html" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\Microsoft.Interop.SourceGeneration\Microsoft.Interop.SourceGeneration.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
| <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices.JavaScript\gen\JSImportGenerator\JSImportGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
| <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices.JavaScript\src\System.Runtime.InteropServices.JavaScript.csproj" SkipUseReferenceAssembly="true"/> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\TestAssets\StartupHookForFunctionalTest\StartupHookForFunctionalTest.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
18 changes: 18 additions & 0 deletions
18
src/tests/FunctionalTests/WebAssembly/Browser/StartupHook/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <!DOCTYPE html> | ||
| <!-- Licensed to the .NET Foundation under one or more agreements. --> | ||
| <!-- The .NET Foundation licenses this file to you under the MIT license. --> | ||
| <html> | ||
|
|
||
| <head> | ||
| <title>Runtime config test</title> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <script type='module' src="./main.js"></script> | ||
| </head> | ||
|
|
||
| <body> | ||
| <h3 id="header">Runtime config test</h3> | ||
| Answer to the Ultimate Question of Life, the Universe, and Everything is : <span id="out"></span> | ||
| </body> | ||
|
|
||
| </html> |
24 changes: 24 additions & 0 deletions
24
src/tests/FunctionalTests/WebAssembly/Browser/StartupHook/main.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { dotnet } from './dotnet.js' | ||
|
|
||
| function wasm_exit(exit_code) { | ||
| var tests_done_elem = document.createElement("label"); | ||
| tests_done_elem.id = "tests_done"; | ||
| tests_done_elem.innerHTML = exit_code.toString(); | ||
| document.body.appendChild(tests_done_elem); | ||
|
|
||
| console.log(`WASM EXIT ${exit_code}`); | ||
| } | ||
|
|
||
| try { | ||
| const { getAssemblyExports } = await dotnet.create(); | ||
| const exports = await getAssemblyExports("WebAssembly.Browser.StartupHook.Test.dll"); | ||
| const testMeaning = exports.Sample.Test.TestMeaning; | ||
| const ret = testMeaning(); | ||
| document.getElementById("out").innerHTML = `${ret}`; | ||
| console.debug(`ret: ${ret}`); | ||
|
|
||
| let exit_code = ret; | ||
| wasm_exit(exit_code); | ||
| } catch (err) { | ||
| console.log(`WASM ERROR ${err}`); | ||
| } |
5 changes: 5 additions & 0 deletions
5
src/tests/FunctionalTests/WebAssembly/Browser/StartupHook/runtimeconfig.template.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "configProperties": { | ||
| "STARTUP_HOOKS": "StartupHookForFunctionalTest" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we won't call the same startup hook logic as CoreCLR and remove the call in ep_rt_mono_init_finish on Mono? If there might be a scenario in the future where the managed parts gets included without EventPipe on Mono (currenlty not the case), then we would need to change this since ep_finish_init would then just be a stub implementation., but the user still expect to get these events delivered over alternative provider. We could of course do that when needed, or we could just do it now, since we get the support that previously was missing and why init of runtime events ended up in ep_rt_mono_init_finish. Anything with the current startup hook implementation that would prevent us from getting the same behavior as we currently have, but done from startup hook instead of ep_rt_mono_init_finish?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two separate issues:
ManagedStartupcall as CoreCLR.I think it's probably reasonable to do something about 1 - we can move the invoke of RuntimeEventSource.Initialize out of EP and into
mini_init, for example.For 2, the issue is that
ManagedStartupcannot be trimmed - there is no way to tell the trimmer "remove a method if 2 feature switches are both disabled". So we would always be paying for a call to managed even if event source and startup hooks are both disabled (for example on single-threaded WASM).So if you think it makes sense to start decoupling EventSource and EventPipe in Mono now, we can do that. But I don't think it makes sense to do 2. Of course if we had some other managed initialization that had to be done explicitly on all platforms, then we could roll all that logic into one function.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, understood, if we still won't end up on the same solution as CoreCLR, then I believe we can keep things as is for now, and move the call to init when/if we ever have a need to separate init of runtime event source from EventPipe availability.