Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
57fe91c
Move DependentHandle to System.Runtime
Sergio0694 Jun 15, 2021
b1f54b5
Update DependentHandle APIs to follow review
Sergio0694 Jun 15, 2021
b331b8f
Make DependentHandle type public
Sergio0694 Jun 15, 2021
a96fa3f
Update DependentHandle on Mono runtime
Sergio0694 Jun 15, 2021
16fdf0e
Add allocation checks to DependentHandle APIs
Sergio0694 Jun 15, 2021
748d88e
Add more unit tests for new public DependentHandle APIs
Sergio0694 Jun 16, 2021
247fa5a
Add faster, unsafe internal APIs versions to DependentHandle
Sergio0694 Jun 16, 2021
66d2ac5
Naming improvements to Ephemeron type
Sergio0694 Jun 16, 2021
4067ac3
Code style tweaks, improved nullability annotations
Sergio0694 Jun 16, 2021
1670339
Remove incorrect DependentHandle comment on Mono
Sergio0694 Jun 16, 2021
96cfc91
Add default Dispose test for DependentHandle
Sergio0694 Jun 16, 2021
6a8db56
Fix race condition in DependentHandle on Mono
Sergio0694 Jun 16, 2021
1601d88
Optimize DependentHandle.nGetPrimary on CoreCLR
Sergio0694 Jun 16, 2021
359938b
Small IL codegen improvement in DependentHandle.nGetPrimary
Sergio0694 Jun 16, 2021
312851a
Simplify comments, add #ifdef for using directive
Sergio0694 Jun 16, 2021
0145a76
Minor code style tweaks
Sergio0694 Jun 16, 2021
4925877
Change nGetPrimaryAndSecondary to nGetSecondary
Sergio0694 Jun 16, 2021
1664a95
Minor code refactoring to DependentHandle on Mono
Sergio0694 Jun 16, 2021
ca515b6
Rename DependentHandle FCalls
Sergio0694 Jun 16, 2021
08df598
Remove DependentHandle.UnsafeGetTargetAndDependent
Sergio0694 Jun 16, 2021
4e2b624
Remove DependentHandle.GetTargetAndDependent
Sergio0694 Jun 16, 2021
4e03297
Fix FCall path for internal DependentHandle APIs
Sergio0694 Jun 16, 2021
25b34c2
Add more DependentHandle unit tests
Sergio0694 Jun 17, 2021
01f32a3
Reintroduce DependentHandle.GetTargetAndDependent()
Sergio0694 Jun 17, 2021
b3963f2
Minor IL tweaks to produce smaller IR in the JIT
Sergio0694 Jun 18, 2021
34e1bcb
Add DependentHandle.StopTracking() API
Sergio0694 Jun 21, 2021
9fd1da4
Rename InternalSetTarget to StopTracking, remove redundant param
Sergio0694 Jun 21, 2021
d7146e0
Remove FCUnique from InternalStopTracking
Sergio0694 Jun 21, 2021
c9c6325
Update API surface to match approved specs from API review
Sergio0694 Jun 22, 2021
c463d54
Update DependentHandle XML docs
Sergio0694 Jun 23, 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
Prev Previous commit
Next Next commit
Update DependentHandle on Mono runtime
  • Loading branch information
Sergio0694 committed Jun 18, 2021
commit a96fa3fb19ae72411b6ab34bcfb1721f7ccbc6b3
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@
<Compile Include="$(BclSourcesRoot)\System\Reflection\Emit\UnmanagedMarshal.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\Metadata\AssemblyExtensions.cs" />
<Compile Include="$(BclSourcesRoot)\System\Resources\ManifestBasedResourceGroveler.Mono.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\DependentHandle.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\GCSettings.Mono.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\DependentHandle.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\JitHelpers.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\RuntimeHelpers.Mono.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\RuntimeFeature.Mono.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,73 +1,100 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;

namespace System.Runtime.CompilerServices
{
internal struct Ephemeron
{
public object? key;
public object? value;
}
}

namespace System.Runtime
{
//
// Instead of dependent handles, mono uses arrays of Ephemeron objects.
//
internal struct DependentHandle
public struct DependentHandle : IDisposable
{
private Ephemeron[] data;

public DependentHandle(object? primary, object? secondary)
public DependentHandle(object? target, object? dependent)
{
data = new Ephemeron[1];
data[0].key = primary;
data[0].value = secondary;
data[0].key = target;
data[0].value = dependent;
GC.register_ephemeron_array(data);
}

public bool IsAllocated => data != null;

// Getting the secondary object is more expensive than getting the first so
// we provide a separate primary-only accessor for those times we only want the
// primary.
public object? GetPrimary()
public object? Target
{
get => GetTarget();
set => SetTarget(value);
}

public object? Dependent
{
get => GetDependent();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be UnsafeGetDependent for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed as part of 64bad6418ff202c60862eabf22468b508dd662f3.

set => SetDependent(value);
}

public (object? Target, object? Dependent) GetTargetAndDependent()
{
if (!IsAllocated)
throw new NotSupportedException();
if (data[0].key == GC.EPHEMERON_TOMBSTONE)
return null;
return data[0].key;
{
return default;
}
return (data[0].key, data[0].value);
}

public object? GetPrimaryAndSecondary(out object? secondary)
public void Dispose()
{
data = null!;
}

private object? GetTarget()
{
// Getting the secondary object is more expensive than getting the first so
// we provide a separate primary-only accessor for those times we only want the
// primary.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this true for the mono implementation as well? That seems... odd... given how it's structured.

Copy link
Contributor Author

@Sergio0694 Sergio0694 Jun 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, don't think that comment is accurate for Mono. It looks like the Mono implementation of DependentHandle had just copied that comment from the CoreCLR reference source and forgot to remove it or to at least update according to their own architecture. Retrieving either the key or the value on Mono does indeed seem to be equally expensive as you said. I have removed it in b6d306e41d1ab4f0e8692b2c16defab1314cacad 🙂


if (!IsAllocated)
throw new NotSupportedException();
if (data[0].key == GC.EPHEMERON_TOMBSTONE)
{
secondary = null;
return null;
}
secondary = data[0].value;
return data[0].key;
}

public void SetPrimary(object? primary)
private void SetTarget(object? primary)
{
if (!IsAllocated)
throw new NotSupportedException();
data[0].key = primary;
}

public void SetSecondary(object? secondary)
private object? GetDependent()
{
if (!IsAllocated)
throw new NotSupportedException();
data[0].value = secondary;
if (data[0].key == GC.EPHEMERON_TOMBSTONE)
{
return null;
}
return data[0].value;
}

public void Free()
private void SetDependent(object? secondary)
{
data = null!;
if (!IsAllocated)
throw new NotSupportedException();
data[0].value = secondary;
}
}
}