Can I compile Java to native code?

风流意气都作罢 提交于 2019-11-26 15:50:46

问题


Is there any way to compile from Java to standalone (or library) machine code without requiring a JVM?


回答1:


There used to be a tool called GCJ that was part of GCC, but it's been removed. Now, all the links in the GCC site re-direct to their non-GCJ equivalents.

NB: the comments all refered to my original answer saying you can compile Java to native code with GCJ.




回答2:


Excelsior JET is a commercial Java to native code compiler.




回答3:


Yes!

Oracle has been working on the GraalVm, which supports Native Images. Check here: https://www.graalvm.org/

Native Image The native image feature with the GraalVM SDK helps improve the startup time of Java applications and gives them a smaller footprint. Effectively, it's converting bytecode that runs on the JVM (on any platform) to native code for a specific OS/platform — which is where the performance comes from. It's using aggressive ahead-of-time (AOT) optimizations to achieve good performance.

See more:

  • Summary
    https://www.graalvm.org/docs/getting-started/#native-images

  • Demos: Native images for faster startup
    https://www.graalvm.org/docs/examples/native-list-dir/

  • Detailed: 'Ahead-of-time Compilation'
    https://www.graalvm.org/docs/reference-manual/aot-compilation/




回答4:


Yes, the JIT in the JVM does exactly that for you.

In fact it can produce faster code than compiling the code in advance as it can generate code optimised for the specific platform based on how the code is used at runtime.

The JVM is always involved even if a very high percentage is compiled to native code as you could load and run byte code dynamically.



来源:https://stackoverflow.com/questions/2991799/can-i-compile-java-to-native-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!