使用“native”编译有哪些约束/限制?
与通常的“非本机”编译相比,使用 +native
选项编译 Erlang .erl
源代码时有哪些限制/约束?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.