Skip to content

Instantly share code, notes, and snippets.

@petitviolet
Last active January 9, 2017 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petitviolet/026979105dbe447c93d47a778a604619 to your computer and use it in GitHub Desktop.
Save petitviolet/026979105dbe447c93d47a778a604619 to your computer and use it in GitHub Desktop.
[Scala]de-compiled Value Class byte-code

de-compiled result of value-class

for compare

object Raw {
  case class UserRaw(id: Long, name: String)
}
// class version 50.0 (50)
// access flags 0x31
public final class net/petitviolet/sandbox/perf/Raw$ {

  // compiled from: ValueClass.scala

  ATTRIBUTE Scala : unknown

  ATTRIBUTE ScalaInlineInfo : unknown

  // access flags 0x19
  public final static Lnet/petitviolet/sandbox/perf/Raw$; MODULE$

  // access flags 0x9
  public static <clinit>()V
    NEW net/petitviolet/sandbox/perf/Raw$
    INVOKESPECIAL net/petitviolet/sandbox/perf/Raw$.<init> ()V
    RETURN
    MAXSTACK = 1
    MAXLOCALS = 0

  // access flags 0x2
  private <init>()V
   L0
    LINENUMBER 62 L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ALOAD 0
    PUTSTATIC net/petitviolet/sandbox/perf/Raw$.MODULE$ : Lnet/petitviolet/sandbox/perf/Raw$;
    RETURN
   L1
    LOCALVARIABLE this Lnet/petitviolet/sandbox/perf/Raw$; L0 L1 0
    MAXSTACK = 1
    MAXLOCALS = 1
}

Value-Class

object Value {
  // not Value class
  case class UserValue(id: IdValue, name: NameValue)
  case class IdValue(value: Long) extends AnyVal
  case class NameValue(value: String) extends AnyVal
}
// class version 50.0 (50)
// access flags 0x31
public final class net/petitviolet/sandbox/perf/Value$ {

  // compiled from: ValueClass.scala

  ATTRIBUTE Scala : unknown

  ATTRIBUTE ScalaInlineInfo : unknown

  // access flags 0x19
  public final static Lnet/petitviolet/sandbox/perf/Value$; MODULE$

  // access flags 0x9
  public static <clinit>()V
    NEW net/petitviolet/sandbox/perf/Value$
    INVOKESPECIAL net/petitviolet/sandbox/perf/Value$.<init> ()V
    RETURN
    MAXSTACK = 1
    MAXLOCALS = 0

  // access flags 0x2
  private <init>()V
   L0
    LINENUMBER 95 L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ALOAD 0
    PUTSTATIC net/petitviolet/sandbox/perf/Value$.MODULE$ : Lnet/petitviolet/sandbox/perf/Value$;
    RETURN
   L1
    LOCALVARIABLE this Lnet/petitviolet/sandbox/perf/Value$; L0 L1 0
    MAXSTACK = 1
    MAXLOCALS = 1
}

non Value-Class

object Normal {
  case class User(id: Id, name: Name)
  case class Id(value: Long)
  case class Name(value: String)
}
// class version 50.0 (50)
// access flags 0x31
public final class net/petitviolet/sandbox/perf/Normal$ {

  // compiled from: ValueClass.scala

  ATTRIBUTE Scala : unknown

  ATTRIBUTE ScalaInlineInfo : unknown

  // access flags 0x19
  public final static Lnet/petitviolet/sandbox/perf/Normal$; MODULE$

  // access flags 0x9
  public static <clinit>()V
    NEW net/petitviolet/sandbox/perf/Normal$
    INVOKESPECIAL net/petitviolet/sandbox/perf/Normal$.<init> ()V
    RETURN
    MAXSTACK = 1
    MAXLOCALS = 0

  // access flags 0x2
  private <init>()V
   L0
    LINENUMBER 66 L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ALOAD 0
    PUTSTATIC net/petitviolet/sandbox/perf/Normal$.MODULE$ : Lnet/petitviolet/sandbox/perf/Normal$;
    RETURN
   L1
    LOCALVARIABLE this Lnet/petitviolet/sandbox/perf/Normal$; L0 L1 0
    MAXSTACK = 1
    MAXLOCALS = 1
}

instantiation

common codes.

val n: Int =new Random().nextInt(100)
val id: Long = new Random().nextInt(100).toLong
val name = UUID.randomUUID().toString

instantiate raw class

def raw(): Raw.UserRaw = {
  Raw.UserRaw(id, name)
}
  // access flags 0x1
  public raw()Lnet/petitviolet/sandbox/perf/Raw$UserRaw;
   L0
    LINENUMBER 27 L0
    NEW net/petitviolet/sandbox/perf/Raw$UserRaw
    DUP
    ALOAD 0
    INVOKEVIRTUAL net/petitviolet/sandbox/perf/ValueClass.id ()J
    ALOAD 0
    INVOKEVIRTUAL net/petitviolet/sandbox/perf/ValueClass.name ()Ljava/lang/String;
    INVOKESPECIAL net/petitviolet/sandbox/perf/Raw$UserRaw.<init> (JLjava/lang/String;)V
    ARETURN
   L1
    LOCALVARIABLE this Lnet/petitviolet/sandbox/perf/ValueClass; L0 L1 0
    MAXSTACK = 5
    MAXLOCALS = 1

instantiate value class

def value(): Value.UserValue = {
  Value.UserValue(Value.IdValue(id), Value.NameValue(name))
}
  // access flags 0x1
  public value()Lnet/petitviolet/sandbox/perf/Value$UserValue;
   L0
    LINENUMBER 39 L0
    NEW net/petitviolet/sandbox/perf/Value$UserValue
    DUP
    ALOAD 0
    INVOKEVIRTUAL net/petitviolet/sandbox/perf/ValueClass.id ()J
    ALOAD 0
    INVOKEVIRTUAL net/petitviolet/sandbox/perf/ValueClass.name ()Ljava/lang/String;
    INVOKESPECIAL net/petitviolet/sandbox/perf/Value$UserValue.<init> (JLjava/lang/String;)V
    ARETURN
   L1
    LOCALVARIABLE this Lnet/petitviolet/sandbox/perf/ValueClass; L0 L1 0
    MAXSTACK = 5
    MAXLOCALS = 1

instantiate non-value class

def normal(): Normal.User = {
  Normal.User(Normal.Id(id), Normal.Name(name))
}
  // access flags 0x1
  public normal()Lnet/petitviolet/sandbox/perf/Normal$User;
   L0
    LINENUMBER 33 L0
    NEW net/petitviolet/sandbox/perf/Normal$User
    DUP
    NEW net/petitviolet/sandbox/perf/Normal$Id
    DUP
    ALOAD 0
    INVOKEVIRTUAL net/petitviolet/sandbox/perf/ValueClass.id ()J
    INVOKESPECIAL net/petitviolet/sandbox/perf/Normal$Id.<init> (J)V
    NEW net/petitviolet/sandbox/perf/Normal$Name
    DUP
    ALOAD 0
    INVOKEVIRTUAL net/petitviolet/sandbox/perf/ValueClass.name ()Ljava/lang/String;
    INVOKESPECIAL net/petitviolet/sandbox/perf/Normal$Name.<init> (Ljava/lang/String;)V
    INVOKESPECIAL net/petitviolet/sandbox/perf/Normal$User.<init> (Lnet/petitviolet/sandbox/perf/Normal$Id;Lnet/petitviolet/sandbox/perf/Normal$Name;)V
    ARETURN
   L1
    LOCALVARIABLE this Lnet/petitviolet/sandbox/perf/ValueClass; L0 L1 0
    MAXSTACK = 6
    MAXLOCALS = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment