- PHPerKaigi 2020
- English Title: Implement JVM with PHP and try to output Hello World
/ / PHPerKaigiPHP JVM HelloWorld© - BASE, Inc.
View Slide
© - BASE, Inc.Who am I?(@m m r )BASE6SDVX
© - BASE, Inc.Who am I?
© - BASE, Inc.PHPerKaigi Builderscon
© - BASE, Inc.php-java/php-java
OSS
© - BASE, Inc.JVMPHP
© - BASE, Inc.Hello World
JVM
© - BASE, Inc.JVMJVM Java Virtual MachineJavaJVMJRE JDK
exec('java HelloWorld')
© - BASE, Inc.JVMJavaclassclassJVM
© - BASE, Inc.JVMJVM Java Virtual MachineSpecification Oracle
© - BASE, Inc.JVM
© - BASE, Inc.JVMJava class
© - BASE, Inc.JVMclass
© - BASE, Inc.PerlPHPJavaScript/BuildersconYAPC::KyotoPHPerKaigiQiitaJVM
© - BASE, Inc.RustEmacsGoRubyrchasergongoZDQNEODaiki MiuraJVM
JVM,
PHP
© - BASE, Inc.fopen /fread OK
© - BASE, Inc.16short, unsigned short, integer,unsigned integerpack / unpackJVM
© - BASE, Inc.PHPint (- ^ ^ - )boolstringfloat, doublearraynulletc...
Java
© - BASE, Inc.Javabytecharshort (- ^ ^ - )int (- ^ ^ - )long (- ^ ^ - )booleanfloatdouble
PHP Java
© - BASE, Inc.( )JVM invokevirtual iload / istore
Hello World
Java Virtual Machine Specification
© - BASE, Inc.JVM SpecJava Virtual Machine SpecificationJVM SpecJVM Spec Oracle JVMhttps://docs.oracle.com/javase/specs/index.html
ClassFile Structure
© - BASE, Inc.ClassFile Structure
© - BASE, Inc.JVM Specu unsigned intu unsigned short
© - BASE, Inc.Constant Pool MethodInfo Code AttributeHello World
Method Info
© - BASE, Inc.Method Info
Code Attribute
© - BASE, Inc.Code Attribute
© - BASE, Inc.JVM Speccode[code_length]JVM Spec
© - BASE, Inc.java.lang.System.outgetstaticprintlninvokevirtual
© - BASE, Inc.Constant Poolldcreturn
4
getstatic
© - BASE, Inc.getstaticgetstaticgetstatic Constant Poolunsigned short
© - BASE, Inc.getstaticgetstatic <0xB >putstatic
© - BASE, Inc.getstatic
invokevirtual
© - BASE, Inc.invokevirtualinvokevirtualConstant Pool
© - BASE, Inc.invokevirtualinvokevirtual <0xB >invoke dynamic, special, interface,static
© - BASE, Inc.invokevirtualinvoke JVMinvokeinvokedynamicinvokeinterface
© - BASE, Inc.invokevirtual
© - BASE, Inc.invokevirtualvoid
ldc
© - BASE, Inc.ldcldc Constant Pool UTFInteger, short, byteConstantPool unsigned byte
© - BASE, Inc.ldcldcLong Double
© - BASE, Inc.ldc
© - BASE, Inc.ldcConstant Pool
return
© - BASE, Inc.returnreturnvoidmoniterenterreturn areturn, ireturn,freturn, dreturn
© - BASE, Inc.Hello WorldB NN MM NN B NN MM B
© - BASE, Inc.Hello WorldB NN MM NN B NN MM Bgetstatic
© - BASE, Inc.Hello WorldB NN MM NN B NN MM Bunsigned short
© - BASE, Inc.Hello WorldB NN MM NN B NN MM Bldc
© - BASE, Inc.Hello WorldB NN MM NN B NN MM Bunsigned byteHello WorldConstant Pool
© - BASE, Inc.Hello WorldB NN MM NN B NN MM Binvokevirtual
© - BASE, Inc.Hello WorldB NN MM NN B NN MM Bunsigned shortConstant Pool
© - BASE, Inc.Hello WorldB NN MM NN B NN MM Breturn
"java.lang.System"
© - BASE, Inc."java.lang.System"Java java.lang.SystemPHP"java\lang\System"System"out"
© - BASE, Inc."java.lang.System";
"out"
© - BASE, Inc."out"PHP JVM static
© - BASE, Inc."out"
"println""java.io.PrintStream"
© - BASE, Inc."java.io.PrintStream"
DEMO
THANK YOU FOR YOUR LISTENING