< prev index next >

test/gc/arguments/TestTargetSurvivorRatioFlag.java

Print this page




  29  * @requires (vm.opt.UseJVMCICompiler == null) | (vm.opt.UseJVMCICompiler == false)
  30  * @library /test/lib
  31  * @modules java.base/jdk.internal.misc
  32  *          java.management
  33  * @build sun.hotspot.WhiteBox
  34  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  35  * @run driver TestTargetSurvivorRatioFlag
  36  */
  37 
  38 import java.lang.management.GarbageCollectorMXBean;
  39 import java.util.Arrays;
  40 import java.util.Collections;
  41 import java.util.LinkedList;
  42 import java.util.List;
  43 import java.util.regex.Matcher;
  44 import java.util.regex.Pattern;
  45 import jdk.internal.misc.Unsafe;
  46 import jdk.test.lib.process.OutputAnalyzer;
  47 import jdk.test.lib.process.ProcessTools;
  48 import jdk.test.lib.Utils;
  49 import jdk.test.lib.unsafe.UnsafeHelper;
  50 import sun.hotspot.WhiteBox;
  51 
  52 /* In order to test that TargetSurvivorRatio affects survivor space occupancy
  53  * we setup fixed MaxTenuringThreshold and then verifying that if size of allocated
  54  * objects is lower than (survivor_size * TargetSurvivorRatio / 100) then objects
  55  * will stay in survivor space until MaxTenuringThreshold minor GC cycles.
  56  * If more than (survivor_size * TargetSurvivorRatio / 100) objects were allocated,
  57  * then we verify that after MaxTenuringThreshold minor GC cycles survivor space
  58  * is almost empty.
  59  */
  60 public class TestTargetSurvivorRatioFlag {
  61 
  62     public static final long M = 1024 * 1024;
  63 
  64     // VM option values
  65     public static final long MAX_NEW_SIZE = 40 * M;
  66     public static final int SURVIVOR_RATIO = 8;
  67     public static final int MAX_TENURING_THRESHOLD = 15;
  68 
  69     // Value used to estimate amount of memory that should be allocated


 232                     m.find();
 233                     survivorOccupancy = Long.valueOf(m.group(3));
 234                 } else if (line.contains(END_TEST)) {
 235                     // It is expected to find at least MaxTenuringThreshold GC events
 236                     // until test end
 237                     if (gcCount < MAX_TENURING_THRESHOLD) {
 238                         throw new RuntimeException("Observed " + gcCount + " GC events, "
 239                                 + "while it is expected to see at least "
 240                                 + MAX_TENURING_THRESHOLD);
 241                     }
 242                     testStarted = false;
 243                 }
 244             }
 245         }
 246         return ratios;
 247     }
 248 
 249     public static class TargetSurvivorRatioVerifier {
 250 
 251         static final WhiteBox wb = WhiteBox.getWhiteBox();
 252         static final Unsafe unsafe = UnsafeHelper.getUnsafe();
 253 
 254         // Desired size of memory allocated at once
 255         public static final int CHUNK_SIZE = 1024;
 256         // Length of byte[] array that will have occupy CHUNK_SIZE bytes in heap
 257         public static final int ARRAY_LENGTH = CHUNK_SIZE - Unsafe.ARRAY_BYTE_BASE_OFFSET;
 258 
 259         public static void main(String args[]) throws Exception {
 260             if (args.length != 1) {
 261                 throw new IllegalArgumentException("Expected 1 arg: <ratio>");
 262             }
 263             if (GCTypes.YoungGCType.getYoungGCType() == GCTypes.YoungGCType.PSNew) {
 264                 System.out.println(UNSUPPORTED_GC);
 265                 return;
 266             }
 267 
 268             int ratio = Integer.valueOf(args[0]);
 269             long maxSurvivorSize = getMaxSurvivorSize();
 270             System.out.println("Max survivor size: " + maxSurvivorSize);
 271 
 272             allocateMemory(ratio - DELTA, maxSurvivorSize);




  29  * @requires (vm.opt.UseJVMCICompiler == null) | (vm.opt.UseJVMCICompiler == false)
  30  * @library /test/lib
  31  * @modules java.base/jdk.internal.misc
  32  *          java.management
  33  * @build sun.hotspot.WhiteBox
  34  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  35  * @run driver TestTargetSurvivorRatioFlag
  36  */
  37 
  38 import java.lang.management.GarbageCollectorMXBean;
  39 import java.util.Arrays;
  40 import java.util.Collections;
  41 import java.util.LinkedList;
  42 import java.util.List;
  43 import java.util.regex.Matcher;
  44 import java.util.regex.Pattern;
  45 import jdk.internal.misc.Unsafe;
  46 import jdk.test.lib.process.OutputAnalyzer;
  47 import jdk.test.lib.process.ProcessTools;
  48 import jdk.test.lib.Utils;

  49 import sun.hotspot.WhiteBox;
  50 
  51 /* In order to test that TargetSurvivorRatio affects survivor space occupancy
  52  * we setup fixed MaxTenuringThreshold and then verifying that if size of allocated
  53  * objects is lower than (survivor_size * TargetSurvivorRatio / 100) then objects
  54  * will stay in survivor space until MaxTenuringThreshold minor GC cycles.
  55  * If more than (survivor_size * TargetSurvivorRatio / 100) objects were allocated,
  56  * then we verify that after MaxTenuringThreshold minor GC cycles survivor space
  57  * is almost empty.
  58  */
  59 public class TestTargetSurvivorRatioFlag {
  60 
  61     public static final long M = 1024 * 1024;
  62 
  63     // VM option values
  64     public static final long MAX_NEW_SIZE = 40 * M;
  65     public static final int SURVIVOR_RATIO = 8;
  66     public static final int MAX_TENURING_THRESHOLD = 15;
  67 
  68     // Value used to estimate amount of memory that should be allocated


 231                     m.find();
 232                     survivorOccupancy = Long.valueOf(m.group(3));
 233                 } else if (line.contains(END_TEST)) {
 234                     // It is expected to find at least MaxTenuringThreshold GC events
 235                     // until test end
 236                     if (gcCount < MAX_TENURING_THRESHOLD) {
 237                         throw new RuntimeException("Observed " + gcCount + " GC events, "
 238                                 + "while it is expected to see at least "
 239                                 + MAX_TENURING_THRESHOLD);
 240                     }
 241                     testStarted = false;
 242                 }
 243             }
 244         }
 245         return ratios;
 246     }
 247 
 248     public static class TargetSurvivorRatioVerifier {
 249 
 250         static final WhiteBox wb = WhiteBox.getWhiteBox();
 251         static final Unsafe unsafe = Unsafe.getUnsafe();
 252 
 253         // Desired size of memory allocated at once
 254         public static final int CHUNK_SIZE = 1024;
 255         // Length of byte[] array that will have occupy CHUNK_SIZE bytes in heap
 256         public static final int ARRAY_LENGTH = CHUNK_SIZE - Unsafe.ARRAY_BYTE_BASE_OFFSET;
 257 
 258         public static void main(String args[]) throws Exception {
 259             if (args.length != 1) {
 260                 throw new IllegalArgumentException("Expected 1 arg: <ratio>");
 261             }
 262             if (GCTypes.YoungGCType.getYoungGCType() == GCTypes.YoungGCType.PSNew) {
 263                 System.out.println(UNSUPPORTED_GC);
 264                 return;
 265             }
 266 
 267             int ratio = Integer.valueOf(args[0]);
 268             long maxSurvivorSize = getMaxSurvivorSize();
 269             System.out.println("Max survivor size: " + maxSurvivorSize);
 270 
 271             allocateMemory(ratio - DELTA, maxSurvivorSize);


< prev index next >