Advantages of stack-based architecture of the JVM's instruction

前端 未结 3 934
囚心锁ツ
囚心锁ツ 2021-01-12 09:21

Why the Java virtual machine was designed with no registers to hold intermediate data values? Instead every thing works on stack. is there any specific advantage of having a

3条回答
  •  暖寄归人
    2021-01-12 09:32

    Java was designed to be portable from the ground up. But how can you keep your bytecode portable if it depends on certain registers being present on the platform you are running it on? Especially taking into account that originally it was intended to run (also) on set-top boxes, which have a very different processor architecture from mainstream PCs.

    It is only runtime that the JVM actually knows the available registers and other hardware specific stuff. Then the JIT compiler can (and will) optimize for these as applicable.

提交回复
热议问题