Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix gc hole in Frozen.cs #76868

Merged
merged 3 commits into from
Oct 11, 2022
Merged
Changes from 1 commit
Commits
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
15 changes: 8 additions & 7 deletions src/tests/GC/API/Frozen/Frozen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,17 @@ internal class Node

internal static class Program
{
private static unsafe IntPtr GetMethodTablePointer(object obj)
internal sealed class RawData
{
GCHandle gch = GCHandle.Alloc(obj);
IntPtr pointerToPointerToObject = GCHandle.ToIntPtr(gch);
IntPtr pointerToObject = *((IntPtr*)pointerToPointerToObject);
IntPtr methodTable = *((IntPtr*)pointerToObject);
gch.Free();
return methodTable;
public byte Data;
}

internal static ref byte GetRawData(this object obj) =>
ref Unsafe.As<RawData>(obj).Data;

internal static unsafe IntPtr GetMethodTablePointer(object obj) =>
(IntPtr)Unsafe.Add(ref Unsafe.As<byte, IntPtr>(ref obj.GetRawData()), -1);
Copy link
Member

Choose a reason for hiding this comment

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

This assumes that offset 0 is a valid byref. It happens to be true in CoreCLR today, but it is not a safe assumption to make.


private static unsafe int Main(string[] args)
{
Node template = new Node();
Expand Down