V8Snapshot

From Qt Wiki
Revision as of 01:19, 18 April 2015 by JKSH (talk | contribs) (Mark outdated)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
IMPORTANT: The content of this page is outdated. Reason: V8 has been replaced by V4. Also, qtjsbackend no longer exists.
If you have checked or updated this page and found the content to be suitable, please remove this notice.

V8 Snapshot

Lots of V8's JavaScript functionality is implemented in JavaScript itself. As a result, there is a one-time performance cost involved in creating a V8 context.

This performance cost can be brought down by creating so called V8 snapshots. The V8 engine starts up it's state set to an "empty" snapshot (snapshot-empty.cc, used when snapshots are disabled). A custom V8 snapshot can be created by evaluating the initial JavaScript and dumping V8's machine state into a cpp file (snapshot.cpp). This cpp file is then compiled instead of snapshot-empty.cc into the final code. Snapshots are created using the mksnapshot tool.

To allow creation of snapshots for architectures other than the host (say an arm snapshot on i386), V8 has CPU simulators.

The procedure for snapshot creation is this:

  • Create mksnapshot. This is essentially compiling the V8 code with the appropriate CPU emulator (i386/arm/mips) and using mksnapshot.cpp for the main(). The mksnapshot binary when run creates a snapshot.cc file. Note mksnapshot has to run on the host, which essentially means we are compiling using the host tool chain.
  • Copy over the snapshot.cc generated above into src/ and let V8 use that as the snapshot.
  • Compile V8 again but now with the target toolchain.

Caveats

  • The CPU simulator can simulate any configuration and needs to know what the target machine is like. So, it needs to know if it has VFP3, floating point eabi to name two. When cross-compiling, we can figure this automatically.

Current state in qtjsbackend

  • Snapshots are disabled when cross compiling
  • When not cross compiling, user can still pass -arch to configure! (i.e no -xplatform set). This -arch is the hint to qtjsbackend as to which simulator to use to create the snapshot. configure currently allows snapshots only for i386 host and arm (-arch arm) target. I beleive the only purpose of this feature is to be able to help in code generation debugging (http://code.google.com/p/v8/wiki/ARMDebuggingWithTheSimulator).
  • When not-cross compiling and no -arch passed, all builds have snapshot support as long as you are not inside arm scratchbox env.
  • The simulator is always setup to use hardfloat and VFP3. Because of the logic in the pri files, we end up passing these arguments to v8 even when cross compiling i.e even when no simulator is in use and snapshotting is disabled. This is the core issue that needs to be fixed, since currently, during cross compiling qtjsbackend ends up assuming a ARMv7 target