PHP で JVM を実装して、 HelloWorld を出力してみる

218473ff7abad0fcd72865da2b23bb5b?s=47 memory
February 09, 2020

PHP で JVM を実装して、 HelloWorld を出力してみる

- PHPerKaigi 2020

- English Title:
Implement JVM with PHP and try to output Hello World

218473ff7abad0fcd72865da2b23bb5b?s=128

memory

February 09, 2020
Tweet

Transcript

  1. / / PHPerKaigi PHP JVM HelloWorld © - BASE, Inc.

  2. © - BASE, Inc. Who am I? (@m m r

    ) BASE 6 SDVX
  3. © - BASE, Inc. Who am I?

  4. None
  5. © - BASE, Inc. PHPerKaigi Builderscon

  6. © - BASE, Inc. php-java/php-java

  7. OSS

  8. None
  9. © - BASE, Inc. JVM PHP

  10. © - BASE, Inc. Hello World

  11. JVM

  12. JVM

  13. © - BASE, Inc. JVM JVM Java Virtual Machine Java

    JVM JRE JDK
  14. JVM

  15. <?php exec('java HelloWorld')

  16. <?php exec('java HelloWorld')

  17. © - BASE, Inc. JVM Java class class JVM

  18. © - BASE, Inc. JVM JVM Java Virtual Machine Specification

    Oracle
  19. © - BASE, Inc. JVM

  20. © - BASE, Inc. JVM Java class

  21. © - BASE, Inc. JVM

  22. © - BASE, Inc. JVM class

  23. JVM

  24. © - BASE, Inc. Perl PHP JavaScript / Builderscon YAPC::Kyoto

    PHPerKaigi Qiita JVM
  25. JVM

  26. © - BASE, Inc. Rust Emacs Go Ruby rchaser gongoZ

    DQNEO Daiki Miura JVM
  27. JVM

  28. JVM,

  29. PHP

  30. None
  31. © - BASE, Inc. fopen / fread OK

  32. None
  33. © - BASE, Inc. 16 short, unsigned short, integer, unsigned

    integer pack / unpack JVM
  34. None
  35. PHP

  36. © - BASE, Inc. PHP int (- ^ ^ -

    ) bool string float, double array null etc...
  37. Java

  38. © - BASE, Inc. Java byte char short (- ^

    ^ - ) int (- ^ ^ - ) long (- ^ ^ - ) boolean float double
  39. None
  40. PHP Java

  41. None
  42. None
  43. © - BASE, Inc. ( ) JVM invokevirtual iload /

    istore
  44. Hello World

  45. Java Virtual Machine Specification

  46. © - BASE, Inc. JVM Spec Java Virtual Machine Specification

    JVM Spec JVM Spec Oracle JVM https://docs.oracle.com/javase/specs/ index.html
  47. ClassFile Structure

  48. © - BASE, Inc. ClassFile Structure

  49. © - BASE, Inc. ClassFile Structure

  50. © - BASE, Inc. JVM Spec u unsigned int u

    unsigned short
  51. Hello World

  52. © - BASE, Inc. Constant Pool Method Info Code Attribute

    Hello World
  53. Method Info

  54. © - BASE, Inc. Method Info

  55. © - BASE, Inc. Method Info

  56. Code Attribute

  57. None
  58. © - BASE, Inc. Code Attribute

  59. © - BASE, Inc. Code Attribute

  60. © - BASE, Inc. Code Attribute

  61. © - BASE, Inc. Code Attribute

  62. © - BASE, Inc. Code Attribute

  63. © - BASE, Inc. Code Attribute

  64. © - BASE, Inc. Code Attribute

  65. None
  66. © - BASE, Inc. JVM Spec code[code_length] JVM Spec

  67. None
  68. None
  69. None
  70. © - BASE, Inc. java.lang.System.out getstatic println invokevirtual

  71. © - BASE, Inc. Constant Pool ldc return

  72. 4

  73. None
  74. getstatic

  75. © - BASE, Inc. getstatic getstatic getstatic Constant Pool unsigned

    short
  76. © - BASE, Inc. getstatic getstatic <0xB > putstatic

  77. © - BASE, Inc. getstatic

  78. © - BASE, Inc. getstatic

  79. © - BASE, Inc. getstatic

  80. © - BASE, Inc. getstatic

  81. © - BASE, Inc. getstatic

  82. © - BASE, Inc. getstatic

  83. © - BASE, Inc. getstatic

  84. invokevirtual

  85. © - BASE, Inc. invokevirtual invokevirtual Constant Pool

  86. © - BASE, Inc. invokevirtual invokevirtual <0xB > invoke dynamic,

    special, interface, static
  87. © - BASE, Inc. invokevirtual invoke JVM invoke invokedynamic invokeinterface

  88. © - BASE, Inc. invokevirtual

  89. © - BASE, Inc. invokevirtual

  90. © - BASE, Inc. invokevirtual

  91. © - BASE, Inc. invokevirtual

  92. © - BASE, Inc. invokevirtual

  93. © - BASE, Inc. invokevirtual

  94. © - BASE, Inc. invokevirtual void

  95. ldc

  96. © - BASE, Inc. ldc ldc Constant Pool UTF Integer,

    short, byte Constant Pool unsigned byte
  97. © - BASE, Inc. ldc ldc Long Double

  98. © - BASE, Inc. ldc

  99. © - BASE, Inc. ldc Constant Pool

  100. © - BASE, Inc. ldc Constant Pool

  101. © - BASE, Inc. ldc

  102. return

  103. © - BASE, Inc. return return void moniterenter return areturn,

    ireturn, freturn, dreturn
  104. Hello World

  105. © - BASE, Inc. Hello World B NN MM NN

    B NN MM B
  106. © - BASE, Inc. Hello World B NN MM NN

    B NN MM B getstatic
  107. © - BASE, Inc. Hello World B NN MM NN

    B NN MM B unsigned short
  108. © - BASE, Inc. Hello World B NN MM NN

    B NN MM B ldc
  109. © - BASE, Inc. Hello World B NN MM NN

    B NN MM B unsigned byte Hello World Constant Pool
  110. © - BASE, Inc. Hello World B NN MM NN

    B NN MM B invokevirtual
  111. © - BASE, Inc. Hello World B NN MM NN

    B NN MM B unsigned short Constant Pool
  112. © - BASE, Inc. Hello World B NN MM NN

    B NN MM B return
  113. None
  114. "java.lang.System"

  115. © - BASE, Inc. "java.lang.System" Java java.lang.System PHP "java\lang\System" System

    "out"
  116. © - BASE, Inc. "java.lang.System" ;

  117. "out"

  118. © - BASE, Inc. "out" PHP JVM static

  119. © - BASE, Inc. "out"

  120. © - BASE, Inc. "out"

  121. "println" "java.io.PrintStream"

  122. © - BASE, Inc. "java.io.PrintStream"

  123. Hello World

  124. DEMO

  125. THANK YOU FOR YOUR LISTENING