> 
> > well then i don't see how jserv is getting a Error 500 out to teh client :)
> 
> maybe it isn't. maybe that is Apache returning that. Really, there is no
> need to catch these types of errors if you have enough stack space allocated
> to the JVM...but so far, you haven't listened to me at all on this issue.
> 

 Could you explain why you think that stack space is an issue when
it comes to out of memory exceptions?

OutOfMemory exceptions are thrown when the JVM runs out of heap space,
not stack space.  By that time, the JVM will have tried to garbage
collect and drop weak refs already.  (Which, btw, the suggestion to 
invoke System.gc() in a catch(OutOfMemory ) clause does not work.)

Let me quote the VMSpec:

    3.5.3
        [...]

        If a computation requires more heap than can be made available by the 
        automatic storage management system, the Java virtual machine throws 
        an OutOfMemoryError

The only instance when lack of stack of space causes an out of memory error
is when the native method stack cannot be extended.
For your convenience, I quote the complete VMSpec subsection:

    3.5.6 Native Method Stacks

    An implementation of the Java virtual machine may use conventional 
    stacks, colloquially called "C stacks," to support native methods, 
    methods written in a language other than the Java programming language. 
    Native method stacks may also be used by the implementation of an 
    interpreter for the Java virtual machine's instruction set in a language 
    such as C. Java virtual machine implementations that cannot load native 
    methods and that do not themselves rely on conventional stacks need not 
    supply native method stacks. If supplied, native method stacks are 
    typically allocated per thread when each thread is created. 

    The Java virtual machine specification permits native method stacks 
    either to be of a fixed size or to dynamically expand and contract as 
    required by the computation. If the native method stacks are of a
    fixed size, the size of each native method stack may be chosen 
    independently when that stack is created. In any case, a Java virtual 
    machine implementation may provide the programmer or the user control 
    over the initial size of the native method stacks. In the case of 
    varying-size native method stacks, it may also make available control 
    over the maximum and minimum method stack sizes.7

    The following exceptional conditions are associated with native method 
    stacks:

        If the computation in a thread requires a larger native method 
        stack than is permitted, the Java virtual machine throws a 
        StackOverflowError. 

        If native method stacks can be dynamically expanded and native method 
        stack expansion is attempted but insufficient memory can be made 
        available, or if insufficient memory can be made available to create 
        the initial native method stack for a new thread, the Java virtual 
        machine throws an OutOfMemoryError. 

How do you know that what causes the out of memory error in the case
discussed was a failure to allocate more memory for the stack?
I would have thought that this would only happen if you set a *very* large
stack limit and then entered a buggy recursive function.

You may also want to try a VM that does not dynamically expand its stacks,
such as Kaffe.  If you still get an OutOfMemoryError (as opposed to a
StackOverflow) exception, you could be sure that not being able to expand
the stack has nothing to do with it the problem --- otherwise, you would
have gotten a StackOverflowError.

In general, reacting to OutOfMemoryErrors is hard.  First, you need a
VM that supports it (Kaffe currently doesn't, I don't think the JDK does
either.) The JVM has to throw the error at a point in time where there are
sufficient resources for the program to proceed to a point where it can
drop references (either by terminating threads or by explicitly dropping
(zeroing out) references) and then invoke a gc.  This is not trivial to
implement.

        - Godmar



----------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
READ THE FAQ!!!!     <http://java.apache.org/faq/>
Archives and Other:  <http://java.apache.org/main/mail.html/>
Problems?:           [EMAIL PROTECTED]

Reply via email to