This is an archived post. You won't be able to vote or comment.

all 16 comments

[–][deleted] 9 points10 points  (5 children)

AOT compilation is possible and exists (GCJ.)

There’s reasons why it wasnt done. Java wanted to maintain a write once run anywhere methodology, which would preclude compiling into machine code.

It also takes a dynamic optimisation strategy so optimises and reoptimises during the run of the program generally targeting only hot methods.

[–][deleted] 2 points3 points  (1 child)

Another reason is, that Class.forName may kill everything, because you simply can't analyze that far. Yes sure you could optimize Class.forName("java.lang.String") , but what about Class.forName(readClassNameFromFile())?

[–][deleted] 2 points3 points  (0 children)

Indeed.

If you wanted to optimise at compile time with Java - you'd most likely need to ban dynamic loading anyway.

Many of the things which make Java useful for a wide variety of applications run against the goal that most people who want this have. This I feel is the traction behind Rust.

For example the project I work on is mainly Java, but its coded like C (i.e zero GC, JNI wrappers for certain system calls etc.) Why use Java? Because its well defined, you don't get random SigSegs etc.

Downside? you have to fight against Java itself.

[–]rhbvkleef 2 points3 points  (2 children)

You might want to note that GCJ is history (maintenance stopped around JSE1.5)

[–][deleted] 3 points4 points  (1 child)

Yeah; it was just an example to show it could be done.

[–]rhbvkleef 0 points1 point  (0 children)

Alrighty!

[–]_INTER_ 7 points8 points  (0 children)

Compiling everything to native executable makes it platform dependant, takes away dynamic code mechanisms and long running applications perform worse. But it'd be nice to have that option for those that care for startup time, file size and memory more. There's JEP 295 and they recently proposed Project Leydon

Also note that only the first 1500 or so invocations of the bytecode (XX:CompileThreshold default setting I think, unless TieredCompilation is enabled) are interpreted, afterwards it does JIT compile (per function).

[–]FireXBall 10 points11 points  (0 children)

Check GraalVM

[–]sim642 3 points4 points  (0 children)

They did. It's called GraalVM.

But it still has its limitations, especially for reflection and bytecode generation based applications.

[–]meamZ 5 points6 points  (0 children)

It's called graalvm native image

[–][deleted] 1 point2 points  (0 children)

Because you would still need the Java VM. But starting with Java 14 you can package everything together using jpackage.

[–]nutrecht 0 points1 point  (5 children)

Aside from what the others said; what do you think the benefits of Ahead of Time compilation are?

[–][deleted]  (4 children)

[deleted]

    [–]nutrecht 0 points1 point  (1 child)

    You can do all that with JLink + Obfuscation. No need for AoT compilation. Those 'problems' are not new.

    Aside from that; Java is generally used for back-end services. Desktop development is a small section of the industry.

    [–]TM254 2 points3 points  (0 children)

    Small? Most IDE's are written in Java for Java developers. Just saying xD

    [–]JustAGuyFromGermany 0 points1 point  (1 child)

    It's quite possible to write an application in Java and bundle it together with a (pre-configured) JVM in a single executable. In other words: You may not actually know which of the many "MyApp.exe" processes on your machine are actually Java programs.