As per Scala 2.10, what are the advantages (if any) of emitting bytecode for the JVM 1.7, when compared to the default of emitting for the 1.6?
Scala is compiled into Java Byte Code which is executed by the Java Virtual Machine (JVM). This means that Scala and Java have a common runtime platform. If you or your organization has standardized on Java, Scala is not going to be a total stranger in your architecture. It's a different language, but the same runtime.
Can I run my scala program without JVM using scala-native? Yes, the goal of Scala Native is to support compilation of Scala programs without any kind of VM.
Although Scala compiles to Java bytecode, it is designed to improve on many of the perceived shortcomings of the Java language.
What Is the Bytecode? Bytecode is the intermediate representation of a Java program, allowing a JVM to translate a program into machine-level assembly instructions. When a Java program is compiled, bytecode is generated in the form of a . class file.
Previous Scala versions emitted version 49.0 of the byte code, which corresponded to Java 5. With Scala 2.10 version the default was changed to version 50.0, corresponding to Java 6 and which has the principal advantage of activating the faster verifier introduced with that version, so it should lead to (slightly) better run time performance.
As you note, with 2.10 it became possible to emit version 51.0 byte code, which corresponds to Java 7. There are a few differences between version 50.0 and version 51.0: the biggest is the inclusion of the invokedynamic
instruction, with the plumbing that goes with it (see the class file format definition for the gory details).
As far as Scala usage of the 51.0 byte code goes, even though the technical parts are in place it is my understanding that work is still at an experimental stage in using this feature. See this EPFL presentation and this thread which shows that the team is working on getting the performance benefits of method handles without having to introduce a dependency on Java 7.
Scala 2.11 maintained the default of emitting version 50.0 bytecode, but the official plan is now to jump straight to Java 8 bytecode with Scala 2.12. In the meantime, there is a new back-end available for Scala 2.11 that will let you try out some of the features that are being prototyped for Scala 2.12, and which will become the default back-end with Scala 2.12.
Anyway, the long-awaited proposed benefits all come from using the invokedynamic
bytecode (and its associated MethodHandle structures). They include:
(Spoiler: Using MethodHandles
to implement closures in the experimental backend is currently slower than the present optimised closure creation!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With