clr 分析器 api:ICorProfilerCallback::ExceptionThrown GC 安全

clr profiler api: is ICorProfilerCallback::ExceptionThrown GC safe

我想知道在 .net 框架分析器中,ExceptionThrown (https://docs.microsoft.com/en-us/dotnet/framework/unmanaged-api/profiling/icorprofilercallback-exceptionthrown-method) gua运行是否与 GC 不重叠?

查看文档,似乎是这样 - "If the profiler blocks here and garbage collection is attempted, the runtime will block until this callback returns"

但是,我 运行 我的探查器附加到 paint.net(https://www.getpaint.net/ - 版本 4.1.6)并且看到了一个特定的案例,我在 ExceptionThrown 期间获得了 GC。 (但那是非常罕见的 - 只发生在启动时,大约每 20 次运行只发生一次) - 这导致数据在我阅读时正确更改,因为 gc 移动了它。

至少在 .net 核心版本中 -https://github.com/dotnet/coreclr/blob/master/Documentation/botr/profiling.md it explicitly says what callbacks are GC callout safe. ExceptionThrown is not one of them. ExceptionUnwindFunctionEnter is, for example. However, back to .NET framework - https://docs.microsoft.com/en-us/dotnet/framework/unmanaged-api/profiling/icorprofilercallback-exceptionunwindfunctionenter-method - 在 .NET 框架文档中关于 GC 的评论与 ExceptionThrown 的评论相同。

我知道 .NET 核心 != .NET 框架。但是,我觉得他们的分析器代码非常相似,并且具有相同的 gua运行tees。我找不到关于 .NET 框架回调的 GC 安全的类似资源。

所以在介绍了这么多之后,我的问题是:

  1. .NET Framework clr profiler ExceptionThrown 回调应该是 GC 安全的。如果是这样,我怎么会看到 GC 调用在 ExceptionThrown 期间开始和结束(可能是 clr 中的错误或预期的行为)?

  2. 如果不是错误,我是否可以至少 100% 依赖 .NET Framework clr 探查器 UnwindExceptionFunctionEnter 回调基于围绕 core-clr 的类似文档是 GC 安全的?

感谢

是的,允许 GC 运行。 .NETCore 接口与 .NETFramework 接口没有根本区别,github 文档是准确的。

the CLR source就很容易看出来了。虽然测试人员似乎一直在 Ballmer Peak 工作,但他的合同声明一定是准确的。 Copy/pasting相关代码:

    // Preemptive mode would be bad, dude.  There's an objectId in the param list!
    MODE_COOPERATIVE;

MODE_COOPERATIVE宏表示启用了GC。 MODE_PREEMPTIVE 宏表示 GC 延迟。