Java's function call stack is the Java Virtual machine stack, which is thread-private and is created with threads to store stack frames.
The stack frame is created as the method is called and destroyed as the method ends. It can be said that the stack frame is the abstraction of a method.
You can then understand the function call process by printing out the stack frame information in the Java Virtual machine stack. The Java code used to implement this process is as follows:
Package Methodcall;public class Methods {public void method1 () {method2 ();} public void Method2 () {method3 ();} public void Method3 () {Throwable ex = new Throwable ();/** * Throwable getstacktrace () can return the virtual machine stack information of the current thread, returning the first element of the array is the top element of the stack, the most The latter element is the bottom element of the stack. */stacktraceelement[] stackelements = Ex.getstacktrace (); System.out.println (stackelements.length); for (Stacktraceelement stacktraceelement:stackelements) { System.out.println (Stacktraceelement.getmethodname ());}}}
Package Methodcall;public class Methodcall {public static void main (string[] args) {//TODO auto-generated method Stubmeth ODS methods = new methods (); Methods.method1 ();}}
The output results are as follows:
4
Method3
Method2
Method1
Main
Reference documents:
Java Virtual Machine specification Java SE 7
Java function Call stack