[Sablevm-developer] Re: [Sablevm-user] About closures...
Brought to you by:
egagnon
From: Etienne M. G. <eg...@j-...> - 2000-07-18 20:46:56
|
Hi Brent. > Is there room for three new bytecodes (UseSameFrame, BeginContinuation, > UseContinuation)? I'm a bit worried :-) Yes. No need to worry about this. We can build compound bytecodes (similar to the "WIDE" bytecode). > In fact, I wonder if the JVM could identify tail-recursion on its > own and handle it behind-the-scenes. In fact, it doesn't have to be recursive... ... invokevirtual <some method> areturn ... This last invoke virtual can obviously reuse the current stack frame (under the condition that this code IS NOT enclosed in an exception handler). In fact, SableVM could automatically detect the general pattern: invokexxx (be it invokespecial, invokestatic, invokevirtual, invokeinterface) xreturn (areturn, ireturn, ...) And implement this reusing the current stack frame. What we gain: tail recursion (and non-recursion:^) What we lose: exact stack trace for debugging. So, this feature could be turned on/off. Potential problems: The latest APIs use some VM collaboration to implement some security scheme that depends on the stack. We would have to doublecheck that we are not introducing any security hole. I am pretty sure that there are no security side effects, even for the new APIs, as the code is not enclosed in exception handlers, so there aren't much other things that can happen to the stack other than popping the method parameters, pushing the method result, and returning it. In fact, this requires no modification to the verifier. This seems like a perfect solution. And it will be easy to implement (and nice to put in my thesis). Free tail recusrion (or should we call it tail-method-invocation?) One problem solved. :-)) Etienne -- ---------------------------------------------------------------------- Etienne M. Gagnon, M.Sc. e-mail: eg...@j-... Author of SableVM: http://www.sablevm.org/ ---------------------------------------------------------------------- |