PHP Presentation to JVM Languages summit

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    PHP Presentation to JVM Languages summit - Presentation Transcript

    1. P8, IBM’s PHP on Java Virtual Machine TM Project Rob Nicholson [email_address]
    2. Why Build PHP on the JVM?
      • 20M+ web domains use PHP
      • 3M+ Programmers know PHP
      • Huge repository of reusable modules, snippets, extensions.
      • Easy language to learn -> Mashups
      • Language has evolved to be easy to use
      TIOBE Programming Community Index (Sep 2008)
      • Same-process interaction Java <-> PHP.
      • Combine Java and PHP assets.
      • Combine Java and PHP programmers.
        • Data sharing without copies.
        • Extend Java with PHP.
      • Benefit from vast investment in Java VM
      • IBM WebSphere sMash has Groovy +P8
    3. What is PHP?
      • Procedural and OO language.
      • Engine and Extensions Implemented in C.
      • Frameworks, Modules, Applications implemented in PHP.
      • Large and active open source communities.
      Apache HTTP server Zend Engine Virtual Machine C Extensions Scripts Modules Frameworks Applications Databases
      • No specification
      • Incomplete documentation
      • Incomplete tests
      • No Unicode
      • Reference Implementation based language
    4. What is P8?
      • PHP 5 on Java 5 SE or later.
      • Hand crafted lexer, LPG generated parser.
      • Started as Interpreter -> transitioning to compiler.
        • Maintain the illusion of interpreter.
      • Extensibility via XAPI
        • XAPI-C for C extensions from php.net
        • XAPI-J for Java extensions, native libraries invoked over JNI and Project Zero interface
      • Java Bridge
        • Extend Java classes in PHP.
        • Implement Java Interfaces in PHP.
        • PHP proxies over Java Classes
      • Debug using via DBGp using Eclipse with PDT
      P8 Runtime PHP Scripts CLI SAPI-J PZ Http Parser Interpreter/Compiler Runtime PHP Engine Java Extensions C Extensions Cache IR XAPI-J XAPI-C Native code Debug (DBGp)
    5. How applications are supported. Zend Engine 2 ZE2 Extension interface file string pcre DOM App1 App2 App3 App4 PHP.net P8 file string pcre DOM App1 App2 App3 App4 XAPI-J todo XAPI-C todo ZE2 Extension interface sMash Apps depend on extensions which depend on ZE2 interfaces Array Array
    6. PHP Characteristics
      • Nothing persists request to request
      • Dynamic runtime inclusion:
        • Many versions of function foo() or class bar
          • In scope version depends on includes at runtime
      • Dynamically declared/used symbols
        • Function/classes are conditionally declared
        • Variables may indirectly referred using string values
      • Both copy semantics and references allowed
        • Arrays and strings are copied for each assignment to any variable
        • References can be created and used almost transparently
      • Heavy use of foreign language functions
        • Heavy calculations are often done in libraries written in C/C++
        • So-called extensions written in C help PHP’s rich language constructs
      • OO PHP becoming popular
        • ~ 10x slower than equivalent Java
      • Functions of unconstrained length
        • Exceed JVM method length limit
    7. Typical PHP inc1.php: <?php include “inc1.php”; $var=1; foo (“bar.php”,$var); include $var; ?> index.php: <?php function foo($a, &$b) { $b=$a; } ?>
    8. PHP Request Processing. Program state Request functions classes constants Global variables Objects Execute includes
    9. Shared nothing architecture
    10. Compiling PHP Functions.
      • Every function creates a class with single known method.
      public class Bytecode1_rob_php extends AbstractBytecode { public PHPValue run(Runtime runtime) { // currently still fetching arguments interpreter style return null; } }
      • Function table is Hash “Name”=>Invocable
      • Invoke using InvokeVirtual
        • Use receiver to select which function to invoke.
    11. Function Invoke w/o methodHandles <?php function foo(){} foo(); bar(); ?> public class Bytecode1_rob_php extends AbstractBytecode { private static Invocable invocable1 ; private Invocable invocable2; public PHPValue run(Runtime runtime) { if ( invocable1 == null ) invocable1 = Op. jhGetInvocable (runtime, “foo” ); Op. jhCALL ( null , invocable1 , runtime, true ); // PHPValue returnVal = invocable1.bytecode.run(runtime); if ( invocable2 == null ) invocable2 = Op. jhGetInvocable (runtime, “bar” ); Op. jhCALL ( null , invocable2 , runtime, true ); // PHPValue returnVal = invocable2.bytecode.run(runtime ); return null ; } }
    12. JSR292
      • Initially use MethodHandles to avoid creating separate class for every PHP function.
      • Not yet clear that InvokeDynamic helps for PHP Function Invocation.
      • Will use InvokeDynamic for PHP method invocation.
    13. PHPValue
      • PHP native VM heavily exploits ability to change types at runtime.
      • PHP values change types during arithmetic.
      • PHP retains references to values.
        • Hard to devise efficient Value representation w/o ability to change class of object at runtime.
      • Currently we use indirection to resolve.
        • Creates heap pressure.
    14. Unicode PHP Engine Java Extensions C Extensions XAPI-J XAPI-C j.l.S byte[] PHP String
      • In PHP5, a string is a sequence of bytes.
      • App programmer knows encoding (if any)
      • So….Strings hold characters AND jpegs.
      • Runtime does not know the difference.
      • P8 wants to deal seamlessly with Java Libraries.
      • C extensions from PHP.net use byte[].
      BUT
      • P8 PHPString can be either j.l.S or byte[]
      • On demand conversion using runtime encoding.
      • Comparisons coerce byte[] to j.l.S iff no decoding errors.
      SO
    15. Questions…?

    + Robert NicholsonRobert Nicholson, 11 months ago

    custom

    644 views, 0 favs, 0 embeds more stats

    This was a talk given at the Sun JVM Languages summ more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 644
      • 644 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 17
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories