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

crossgen2: Report CORINFO_FLG_NOGCCHECK back for internal calls #65300

Merged
merged 2 commits into from
Feb 14, 2022

Conversation

jakobbotsch
Copy link
Member

When there are loops or tailcalls in a function the JIT will check for
a dominating call that is a GC safepoint to figure out if the function
needs to be marked fully interruptible or not. Methods with the
InternalCall flag may turn into fcalls that are not hijackable and thus
not GC safepoints, so in this case JIT should still mark the function
fully interruptible, but was not doing so because crossgen2 was not
reporting this flag back.

Fix #64980

When there are loops or tailcalls in a function the JIT will check for
a dominating call that is a GC safepoint to figure out if the function
needs to be marked fully interruptible or not. Methods with the
InternalCall flag may turn into fcalls that are not hijackable and thus
not GC safepoints, so in this case JIT should still mark the function
fully interruptible, but was not doing so because crossgen2 was not
reporting this flag back.

Fix dotnet#64980
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 14, 2022
@ghost ghost assigned jakobbotsch Feb 14, 2022
@ghost
Copy link

ghost commented Feb 14, 2022

Tagging subscribers to this area: @JulieLeeMSFT
See info in area-owners.md if you want to be subscribed.

Issue Details

When there are loops or tailcalls in a function the JIT will check for
a dominating call that is a GC safepoint to figure out if the function
needs to be marked fully interruptible or not. Methods with the
InternalCall flag may turn into fcalls that are not hijackable and thus
not GC safepoints, so in this case JIT should still mark the function
fully interruptible, but was not doing so because crossgen2 was not
reporting this flag back.

Fix #64980

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch
Copy link
Member Author

I have tried for a while to create a simple regression test, but with checked bits the following case has very long suspension times and sometimes hits the timeout, even though FcallInLoop is fully interruptible.

using System;
using System.Threading;

public class Program
{
    public static void Main()
    {
        Program p = new Program();
        Thread hijack = new Thread(p.FcallInLoop);
        hijack.Start();
        p.GCInLoop();
        hijack.Join();
    }

    private readonly object _doneObj = new object();
    private object _state;

    public void FcallInLoop()
    {
        while (true)
        {
            object oldVal = Interlocked.CompareExchange(ref _state, null, null);
            if (oldVal == _doneObj)
                break;
        }
    }

    public void GCInLoop()
    {
        Thread.Sleep(50);

        System.Console.WriteLine("Starting GCInLoop");
        for (int i = 0; i < 10; i++)
        {
            System.Console.WriteLine("GC {0}", i + 1);
            GC.Collect();
            Thread.Sleep(1);
        }

        _state = _doneObj;
    }
}

With release bits it seems to be much better, presumably because it spends more time in FcallInLoop relatively to the fcall.

@jkotas Is this what you meant when you said that the story around GC suspension and fcalls is not perfect even for the JIT case?

@jkotas
Copy link
Member

jkotas commented Feb 14, 2022

@jkotas Is this what you meant when you said that the story around GC suspension and fcalls is not perfect even for the JIT case?

Yes. Ideally, we would emit an explicit GC suspension check after each FCall, similar to what we are doing for PInvokes with SuppressGCTransition.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thanks

@jkotas jkotas merged commit 6200568 into dotnet:main Feb 14, 2022
@jakobbotsch jakobbotsch deleted the fix-64980 branch March 6, 2022 14:02
@ghost ghost locked as resolved and limited conversation to collaborators Apr 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AddRemoveFromDifferentThreads<string>.ConcurrentStack benchmark hangs on ARM64
2 participants