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

Mono hot reload reorg and beginning (disabled) add method support #61853

Merged
merged 20 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
36d9693
checkpoint: allow adding methods to existing classes.
lambdageek Jun 8, 2021
0c4aa74
fixme in loader
lambdageek Jun 22, 2021
c68b895
[metadata] Add mono_metadata_table_num_rows
lambdageek Jul 13, 2021
d0b7d77
add table to ptr table helper
lambdageek Jul 13, 2021
25e2fb8
Param attr lookups for deltas can have param_index == 0
lambdageek Jul 13, 2021
099edb5
WIP: start adding support for parameter additions.
lambdageek Jul 13, 2021
6cbee0b
WIP: add MethodDef -> TypeDef lookup
lambdageek Jul 15, 2021
8cfb9fb
Add hot reload test for lambda capturing this
lambdageek Jul 15, 2021
287654e
clarify comments about MONO_METHOD_PARAMLIST
lambdageek Jul 15, 2021
6336699
[hot_reload] Store debug info of updated methods
lambdageek Jul 16, 2021
cdfb9a7
[hot_reload] Allocate modifiable tables in DeltaInfo
lambdageek Nov 12, 2021
4b250b9
[mini] Allow MONO_VERBOSE_METHOD='*:*'
lambdageek Nov 12, 2021
cdcf003
populate mutated table rows
lambdageek Nov 12, 2021
ac0ac83
[hot_reload] Switch lookups to the mutant tables
lambdageek Nov 16, 2021
25253f7
cleanup: remove of effective_table calculation
lambdageek Nov 19, 2021
38b17da
cleanup: Remove relative_delta_index from component API
lambdageek Nov 19, 2021
d1c1c8e
cleanup: Pass DeltaInfo to relative_delta_index
lambdageek Nov 19, 2021
629075d
cleanup: Store a list of DeltaInfo in the BaselineInfo
lambdageek Nov 19, 2021
3114871
Turn off method addition support, for now
lambdageek Nov 19, 2021
6e56f85
Fix null ptr when checking for updated ppdb info
lambdageek Nov 29, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;


namespace System.Reflection.Metadata.ApplyUpdate.Test
{
public class AddLambdaCapturingThis
{
public AddLambdaCapturingThis () {
field = "abcd";
}

public string GetField => field;

private string field;

public string TestMethod () {
// capture 'this' but no locals
Func<string,string> fn = s => field;
return "123";
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;


namespace System.Reflection.Metadata.ApplyUpdate.Test
{
public class AddLambdaCapturingThis
{
public AddLambdaCapturingThis () {
field = "abcd";
}

public string GetField => field;

private string field;

public string TestMethod () {
// capture 'this' but no locals
Func<string,string> fn = s => NewMethod (s + field, 42);
return fn ("123");
}

private string NewMethod (string s, int i) {
return i.ToString() + s;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>System.Runtime.Loader.Tests</RootNamespace>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
<TestRuntime>true</TestRuntime>
<DeltaScript>deltascript.json</DeltaScript>
</PropertyGroup>
<ItemGroup>
<Compile Include="AddLambdaCapturingThis.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"changes": [
{"document": "AddLambdaCapturingThis.cs", "update": "AddLambdaCapturingThis_v1.cs"},
]
}

20 changes: 20 additions & 0 deletions src/libraries/System.Runtime.Loader/tests/ApplyUpdateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,26 @@ public void AsyncMethodChanges()
});
}

[ActiveIssue ("https://github.com/dotnet/runtime/issues/50249", TestRuntimes.Mono)]
[ConditionalFact(typeof(ApplyUpdateUtil), nameof(ApplyUpdateUtil.IsSupported))]
public static void TestAddLambdaCapturingThis()
{
ApplyUpdateUtil.TestCase(static () =>
{
var assm = typeof(System.Reflection.Metadata.ApplyUpdate.Test.AddLambdaCapturingThis).Assembly;

var x = new System.Reflection.Metadata.ApplyUpdate.Test.AddLambdaCapturingThis();

Assert.Equal("123", x.TestMethod());

ApplyUpdateUtil.ApplyUpdate(assm);

string result = x.TestMethod();
Assert.Equal("42123abcd", result);
});
}


class NonRuntimeAssembly : Assembly
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.LambdaBodyChange\System.Reflection.Metadata.ApplyUpdate.Test.LambdaBodyChange.csproj" />
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.LambdaCapturesThis\System.Reflection.Metadata.ApplyUpdate.Test.LambdaCapturesThis.csproj" />
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.FirstCallAfterUpdate\System.Reflection.Metadata.ApplyUpdate.Test.FirstCallAfterUpdate.csproj" />
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.AddLambdaCapturingThis\System.Reflection.Metadata.ApplyUpdate.Test.AddLambdaCapturingThis.csproj" />

</ItemGroup>
<ItemGroup Condition="'$(TargetOS)' == 'Browser'">
Expand All @@ -60,6 +61,7 @@
<TrimmerRootAssembly Condition="$([System.String]::Copy('%(ResolvedFileToPublish.FileName)%(ResolvedFileToPublish.Extension)').EndsWith('System.Reflection.Metadata.ApplyUpdate.Test.LambdaBodyChange.dll'))" Include="%(ResolvedFileToPublish.FullPath)" />
<TrimmerRootAssembly Condition="$([System.String]::Copy('%(ResolvedFileToPublish.FileName)%(ResolvedFileToPublish.Extension)').EndsWith('System.Reflection.Metadata.ApplyUpdate.Test.LambdaCapturesThis.dll'))" Include="%(ResolvedFileToPublish.FullPath)" />
<TrimmerRootAssembly Condition="$([System.String]::Copy('%(ResolvedFileToPublish.FileName)%(ResolvedFileToPublish.Extension)').EndsWith('System.Reflection.Metadata.ApplyUpdate.Test.FirstCallAfterUpdate.dll'))" Include="%(ResolvedFileToPublish.FullPath)" />
<TrimmerRootAssembly Condition="$([System.String]::Copy('%(ResolvedFileToPublish.FileName)%(ResolvedFileToPublish.Extension)').EndsWith('System.Reflection.Metadata.ApplyUpdate.Test.AddLambdaCapturingThis.dll'))" Include="%(ResolvedFileToPublish.FullPath)" />
</ItemGroup>
</Target>

Expand Down
45 changes: 33 additions & 12 deletions src/mono/mono/component/hot_reload-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ static void
hot_reload_stub_cleanup_on_close (MonoImage *image);

static void
hot_reload_stub_effective_table_slow (const MonoTableInfo **t, int *idx);

static int
hot_reload_stub_relative_delta_index (MonoImage *image_dmeta, int token);
hot_reload_stub_effective_table_slow (const MonoTableInfo **t, int idx);

static void
hot_reload_stub_close_except_pools_all (MonoImage *base_image);
Expand All @@ -65,6 +62,15 @@ hot_reload_stub_get_updated_method_ppdb (MonoImage *base_image, uint32_t idx);
static gboolean
hot_reload_stub_has_modified_rows (const MonoTableInfo *table);

static int
hot_reload_stub_table_num_rows_slow (MonoImage *image, int table_index);

static GArray*
hot_reload_stub_get_added_methods (MonoClass *klass);

static uint32_t
hot_reload_stub_method_parent (MonoImage *image, uint32_t method_index);

static MonoComponentHotReload fn_table = {
{ MONO_COMPONENT_ITF_VERSION, &hot_reload_stub_available },
&hot_reload_stub_set_fastpath_data,
Expand All @@ -74,7 +80,6 @@ static MonoComponentHotReload fn_table = {
&hot_reload_stub_get_thread_generation,
&hot_reload_stub_cleanup_on_close,
&hot_reload_stub_effective_table_slow,
&hot_reload_stub_relative_delta_index,
&hot_reload_stub_apply_changes,
&hot_reload_stub_close_except_pools_all,
&hot_reload_stub_close_all,
Expand All @@ -83,6 +88,9 @@ static MonoComponentHotReload fn_table = {
&hot_reload_stub_delta_heap_lookup,
&hot_reload_stub_get_updated_method_ppdb,
&hot_reload_stub_has_modified_rows,
&hot_reload_stub_table_num_rows_slow,
&hot_reload_stub_get_added_methods,
&hot_reload_stub_method_parent,
};

static bool
Expand Down Expand Up @@ -135,13 +143,7 @@ hot_reload_stub_cleanup_on_close (MonoImage *image)
}

void
hot_reload_stub_effective_table_slow (const MonoTableInfo **t, int *idx)
{
g_assert_not_reached ();
}

static int
hot_reload_stub_relative_delta_index (MonoImage *image_dmeta, int token)
hot_reload_stub_effective_table_slow (const MonoTableInfo **t, int idx)
{
g_assert_not_reached ();
}
Expand Down Expand Up @@ -192,6 +194,25 @@ hot_reload_stub_has_modified_rows (const MonoTableInfo *table)
return FALSE;
}

static int
hot_reload_stub_table_num_rows_slow (MonoImage *image, int table_index)
{
g_assert_not_reached (); /* should always take the fast path */
}

static GArray*
hot_reload_stub_get_added_methods (MonoClass *klass)
{
return NULL;
}

static uint32_t
hot_reload_stub_method_parent (MonoImage *image, uint32_t method_index)
{
return 0;
}


MONO_COMPONENT_EXPORT_ENTRYPOINT
MonoComponentHotReload *
mono_component_hot_reload_init (void)
Expand Down
Loading