Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
492 views
in Technique[技术] by (71.8m points)

stack and heap in V8 ( JavaScript)

does V8 uses stack and heap like the JVM? if so does it put primitives on the stack and objects on the heap?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  • In V8 null, undefined, true and false internally are heap allocated objects. If you are comming from Java you can say that true and false in V8 are more like Boolean.TRUE and Boolean.FALSE in Java.
  • There is an important difference between real local variables and variables that are captured by closures or shadowed by eval/with. Captures variables are stored in a special heap allocated structure called Context and are accessed indirectly. For more details about real vs. context allocates variables see my answer to a different question
  • V8 has two compilers: non-optimizing (aka full) and optimizing one:

    • Non-optimizing compiler can't store floating point numbers and integers beyond 31-bit (32-bit on x64) on the stack it always boxes them into HeapNumbers. It does not try to do register allocation and stores real local variables on the stack.
    • Optimizing compiler is much smarter. It does register allocation (linear scan) and can keep full 32-bit integers and floating point numbers on the stack and in the registers (including XMM registers).
  • Speaking of JVM: it can perform so called stack allocation and allocate a non-escaping object on the stack instead of the heap. A more generic optimization (scalar replacement) can sometimes completely eliminate allocation of non-escaping object and explode it into separate fields.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...