Skip to content
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

Span: VM side of GC reporting for Span<T> - slow tail calls #7263

Closed
kouvel opened this issue Jan 21, 2017 · 4 comments
Closed

Span: VM side of GC reporting for Span<T> - slow tail calls #7263

kouvel opened this issue Jan 21, 2017 · 4 comments
Assignees
Milestone

Comments

@kouvel
Copy link
Member

kouvel commented Jan 21, 2017

Fix the following places on the VM side to do proper GC reporting for Span<T>:

  • StubLinkerCPU::CreateTailCallCopyArgsThunk, or slow tailcalls have to be disabled for calls with Span<T> arguments

Slow tail calls may not currently be an issue, but apparently, that could change.

Forked from #7103

@kouvel kouvel removed their assignment Sep 15, 2017
@ahsonkhan
Copy link
Member

ahsonkhan commented Oct 18, 2017

@kouvel, any updates on this issue?
This is one of the two remaining issues under "VM - Correctness" from https://github.com/dotnet/coreclr/issues/5851#issue-160849016

@kouvel
Copy link
Member Author

kouvel commented Oct 18, 2017

Last I remember from talking with @jkotas about this is that this was something that is not currently an issue but could be in the future (at the time, the future was earlier in time), I don't remember the details. @jkotas, is there something here that has a potential for failure that needs to be investigated?

@jkotas
Copy link
Member

jkotas commented Oct 18, 2017

Repro:

using System;
using System.Reflection;
using System.Reflection.Emit;

public class My {

public static void Target(Span<int> a, Span<int> b, Span<int> c, Span<int> d, Span<int> e)
{
   GC.Collect();
   for (int i = 0; i < 10000; i++) GC.KeepAlive(new Object());
   if (a[0] != 42 || b[0] != 42 || c[0] != 42 || d[0] != 42 || e[0] != 42)
       Internal.Console.WriteLine("FAILED");
}

delegate void MyDelegate(Span<int> x);

static void Main() {
    DynamicMethod dm = new DynamicMethod("TailCall", typeof(void), new Type[] { typeof(Span<int>) });
    ILGenerator il = dm.GetILGenerator();
    il.Emit(OpCodes.Ldarg_0);        
    il.Emit(OpCodes.Ldarg_0);
    il.Emit(OpCodes.Ldarg_0);
    il.Emit(OpCodes.Ldarg_0);
    il.Emit(OpCodes.Ldarg_0);
    il.Emit(OpCodes.Tailcall);
    il.Emit(OpCodes.Call, typeof(My).GetMethod("Target"));
    il.Emit(OpCodes.Ret);
    
    var d = (MyDelegate)dm.CreateDelegate(typeof(MyDelegate));
   
    for (;;) { GC.KeepAlive(new Object()); d(new Span<int>(new int[1] { 42 })); GC.KeepAlive(new Object()); }
}

}

Actual result on Windows x64: prints FAILED occasionally
Expected result: does not print FAILED

@kouvel
Copy link
Member Author

kouvel commented Oct 18, 2017

Thanks, I'll take a look

@kouvel kouvel self-assigned this Oct 31, 2017
kouvel referenced this issue in kouvel/coreclr Nov 2, 2017
Fixes https://github.com/dotnet/coreclr/issues/9032:
- Refactored by-ref-like method table walking to find offsets of by-ref pointers in siginfo.hpp/cpp
- Reused that for appending GC layout when creating the copy-args helper for a slow tail call
kouvel referenced this issue in kouvel/coreclr Nov 3, 2017
Fixes https://github.com/dotnet/coreclr/issues/9032:
- Refactored by-ref-like method table walking to find offsets of by-ref pointers in siginfo.hpp/cpp
- Reused that for appending GC layout when creating the copy-args helper for a slow tail call
kouvel referenced this issue in dotnet/coreclr Nov 6, 2017
Fix GC reporting for slow tail call arguments of type `Span<T>`

Fixes https://github.com/dotnet/coreclr/issues/9032:
- Refactored by-ref-like method table walking to find offsets of by-ref pointers in siginfo.hpp/cpp
- Reused that for appending GC layout when creating the copy-args helper for a slow tail call
nategraf referenced this issue in nategraf/coreclr Nov 7, 2017
…et#14826)

Fix GC reporting for slow tail call arguments of type `Span<T>`

Fixes https://github.com/dotnet/coreclr/issues/9032:
- Refactored by-ref-like method table walking to find offsets of by-ref pointers in siginfo.hpp/cpp
- Reused that for appending GC layout when creating the copy-args helper for a slow tail call
@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the 2.1.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants