1

As we know, operand stack is one member of the jvm runtime stack frame. But why not just use one global operand stack instead? Is there any techical reason for having individual operand stack for each frame?

choxsword
  • 3,187
  • 18
  • 44
  • 2
    'V' in the JVM stands for 'Virtual'. It's not a real machine - it's an abstraction. So is the operand stack. JVM implementation may allocate either a local or a global stack anywhere or nowhere at all, as long as it acts *as if* each stack frame has its own operand stack. Why each frame has its own stack - because this makes sense. I.e. the bytecode of a method can operate only the operand stack of this method, not of any other method. Operand stack is *associated* with a particular method, e.g. when a stack frame is removed because of an exception, its operand stack is discarded. – apangin Feb 16 '21 at 15:41
  • 2
    Organizing the stack in frames is state of the art since, I don’t know, fifty or sixty years, regardless of the programming language. It’s not even clear what your “global operand stack” is supposed to be. A stack can’t be global, it must be thread-local. If you are just proposing a frame-less stack for a thread, there’s almost no difference in the memory layout, only some operation become less efficient. – Holger Feb 17 '21 at 11:44
  • @Holger 'global' means thread local global, that is, one operand stack for all stack frames in current thread. – choxsword Feb 18 '21 at 11:59
  • 1
    That is, `[a b c d e f g h]` vs `[a b c] [d e] [f g h]`, as said, almost no difference in the memory layout, but frames allow several optimizations. – Holger Feb 18 '21 at 12:42

0 Answers0