Skip to content

Instantly share code, notes, and snippets.

@luciferous
Last active August 29, 2015 14:15
Show Gist options
  • Save luciferous/ec2255344440599579ea to your computer and use it in GitHub Desktop.
Save luciferous/ec2255344440599579ea to your computer and use it in GitHub Desktop.
Comparison of a polymorphic and monomorphic value class
scala> class Bar(val a: Object) extends AnyVal
defined class Bar
scala> val x = new Bar(new Object)
x: Bar = Bar@5d0b5bcb
scala> :javap -v x
Size 599 bytes
MD5 checksum cc127130545aa10c64d151abbffcae83
Compiled from "<console>"
public class
SourceFile: "<console>"
InnerClasses:
public static #26= #23 of #25; //=class of class $line18/$read
public static #26= #2 of #23; //=class of class
Scala: length = 0x0
minor version: 0
major version: 50
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Utf8
#2 = Class #1 //
#3 = Utf8 java/lang/Object
#4 = Class #3 // java/lang/Object
#5 = Utf8 <console>
#6 = Utf8 MODULE$
#7 = Utf8 L;
#8 = Utf8 <clinit>
#9 = Utf8 ()V
#10 = Utf8 <init>
#11 = NameAndType #10:#9 // "<init>":()V
#12 = Methodref #2.#11 // ."<init>":()V
#13 = Utf8 x
#14 = Utf8 Ljava/lang/Object;
#15 = Utf8 ()Ljava/lang/Object;
#16 = NameAndType #13:#14 // x:Ljava/lang/Object;
#17 = Fieldref #2.#16 // .x:Ljava/lang/Object;
#18 = Utf8 this
#19 = Methodref #4.#11 // java/lang/Object."<init>":()V
#20 = NameAndType #6:#7 // MODULE$:L;
#21 = Fieldref #2.#20 // .MODULE$:L;
#22 = Utf8
#23 = Class #22 //
#24 = Utf8 $line18/$read
#25 = Class #24 // $line18/$read
#26 = Utf8
#27 = Utf8 Code
#28 = Utf8 LocalVariableTable
#29 = Utf8 LineNumberTable
#30 = Utf8 SourceFile
#31 = Utf8 InnerClasses
#32 = Utf8 Scala
{
public static final MODULE$;
flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL
public static {};
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=1, locals=0, args_size=0
0: new #2 // class
3: invokespecial #12 // Method "<init>":()V
6: return
public java.lang.Object x();
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: getfield #17 // Field x:Ljava/lang/Object;
4: areturn
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this L;
LineNumberTable:
line 9: 0
public ();
flags: ACC_PUBLIC
Code:
stack=3, locals=1, args_size=1
0: aload_0
1: invokespecial #19 // Method java/lang/Object."<init>":()V
4: aload_0
5: putstatic #21 // Field MODULE$:L;
8: aload_0
9: new #4 // class java/lang/Object
12: dup
13: invokespecial #19 // Method java/lang/Object."<init>":()V
16: putfield #17 // Field x:Ljava/lang/Object;
19: return
LocalVariableTable:
Start Length Slot Name Signature
0 20 0 this L;
LineNumberTable:
line 14: 0
line 9: 8
}
scala> class Bar(val a: Object) extends AnyVal
defined class Bar
scala> val x = new Bar(new Object)
x: Bar = Bar@5d0b5bcb
scala> :javap -v x
Size 599 bytes
MD5 checksum cc127130545aa10c64d151abbffcae83
Compiled from "<console>"
public class
SourceFile: "<console>"
InnerClasses:
public static #26= #23 of #25; //=class of class $line18/$read
public static #26= #2 of #23; //=class of class
Scala: length = 0x0
minor version: 0
major version: 50
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Utf8
#2 = Class #1 //
#3 = Utf8 java/lang/Object
#4 = Class #3 // java/lang/Object
#5 = Utf8 <console>
#6 = Utf8 MODULE$
#7 = Utf8 L;
#8 = Utf8 <clinit>
#9 = Utf8 ()V
#10 = Utf8 <init>
#11 = NameAndType #10:#9 // "<init>":()V
#12 = Methodref #2.#11 // ."<init>":()V
#13 = Utf8 x
#14 = Utf8 Ljava/lang/Object;
#15 = Utf8 ()Ljava/lang/Object;
#16 = NameAndType #13:#14 // x:Ljava/lang/Object;
#17 = Fieldref #2.#16 // .x:Ljava/lang/Object;
#18 = Utf8 this
#19 = Methodref #4.#11 // java/lang/Object."<init>":()V
#20 = NameAndType #6:#7 // MODULE$:L;
#21 = Fieldref #2.#20 // .MODULE$:L;
#22 = Utf8
#23 = Class #22 //
#24 = Utf8 $line18/$read
#25 = Class #24 // $line18/$read
#26 = Utf8
#27 = Utf8 Code
#28 = Utf8 LocalVariableTable
#29 = Utf8 LineNumberTable
#30 = Utf8 SourceFile
#31 = Utf8 InnerClasses
#32 = Utf8 Scala
{
public static final MODULE$;
flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL
public static {};
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=1, locals=0, args_size=0
0: new #2 // class
3: invokespecial #12 // Method "<init>":()V
6: return
public java.lang.Object x();
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: getfield #17 // Field x:Ljava/lang/Object;
4: areturn
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this L;
LineNumberTable:
line 9: 0
public ();
flags: ACC_PUBLIC
Code:
stack=3, locals=1, args_size=1
0: aload_0
1: invokespecial #19 // Method java/lang/Object."<init>":()V
4: aload_0
5: putstatic #21 // Field MODULE$:L;
8: aload_0
9: new #4 // class java/lang/Object
12: dup
13: invokespecial #19 // Method java/lang/Object."<init>":()V
16: putfield #17 // Field x:Ljava/lang/Object;
19: return
LocalVariableTable:
Start Length Slot Name Signature
0 20 0 this L;
LineNumberTable:
line 14: 0
line 9: 8
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment