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

PHPerKaigi 2019

memory
March 29, 2019

PHPerKaigi 2019

memory

March 29, 2019
Tweet

More Decks by memory

Other Decks in Programming

Transcript

  1. PHP Ͱ JVM ʹೖ໳͢Δ
    - ༧උ஌ࣝฤ -
    PHPerKaigi 2019
    2019/03/29
    Ί΋Γʔ(@m3m0r7)


    View full-size slide

  2. ͩΕʁ
    Ί΋Γʔ(@m3m0r7) Ͱ͢ɻ

    ը૾͸ ϋϜελʔքͷఱ࢖ Lily ͪΌΜͰ͢ɻ

    ϫλγϋϐʔΤΠνϐʔνϣοτσΩϧ

    גࣜձࣾ GameWith ͱ͍͏ձࣾͰಇ͍ͯ·͢ɻ

    View full-size slide

  3. ༧උ஌ࣝฤͰ࿩͢͜ͱ


    View full-size slide

  4. ༧උ஌ࣝฤͰ࿩͢͜ͱ
    • 16ਐ਺ͷܭࢉํ๏ʹ͍ͭͯ
    • signed / unsgined ͳܕʹ͍ͭͯ
    • double ΍ float ͳͲͷුಈখ਺఺ͷܭࢉํ๏ʹ͍ͭͯ
    • ΤϯσΟΞϯʹ͍ͭͯ

    View full-size slide

  5. 16 ਐ਺ͷܭࢉํ๏


    View full-size slide

  6. ܭࢉํ๏͝ଘ஌ͷํ✋


    View full-size slide

  7. ͦ͏Ͱ͢Ͷɺ dechex / hexdec /
    base_convert ؔ਺Ͱ͢


    View full-size slide

  8. ৑ஊͰ͢


    View full-size slide

  9. 16ਐ਺ͷܭࢉํ๏
    • 10ਐ਺͔Β16ਐ਺ͷܭࢉํ๏͸Լهͷࣜʹ౰ͯ͸ΊΒΕ·͢
    0xFF = (16 - 1) * 16^1 + (16 - 1) * 16^0 = 255(10)
    1ܻ໨͔Βܻ਺͕૿͑Δͨͼʹ1৐,2৐…N৐ͱ૿͍͖͑ͯ·͢ɻͭ·Γɺ0xFFFFͷ
    ৔߹͸ԼهͷΑ͏ʹͳΓ·͢ɻ
    0xFFFF
    = (16 - 1) * 16^3 +(16 - 1) * 16^2 + (16 - 1) * 16^1 +
    (16 - 1) * 16^0
    = 65535(10)
    16͔Β1ΛҾ͍͍ͯΔͷ͸ɺ։࢝͢Δ਺ࣈ͕0͔Β࢝·ΔͨΊͰ͢ɻA͸10, B͸
    11, … F͸15ͱ֮͑ͯ͠·͍·͠ΐ͏ɻ

    View full-size slide

  10. 16ਐ਺ͷܭࢉํ๏
    • PHPͰܭࢉ͢Δʹ͸ʁ
    ͜Μͳܭࢉਖ਼௚΍Γͨ͘ͳ͍ɻϓϩάϥϚςΟοΫʹղܾͰ͖ΔͳΒղܾ͢Δʹӽ
    ͨ͜͠ͱ͸ͳ͍Ͱ͢ɻ
    • 10ਐ਺͔Β16ਐ਺ʹ͢Δ
    = dechex(255) ?>
    • 16ਐ਺͔Β10ਐ਺ʹ͢Δ
    = hexdec(‘0xFF’) ?>
    = base_convert(255, 10, 16) ?>
    = base_convert(‘0xFF’, 16, 10) ?>

    View full-size slide

  11. ͱͬͯ΋؆୯Ͱ͢Ͷ


    View full-size slide

  12. signed / unsigned ͳܕʹ͍ͭͯ


    View full-size slide

  13. ͱ͜ΖͰɺPHPer ͷΈͳ͞Μ͕
    ͝ଘ஌ͷܕ͸ԿͰ͠ΐ͏͔


    View full-size slide

  14. JVM Ͱ͸ܕ͕૿͑·͢


    View full-size slide

  15. PHP͔Βݟͯ૿͑ͨܕ
    • boolean
    • int (4 byte)
    • string
    • float
    • ࣮࣭ float ͷ double
    • byte (1 byte)
    • short (2 byte)
    • long (8 byte)
    • Ψν float (4 byte, ୯ਫ਼౓ුಈখ਺఺਺)
    • Ψν double (8 byte, ഒਫ਼౓ුಈখ਺఺਺)

    View full-size slide

  16. ଟݴޠΛѻͬͨ͜ͱͳ͍ํ͸
    ೃછΈ͕ͳ͍͔΋͠Ε·ͤΜ


    View full-size slide

  17. JVM ্ͷ֤ܕʹ͍ͭͯ


    View full-size slide

  18. ֤ܕʹ͍ͭͯ - byte
    • signed byte (ූ߸෇͖ byte)
    • -128(10) ʙ 127(10) ͕ ූ߸෇͖ byte ͷൣғͱͳΓ·͢ɻ
    • 16ਐ਺Ͱ͸ 0x00 ʙ 0xFF ·ͰͰ͢ɻ
    • ਖ਼ͷ਺͸ 0x00ʙ0x7F, ෛͷ਺͸ 0x80 ʙ 0xFF ͱͳΓ·͢ɻ
    • unsigned byte (ූ߸ͳ͠ byte)
    • 0(10) ʙ 255(10) ͕ූ߸ͳ͠ byte ͷൣғͱͳΓ·͢ɻ
    • 16ਐ਺Ͱ͸ 0x00 ʙ 0xFF ·ͰͰ͢
    • ਖ਼ͷ਺ͷΈͰ͢ɻ

    View full-size slide

  19. ֤ܕʹ͍ͭͯ - short
    • signed short (ූ߸෇͖ short)
    • -32768(10) ʙ 32767(10) ͕ ූ߸෇͖ short ͷൣғͱͳΓ·͢ɻ
    • 16ਐ਺Ͱ͸ 0x0000 ʙ 0xFFFF ·ͰͰ͢ɻ
    • ਖ਼ͷ਺͸ 0x0000ʙ0x7FFF, ෛͷ਺͸ 0x8000 ʙ 0xFFFF ͱͳΓ·͢ɻ
    • unsigned short (ූ߸ͳ͠ short)
    • 0(10) ʙ 65535(10) ͕ූ߸ͳ͠ short ͷൣғͱͳΓ·͢ɻ
    • 16ਐ਺Ͱ͸ 0x0000 ʙ 0xFFFF ·ͰͰ͢
    • ਖ਼ͷ਺ͷΈͰ͢ɻ

    View full-size slide

  20. ֤ܕʹ͍ͭͯ - int
    • signed int (ූ߸෇͖ int)
    • -2147483648(10) ʙ 2147483647(10) ͕ ූ߸෇͖ int ͷൣғͱͳΓ·
    ͢ɻ
    • 16ਐ਺Ͱ͸ 0x000000 ʙ 0xFFFFFF ·ͰͰ͢ɻ
    • ਖ਼ͷ਺͸ 0x000000ʙ0x7FFFFF, ෛͷ਺͸ 0x800000 ʙ 0xFFFFFF ͱͳ
    Γ·͢ɻ
    • unsigned int (ූ߸ͳ͠ int)
    • 0(10) ʙ 4294967295(10) ͕ූ߸ͳ͠ int ͷൣғͱͳΓ·͢ɻ
    • 16ਐ਺Ͱ͸ 0x000000 ʙ 0xFFFFFF ·ͰͰ͢
    • ਖ਼ͷ਺ͷΈͰ͢ɻ

    View full-size slide

  21. ֤ܕʹ͍ͭͯ - long
    • signed long (ූ߸෇͖ long)
    • -9223372036854775808(10) ʙ 9223372036854775807(10) ͕ ූ߸෇͖
    long ͷൣғͱͳΓ·͢ɻ
    • 16ਐ਺Ͱ͸ 0x00000000 ʙ 0xFFFFFFFF ·ͰͰ͢ɻ
    • ਖ਼ͷ਺͸ 0x00000000ʙ0x7FFFFFFF, ෛͷ਺͸ 0x80000000 ʙ
    0xFFFFFFFF ͱͳΓ·͢ɻ
    • unsigned long (ූ߸ͳ͠ long)
    • 0(10) ʙ 18446744073709551615(10) ͕ූ߸ͳ͠ long ͷൣғͱͳΓ·
    ͢ɻ
    • 16ਐ਺Ͱ͸ 0x00000000 ʙ 0xFFFFFFFF ·ͰͰ͢
    • ਖ਼ͷ਺ͷΈͰ͢ɻ

    View full-size slide

  22. ͓ؾ͖ͮͷํ΋͍Δ͔΋஌Ε·ͤΜ


    View full-size slide

  23. ͦ͏ɺPHP Ͱ͸ܭࢉͰ͖ͳ͍਺ࣈ͕
    ؚ·Ε͍ͯΔͷͰ͢


    View full-size slide

  24. Ͱ΋େৎ෉


    View full-size slide

  25. ͦ͏ gmp ؔ਺ͳΒͶ


    View full-size slide

  26. PHP ͰܭࢉͰ͖ͳ͍஋Λܭࢉ͢Δ
    • PHP Ͱ͸ unsigned long ͷ஋ΛܭࢉͰ͖ͳ͍͕ɺ gmpؔ਺
    Ͱܭࢉͤ͞Δ͜ͱ͸Մೳɻྫ͑͹
    = gmp_strval(gmp_add(PHP_INT_MAX, PHP_INT_MAX));" ?>
    • ݁Ռ͸ 18446744073709551614 ͱͳΓ·͢

    View full-size slide

  27. ුಈখ਺఺ͷܭࢉʹ͍ͭͯ


    View full-size slide

  28. ܭࢉํ๏͝ଘ஌ͷํ✋


    View full-size slide

  29. ͪͳΈʹɺࢲ͸ۤखͰ͢


    View full-size slide

  30. ͋ͱɺຊฤͰ͸࢖Θͳ͍ͷͰ༨ஊͱͯ͠
    ָ͓͠Έ͍ͩ͘͞


    View full-size slide

  31. ුಈখ਺఺ͷܭࢉํ๏
    • ුಈখ਺఺ͷܭࢉํ๏Ͱ༗໊ॴ͸Լه͔ͱࢥ͍·͢ɻ
    • ୯ਫ਼౓ුಈখ਺఺਺
    • ഒਫ਼౓ුಈখ਺఺਺
    • ͪͳΈʹ͜ΕΒ͸ IEEE754 Ͱఆٛ͞Ε͍ͯΔͷͰৄ͘͠஌Γ
    ͍ͨํ͸ޚཡ͍ͩ͘͞ɻ
    • ୯ਫ਼౓ුಈখ਺఺਺͸ 32 Ϗοτ (4 byte) ഒਫ਼౓ුಈখ਺఺਺
    ͸ 64 Ϗοτ (8 byte) ͷදݱ෯ͷҧ͍͕͋Γ·͢ɻ
    ࢀরɿhttps://ja.wikipedia.org/wiki/IEEE_754
    ը૾ʹ͍ͭͯɿhttps://creativecommons.org/licenses/by-sa/3.0/

    View full-size slide

  32. ුಈখ਺఺ͷܭࢉํ๏
    • ୯ਫ਼౓ුಈখ਺఺਺ (float) ͷܭࢉํ๏
    • sign ͕ූ߸ͱͳΓ·͢ɻ (sͱஔ͖·͢)

    • exponent ͕ࢦ਺෦ͱͳΓ·͢ɻ (e ͱஔ͖·͢)

    • fraction ͕Ծ਺෦ͱͳΓ·͢ɻ (f ͱஔ͖·͢ɻ)
    ࢀরɿhttps://ja.wikipedia.org/wiki/IEEE_754
    ը૾ʹ͍ͭͯɿhttps://creativecommons.org/licenses/by-sa/3.0/
    ୯ਫ਼౓ුಈখ਺఺਺ͷܭࢉࣜ͸
    = s * f * 2^(e - 127)

    View full-size slide

  33. ුಈখ਺఺ͷܭࢉํ๏
    • ഒਫ਼౓ුಈখ਺఺਺ (double) ͷܭࢉํ๏
    • جຊతʹ͸୯ਫ਼౓ුಈখ਺఺਺ͱมΘΓ·ͤΜɻ

    • sign ͕ූ߸ͱͳΓ·͢ɻ (sͱஔ͖·͢)

    • exponent ͕ࢦ਺෦ͱͳΓ·͢ɻ (e ͱஔ͖·͢)

    • fraction ͕Ծ਺෦ͱͳΓ·͢ɻ (f ͱஔ͖·͢ɻ)
    ࢀরɿhttps://ja.wikipedia.org/wiki/IEEE_754
    ը૾ʹ͍ͭͯɿhttps://creativecommons.org/licenses/by-sa/3.0/
    ഒਫ਼౓ුಈখ਺఺਺ͷܭࢉࣜ͸
    = s * f * 2^(e - 1023)

    View full-size slide

  34. ͕͔ͩ͠͠


    View full-size slide

  35. JVM ্ͩͱҧ͏ΜͰ͢


    View full-size slide

  36. ුಈখ਺఺ͷܭࢉํ๏
    • JVM্ʹ͓͚Δ୯ਫ਼౓ුಈখ਺఺਺ͷܭࢉํ๏͸Լهͷ௨Γ
    • JVM্ʹ͓͚Δഒਫ਼౓ුಈখ਺఺਺ͷܭࢉํ๏͸Լهͷ௨Γ
    • ࢦ਺෦ͷϚεΫ͍ͯ͠Δ஋͕ҟͳΓ·͢ɻ
    = s * f * 2^(e - 1075)
    = s * f * 2^(e - 150)

    View full-size slide

  37. ΤϯσΟΞϯʹ͍ͭͯ


    View full-size slide

  38. ΤϯσΟΞϯͱ͍͏ݴ༿Λ
    ஌͍ͬͯΔํ✋


    View full-size slide

  39. ΤϯσΟΞϯʹ͍ͭͯ
    • ΤϯσΟΞϯ͸ओʹ2ͭ͋Γ·͢
    • ϦτϧΤϯσΟΞϯ
    • ϏοάΤϯσΟΞϯ
    • ϦτϧΤϯσΟΞϯ͸ӈ͔Βࠨ΁ɺϏοάΤϯσΟΞϯ͸ࠨ
    ͔Βӈ΁ಡΉͱ֮͑Ε͹େৎ෉Ͱ͢ɻ

    View full-size slide

  40. ͪͳΈʹϛυϧΤϯσΟΞϯͱ͍͏ͷ΋
    ͋ΔΒ͍͠


    View full-size slide

  41. ࢀরɿhttps://ja.wikipedia.org/wiki/
    %E3%82%A8%E3%83%B3%E3%83%87%E3%82%A3%E3%82%A2%E3%83%B3

    View full-size slide

  42. ࢀরɿhttps://ja.wikipedia.org/wiki/
    %E3%82%A8%E3%83%B3%E3%83%87%E3%82%A3%E3%82%A2%E3%83%B3

    View full-size slide

  43. มͳ΋ͷͩͦ͏Ͱ͢


    View full-size slide

  44. ϦτϧΤϯσΟΞϯʹ͍ͭͯ


    View full-size slide

  45. ϦτϧΤϯσΟΞϯʹ͍ͭͯ
    • ϦτϧΤϯσΟΞϯͷಈ͖͸ԼهͷΑ͏ʹϝϞϦʹੵ·Εͯ
    ͍͖·͢
    00 AA BB CC DD
    Ϩδελ
    DD CC
    ϝϞϦ
    0xA
    ΞυϨε 0xB 0xC 0xD 0xE

    View full-size slide

  46. ϏοάΤϯσΟΞϯʹ͍ͭͯ


    View full-size slide

  47. ϏοάΤϯσΟΞϯʹ͍ͭͯ
    • ϏοάΤϯσΟΞϯͷಈ͖͸ԼهͷΑ͏ʹϝϞϦʹੵ·Εͯ
    ͍͖·͢
    00 AA BB CC DD
    Ϩδελ
    CC DD
    ϝϞϦ
    0xA
    ΞυϨε 0xB 0xC 0xD 0xE

    View full-size slide

  48. ͓͞Β͍


    View full-size slide

  49. ͓͞Β͍
    •gmp_* ؔ਺Λ֮͑ͯؼΖ͏
    •dechex / hexdec / base_convert ؔ਺Λ֮͑ͯ
    ؼΖ͏
    •signed, unsigned ͳ஋ʹ͍֮ͭͯ͑ͯؼΖ͏
    •ුಈখ਺఺ͷܭࢉํ๏Λ֮͑ͯؼΖ͏
    •ΤϯσΟΞϯʹ͍֮ͭͯ͑ͯؼΖ͏

    View full-size slide

  50. લ࠲͸ऴྃͰ͢


    View full-size slide

  51. ͋ͳͨ͸஌͍ͬͯΔͩΖ͏͔


    View full-size slide

  52. 30 ԯͷσόΠεͰ૸ΔϠπͷ͜ͱΛ…


    View full-size slide

  53. ͦ͏ Java ͷ͜ͱΛ…


    View full-size slide

  54. ͦ͏ Java ͷ͜ͱΛ…
    PHP


    View full-size slide

  55. PHP Ͱ JVM ʹೖ໳͢Δ
    - ຊฤ -


    PHPerKaigi 2019
    2019/03/29
    Ί΋Γʔ(@m3m0r7)

    View full-size slide

  56. ͩΕʁ
    Ί΋Γʔ(@m3m0r7)

    ϫλγϋϐʔΤΠνϐʔνϣοτσΩϧ

    גࣜձࣾ GameWith ͱ͍͏ձࣾͰಇ͍ͯ·͢ɻ

    View full-size slide

  57. PHP ͰόΠφϦϦʔσΟϯά

    View full-size slide

  58. ΍ΓํΛ͝ଘ஌ͷํ✋

    View full-size slide

  59. ͦ΋ͦ΋ɺόΠφϦϦʔσΟϯάͱ͸ʁ

    View full-size slide

  60. ੺࿮ͷͱ͜ΖΛಡΜͰ͍͘͜ͱͰ͢

    View full-size slide

  61. ͦ΋ͦ΋ɺPHP Ͱ JVM Λ
    ಡΜͰԿָ͕͍͠ͷʁ

    View full-size slide

  62. PHP Ͱ JVM ΛಡΜͰԿָ͕͍͠ͷ͔
    • ελοΫϚγϯ͕ͲͷΑ͏ʹಈ͍ͯΔ͔ཧղ͢Δ͜ͱ͕Ͱ͖
    ͨؾ࣋ͪʹͳΔ
    • ͨͩ͠ JVM ͸ϩʔΧϧม਺ͷετΞ΍ϩʔυ͕ແݶେʹͰ
    ͖ΔͨΊ७ਮͳελοΫϚγϯͰ͸ͳ͍
    • php ͷதؒίʔυ͕ཧղ͠΍͘͢ͳΔ
    • vld extension ͷؾ࣋ͪʹͳΕΔ
    • 30 ԯͷσόΠεͰ૸Δ͜ͱ͕Ͱ͖Δ
    • ͳΜͳΒ PHP ͕Քಇ͍ͯ͠Δαʔόʔ୆਺෼΋ؚΊΔͱ
    Java ΑΓ΋͍͢͝ͷͰ͸

    View full-size slide

  63. JVM Λೖ໳͢Δʹ͋ͨͬͯ

    View full-size slide

  64. The Java® Virtual Machine Specification
    ΋ҰॹʹಡΜͰ͍͖·͢

    View full-size slide

  65. The Java® Virtual Machine Specification
    https://docs.oracle.com/javase/specs/jvms/se11/html/index.html

    View full-size slide

  66. ͬͦ͘͞όΠφϦϦʔσΟϯά͠·͢

    View full-size slide

  67. Java ͷΫϥεϑΝΠϧ͸͜ͷߏ଄

    View full-size slide

  68. unsigned int
    unsigned short
    object (PHPͩͬͨΒ഑ྻͰOK)

    View full-size slide

  69. ࣮ࡍʹ PHP ͰಡΜͰ͍͘

    View full-size slide

  70. όΠφϦΛಡΉʹ͸
    • PHPͷϑΝΠϧؔ਺Λ࢖͏
    • fopen ؔ਺
    • fread ؔ਺
    • fseek ؔ਺
    • int ΍ short ͳͲͷ஋Λܭࢉ͢Δ
    • base_convert ؔ਺
    • pack / unpack ؔ਺ (ࠓճ͸͜ΕΛ࢖͍·͢)
    • ord / chr ؔ਺
    • ؾ߹

    View full-size slide

  71. unsigned int
    magic
    unsigned short
    minor version
    unsigned short
    major version
    unsigned short
    constant pool count

    View full-size slide

  72. PHP Ͱද͢ͱ

    View full-size slide

  73. N ͸ unsigned int Ͱ
    ϏοάΤϯσΟΞϯ
    όΠτΦʔμʔ
    n ͸ unsigned short Ͱ
    ϏοάΤϯσΟΞϯ
    όΠτΦʔμʔ
    cafebabe
    0
    52 (JDK 8)
    29
    ͜͜Ͱ͍͏ int (4byte) ΍ short (2byte) ͷαΠζ͸ JVM ্Ͱͷ࿩ʹͳΓ·͢ɻ

    View full-size slide

  74. Ͷʁ؆୯Ͱ͠ΐʁ

    View full-size slide

  75. औಘͨ͠ constant_pool_count ΑΓ
    Constant Pool Λऔಘ͠·͢

    View full-size slide

  76. ੺࿮͕ constant pool

    View full-size slide

  77. PHP Ͱද͢ͱ

    View full-size slide

  78. ʁʁʁ
    ʁʁʁ
    ʁʁʁ
    ʁʁʁ

    View full-size slide

  79. 0x0A ΍ 0x09 ͷ஋ͬͯʁ

    View full-size slide

  80. Constant Kind ͱ Tag ͷ͜ͱΛ
    ͍ࣔͯ͠·͢
    unsigned byte

    View full-size slide

  81. ͭ·Γ Constant Kind ͷ Tag ͷ
    ஋ʹΑͬͯॲཧͷ࢓ํ͕
    มΘΓ·͢

    View full-size slide

  82. ॲཧͷํ๏͕ҟͳΔ
    • ࠓճ͸ Methodref (0x0A), Fieldref (0x09), String (0x08),
    Class (0x07), Utf8 (0x01), NameAndType(0x0C) ͷ6ͭͷΈ
    ରԠɻ
    Constant Kind Tag Read bytes
    CONSTANT_Methodref 0x0A
    2 byte + 2 byte

    ( unsigned short + unsigned short )
    CONSTANT_Fieldref 0x09
    2 byte + 2 byte

    ( unsigned short + unsigned short )
    CONSTANT_String 0x08
    2 byte

    ( unsigned short )
    CONSTANT_Class 0x07
    2 byte

    ( unsigned short )
    CONSTANT_Utf8 0x01
    ( length = 2 byte ) + length bytes

    ( unsigned short + length bytes )
    CONSTANT_NameAndType 0x0C
    2 byte + 2 byte

    ( unsigned byte + unsigned byte )

    View full-size slide

  83. ͜ΕΛ΋ͱʹͯ͠…

    View full-size slide

  84. C ͸ unsigned byte
    constant pool count ͸ྺ࢙తͳ
    ཧ༝ʹΑΓ -1 ͢Δ
    CONSTANT_Methodref
    CONSTANT_Fieldref
    CONSTANT_String
    CONSTANT_Class

    View full-size slide

  85. CONSTANT_Utf8
    CONSTANT_NameAndType
    औಘͨ݁͠ՌΛ֨ೲ͢Δ

    View full-size slide

  86. ࣮ࡍʹग़ྗͯ͠ΈΔͱͲ͏ͳΔ͔ʁ

    View full-size slide

  87. ͦΕͬΆ͍ͷ͕ݟ͑ͯ͘Δ

    View full-size slide

  88. ✌(‘ω'✌ )ࡾ✌('ω')✌ࡾ( ✌’ω’)✌
    ָ͍͠ !!!

    View full-size slide

  89. Ҿ͖ଓ͖ಡΜͰ͍͖·͢

    View full-size slide

  90. unsigned short
    access flag
    unsigned short
    this class
    unsigned short
    super class
    unsigned short
    interface count
    unsigned short
    fields count
    unsigned short
    methods count

    View full-size slide

  91. PHP Ͱද͢ͱ

    View full-size slide

  92. 32 (ACC_SUPER)
    Test
    java/lang/Object
    0 (ΠϯλϑΣʔε͸ఆٛ͞Ε͍ͯͳ͍ͨΊ)
    0 (ϑΟʔϧυ͸ఆٛ͞Ε͍ͯͳ͍ͨΊ)
    2 ( ͱ main ͕ఆٛ͞Ε͍ͯΔͨΊ)

    View full-size slide

  93. ϝιου͕ 2 ͭ͋ΔͷͰ
    ಡΜͰ͍͖·͢

    View full-size slide

  94. unsigned short
    unsigned short
    unsigned short
    unsigned short
    ϝιουʹ͸ Code Attribute ؚ͕·ΕΔ
    ʢͦΕҎ֎΋ؚ·Ε·͕͢লུ͠·͢ʣ

    View full-size slide

  95. Code Attribute ͷߏ଄͸ʁ

    View full-size slide

  96. unsigned short
    length byte
    unsigned int
    Code Attribute ʹ͸ LineNumberTable Attribute
    ؚ͕·Ε·͢
    ʢͦΕҎ֎΋ؚ·Ε·͕͢লུ͠·͢ʣ

    View full-size slide

  97. LineNumberTable Attribute ͷߏ଄͸ʁ

    View full-size slide

  98. unsigned short
    unsigned int

    View full-size slide

  99. ੺࿮͕ϝιουͷ৘ใͱ
    JVM ͷίʔυͷ৘ใʹͳΓ·͢

    View full-size slide

  100. PHP Ͱද͢ͱ

    View full-size slide

  101. ࣮ࡍͷ JVM ্ͷίʔυ͕֨ೲ͞Ε͍ͯ·͢
    Attribute ͷछྨʹΑΓॲཧํ๏͕ҟͳΔͨΊ
    ෼ذ͍ͯ͠·͢
    ࠶ؼ͢Δඞཁ͕͋ΔͷͰؔ਺Խͯ͠·͢

    View full-size slide

  102. Attribute ͷछྨʹΑΓॲཧํ๏͕ҟͳΔͨΊ
    ෼ذ͍ͯ͠·͢
    ࠶ؼͰॲཧ͍ͯ͠·͢

    View full-size slide

  103. 0 (ϝιου΁ͷΞΫηεݖΛ͍ࣔͯ͠·͢)
    , mainͳͲͷϝιου໊
    ()V, ([Ljava/lang/String;)VͳͲͷ
    ϝιουͷҾ਺ͷ৘ใ
    Code Attribute ͳͲͷ৘ใ

    View full-size slide

  104. ࣮ࡍʹग़ྗͯ͠ΈΔͱʁ

    View full-size slide

  105. ͍͍ײ͡ʹऔΕ͖ͯ·ͨ͠

    View full-size slide

  106. ϥετεύʔτ

    View full-size slide

  107. ࠷ޙ͸ Ϋϥεͷ Attribute Λऔಘ͢Δ

    View full-size slide

  108. ClassFile Structure ʹ͸ SourceFile Attribute ͕
    ؚ·Ε·͢
    ʢͦΕҎ֎΋ؚ·Ε·͕͢লུ͠·͢ʣ

    View full-size slide

  109. SourceFile Attribute ͷߏ଄͸ʁ

    View full-size slide

  110. unsigned short
    attribute count
    unsigned short
    attribute name index
    unsigned int
    attribute length
    unsigned short
    sourcefile index

    View full-size slide

  111. PHP Ͱද͢ͱ

    View full-size slide

  112. readAttributeؔ਺ʹ SourceFile Λ௥Ճ

    View full-size slide

  113. ϝιουͱಉ͡Α͏ͳॲཧΛॻ͘

    View full-size slide

  114. Ҏ্Ͱ JVM ೖ໳׬ྃͰ͢

    View full-size slide

  115. 30ԯͷσόΠεͰ૸Δ Java ͷ
    ؾ࣋ͪʹͳΕ·͔ͨ͠ʁ
    PHP

    View full-size slide

  116. PHP Ͱ JVM Λಈ͔͢
    χʔϞχοΫͱ͸
    Operation Code ͱ͸
    iload_0 ͬͯͳΜͩ…
    tableswitch ͱ lookupswitch ͷҧ͍
    Φϖϥϯυ
    ϩʔΧϧετϨʔδ
    invokespecial ͱ invokevirtual
    ಥવͷ
    ͳͥ PHP Ͱ΍ΔΜͩ…

    View full-size slide

  117. ָ͓͠Έʹʂ
    ※͓࿩͢Δ৔ॴ͸ܾ·ͬͯ·ͤΜ
    ※͓࿩͢Δ͜ͱࣗମܾ·ͬͯ·ͤΜ

    View full-size slide

  118. ͜ͷ೔ͷͨΊʹɺେྔͷ࣮૷ͱ
    ϦϑΝΫλϦϯάΛ͖ͯ͠·ͨ͠

    View full-size slide

  119. JAR ͷରԠ, ΞϊςʔγϣϯͷରԠ, ֎෦Ϋϥε
    ͷରԠ ͳͲͳͲ…

    View full-size slide

  120. Before
    ʊਓਓਓਓਓਓʊ
    ʼɹ.DS_Storeɹʻ
    ʉY^Y^Y^Y^Y^Y^ʉ
    ʊਓਓਓਓਓਓʊ
    ʼɹnbprojectɹʻ
    ʉY^Y^Y^Y^Y^Y^ʉ
    ʊਓਓਓਓʊ
    ʼɹ4೥લɹʻ
    ʉY^Y^Y^Y^ʉ

    View full-size slide

  121. 20ࡀͷͱ͖ʹ͜Εॻ͍ͨͷ͔…

    View full-size slide

  122. After
    PHPUnit Ͱςετ
    composer ରԠ
    PHP CodeSniffer ͰίʔσΟϯάϧʔϧΛ౷Ұ
    TravisCIͰςετΛ୲อ

    View full-size slide

  123. ϞμϯʹͳΓ·ͨ͠

    View full-size slide

  124. DEMO
    (͕࣌ؒ͋Ε͹)

    View full-size slide

  125. php-java ͱ͍͏໊લͰ JVM ΤϛϡϨʔλΛެ։͍ͯ͠·͢
    ͥͻࣗ͝਎ͷ PC Ͱࢼͯ͠Έ͍ͯͩ͘͞
    ͦͯ͠ίϯτϦϏϡʔλʹͳ͍ͬͯͩ͘͞ʂʂ
    https://github.com/memory-agape/php-java

    View full-size slide

  126. ຊ೔ͷαϯϓϧ͸ͪ͜Β
    https://gist.github.com/memory-agape/
    6d4dce2af4ece6e41293afb4e2caa5e1

    View full-size slide

  127. THANK YOU FOR YOUR LISTENING

    View full-size slide