Tail recursion in the JVM

Why can't the standard JVM does not include tail recursion handling as IBM JVM does.

It would be easy to implement.

consider the method:

Object foo(int a) {

int b=a+1;

if (b<555)

return bar(b);

}

The code of foo includes or ends with

8 invokevirutal #4 <Method java.lang.Object bar(int)>

11 return

This is interpreted by pushing data on the stack, calling bar(), then retrieving the previous top of stack, then discarding it by returning. Why don't JVM interpret these to byte codes as one special byte code which discard the top of stack (we don't need it anymore) before calling bar(). When bar ends, it returns directly to the caller of foo().

It does not change anything to the compiler.

[791 byte] By [castro] at [2007-9-26 4:18:00]
# 1

Not quite sure I understand the question.

A JVM run code.It could use jit to optimize the code. But to know that one would have to either dig deeply into the source of both JVM or use a OS debugger.

On the other hand a compiler takes java source and creates byte codes. And that could optimize the code output too. And it would be more consistent with the byte code output that you are suggesting.

So given that that you are actually referring to the compiler, the reason is probably because very little code is written that way. So modifying the compiler to do that is going to effect less than 1% of the java code (and probably significantly less than that.) Where as, for example, speeding up a method call or lowering the thread creation cost, would effect a far greater amount of code.

You can enter "Requests For Enhancement" in to the bug database and if a lot of people vote for it then Sun might add it in.

jschell at 2007-6-29 17:18:45 > top of Java-index,Java HotSpot Virtual Machine,Specifications...