A DESCRIPTION OF THE REQUEST :
Object creation is still time consuming. Especially for large immutable objects (e.g. adding immutable large integers can be 8x faster when the objects are transparently recycled, ref. JScience benchmark: http://jscience.org/doc/benchmark.html
JUSTIFICATION :
Escape analysis has several limitation. It has to be very conservative at compile time and time consuming at run-time.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
What I propose is that when a thread execute within a specified context (e.g. PoolContext) objects created with "new" keyword are allocated on the stack. The stack is reset when the thread exits the stack context except for objects which are referenced from outside the stack (e.g. static). Those can be copied (or better moved) outside of the stack by the vm.
This approach has been implemented by the Javolution library :http://javolution.org/api/javolution/realtime/package-summary.html#OVERVIEW).
But, having direct vm support would make the whole process:
- Faster: Stacks/pools held by the thread object.
- Easier: <i>new</i> keyword instead of object factories.
- Safer: Export/preserve done automatically by the compiler (e.g. assigning to a static member would result in preserve being called).
ACTUAL -
The actual behavior is quite slow for large objects allocations.
---------- BEGIN SOURCE ----------
A possible course of action would be first to include the Javolution real-time package to Java standard distribution. And then, integrate more and more feature to the JVM.
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use Javolution PoolContext.