title: Does Hotspot JVM perform redundancy elimination of casts, unboxing and divisions?
body: <p>For example, in this case</p>
  
  <pre><code>int x;
  for (...) {
      ... some work, y and z not changed
      x = y / z;
      ... some code using x
  }
  </code></pre>
  
  <p>Is JVM (actually JIT compiler) allowed to compute <code>x = y / z</code> once before the <code>for</code> loop and "some work" (with side effects probably or throwing different exceptions), if it couldn't prove that <code>z</code> is non-zero, to throw <code>ArithmeticException</code> at the "right" moment?</p>
  
  <p>The same question about casts (which might result to <code>ClassCastException</code>) and unboxing (which might cause <code>NullPointerException</code>), still assuming in the certain case JVM/JIT compiler cannot prove that the object has appropriate class or unboxed value is non-null.</p>
  
  <p>Upd. <a href="https://stackoverflow.com/users/2164109/morgano">morgano</a> said that this question is devoted to the JVM implementation. In this case, my question is about Hotspot JVM/JIT compiler implementation.</p>