Difference between evaluation stack and thread stack

I am currently trying to teach myself MSIL by playing around with C # translation into MSIL commands.

That said, if I believe I stumbled across, the assumption is made that the "evaluation stack", which is pushed with values ​​and then popped and stored in the local variable list, is another way of accessing the stack that is assigned to the thread during execution.

Reading Eric Lippert's answer for the purpose of evaluating the stack makes it clear that they are not the same:

I am assuming you mean the MSIL evaluation stack, not the actual stack on a thread at runtime.

My question is, what is the exact difference between these two stacks? And how are they related?

+3


source to share


2 answers


No, there is only one stack. There are several languages ​​that distinguish between the eval stack and the return stack. The fourth language prompts us as a basic example, quite influential in the early days of microprocessors. And extremely complex using the syntax of the language, rather unfriendly to the program. Easy to implement, however, it doesn't take up more than 2 kilobytes of code. Roughly what your understanding of the Linq query understands :)

But no, MSIL is not one of them. VM (virtual machine) defines only one stack per method. It is fully type-aggregated, it can store an int or a double or an object reference or method return address with equal aplomb. Pushing and adding a value to / from the stack is just a logical operation and not simulating the actual data transfer at all.



The job of jitter is to turn this into machine code that processes real data. It's actually not that hard, the processor has a stack just like a virtual machine. And it can store all kinds of different data types as well, but without the ability to ignore the data size of course. And above all, eliminating this kind of pushes and popping and using a processor registry bank not fully modeled in MSIL. It is no coincidence that different processors have very different registry bank capabilities. It is very important to code quickly.

And yes, each thread has its own stack. It is absolutely essential that the stack holds the return address method and that threads can execute other code. Both MSIL and machine code.

+4


source


Basically, the CIL test stack is what you manipulate with CIL instructions, the actual execution stack on a thread is what you manipulate with machine code (assembly) instructions.

The CIL stack doesn't really exist at runtime as it is part of the virtual machine defined by the CLI specification.



What the CLR JIT compiler does is take the CIL code that uses the CIL stack and transforms it into machine code (specific to your architecture like x86 or ARM) that uses the actual execution stack.

+2


source







All Articles