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 the source code, design documents, or content of the product. The open-source model is a decentralized so ...
virtual machine based on
just-in-time (JIT) compilation that serves as an execution engine for the
Hack programming language and used to support
PHP execution before the release of HHVM version 4. 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 version of the x86 instruction set, first released in 1999. It introduced two new modes of operation, 64-bit mode and compatibility mode, along with a new 4-level paging ...
machine code, optimized, and natively executed. This contrasts with PHP's usual
interpreted execution, in which the
Zend Engine transforms PHP
source code
In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the ...
into
opcode
In computing, an opcode (abbreviated from operation code, also known as instruction machine code, instruction code, instruction syllable, instruction parcel or opstring) is the portion of a machine language instruction that specifies the operat ...
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 (norma ...
, and executes the opcodes directly on the Zend Engine's virtual
CPU
A central processing unit (CPU), also called a central processor, main processor or just processor, is the electronic circuitry that executes instructions comprising a computer program. The CPU performs basic arithmetic, logic, controlling, a ...
.
HHVM is developed by
Meta
Meta (from the Greek μετά, '' meta'', meaning "after" or "beyond") is a prefix meaning "more comprehensive" or "transcending".
In modern nomenclature, ''meta''- can also serve as a prefix meaning self-referential, as a field of study or end ...
, with the project's source code hosted on
GitHub
GitHub, Inc. () is an Internet hosting service for software development and version control using Git. It provides the distributed version control of Git plus access control, bug tracking, software feature requests, task management, cont ...
; it is licensed under the terms of the
PHP License and
Zend License.
Overview
HHVM was created as the successor to the
HipHop for PHP
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 executi ...
(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/ emulation of a computer system. Virtual machines are based on computer architectures and provide functionality of a physical computer. Their implementations may involve specialized h ...
. Issues associated with HPHPc included its reaching of a
plateau
In geology and physical geography, a plateau (; ; ), 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. Often one or more sides ...
for further performance improvements, lack of full support for all features of the PHP language, and difficulties arising from specific time- and resource-consuming development and deployment processes required for PHP projects that used HPHPc.
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 PHP or Hack code into a 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 (norma ...
, HHBC, which is also known as an
intermediate language. HHBC is a bytecode format created specifically for HHVM, in a form that is appropriate for consumption by both
interpreters
Interpreting is a translational activity in which one produces a first and final target-language output on the basis of a one-time exposure to an expression in a source language.
The most common two modes of interpreting are simultaneous interp ...
and just-in-time compilers. As the next steps in execution, HHVM dynamically ("just-in-time") translates the HHBC bytecode into x86-64 machine code, performs its additional
optimizations through a dynamic analysis of the translated bytecode, and 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 instru ...
(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 describe ...
(JVM, for the
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mo ...
language).
HHVM brings many benefits in comparison with HPHPc, and one of them is almost complete support for the entire PHP language as defined by the official implementation of PHP version 5.4, including the HHVM's support for
create_function()
and
eval()
constructs. Furthermore, 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 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 ...
(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 PHP programs, resulting in much simpler development and deployment processes than it was the case with HPHPc.
Together with HHVM, Meta also released
Hack
Hack may refer to:
Arts, entertainment, and media Games
* ''Hack'' (Unix video game), a 1984 roguelike video game
* ''.hack'' (video game series), a series of video games by the multimedia franchise ''.hack''
Music
* ''Hack'' (album), a 199 ...
, a derivative of PHP that allows programmers to use both
dynamic typing and
static typing, which is a concept also known as
gradual typing
Gradual typing is a type system in which some variable (computer science), variables and expressions may be given types and the correctness of the typing is checked at compile time (which is static typing) and some expressions may be left untyped ...
, and allows
types to be specified for
function arguments, 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 s ...
s, and
class properties; however, types of
local variables cannot be specified. At the same time, Hack does not provide complete
backward compatibility
Backward compatibility (sometimes known as backwards compatibility) is a property of an operating system, product, or technology that allows for interoperability with an older legacy system, or with input designed for such a system, especiall ...
by not carrying on some of the PHP features, such as the
goto
GoTo (goto, GOTO, GO TO or other case combinations, depending on the programming language) is a statement found in many computer programming languages. It performs a one-way transfer of control to another line of code; in contrast a function c ...
statement and dynamic
variable names.
In September 2017, it was announced that version 3.24 would be the last version of HHVM to officially support PHP, and that HHVM will only support Hack going forward, citing differences and incompatibilities in PHP 7.
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 any low-level programming language, consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). Each instruction causes the CPU to perform a ver ...
, leading to a higher web server
throughput and lower
latency. In Q4 2012, the execution of facebook.com's
source code
In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the ...
on HHVM achieved performance parity with HPHPc,
and in December 2013 HPHPc was even surpassed by around 15%.
See also
*
LLVM
LLVM is a set of compiler and toolchain technologies that can be used to develop a front end for any programming language and a back end for any instruction set architecture. LLVM is designed around a language-independent intermediate repre ...
*
Parrot virtual machine
Parrot was a 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 Parrot bytecode a ...
*
Phalanger
Notes
References
External links
*
{{Facebook navbox
2011 software
C++ software
Rust (programming language) software
Facebook software
Free compilers and interpreters
OCaml software
PHP software
Software using the PHP license
Virtual machines
Bytecodes