Origin and relation between the virtual machine stack and stack frames

background

See "in-depth understanding of the Java Virtual Machine," this book, talked about part of the Java virtual machine stack and stack frames, why is not clear to create this concept, there is what is the purpose of this memory model is, what the source is, the book did not extended open that are clear and understand the origin of a concept to understand this concept is helpful.

Online search a few articles no background knowledge when it comes to this, about the origin of the virtual machine stack and stack frames, you can look at this YouTube video: Procedures, Video 3: Stack-based languages

A bar Hardware / Software Interface class belongs to the video in the famous, made a very clear.

This article is a combination of the video do notes combined with his understanding, a deeper impression.

Stack-Based Languages

Objective: To make it possible to support recursion in most of the programming languages, you have to keep track of all of the recursive functions that being called a recursive call to implement a method itself, we need a way to store the state of each recursive call. etc, includes:

Argument;Local Variable;Return Pointer。

Stack Frame

Stack allocated in frames, which is called Stack Frame.

When we call a function, we create a new frame for it, by addressing the stack pointer to create a space (memory) for all these states.

State: Local Variables;Function arguments; Return infomation; Temporary space.

Stack-based Language describes a concept stack language, whether it is java or c methods are used in a stack language.

VM stack is for the thread, the thread way to the corresponding element in the stack - the stack frame.

Push the stack flow analysis

Each implementation of a method, this method is created for the corresponding stack frame, and the big push to the thread stack container --Java virtual machine, executing the will pop out of the stack.

The method of collection of stack frames corresponding chain

Method for the plurality of sub-methods, the method corresponds to a call chain, the parent first method begins execution stack, in the end portion is pressed, and then performs sub-method, the stack pressure to the top of the parent method. If this method also has its own sub-sub-method, the same way, then pressed to the top of the sub-sub-sub-method approach. Until the end of the chain calls the method, then the stack one by one from the deepest sub-method, and then the next layer of the stack process, until the last return statement to execute the parent method, a series of chain corresponding to the stack frame of the method are the stack is completed.

example

Reproduced in: https: //juejin.im/post/5cfddb6b6fb9a07ee85c1e42

Guess you like

Origin blog.csdn.net/weixin_34327761/article/details/93174426
Recommended