Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Inside Kotlin

Inside Kotlin

rejasupotaro

March 23, 2016
Tweet

More Decks by rejasupotaro

Other Decks in Technology

Transcript

  1. Inside Kotlin

    View full-size slide

  2. What’s “runs on JVM”?

    View full-size slide

  3. JVM executes .class
    00000000 ca fe ba be 00 00 00 34 00 1d 0a 00 06 00 0f 09 |.......4........|
    00000010 00 10 00 11 08 00 12 0a 00 13 00 14 07 00 15 07 |................|
    00000020 00 16 01 00 06 3c 69 6e 69 74 3e 01 00 03 28 29 |........()|
    00000030 56 01 00 04 43 6f 64 65 01 00 0f 4c 69 6e 65 4e |V...Code...LineN|
    00000040 75 6d 62 65 72 54 61 62 6c 65 01 00 04 6d 61 69 |umberTable...mai|
    00000050 6e 01 00 16 28 5b 4c 6a 61 76 61 2f 6c 61 6e 67 |n...([Ljava/lang|
    00000060 2f 53 74 72 69 6e 67 3b 29 56 01 00 0a 53 6f 75 |/String;)V...Sou|
    00000070 72 63 65 46 69 6c 65 01 00 0a 48 65 6c 6c 6f 2e |rceFile...Hello.|
    00000080 6a 61 76 61 0c 00 07 00 08 07 00 17 0c 00 18 00 |java............|
    00000090 19 01 00 0b 48 65 6c 6c 6f 20 57 6f 72 6c 64 07 |....Hello World.|
    000000a0 00 1a 0c 00 1b 00 1c 01 00 05 48 65 6c 6c 6f 01 |..........Hello.|
    000000b0 00 10 6a 61 76 61 2f 6c 61 6e 67 2f 4f 62 6a 65 |..java/lang/Obje|
    000000c0 63 74 01 00 10 6a 61 76 61 2f 6c 61 6e 67 2f 53 |ct...java/lang/S|
    000000d0 79 73 74 65 6d 01 00 03 6f 75 74 01 00 15 4c 6a |ystem...out...Lj|
    000000e0 61 76 61 2f 69 6f 2f 50 72 69 6e 74 53 74 72 65 |ava/io/PrintStre|
    000000f0 61 6d 3b 01 00 13 6a 61 76 61 2f 69 6f 2f 50 72 |am;...java/io/Pr|
    00000100 69 6e 74 53 74 72 65 61 6d 01 00 07 70 72 69 6e |intStream...prin|
    00000110 74 6c 6e 01 00 15 28 4c 6a 61 76 61 2f 6c 61 6e |tln...(Ljava/lan|
    00000120 67 2f 53 74 72 69 6e 67 3b 29 56 00 21 00 05 00 |g/String;)V.!...|
    00000130 06 00 00 00 00 00 02 00 01 00 07 00 08 00 01 00 |................|
    00000140 09 00 00 00 1d 00 01 00 01 00 00 00 05 2a b7 00 |.............*..|
    00000150 01 b1 00 00 00 01 00 0a 00 00 00 06 00 01 00 00 |................|
    00000160 00 01 00 09 00 0b 00 0c 00 01 00 09 00 00 00 25 |...............%|
    00000170 00 02 00 01 00 00 00 09 b2 00 02 12 03 b6 00 04 |................|
    00000180 b1 00 00 00 01 00 0a 00 00 00 0a 00 02 00 00 00 |................|
    00000190 03 00 08 00 04 00 01 00 0d 00 00 00 02 00 0e |...............|
    0000019f
    => “Hello World”

    View full-size slide

  4. “runs on JVM” means
    generating JVM instructions

    View full-size slide

  5. .class public Main
    .super java/lang/Object
    .method public static main([Ljava/lang/String;)V
    .limit stack 2
    getstatic java/lang/System/out Ljava/io/PrintStream;
    ldc "Hello World"
    invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
    return
    .end method
    JVM assembler
    => “Hello World”

    View full-size slide

  6. public class Main {
    public static void main(String[] args) {
    System.out.println("Hello World");
    }
    }
    Java
    => “Hello World”

    View full-size slide

  7. Kotlin
    => “Hello World”
    fun main(args: Array) {
    println("Hello World")
    }

    View full-size slide

  8. 0000000 ca fe ba be 00 03 00 2d 00 18 07 00 0f 0c 00 15
    0000010 00 17 01 00 16 28 5b 4c 6a 61 76 61 2f 6c 61 6e
    0000020 67 2f 53 74 72 69 6e 67 3b 29 56 01 00 10 6a 61
    0000030 76 61 2f 6c 61 6e 67 2f 4f 62 6a 65 63 74 07 00
    0000040 04 07 00 0e 01 00 07 48 65 6c 6c 6f 2e 6a 07 00
    0000050 11 01 00 04 43 6f 64 65 01 00 04 6d 61 69 6e 09
    0000060 00 08 00 02 01 00 0a 53 6f 75 72 63 65 46 69 6c
    0000070 65 0c 00 10 00 16 01 00 13 6a 61 76 61 2f 69 6f
    0000080 2f 50 72 69 6e 74 53 74 72 65 61 6d 01 00 04 4d
    0000090 61 69 6e 01 00 07 70 72 69 6e 74 6c 6e 01 00 10
    00000a0 6a 61 76 61 2f 6c 61 6e 67 2f 53 79 73 74 65 6d
    00000b0 01 00 0b 48 65 6c 6c 6f 20 57 6f 72 6c 64 0a 00
    00000c0 06 00 0d 08 00 12 01 00 03 6f 75 74 01 00 15 28
    00000d0 4c 6a 61 76 61 2f 6c 61 6e 67 2f 53 74 72 69 6e
    00000e0 67 3b 29 56 01 00 15 4c 6a 61 76 61 2f 69 6f 2f
    00000f0 50 72 69 6e 74 53 74 72 65 61 6d 3b 00 21 00 01
    0000100 00 05 00 00 00 00 00 01 00 09 00 0a 00 03 00 01
    0000110 00 09 00 00 00 15 00 02 00 01 00 00 00 09 b2 00
    0000120 0b 12 14 b6 00 13 b1 00 00 00 00 00 01 00 0c 00
    0000130 00 00 02 00 07
    0000135
    .class public Main
    .super java/lang/Object
    .method public static main([Ljava/lang/String;)V
    .limit stack 2
    getstatic java/lang/System/out Ljava/io/PrintStream;
    ldc "Hello World"
    invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
    return
    .end method
    public class Main {
    public static void main(String[] args) {
    System.out.println("Hello World");
    }
    }
    fun main(args: Array) {
    println("Hello, World")
    }
    Abstract
    Concrete
    The difference is abstraction level

    View full-size slide

  9. .class
    Class Loader
    JVM
    javac kotlinc
    fun main(args: Array) {
    println("Hello, World")
    }
    public class Main {
    public static void main(String[] args) {
    System.out.println("Hello World");
    }
    }
    Execution Engine
    JIT Compiler
    Garbage Collector

    View full-size slide

  10. JetBrains/kotlin

    View full-size slide

  11. Issue tracker

    View full-size slide

  12. Execute now
    $ git clone [email protected]:JetBrains/kotlin.git
    $ cd kotlin
    $ brew install ant
    $ ant -f update_dependencies.xml
    if you want to play Kotlin

    View full-size slide

  13. * libraries/stdlib
    * libraries/tools/kotlin-annotation-processing
    * libraries/tools/kotlin-gradle-plugin
    * compiler
    Directories that you may be
    going to see

    View full-size slide

  14. What’s “stdlib"?

    View full-size slide

  15. // Hello.kt
    fun main(args: Array) {
    println("Hello World")
    }
    $ kotlinc Hello.kt # javac Hello.java
    $ kotlin HelloKt # java Hello
    Hello World
    $ java HelloKt
    Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
    at HelloKt.main(Hello.kt)
    Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more
    Try running .class

    View full-size slide

  16. $ javap -c HelloKt.class
    Compiled from "Hello.kt"
    public final class HelloKt {
    public static final void main(java.lang.String[]);
    Code:
    0: aload_0
    1: ldc #9 // String args
    3: invokestatic #15 // Method kotlin/jvm/internal/Intrinsics.checkParameterIsNotNull:(Ljava/lang/Object;Ljava/lang/String;)V
    6: ldc #17 // String Hello World
    8: invokestatic #23 // Method kotlin/io/ConsoleKt.println:(Ljava/lang/Object;)V
    11: return
    }
    $ javap -c Hello.class
    Compiled from "Hello.java"
    public class Hello {
    public Hello();
    Code:
    0: aload_0
    1: invokespecial #1 // Method java/lang/Object."":()V
    4: return
    public static void main(java.lang.String[]);
    Code:
    0: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
    3: ldc #3 // String Hello World
    5: invokevirtual #4 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
    8: return
    }
    generated by kotlinc
    generated by javac

    View full-size slide

  17. $ kotlinc Hello.kt
    $ kotlin HelloKt
    Hello World
    $ kotlinc Hello.kt -include-runtime -d Hello.jar
    $ java -jar Hello.jar
    Hello World
    -include-runtime

    View full-size slide

  18. $ tree -L 2
    .
    !"" META-INF
    # !"" MANIFEST.MF
    # %"" main.kotlin_module
    !"" HelloKt.class
    !"" kotlin
    # !"" ArrayIntrinsicsKt.class
    # !"" ArraysKt.class
    # !"" BooleanIterator.class
    # !"" ByteIterator.class
    # !"" ByteProgression$Companion.class
    # !"" ByteProgression.class
    # !"" ByteProgressionIterator.class
    # !"" ByteRange$Companion.class
    # !"" ByteRange.class
    # !"" CharCategory$Companion$categoryMap$1.class
    # !"" CharCategory$Companion$categoryMap$2.class
    # !"" CharCategory$Companion.class
    # !"" CharCategory.class
    # !"" CharDirectionality$Companion$directionalityMap$1.class
    # !"" CharDirectionality$Companion$directionalityMap$2.class
    # !"" CharDirectionality$Companion.class
    # !"" CharDirectionality.class
    # !"" CharIterator.class
    # !"" CharProgression$Companion.class
    # !"" CharProgression.class
    # !"" CharProgressionIterator.class
    # !"" CharRange$Companion.class
    # !"" CharRange.class
    # !"" CharsKt.class
    # !"" Charsets.class
    # !"" ClosedRange$DefaultImpls.class
    # !"" ClosedRange.class
    # !"" CollectionsKt.class
    # !"" ComparisonsKt$comparator$1.class
    # !"" ComparisonsKt$compareBy$1.class
    # !"" ComparisonsKt$compareBy$2.class
    # !"" ComparisonsKt$compareBy$3.class
    # !"" ComparisonsKt$compareByDescending$1.class
    # !"" ComparisonsKt$compareByDescending$2.class
    # !"" ComparisonsKt$nullsFirst$1.class
    # !"" ComparisonsKt$nullsLast$1.class
    # !"" ComparisonsKt$then$1.class
    # !"" ComparisonsKt$thenBy$1.class
    # !"" ComparisonsKt$thenBy$2.class
    # !"" ComparisonsKt$thenByDescending$1.class
    # !"" ComparisonsKt$thenByDescending$2.class
    # !"" ComparisonsKt$thenComparator$1.class
    # !"" ComparisonsKt$thenDescending$1.class
    # !"" ComparisonsKt.clas
    # !"" Deprecated.class
    # !"" DeprecatedBuiltinsKt.class
    # !"" DeprecationLevel.class
    # !"" DoubleIterator.class
    # !"" EnumsKt.class
    # !"" EnumsKt__EnumsKt.class
    # !"" ExceptionsKt.class
    # !"" ExceptionsKt__StandardJVMKt.class
    # !"" Extension.class
    # !"" ExtensionsKt.class
    # !"" ExtensionsKt__JLangJVMKt.class
    # !"" FloatIterator.class
    # !"" FloatingPointConstants.class
    # !"" Function.class
    # !"" FunctionsKt$toGenerator$1.class
    # !"" FunctionsKt.class
    # !"" HiddenDeclaration.class
    # !"" IndexedValue.class
    # !"" IndexingIterable.class
    # !"" IndexingIterator.class
    # !"" InitializedLazyImpl.class
    # !"" IntIterator.class
    # !"" IntProgression$Companion.class
    # !"" IntProgression.class
    # !"" IntProgressionIterator.class
    # !"" IntRange$Companion.class
    # !"" IntRange.class
    # !"" IntegerConstants.class
    # !"" KotlinNullPointerException.class
    # !"" Lazy.class
    # !"" LazyKt$WhenMappings.class
    # !"" LazyKt.class
    # !"" LazyThreadSafetyMode.class
    # !"" LongIterator.class
    # !"" LongProgression$Companion.class
    # !"" LongProgression.class
    # !"" LongProgressionIterator.class
    # !"" LongRange$Companion.class
    # !"" LongRange.class
    # !"" MapsKt.class
    # !"" MathKt.class
    # !"" MathKt__BigNumbersKt.class
    # !"" MathKt__NumbersKt.class
    # !"" NaturalOrderComparator.class
    # !"" NoWhenBranchMatchedException.class
    # !"" NotImplementedError.class
    # !"" Pair.class
    # !"" PreconditionsKt.class
    # !"" PreconditionsKt__AssertionsJVMKt.class
    # !"" PreconditionsKt__PreconditionsKt.class
    # !"" Progression.class
    # !"" Range$DefaultImpls.class
    # !"" Range.class
    # !"" RangesKt.class
    # !"" ReplaceWith.class
    # !"" ReverseOrderComparator.class
    # !"" ReversedComparator.class
    # !"" SafePublicationLazyImpl$Companion.class
    # !"" SafePublicationLazyImpl.class
    # !"" Sequence.class
    # !"" SequencesKt.class
    # !"" SetsKt.class
    # !"" ShortIterator.class
    # !"" ShortProgression$Companion.class
    # !"" ShortProgression.class
    # !"" ShortProgressionIterator.class
    # !"" ShortRange$Companion.class
    # !"" ShortRange.class
    # !"" StandardKt.class
    # !"" StandardKt__IntegersKt.class
    # !"" StandardKt__StandardKt.class
    # !"" StandardKt__SynchronizedKt.class
    # !"" StringsKt.class
    # !"" Suppress.class
    # !"" SynchronizedLazyImpl.class
    # !"" Triple.class
    # !"" TuplesKt.class
    # !"" TypeCastException.class
    # !"" Typography.class
    # !"" UNINITIALIZED_VALUE.class
    # !"" UninitializedPropertyAccessException.class
    # !"" Unit.class
    # !"" UnsafeLazyImpl.class
    # !"" UnsafeVariance.class
    # !"" _Assertions.class
    # !"" annotation
    # !"" collections
    # !"" concurrent
    # !"" internal
    # !"" io
    # !"" jvm
    # !"" math
    # !"" properties
    # !"" ranges
    # !"" reflect
    # !"" sequences
    # !"" support
    # !"" system
    # !"" test
    # !"" text
    # !"" throws.class
    # %"" util

    View full-size slide

  19. .class + stdlib
    JVM
    kotlinc
    fun main(args: Array) {
    println("Hello, World")
    }
    Class Loader
    Execution Engine
    JIT Compiler
    Garbage Collector
    From the viewpoint of architecture

    View full-size slide

  20. Kotlin
    $ tree libraries/stdlib/src -d
    kotlin/libraries/stdlib/src/
    !"" generated
    %"" kotlin
    !"" collections
    !"" comparisons
    !"" concurrent
    !"" internal
    !"" io
    # %"" files
    !"" jvm
    # %"" internal
    # %"" unsafe
    !"" properties
    !"" ranges
    !"" system
    !"" text
    # %"" regex
    %"" util
    17 directories, 70 files
    Scala
    $ tree scala/src/library -d
    scala/src/library/
    %"" scala
    !"" annotation
    # !"" meta
    # %"" unchecked
    !"" beans
    !"" collection
    # !"" concurrent
    # !"" convert
    # !"" generic
    # !"" immutable
    # !"" mutable
    # !"" parallel
    # # !"" immutable
    # # %"" mutable
    # %"" script
    !"" compat
    !"" concurrent
    # !"" duration
    # !"" forkjoin
    # %"" impl
    !"" io
    !"" math
    !"" ref
    !"" reflect
    # %"" macros
    # %"" internal
    !"" runtime
    # %"" java8
    !"" sys
    # %"" process
    !"" text
    %"" util
    !"" control
    !"" hashing
    %"" matching
    35 directories, 751 files

    View full-size slide

  21. Kotlin: 70 files
    Scala: 751 files
    Kotlin provides convenient syntax and extension
    methods (== better Java)
    Scala has a lot of classes for full support of
    functional programming (== realizing different
    paradigm)

    View full-size slide

  22. “But we have proguard, right?”
    “Ah, yeah…”

    View full-size slide

  23. Modifying stdlib is easy
    // libraries/stdlib/src/kotlin/text/Strings.kt
    public inline fun String.hello(): String = "Hello World"
    // Hello.kt
    “”.hello()
    $ ant runtime
    $ dist/kotlinc/bin/kotlinc Hello.kt && dist/kotlinc/bin/kotlin HelloKt
    `ant runtime` is finished around a minute!

    View full-size slide

  24. What’s “kotlinc"?

    View full-size slide

  25. Text Tokens AST JVM
    bytecode
    Machine
    code
    Lexer Parser Code generator
    Frontend Backend
    Compiler

    View full-size slide

  26. .kt
    Kt
    Tokens
    AST
    Node
    .class Machine
    code
    Compiler
    JFlex PsiParser ASM
    compiler/frontend compiler/backend

    View full-size slide

  27. Lexical analysis
    Source
    program
    Lexical analyzer Parser
    Read characters
    Push back extra characters
    Token
    Ask for next token

    View full-size slide

  28. Lexical analysis with JFlex
    * JFlex - fast lexical analyzer generator
    * Input: scanner specification file
    * Output: a lexical analyzer
    _JetLexer.java
    JFlex
    Kotlin.flex
    Lexical specification
    Read .flex file Generate lexer

    View full-size slide

  29. switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
    case 22:
    { return KtTokens.LBRACKET ;
    }
    case 106: break;
    case 78:
    { return KtTokens.FUN_KEYWORD ;
    }
    case 107: break;
    case 48:
    { return KtTokens.IN_KEYWORD ;
    }
    case 108: break;
    case 58:
    { return KtTokens.GTEQ ;
    }
    case 109: break;
    case 87:
    { return KtTokens.TRUE_KEYWORD ;
    }
    ...
    "return" { return KtTokens.RETURN_KEYWORD ;}
    "while" { return KtTokens.WHILE_KEYWORD ;}
    "break" { return KtTokens.BREAK_KEYWORD ;}
    "class" { return KtTokens.CLASS_KEYWORD ;}
    "throw" { return KtTokens.THROW_KEYWORD ;}
    ...
    "++" { return KtTokens.PLUSPLUS ; }
    "--" { return KtTokens.MINUSMINUS; }
    "<=" { return KtTokens.LTEQ ; }
    ">=" { return KtTokens.GTEQ ; }
    "==" { return KtTokens.EQEQ ; }
    "!=" { return KtTokens.EXCLEQ ; }
    ...
    HEX_DIGIT=[0-9A-Fa-f]
    ESCAPE_SEQUENCE=\\(u{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT}|[^\n])
    CHARACTER_LITERAL="'"([^\\\'\n]|{ESCAPE_SEQUENCE})*("'"|\\)?
    {CHARACTER_LITERAL} { return KtTokens.CHARACTER_LITERAL; }
    _JetLexer.java
    JFlex
    Kotlin.flex
    Lexical specification

    View full-size slide

  30. Parser
    Source
    program
    Lexical analyzer Parser
    Read characters
    Push back extra characters
    Token
    Ask for next token

    View full-size slide

  31. ::= "+"
    |
    ::= "*"
    |
    ::= "(" ")"
    |
    ::= integer
    Inside parser: formal grammar and automata
    e.g. yacc generates push down automata from context-free grammar

    View full-size slide

  32. IntelliJ Platform SDK
    http:/
    /www.jetbrains.org/intellij/sdk/docs/reference_guide/custom_language_support/implementing_parser_and_psi.html

    View full-size slide

  33. Optimizer
    * Remove redundant boxing
    * Remove redundant null check
    * Remove redundant GOTO
    * Remove dead code
    * …

    View full-size slide

  34. Code generator
    AST to
    0000000 ca fe ba be 00 03 00 2d 00 18 07 00 0f 0c 00 15
    0000010 00 17 01 00 16 28 5b 4c 6a 61 76 61 2f 6c 61 6e
    0000020 67 2f 53 74 72 69 6e 67 3b 29 56 01 00 10 6a 61
    0000030 76 61 2f 6c 61 6e 67 2f 4f 62 6a 65 63 74 07 00
    0000040 04 07 00 0e 01 00 07 48 65 6c 6c 6f 2e 6a 07 00
    0000050 11 01 00 04 43 6f 64 65 01 00 04 6d 61 69 6e 09
    0000060 00 08 00 02 01 00 0a 53 6f 75 72 63 65 46 69 6c
    0000070 65 0c 00 10 00 16 01 00 13 6a 61 76 61 2f 69 6f
    0000080 2f 50 72 69 6e 74 53 74 72 65 61 6d 01 00 04 4d
    0000090 61 69 6e 01 00 07 70 72 69 6e 74 6c 6e 01 00 10
    00000a0 6a 61 76 61 2f 6c 61 6e 67 2f 53 79 73 74 65 6d
    00000b0 01 00 0b 48 65 6c 6c 6f 20 57 6f 72 6c 64 0a 00
    00000c0 06 00 0d 08 00 12 01 00 03 6f 75 74 01 00 15 28
    00000d0 4c 6a 61 76 61 2f 6c 61 6e 67 2f 53 74 72 69 6e
    00000e0 67 3b 29 56 01 00 15 4c 6a 61 76 61 2f 69 6f 2f
    00000f0 50 72 69 6e 74 53 74 72 65 61 6d 3b 00 21 00 01
    0000100 00 05 00 00 00 00 00 01 00 09 00 0a 00 03 00 01
    0000110 00 09 00 00 00 15 00 02 00 01 00 00 00 09 b2 00
    0000120 0b 12 14 b6 00 13 b1 00 00 00 00 00 01 00 0c 00
    0000130 00 00 02 00 07
    0000135

    View full-size slide

  35. Kotlin, Groovy, Clojure, JRuby, IntelliJ, Eclipse, Lombok,
    Jamaica, AspectJ, … and a lot of products are using
    ASM

    View full-size slide

  36. MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC,
    "main",
    "([Ljava/lang/String;)V",
    null,
    null);
    methodVisitor.visitCode();
    methodVisitor.visitFieldInsn(Opcodes.GETSTATIC,
    "java/lang/System",
    "out",
    "Ljava/io/PrintStream;");
    methodVisitor.visitLdcInsn("Hello World");
    methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
    "java/io/PrintStream",
    "println",
    "(Ljava/lang/String;)V");
    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitEnd();
    Hello World

    View full-size slide

  37. .class public Main
    .super java/lang/Object
    .method public static main([Ljava/lang/String;)V
    .limit stack 2
    getstatic java/lang/System/out Ljava/io/PrintStream;
    ldc "Hello World"
    invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
    return
    .end method
    JVM assembler

    View full-size slide

  38. JVM instruction set

    View full-size slide

  39. $ javap -v Hello.class
    Classfile /Users/kentaro-takiguchi/workspace/kotlin/Hello.class
    Last modified Mar 21, 2016; size 415 bytes
    MD5 checksum bd70c66b565a03a1fc2b96589b11a4cc
    Compiled from "Hello.java"
    public class Hello
    minor version: 0
    major version: 52
    flags: ACC_PUBLIC, ACC_SUPER
    Constant pool:
    #1 = Methodref #6.#15 // java/lang/Object."":()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
    #5 = Class #21 // Hello
    #6 = Class #22 // java/lang/Object
    #7 = Utf8
    #8 = Utf8 ()V
    #9 = Utf8 Code
    #10 = Utf8 LineNumberTable
    #11 = Utf8 main
    #12 = Utf8 ([Ljava/lang/String;)V
    #13 = Utf8 SourceFile
    #14 = Utf8 Hello.java
    #15 = NameAndType #7:#8 // "":()V
    #16 = Class #23 // java/lang/System
    #17 = NameAndType #24:#25 // out:Ljava/io/PrintStream;
    #18 = Utf8 Hello World
    #19 = Class #26 // java/io/PrintStream
    #20 = NameAndType #27:#28 // println:(Ljava/lang/String;)V
    #21 = Utf8 Hello
    #22 = Utf8 java/lang/Object
    #23 = Utf8 java/lang/System
    #24 = Utf8 out
    #25 = Utf8 Ljava/io/PrintStream;
    #26 = Utf8 java/io/PrintStream
    #27 = Utf8 println
    #28 = Utf8 (Ljava/lang/String;)V
    {
    public Hello();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
    stack=1, locals=1, args_size=1
    0: aload_0
    1: invokespecial #1 // Method java/lang/Object."":()V
    4: return
    LineNumberTable:
    line 1: 0
    public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
    stack=2, locals=1, args_size=1
    0: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
    3: ldc #3 // String Hello World
    5: invokevirtual #4 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
    8: return
    LineNumberTable:
    line 3: 0
    line 4: 8
    }
    SourceFile: "Hello.java"
    $ hexdump -C Hello.class
    00000000 ca fe ba be 00 00 00 34 00 1d 0a 00 06 00 0f 09 |.......4........|
    00000010 00 10 00 11 08 00 12 0a 00 13 00 14 07 00 15 07 |................|
    00000020 00 16 01 00 06 3c 69 6e 69 74 3e 01 00 03 28 29 |........()|
    00000030 56 01 00 04 43 6f 64 65 01 00 0f 4c 69 6e 65 4e |V...Code...LineN|
    00000040 75 6d 62 65 72 54 61 62 6c 65 01 00 04 6d 61 69 |umberTable...mai|
    00000050 6e 01 00 16 28 5b 4c 6a 61 76 61 2f 6c 61 6e 67 |n...([Ljava/lang|
    00000060 2f 53 74 72 69 6e 67 3b 29 56 01 00 0a 53 6f 75 |/String;)V...Sou|
    00000070 72 63 65 46 69 6c 65 01 00 0a 48 65 6c 6c 6f 2e |rceFile...Hello.|
    00000080 6a 61 76 61 0c 00 07 00 08 07 00 17 0c 00 18 00 |java............|
    00000090 19 01 00 0b 48 65 6c 6c 6f 20 57 6f 72 6c 64 07 |....Hello World.|
    000000a0 00 1a 0c 00 1b 00 1c 01 00 05 48 65 6c 6c 6f 01 |..........Hello.|
    000000b0 00 10 6a 61 76 61 2f 6c 61 6e 67 2f 4f 62 6a 65 |..java/lang/Obje|
    000000c0 63 74 01 00 10 6a 61 76 61 2f 6c 61 6e 67 2f 53 |ct...java/lang/S|
    000000d0 79 73 74 65 6d 01 00 03 6f 75 74 01 00 15 4c 6a |ystem...out...Lj|
    000000e0 61 76 61 2f 69 6f 2f 50 72 69 6e 74 53 74 72 65 |ava/io/PrintStre|
    000000f0 61 6d 3b 01 00 13 6a 61 76 61 2f 69 6f 2f 50 72 |am;...java/io/Pr|
    00000100 69 6e 74 53 74 72 65 61 6d 01 00 07 70 72 69 6e |intStream...prin|
    00000110 74 6c 6e 01 00 15 28 4c 6a 61 76 61 2f 6c 61 6e |tln...(Ljava/lan|
    00000120 67 2f 53 74 72 69 6e 67 3b 29 56 00 21 00 05 00 |g/String;)V.!...|
    00000130 06 00 00 00 00 00 02 00 01 00 07 00 08 00 01 00 |................|
    00000140 09 00 00 00 1d 00 01 00 01 00 00 00 05 2a b7 00 |.............*..|
    00000150 01 b1 00 00 00 01 00 0a 00 00 00 06 00 01 00 00 |................|
    00000160 00 01 00 09 00 0b 00 0c 00 01 00 09 00 00 00 25 |...............%|
    00000170 00 02 00 01 00 00 00 09 b2 00 02 12 03 b6 00 04 |................|
    00000180 b1 00 00 00 01 00 0a 00 00 00 0a 00 02 00 00 00 |................|
    00000190 03 00 08 00 04 00 01 00 0d 00 00 00 02 00 0e |...............|
    0000019f

    View full-size slide

  40. Can we use Kotlin?

    View full-size slide

  41. Before Jack & Jill

    View full-size slide

  42. After Jack & Jill
    We may be able to keep using Kotlin

    View full-size slide

  43. Finally, Android will become NOT JAVA.
    We won’t be able to obtain Java updates until Google
    will do (By any chance, it may be the same as now ).
    Why should we keep using Java???
    My concern is…

    View full-size slide