Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8132651

The Performance Difference Between The JDK 7 And JDK 8 Use AtomicLong.incrementA

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_45"
      Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7600]

      A DESCRIPTION OF THE PROBLEM :
      Use the method of AtomicLong.incrementAndGet to test the performance difference between JDK 7 and JDK 8, the test data shows that the performance in JDK7 is better than JDK 8. Why does JDK7 performance is better than JDK 8? What causes the poor performance in JDK 8?
      Test Report:
      The number of threads JDK7(Unit:Milliseconds) JDK8(Unit:Milliseconds)
                      1 441351 444246
                      4 245872 248655
                      8 245872 245395
                     16 275445 279481


      REGRESSION. Last worked in version 7u79

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.7.0_79"
      Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      executor test case

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      JDK8 performance is better than JDK 7
      ACTUAL -
      JDK 7 performance is better than JDK 8

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      JVM parameters:
      JDK 7:
      set JVM_OPT=-Xms1024m -Xmx1024m -Xmn256m -XX:SurvivorRatio=8 -XX:PermSize=128m -XX:MaxPermSize=256m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC
      SET JVM_OPT=%JVM_OPT% -XX:+DisableExplicitGC
      SET JVM_OPT=%JVM_OPT% -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0
       
      set JVM_OPT=%JVM_OPT% -Dthread_count=16
      set JVM_OPT=%JVM_OPT% -Dsize=5
      set JVM_OPT=%JVM_OPT% -Dmax=300000000
       
      JDK 8:
      set JVM_OPT=-Xms1024m -Xmx1024m -Xmn256m -XX:SurvivorRatio=8 -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC
      SET JVM_OPT=%JVM_OPT% -XX:+DisableExplicitGC
      SET JVM_OPT=%JVM_OPT% -XX:+UseFastAccessorMethods -XX:+CMSClassUnloadingEnabled -XX:+CMSParallelRemarkEnabled
      SET JVM_OPT=%JVM_OPT% -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=62
       
      set JVM_OPT=%JVM_OPT% -Dthread_count=16
      set JVM_OPT=%JVM_OPT% -Dsize=5
      set JVM_OPT=%JVM_OPT% -Dmax=300000000
       
      Test code:
      public class Main {
        private static final int K_SIZE = 1024;
        private static final long MAX = 300_000_000L;
       
        public static void main(String[] args) {
       
          int threadCount = Integer.getInteger("thread_count", 4);
          final int size = Integer.getInteger("size", 5);
          final long max = Long.getLong("max", MAX);
       
          final AtomicLong count = new AtomicLong();
       
          final CountDownLatch beginLatch = new CountDownLatch(1);
          final CountDownLatch endLatch = new CountDownLatch(threadCount);
       
          ExecutorService executor = Executors.newFixedThreadPool(threadCount);
       
          for (int i = 0; i < threadCount; i++) {
            executor.execute(new Runnable() {
              ConcurrentMap<Long, Long> map = new ConcurrentHashMap<Long, Long>();
       
              @Override
              public void run() {
                try {
                  beginLatch.await();
       
                           byte[] data = null;
                           while (!Thread.currentThread().isInterrupted()) {
                             data = new byte[size * K_SIZE];
                             long current = count.incrementAndGet();
                             map.put(current, current);
                             data[0] = (byte) current;
                             if (current >= max) {
                               endLatch.countDown();
                                  break;
                             } else if ((current % 1000) == 0) {
                               map.clear();
                             }
                           }
                } catch (InterruptedException e) {
                   Thread.currentThread().interrupt();
                }
              }
           });
         }
       
         long startTime = System.currentTimeMillis();
        beginLatch.countDown();
        try {
          endLatch.await();
          long endTime = System.currentTimeMillis();
          System.out.println(endTime - startTime);
        } catch (InterruptedException e) {
        }
       
        executor.shutdown();
        }
      }
      ---------- END SOURCE ----------

            robm Robert Mckenna
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: