zoukankan      html  css  js  c++  java
  • JAVA and .Net Complier Rearrange code lines feature.

    In my previous post. I have been talking about the .Net JIT re-order instructions feature. Actually . In java world . 

    The javac compiler has performs next to no optimisations.

    The JIT native compiler could re-order instructions where there is a memory ordering problem. However, the CPU also can re-order instructions and memory updates which have the same effect.

    What is achieved by allowing this freedm to the compiler ?

    The main benefit is code portability. The more guarantees you provide, the more difficult it is to ensure every platform actually does this.

    There is also a significant performance improvement by allowing the CPU to execute instructions as and when it can rather than in a strict order.

    Is it really possible for the compiler to produce code which is more efficient by rearranging the code ?

    Yes. but the re-ordering done by the CPU is more significant.

    I am yet to see a practical case for this. I feel sometimes that the benefits if any are far outweighed by the concurrency risks this can introduce.

    Is there any way that programmer can tell compiler not to rearrange lines like this ?

    This is why you use memory barriers like volatilesynchronized blocks and Lock. When you use these you get thread safety guarantees.

    I know that using synchronization primitives effectively handles the side-effects of rearranging , but I am asking if there is any direct way ( compiler option ) to turn this off ?

    You can turn off the JIT, but most re-ordering is done by the CPU so it wouldn't achieve much.

    Avoiding re-ordering of updates is such a small part of the thread safety problem (its biggest issue is that is obscure and rarely occurs which makes testing it hard) And once you write thread safe code, this is alleviated.

  • 相关阅读:
    Windows7下面手把手教你安装Django
    windows系统下Python环境的搭建
    PHP、Java、Python、C、C++ 这几种编程语言都各有什么特点或优点
    结构化程序设计 ?
    编译性语言、解释性语言和脚本语言
    在linux中关闭防火墙
    Linux下Apache服务的查看和启动
    AWS中,如果使用了ELB,出现outofservice
    亚马逊的PuTTY连接AWS出现network error connection refused,终极解决方案。
    9.Node.js 包管理器npm
  • 原文地址:https://www.cnblogs.com/malaikuangren/p/2591469.html
Copyright © 2011-2022 走看看