title: What causes long spin and sync times in Java?
body: <p>In Java 8 Update 45, adding these options to the <code>java</code> call:</p>
  
  <pre><code>-XX:+PrintGCApplicationStoppedTime
  -XX:+PrintSafepointStatistics
  -XX:PrintSafepointStatisticsCount=1
  </code></pre>
  
  <p>shows me statistics like these:</p>
  
  <pre><code>vmop [threads: total initially_running wait_to_block] [time: spin block sync cleanup vmop] page_trap_count
  3679.229: no vm operation [ 72 1 2 ] [ 6016 0 6016 0 0 ]  1
  2015-05-22T11:25:27.519+0200: Total time for which application threads were stopped: 6.0168551 seconds, Stopping threads took: 6.0164099 seconds
  </code></pre>
  
  <p>The problem here is the long time for <code>Stopping threads</code>. In this example, it is 6 seconds which is already a problem for our application, but I have seen even larger times, in one instance (without full logging, though) amounting to almost a minute.</p>
  
  <p>The VM operation (here: <code>no vm operation</code>) is varying. I have also seen, e.g. <code>RevokeBias</code>, <code>G1IncCollectionPause</code>, or <code>GCG_Operation</code>. Also, the <code>page_trap_count</code> seems to be irrelevant. I have seen examples where it was 0, and others where it was 2. Consistent, though, is that the time always is reflected in the values of <code>spin</code> and <code>sync</code>.</p>
  
  <p>I am looking for an in-depth explanation of those timing values <code>spin</code> and <code>sync</code>, but mostly I am interested in why this is happening and what I can do against it. I am not aware of anything 'evil' in our configuration. There are plenty of bored cores and unused memory on the machine, we are running pure Java (no JNI), and we are not aware of any excessive synchronization in our code.</p>