SlideShare una empresa de Scribd logo
1 de 89
Descargar para leer sin conexión
Koichi	
  Sakata  (阪田  浩一)  
@jyukutyo
How	
  Scala	
  code	
  is	
  
expressed	
  in	
  the	
  JVM	
  
-­‐	
  ScalaMatsuri	
  2016	
  -­‐
関ジャバです!
2
@jyukutyo
produced three Java framework books
one was translated into Korean
JUG Leader (KansaiJUG)
blog:Fight the Future
http://jyukutyo.hatenablog.com/
FURYU CORPORATION
age: 36
Koichi Sakata (阪田 浩一)
フリューの阪田です 関ジャバの会長です
I	
  ♥	
  JVM
this	
  session	
  is	
  
for	
  beginners	
  
about	
  JVM	
  
byte	
  codes
このセッションは
JVMのバイトコード初心者向けです
Do	
  you	
  know	
  
what	
  happens	
  
when	
  we	
  compile	
  
Scala	
  code?
Scalaコードをコンパイルする時
何が起こるかご存じでしょうか?
Java
Scala
JRuby
Groovy
C
o
m
p
i
l
e
r
Class	
  
file
cafe babe
0000 0032
0017 0100
JVM
Class	
  
file
Class	
  
file
Class	
  
file
Class	
  
file
Class	
  
file § Runs
§ Interprets
§ Translates
bytecode
into
Native
Machine
Code
Have	
  you	
  ever	
  
opened	
  	
  
a	
  class	
  file?
クラスファイルを開いたことはありますか
First,	
  	
  
let's	
  try	
  opening	
  	
  
a	
  class	
  file	
  	
  
from	
  a	
  simple	
  	
  
Java	
  code
Javaのクラスファイルを開いてみましょう
Hello	
  World	
  (Java)	
  
public	
  class	
  HelloWorld	
  {	
  
	
  	
  public	
  static	
  void	
  main(String[]	
  args)	
  {	
  
	
  	
  	
  	
  System.out.println("Hello,	
  world!");	
  
	
  	
  }	
  
}	
  
§ Compiled	
  into...	
  
§ HelloWorld.class	
  
open	
  
HelloWorld.class	
  
file	
  	
  
with	
  binary	
  editor	
  
e.g.)	
  hexl-­‐find-­‐file	
  
(Emacs)
クラスファイルをバイナリエディタで開く
cafe	
  babe	
  0000	
  0032	
  0017	
  0100	
  0a48	
  656c	
  
6c6f	
  576f	
  726c	
  6407	
  0001	
  0100	
  106a	
  6176	
  
612f	
  6c61	
  6e67	
  2f4f	
  626a	
  6563	
  7407	
  0003	
  
0100	
  1048	
  656c	
  6c6f	
  576f	
  726c	
  642e	
  7363	
  
616c	
  6101	
  001e	
  4c73	
  6361	
  6c61	
  2f72	
  6566	
  
6c65	
  6374	
  2f53	
  6361	
  6c61	
  5369	
  676e	
  6174	
  
7572	
  653b	
  0100	
  0562	
  7974	
  6573	
  0100	
  ef06	
  
0115	
  3a51	
  2101	
  0209	
  0215	
  0921	
  0253	
  336d	
  
593e	
  3c76	
  4e1d	
  3765	
  1505	
  1911	
  6102	
  1f66	
  
5b42	
  2418	
  5050	
  0201	
  2109	
  3171	
  2144	
  0103	
  
0d15	
  4121	
  0123	
  010a	
  0529	
  4155	
  0d1c	
  3770	
  
2f3e	
  1448	
  0e5a	
  0a03	
  0f29	
  0122	
  6103	
  080e	
  
0331	
  5111	
  2144	
  0106	
  670e	
  0c47	
  2e59	
  0503	
  
1f31	
  1161	
  2111	
  387a	
  2516	
  3407	
  2242	
  0908
you	
  will	
  
close	
  the	
  editor	
  
right	
  away
すぐにエディタを閉じるでしょう
class	
  file	
  
has	
  a	
  format
クラスファイルには
フォーマットがあります
ClassFile	
  {	
  
	
  	
  u4	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  magic;	
  
	
  	
  u2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  minor_version;	
  
	
  	
  u2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  major_version;	
  
	
  	
  u2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  constant_pool_count;	
  
	
  	
  cp_info	
  	
  constant_pool[constant_pool_count-­‐1];	
  
	
  	
  u2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  access_flags;	
  
	
  	
  u2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  this_class;	
  
	
  	
  u2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  super_class;	
  
	
  	
  u2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  interfaces_count;	
  
	
  	
  u2	
  	
  	
  	
  	
  	
  interfaces[interfaces_count];	
  
...	
  
-­‐-­‐	
  u1	
  represents	
  one-­‐byte	
  quantity,	
  
	
  	
  	
  Hexadecimal	
  2	
  digit.
...	
  
	
  	
  u2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  fields_count;	
  
	
  	
  field_info	
  	
  	
  	
  	
  fields[fields_count];	
  
	
  	
  u2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  methods_count;	
  
	
  	
  method_info	
  	
  	
  methods[methods_count];	
  
	
  	
  u2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  attributes_count;	
  
	
  	
  attribute_info	
  attributes[attributes_count];	
  
}	
  
-­‐-­‐	
  u1	
  represents	
  one-­‐byte	
  quantity,	
  
	
  	
  	
  Hexadecimal	
  2	
  digit.
u1が1バイト
16進数では2桁になります
Let's	
  
try	
  again
cafe	
  babe	
  0000	
  0032	
  0017	
  0100	
  0a48	
  656c	
  
6c6f	
  576f	
  726c	
  6407	
  0001	
  0100	
  106a	
  6176	
  
612f	
  6c61	
  6e67	
  2f4f	
  626a	
  6563	
  7407	
  0003	
  
0100	
  1048	
  656c	
  6c6f	
  576f	
  726c	
  642e	
  7363	
  
616c	
  6101	
  001e	
  4c73	
  6361	
  6c61	
  2f72	
  6566	
  
6c65	
  6374	
  2f53	
  6361	
  6c61	
  5369	
  676e	
  6174	
  
7572	
  653b	
  0100	
  0562	
  7974	
  6573	
  0100	
  ef06	
  
0115	
  3a51	
  2101	
  0209	
  0215	
  0921	
  0253	
  336d	
  
593e	
  3c76	
  4e1d	
  3765	
  1505	
  1911	
  6102	
  1f66	
  
5b42	
  2418	
  5050	
  0201	
  2109	
  3171	
  2144	
  0103	
  
0d15	
  4121	
  0123	
  010a	
  0529	
  4155	
  0d1c	
  3770	
  
2f3e	
  1448	
  0e5a	
  0a03	
  0f29	
  0122	
  6103	
  080e	
  
0331	
  5111	
  2144	
  0106	
  670e	
  0c47	
  2e59	
  0503	
  
1f31	
  1161	
  2111	
  387a	
  2516	
  3407	
  2242	
  0908
cafe	
  babe	
  0000	
  0032	
  
ClassFile	
  {	
  
	
  	
  u4	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  magic;	
  
	
  	
  u2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  minor_version;	
  
	
  	
  u2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  major_version;	
  
"magic"	
  is	
  always	
  
"0xCAFEBABE"
major:	
  0x0032	
  =	
  50	
  
minor:	
  0x0000	
  =	
  0	
  
50.0	
  means	
  Java	
  SE	
  6	
  
51.0	
  is	
  7,	
  52.0	
  is	
  8...
Yes!
but,	
  this	
  is	
  
purgatory
でもこれは苦行です
Never	
  mind!	
  
We	
  have	
  
a	
  handy	
  tool!
便利なツールがあります!
javap	
  command	
  
The	
  Java	
  Class	
  File	
  Disassembler	
  
§ included	
  in	
  JDK	
  
§ `javap	
  -­‐v	
  [FQCN]`	
  
§ Scala	
  REPL	
  
§ scala>	
  :javap	
  [FQCN]	
  
§ equivalent	
  to	
  `javap	
  -­‐v`	
  
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javap.html
javap - Java クラスファイル逆アセンブラ
so,	
  a	
  class	
  file	
  	
  
can	
  be	
  
disassembled	
  
to	
  Java	
  Classes
クラスファイルはJavaのクラスに
逆アセンブルできるのです
javap	
  -­‐v	
  HelloWorld
public	
  class	
  HelloWorld	
  
	
  	
  minor	
  version:	
  0	
  
	
  	
  major	
  version:	
  52	
  
Constant	
  pool:	
  
	
  	
  	
  #1	
  =	
  Methodref	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #6.#15	
  	
  	
  	
  	
  	
  	
  	
  
//	
  java/lang/Object."<init>":()V	
  
	
  	
  	
  #2	
  =	
  Fieldref	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #16.#17	
  	
  	
  	
  	
  	
  	
  
//	
  java/lang/System.out:Ljava/io/
PrintStream;	
  
	
  	
  	
  #3	
  =	
  String	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #18	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Hello,	
  world!	
  
	
  	
  	
  #4	
  =	
  Methodref	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #19.#20	
  	
  	
  	
  	
  	
  	
  
//	
  java/io/PrintStream.println:(Ljava/
lang/String;)V
Constant	
  pool	
  is	
  
a	
  table	
  of	
  
symbolic	
  
information
コンスタントプールは
シンボル情報のテーブル
public	
  static	
  void	
  
main(java.lang.String[]);	
  
	
  Code:	
  
	
  	
  	
  	
  	
  	
  	
  0:	
  getstatic	
  	
  	
  	
  	
  #2	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  3:	
  ldc	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #3	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  5:	
  invokevirtual	
  #4	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  8:	
  return	
  
JVM	
  instructions	
  
aaload aastore aconst_null aload
anewarray areturn arraylength astore
athrow baload bastore bipush
caload castore checkcast d2f
d2i d2l dadd daload
dastore dcmp<op> dconst_<d> ddiv
dload dmul dneg ...
about	
  200	
  
instructions
Since	
  first	
  
release	
  of	
  Java,	
  
added	
  instruction	
  
is	
  ...
Javaが最初にリリースされてから
追加されたJVM命令は...
only	
  ONE!
Initial	
  design	
  	
  
of	
  JVM	
  	
  
is	
  excellent!
JVMは初期設計から優秀だった!
instructions	
  of	
  method	
  call	
  
invokevirtual
invoke	
  instance	
  method;	
  
dispatched	
  based	
  on	
  class
invokeinterface invoke	
  interface	
  method
invokestatic invoke	
  static	
  method
invokespecial
invoke	
  method;	
  
superclass,	
  private,	
  
constructor...
invokedynamic invoke	
  dynamic	
  method
public	
  static	
  void	
  
main(java.lang.String[]);	
  
	
  Code:	
  
	
  	
  	
  	
  	
  	
  	
  0:	
  getstatic	
  	
  	
  	
  	
  #2	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  3:	
  ldc	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #3	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  5:	
  invokevirtual	
  #4	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  8:	
  return	
  
-­‐-­‐	
  #0	
  =	
  index	
  of	
  Constant	
  pool  
public	
  class	
  HelloWorld	
  
Constant	
  pool:	
  
	
  	
  	
  #1	
  =	
  Methodref	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #6.#15	
  	
  	
  	
  	
  	
  	
  	
  
//	
  java/lang/Object."<init>":()V	
  
	
  	
  	
  #2	
  =	
  Fieldref	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #16.#17	
  	
  	
  	
  	
  	
  	
  
//	
  java/lang/System.out:Ljava/io/
PrintStream;	
  
	
  	
  	
  #3	
  =	
  String	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #18	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Hello,	
  world!	
  
	
  	
  	
  #4	
  =	
  Methodref	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #19.#20	
  	
  	
  	
  	
  	
  	
  
//	
  java/io/PrintStream.println:(Ljava/
lang/String;)V	
  
...
OK!	
  
It's	
  Scala's	
  turn!
Hello	
  world
Hello	
  World	
  (Scala)	
  
object	
  HelloWorld	
  {	
  
	
  	
  def	
  main(args:	
  Array[String])	
  {	
  
	
  	
  	
  	
  println("Hello,	
  world!")	
  
	
  	
  }	
  
}	
  
§ Compiled	
  into...	
  
§ HelloWorld.class	
  
§ HelloWorld$.class	
  
public	
  final	
  class	
  HelloWorld	
  
Constant	
  pool:	
  
	
  	
  #15	
  =	
  NameAndType	
  	
  	
  	
  	
  	
  	
  	
  #13:#14	
  	
  	
  	
  	
  	
  	
  
//	
  MODULE$:LHelloWorld$;	
  
	
  	
  #16	
  =	
  Fieldref	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #12.#15	
  	
  	
  	
  	
  	
  	
  
//	
  HelloWorld$.MODULE$:LHelloWorld$;	
  
	
  	
  #17	
  =	
  NameAndType	
  	
  	
  	
  	
  	
  	
  	
  #9:#10	
  	
  	
  	
  	
  	
  	
  	
  
//	
  main:([Ljava/lang/String;)V	
  
	
  	
  #18	
  =	
  Methodref	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #12.#17	
  	
  	
  	
  	
  	
  	
  
//	
  HelloWorld$.main:	
  
([Ljava/lang/String;)V	
  
...
public	
  static	
  void	
  	
  
main(java.lang.String[]);	
  
	
  	
  0:	
  getstatic	
  	
  	
  	
  	
  #16	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Field	
  HelloWorld$.	
  
MODULE$:LHelloWorld$;	
  
	
  	
  3:	
  aload_0	
  
	
  	
  4:	
  invokevirtual	
  #18	
  
//	
  Method	
  HelloWorld$.main:	
  
([Ljava/lang/String;)V	
  
	
  	
  7:	
  return	
  
-­‐-­‐	
  4:	
  in	
  Java	
  
HelloWorld$.MODULE$.main(arg);
public	
  final	
  class	
  HelloWorld$	
  
-­‐-­‐	
  omit	
  Constant	
  pool  
	
  	
  public	
  static	
  {};	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  0:	
  new	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #2	
  	
  	
  	
  	
  	
  
//	
  class	
  HelloWorld$	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  3:	
  invokespecial	
  #12	
  	
  	
  	
  	
  
//	
  Method	
  "<init>":()V	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  6:	
  return	
  
-­‐-­‐	
  <init>	
  means	
  constructor	
  
 	
  public	
  void	
  main(java.lang.String[]);	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  0:	
  getstatic	
  	
  	
  	
  	
  #19	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Field	
  scala/Predef$.MODULE$:	
  
Lscala/Predef$;	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  3:	
  ldc	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #21	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  String	
  Hello,	
  world!	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  5:	
  invokevirtual	
  #25	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Method	
  scala/Predef$.println:	
  
(Ljava/lang/Object;)V	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  8:	
  return	
  
you	
  can	
  read	
  it!
The	
  following	
  samples	
  
are	
  quoted	
  	
  
from	
  tutorials	
  	
  
in	
  Scala	
  official	
  site	
  
http://docs.scala-­‐lang.org/tutorials/
これ以降で使用するサンプルは
Scalaの公式サイトのチュートリアルです
Traits
trait	
  Similarity	
  {	
  
	
  	
  def	
  isSimilar(x:	
  Any):	
  Boolean	
  
	
  	
  def	
  isNotSimilar(x:	
  Any):	
  Boolean	
  =	
  
	
  !isSimilar(x)	
  
}	
  
class	
  Point(xc:	
  Int,	
  yc:	
  Int)	
  	
  
extends	
  Similarity	
  {	
  
	
  	
  var	
  x:	
  Int	
  =	
  xc	
  
	
  	
  var	
  y:	
  Int	
  =	
  yc	
  
	
  	
  def	
  isSimilar(obj:	
  Any)	
  =	
  
	
  	
  	
  	
  obj.isInstanceOf[Point]	
  &&	
  
	
  	
  	
  	
  obj.asInstanceOf[Point].x	
  ==	
  x	
  
}	
  
§ Compiled	
  into...	
  
§ Similarity.class	
  
§ Similarity$class.class	
  
§ Point.class	
  
javap	
  -­‐v
public	
  interface	
  Similarity	
  
	
  	
  public	
  abstract	
  boolean	
  	
  
isSimilar(java.lang.Object);	
  
	
  	
  	
  
	
  	
  public	
  abstract	
  boolean	
  	
  
isNotSimilar(java.lang.Object);	
  
public	
  abstract	
  class	
  Similarity$class	
  
	
  	
  public	
  static	
  boolean	
  	
  
isNotSimilar(Similarity,j.l.Object);	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  0:	
  aload_0	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  1:	
  aload_1	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  2:	
  invokeinterface	
  #13,	
  	
  2	
  	
  	
  	
  	
  	
  
//	
  InterfaceMethod	
  
Similarity.isSimilar:	
  
(Ljava/lang/Object;)Z	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  7:	
  ifeq	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  14	
  
	
  	
  	
  	
  	
  	
  	
  	
  10:	
  iconst_0	
  
	
  	
  	
  	
  	
  	
  	
  	
  11:	
  goto	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  15	
  
	
  	
  	
  	
  	
  	
  	
  	
  14:	
  iconst_1	
  
	
  	
  	
  	
  	
  	
  	
  	
  15:	
  ireturn
a	
  trait	
  is	
  	
  
divided	
  into	
  	
  
an	
  interface	
  and	
  
an	
  abstract	
  class
トレイトはインタフェースと
抽象クラスに分かれます
Case	
  Classes
abstract	
  class	
  Term	
  
case	
  class	
  Var(name:	
  String)	
  
	
  extends	
  Term	
  
case	
  class	
  Fun(arg:	
  String,	
  body:	
  Term)	
  	
  
extends	
  Term	
  
case	
  class	
  App(f:	
  Term,	
  v:	
  Term)	
  	
  
extends	
  Term	
  
§ Compiled	
  into...	
  
§ Term.class	
  
§ App.class	
  
§ App$.class	
  
§ Fun.class	
  
§ Fun$.class	
  
§ Var.class	
  
§ Var$.class	
  
javap	
  -­‐v
public	
  class	
  App	
  extends	
  Term	
  
	
  implements	
  s.Product,s.Serializable	
  
	
  	
  public	
  static	
  	
  
s.Option<scala.Tuple2<Term,	
  Term>>	
  
unapply(App);	
  
	
  	
  public	
  static	
  App	
  apply(Term,	
  Term);	
  
	
  	
  public	
  ...	
  tupled();	
  
	
  	
  public	
  ...	
  curried();	
  
	
  	
  public	
  Term	
  f();	
  
	
  	
  public	
  Term	
  v();	
  
	
  	
  public	
  App	
  copy(Term,	
  Term);	
  
	
  	
  public	
  j.l.String	
  productPrefix();	
  
	
  	
  public	
  boolean	
  equals(j.l.Object);	
  
...
public	
  final	
  class	
  App$	
  extends	
  	
  
s.r.AbstractFunction2<Term,	
  Term,	
  App>	
  
implements	
  scala.Serializable	
  
	
  	
  public	
  App	
  apply(Term,	
  Term);	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  0:	
  new	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #23	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  class	
  App	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  3:	
  dup	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  4:	
  aload_1	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  5:	
  aload_2	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  6:	
  invokespecial	
  #26	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Method	
  App."<init>":(LTerm;LTerm;)V	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  9:	
  areturn	
  
Fun	
  and	
  Var	
  looks	
  
the	
  same	
  as	
  App
FunとVarも同様の内容です
Scala	
  compiler	
  
generates	
  	
  
many	
  functions	
  
from	
  few	
  snippets	
  
of	
  code
Scalaコンパイラは少ないコードから
多くの機能を生成しています
Pattern	
  Matching
object	
  MatchTest2	
  extends	
  App	
  {	
  
	
  	
  def	
  matchTest(x:	
  Any):	
  Any	
  =	
  x	
  match	
  
	
  	
  {	
  
	
  	
  	
  	
  case	
  1	
  =>	
  "one"	
  
	
  	
  	
  	
  case	
  "two"	
  =>	
  2	
  
	
  	
  	
  	
  case	
  y:	
  Int	
  =>	
  "scala.Int"	
  
	
  	
  }	
  
	
  	
  println(matchTest("two"))	
  
}
§ Compiled	
  into...	
  
§ MatchTest2.class	
  
§ MatchTest2$.class	
  
§ MatchTest2$delayedInit$body.class	
  
javap	
  -­‐v
public	
  final	
  class	
  MatchTest2$	
  	
  
implements	
  scala.App	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  7:	
  invokestatic	
  	
  #67	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Method	
  BoxesRunTime.equals:..	
  
	
  	
  	
  	
  	
  	
  	
  	
  10:	
  ifeq	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  19	
  
	
  	
  	
  	
  	
  	
  	
  	
  13:	
  ldc	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #69	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  String	
  one	
  
	
  	
  	
  	
  	
  	
  	
  	
  15:	
  astore_3	
  
	
  	
  	
  	
  	
  	
  	
  	
  16:	
  goto	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  46	
  
	
  	
  	
  	
  	
  	
  	
  	
  19:	
  ldc	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #71	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  String	
  two	
  
	
  	
  	
  	
  	
  	
  	
  	
  21:	
  aload_2	
  
	
  	
  	
  	
  	
  	
  	
  	
  22:	
  invokevirtual	
  #74	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Method	
  java/lang/Object.equals:	
  
 	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  19:	
  ldc	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #71	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  String	
  two	
  
	
  	
  	
  	
  	
  	
  	
  	
  21:	
  aload_2	
  
	
  	
  	
  	
  	
  	
  	
  	
  22:	
  invokevirtual	
  #74	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Method	
  java/lang/Object.equals:	
  
(Ljava/lang/Object;)Z	
  
	
  	
  	
  	
  	
  	
  	
  	
  25:	
  ifeq	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  36	
  
	
  	
  	
  	
  	
  	
  	
  	
  28:	
  iconst_2	
  
	
  	
  	
  	
  	
  	
  	
  	
  32:	
  astore_3	
  
	
  	
  	
  	
  	
  	
  	
  	
  33:	
  goto	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  46
 	
  	
  	
  	
  	
  	
  	
  36:	
  aload_2	
  
	
  	
  	
  	
  	
  	
  	
  	
  37:	
  instanceof	
  	
  	
  	
  #76	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  class	
  java/lang/Integer	
  
	
  	
  	
  	
  	
  	
  	
  	
  40:	
  ifeq	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  48	
  
	
  	
  	
  	
  	
  	
  	
  	
  43:	
  ldc	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #78	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  String	
  scala.Int	
  
	
  	
  	
  	
  	
  	
  	
  	
  45:	
  astore_3	
  
	
  	
  	
  	
  	
  	
  	
  	
  46:	
  aload_3	
  
	
  	
  	
  	
  	
  	
  	
  	
  47:	
  areturn	
  
...
Compiled	
  into	
  
if	
  statements
if文へコンパイルしています
in	
  case	
  of	
  
another	
  Pattern	
  
Matching...
違うパターンマッチの場合
object	
  MatchTest1	
  {	
  
	
  	
  def	
  matchTest(x:	
  Int):	
  String	
  =	
  x	
  
match	
  {	
  
	
  	
  	
  	
  case	
  1	
  =>	
  "one"	
  
	
  	
  	
  	
  case	
  2	
  =>	
  "two"	
  
	
  	
  	
  	
  case	
  _	
  =>	
  "many"	
  
	
  	
  }	
  
	
  	
  def	
  main(args:	
  Array[String])	
  {	
  
	
  	
  	
  	
  println(matchTest(3))	
  
	
  	
  }	
  
}
javap	
  -­‐v
 	
  	
  	
  	
  	
  	
  	
  	
  3:	
  tableswitch	
  	
  	
  {	
  //	
  1	
  to	
  2	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1:	
  34	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2:	
  29	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  default:	
  24	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  	
  	
  	
  	
  24:	
  ldc	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #16	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  String	
  many	
  
	
  	
  	
  	
  	
  	
  	
  	
  26:	
  goto	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  36	
  
	
  	
  	
  	
  	
  	
  	
  	
  29:	
  ldc	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #18	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  String	
  two	
  
	
  	
  	
  	
  	
  	
  	
  	
  31:	
  goto	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  36	
  
	
  	
  	
  	
  	
  	
  	
  	
  34:	
  ldc	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #20	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  String	
  one	
  
	
  	
  	
  	
  	
  	
  	
  	
  36:	
  areturn
Compiled	
  into	
  
a	
  switch	
  statement
switch文にコンパイルしています
Currying
object	
  CurryTest	
  {	
  
	
  	
  def	
  filter(xs:	
  List[Int],	
  	
  
p:	
  Int	
  =>	
  Boolean):	
  List[Int]	
  =	
  
	
  	
  	
  	
  if	
  (xs.isEmpty)	
  xs	
  
	
  	
  	
  	
  else	
  if	
  (p(xs.head))	
  	
  
xs.head	
  ::	
  filter(xs.tail,	
  p)	
  
	
  	
  	
  	
  else	
  filter(xs.tail,	
  p)	
  
	
  	
  def	
  modN(n:	
  Int)(x:	
  Int)	
  =	
  	
  
((x	
  %	
  n)	
  ==	
  0)	
  
 	
  def	
  main(args:	
  Array[String])	
  {	
  
	
  	
  	
  	
  val	
  nums	
  =	
  List(1,	
  2,	
  3,	
  4,	
  	
  
5,	
  6,	
  7,	
  8)	
  
	
  	
  	
  	
  println(filter(nums,	
  modN(2)))	
  
	
  	
  	
  	
  println(filter(nums,	
  modN(3)))	
  
	
  	
  }	
  
}	
  
§ Compiled	
  into...	
  
§ CurryTest.class	
  
§ CurryTest$.class	
  
§ CurryTest$$anonfun$main$1.class	
  
§ CurryTest$$anonfun$main$2.class	
  
javap	
  -­‐v
public	
  final	
  class	
  	
  
CurryTest$$anonfun$main$1	
  extends	
  
scala.runtime.AbstractFunction1$mcZI$sp	
  
implements	
  scala.Serializable	
  
	
  	
  public	
  boolean	
  apply$mcZI$sp(int);	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  3:	
  iconst_2	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  4:	
  iload_1	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  5:	
  invokevirtual	
  #33	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Method	
  CurryTest$.modN:(II)Z	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  8:	
  ireturn	
  
public	
  final	
  class	
  	
  
CurryTest$$anonfun$main$2	
  extends	
  
scala.runtime.AbstractFunction1$mcZI$sp	
  
implements	
  scala.Serializable	
  
	
  	
  public	
  boolean	
  apply$mcZI$sp(int);	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  3:	
  iconst_3	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  4:	
  iload_1	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  5:	
  invokevirtual	
  #33	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Method	
  CurryTest$.modN:(II)Z	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  8:	
  ireturn	
  
 	
  def	
  main(args:	
  Array[String])	
  {	
  
	
  	
  	
  	
  val	
  nums	
  =	
  List(1,	
  2,	
  3,	
  4,	
  	
  
5,	
  6,	
  7,	
  8)	
  
	
  	
  	
  	
  println(filter(nums,	
  modN(2)))	
  
	
  	
  	
  	
  println(filter(nums,	
  modN(3)))	
  
	
  	
  }	
  
}	
  
each	
  partial	
  
application	
  
creates	
  	
  
a	
  new	
  class
部分適用の箇所ごとに
クラスを生成しています
public	
  final	
  class	
  CurryTest$	
  
...	
  
	
  	
  public	
  void	
  main(java.lang.String[]);	
  
	
  	
  	
  	
  	
  	
  	
  	
  63:	
  invokespecial	
  #82	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Method	
  CurryTest$$anonfun$main$1.	
  
"<init>":()V	
  
	
  	
  	
  	
  	
  	
  	
  	
  66:	
  invokevirtual	
  #41	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Method	
  filter:(Lscala/collection/	
  
immutable/List;Lscala/Function1;)	
  
Lscala/collection/immutable/List;	
  
	
  	
  	
  	
  	
  	
  	
  	
  69:	
  invokevirtual	
  #86	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Method	
  scala/Predef$.println:	
  
(Ljava/lang/Object;)V
public	
  final	
  class	
  	
  
CurryTest$$anonfun$main$1	
  extends	
  
scala.runtime.AbstractFunction1$mcZI$sp	
  
implements	
  scala.Serializable	
  
CurryTest$$anonfun
$main$2	
  
is	
  same
$2も同様です
 	
  	
  	
  	
  	
  	
  	
  81:	
  invokespecial	
  #89	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Method	
  CurryTest$$anonfun$main$2.	
  
"<init>":()V	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  84:	
  invokevirtual	
  #41	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Method	
  filter:(Lscala/collection/	
  
immutable/List;Lscala/Function1;)	
  
Lscala/collection/immutable/List;	
  
	
  	
  	
  	
  	
  	
  	
  	
  87:	
  invokevirtual	
  #86	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
//	
  Method	
  scala/Predef$.println:	
  
(Ljava/lang/Object;)V	
  
§ Summary	
  
§ JVM	
  is	
  excellent!	
  
§ class	
  file	
  has	
  a	
  format	
  
§ javap	
  is	
  useful	
  to	
  understand	
  	
  	
  
Scala	
  at	
  the	
  bytecode	
  level	
  	
  
Try	
  typing	
  "javap"	
  
after	
  you	
  compile	
  
Scala	
  code
Thank	
  you!

Más contenido relacionado

La actualidad más candente

Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングscalaconfjp
 
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...scalaconfjp
 
A Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to ScalaA Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to ScalaDerek Chen-Becker
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesCharles Nutter
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scalatod esking
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Mario Camou Riveroll
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemRafael Winterhalter
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!scalaconfjp
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and FallaciesRoman Elizarov
 
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...Christopher Frohoff
 
A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9Marcus Lagergren
 
Lagergren jvmls-2013-final
Lagergren jvmls-2013-finalLagergren jvmls-2013-final
Lagergren jvmls-2013-finalMarcus Lagergren
 
Why GC is eating all my CPU?
Why GC is eating all my CPU?Why GC is eating all my CPU?
Why GC is eating all my CPU?Roman Elizarov
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/HibernateSunghyouk Bae
 

La actualidad más candente (20)

Zen of Akka
Zen of AkkaZen of Akka
Zen of Akka
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
 
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
 
55 New Features in Java 7
55 New Features in Java 755 New Features in Java 7
55 New Features in Java 7
 
A Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to ScalaA Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to Scala
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scala
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystem
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and Fallacies
 
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
 
A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9
 
Lagergren jvmls-2013-final
Lagergren jvmls-2013-finalLagergren jvmls-2013-final
Lagergren jvmls-2013-final
 
Why GC is eating all my CPU?
Why GC is eating all my CPU?Why GC is eating all my CPU?
Why GC is eating all my CPU?
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/Hibernate
 
Java 5 and 6 New Features
Java 5 and 6 New FeaturesJava 5 and 6 New Features
Java 5 and 6 New Features
 

Similar a How Scala code is expressed in the JVM

Inside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUGInside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUGSylvain Wallez
 
Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Anton Arhipov
 
No dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real worldNo dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real worldtcurdt
 
Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Sylvain Wallez
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaCharles Nutter
 
Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Anton Arhipov
 
Down the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandDown the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandCharles Nutter
 
Object Oriented Programming-JAVA
Object Oriented Programming-JAVAObject Oriented Programming-JAVA
Object Oriented Programming-JAVAHome
 
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Anton Arhipov
 
engage 2016 - Get ready for moving from Java 6 to Java 8 - Now!
engage 2016 - Get ready for moving from Java 6 to Java 8 - Now!engage 2016 - Get ready for moving from Java 6 to Java 8 - Now!
engage 2016 - Get ready for moving from Java 6 to Java 8 - Now!René Winkelmeyer
 
Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topicsRajesh Verma
 
Introduction to java programming tutorial
Introduction to java programming   tutorialIntroduction to java programming   tutorial
Introduction to java programming tutorialjackschitze
 
Monkeybars in the Manor
Monkeybars in the ManorMonkeybars in the Manor
Monkeybars in the Manormartinbtt
 
Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaKeith Bennett
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionGanesh Samarthyam
 

Similar a How Scala code is expressed in the JVM (20)

Inside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUGInside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUG
 
In Vogue Dynamic
In Vogue DynamicIn Vogue Dynamic
In Vogue Dynamic
 
Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012
 
No dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real worldNo dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real world
 
Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible Java
 
Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011
 
Mastering Java ByteCode
Mastering Java ByteCodeMastering Java ByteCode
Mastering Java ByteCode
 
Down the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandDown the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM Wonderland
 
FTD JVM Internals
FTD JVM InternalsFTD JVM Internals
FTD JVM Internals
 
Object Oriented Programming-JAVA
Object Oriented Programming-JAVAObject Oriented Programming-JAVA
Object Oriented Programming-JAVA
 
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011
 
Jvm internals
Jvm internalsJvm internals
Jvm internals
 
engage 2016 - Get ready for moving from Java 6 to Java 8 - Now!
engage 2016 - Get ready for moving from Java 6 to Java 8 - Now!engage 2016 - Get ready for moving from Java 6 to Java 8 - Now!
engage 2016 - Get ready for moving from Java 6 to Java 8 - Now!
 
Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topics
 
Java On Speed
Java On SpeedJava On Speed
Java On Speed
 
Introduction to java programming tutorial
Introduction to java programming   tutorialIntroduction to java programming   tutorial
Introduction to java programming tutorial
 
Monkeybars in the Manor
Monkeybars in the ManorMonkeybars in the Manor
Monkeybars in the Manor
 
Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-java
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - Description
 

Más de Koichi Sakata

Introduction to JIT Compiler in JVM
Introduction to JIT Compiler in JVMIntroduction to JIT Compiler in JVM
Introduction to JIT Compiler in JVMKoichi Sakata
 
Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)
Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)
Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)Koichi Sakata
 
Guide to GraalVM (JJUG CCC 2019 Fall)
Guide to GraalVM (JJUG CCC 2019 Fall)Guide to GraalVM (JJUG CCC 2019 Fall)
Guide to GraalVM (JJUG CCC 2019 Fall)Koichi Sakata
 
Introduction to GraalVM and Native Image
Introduction to GraalVM and Native ImageIntroduction to GraalVM and Native Image
Introduction to GraalVM and Native ImageKoichi Sakata
 
Introduction to GraalVM
Introduction to GraalVMIntroduction to GraalVM
Introduction to GraalVMKoichi Sakata
 
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼうGraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼうKoichi Sakata
 
Bytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte BuddyBytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte BuddyKoichi Sakata
 
Great Ideas in GraalVM
Great Ideas in GraalVMGreat Ideas in GraalVM
Great Ideas in GraalVMKoichi Sakata
 
Graal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerGraal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerKoichi Sakata
 
Kanjava 201804 Java News
Kanjava 201804 Java NewsKanjava 201804 Java News
Kanjava 201804 Java NewsKoichi Sakata
 
KanJava 201804 Career 思い込みから逃れた先には、可能性がある
KanJava 201804 Career 思い込みから逃れた先には、可能性があるKanJava 201804 Career 思い込みから逃れた先には、可能性がある
KanJava 201804 Career 思い込みから逃れた先には、可能性があるKoichi Sakata
 
from Java EE to Jakarta EE
from Java EE to Jakarta EEfrom Java EE to Jakarta EE
from Java EE to Jakarta EEKoichi Sakata
 
Java release cadence has been changed and about Project Amber
Java release cadence has been changed and about Project AmberJava release cadence has been changed and about Project Amber
Java release cadence has been changed and about Project AmberKoichi Sakata
 
JJUG CCC 2017 Fall オレオレJVM言語を作ってみる
JJUG CCC 2017 Fall オレオレJVM言語を作ってみるJJUG CCC 2017 Fall オレオレJVM言語を作ってみる
JJUG CCC 2017 Fall オレオレJVM言語を作ってみるKoichi Sakata
 
KANJAVA PARTY 2017 前説
KANJAVA PARTY 2017 前説KANJAVA PARTY 2017 前説
KANJAVA PARTY 2017 前説Koichi Sakata
 
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めた
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めたJJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めた
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めたKoichi Sakata
 
“Purikura” culture in Japan and our web application architecture
“Purikura” culturein Japan andour web application architecture“Purikura” culturein Japan andour web application architecture
“Purikura” culture in Japan and our web application architectureKoichi Sakata
 
デブサミ2017 Javaコミュニティ作ったら人生変わった
デブサミ2017 Javaコミュニティ作ったら人生変わったデブサミ2017 Javaコミュニティ作ったら人生変わった
デブサミ2017 Javaコミュニティ作ったら人生変わったKoichi Sakata
 
JJUG CCC 2016 fall バイトコードが君のトモダチになりたがっている
JJUG CCC 2016 fall バイトコードが君のトモダチになりたがっているJJUG CCC 2016 fall バイトコードが君のトモダチになりたがっている
JJUG CCC 2016 fall バイトコードが君のトモダチになりたがっているKoichi Sakata
 
日本からJavaOneに行こう!
日本からJavaOneに行こう!日本からJavaOneに行こう!
日本からJavaOneに行こう!Koichi Sakata
 

Más de Koichi Sakata (20)

Introduction to JIT Compiler in JVM
Introduction to JIT Compiler in JVMIntroduction to JIT Compiler in JVM
Introduction to JIT Compiler in JVM
 
Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)
Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)
Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)
 
Guide to GraalVM (JJUG CCC 2019 Fall)
Guide to GraalVM (JJUG CCC 2019 Fall)Guide to GraalVM (JJUG CCC 2019 Fall)
Guide to GraalVM (JJUG CCC 2019 Fall)
 
Introduction to GraalVM and Native Image
Introduction to GraalVM and Native ImageIntroduction to GraalVM and Native Image
Introduction to GraalVM and Native Image
 
Introduction to GraalVM
Introduction to GraalVMIntroduction to GraalVM
Introduction to GraalVM
 
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼうGraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
 
Bytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte BuddyBytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte Buddy
 
Great Ideas in GraalVM
Great Ideas in GraalVMGreat Ideas in GraalVM
Great Ideas in GraalVM
 
Graal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerGraal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT Compiler
 
Kanjava 201804 Java News
Kanjava 201804 Java NewsKanjava 201804 Java News
Kanjava 201804 Java News
 
KanJava 201804 Career 思い込みから逃れた先には、可能性がある
KanJava 201804 Career 思い込みから逃れた先には、可能性があるKanJava 201804 Career 思い込みから逃れた先には、可能性がある
KanJava 201804 Career 思い込みから逃れた先には、可能性がある
 
from Java EE to Jakarta EE
from Java EE to Jakarta EEfrom Java EE to Jakarta EE
from Java EE to Jakarta EE
 
Java release cadence has been changed and about Project Amber
Java release cadence has been changed and about Project AmberJava release cadence has been changed and about Project Amber
Java release cadence has been changed and about Project Amber
 
JJUG CCC 2017 Fall オレオレJVM言語を作ってみる
JJUG CCC 2017 Fall オレオレJVM言語を作ってみるJJUG CCC 2017 Fall オレオレJVM言語を作ってみる
JJUG CCC 2017 Fall オレオレJVM言語を作ってみる
 
KANJAVA PARTY 2017 前説
KANJAVA PARTY 2017 前説KANJAVA PARTY 2017 前説
KANJAVA PARTY 2017 前説
 
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めた
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めたJJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めた
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めた
 
“Purikura” culture in Japan and our web application architecture
“Purikura” culturein Japan andour web application architecture“Purikura” culturein Japan andour web application architecture
“Purikura” culture in Japan and our web application architecture
 
デブサミ2017 Javaコミュニティ作ったら人生変わった
デブサミ2017 Javaコミュニティ作ったら人生変わったデブサミ2017 Javaコミュニティ作ったら人生変わった
デブサミ2017 Javaコミュニティ作ったら人生変わった
 
JJUG CCC 2016 fall バイトコードが君のトモダチになりたがっている
JJUG CCC 2016 fall バイトコードが君のトモダチになりたがっているJJUG CCC 2016 fall バイトコードが君のトモダチになりたがっている
JJUG CCC 2016 fall バイトコードが君のトモダチになりたがっている
 
日本からJavaOneに行こう!
日本からJavaOneに行こう!日本からJavaOneに行こう!
日本からJavaOneに行こう!
 

Último

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 

How Scala code is expressed in the JVM

  • 1. Koichi  Sakata  (阪田  浩一)   @jyukutyo How  Scala  code  is   expressed  in  the  JVM   -­‐  ScalaMatsuri  2016  -­‐
  • 2. 関ジャバです! 2 @jyukutyo produced three Java framework books one was translated into Korean JUG Leader (KansaiJUG) blog:Fight the Future http://jyukutyo.hatenablog.com/ FURYU CORPORATION age: 36 Koichi Sakata (阪田 浩一) フリューの阪田です 関ジャバの会長です
  • 4. this  session  is   for  beginners   about  JVM   byte  codes このセッションは JVMのバイトコード初心者向けです
  • 5. Do  you  know   what  happens   when  we  compile   Scala  code? Scalaコードをコンパイルする時 何が起こるかご存じでしょうか?
  • 6. Java Scala JRuby Groovy C o m p i l e r Class   file cafe babe 0000 0032 0017 0100 JVM Class   file Class   file Class   file Class   file Class   file § Runs § Interprets § Translates bytecode into Native Machine Code
  • 7. Have  you  ever   opened     a  class  file? クラスファイルを開いたことはありますか
  • 8. First,     let's  try  opening     a  class  file     from  a  simple     Java  code Javaのクラスファイルを開いてみましょう
  • 9. Hello  World  (Java)   public  class  HelloWorld  {      public  static  void  main(String[]  args)  {          System.out.println("Hello,  world!");      }   }   § Compiled  into...   § HelloWorld.class  
  • 10. open   HelloWorld.class   file     with  binary  editor   e.g.)  hexl-­‐find-­‐file   (Emacs) クラスファイルをバイナリエディタで開く
  • 11. cafe  babe  0000  0032  0017  0100  0a48  656c   6c6f  576f  726c  6407  0001  0100  106a  6176   612f  6c61  6e67  2f4f  626a  6563  7407  0003   0100  1048  656c  6c6f  576f  726c  642e  7363   616c  6101  001e  4c73  6361  6c61  2f72  6566   6c65  6374  2f53  6361  6c61  5369  676e  6174   7572  653b  0100  0562  7974  6573  0100  ef06   0115  3a51  2101  0209  0215  0921  0253  336d   593e  3c76  4e1d  3765  1505  1911  6102  1f66   5b42  2418  5050  0201  2109  3171  2144  0103   0d15  4121  0123  010a  0529  4155  0d1c  3770   2f3e  1448  0e5a  0a03  0f29  0122  6103  080e   0331  5111  2144  0106  670e  0c47  2e59  0503   1f31  1161  2111  387a  2516  3407  2242  0908
  • 12. you  will   close  the  editor   right  away すぐにエディタを閉じるでしょう
  • 13. class  file   has  a  format クラスファイルには フォーマットがあります
  • 14. ClassFile  {      u4                          magic;      u2                          minor_version;      u2                          major_version;      u2                          constant_pool_count;      cp_info    constant_pool[constant_pool_count-­‐1];      u2                          access_flags;      u2                          this_class;      u2                          super_class;      u2                          interfaces_count;      u2            interfaces[interfaces_count];   ...   -­‐-­‐  u1  represents  one-­‐byte  quantity,        Hexadecimal  2  digit.
  • 15. ...      u2                          fields_count;      field_info          fields[fields_count];      u2                          methods_count;      method_info      methods[methods_count];      u2                          attributes_count;      attribute_info  attributes[attributes_count];   }   -­‐-­‐  u1  represents  one-­‐byte  quantity,        Hexadecimal  2  digit. u1が1バイト 16進数では2桁になります
  • 17. cafe  babe  0000  0032  0017  0100  0a48  656c   6c6f  576f  726c  6407  0001  0100  106a  6176   612f  6c61  6e67  2f4f  626a  6563  7407  0003   0100  1048  656c  6c6f  576f  726c  642e  7363   616c  6101  001e  4c73  6361  6c61  2f72  6566   6c65  6374  2f53  6361  6c61  5369  676e  6174   7572  653b  0100  0562  7974  6573  0100  ef06   0115  3a51  2101  0209  0215  0921  0253  336d   593e  3c76  4e1d  3765  1505  1911  6102  1f66   5b42  2418  5050  0201  2109  3171  2144  0103   0d15  4121  0123  010a  0529  4155  0d1c  3770   2f3e  1448  0e5a  0a03  0f29  0122  6103  080e   0331  5111  2144  0106  670e  0c47  2e59  0503   1f31  1161  2111  387a  2516  3407  2242  0908
  • 18. cafe  babe  0000  0032   ClassFile  {      u4                          magic;      u2                          minor_version;      u2                          major_version;  
  • 19. "magic"  is  always   "0xCAFEBABE"
  • 20. major:  0x0032  =  50   minor:  0x0000  =  0   50.0  means  Java  SE  6   51.0  is  7,  52.0  is  8...
  • 21. Yes!
  • 22. but,  this  is   purgatory でもこれは苦行です
  • 23. Never  mind!   We  have   a  handy  tool! 便利なツールがあります!
  • 24. javap  command   The  Java  Class  File  Disassembler   § included  in  JDK   § `javap  -­‐v  [FQCN]`   § Scala  REPL   § scala>  :javap  [FQCN]   § equivalent  to  `javap  -­‐v`   http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javap.html javap - Java クラスファイル逆アセンブラ
  • 25. so,  a  class  file     can  be   disassembled   to  Java  Classes クラスファイルはJavaのクラスに 逆アセンブルできるのです
  • 27. public  class  HelloWorld      minor  version:  0      major  version:  52   Constant  pool:        #1  =  Methodref                    #6.#15                 //  java/lang/Object."<init>":()V        #2  =  Fieldref                      #16.#17               //  java/lang/System.out:Ljava/io/ PrintStream;        #3  =  String                          #18                       //  Hello,  world!        #4  =  Methodref                    #19.#20               //  java/io/PrintStream.println:(Ljava/ lang/String;)V
  • 28. Constant  pool  is   a  table  of   symbolic   information コンスタントプールは シンボル情報のテーブル
  • 29. public  static  void   main(java.lang.String[]);    Code:                0:  getstatic          #2                            3:  ldc                      #3                            5:  invokevirtual  #4                            8:  return  
  • 30. JVM  instructions   aaload aastore aconst_null aload anewarray areturn arraylength astore athrow baload bastore bipush caload castore checkcast d2f d2i d2l dadd daload dastore dcmp<op> dconst_<d> ddiv dload dmul dneg ...
  • 32. Since  first   release  of  Java,   added  instruction   is  ... Javaが最初にリリースされてから 追加されたJVM命令は...
  • 34. Initial  design     of  JVM     is  excellent! JVMは初期設計から優秀だった!
  • 35. instructions  of  method  call   invokevirtual invoke  instance  method;   dispatched  based  on  class invokeinterface invoke  interface  method invokestatic invoke  static  method invokespecial invoke  method;   superclass,  private,   constructor... invokedynamic invoke  dynamic  method
  • 36. public  static  void   main(java.lang.String[]);    Code:                0:  getstatic          #2                            3:  ldc                      #3                            5:  invokevirtual  #4                            8:  return   -­‐-­‐  #0  =  index  of  Constant  pool  
  • 37. public  class  HelloWorld   Constant  pool:        #1  =  Methodref                    #6.#15                 //  java/lang/Object."<init>":()V        #2  =  Fieldref                      #16.#17               //  java/lang/System.out:Ljava/io/ PrintStream;        #3  =  String                          #18                       //  Hello,  world!        #4  =  Methodref                    #19.#20               //  java/io/PrintStream.println:(Ljava/ lang/String;)V   ...
  • 40. Hello  World  (Scala)   object  HelloWorld  {      def  main(args:  Array[String])  {          println("Hello,  world!")      }   }   § Compiled  into...   § HelloWorld.class   § HelloWorld$.class  
  • 41. public  final  class  HelloWorld   Constant  pool:      #15  =  NameAndType                #13:#14               //  MODULE$:LHelloWorld$;      #16  =  Fieldref                      #12.#15               //  HelloWorld$.MODULE$:LHelloWorld$;      #17  =  NameAndType                #9:#10                 //  main:([Ljava/lang/String;)V      #18  =  Methodref                    #12.#17               //  HelloWorld$.main:   ([Ljava/lang/String;)V   ...
  • 42. public  static  void     main(java.lang.String[]);      0:  getstatic          #16                                 //  Field  HelloWorld$.   MODULE$:LHelloWorld$;      3:  aload_0      4:  invokevirtual  #18   //  Method  HelloWorld$.main:   ([Ljava/lang/String;)V      7:  return   -­‐-­‐  4:  in  Java   HelloWorld$.MODULE$.main(arg);
  • 43. public  final  class  HelloWorld$   -­‐-­‐  omit  Constant  pool      public  static  {};                    0:  new                      #2             //  class  HelloWorld$                    3:  invokespecial  #12           //  Method  "<init>":()V                    6:  return   -­‐-­‐  <init>  means  constructor  
  • 44.    public  void  main(java.lang.String[]);                    0:  getstatic          #19                         //  Field  scala/Predef$.MODULE$:   Lscala/Predef$;                    3:  ldc                      #21                         //  String  Hello,  world!                    5:  invokevirtual  #25                         //  Method  scala/Predef$.println:   (Ljava/lang/Object;)V                    8:  return  
  • 46. The  following  samples   are  quoted     from  tutorials     in  Scala  official  site   http://docs.scala-­‐lang.org/tutorials/ これ以降で使用するサンプルは Scalaの公式サイトのチュートリアルです
  • 48. trait  Similarity  {      def  isSimilar(x:  Any):  Boolean      def  isNotSimilar(x:  Any):  Boolean  =    !isSimilar(x)   }   class  Point(xc:  Int,  yc:  Int)     extends  Similarity  {      var  x:  Int  =  xc      var  y:  Int  =  yc      def  isSimilar(obj:  Any)  =          obj.isInstanceOf[Point]  &&          obj.asInstanceOf[Point].x  ==  x   }  
  • 49. § Compiled  into...   § Similarity.class   § Similarity$class.class   § Point.class  
  • 51. public  interface  Similarity      public  abstract  boolean     isSimilar(java.lang.Object);            public  abstract  boolean     isNotSimilar(java.lang.Object);  
  • 52. public  abstract  class  Similarity$class      public  static  boolean     isNotSimilar(Similarity,j.l.Object);                    0:  aload_0                    1:  aload_1                    2:  invokeinterface  #13,    2             //  InterfaceMethod   Similarity.isSimilar:   (Ljava/lang/Object;)Z                    7:  ifeq                    14                  10:  iconst_0                  11:  goto                    15                  14:  iconst_1                  15:  ireturn
  • 53. a  trait  is     divided  into     an  interface  and   an  abstract  class トレイトはインタフェースと 抽象クラスに分かれます
  • 55. abstract  class  Term   case  class  Var(name:  String)    extends  Term   case  class  Fun(arg:  String,  body:  Term)     extends  Term   case  class  App(f:  Term,  v:  Term)     extends  Term  
  • 56. § Compiled  into...   § Term.class   § App.class   § App$.class   § Fun.class   § Fun$.class   § Var.class   § Var$.class  
  • 58. public  class  App  extends  Term    implements  s.Product,s.Serializable      public  static     s.Option<scala.Tuple2<Term,  Term>>   unapply(App);      public  static  App  apply(Term,  Term);      public  ...  tupled();      public  ...  curried();      public  Term  f();      public  Term  v();      public  App  copy(Term,  Term);      public  j.l.String  productPrefix();      public  boolean  equals(j.l.Object);   ...
  • 59. public  final  class  App$  extends     s.r.AbstractFunction2<Term,  Term,  App>   implements  scala.Serializable      public  App  apply(Term,  Term);                    0:  new                      #23                         //  class  App                    3:  dup                    4:  aload_1                    5:  aload_2                    6:  invokespecial  #26                         //  Method  App."<init>":(LTerm;LTerm;)V                    9:  areturn  
  • 60. Fun  and  Var  looks   the  same  as  App FunとVarも同様の内容です
  • 61. Scala  compiler   generates     many  functions   from  few  snippets   of  code Scalaコンパイラは少ないコードから 多くの機能を生成しています
  • 63. object  MatchTest2  extends  App  {      def  matchTest(x:  Any):  Any  =  x  match      {          case  1  =>  "one"          case  "two"  =>  2          case  y:  Int  =>  "scala.Int"      }      println(matchTest("two"))   }
  • 64. § Compiled  into...   § MatchTest2.class   § MatchTest2$.class   § MatchTest2$delayedInit$body.class  
  • 66. public  final  class  MatchTest2$     implements  scala.App                    7:  invokestatic    #67                         //  Method  BoxesRunTime.equals:..                  10:  ifeq                    19                  13:  ldc                      #69                         //  String  one                  15:  astore_3                  16:  goto                    46                  19:  ldc                      #71                         //  String  two                  21:  aload_2                  22:  invokevirtual  #74                         //  Method  java/lang/Object.equals:  
  • 67.                                  19:  ldc                      #71                         //  String  two                  21:  aload_2                  22:  invokevirtual  #74                         //  Method  java/lang/Object.equals:   (Ljava/lang/Object;)Z                  25:  ifeq                    36                  28:  iconst_2                  32:  astore_3                  33:  goto                    46
  • 68.                36:  aload_2                  37:  instanceof        #76                         //  class  java/lang/Integer                  40:  ifeq                    48                  43:  ldc                      #78                         //  String  scala.Int                  45:  astore_3                  46:  aload_3                  47:  areturn   ...
  • 69. Compiled  into   if  statements if文へコンパイルしています
  • 70. in  case  of   another  Pattern   Matching... 違うパターンマッチの場合
  • 71. object  MatchTest1  {      def  matchTest(x:  Int):  String  =  x   match  {          case  1  =>  "one"          case  2  =>  "two"          case  _  =>  "many"      }      def  main(args:  Array[String])  {          println(matchTest(3))      }   }
  • 73.                  3:  tableswitch      {  //  1  to  2                                                1:  34                                                2:  29                                    default:  24                          }                  24:  ldc                      #16                         //  String  many                  26:  goto                    36                  29:  ldc                      #18                         //  String  two                  31:  goto                    36                  34:  ldc                      #20                         //  String  one                  36:  areturn
  • 74. Compiled  into   a  switch  statement switch文にコンパイルしています
  • 76. object  CurryTest  {      def  filter(xs:  List[Int],     p:  Int  =>  Boolean):  List[Int]  =          if  (xs.isEmpty)  xs          else  if  (p(xs.head))     xs.head  ::  filter(xs.tail,  p)          else  filter(xs.tail,  p)      def  modN(n:  Int)(x:  Int)  =     ((x  %  n)  ==  0)  
  • 77.    def  main(args:  Array[String])  {          val  nums  =  List(1,  2,  3,  4,     5,  6,  7,  8)          println(filter(nums,  modN(2)))          println(filter(nums,  modN(3)))      }   }  
  • 78. § Compiled  into...   § CurryTest.class   § CurryTest$.class   § CurryTest$$anonfun$main$1.class   § CurryTest$$anonfun$main$2.class  
  • 80. public  final  class     CurryTest$$anonfun$main$1  extends   scala.runtime.AbstractFunction1$mcZI$sp   implements  scala.Serializable      public  boolean  apply$mcZI$sp(int);                    3:  iconst_2                    4:  iload_1                    5:  invokevirtual  #33                         //  Method  CurryTest$.modN:(II)Z                    8:  ireturn  
  • 81. public  final  class     CurryTest$$anonfun$main$2  extends   scala.runtime.AbstractFunction1$mcZI$sp   implements  scala.Serializable      public  boolean  apply$mcZI$sp(int);                    3:  iconst_3                    4:  iload_1                    5:  invokevirtual  #33                         //  Method  CurryTest$.modN:(II)Z                    8:  ireturn  
  • 82.    def  main(args:  Array[String])  {          val  nums  =  List(1,  2,  3,  4,     5,  6,  7,  8)          println(filter(nums,  modN(2)))          println(filter(nums,  modN(3)))      }   }  
  • 83. each  partial   application   creates     a  new  class 部分適用の箇所ごとに クラスを生成しています
  • 84. public  final  class  CurryTest$   ...      public  void  main(java.lang.String[]);                  63:  invokespecial  #82                         //  Method  CurryTest$$anonfun$main$1.   "<init>":()V                  66:  invokevirtual  #41                         //  Method  filter:(Lscala/collection/   immutable/List;Lscala/Function1;)   Lscala/collection/immutable/List;                  69:  invokevirtual  #86                         //  Method  scala/Predef$.println:   (Ljava/lang/Object;)V
  • 85. public  final  class     CurryTest$$anonfun$main$1  extends   scala.runtime.AbstractFunction1$mcZI$sp   implements  scala.Serializable  
  • 87.                81:  invokespecial  #89                         //  Method  CurryTest$$anonfun$main$2.   "<init>":()V                                    84:  invokevirtual  #41                         //  Method  filter:(Lscala/collection/   immutable/List;Lscala/Function1;)   Lscala/collection/immutable/List;                  87:  invokevirtual  #86                         //  Method  scala/Predef$.println:   (Ljava/lang/Object;)V  
  • 88. § Summary   § JVM  is  excellent!   § class  file  has  a  format   § javap  is  useful  to  understand       Scala  at  the  bytecode  level     Try  typing  "javap"   after  you  compile   Scala  code