Lew schrieb:
>> Unlike C# or other languages, the stack / heap dichotomy is not part of
>> the programming model in Java.
> Do you know if java really doesn`t have a stack under the hood for
> faster garbage collecting ?
Of course Java has a stack, but it's got nothing to do with speeding up GC.
> Wouldn`t it be rather easy to determine what objects in a function call
> could be put on a stack instead of a heap... (no Global reference to
> them directly or indirectly)
The JVM does all sorts of optimizations, some of which involve putting objects
on the heap, or even in registers. Escape analysis is part of how it does that.
> I mean wouldn`t it be helpful for the garbage collector, if it would
> know Objects that would usually be put on the stack, so they could be
> cleared from the heap when the method that allocated them returned?
If they're on the stack, there's nothing to "be cleared from the heap" in the
first place.
> So not a real stack but it sounds like an easy to do optimization.
There is a stack in Java, it's just not part of the programming model (much).
It holds the method-call frame, variables and the like. It's also a
convenient tool for the optimizer, as you discerned.
As programmers, we allocate objects on the heap, conceptually. They may wind
up on the stack, in registers or even not allocated whatsoever, at run time,
according to the optimizer's wisdom, but that is of no moment to the programmer.

Signature
Lew
>> Unlike C# or other languages, the stack / heap dichotomy is not part of
>> the programming model in Java.
>>
>Do you know if java really doesn`t have a stack under the hood for
>faster garbage collecting ?
What happens under the hood is not part of the programming model. Java
presents a higher level programming interface than C++. You can't get
as close to the silicon.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com