Skip to content

Commit

Permalink
Share TypedReference managed code between CoreCLR and Mono (dotnet#60636
Browse files Browse the repository at this point in the history
)

* [mono] Rename common TypedReference fields to the same names as CoreCLR

* Share TypedReference managed code between CoreCLR and Mono

The field layout is different. Although both have `_value` as a pointer to the
value (and this PR updates mono to use a `ByReference<byte>` for that pointer,
same as CoreCLR), and a `_type` which is a type handle (`MonoClass` in mono on
the native side), in addition, mono also has a RuntimeTypeHandle (`MonoType` in
mono on the native side) that is used to help the JIT.

But the managed code is identical and only uses `_value` and `_type`.
  • Loading branch information
lambdageek authored Oct 20, 2021
1 parent 353c27d commit ab10871
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
<Compile Include="$(BclSourcesRoot)\System\Threading\Timer.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\WaitHandle.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Type.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypedReference.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypedReference.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypeLoadException.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypeNameParser.cs" />
<Compile Include="$(BclSourcesRoot)\System\ValueType.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// TypedReference is basically only ever seen on the call stack, and in param arrays.
// These are blob that must be dealt with by the compiler.

using System.Reflection;
using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;

namespace System
{
[System.Runtime.Versioning.NonVersionable] // This only applies to field layout
public ref partial struct TypedReference
{
private readonly ByReference<byte> _value;
private readonly IntPtr _type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Type.Helpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TypeAccessException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TypeCode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TypedReference.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TypeInitializationException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TypeLoadException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TypeUnloadedException.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
namespace System
{
[CLSCompliant(false)]
[System.Runtime.Versioning.NonVersionable] // This only applies to field layout
public ref struct TypedReference
public ref partial struct TypedReference
{
private readonly ByReference<byte> _value;
private readonly IntPtr _type;

public static TypedReference MakeTypedReference(object target, FieldInfo[] flds)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<Compile Include="$(BclSourcesRoot)\System\String.Mono.cs" />
<Compile Include="$(BclSourcesRoot)\System\Type.Mono.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypeIdentifier.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypedReference.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypedReference.Mono.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypeLoadException.Mono.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypeNameParser.cs" />
<Compile Include="$(BclSourcesRoot)\System\ValueType.cs" />
Expand Down
20 changes: 20 additions & 0 deletions src/mono/System.Private.CoreLib/src/System/TypedReference.Mono.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Reflection;
using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;

namespace System
{
public ref partial struct TypedReference
{
#region sync with object-internals.h
#pragma warning disable CA1823 // used by runtime
private readonly RuntimeTypeHandle type;
private readonly ByReference<byte> _value;
private readonly IntPtr _type;
#pragma warning restore CA1823
#endregion
}
}
108 changes: 0 additions & 108 deletions src/mono/System.Private.CoreLib/src/System/TypedReference.cs

This file was deleted.

0 comments on commit ab10871

Please sign in to comment.