Note that there are some explanatory texts on larger screens.

plurals
  1. POIs JIT reason of this behaviour?
    primarykey
    data
    text
    <p>Inspired by this <a href="https://stackoverflow.com/questions/18460580/is-the-check-thread-safe">question</a>, I wrote the test:</p> <pre><code>public class Main { private static final long TEST_NUMBERS = 5L; private static final long ITERATION_NUMBER = 100000L; private static long value; public static void main(final String [] args) throws Throwable { for(int i=0; i&lt;TEST_NUMBERS; i++) { value = 0; final Thread incrementor = new Thread(new Incrementor()); final Thread checker = new Thread(new Checker()); incrementer.start(); checker.start(); checker.join(); incrementer.join(); } } static class Incrementor implements Runnable { public void run() { for(int i=0; i&lt;ITERATION_NUMBER; i++){ ++value; } } } static class Checker implements Runnable { public void run() { long nonEqualsCount = 0; for(int i=0; i&lt;ITERATION_NUMBER; i++){ if(value != value) { ++nonEqualsCount; } } System.out.println("nonEqualsCount = " + nonEqualsCount); } } } </code></pre> <p>This program are printed in common case:</p> <pre><code>nonEqualsCount = 12; //or other non 0 value; nonEqualsCount = 0; nonEqualsCount = 0; nonEqualsCount = 0; nonEqualsCount = 0; </code></pre> <p>First: I explain this behaviour is presence of the JIT-compiler. JIT-compiler cache value non <code>volatile</code> field for each thread after "warmup". It right?</p> <p>Second: If first right or not right, how can I verify this?</p> <p>P.S. - I know about <strong>PrintAssebly</strong>-option.</p> <p><strong>Update:</strong> enviroment: Windows 7 64bit, JDK 1.7.0_40-b43(Hot Spot).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload