Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\GenericsHelpers.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\InitHelpers.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\AsyncHelpers.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\AsyncProfiler.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\RuntimeHelpers.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\StaticsHelpers.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\VirtualDispatchHelpers.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ internal unsafe ref struct AsyncDispatcherInfo
// to match an inflight Task to the corresponding Continuation chain.
public Task? CurrentTask;

#if TARGET_64BIT
[FieldOffset(24)]
#else
[FieldOffset(12)]
#endif
public AsyncProfiler.Info AsyncProfilerInfo;

// Information about current task dispatching, to be used for async
// stackwalking.
[ThreadStatic]
Expand Down Expand Up @@ -498,7 +505,7 @@ internal void InstrumentedHandleSuspended(AsyncInstrumentation.Flags flags, ref
{
if (AsyncInstrumentation.IsEnabled.AsyncDebugger(flags))
{
Continuation? nextContinuation = t_runtimeAsyncAwaitState.SentinelContinuation!.Next;
Continuation? nextContinuation = state.SentinelContinuation!.Next;

AsyncDebugger.HandleSuspended(nextContinuation, newContinuation);

Expand Down Expand Up @@ -659,20 +666,21 @@ private unsafe void InstrumentedDispatchContinuations(AsyncInstrumentation.Flags
ref byte resultLoc = ref nextContinuation != null ? ref nextContinuation.GetResultStorageOrNull() : ref GetResultStorage();

RuntimeAsyncInstrumentationHelpers.ResumeRuntimeAsyncMethod(ref asyncDispatcherInfo, flags, curContinuation);
Continuation? newContinuation = curContinuation.ResumeInfo->Resume(curContinuation, ref resultLoc);
Continuation? newContinuation = RuntimeAsyncInstrumentationHelpers.ResumeContinuation(ref asyncDispatcherInfo, flags, curContinuation, ref resultLoc);

if (newContinuation != null)
{
newContinuation.Next = nextContinuation;
RuntimeAsyncInstrumentationHelpers.SuspendRuntimeAsyncContext(flags, curContinuation, newContinuation);

RuntimeAsyncInstrumentationHelpers.AwaitSuspendedRuntimeAsyncContext(ref asyncDispatcherInfo, flags, curContinuation, newContinuation, awaitState.SentinelContinuation!.Next);
InstrumentedHandleSuspended(flags, ref awaitState, newContinuation);

awaitState.Pop();
refDispatcherInfo = asyncDispatcherInfo.Next;
return;
}

RuntimeAsyncInstrumentationHelpers.CompleteRuntimeAsyncMethod(flags, curContinuation);
RuntimeAsyncInstrumentationHelpers.CompleteRuntimeAsyncMethod(ref asyncDispatcherInfo, flags, curContinuation);
}
catch (Exception ex)
{
Expand All @@ -698,7 +706,7 @@ private unsafe void InstrumentedDispatchContinuations(AsyncInstrumentation.Flags
return;
}

RuntimeAsyncInstrumentationHelpers.UnwindRuntimeAsyncMethodHandledException(flags, curContinuation, unwindedFrames);
RuntimeAsyncInstrumentationHelpers.UnwindRuntimeAsyncMethodHandledException(ref asyncDispatcherInfo, flags, curContinuation, unwindedFrames);

handlerContinuation.SetException(ex);
asyncDispatcherInfo.NextContinuation = handlerContinuation;
Expand All @@ -723,7 +731,7 @@ private unsafe void InstrumentedDispatchContinuations(AsyncInstrumentation.Flags

if (QueueContinuationFollowUpActionIfNecessary(asyncDispatcherInfo.NextContinuation))
{
RuntimeAsyncInstrumentationHelpers.SuspendRuntimeAsyncContext(ref asyncDispatcherInfo, flags, curContinuation);
RuntimeAsyncInstrumentationHelpers.QueueSuspendedRuntimeAsyncContext(ref asyncDispatcherInfo, flags, curContinuation, asyncDispatcherInfo.NextContinuation);

awaitState.Pop();
refDispatcherInfo = asyncDispatcherInfo.Next;
Expand Down Expand Up @@ -837,6 +845,15 @@ private static void InstrumentedFinalizeRuntimeAsyncTask<T>(RuntimeAsyncTask<T>
{
if (AsyncInstrumentation.IsEnabled.CreateAsyncContext(flags))
{
if (AsyncInstrumentation.IsEnabled.AsyncProfiler(flags))
{
Continuation? nextContinuation = state.SentinelContinuation!.Next;
if (nextContinuation != null)
{
AsyncProfiler.CreateAsyncContext.Create((ulong)task.Id, nextContinuation);
}
}

if (AsyncInstrumentation.IsEnabled.AsyncDebugger(flags))
{
task.NotifyDebuggerOfRuntimeAsyncState();
Expand Down Expand Up @@ -1053,9 +1070,15 @@ public static bool InstrumentCheckPoint
public static void ResumeRuntimeAsyncContext(Task task, ref AsyncDispatcherInfo info, AsyncInstrumentation.Flags flags)
{
info.CurrentTask = task;
AsyncProfiler.InitInfo(ref info.AsyncProfilerInfo);

if (AsyncInstrumentation.IsEnabled.ResumeAsyncContext(flags))
{
if (AsyncInstrumentation.IsEnabled.AsyncProfiler(flags))
{
AsyncProfiler.ResumeAsyncContext.Resume(ref info);
}

if (AsyncInstrumentation.IsEnabled.AsyncDebugger(flags))
{
AsyncDebugger.ResumeAsyncContext(task.Id);
Expand All @@ -1064,10 +1087,15 @@ public static void ResumeRuntimeAsyncContext(Task task, ref AsyncDispatcherInfo
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SuspendRuntimeAsyncContext(ref AsyncDispatcherInfo info, AsyncInstrumentation.Flags flags, Continuation curContinuation)
public static void QueueSuspendedRuntimeAsyncContext(ref AsyncDispatcherInfo info, AsyncInstrumentation.Flags flags, Continuation curContinuation, Continuation nextContinuation)
{
if (AsyncInstrumentation.IsEnabled.SuspendAsyncContext(flags))
{
if (AsyncInstrumentation.IsEnabled.AsyncProfiler(flags))
{
AsyncProfiler.SuspendAsyncContext.Suspend(ref info, nextContinuation);
}

if (AsyncInstrumentation.IsEnabled.AsyncDebugger(flags))
{
AsyncDebugger.SuspendAsyncContext(ref info, curContinuation);
Expand All @@ -1076,10 +1104,15 @@ public static void SuspendRuntimeAsyncContext(ref AsyncDispatcherInfo info, Asyn
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SuspendRuntimeAsyncContext(AsyncInstrumentation.Flags flags, Continuation curContinuation, Continuation newContinuation)
public static void AwaitSuspendedRuntimeAsyncContext(ref AsyncDispatcherInfo info, AsyncInstrumentation.Flags flags, Continuation curContinuation, Continuation newContinuation, Continuation? nextContinuation)
{
if (AsyncInstrumentation.IsEnabled.SuspendAsyncContext(flags))
{
if (AsyncInstrumentation.IsEnabled.AsyncProfiler(flags))
{
AsyncProfiler.SuspendAsyncContext.Suspend(ref info, nextContinuation ?? newContinuation);
}

if (AsyncInstrumentation.IsEnabled.AsyncDebugger(flags))
{
AsyncDebugger.SuspendAsyncContext(curContinuation, newContinuation);
Expand All @@ -1092,28 +1125,53 @@ public static void CompleteRuntimeAsyncContext(ref AsyncDispatcherInfo info, Asy
{
if (AsyncInstrumentation.IsEnabled.CompleteAsyncContext(flags))
{
if (AsyncInstrumentation.IsEnabled.AsyncProfiler(flags))
{
AsyncProfiler.CompleteAsyncContext.Complete(ref info.AsyncProfilerInfo);
}

if (AsyncInstrumentation.IsEnabled.AsyncDebugger(flags))
{
AsyncDebugger.CompleteAsyncContext(info.CurrentTask);
}
}
}

public static void UnwindRuntimeAsyncMethodUnhandledException(ref AsyncDispatcherInfo info, AsyncInstrumentation.Flags flags, Exception ex, Continuation curContinuation, uint _)
public static void UnwindRuntimeAsyncMethodUnhandledException(ref AsyncDispatcherInfo info, AsyncInstrumentation.Flags flags, Exception ex, Continuation curContinuation, uint unwindedFrames)
{
if (AsyncInstrumentation.IsEnabled.AsyncProfiler(flags))
{
AsyncProfiler.ContinuationWrapper.UnwindIndex(ref info.AsyncProfilerInfo, unwindedFrames);
}

if (AsyncInstrumentation.IsEnabled.UnwindAsyncException(flags))
{
if (AsyncInstrumentation.IsEnabled.AsyncProfiler(flags))
{
AsyncProfiler.AsyncMethodException.Unhandled(ref info.AsyncProfilerInfo, unwindedFrames);
}

if (AsyncInstrumentation.IsEnabled.AsyncDebugger(flags))
{
AsyncDebugger.AsyncMethodUnhandledException(info.CurrentTask, ex, curContinuation);
}
}
}

public static void UnwindRuntimeAsyncMethodHandledException(AsyncInstrumentation.Flags flags, Continuation curContinuation, uint unwindedFrames)
public static void UnwindRuntimeAsyncMethodHandledException(ref AsyncDispatcherInfo info, AsyncInstrumentation.Flags flags, Continuation curContinuation, uint unwindedFrames)
{
if (AsyncInstrumentation.IsEnabled.AsyncProfiler(flags))
{
AsyncProfiler.ContinuationWrapper.UnwindIndex(ref info.AsyncProfilerInfo, unwindedFrames);
}

if (AsyncInstrumentation.IsEnabled.UnwindAsyncException(flags))
{
if (AsyncInstrumentation.IsEnabled.AsyncProfiler(flags))
{
AsyncProfiler.AsyncMethodException.Handled(ref info.AsyncProfilerInfo, unwindedFrames);
}

if (AsyncInstrumentation.IsEnabled.AsyncDebugger(flags))
{
AsyncDebugger.AsyncMethodHandledException(curContinuation, unwindedFrames);
Expand All @@ -1126,6 +1184,11 @@ public static void ResumeRuntimeAsyncMethod(ref AsyncDispatcherInfo info, AsyncI
{
if (AsyncInstrumentation.IsEnabled.ResumeAsyncMethod(flags))
{
if (AsyncInstrumentation.IsEnabled.AsyncProfiler(flags))
{
AsyncProfiler.ResumeAsyncMethod.Resume(ref info.AsyncProfilerInfo);
}

if (AsyncInstrumentation.IsEnabled.AsyncDebugger(flags))
{
AsyncDebugger.ResumeAsyncMethod(ref info, curContinuation);
Expand All @@ -1134,16 +1197,40 @@ public static void ResumeRuntimeAsyncMethod(ref AsyncDispatcherInfo info, AsyncI
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void CompleteRuntimeAsyncMethod(AsyncInstrumentation.Flags flags, Continuation curContinuation)
public static void CompleteRuntimeAsyncMethod(ref AsyncDispatcherInfo info, AsyncInstrumentation.Flags flags, Continuation curContinuation)
{
if (AsyncInstrumentation.IsEnabled.AsyncProfiler(flags))
{
AsyncProfiler.ContinuationWrapper.IncrementIndex(ref info.AsyncProfilerInfo);
}

if (AsyncInstrumentation.IsEnabled.CompleteAsyncMethod(flags))
{
if (AsyncInstrumentation.IsEnabled.AsyncProfiler(flags))
{
AsyncProfiler.CompleteAsyncMethod.Complete(ref info.AsyncProfilerInfo);
}

if (AsyncInstrumentation.IsEnabled.AsyncDebugger(flags))
{
AsyncDebugger.CompleteAsyncMethod(curContinuation);
}
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Continuation? ResumeContinuation(ref AsyncDispatcherInfo info, AsyncInstrumentation.Flags flags, Continuation curContinuation, ref byte resultLoc)
{
if (AsyncInstrumentation.IsEnabled.AsyncProfiler(flags))
{
return AsyncProfiler.ContinuationWrapper.Dispatch(ref info, curContinuation, ref resultLoc);
}

unsafe
{
return curContinuation.ResumeInfo->Resume(curContinuation, ref resultLoc);
}
}
}

internal static class AsyncDebugger
Expand Down
Loading
Loading