是否CLR执行"锁省略"优化?如果不是,为什么不呢? [英] Does the CLR perform "lock elision" optimization? If not why not?

查看:100
本文介绍了是否CLR执行"锁省略"优化?如果不是,为什么不呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JVM执行一个巧妙的名为锁省略以避免锁定在仅可见的一个线程对象的成本。

The JVM performs a neat trick called lock elision to avoid the cost of locking on objects that are only visible to one thread.

有诀窍的一个很好的描述在这里:

There's a good description of the trick here:

<一个href="http://www.ibm.com/developerworks/java/library/j-jtp10185/">http://www.ibm.com/developerworks/java/library/j-jtp10185/

请问.NET CLR做类似的事情?如果没有,那么为什么不呢?

Does the .Net CLR do something similar? If not then why not?

推荐答案

它的整洁,但它有用吗?我也很难想出一个例子,编译器可以证明一个锁线程本地。几乎所有的类不使用默认的锁定,当你选择一个锁,那么在大多数情况下,它会从某种静态变量反正挫败编译器的优化引用。

It's neat, but is it useful? I have a hard time coming up with an example where the compiler can prove that a lock is thread local. Almost all classes don't use locking by default, and when you choose one that locks, then in most cases it will be referenced from some kind of static variable foiling the compiler optimization anyways.

另一件事是,Java虚拟机使用转义分析它的证明。而AFAIK .NET并没有实现逃逸分析。逃逸分析的其他用途,如用堆栈分配取代堆分配的声音更有益的,应先执行。

Another thing is that the java vm uses escape analysis in its proof. And AFAIK .net hasn't implemented escape analysis. Other uses of escape analysis such as replacing heap allocations with stack allocations sound much more useful and should be implemented first.

国际海事组织它目前不值得的编码工作。有许多地区在.NET VM这是不是最优化的非常好,并有更大的​​影响。

IMO it's currently not worth the coding effort. There are many areas in the .net VM which are not optimized very well and have much bigger impact.

SSE向量指令和委托内联是两个例子从我的code将受益比这种优化等等。

SSE vector instructions and delegate inlining are two examples from which my code would profit much more than from this optimization.

这篇关于是否CLR执行&QUOT;锁省略&QUOT;优化?如果不是,为什么不呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆