Java Manual Stack Allocation

193 views Asked by At

So I'm relatively new to Java, and just read this really interesting Wikipedia article about escape analysis. However, the only time it mentions that stack allocation is used is when the object does not escape the method call. This seems somewhat limited; but then again, I can't think of any other time I would want an object allocated to the stack. So I'm wondering:

1) Is there any other time that it would make sense for an object to be allocated to the stack?
2) Is there any way to manually allocate an object to the stack, not the heap?
2.5) If there is, would it be any faster to do that (for objects that don't escape the method), instead of having escape analysis have to figure it out? Or is there any way to tell Java something like "In this method, I need every object to be on the heap, don't bother trying to see if any can be on the stack"?

Thanks!

1

There are 1 answers

6
Elliott Frisch On
  1. Yes. If appropriate. Are you familiar with Recursion? If not, see 1.
  2. new String("Foo")

2.5... What? Why are you trying to optimize the compile phase like that? What is the point?