3 ms·
> although it does do escape analysis to figure out what can be allocated on the stack instead. (Java does this as well.) Walter has a misconception here - Jav
by chrisseaton 4y ago
> although it does do escape analysis to figure out what can be allocated on the stack instead. (Java does this as well.)
Walter has a misconception here - Java does scalar replacement - it doesn’t currently do stack allocation.
- ErikCorry 4y agoInteresting distinction, but once the object is replaced by scalars, those scalars are placed on the stack. Do I understand it correctly that you are saying real stack allocation would involve allocating the whole object, including the header, on the stack, and passing references to such objects to (non-inlined) functions that worked on either stack allocated or heap allocated objects?
- chrisseaton 4y ago> Interesting distinction, but once the object is replaced by scalars, those scalars are placed on the stack. No, they become data flow edges, so could be in a register, or part of an addressing operation, or value-numbered, or nothing at all if they’re never used, so only on the stack as a worst-case fallback. > Do I understand it correctly that you are saying real stack allocation would involve allocating the whole object, including the header, on the stack Yes, which is useful in some cases, but generally a lot weaker than full scalar replacement.
- vips7L 4y agoAn interesting read on Java escape analysis/scalar replacement if anyone is interested: https://gist.github.com/JohnTortugo/c2607821202634a6509ec3c321ebf370 https://gist.github.com/JohnTortugo/c2607821202634a6509ec3c3...