title: JIT - micro optimization - if statement elimination
body: <p>Let's assume we have the following code: </p>
  
  <pre><code>public static void check() {   
      if (Config.initialized) {
             ...
      }
  }
  </code></pre>
  
  <p>Config.initialized is false at the beginning and only changes to true at some point after the method has been JIT compiled already. The value never goes back to false. </p>
  
  <p>I "know" there are a lot of very sophisticated optimizations ongoing (loop-unrolling, branch prediction, inlining, escape analysis, etc) and although I'm far away from understanding all of them in detail I'm mainly interested in the following for now: </p>
  
  <ol>
  <li><p>Does the JIT compiler have a way to detect that the if will always be true after a certain point in time so that the check could be skipped completely? By completely I really mean no variable access, no condition check / jne, etc...  </p></li>
  <li><p>In case there is no way for JIT to get rid of the (from a certain point onwards) unnecessary check from the sample (and I would not know how it could) is there anything I could do to support that? My only idea is to retransform the class and to remove the unnecessary code from the byte code after the initialization event took place. </p></li>
  </ol>
  
  <p>I am aware that this is total micro optimization and probably hard to meassure even using tools like JMH, but I would still like to know and understand.</p>
  
  <p>Last but not least: </p>
  
  <ol start="3">
  <li>Is my understanding correct that if the above method got inlined somewhere that all those methods would be recompiled (assuming they are hot) in case something changes so that the <code>check</code> method needs to be recompiled?</li>
  </ol>
  
  <p>If I understand the results of my JitWatch test correctly the answer to the above questions should be: </p>
  
  <ol>
  <li>No, no way. There will always be a condition check.  </li>
  <li>Really only by transformation </li>
  <li>Yes</li>
  </ol>