< prev index next >

test/hotspot/jtreg/gc/shenandoah/TestStringDedupStress.java

Print this page
@@ -1,7 +1,8 @@
  /*
   * Copyright (c) 2017, 2021, Red Hat, Inc. All rights reserved.
+  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

@@ -40,10 +41,26 @@
   *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
   *      -XX:-ShenandoahDegeneratedGC
   *      TestStringDedupStress
   */
  
+ /*
+  * @test id=generational
+  * @summary Test Shenandoah string deduplication implementation
+  * @key randomness
+  * @requires vm.gc.Shenandoah
+  * @library /test/lib
+  * @modules java.base/java.lang:open
+  *          java.management
+  *
+  * @run main/othervm -Xmx1g -Xlog:gc+stats -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseStringDeduplication
+  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
+  *      -XX:+ShenandoahDegeneratedGC
+  *      -DtargetStrings=3000000
+  *      TestStringDedupStress
+  */
+ 
  /*
   * @test id=default
   * @summary Test Shenandoah string deduplication implementation
   * @key randomness
   * @requires vm.gc.Shenandoah

@@ -111,11 +128,11 @@
  public class TestStringDedupStress {
      private static Field valueField;
  
      private static final int TARGET_STRINGS = Integer.getInteger("targetStrings", 2_500_000);
      private static final long MAX_REWRITE_GC_CYCLES = 6;
-     private static final long MAX_REWRITE_TIME = 30*1000; // ms
+     private static final long MAX_REWRITE_TIME_NS = 30L * 1_000_000_000L; // 30s in ns
  
      private static final int UNIQUE_STRINGS = 20;
  
      static {
          try {

@@ -209,11 +226,11 @@
          for (int index = 0; index < genIters; index++) {
              generateStrings(astrs, UNIQUE_STRINGS);
          }
  
          long cycleBeforeRewrite = gcCycleMBean.getCollectionCount();
-         long timeBeforeRewrite = System.currentTimeMillis();
+         long timeBeforeRewriteNanos = System.nanoTime();
  
          long loop = 1;
          while (true) {
              int arrSize = astrs.size();
              int index = rn.nextInt(arrSize);

@@ -227,11 +244,11 @@
                  if (gcCycleMBean.getCollectionCount() - cycleBeforeRewrite >= MAX_REWRITE_GC_CYCLES) {
                      break;
                  }
  
                  // enough time is spent waiting for GC to happen
-                 if (System.currentTimeMillis() - timeBeforeRewrite >= MAX_REWRITE_TIME) {
+                 if (System.nanoTime() - timeBeforeRewriteNanos >= MAX_REWRITE_TIME_NS) {
                      break;
                  }
              }
          }
          verifyDedupString(astrs);
< prev index next >