Java Reference
In-Depth Information
with a single method call. This frame holds all the data accessible within the
scope of its method call, including its method parameters, local variables, and
instance variables.
Each time a method is called, a new frame is added to the call stack. When that
method returns, its frame is eliminated from the call stack, because it's no longer
needed. When a Java program is started, the call stack contains only a single stack
frame, belonging to the main() method of your executable class. As additional
methods are called, new frames are added to the call stack. At any given time,
there will probably be several frames on the stack, depending on the complexity
of your code.
Examining the contents of the call stack
If you've ever thrown an exception and printed out its stack trace (and who hasn't),
you're looking at the contents of the call stack at the time the exception occurred.
Effectively, this gives you a history of the method calls that led to the exception. A
called B, which called C, which called D, which threw a NullPointerException ,
for example.
Like that stack trace, the debugger lets you examine the contents of the call
stack to see what called what when. In addition, it gives you access to the stack
frames, which contain all the values available to that frame's method call. And
unlike the stack trace, you can examine the call stack any time you trigger a break-
point or manually suspend program execution. The Frame tab of the Debug win-
dow shows a view of the contents of the current, or topmost, stack frame. However,
you can still examine the contents of other frames on the call stack.
Navigating through the call stack
At the top of the Frame tab in the Debug window are the call stack and thread
selector, as shown in figure 6.6. The leftmost drop-down list represents the call
stack; it lists each method currently on the call stack, as well as the class and line
number they originated from. Changing the selection changes the current frame
in the Debug window. By selecting previous frame entries, you can examine the
contents of older frames to understand how things got to where they are now. As a
convenience, you can also use the up and down arrow icons (or press Ctrl+Alt+
Up and Ctrl+Alt+Down ) to navigate through the call stack sequentially.
Figure 6.6 The call stack component lets you select which frame of the call stack the debugger is
examining and also look at the call stack of any thread in the VM.
 
 
 
 
Search WWH ::




Custom Search