Can robovm allocate local method objects on the stack rather than heap?

59 views Asked by At

In C (resp. C++), it is possible to allocate arrays, structures, (resp. objects) which are strictly local to a function (resp. method) in the stack frame allocated for this function.

However, in java, all objects are allocated on the heap, even objects which are completely local to a method and are never leaked outside the method.

In some cases, being able to allocate such objects on the stack rather than the heap would provide great efficiency gains.

Does RoboVM code generation support this, or could it support this in the future?

Regards

1

There are 1 answers

1
ntherning On BEST ANSWER

RoboVM does not support stack allocations. Some VMs do escape analysis to determine if a certain allocation is local to a method and can be done on the stack instead of the heap. We might add that to RoboVM in the future as an optimization though it wouldn't be directly user controllable. I know that IBM is experimenting with something similar to .NET's structs: http://www.slideshare.net/mmitran/ibm-java-packed-objects-mmit-20121120. If that is ever accepted as a standard we will try to implement it in RoboVM.