HipHop Virtual Machine (HHVM) is an
open-source
Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use and view the source code, design documents, or content of the product. The open source model is a decentrali ...
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
x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit extension of the x86 instruction set architecture, instruction set. It was announced in 1999 and first available in the AMD Opteron family in 2003. It introduces two new ope ...
machine code
In computer programming, machine code is computer code consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). For conventional binary computers, machine code is the binaryOn nonb ...
, optimized, and natively executed. This contrasts with PHP's usual
interpreted execution, in which the
Zend Engine
The Zend Engine is a compiler and runtime environment for the PHP scripting language and consists of the Zend Virtual Machine, which is composed of the Zend Compiler and the Zend Executor, that compiles and executes the PHP code. It was origi ...
transforms PHP
source code
In computing, source code, or simply code or source, is a plain text computer program written in a programming language. A programmer writes the human readable source code to control the behavior of a computer.
Since a computer, at base, only ...
into
opcode
In computing, an opcode (abbreviated from operation code) is an enumerated value that specifies the operation to be performed. Opcodes are employed in hardware devices such as arithmetic logic units (ALUs), central processing units (CPUs), and ...
s that serve as a form of
bytecode
Bytecode (also called portable code or p-code) 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 (normal ...
, and executes the opcodes directly on the Zend Engine's virtual
CPU.
HHVM is developed by
Meta, with the project's source code hosted on
GitHub
GitHub () is a Proprietary software, proprietary developer platform that allows developers to create, store, manage, and share their code. It uses Git to provide distributed version control and GitHub itself provides access control, bug trackin ...
; it is licensed under the terms of the
PHP License
The ''PHP License'' is the open-source license under which the PHP scripting language is released. The PHP License is designed to encourage widespread adoption of the source code. Redistribution is permitted in source or binary form with or ...
and
Zend License.
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.
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
In computing, a virtual machine (VM) is the virtualization or emulator, emulation of a computer system. Virtual machines are based on computer architectures and provide the functionality of a physical computer. Their implementations may involve ...
. Issues associated with HPHPc included reaching a
plateau
In geology and physical geography, a plateau (; ; : plateaus or plateaux), also called a high plain or a tableland, is an area of a highland consisting of flat terrain that is raised sharply above the surrounding area on at least one side. ...
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.
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
An intermediate representation (IR) is the data structure or code used internally by a compiler or virtual machine to represent source code. An IR is designed to be conducive to further processing, such as optimization and translation. A "good" ...
, the high-level
bytecode
Bytecode (also called portable code or p-code) 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 (normal ...
HHBC. HHBC is a bytecode format created specifically for HHVM, appropriate for consumption by both
interpreters
Interpreting is translation from a spoken or signed language into another language, usually in real time to facilitate live communication. It is distinguished from the translation of a written text, which can be more deliberative and make use o ...
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.
As a result, HHVM has certain similarities to the virtual machines used by other programming languages, including the
Common Language Runtime
The Common Language Runtime (CLR), the virtual machine component of Microsoft .NET Framework, manages the execution of .NET programs. Just-in-time compilation converts the managed code (compiled intermediate language code) into machine instr ...
(CLR, for the
C# language) and
Java virtual machine
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 descr ...
(JVM, for the
Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
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
A debugger is a computer program used to test and debug other programs (the "target" programs). Common features of debuggers include the ability to run or halt the target program using breakpoints, step through code line by line, and display ...
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.
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.
Together with HHVM 3.0, Meta also released
Hack
Hack may refer to:
Arts, entertainment, and media Games
* Hack (Unix video game), ''Hack'' (Unix video game), a 1984 roguelike video game
* .hack (video game series), ''.hack'' (video game series), a series of video games by the multimedia fran ...
, a derivative of PHP that allows programmers to use both
dynamic typing
In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a ''type'' (for example, integer, floating point, string) to every '' term'' (a word, phrase, or other set of symbols). Usu ...
and
static typing
In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a ''type'' (for example, integer, floating point, string) to every '' term'' (a word, phrase, or other set of symbols). Usu ...
(a concept also known as
gradual typing), and allows
types
Type may refer to:
Science and technology Computing
* Typing, producing text via a keyboard, typewriter, etc.
* Data type, collection of values used for computations.
* File type
* TYPE (DOS command), a command to display contents of a file.
* Ty ...
to be specified for
function arguments
An argument is a series of sentences, statements, or propositions some of which are called premises and one is the conclusion. The purpose of an argument is to give reasons for one's conclusion via justification, explanation, and/or persua ...
, function
return value
In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after the instruction which called the subroutine, known as its return address. The return address is sav ...
s, and
class properties
In object-oriented programming, a class defines the shared aspects of objects created from the class. The capabilities of a class differ between programming languages, but generally the shared aspects consist of state ( variables) and behavior ( ...
. However, Hack does not provide complete
backward compatibility
In telecommunications and computing, backward compatibility (or backwards compatibility) is a property of an operating system, software, real-world product, or technology that allows for interoperability with an older legacy system, or with Input ...
since it removes several PHP features, such as the
goto
statement and dynamic
variable names.
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. This was due to differences and incompatibilities in PHP 7. HHVM 4.0, released in February 2019, was the first version without support for PHP.
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
In computer programming, machine code is computer program, computer code consisting of machine language instruction set architecture, instructions, which are used to control a computer's central processing unit (CPU). For conventional binary ...
, leading to a higher web server
throughput
Network throughput (or just throughput, when in context) refers to the rate of message delivery over a communication channel in a communication network, such as Ethernet or packet radio. The data that these messages contain may be delivered ov ...
and lower
latency. In Q4 2012, the execution of facebook.com's
source code
In computing, source code, or simply code or source, is a plain text computer program written in a programming language. A programmer writes the human readable source code to control the behavior of a computer.
Since a computer, at base, only ...
on HHVM achieved performance parity with HPHPc,
and in December 2013 HPHPc was even surpassed by around 15%.
See also
*
LLVM
LLVM, also called LLVM Core, is a target-independent optimizer and code generator. It can be used to develop a Compiler#Front end, frontend for any programming language and a Compiler#Back end, backend for any instruction set architecture. LLVM i ...
*
Parrot 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 (PIR, an intermediate language) to Parr ...
*
Phalanger
Notes
References
External links
*
{{Facebook navbox
2011 software
C++ software
Rust (programming language) software
Facebook software
Free and open source compilers
OCaml software
PHP software
Software using the PHP license
Stack-based virtual machines
Bytecodes