title: Java VM tuning - Xbatch and -Xcomp
body: <p>I am looking at the JVM configuration options for running Alfresco, mainly <a href="http://wiki.alfresco.com/wiki/JVM_Tuning" rel="noreferrer">this</a> document on the <a href="http://wiki.alfresco.com/wiki/Main_Page" rel="noreferrer">Alfresco Wiki</a>. One of the recommendations is to use the JVM flags <code>-Xcomp</code> and <code>-Xbatch</code>. The justification of this is:</p>
  
  <blockquote>
    <p>If you wish to have Hotspot precompile the classes, you can add [-Xcomp and -Xbatch]. This will, however, significantly increase the server startup time, but will highlight missing dependencies that can be hit later.</p>
  </blockquote>
  
  <p>From what I have <a href="http://blogs.oracle.com/watt/resource/jvm-options-list.html" rel="noreferrer">read elsewhere</a> about the <code>-Xcomp</code> and <code>-Xbatch</code> flags, I am wondering whether they really provide any benefit.</p>
  
  <ul>
  <li><code>-Xcomp</code> gets HotSpot to compile all code beforehand with maximum optimization, thus foregoing any profiling that the VM will get through the standard running of the system.</li>
  <li><code>-Xbatch</code> stops background compiling, meaning the thread which caused the code to be compiled blocks until the compile is complete. However, after the compile is finished, the previously-blocked thread <em>will not run the compiled code</em>, <a href="http://blogs.oracle.com/fatcatair/entry/more_tiered_compilation" rel="noreferrer">it will still run the interpreted code</a>. This was a change in Java 6 (Mustang) – before Mustang, threads blocked for compiling by the presence of the <code>-Xbatch</code> flag were guaranteed to run in the compiled code as soon as the compile was completed. Therefore, I am guessing that the recommendation of the <code>-Xbatch</code> flag is a relic of running Alfresco on older VMs.</li>
  </ul>
  
  <p>Does anyone have any thoughts? My inclination is to get rid of these two flags and rely on the VM to get things right.</p>
  
  <p>I would like to add two things, first of all that I don't yet have access to an Alfresco instance to test this on and secondly I don't really know what spec of machine is hosting Alfresco other than that by looking at the other configuration options it must be a 64 bit VM. Despite this, I hope the community will have some useful input, perhaps from a general HotSpot-tuning point of view.</p>