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

Shenandoah: Regression caused by ShenandoahLock under extreme contention

XMLWordPrintable

    • gc
    • b12

      We have noticed there is significant regression in at-safepoint time with recent changes made to ShenandoahLock, more specifically this pr https://github.com/openjdk/jdk/pull/19570

      We have written a reproducer which could stably reproduce the issue:
      ```
      import java.util.concurrent.CountDownLatch;
      import java.util.concurrent.Semaphore;

      public class Alloc {
          static final CountDownLatch startSignal = new CountDownLatch(1);
          static final Semaphore semaphore = new Semaphore(128);
          static final int THREADS = 1024; //64 threads per CPU core, 16 cores
          static final Object[] sinks = new Object[64 * THREADS];
          static volatile boolean start;
          static volatile boolean stop;

          private static void waitOnStartSignal() {
              try {
                  startSignal.await();
              } catch (InterruptedException e) {
                  throw new RuntimeException(e);
              }
          }

          public static void main(String... args) throws Throwable {
              for (int t = 0; t < THREADS; t++) {
                  int ft = t;
                  new Thread(() -> work(ft * 64)).start();
              }

              Thread.sleep(1000);
              startSignal.countDown();
              Thread.sleep(30_000);
              stop = true;
          }

          public static void work(int idx) {
              waitOnStartSignal();
              while (!stop) {
                  semaphore.acquireUninterruptibly();
                  try {
                      sinks[idx] = new byte[128];
                  } catch (Throwable ex) {
                      throw new RuntimeException(ex);
                  } finally {
                      semaphore.release();
                  }
              }
          }
      }
      ```
      Run it with command-line below to list top at-safepoint times:
      ```
      java -Xms256m -Xmx256m -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:-ShenandoahPacing -XX:-UseTLAB -Xlog:gc -Xlog:safepoint Alloc.java | grep -Po "At safepoint: \d+ ns" | grep -Po "\d+" | sort -nr
      ```

      test with tip:
      ```
      94069776
      50993550
      49321667
      33903446
      32291313
      30587810
      27759958
      25080997
      24657404
      23874338
      ```

      test result with revert of the https://github.com/openjdk/jdk/pull/19570
      ```
      58428998
      44410618
      30788370
      20636942
      15986465
      15307468
      9686426
      9432094
      7473938
      6854014
      ```

            xpeng Xiaolong Peng
            xpeng Xiaolong Peng
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: