JavaScript, ECMA262 5.1(June 2011) TC39 Conformance Suite Test262 Building modern JavaScript Engine YUSUKE SUZUKI, We implemented an engine that is fully compliant with ECMA262 5.1 (June 2011) and confirmed it by using Conformance Suite Test262 provided by TC39. And we optimized it. 1. ECMAScript JavaScript TC39 (Technical Committee 39) 1. ECMA262 2 5.1. V8 3, JavaScriptCore 4, SpiderMonkey 5.,,. ECMA262 5.1 lv5. ECMA262 5.1,, 2. TC39, ECMA262 Test Suite Test262 6 Cybozu Labs Youth 3 3rd grade of Department of Science and Technology, Keio University 1 http://www.ecma-international.org/memento/tc39.htm 2 http://www.ecma-international.org/ publications/standards/ecma-262.htm 3 http://code.google.com/p/v8/ 4 http://www.webkit.org/projects/javascript/ 5 https://developer.mozilla.org/en/spidermonkey 6 http://test262.ecmascript.org/. Test. Test sputniktests 7 ES5 Conformance Suite 8,,, lv5 Test Suite. Opera 11.51 Safari 5.1.1 GoogleChrome 15.0.824.120 : V8 3.5.10.23 Firefox 8.0 lv5 : 1 1. lv5, Test262 11029 11011, 99.83% pass 18 Test262, Test262 1 Test pass fail (%) Opera 11029 7276 3753 65.97 Safari 11029 10256 773 92.99 GoogleChrome 11029 10611 418 96.21 Firefox 11029 10865 164 98.51 lv5 11029 11011 18 99.83 7 http://code.google.com/p/sputniktests/ 8 http://es5conform.codeplex.com/ 171
1. 1 2 3 4, Test262 3. lv5 lv5, 3.1 NaN boxing ECMAScript. JSVal. JSVal,, JSVal 64bit 2 IEEE 754 IEEE 754 (Exp) 1 (Fraction) 0 quiet NaN, NaN NaN, NaN, boxing. LuaJIT 5 2 IEEE 754 1 https://bugs.ecmascript.org/show_bug.cgi?id=215 2 https://bugs.ecmascript.org/show_bug.cgi?id=216 3 https://bugs.ecmascript.org/show_bug.cgi?id=217 4 https://bugs.ecmascript.org/show_bug.cgi?id=218 5 http://luajit.org/, JavaScriptCore SpiderMonkey. 32bit, 32bit 32bit, int32 t boxing, JSVal 64bit 64bit 64bit., Linux, Windows OS 16bit 0, boxing. Solaris JSVal 128bit. 6 NaN 16bit 0x0000 0xFFF0. -Infinity. 16bit 1, 0x0001 0xFFF1., 0x0000, NaN 7, 16bit 0x0000,, GC lv5, BoehmGC 8 GC,. 6 https://bugzilla.mozilla.org/show_bug.cgi?id=577056 7 0xFFF1 8 http://www.hpl.hp.com/personal/hans_boehm/gc/ 172
3.2 Stack VM AST, ECMA262., VM. VM,, ECMAScript. VM ECMAScript,, ECMAScript VM, C, VM ECMAScript, finally return 3.3 ECMAScript, STACK, HEAP, DY- NAMIC, GLOBAL 4,.,.,,,,. STACK.,.,, HEAP.,, HEAP.,,, Global, Global, Global function stack() { function heap() { inner(); function global() { function with_dynamic() { var obj = {; with (obj) { function with_not_dynamic() { var obj = {; with (obj) { function eval_dynamic() { eval("var i = 20"); 3 GLOBAL. ECMAScript,,. DYNAMIC. (1) with 3 with dynamic i 173
function Point(x, y) { this.x = x; this.y = y; Point.prototype.add = function(rhs) { return new Point( this.x + rhs.x, this.y + rhs.y); var point = new Point(0, 10); 4 class with with, with trap. DYNAMIC with not dynamic i trap, (2) direct call to eval eval eval, direct call to eval., eval, eval, strict, 1,., eval, eval, 3 eval dynamic i DYNAMIC. (3) arguments arguments,. strict, arguments, HEAP. 3.4 Inline Cache Inline Cache Self 1,V8 Hidden Class 2 V8, JavaScriptCore 3. ECMAScript, prototypal, 1 http://labs.oracle.com/self/papers/pics.html 2 http://code.google.com/ intl/ja/apis/v8/design.html#prop_access 3 http://www.webkit.org/ blog/214/introducing-squirrelfish-extreme/,, ECMAScript,, ECMAScript. 4, Point x, y, add rhs Point V8 HiddenClass 4, JavaScriptCore Structure., Map Map Map. Map, Map Map, transit., Map transit,, transit Map Map Map Map., rhs.x, Map,, Map, Map, 3.5 Global ECMAScript Global Global, Global., Global ECMAScript, Global Inline Cache. 4 Map 174
lv5, Own Property. Global, [[Prototype]] Object.prototype 3.6, eval,,,,. 3.7 String Rope ECMAScript String., String Rope, lv5 Rope String. 3.8,. 3.9 RegExp V8 JavaScriptCore JSCRE, ECMA262, RegExp. 3.10 strict ECMA262 5 strict. strict, strict 3.10.1 arguments arguments strict 5 normal, arguments[0], x.,, arguments, HEAP arguments, arguments, arguments, strict arguments., strict lv5 x STACK,, function normal(x) { arguments[0] = 20; console.assert(x === 20); normal(10); function strict(x) { "use strict"; arguments[0] = 20; console.assert(x === 10); strict(10); 5 function normal() { function outer(str) { eval(str); function strict() { "use strict"; function outer(str) { eval(str); 6 strict arguments mode strict eval STACK, HEAP 3.10.2 eval strict eval, 6 normal, outer( var i = 50 ) eval i trap, i strict, 6 strict, inner i outer eval trap. strict 175
2 SunSpider (ms) lv5 55000 lv5 1830 Opera 212 Safari 185 GoogleChrome 214 Firefox 223 SpiderMonkey JIT 950 SpiderMonkey C 3657 eval 1,, i strict i, lv5 HEAP. 4., SunSpider 1.,. 2. 10, 20 5. 5.1 GC BoehmGC GC, GC,, C++ RAII Exact GC, Mark & Sweep 5.2 JIT ECMAScript JIT. JIT dispatch, V8 VM JavaScript- Core VM VM, VM, JIT, 1 http://www.webkit.org/perf/sunspider/sunspider.html Inline Cache. 5.3 RegExp JIT RegExp, RegExp VM,. 5.4 V8 API V8, ECMAScript node.js 2,, V8Monkey 3 SpiderMonkey V8 API, lv5 V8 API. 6. Test262, ECMA262 5.1, lv5. lv5 4,,,,, 1) Urs Hlzle, Craig Chambers, and David Ungar: Optimizing Dynamically-Typed Object- Oriented Programming Languages with Polymorphic Inline Caches (1991). 2) Russ Cox: Regular Expression Matching: the Virtual Machine Approach (2009). 3) Standard ECMA-262 ECMAScript Language Specification Edition 5.1: http://www.ecma-international.org/ publications/standards/ecma-262.htm. 4) V8: http://code.google.com/p/v8/. 5) WebKit: http://www.webkit.org/. 2 http://nodejs.org/ 3 https://github.com/zpao/v8monkey 4 https://github.com/constellation/iv 176