-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hot_reload] Add instance fields (#76462)
* [hot_reload] Add new AddInstanceField test * Add AddInstanceFieldToExistingType capability to runtime * Add instance field: reflection and nested struct * make TypedReference work with added fields * Add FieldInfo.SetValue testcase * make FieldInfo.SetValue work * Implement LDFLDA opcode for added fields; add test * Disable test on CoreCLR *adding a wasm debugger test * make the debugger test a bit more interesting * implement a debugger test that gets/sets instance fields * Clear the debugger type cache on EnC update we only need to clear the type on which fields or methods were added. but right now we just clear the whole cache * [sdb] implement get/set field for added instance fields * [handles] remove the field getter/setter macros They had no callers, and now we don't do things this way - we assume the enclosing object had been pinned by a stack reference. * [metadata-update] comments on asserts * implement mono_field_get_addr added field support * remove last use of MONO_HANDLE_SET_FIELD_REF * WeakAttribute is not picked up from added fields * Add a test for an array with RVA * Impl mono_metadata_field_info_full * mono_class_get_field_token * mono_field_get_rva * Add SetValueDirect/GetValueDirect test (failing) * Implement GetValueDirect - hot reload test passes now * Added test for auto property; crashes in ves_icall_RuntimePropertyInfo_get_property_info * add_props Note: we're not doing anything with the new PropertyMap row Note2: we get MethodSemantics rows for properties that got updated, and we're currently ignoring them. Need to check that this is reasonable. (A test would be to use reflection to grab a getter or setter whose method body was changed and then try and invoke it and verify that we're calling the correct method.) * fixup comment - repeated MethodSemantics rows can happen * added properties iteration * protect callers of mono_class_get_property_token * make mono_class_get_property_token work for added props * add test for adding instance event * basic event reflection works * Fire the new event, too * make reflection MetadataToken work * remove unused ifdefs and fix whitespace Fixes #63643
- Loading branch information
1 parent
dc1efbf
commit 2ae7f5d
Showing
39 changed files
with
1,220 additions
and
156 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...lyUpdate/System.Reflection.Metadata.ApplyUpdate.Test.AddInstanceField/AddInstanceField.cs
This file contains 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,51 @@ | ||
// 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 AddInstanceField | ||
{ | ||
public AddInstanceField () { | ||
} | ||
|
||
public string GetStringField => _stringField; | ||
public double GetDoubleField => _doubleField; | ||
|
||
private string _stringField; | ||
private double _doubleField; | ||
|
||
private int[] _intArrayFieldWithInit = new[] { 2, 4, 6, 8, 10, 12 }; | ||
|
||
public void TestMethod () { | ||
_stringField = "abcd"; | ||
_doubleField = 3.14159; | ||
} | ||
|
||
public int GetIntArrayLength() => _intArrayFieldWithInit?.Length ?? -1; | ||
public int GetIntArrayElt(int i) => _intArrayFieldWithInit[i]; | ||
|
||
public void IncRefDouble (ref double d) | ||
{ | ||
d += 1.0; | ||
} | ||
|
||
public string GetStringProp => string.Empty; | ||
|
||
public event EventHandler<double> ExistingEvent; | ||
|
||
public double Accumulator; | ||
|
||
private void AccumHandler (object sender, double value) => Accumulator += value; | ||
|
||
public double FireEvents() { | ||
Accumulator = 0.0; | ||
ExistingEvent += AccumHandler; | ||
ExistingEvent(this, 123.0); | ||
ExistingEvent -= AccumHandler; | ||
|
||
return Accumulator; | ||
} | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...pdate/System.Reflection.Metadata.ApplyUpdate.Test.AddInstanceField/AddInstanceField_v1.cs
This file contains 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,89 @@ | ||
// 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 AddInstanceField | ||
{ | ||
public AddInstanceField () { | ||
_doubleField2 = 5.5; | ||
_stringField2 = "New Initial Value"; | ||
NewStructField = new NewStruct { | ||
D = -1985.0, | ||
O = new int[2] { 15, 17 }, | ||
}; | ||
// a little bit ldflda testing | ||
IncRefDouble (ref NewStructField.D); | ||
IncRefDouble (ref _doubleField2); | ||
|
||
AddedStringAutoProp = "abcd"; | ||
|
||
AddedEvent += MyHandler; | ||
|
||
void MyHandler (object sender, double data) { | ||
} | ||
} | ||
|
||
public void IncRefDouble (ref double d) | ||
{ | ||
d += 1.0; | ||
} | ||
|
||
public string GetStringField => _stringField2; | ||
public double GetDoubleField => _doubleField2; | ||
|
||
private string _stringField; | ||
private string _stringField2; | ||
private double _doubleField; | ||
private double _doubleField2; | ||
|
||
private int[] _intArrayFieldWithInit = new[] { 2, 4, 6, 8, 10, 12 }; | ||
private int[] _intArrayFieldWithInit2 = new[] { 1, 3, 5, 7, 9, 11 }; | ||
|
||
public void TestMethod () { | ||
_stringField = "spqr"; | ||
_stringField2 = "4567"; | ||
_doubleField = 2.71828; | ||
_doubleField2 = 0.707106; | ||
AddedStringAutoProp = AddedStringAutoProp + "Test"; | ||
} | ||
|
||
public int GetIntArrayLength() => _intArrayFieldWithInit2?.Length ?? -1; | ||
public int GetIntArrayElt(int i) => _intArrayFieldWithInit2[i]; | ||
|
||
public struct NewStruct | ||
{ | ||
public double D; | ||
public object O; | ||
} | ||
|
||
public NewStruct NewStructField; | ||
|
||
public string GetStringProp => AddedStringAutoProp; | ||
|
||
public string AddedStringAutoProp { get; set; } | ||
|
||
public event EventHandler<double> ExistingEvent; | ||
public event EventHandler<double> AddedEvent; | ||
|
||
public double Accumulator; | ||
|
||
private void AccumHandler (object sender, double value) => Accumulator += value; | ||
|
||
public double FireEvents() { | ||
Accumulator = 0.0; | ||
ExistingEvent += AccumHandler; | ||
ExistingEvent(this, 123.0); | ||
ExistingEvent -= AccumHandler; | ||
|
||
AddedEvent += AccumHandler; | ||
AddedEvent(this, 123.0); | ||
AddedEvent -= AccumHandler; | ||
|
||
return Accumulator; | ||
} | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...Test.AddInstanceField/System.Reflection.Metadata.ApplyUpdate.Test.AddInstanceField.csproj
This file contains 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,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<RootNamespace>System.Runtime.Loader.Tests</RootNamespace> | ||
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework> | ||
<TestRuntime>true</TestRuntime> | ||
<DeltaScript>deltascript.json</DeltaScript> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="AddInstanceField.cs" /> | ||
</ItemGroup> | ||
</Project> |
6 changes: 6 additions & 0 deletions
6
...ApplyUpdate/System.Reflection.Metadata.ApplyUpdate.Test.AddInstanceField/deltascript.json
This file contains 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,6 @@ | ||
{ | ||
"changes": [ | ||
{"document": "AddInstanceField.cs", "update": "AddInstanceField_v1.cs"}, | ||
] | ||
} | ||
|
This file contains 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 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 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 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
Oops, something went wrong.