如何在不指定域中立性的情况下将 .net 本机映像 (NGEN) 加载到多个应用程序域中?

发布于 2024-10-08 20:08:27 字数 782 浏览 11 评论 0原文

NGEN + AppDomain 问题在这里。

我正在对一些应用程序进行更改,这些更改围绕使本机图像正确加载以防止我们的 .net 应用程序中出现糟糕的 JIT 时间。有些部分很简单,但是任何必须在应用程序域中加载的程序集(我们的应用程序由于各种原因必须使用它)只会在第一次加载其本机图像,并在后续加载时(在现在的新应用程序域中)图像被拒绝并发生 JIT。

我了解有关域中立加载的所有信息,并且已经在一些有意义的程序集中使用了它,但是进行域中立加载首先消除了我们使用 appdomains 的主要原因之一 -因为域中性图像永远无法卸载。

简而言之,我需要一种方法来加载本机图像和卸载程序集。我原本希望只要在尝试再次加载本机映像之前卸载本机映像的第一次使用,就不会应用正常的限制,但这会导致拒绝,就像尝试同时加载本机映像一样。

这篇 MSDN 文章 包含以下引用:

另一种应对跌倒的方法 回到JIT编译就是加载 原生镜像的不同副本 到每个加载的AppDomain中 相应的组件为 特定领域的。然而,这 方法需要每个副本 NGen 图像,除了第一个之外, 加载到不同的地址 从其首选基地址。因此 NGen 映像的所有这些副本 需要修复他们的地址。

这将非常适合我的需求,但那篇文章是我见过的唯一提到它的地方,我不确定它将如何实现。

预先感谢您的任何见解,并感谢您的关注。

NGEN + AppDomain problem here.

I'm working on some application changes that revolve around making native images load correctly to prevent awful JIT time in our .net application. Some parts were easy, but any assemblies that have to load in appdomains (which our app has to use for a variety of reasons) will only load their native image the first time, and on subsequent loads (in what is now a new appdomain) the image is rejected and JIT occurs.

I know all about domain-neutral loading, and have already made use of it for some of our assemblies where it makes sense, but doing domain-neutral loading cancels out one of the major reasons for using appdomains in the first place for us -- as domain neutral images can never be unloaded.

Put succinctly, I need a way to have native images loading and assembly unloading. I had hoped that the normal restriction wouldn't apply as long as I unloaded the first usage of the native image before I tried to load it again, but this resulted in rejection just like if trying to load the native image concurrently.

This MSDN article contains the following quote:

An alternative approach to falling
back to JIT compilation is to load
different copies of the native image
into every AppDomain that loads the
corresponding assembly as
domain-specific. However, this
approach would require every copy of
the NGen image, except for the first,
to be loaded at a different address
from its preferred base address. Thus
all of these copies of the NGen image
would need their addresses fixed up.

This would be perfect for my needs, but that article was the only place I've ever seen it mentioned and I am unsure how it would be implemented.

Thanks in advance for any insight, and thanks for looking.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

英雄似剑 2024-10-15 20:08:28

<块引用>

我本来希望只要在尝试再次加载本机映像之前卸载本机映像的第一次使用,就不会应用正常的限制,但这会导致拒绝,就像尝试同时加载本机映像一样。

这可行,但您必须等待本机映像实际卸载。当 AppDomain.Unload 返回时,appdomain 未完全卸载。仅在下一次完整 GC 后,appdomain 才会完全卸载(连同本机映像)。

<块引用>

这篇 MSDN 文章包含以下引用:

Surupa 正在推测 CLR 中可能的替代实现,但目前尚未实现。

谢谢
拉克山·费尔南多
CLR团队

I had hoped that the normal restriction wouldn't apply as long as I unloaded the first usage of the native image before I tried to load it again, but this resulted in rejection just like if trying to load the native image concurrently.

This works, but you have to wait for the native image to be actually unloaded. When AppDomain.Unload returns, the appdomain is not fully unloaded. The appdomain will get fully unloaded (along with native images) only after next full GC.

This MSDN article contains the following quote:

Surupa was speculating about a possible alternative implementation in the CLR but this is not currently implemented.

Thanks
Lakshan Fernando
CLR Team

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文