News for hackers. Stuff that matters.
Re:Scala Native with Denys Shabalin – Software Engineering D... by nerdponx on Wednesday October 18, 2017 @10:29PM (#15505046)
Why would you compile Scala natively itself instead of compiling JVM bytecode?
Re:Scala Native with Denys Shabalin – Software Engineering D... by binarynate on Thursday October 19, 2017 @01:59AM (#15505753)
Interesting question - I hadn't thought about compiling the JVM bytecode to machine code. It looks like there is a Java frontend for LLVM that achieves that: https://llvm.org/svn/llvm-project/java/trunk/docs/java-front...

One of the things that appeals to me about Scala Native is its interoperability with C, which I suspect is something that the LLVM Java frontend doesn't provide.

Re:Scala Native with Denys Shabalin – Software Engineering D... by nerdponx on Friday October 20, 2017 @09:18AM (#15515496)
Doesn't the JVM have some kind of native FFI?
Re:Scala Native with Denys Shabalin – Software Engineering D... by binarynate on Sunday October 22, 2017 @02:44AM (#15525490)
I suspect the built-in Java Native Interface (JNI) won't work when compiling bytecode to native code, since the JNI methods require a pointer to the JVM (passing a pointer to the JVM to C functions or calling methods on the JVM class in C++). Perhaps an FFI library like this could work, though: https://github.com/jnr/jnr-ffi .
Re:Scala Native with Denys Shabalin – Software Engineering D... by densh on Wednesday October 18, 2017 @10:33PM (#15505066)
JVM startup is really painful for short to medium time running apps, this is the niche we’re trying to address.
Re:Scala Native with Denys Shabalin – Software Engineering D... by nerdponx on Wednesday October 18, 2017 @10:38PM (#15505083)
I meant, "compile bytecode to machine code." The fact that nobody does it is a sign that it's not a good idea. I guess I was just wondering why.
Re:Scala Native with Denys Shabalin – Software Engineering D... by rpeden on Wednesday October 18, 2017 @11:02PM (#15505180)
Excelsior JET does it, and it works Scala. So you can already compile JVM targeted Scala to native code that way if you want to. JET is fairly expensive, though.
Re:Scala Native with Denys Shabalin – Software Engineering D... by densh on Wednesday October 18, 2017 @10:47PM (#15505119)
Scala is a relatively simple language in the end of the compiler pipeline. We just take lowered ASTs and emit our SSA representation from there because it’s easy it to implement it this way. You can totally do something similar from the bytecode.
Re:Scala Native with Denys Shabalin – Software Engineering D... by pjmlp on Thursday October 19, 2017 @01:13AM (#15505620)
Lots of people do it.

Besides ExcelsiorJET named in a sibling answer, the JDKs from Aicas, IBM, PTC, STMicroelectronics, Google with their ART implementation and a few smaller vendors for the embedded market.

Also Oracle just added initial AOT on Java 9, with plans to extend it to other platforms, and eventually (long term plan) rewrite everything in Java as part of Project Metropolis.

Oracle also had AOT compilers before Sun's acquisition, like JServe and JRockit.

Why does it seem no one does it?

Sun was religiously against AOT, leaving it to third party commercial vendors.

And since the rise of FOSS most developers think it is outrageous to pay for compilers, only Fortune 500s buy such compilers.

Re:Scala Native with Denys Shabalin – Software Engineering D... by nerdponx on Thursday October 19, 2017 @04:02PM (#15511094)
Are they all proprietary/closed-source? When I was first learning about Clojure I really wanted a native JVM compiler, but as a hobbyist I was not about to go all-in on an enterprise compiler. The only FOSS solution I found was GCJ.

That, and "the JVM startup is slow!" seems to be a popular argument against Clojure and Scala here on the Intertubes.

Re:Scala Native with Denys Shabalin – Software Engineering D... by pacala on Thursday October 19, 2017 @09:45AM (#15507797)
How about generating .so, callable from other environments, for example CPython?
Re:Scala Native with Denys Shabalin – Software Engineering D... by densh on Thursday October 19, 2017 @11:01AM (#15508492)
This is on our roadmap, stay tuned.
Re:Scala Native with Denys Shabalin – Software Engineering D... by dmytrish on Thursday October 19, 2017 @08:39AM (#15507346)
Scala may be written in functional style, which is a poor match for JVM (e.g.: uglyness of `@tailrec` annotations, absence of mutually-recursive functions, JVMs GCs are not usually optimized for that many ephemeral objects, etc).

Native code is not much better as a compilation target for FP, but at least you don't have to fight through JVM constraints first (GHC compiles to pretty efficient native code).