The HipHop Virtual Machine
目前Facebook已将该HipHop虚拟机开源,源代码发布在GitHub上。关于该工具的技术原理在Facebook的开发者页面上有一篇详细的文章介绍,查看这里。
如果看不到的可以看下面的转载:
We're always looking for ways to make our computing infrastructure more efficient, and in 2010 we deployed HipHop for PHP to help support the growing number of Facebook users. While HipHop has helped us make significant gains in the performance of our code, its reliance on static compilation makes optimizing our code time consuming. We were also compelled to develop a separate HipHop interpreter (hphpi) that requires a lot of effort to maintain. So, early last year, we put together a small team to experiment with dynamic translation of PHP code into native machine code. What resulted is a new PHP execution engine based on the HipHop language runtime that we call the HipHop Virtual Machine (hhvm). We're excited to report that Facebook is now using hhvm as a faster replacement for hphpi, with plans to eventually use hhvm for all PHP execution.
Facebook uses hphpi (and now hhvm) for day-to-day software development, but uses the HipHop compiler (hphpc) to create optimized binaries that serve the Facebook website. hphpc is in essence a traditional static compiler that converts PHP→AST→C++→x64. We have long been keenly aware of the limitations to static analysis imposed by such a dynamic language as PHP, not to mention the risks inherent in developing software with hphpi and deploying with hphpc. Our experiences with hphpc led us to start experimenting with dynamic translation to native machine code, also known as just-in-time (JIT) compilation. A dynamic translator can observe data types as the program executes, and generate type-specialized machine code. Unfortunately we didn't have a clean model of PHP language semantics built into HipHop, as hphpc and hphpi are based directly on two distinct abstract syntax tree (AST) implementations, rather than sharing a unified intermediate representation. Therefore we developed a high-level stack-based virtual machine specifically tailored to PHP that executes HipHop bytecode (HHBC). hhvm uses hphpc's PHP→AST implementation and extends the pipeline to PHP→AST→HHBC. We iteratively codeveloped both an interpreter and a dynamic HHBC→x64 translator that seamlessly interoperate, with the primary goal of cleanly supporting translation.
Throughout the hhvm project we have tended toward simple solutions. This is nowhere more evident than in the core premise of the dynamic translator itself. Most existing systems use method-at-a-time JIT compilation (e.g., Java and C#), though trace-based translation has also been explored in recent systems (e.g., Tamarin and TraceMonkey). We decided to try a very simple form of tracing that limits each trace to a single basic block with known input types. This "tracelet" approach simplifies the trace cache management problem, because complex application control flow cannot create a combinatorial explosion of traces. Each tracelet has a simple three-part structure:
- Type guard(s)
- Body
- Linkage to subsequent tracelet(s)
The type guards prevent execution for incompatible input types, and the remainder of the tracelet does the real work. Each tracelet has great freedom, the only requirement being that it restore the virtual machine to a consistent state any time execution escapes the tracelet and its helpers. The obvious disadvantage is that tracelet guards may repeat unnecessary work. Thus far we have not found this to be a problem, but we do have some solutions in mind should a need arise.
For those who are interested in understanding HHBC in detail, the bytecode specificationis available in the HipHop source tree. However, detailed knowledge should not be necessary for understanding the following example:
f() is executed twice, for which the translator creates three tracelets total as shown below. f($a, 42) causes creation of tracelets A and B, and f($a, "hello") causes creation of tracelet C; B is used by both invocations.
How well does hhvm work? As compared to hphpi, the hhvm bytecode interpreter is approximately 1.6X faster for a set of real-world Facebook-specific benchmarks. Right now there is a stability gap between the hhvm interpreter and translator, which precludes us reporting translator performance for the same set of benchmarks. However, we can infer from a set of benchmarks based on the Language Shootout that translator performance is closer to hphpc-compiled program performance than to interpreter performance, as indicated by the geometric mean of the benchmarks (rightmost column in the following figure). The interpreters are all roughly 0.2X as fast as hphpc, and the translator is approximately 0.6X as fast. For perspective on why this matters, consider that many Facebook engineers spend their days developing PHP code in an endless edit-reload-debug cycle. The difference between 8-second and 5-second reloads due to switching from hphpi to the hhvm interpreter makes a big difference to productivity, and this improvement will be even more dramatic once we enable the translator.
We expect hhvm to rapidly close the performance gap with hphpc-compiled binaries over the coming months as the dynamic translator stabilizes and matures. In fact, we predict that hhvm will eventually outperform statically compiled binaries in Facebook's production environment, in part because we are already sharing enough infrastructure with the static compiler that we will soon be able to leverage static analysis results during tracelet creation.
Many challenges remain, as well as some uncertainty regarding the translator's behavior when running the entirety of Facebook's PHP codebase. In the near term we need to stabilize the translator and create an on-disk bytecode format (to reduce startup time and to store global static analysis results). Then we will need to optimize/tune both the translator and the interpreter as we observe how the system behaves under production workloads. Here are just a couple of the interesting problems we will soon face:
- The x64 machine code that the translator generates consumes approximately ten times as much memory as the corresponding HHBC. CPU instruction cache misses are a limiting factor for the large PHP applications that Facebook runs, so a hybrid between interpretation and translation may outperform pure translation.
- The translator currently makes no use of profile feedback, though we do have sample-based profiling infrastructure in place. Profile-guided optimization is an especially interesting problem for us because Facebook dynamically reconfigures its website between code pushes. Hot code paths mutate over time, and portions of the x64 translation cache effectively become garbage. One solution may be to repeatedly create a new translation cache based on the previous one, taking advantage of recent profile data. This approach has a lot in common with semi-space garbage collection.
The first 90% of the hhvm project is done; now we're on to the second 90% as we make it really shine. The hhvm code is deeply integrated with the HipHop source code, and we will continue to share HipHop via the public GitHub site for HipHop, just as we have since HipHop's initial release in early 2010. We hope that the PHP community will find hhvm useful as it matures and engage with us to broaden its usefulness through technical discussions, bug reports, and code contributions. We actively monitor theGitHub site and mailing list.
Jason Evans is a software engineer on the HipHop team at Facebook, one of nearly 20 people who have contributed to the hhvm project so far.
原文地址:http://www.facebook.com/note.php?note_id=10150415177928920
相关文章:

node建立博客系统遇到的问题,1,乱码。2,multer的使用错误。3使用session问题...
2019独角兽企业重金招聘Python工程师标准>>> 1,乱码 文件存储为utf-8格式后还是报错。 原来这个设置只对新建文件编码有效,旧文件不处理的,我还以为旧文件也给转换了。 2,上传文件的multer模块使用错误。 throw new Ty…

python时间函数入门_calendar在python3时间中有哪些常用函数?怎么用?
想要在python中写代码游刃有余,没有函数的支持是万万不行的。很多小伙伴反映,最近函数的应用知识不够了,所以小编挑选了python3时间中的函数,希望可以帮助大家在处理日历方面更加的迅速。其他更多的函数,大家也可以自行…

9.spark core之共享变量
简介 spark执行操作时,可以使用驱动器程序Driver中定义的变量,但有时这种默认的使用方式却并不理想。 集群中运行的每个任务都会连接驱动器获取变量。如果获取的变量比较大,执行效率会非常低下。每个任务都会得到这些变量的一份新的副本&…

【CSDN2012年度博客之星】需要您的一票,感谢大家的支持
从2004年9月,本人一直将自己工作和学习经验写成博文分享给大家,本人有幸被选为2012年88位候选博客之星,如果各位IT‘er喜欢我的博文,请投我一票,做…

双绞线和同轴电缆
线缆作为连接器件,相当于不同系统之间沟通的“桥梁”,选择线缆类型的好坏,也决定着传输信号的质量,影响着整个系统的稳定性。 (1)特性阻抗 先说一下关于线缆在传输过程中的特性阻抗问题。 特性阻抗是指电缆…

keras训练完以后怎么预测_使用Keras建立Wide Deep神经网络,通过描述预测葡萄酒价格...
你能通过“优雅的单宁香”、“成熟的黑醋栗香气”或“浓郁的酒香”这样的描述,预测葡萄酒的价格吗?事实证明,机器学习模型可以。在这篇文章中,我将解释我是如何利用Keras(tf.keras)建立一个Wide & Deep神经网络,并…
如何发布自己的NPM包(模块)?
1.注册NPM 账号 注册地址:https://www.npmjs.com/。 2.初始化自己要发布的项目 搭建本地环境:安装node.js,包含了npm命令。新建目录,在该目录下,初始化项目:npm init。按照提示填写初始化信息,我…

PHP对于浮点型的数据需要用不同的方法去解决
Php: BCMathbc是Binary Calculator的缩写。bc*函数的参数都是操作数加上一个可选的 [int scale],比如string bcadd(string $left_operand, string $right_operand[, int $scale]),如果scale没有提供,就用bcscale的缺省值。这里大数直接用一个…

mysql提示符详解_MySQL字符集使用详解
查看字符集相关变量mysql> show variables like character%;————————–——————————-| Variable_name | Value |————————–——————————-| character_set_client | latin1 || character_set_connection | latin1 || character_set_database…

Apache漏洞修复
今天受同事的委托,修复一台服务器的Apache漏洞,主要集中在以下几点: 1.Apache httpd remote denial of service(中危) 修复建议:将Apache HTTP Sever升级到2.2.20或更高版本。 解决方法:升级HTT…

Java遍历Map对象的四种方式
关于java中遍历map具体哪四种方式,请看下文详解吧。 方式一 这是最常见的并且在大多数情况下也是最可取的遍历方式。在键值都需要时使用。 1 2 3 4 Map<Integer, Integer> map new HashMap<Integer, Integer>(); for (Map.Entry<Integer, Intege…

Tokyo Cabinet 安装
tokyocabinet :一个key-value的DBM数据库,但是没有提供网络接口,以下称TC。 tokyotyrant :是为TC写的网络接口,他支持memcache协议,也可以通过HTTP操作,以下称TT。 Tokyo Cabinet 是一款 DBM 数据库,Tokyo …

Packagist / Composer 中国全量镜像
Packagist 镜像 请各位使用本镜像的同学注意: 本镜像已经依照 composer 官方的数据源安全策略完全升级并支持 https 协议!请各位同学 按照下面所示的两个方法将 http://packagist.phpcomposer.com 修改为 https://packagist.phpcomposer.com 还没安装 co…
centos yum mysql-devel 5.5_CentOS 6.5下yum安装 MySQL-5.5全过程图文教程
在linux安装mysql是一个困难的事情,yum安装一般是安装的mysql5.1,现在经过自己不懈努力终于能用yum安装mysql5.5了。下面通过两种方法给大家介绍CentOS 6.5下yum安装 MySQL-5.5全过程,一起学习吧。方法一:具体方法和步骤如下所示&…

py 的 第 31 天
1.osi 7层模型 5层: 应用层 应用层 表示层 会话层 传输层 网络层 数据链路层 物理层 4层: 应用层 应用层 表示层 会话层 传输层 网络层 物理层 数据链路层 物理层 注意:7层背会。 2.tcp的三次握手&…

mysql实训报告_mysql数据库技术》实验报告.doc
mysql数据库技术》实验报告MySQL数据库技术实验报告系 别班 级学 号姓 名地点地点机房课程名称MySQL数据库技术实验名称实验1 MySQL的使用实 验 过 程目的要求:(1)掌握MySQL服务器安装方法(2)掌握MySQL Administrator的基本使用方法(3)基本了解数据库及其对象实验准…

PHP中魔术方法的用法
PHP中魔术方法的用法 /** PHP把所有以__(两个下划线)开头的类方法当成魔术方法。所以你定义自己的类方法时,不要以 __为前缀。 * */// __toString、__set、__get__isset()、__unset() /*The __toString method allows a class to decide how …

“互联网+”的时代,易佳互联也随着时代步伐前进着
一谈到互联网,我想大家的心里都不陌生,咱们总理工作报告中提出,制定“互联网”行动计划,推动移动互联网、云计算、大数据、物联网等与现代制造业结合,促进电子商务、工业互联网和互联网金融健康发展,引导互…

PHP 获取数组最后一个值
<?PHP$array array(1,2,4,6,8);echo end($array);?> <?PHP$array array(1,2,4,6,8);echo array_pop($array);?> <?PHP$array array(1,2,4,6,8);$k array_slice($array,-1,1);print_r($k); //结果是一维数组?>

解决nginx 502 bad gateway--团队的力量
nginx 502 bad gateway可以采取客户端强制刷新的方法,但是真正的解决要么改配置或者放CDN上。遇到这个问题,首先是有人发现可以加index.html访问,因为我们是线上网站,没有太多时间去研究,所以先临时这样;然…

MYSQL企业常用架构与调优经验分享
小道消息:2016爱维Linux高薪实战运维提高班全新登场,课程大纲:http://www.iivey.com/666-2一、选择Percona Server、MariaDB还是MYSQL1、Mysql三种存储引擎MySQL提供了两种存储引擎:MyISAM和 InnoDB,MySQL4和5使用默认的MyISAM存储…

mysql 5.x 安装_mysql 5.5.x zip直接解压版安装方法
到官网下载mysql-5.5.10-win32.zip,然后将mysql解压到任意路径,如:C:\mysql-5.5.10-win32打开计算机->属性->高级系统设置->环境变量,新建一个环境变量,变量名为:MYSQL_HOME,变量值为你…

阿里云移动数据分析服务使用教程
阿里云大学课程:阿里云移动数据分析服务使用教程课程介绍:移动数据分析 (Mobile Analytics) 是阿里云推出的一款移动App数据统计分析产品,为开发者提供一站式数据化运营服务:通用的多维度用户行为分析、数据开放并支持自定义分析、…

Apache的服务端包含--SSI
SSI定义: SSI(服务器端包含)提供了一种对现有HTML文档增加动态内容的方法。 作用: 一般出于效率的考虑,网站都会把内容尽可能的静态化成HTML文件,但是网站页面的布局往往比较复杂,各个部分的更新…

mysql校对规则_MySQL中的校对规则
详解MySQL中的校对规则Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 7Server version: 5.6.14 MySQL Community Server (GPL)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered…

c#操作oracle的通用类
using System;using System.Collections;using System.Collections.Generic;using System.Data;using System.Linq;using System.Text;using DDTek.Oracle;using System.Configuration;namespace Common{ <summary> /// OracleHelper 的摘要说明。 /// </summary> …

react es6+ 代码优化之路-1
这里集合了一些代码优化的小技巧 在初步接触 es6 和 react 的时候总结的一些让代码跟加简化和可读性更高的写法大部分知识点是自己在平时项目中还不知道总结的,一致的很多优化的点没有写出来,逐步增加中,目的是使用最少的代码,高效的解决问题…

反向ajax实现
英文原文: Reverse Ajax, Part 1: Introduction to Comet在过去的几年中,web开发已经发生了很大的变化。现如今,我们期望的是能够通过web快速、动态地访问应用。在这一新的文章系列中,我们学习如何使用反向Ajax(Revers…

ef关联多实体查询_Mybatis基本知识十二:关联关系查询之延迟加载:侵入式延迟加载...
上一篇文章:《Mybatis基本知识十一:关联关系查询之延迟加载策略:直接加载》若文中有纰漏,请多多指正!!!1.前言延续上一章节,本章节主要讲解和演示在关联关系查询中侵入式延迟加载是怎么回事。与…

Java高危漏洞被再度利用 可攻击最新版本服务器
2019独角兽企业重金招聘Python工程师标准>>> 安全研究人员警告称,甲骨文在2013年发布的一个关键 Java 漏洞更新是无效的,黑客可以轻松绕过。这使得此Java高危漏洞可以被再度利用,击运行最新版本 Java 的个人计算机及服务器。甲骨文…