[2747] in java-interest

home help back first fref pref prev next nref lref last post

Re: Stack overflow

daemon@ATHENA.MIT.EDU (David Hopwood)
Thu Oct 12 15:33:37 1995

From: David Hopwood <david.hopwood@lady-margaret-hall.oxford.ac.uk>
To: java-interest@java.Eng.Sun.COM
Date: Thu, 12 Oct 1995 18:18:50 +0000 (BST)

In article <Pine.SOL.3.91.951012202610.10634A-100000@17607-news.dodo>,
Richard Wahongan <n1061925@dodo.fit.qut.edu.au> wrote:
>I read the article :
>    HotJava : The Security Story (page 2 particularly)
>
>Can anyone give me an example (if possible in Java codes )
>How stack overflow can happen, and how Java handles it ?

Stack overflow can potentially happen either within a stack frame
(e.g. a loop containing a push instruction), or as a result of two many
nested method calls.

Java prevents the first case by analysing how the stack is used within each
method. Each VM instruction has a stack signature.

E.g. ipush x (push the integer x), has the signature
    ... -> ..., int

From this the bytecode verifier can statically infer the type and size of
the stack at each point in the code.
There is a restriction on branch instructions, that the target must have
the same stack state as the source. For example,

X: ipush 0
Y: jmp X

is illegal, because the stack state is not the same at X and Y.

The second case (nested method invokations), is prevented by checking the
stack pointer on each method call (doing this after each stack instruction
would be too slow).


David Hopwood
david.hopwood@lmh.ox.ac.uk


-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post