23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

More specifically, dur<strong>in</strong>g the execution of a <strong>Java</strong> program, the <strong>Java</strong> Virtual<br />

Mach<strong>in</strong>e (JVM) ma<strong>in</strong>ta<strong>in</strong>s a stack whose elements are descriptors of the currently<br />

active (that is, nonterm<strong>in</strong>ated) <strong>in</strong>vocations of methods. These descriptors are<br />

called frames. A frame for some <strong>in</strong>vocation of method "fool" stores the current<br />

values of the local variables <strong>and</strong> parameters of method fool, as well as<br />

<strong>in</strong>formation on method "cool" that called fool <strong>and</strong> on what needs to be<br />

returned to method "cool".<br />

Figure 14.1: An example of a <strong>Java</strong> method stack:<br />

method fool has just been called by method cool,<br />

which itself was previously called by method ma<strong>in</strong>.<br />

Note the values of the program counter, parameters,<br />

<strong>and</strong> local variables stored <strong>in</strong> the stack frames. When<br />

the <strong>in</strong>vocation of method fool term<strong>in</strong>ates, the<br />

<strong>in</strong>vocation of method cool will resume its execution<br />

at <strong>in</strong>struction 217, which is obta<strong>in</strong>ed by <strong>in</strong>crement<strong>in</strong>g<br />

the value of the program counter stored <strong>in</strong> the stack<br />

frame.<br />

886

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!