Are there any good writeups of how the Scala compiler maps various Scala features to bytecode?
A quick google turned up the supporting material from David Pollak's 2009 talk
https://github.com/dpp/jvm_summit_2009/blob/master/scala_fancy_pants.pdf
But I suspect this may be both dated and incomplete.
I could try and gather this data myself via scalap javap, but it would be nice to benefit from someone elses effort and insight.
on the Scala REPL, use :javap -c
to see the generated bytecode.
For instance:
scala> class Bytes { def a = println("hello") }
defined class Bytes
scala> :javap -c Bytes
Compiled from "<console>"
public class Bytes extends java.lang.Object{
public void a();
Code:
0: getstatic #13; //Field scala/Predef$.MODULE$:Lscala/Predef$;
3: ldc #15; //String hello
5: invokevirtual #19; //Method scala/Predef$.println:(Ljava/lang/Object;)V
8: return
public Bytes();
Code:
0: aload_0
1: invokespecial #24; //Method java/lang/Object."<init>":()V
4: return
}
None that I'm aware of. Consider using a bytecode inspection tool to inspect the code that the compiler produces. It is often useful when writing performance-critical code to verify whether specialization has been properly applied, closures eliminated, arrays are being accessed directly via bytecode instructions, macros properly expanded, etc.
If you are using Sublime, there is a this plugin for viewing the bytecode.
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