What happens after calling the method in Java?

It looks like a stupid question, but I find it difficult to do it I've asked different people, but I can't get the ideal answer

I want to know what happens after calling common methods in Java (provided in a single thread environment).

My understanding is:

>All current stack variables are accelerated and stored somewhere (where?) > Suspension of current method call > parameters of the new method are pushed to the stack > method code running > after the method runs, the stack is emptied again and the contents of the old stack are restored again (what happens if the function returns a value?). > The code continues to use the calling method

This is a very incomplete and possibly wrong answer Can anyone provide a more detailed description?

Thank you.

Solution

No, this is actually quite accurate:

1) The current stack variable remains in the stack

2) The current method is paused

3) The parameters of the newly called method are pushed to the stack

4) Method code run

5) After the method runs, we pop the stack The stack variables of the called method are no longer valid - they no longer "exist"

6) We pass the return value (if any) to the caller

7) The code continues to use the calling method All its stack variables remain unchanged

==============================

Appendix:

@Kevin –

>Conceptually, I think you're right I clarified a few points and hope to be helpful. > If you want to learn more about how the JVM implements "method calls", David Wallace's link is very good. > This is a good overview of how the stack works Any stack, call any subroutine – not just Java: http://en.wikipedia.org/wiki/Call_stack >Finally, Marko topolnik is right "Reality" is almost always complex. It is not suitable for simple, one size fits all answers But I definitely think your understanding is good At least 10000 feet

With all due respect

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>