-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Improve the performance of ConditionalWeakTable.TryGetValue #80059
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 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bd618d4
[NativeAOT] Fix Objective-C reference tracking
AustinWise ce38802
Move implementation-specific comment out of public doc comment
AustinWise 9967b1f
Duplicate code for TryGetHashCode implementations.
AustinWise 07bb690
Replace comments with a passing test.
AustinWise 6a13d23
Add moke test for restricted callouts.
AustinWise d9a6dc2
Remove TryGetHashCode from Mono
AustinWise cd22146
Update src/tests/Interop/ObjectiveC/ObjectiveCMarshalAPI/Program.cs
AustinWise 2131f4d
Update src/libraries/System.Private.CoreLib/src/System/Runtime/Compil…
AustinWise 129eee0
Revert "Add moke test for restricted callouts."
AustinWise e81000f
Add test coverage for untracked objective objects.
AustinWise 2eaed50
Spelling
AustinWise 1ccbe61
Implement RuntimeHelpers.TryGetHashCode for Mono
AustinWise 84d8c40
Remove unneeded MONO_COMPONENT_API
AustinWise 58f3667
Remove Mono intrinsic for InternalGetHashCode
AustinWise 1d94c9c
Move interpreter transforms to correct class.
AustinWise 93f22e1
Rename and move icall to match convention.
AustinWise 4d65fa4
Merge remote-tracking branch 'origin/main' into austin/TryGetHashCode
AustinWise 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
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
16 changes: 16 additions & 0 deletions
16
src/tests/nativeaot/SmokeTests/GcRestrictedCallouts/GcRestrictedCallouts.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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<CLRTestKind>BuildAndRun</CLRTestKind> | ||
<CLRTestPriority>0</CLRTestPriority> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="RuntimeImportAttribute.cs" /> | ||
<Compile Include="RuntimeImports.cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
38 changes: 38 additions & 0 deletions
38
src/tests/nativeaot/SmokeTests/GcRestrictedCallouts/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,38 @@ | ||
// 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; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.CompilerServices; | ||
|
||
static class Program | ||
{ | ||
static readonly ConditionalWeakTable<object, object> s_weakTable = new(); | ||
static readonly object s_inTableObject = new(); | ||
static readonly object s_notInTableObject = new(); | ||
|
||
static volatile bool s_testPass; | ||
|
||
static unsafe int Main() | ||
{ | ||
s_weakTable.Add(s_inTableObject, new object()); | ||
|
||
Console.WriteLine("RhRegisterGcCallout"); | ||
RuntimeImports.RhRegisterGcCallout(RuntimeImports.GcRestrictedCalloutKind.AfterMarkPhase, | ||
(IntPtr)(delegate* unmanaged<uint, void>)&GcCallback); | ||
|
||
Console.WriteLine("GC.Collect"); | ||
GC.Collect(); | ||
|
||
Console.WriteLine("Test passed: " + s_testPass); | ||
return s_testPass ? 100 : 1; | ||
} | ||
|
||
[UnmanagedCallersOnly] | ||
static void GcCallback(uint uiCondemnedGeneration) | ||
{ | ||
s_testPass = s_weakTable.TryGetValue(s_inTableObject, out object _) && | ||
!s_weakTable.TryGetValue(s_notInTableObject, out object _); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/tests/nativeaot/SmokeTests/GcRestrictedCallouts/RuntimeImportAttribute.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,24 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Runtime | ||
{ | ||
// Exposed in Internal.CompilerServices only | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false)] | ||
public sealed class RuntimeImportAttribute : Attribute | ||
{ | ||
public string DllName { get; } | ||
public string EntryPoint { get; } | ||
|
||
public RuntimeImportAttribute(string entry) | ||
{ | ||
EntryPoint = entry; | ||
} | ||
|
||
public RuntimeImportAttribute(string dllName, string entry) | ||
{ | ||
EntryPoint = entry; | ||
DllName = dllName; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/tests/nativeaot/SmokeTests/GcRestrictedCallouts/RuntimeImports.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,31 @@ | ||
// 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; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace System.Runtime | ||
{ | ||
// Copied from src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs | ||
static class RuntimeImports | ||
{ | ||
private const string RuntimeLibrary = "*"; | ||
|
||
internal enum GcRestrictedCalloutKind | ||
{ | ||
StartCollection = 0, // Collection is about to begin | ||
EndCollection = 1, // Collection has completed | ||
AfterMarkPhase = 2, // All live objects are marked (not including ready for finalization objects), | ||
// no handles have been cleared | ||
} | ||
|
||
[MethodImplAttribute(MethodImplOptions.InternalCall)] | ||
[RuntimeImport(RuntimeLibrary, "RhRegisterGcCallout")] | ||
internal static extern bool RhRegisterGcCallout(GcRestrictedCalloutKind eKind, IntPtr pCalloutMethod); | ||
|
||
[MethodImplAttribute(MethodImplOptions.InternalCall)] | ||
[RuntimeImport(RuntimeLibrary, "RhUnregisterGcCallout")] | ||
internal static extern void RhUnregisterGcCallout(GcRestrictedCalloutKind eKind, IntPtr pCalloutMethod); | ||
} | ||
} |
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.