HHVM

Last updated

HHVM
Developer(s) Meta Platforms
Initial releaseDecember 9, 2011;11 years ago (2011-12-09) [1]
Stable release
4.172.0 [2] [3]   OOjs UI icon edit-ltr-progressive.svg / 2 November 2022;12 months ago (2 November 2022)
Repository
Written in PHP, C++, [4] OCaml [5] [lower-alpha 1] and Rust [6]
License PHP License and Zend License [7]
Website hhvm.com OOjs UI icon edit-ltr-progressive.svg

HipHop Virtual Machine (HHVM) is an open-source virtual machine based on just-in-time (JIT) compilation that serves as an execution engine for the Hack programming language. By using the principle of JIT compilation, Hack code is first transformed into intermediate HipHop bytecode (HHBC), which is then dynamically translated into x86-64 machine code, optimized, and natively executed. [8] [9] This contrasts with PHP's usual interpreted execution, in which the Zend Engine transforms PHP source code into opcodes that serve as a form of bytecode, and executes the opcodes directly on the Zend Engine's virtual CPU. [10]

Contents

HHVM is developed by Meta, with the project's source code hosted on GitHub; [11] it is licensed under the terms of the PHP License and Zend License. [1] [7]

Overview

HHVM was created as the successor to the HipHop for PHP (HPHPc) PHP execution engine, which is a PHP-to-C++ transpiler also created by Facebook. [12] [13] Based on the gained experience and aiming to solve issues introduced by HPHPc, Meta decided in early 2010 to create a JIT-based PHP virtual machine. Issues associated with HPHPc included reaching a plateau for further performance improvements, a fundamental inability to support all features of the PHP language, and difficulties arising from specific time- and resource-consuming development and deployment processes. [12] In Q1 2013, the production version of the facebook.com website stopped using HPHPc and switched to HHVM.

Following the JIT compilation principle, HHVM first converts the executed code into an intermediate language, the high-level bytecode HHBC. HHBC is a bytecode format created specifically for HHVM, appropriate for consumption by both interpreters and just-in-time compilers. Next, HHVM dynamically ("just-in-time") translates the HHBC into x86-64 machine code, optimized through dynamic analysis of the translated bytecode. Finally, it executes the x86-64 machine code. [1] [12] [14] As a result, HHVM has certain similarities to the virtual machines used by other programming languages, including the Common Language Runtime (CLR, for the C# language) and Java virtual machine (JVM, for the Java language).

HHVM brings many benefits in comparison with HPHPc. HHVM uses the same execution engine when deployed in both production and development environments, while supporting integration between the execution engine and the HPHPd debugger in both environment types; as a result, maintaining HPHPi (HipHop interpreter) separately as a development utility is no longer needed as it was the case with HPHPc. HHVM also eliminates the lengthy builds required by HPHPc to run programs, resulting in much simpler development and deployment processes than it was the case with HPHPc. [1] Finally, versions of HHVM before 4.0 have almost complete support for the entire PHP language (as defined by the official implementation of PHP version 5.4), including the support for the create_function() and eval() constructs, which was impossible with HPHPc. [15] [16]

Together with HHVM 3.0, [17] Meta also released Hack, a derivative of PHP [18] [19] that allows programmers to use both dynamic typing and static typing (a concept also known as gradual typing), and allows types to be specified for function arguments, function return values, and class properties. However, Hack does not provide complete backward compatibility since it removes several PHP features, such as the goto statement and dynamic variable names. [20] [21] [22] [23]

In September 2017, it was announced that version 3.30 would be the last version of HHVM to officially support PHP, and that HHVM will only support Hack going forward. [24] This was due to differences and incompatibilities in PHP 7. [25] HHVM 4.0, released in February 2019, was the first version without support for PHP. [26]

Performance

As a process virtual machine that provides the execution environment, HHVM has the ability to use live type information to produce more efficient native code, leading to a higher web server throughput and lower latency. In Q4 2012, the execution of facebook.com's source code on HHVM achieved performance parity with HPHPc, [12] and in December 2013 HPHPc was even surpassed by around 15%. [27]

See also

Notes

  1. Only the Hack's type-checking (hh_server and hh_client) and code-formatting (hh_format) command-line utilities and daemons bundled together with the HipHop Virtual Machine are written in OCaml.

Related Research Articles

<span class="mw-page-title-main">Java virtual machine</span> Virtual machine that runs Java programs

A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes what is required in a JVM implementation. Having a specification ensures interoperability of Java programs across different implementations so that program authors using the Java Development Kit (JDK) need not worry about idiosyncrasies of the underlying hardware platform.

<span class="mw-page-title-main">PHP</span> Scripting language created in 1994

PHP is a general-purpose scripting language geared towards web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by the PHP Group. PHP was originally an abbreviation of Personal Home Page, but it now stands for the recursive initialism PHP: Hypertext Preprocessor.

OCaml is a general-purpose, high-level, multi-paradigm programming language which extends the Caml dialect of ML with object-oriented features. OCaml was created in 1996 by Xavier Leroy, Jérôme Vouillon, Damien Doligez, Didier Rémy, Ascánder Suárez, and others.

<span class="mw-page-title-main">Interpreter (computing)</span> Program that executes source code without a separate compilation step

In computer science, an interpreter is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program. An interpreter generally uses one of the following strategies for program execution:

  1. Parse the source code and perform its behavior directly;
  2. Translate source code into some efficient intermediate representation or object code and immediately execute that;
  3. Explicitly execute stored precompiled bytecode made by a compiler and matched with the interpreter Virtual Machine.

Parrot is a discontinued register-based process virtual machine designed to run dynamic languages efficiently. It is possible to compile Parrot assembly language and Parrot intermediate representation to Parrot bytecode and execute it. Parrot is free and open-source software.

Bytecode is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references that encode the result of compiler parsing and performing semantic analysis of things like type, scope, and nesting depths of program objects.

In computing, just-in-time (JIT) compilation is compilation during execution of a program rather than before execution. This may consist of source code translation but is more commonly bytecode translation to machine code, which is then executed directly. A system implementing a JIT compiler typically continuously analyses the code being executed and identifies parts of the code where the speedup gained from compilation or recompilation would outweigh the overhead of compiling that code.

<span class="mw-page-title-main">QEMU</span> Free virtualization and emulation software

QEMU is a free and open-source emulator. It emulates a computer's processor through dynamic binary translation and provides a set of different hardware and device models for the machine, enabling it to run a variety of guest operating systems. It can interoperate with Kernel-based Virtual Machine (KVM) to run virtual machines at near-native speed. QEMU can also do emulation for user-level processes, allowing applications compiled for one architecture to run on another.

In computer science, ahead-of-time compilation is the act of compiling an (often) higher-level programming language into an (often) lower-level language before execution of a program, usually at build-time, to reduce the amount of work needed to be performed at run time.

The Berkeley Packet Filter (BPF) is a technology used in certain computer operating systems for programs that need to, among other things, analyze network traffic. It provides a raw interface to data link layers, permitting raw link-layer packets to be sent and received. In addition, if the driver for the network interface supports promiscuous mode, it allows the interface to be put into that mode so that all packets on the network can be received, even those destined to other hosts.

<span class="mw-page-title-main">V8 (JavaScript engine)</span> Open-source JavaScript and WebAssembly engine developed by Google

V8 is a free and open-source JavaScript and WebAssembly engine developed by the Chromium Project for Chromium and Google Chrome web browsers. The project's creator is Lars Bak. The first version of the V8 engine was released at the same time as the first version of Chrome: 2 September 2008. It has also been used on the server side, for example in Couchbase, Deno and Node.js.

HipHop for PHP (HPHPc) is a discontinued PHP transpiler created by Facebook. By using HPHPc as a source-to-source compiler, PHP code is translated into C++, compiled into a binary and run as an executable, as opposed to the PHP's usual execution path of PHP code being transformed into opcodes and interpreted. HPHPc consists mainly of C++, C and PHP source codes, and it is free and open-source software distributed under the PHP License.

<span class="mw-page-title-main">GraalVM</span>

GraalVM is a Java Development Kit (JDK), written in Java. The open-source distribution of GraalVM is based on OpenJDK, and the enterprise distribution is based on Oracle JDK. As well as just-in-time (JIT) compilation, GraalVM can compile a Java application ahead-of-time so that it starts instantly, provides peak performance with no warmup, and uses fewer resources. It provides additional programming languages and execution modes. The first production-ready release, GraalVM 19.0, was distributed in May 2019. The most recent release is GraalVM for JDK 21, made available in September 2023.

XHP is an augmentation of PHP and Hack developed at Meta to allow XML syntax for the purpose of creating custom and reusable HTML elements. It is available as an open-source software GitHub project and as a Homebrew module for PHP 5.3, 5.4, and 5.5. Meta also developed a similar augmentation for JavaScript, named JSX.

Hack is a programming language for the HipHop Virtual Machine (HHVM), created by Meta as a dialect of PHP. The language implementation is open-source, licensed under the MIT License.

<span class="mw-page-title-main">WebAssembly</span> Cross-platform assembly language and bytecode designed for execution in web browsers

WebAssembly defines a portable binary-code format and a corresponding text format for executable programs as well as software interfaces for facilitating interactions between such programs and their host environment.

<span class="mw-page-title-main">PeachPie</span>

PeachPie is an open-source PHP language compiler and runtime for the .NET Framework and .NET. It is built on top of the Microsoft Roslyn compiler platform and is based on the first-generation Phalanger project. PeachPie compiles source code written in PHP to CIL byte-code. PeachPie takes advantage of the JIT compiler component of the .NET Framework in order to handle the beginning of the compilation process. Its purpose is not to generate or optimize native code, but rather to compile PHP scripts into .NET assemblies containing CIL code and meta-data. In July 2017, the project became a member of the .NET Foundation.

References

  1. 1 2 3 4 Jason Evans (December 9, 2011). "The HipHop Virtual Machine". Meta Platforms . Retrieved August 2, 2014.
  2. "HHVM 4.172, HHVM Blog".
  3. "HHVM-4.172.0 tag, GitHub".
  4. "Building and installing HHVM on CentOS 7.x". github.com. Meta Platforms. May 26, 2015. Retrieved June 12, 2015.
  5. "Building the Hack typechecker". github.com. Meta. September 10, 2014. Retrieved June 12, 2015.
  6. "Facebook's HHVM Begins Seeing Rust Rewrite - Phoronix" . Retrieved August 29, 2019.
  7. 1 2 "facebook/hhvm: License". github.com. Facebook, Inc. Retrieved August 2, 2014.
  8. Ottoni, Guilherme (June 20, 2018). "HHVM JIT: A Profile-Guided, Region-Based Compiler for PHP and Hack". Proceedings of the 39th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). ACM. pp. 151–165.
  9. "facebook/hhvm". github.com. Meta Platforms. Retrieved August 2, 2014.
  10. Kaushik Pal (April 28, 2014). "PHP and Zend Engine Internals". phpbuilder.com. Archived from the original on September 15, 2014. Retrieved September 23, 2014.
  11. HHVM source code on GitHub
  12. 1 2 3 4 Drew Paroski (November 29, 2012). "Speeding up PHP-based development with HHVM". Meta Platforms . Retrieved August 2, 2014.
  13. "Announcement on GitHub removing HPHPc support". github.com. Meta Platforms. February 19, 2013. Retrieved May 24, 2013.
  14. "HipHop Bytecode v1 revision 18". github.com. Meta Platforms. July 31, 2014. Retrieved May 24, 2013.
  15. "facebook/hhvm: About upgrade to PHP 5.4 engine". github.com. May 2013. Retrieved August 2, 2014.
  16. "facebook/hhvm: Home". github.com. Meta Platforms. May 8, 2014. Retrieved August 2, 2014.
  17. Paul Tarjan (March 28, 2014). "HHVM 3.0.0". Facebook . Retrieved December 26, 2022.
  18. Cade Metz (March 20, 2014). "Facebook Introduces 'Hack,' the Programming Language of the Future". Wired . Retrieved April 15, 2014.
  19. Julien Verlaguet; Alok Menghrajani (April 2014). "Hack: a new programming language for HHVM". code.facebook.com. Facebook . Retrieved March 23, 2014.
  20. Josh Lockhart (April 3, 2014). "Facebook's Hack, HHVM, and the future of PHP". O'Reilly Media . Retrieved August 2, 2014.
  21. "Hack and HHVM: Type Annotations (Hack Manual)". docs.hhvm.com. Retrieved March 25, 2014.
  22. "Hack and HHVM: Type Inference (Hack Manual)". docs.hhvm.com. Archived from the original on March 26, 2014. Retrieved March 25, 2014.
  23. "Hack and HHVM: Unsupported PHP Features in Hack (Hack Manual)". docs.hhvm.com. Archived from the original on November 4, 2015. Retrieved April 2, 2014.
  24. Fred Emmott (September 12, 2018). "Ending PHP Support, and The Future Of Hack" . Retrieved December 26, 2022.
  25. Krill, Paul (September 20, 2017). "Forget PHP! Facebook's HHVM engine switches to Hack instead". InfoWorld. Retrieved February 6, 2019.
  26. Fred Emmott (February 11, 2019). "HHVM 4.0.0" . Retrieved December 26, 2022.
  27. "We are the 98.5% (and the 16%)". hhvm.com. December 19, 2013. Retrieved August 2, 2014.