Search code examples
javascriptv8embedded-v8nwjs

Is V8's ScriptCompiler::CachedData bytecode or machine code?


Or rather more generally, are the javascript files compiled by V8 saved to disk as V8 bytecode or as host-specific machine code?

I'm trying to understand how node-webkit's nwjc works. The function I'm referring to is https://github.com/nwjs/v8/blob/nw75/src/nwjc.cc#L168-L183


Solution

  • (V8 developer here.)

    I haven't worked on this area of V8 myself, but as far as I can tell from looking at the code (v8::internal::CodeSerializer::Serialize and its callees), the cached data contains only bytecode, no machine code. That said, there are a few comments indicating that in the future, baseline machine code might also get cached. The format is definitely custom (and unspecified); along with the bytecode itself it contains certain objects that are referenced from the bytecode.

    I don't know whether there actually is anything platform-specific in the cached data. There might well be. Or maybe there was in the past. As the comments about baseline machine code indicate, there might also be some in the future. This really is a use case that V8 wasn't designed for, and that isn't officially supported, so V8 makes no promises about just how portable the cached data might be, and it's better to be safe than sorry.
    (Something similar holds for the version-specificity. For most version upgrades, the cached data will probably be compatible. But sometimes it won't be, and nobody tracks when that will be the case, so the safe move is to always require an exact version match.)