Subj : Re: OO compilers and efficiency To : comp.programming From : Rob Thorpe Date : Mon Jul 25 2005 02:23 am Chris Dollin wrote: > Rob Thorpe wrote: > > > Chris Dollin wrote: > > >> [And of course this isn't a property of Java particularly; isn't the > >> same true in Lisp, Smalltalk, Pop11, SML, OCaml, etc?] > > > > No, not all of them. > > > > Let's call the commonly used data structures of each of those languages > > "things", for want of a better word. In many of those languages the > > compiler can (and will) allocate those things on the stack so long as > > no pointer to them could possibly leave the context. > > In what way is it different for Java? If no pointer to a `new Spoo()` > can leave the context, then why can't a Java compiler allocate the > Spoo on the stack? > > [Here, the `compiler` is whatever post-processes the bytecode at > runtime, not the Java source -> classfile compiler.] > > I can see that the analysis for "no pointer could possibly leave > the context" can be harder, much harder, because of polymorphism. > So mayhap a Java compiler can stackallocate much less often for > just this reason. Is that the claim? > > [Do you happen to have cites for any of Lisp, Smalltalk, Pop11, SML, > or OCaml doing stack-allocation, 'cos I'd like to chase them up. > I'm sure I remember reading stuff about Lisp compilers attempting > it; I'm equally - or more - sure that Pop11 doesn't do it.] The question here is what languages can allocate more than just simple data structures on the stack. I had a look at the sources of some of the languages you mention above. I found: - SML/OCaml - Only allocate simple things on the Stack Pop11 - Couldn't find out about this one, I'll take your word on it. Lisp - Allocates anything you want on the stack if the programmer specifies "dynamic-extent" but will cannot do so automatically. Smalltalk - Smalltalk "contexts" are held in a stack, but this makes little odds since "new:" is not a language intrinsic, it's a class method. So, I've successfully proved myself wrong. (Think of this as a mid-thread batting collapse. I'll make it up in the second test, promise.) .