Slide 1

Slide 1 text

/ / builderscon Tokyo PHP JVM Hello World © - BASE, Inc.

Slide 2

Slide 2 text

© - BASE, Inc. Who am I? (@m m r ) BASE PHP, React

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

© - BASE, Inc. PHP JVM

Slide 5

Slide 5 text

© - BASE, Inc. Hello World JVM PHP JVM

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

© - BASE, Inc. PHP JVM Specification Java

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

© - BASE, Inc. PHP JVM PHPerKaigi https://speakerdeck.com/memory /phperkaigi-

Slide 10

Slide 10 text

© - BASE, Inc. PHP JVM OSS ( ) https://github.com/php-java/php-java

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

1. JDK JDK

Slide 13

Slide 13 text

2. 


Slide 14

Slide 14 text

JVM PHP

Slide 15

Slide 15 text

© - BASE, Inc. PHP JVM

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

© - BASE, Inc. PHP

Slide 18

Slide 18 text

© - BASE, Inc.

Slide 19

Slide 19 text

© - BASE, Inc. 2014 2015 1 30 nbproject Netbeans C:\\ 
 Windows 1 
 (Hello World ) 
 ( )

Slide 20

Slide 20 text

© - BASE, Inc.

Slide 21

Slide 21 text

© - BASE, Inc.

Slide 22

Slide 22 text

© - BASE, Inc.

Slide 23

Slide 23 text

© - BASE, Inc.

Slide 24

Slide 24 text

© - BASE, Inc.

Slide 25

Slide 25 text

© - BASE, Inc.

Slide 26

Slide 26 text

© - BASE, Inc.

Slide 27

Slide 27 text

© - BASE, Inc. Wikipedia JVM 
 PHP ( ) https://en.wikipedia.org/wiki/List_of_Java_virtual_machines JPHP Java PHP ( ) https://github.com/jphp-group/jphp

Slide 28

Slide 28 text

© - BASE, Inc. PHP

Slide 29

Slide 29 text

© - BASE, Inc. PHP PHP PHP Laravel 
 PHP 
 JVM

Slide 30

Slide 30 text

© - BASE, Inc. PHP JVM

Slide 31

Slide 31 text

JVM

Slide 32

Slide 32 text

© - BASE, Inc. JVM JVM class 
 (= ) 


Slide 33

Slide 33 text

© - BASE, Inc. JVM class javac java JAR (Java ARchive) class kotlinc -include-runtime class 
 JAR Scala sbt-assembly JAR

Slide 34

Slide 34 text

© - BASE, Inc. JVM JVM C CPU Oracle 
 PHP Rust ( ) invoke_*

Slide 35

Slide 35 text

© - BASE, Inc. JVM 3 PHP PHP class

Slide 36

Slide 36 text

© - BASE, Inc. JVM PHP PHP class

Slide 37

Slide 37 text

© - BASE, Inc. JVM PHP class PHPerKaigi 
 https://speakerdeck.com/memory /phperkaigi-

Slide 38

Slide 38 text

© - BASE, Inc. PHP JVM

Slide 39

Slide 39 text

PHP

Slide 40

Slide 40 text

PHP

Slide 41

Slide 41 text

© - BASE, Inc. PHP PHP Object java.lang.Object? String Void Integer, Long OK

Slide 42

Slide 42 text

© - BASE, Inc. PHP Swoole parallel 
 


Slide 43

Slide 43 text

© - BASE, Inc. PHP PHP Exception Java java.lang.Object

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

© - BASE, Inc. Hello World JVM PHP JVM

Slide 47

Slide 47 text

JVM

Slide 48

Slide 48 text

OpCode

Slide 49

Slide 49 text

OpCode

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

© - BASE, Inc. 1 JVM 算

Slide 52

Slide 52 text

© - BASE, Inc. CPU mov rax, rbx ( 0x ) 1, 2

Slide 53

Slide 53 text

© - BASE, Inc. JVM ldc # ( 0x ) #3 Constant Pool 3

Slide 54

Slide 54 text

Constant Pool

Slide 55

Slide 55 text

© - BASE, Inc. Constant Pool Constant Pool 
 The Java Virtual Machine maintains a per-type constant pool, a run- time data structure that serves many of the purposes of the symbol table of a conventional programming language implementation. Java Virtual Machine Specification : : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . Constant Pool Hello World 
 JVM Constant Pool

Slide 56

Slide 56 text

© - BASE, Inc. Constant Pool Constant Pool 
 Java Virtual Machine Constant Pool ( ) Java Virtual Machine Specification : : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . Constant Pool Hello World 
 JVM Constant Pool

Slide 57

Slide 57 text

© - BASE, Inc. Constant Pool Constant Pool

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

© - BASE, Inc. Hello World JVM PHP JVM

Slide 60

Slide 60 text

Hello World

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

© - BASE, Inc. PHP JDK

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

© - BASE, Inc. java javap Constant Pool 
 javac Java php

Slide 65

Slide 65 text

Java

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

© - BASE, Inc. Java

Slide 68

Slide 68 text

Hello World

Slide 69

Slide 69 text

© - BASE, Inc. Hello World Hello World ClassFile Structure 
 Constant Pool Methodref 
 Constant Pool Code Attribute Code Attribute Constant Pool : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- .

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

© - BASE, Inc. ClassFile Structure Code Attribute 1 Constant Pool

Slide 72

Slide 72 text

© - BASE, Inc. ClassFile Structure Code Attribute 1 Constant Pool

Slide 73

Slide 73 text

ClassFile Structure

Slide 74

Slide 74 text

© - BASE, Inc. ClassFile Structure ClassFile Structure 
 Java Constant Pool etc : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- .

Slide 75

Slide 75 text

© - BASE, Inc. ClassFile Structure : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . JVM Specification

Slide 76

Slide 76 text

© - BASE, Inc. ClassFile Structure : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . JVM Specification

Slide 77

Slide 77 text

© - BASE, Inc. ClassFile Structure javac 
 : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . javac -encoding UTF- HelloWorld.java

Slide 78

Slide 78 text

© - BASE, Inc. ClassFile Structure PHP 
 unpack fopen fread unpack https://gist.github.com/memory-agape/ d dce af ece e afb e caa e

Slide 79

Slide 79 text

ClassFile Structure Constant Pool

Slide 80

Slide 80 text

© - BASE, Inc. ClassFile Structure Code Attribute 1 Constant Pool

Slide 81

Slide 81 text

© - BASE, Inc. Constant Pool : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . Constant Pool u unsigned short

Slide 82

Slide 82 text

© - BASE, Inc. Constant Pool Constant Pool

Slide 83

Slide 83 text

© - BASE, Inc. Constant Pool : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . Constant Pool 16bit 
 Constant Pool 
 JVM Specification

Slide 84

Slide 84 text

© - BASE, Inc. Constant Pool : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . tag Constant Pool tag prefix CONSTANT_ छྨ ஋ छྨ ஋ Class 0x07 Fieldref 0x09 Methodref 0x0A InterfaceMethodref 0x0B String 0x08 Integer 0x03 Float 0x04 Long 0x05 Double 0x06 NameAndType 0x0C Utf8 0x01 MethodHandle 0x0F MethodType 0x10 InvokeDynamic 0x12

Slide 85

Slide 85 text

© - BASE, Inc. Constant Pool : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . Hello World Class, Methodref, 
 String, Utf , NameAndType 5 छྨ ஋ छྨ ஋ Class 0x07 Fieldref 0x09 Methodref 0x0A InterfaceMethodref 0x0B String 0x08 Integer 0x03 Float 0x04 Long 0x05 Double 0x06 NameAndType 0x0C Utf8 0x01 MethodHandle 0x0F MethodType 0x10 InvokeDynamic 0x12

Slide 86

Slide 86 text

© - BASE, Inc. Constant Pool : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- .

Slide 87

Slide 87 text

ClassFile Structure

Slide 88

Slide 88 text

© - BASE, Inc. ClassFile Structure Code Attribute 1 Constant Pool

Slide 89

Slide 89 text

© - BASE, Inc. : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . ClassFile Structure

Slide 90

Slide 90 text

© - BASE, Inc. 
 CodeAttribute

Slide 91

Slide 91 text

© - BASE, Inc. 
 CodeAttribute

Slide 92

Slide 92 text

© - BASE, Inc. : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- .

Slide 93

Slide 93 text

© - BASE, Inc. : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . CodeAttribute Constant Pool 
 ( CONSTANT_Utf )

Slide 94

Slide 94 text

© - BASE, Inc. ClassFile Structure Code Attribute 1 Constant Pool

Slide 95

Slide 95 text

Code Attribute

Slide 96

Slide 96 text

© - BASE, Inc. Code Attribute Code Attribute 


Slide 97

Slide 97 text

© - BASE, Inc. Code Attribute Code Attribute 


Slide 98

Slide 98 text

© - BASE, Inc. Code Attribute

Slide 99

Slide 99 text

© - BASE, Inc. Code Attribute

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

© - BASE, Inc. ClassFile Structure Code Attribute 1 Constant Pool

Slide 103

Slide 103 text

1

Slide 104

Slide 104 text

javap

Slide 105

Slide 105 text

© - BASE, Inc. javap 


Slide 106

Slide 106 text

© - BASE, Inc. javap 
 main main #

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

© - BASE, Inc. (java.lang.Object) main System.out.println Hello World!

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

© - BASE, Inc. : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . χʔϞχοΫ Φϖίʔυ ໾ׂ getstatic 0xB2 Get static field from class ldc 0x12 Push item from run-time constant pool invokevirtual 0xB6 Invoke instance method; dispatch based on class return 0xB1 Return void from method

Slide 111

Slide 111 text

© - BASE, Inc. : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . 
 χʔϞχοΫ Φϖίʔυ ໾ׂ getstatic 0xB2 ੩తϑΟʔϧυΛऔಘͯ͠ɺΦϖϥϯυελοΫʹੵΈ·͢ɻ ldc 0x12 Constant Pool ͔Β஋Λऔಘͯ͠ɺΦϖϥϯυελοΫʹੵΈ·͢ɻ invokevirtual 0xB6 ΦϖϥϯυελοΫͷ஋ΑΓɺΫϥε্ʹ͓͚ΔϝιουΛ࣮ߦ͠·͢ return 0xB1 void Λฦ͠·͢ɻPHP ͸੍໿͕͋Γɺ return; ͱͯ͠΋ null Λฦ͢࢓༷Ͱ͢

Slide 112

Slide 112 text

© - BASE, Inc. (Operand Stack) JVM JVM PHPer array_push 
 array_pop

Slide 113

Slide 113 text

No content

Slide 114

Slide 114 text

© - BASE, Inc. public static main (String[]) main 
 ( ) ldc invokevirtual return getstatic

Slide 115

Slide 115 text

© - BASE, Inc. public static main (String[]) main 
 ( ) getstatic ldc invokevirtual return System.out 


Slide 116

Slide 116 text

© - BASE, Inc. public static main (String[]) main 
 ( ) ldc invokevirtual return getstatic java.lang.String (Hello World)

Slide 117

Slide 117 text

© - BASE, Inc. public static main (String[]) main 
 ( ) getstatic ldc invokevirtual return System.out 
 Hello World

Slide 118

Slide 118 text

© - BASE, Inc. public static main (String[]) main 
 ( ) getstatic ldc invokevirtual return void 
 PHP void

Slide 119

Slide 119 text

Code Attribute

Slide 120

Slide 120 text

© - BASE, Inc. Code Attribute main 16 B B B

Slide 121

Slide 121 text

© - BASE, Inc. Code Attribute main 16 B B B getstatic getstatic (Constant Pool 2 )

Slide 122

Slide 122 text

© - BASE, Inc. Code Attribute main 16 B B B ldc ldc (Constant Pool 3 )

Slide 123

Slide 123 text

© - BASE, Inc. Code Attribute main 16 B B B invokevirtual invokevirtual (Constant Pool 4 )

Slide 124

Slide 124 text

© - BASE, Inc. Code Attribute main 16 B B B return

Slide 125

Slide 125 text

PHP

Slide 126

Slide 126 text

No content

Slide 127

Slide 127 text

© - BASE, Inc. PHP

Slide 128

Slide 128 text

getstatic

Slide 129

Slide 129 text

© - BASE, Inc. getstatic getstatic 2 (operand[ ] << ) | operand[ ] unsigned short Constant Pool Constant Pool Operand Stack 
 PHP unsigned short unpack 
 PHP 
 PHP unsigned short v n 
 n : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic

Slide 130

Slide 130 text

© - BASE, Inc. getstatic : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic

Slide 131

Slide 131 text

© - BASE, Inc. getstatic : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic 2 unsigned short

Slide 132

Slide 132 text

© - BASE, Inc. getstatic : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic java.lang.System Constant Pool

Slide 133

Slide 133 text

© - BASE, Inc. getstatic : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic out Constant Pool

Slide 134

Slide 134 text

© - BASE, Inc. getstatic : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic out Constant Pool PrintStream out

Slide 135

Slide 135 text

© - BASE, Inc. getstatic : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic java/lang/System PHP 
 java\lang\System

Slide 136

Slide 136 text

© - BASE, Inc. getstatic : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic

Slide 137

Slide 137 text

ldc

Slide 138

Slide 138 text

© - BASE, Inc. ldc ldc 1 Constant Pool int, float, , ldc ldc_w ldc _w : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic

Slide 139

Slide 139 text

© - BASE, Inc. ldc : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic

Slide 140

Slide 140 text

© - BASE, Inc. ldc : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic 1 
 Constant Pool

Slide 141

Slide 141 text

© - BASE, Inc. ldc : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic Constant Pool 
 Constant Pool 
 Constant Pool Hello World

Slide 142

Slide 142 text

© - BASE, Inc. ldc : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic Hello World

Slide 143

Slide 143 text

invokevirtual

Slide 144

Slide 144 text

© - BASE, Inc. invokevirtual invokevirtual invokevirtual 
 invoke php-java 
 invokevirtual 2 Constant Pool descriptor_index 範 
 : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .invokevirtual

Slide 145

Slide 145 text

© - BASE, Inc. invokevirtual invokevirtual Hello World 


Slide 146

Slide 146 text

© - BASE, Inc. invokevirtual invokevirtual Hello World 
 2

Slide 147

Slide 147 text

© - BASE, Inc. invokevirtual : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic invokevirtual Hello World 
 
 NameAndType Structure

Slide 148

Slide 148 text

© - BASE, Inc. invokevirtual invokevirtual Hello World 
 
 ;

Slide 149

Slide 149 text

© - BASE, Inc. invokevirtual invokevirtual Hello World 
 
 1 範

Slide 150

Slide 150 text

© - BASE, Inc. invokevirtual invokevirtual Hello World 


Slide 151

Slide 151 text

© - BASE, Inc. invokevirtual invokevirtual Hello World 
 java/lang/System.out.println

Slide 152

Slide 152 text

java/lang/System.out.println

Slide 153

Slide 153 text

No content

Slide 154

Slide 154 text

java\lang\System.out

Slide 155

Slide 155 text

© - BASE, Inc. java\lang\System.out : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic $out PrintStream 
 PHP 


Slide 156

Slide 156 text

java\io\PrintStream.println

Slide 157

Slide 157 text

© - BASE, Inc. java\io\PrintStream.println : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic java\lang\System.out PrintStream 
 PrintStream

Slide 158

Slide 158 text

php

Slide 159

Slide 159 text

© - BASE, Inc. php DEMONSTRATION

Slide 160

Slide 160 text

Hello World

Slide 161

Slide 161 text

return

Slide 162

Slide 162 text

© - BASE, Inc. return return void PHP void return ireturn, freturn, areturn dreturn monitorexit 
 : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .return

Slide 163

Slide 163 text

© - BASE, Inc. return : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic return

Slide 164

Slide 164 text

© - BASE, Inc. return : https://docs.oracle.com/javase/specs/jvms/se /html/jvms- .html#jvms- . .getstatic return while break 
 PHP break continue 


Slide 165

Slide 165 text

Hello World

Slide 166

Slide 166 text

THANK YOU FOR YOUR LISTENING