< prev index next >

test/hotspot/jtreg/gc/z/TestHighUsage.java

Print this page




  57                 System.gc();
  58                 Thread.sleep(2000);
  59             }
  60 
  61             System.out.println("Allocating garbage slowly");
  62 
  63             // Allocate garbage slowly, such that the sampled allocation rate on
  64             // average becomes zero MB/s for the last 1 second windows. If free
  65             // memory goes below the spike limit we induce an allocation spike.
  66             // The expected behavior is that the "High Usage" rule kicks in before
  67             // the spike happens, avoiding an "Allocation Stall".
  68             for (int i = 0; i < 300; i++) {
  69                 final long free = Runtime.getRuntime().freeMemory();
  70                 System.out.println("Free: " + (free / M) + "M");
  71 
  72                 if (free > spikeAt) {
  73                     // Low allocation rate
  74                     dummy = new byte[128 * K];
  75                 } else {
  76                     // High allocation rate








  77                     dummy = new byte[8 * M];
  78                 }
  79 
  80                 Thread.sleep(250);
  81             }
  82 
  83             System.out.println("Done");
  84         }
  85     }
  86 
  87     public static void main(String[] args) throws Exception {
  88         ProcessTools.executeTestJvm(new String[]{ "-XX:+UnlockExperimentalVMOptions",
  89                                                   "-XX:+UseZGC",
  90                                                   "-XX:+UnlockDiagnosticVMOptions",
  91                                                   "-XX:-ZProactive",
  92                                                   "-Xms128M",
  93                                                   "-Xmx128M",
  94                                                   "-XX:ParallelGCThreads=1",
  95                                                   "-XX:ConcGCThreads=1",
  96                                                   "-Xlog:gc",
  97                                                   Test.class.getName() })
  98                     .shouldNotContain("Allocation Stall")
  99                     .shouldContain("High Usage")
 100                     .shouldHaveExitValue(0);
 101     }
 102 }


  57                 System.gc();
  58                 Thread.sleep(2000);
  59             }
  60 
  61             System.out.println("Allocating garbage slowly");
  62 
  63             // Allocate garbage slowly, such that the sampled allocation rate on
  64             // average becomes zero MB/s for the last 1 second windows. If free
  65             // memory goes below the spike limit we induce an allocation spike.
  66             // The expected behavior is that the "High Usage" rule kicks in before
  67             // the spike happens, avoiding an "Allocation Stall".
  68             for (int i = 0; i < 300; i++) {
  69                 final long free = Runtime.getRuntime().freeMemory();
  70                 System.out.println("Free: " + (free / M) + "M");
  71 
  72                 if (free > spikeAt) {
  73                     // Low allocation rate
  74                     dummy = new byte[128 * K];
  75                 } else {
  76                     // High allocation rate
  77 
  78                     // Before inducing an allocation spike, give the GC time to
  79                     // complete a cycle. This is needed in case the test system
  80                     // is starved on CPU, in which case the GC might not otherwise
  81                     // be able to complete a cycle before the allocation spike
  82                     // happens, resulting in an allocation stall.
  83                     Thread.sleep(50000);
  84 
  85                     dummy = new byte[8 * M];
  86                 }
  87 
  88                 Thread.sleep(250);
  89             }
  90 
  91             System.out.println("Done");
  92         }
  93     }
  94 
  95     public static void main(String[] args) throws Exception {
  96         ProcessTools.executeTestJvm(new String[]{ "-XX:+UnlockExperimentalVMOptions",
  97                                                   "-XX:+UseZGC",
  98                                                   "-XX:+UnlockDiagnosticVMOptions",
  99                                                   "-XX:-ZProactive",
 100                                                   "-Xms128M",
 101                                                   "-Xmx128M",
 102                                                   "-XX:ParallelGCThreads=1",
 103                                                   "-XX:ConcGCThreads=1",
 104                                                   "-Xlog:gc,gc+start",
 105                                                   Test.class.getName() })
 106                     .shouldNotContain("Allocation Stall")
 107                     .shouldContain("High Usage")
 108                     .shouldHaveExitValue(0);
 109     }
 110 }
< prev index next >