5 ms·
In general - yes: https://github.com/dotnet/coreclr/issues/1784 https://github.com/dotnet/coreclr/issues/1784. However, nothing more specific I can say...
by kkokosa 9y ago
In general - yes: https://github.com/dotnet/coreclr/issues/1784 https://github.com/dotnet/coreclr/issues/1784. However, nothing more specific I can say...
- cpeterso 9y agoFor a VM as mature as .NET, I am surprised they don't do escape analysis. Java and Go both do escape analysis, though the coreclr issue you linked to makes the point that Java really needs escape analysis because it doesn't have value types like C# structs.
- tybit 9y agoI'd say .NET is surprisingly immature considering it's age and it's popularity, at least compared to JVM and JS options. Don't get me wrong I think .NET is great, and they've made some smart decisions that allow it to be competitive with much less engineering work on the VM. As well as not having escape analysis it also lacks tiered compilation which is a much more pressing problem from my perspective, and is being actively tackled now.
- pjmlp 9y agoLooking from the outside, but also following everything that comes out of MS and MSR, I think it was a political consequence. There was always the DevTools vs WinDev differences regarding the role of .NET in Windows, and for a while it seemed Microsoft has happy having .NET just be good enough. Thankfully they have changed their mindset and are improving .NET to be as close to C++ as possible, at least for 99% of the use cases where using a GC language is an acceptable trade off.
- alkonaut 9y agoI realize it's a pretty hard problem - and hadn't java already demonstrated the feasibility of it, I would have doubted it to be possible at all without major surgery to both language and runtime (special scoped types etc). So I guess my question is: is there something about C# or .NET that makes it much harder to do escape analysis than it is in Java world? An evil example is class Something { private static readonly Something _inst; public Something() { _inst = this; } } Where the reference leaked just by instantiating it. Does java detect that this escaped the stack? How?
- kkokosa 9y agoI believe it is not difficulty level problem but the fact that due to value types existence in .NET it was ok to live without escape analysis for so many years (like @cpeterso also pointed out).
- pjmlp 9y ago> Does java detect that this escaped the stack? How? There isn't one Java, rather lots of it. So, in what concerns Oracle, there are reports from Oracle Labs that Graal is better than Hotspot on escape analysis. No idea where IBM, Azul, Aicas, microEJ, PTC stand. Even less regarding Android, because not only Google has done their own thing, each OEM also has the freedom to change how ART works. Regarding your actual question, I have this feeling none of them is able to detect it.
- aardvark179 9y agoConstruction is a two step process. The space for something is allocated and then the constructor is called so there isn’t anything magical in that example. It does however also remove half the guarantees about uninitiated object visibility in the java memory model because your leaking the reference inside the constructor.
- matthewwarren 9y agoThis post has a nice investigation into 'Escape Analysis' in Java, https://shipilev.net/jvm-anatomy-park/18-scalar-replacement/ https://shipilev.net/jvm-anatomy-park/18-scalar-replacement/ Shows that the Hotspot doesn't handle it in all scenarios: > But, EA is not ideal: if we cannot statically determine the object is not escaping, we have to assume it does. Complicated control flow may bail earlier. Calling non-inlined — and thus opaque for current analysis — instance method bails. Doing some things that rely on object identity bail, although trivial things like reference comparison with non-escaping objects gets folded efficiently. > This is not an ideal optimization, but when it works, it works magnificently well. Further improvements in compiler technology might widen the number of cases where EA works well.
- alkonaut 9y ago