Jenny
Jenny

Reputation: 111

Why is Javascript's Byte Code(v8 engine) generation different in different architectures

Is byte code generated by v8 platform-independent?

If so, I have tried to generate byte code in different architectures(x86、x64).It turned out byte code generation is different in different architectures. What is the reason?

Byte code generated by the same JS under x86 and x64. enter image description here

Upvotes: 0

Views: 754

Answers (2)

jmrk
jmrk

Reputation: 40491

(V8 developer here.)

JavaScript, as a language, doesn't have a standardized byte code, so there are no statements to be made about generic "JavaScript byte code" other than "it doesn't exist".

That said, some JavaScript engines, including recent versions of V8, use a byte code internally. That's entirely an engine-internal implementation detail. We make no promises about it and provide no documentation for it because nobody outside the engine is supposed to rely on any particular aspects of it, or its existence at all. (Historically, before ~2017, V8 has not used a byte code internally; and who knows, maybe in the future we'll eventually go back to a byte code free implementation. In the meantime, some details of the bytecode often change from one V8 version to the next.)

ByteNode is a hack that repurposes (or "abuses") engine-internal details for other purposes. If you feel that it solves a problem that you have, then great; but it's not something we (=V8 team) support or endorse. (In fact, personally, I'm quite skeptical that it accomplishes anything more than minified/"uglified" JS does: a bit of obfuscation.)

As for the specific question: the general bytecode mechanism is platform independent, that's part of its purpose. But the byte code was never designed/intended to leave the machine it was generated on, so there's no reason not to have some details depend on what that machine is. To find such details, you can browse through bytecode-generator.cc and look for anything that depends on the current platform or pointer size. Although once you find such a difference, there likely won't be anything you can do to work around it.

Upvotes: 1

ProfDFrancis
ProfDFrancis

Reputation: 9411

Byte code is not always platform-independent

Python's bytecode is platform-independent.

https://opensource.com/article/18/4/introduction-python-bytecode

In contrast, Javascript's is not.

https://softwareengineering.stackexchange.com/questions/402250/why-is-javascript-not-compiled-to-bytecode-before-sending-over-the-network/402273

Upvotes: 0

Related Questions