使用“native”编译有哪些约束/限制?

发布于 2024-08-20 13:26:11 字数 224 浏览 3 评论 0原文

与通常的“非本机”编译相比,使用 +native 选项编译 Erlang .erl 源代码时有哪些限制/约束?

相关内容:Erlang OTP 版本使用 HiPE 进行编译?

What are the limitations/constraints when compiling Erlang .erl source with the +native option compared with the usual "non native" compilation?

Related to: Erlang OTP release compiles with HiPE?

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

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

发布评论

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

评论(1

自演自醉 2024-08-27 13:26:11

BEAM 模拟器提供的跟踪、断点和单步执行功能在本机编译代码中不可用。还有一个限制,即当您加载同一模块的较新版本时,本机代码并未真正从内存中卸载。 (如果您有一个长期运行的系统,需要不断升级模块或动态生成和编译模块,这可能会成为一个问题。)

此外,在本机代码和模拟 BEAM 代码之间跳转时会产生很小的开销,因此您应该避免这样做一种紧密循环中的模式切换,其中速度很重要。最好将所有密切相关的模块编译为本机,如果可能的话,还编译最重要的标准库模块。

最后,虽然本机编译器经过了很好的测试,但 HiPE 中编译器错误的概率比 BEAM 仿真器 C 代码中错误的概率要高一些(尽管可能不高于 GCC 中错误的概率),因此您可以运行系统段错误的风险更大。不过现在这种情况已经很少见了。

总而言之,目前可能不建议使用本机编译的主要地方是在独立产品中(例如您交付给客户的黑盒服务器),其中稳定性、远程调试性和低内存使用率是您的主要目标关注点和计算速度通常不是。

The functionality for tracing, breakpoints and single stepping that the BEAM emulator provides are not available in native compiled code. There is also still a limitation that native code is not really unloaded from memory when you load newer versions of the same module. (This can be an issue if you have a long-running system where you keep upgrading modules or generate and compile modules dynamically.)

Furthermore, there is a small overhead when jumping between native code and emulated BEAM code, so you should avoid having that kind of mode switch in a tight loop where speed matters. Preferably compile all closely related modules to native, and if possible also the most important standard library modules.

Finally, although the native compiler is quite well tested, the probability of a compiler bug in HiPE is a bit higher than that of bugs in the BEAM emulator C code (though probably no higher than that of bugs in GCC), so you may run a greater risk of system segfaults. It's quite rare these days though.

In summary, the main place where native compilation is probably not recommended for now, is in stand-alone products (like a black-box server that you deliver to a customer), where stability, remote debuggability, and low memory usage are your main concern and computation speed is typically not.

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