Search code examples
jvmjvm-hotspotjvm-arguments

JVM C1 and C2 Compile Time Benchmark


I have simple hello world program, and set -XX:TieredStopAtLevel=[0 to 4]. I understand the basic difference how it uses either interpreter or C1 or C2 or both C1 and C2 to compile code.

I'd like to know real benchmark details to know compile time, and others details if i use different numbers.


Solution

  • To benchmark JIT compilers, use -Xcomp to force compilation of all executed methods, and check CompilationMXBean.getTotalCompilationTime to find the total time spent in JIT compilation.

    Example

    import java.lang.management.ManagementFactory;
    
    public class CompilationTime {
    
        public static void main(String[] args) throws Exception {
            System.out.println(ManagementFactory.getCompilationMXBean().getTotalCompilationTime());
        }
    }
    

    C1

    $ java -Xcomp -XX:TieredStopAtLevel=1 CompilationTime
    162  // milliseconds
    

    C2

    $ java -Xcomp -XX:-TieredCompilation CompilationTime
    1129  // milliseconds