(Translated by https://www.hiragana.jp/)
GitHub - ispras/webkit-aotc: WebKit JavaScriptCore ahead-of-time compilation project
Skip to content

WebKit JavaScriptCore ahead-of-time compilation project

Notifications You must be signed in to change notification settings

ispras/webkit-aotc

 
 

Repository files navigation

Webkit with JavaScriptCore AOTB support

This is a modified version of WebKit. AOTB acronym stands for Ahead-Of-Time Bytecode saving. Main changes are in JavaScriptCore and it supports saving JSC bytecode in a file and later executing it. Saving is possible with or without running JavaScript program. Based on version 538.28.

Building

The easiest way to build modified JavaScriptCore is to use the Tools/Scripts/build-jsc script. Basic options for Linux are --gtk and --release. Whole WebKit build is also supported, but the only difference outside JSC is that for local JS files URLs WebCore tries to load bytecode files instead of JS source, using the same path but with ".bytecode" additional file extension.

Bytecode saving (JS to bytecode conversion) is available only in command line JSC version.

New command line options for JSC

option description
--save <file.js> Main option for JS to bytecode conversion, saves bytecode for all functions in JS source without running it. Only one JS file allowed per one JSC run.
-o <file> Allows to specify output file name for bytecode file. Without this options, bytecode is stored in /tmp/<file.js>.bytecode
-b <file> Like -f for JS source, it runs code loaded from bytecode file. Several bytecode files are supported (each with its own -b option) and mixing with normal JS files is also possible.
--saveBytecode=<flag> Enables saving bytecode while running JS program, but only executed functions are saved. Default is false (0).
--compression=<level> Enables zlib per-function bytecode compression level 0-9, zero (default) means no compression.

Example

If standard run from command line looks like

$ jsc foo.js -- <params>

AOTB save command is

$ jsc --save foo.js -o foo.bc

To run existing bytecode file, use

$ jsc -b foo.bc -- <params>

Description

JavaScriptCore parses each function only when it is called for the first time. After parsing it generates bytecode in memory and all execution levels (interpreter, baseline JIT, DFG JIT) work only with bytecode, without using source. This version allows to save bytecode in a file, even without running the JS program, and later load bytecode and execute it without parsing source.

Bytecode for runtime-generated JavaScript (like eval() or new Function() calls) is not saved, and while running from saved bytecode, it is processed as usual starting from parsing and creating syntax tree. JSC generates a bit different bytecode when function is used as constructor, we implement necessary conversion for bytecode to translate it from standard form into constructor form instead of saving both versions in a file. Our implementation successfully passes JSC regression tests except those which explicitly require the JS source code, for example, for printing function source or storing line numbers in exceptions.

The original idea was to store more different internal representations from JSC, and baseline JIT code saving was also implemented, but we publish only the AOTB part. AOTB is platform-independent, it was tested on x86_64 and ARMv7 under Linux.

Resources

License

WebKit License

About

WebKit JavaScriptCore ahead-of-time compilation project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published