Skip to content

Instantly share code, notes, and snippets.

@kmizu
Created January 7, 2020 05:59
Show Gist options
  • Save kmizu/bdd6f2fbcbe8cfed04752d609b3c22e0 to your computer and use it in GitHub Desktop.
Save kmizu/bdd6f2fbcbe8cfed04752d609b3c22e0 to your computer and use it in GitHub Desktop.
Disassemble Hello.scala
[k.mizushima]$ javap -c Hello
Compiled from "Hello.scala"
public class Hello {
public int return100();
Code:
0: new #4 // class java/lang/Object
3: dup
4: invokespecial #26 // Method java/lang/Object."<init>":()V
7: astore_1
8: getstatic #32 // Field scala/runtime/RichInt$.MODULE$:Lscala/runtime/RichInt$;
11: getstatic #37 // Field scala/Predef$.MODULE$:Lscala/Predef$;
14: iconst_1
15: invokevirtual #41 // Method scala/Predef$.intWrapper:(I)I
18: sipush 1000
21: invokevirtual #45 // Method scala/runtime/RichInt$.to$extension0:(II)Lscala/collection/immutable/Range$Inclusive;
24: aload_1
25: invokedynamic #67, 0 // InvokeDynamic #0:apply$mcVI$sp:(Ljava/lang/Object;)Lscala/runtime/java8/JFunction1$mcVI$sp;
30: invokevirtual #71 // Method scala/collection/immutable/Range$Inclusive.foreach$mVc$sp:(Lscala/Function1;)V
33: iconst_0
34: goto 58
37: astore_2
38: aload_2
39: invokevirtual #75 // Method scala/runtime/NonLocalReturnControl.key:()Ljava/lang/Object;
42: aload_1
43: if_acmpne 53
46: aload_2
47: invokevirtual #78 // Method scala/runtime/NonLocalReturnControl.value$mcI$sp:()I
50: goto 55
53: aload_2
54: athrow
55: goto 58
58: ireturn
Exception table:
from to target type
8 34 37 Class scala/runtime/NonLocalReturnControl
public static final void $anonfun$return100$1(java.lang.Object, int);
Code:
0: iload_1
1: bipush 100
3: if_icmpne 17
6: new #86 // class scala/runtime/NonLocalReturnControl$mcI$sp
9: dup
10: aload_0
11: bipush 100
13: invokespecial #88 // Method scala/runtime/NonLocalReturnControl$mcI$sp."<init>":(Ljava/lang/Object;I)V
16: athrow
17: return
public Hello();
Code:
0: aload_0
1: invokespecial #26 // Method java/lang/Object."<init>":()V
4: return
}
class Hello {
def return100: Int = {
for(i <- 1 to 1000)
if(i == 100) return 100
0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment