< prev index next >

test/gc/g1/mixedgc/TestLogging.java

Print this page




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test TestLogging
  26  * @summary Check that a mixed GC is reflected in the gc logs
  27  * @requires vm.gc=="G1" | vm.gc=="null"
  28  * @library /testlibrary /test/lib
  29  * @ignore 8138607
  30  * @modules java.management
  31  * @build sun.hotspot.WhiteBox gc.g1.mixedgc.TestLogging
  32  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  33  * @run driver gc.g1.mixedgc.TestLogging
  34  */
  35 
  36 package gc.g1.mixedgc;
  37 
  38 import jdk.test.lib.OutputAnalyzer;
  39 import jdk.test.lib.ProcessTools;
  40 import jdk.test.lib.Asserts;
  41 import sun.hotspot.WhiteBox;
  42 
  43 import java.util.ArrayList;
  44 import java.util.List;
  45 import java.util.Collections;
  46 
  47 /**
  48  * Test spawns MixedGCProvoker in a separate VM and expects to find a message
  49  * telling that a mixed gc has happened


  51 public class TestLogging {
  52     private static final String[] COMMON_OPTIONS = new String[]{
  53             "-Xbootclasspath/a:.", "-XX:+UseG1GC",
  54             "-XX:+UnlockExperimentalVMOptions",
  55             "-XX:+UnlockDiagnosticVMOptions",
  56             "-XX:+WhiteBoxAPI",
  57             "-XX:SurvivorRatio=1", // Survivor-to-eden ratio is 1:1
  58             "-Xms10M", "-Xmx10M",
  59             "-XX:MaxTenuringThreshold=1", // promote objects after first gc
  60             "-XX:InitiatingHeapOccupancyPercent=0", // marking cycle happens
  61             // each time
  62             "-XX:G1MixedGCCountTarget=4",
  63             "-XX:MaxGCPauseMillis=30000", // to have enough time
  64             "-XX:G1HeapRegionSize=1m", "-XX:G1HeapWastePercent=0",
  65             "-XX:G1MixedGCLiveThresholdPercent=100"};
  66 
  67     public static final int ALLOCATION_SIZE = 20000;
  68     public static final int ALLOCATION_COUNT = 15;
  69 
  70     public static void main(String args[]) throws Exception {
  71         // Test turns logging on by giving -XX:+PrintGC flag
  72         test("-XX:+PrintGC");
  73         // Test turns logging on by giving -XX:+PrintGCDetails
  74         test("-XX:+PrintGCDetails");
  75     }
  76 
  77     private static void test(String vmFlag) throws Exception {
  78         System.out.println(String.format("%s: running with %s flag", TestLogging.class.getSimpleName(), vmFlag));
  79         OutputAnalyzer output = spawnMixedGCProvoker(vmFlag);
  80         System.out.println(output.getStdout());
  81         output.shouldHaveExitValue(0);
  82         output.shouldContain("GC pause (G1 Evacuation Pause) (mixed)");
  83     }
  84 
  85     /**
  86      * Method spawns MixedGCProvoker with addition flags set
  87      *
  88      * @parameter extraFlags -flags to be added to the common options set
  89      */
  90     private static OutputAnalyzer spawnMixedGCProvoker(String... extraFlags)
  91             throws Exception {
  92         List<String> testOpts = new ArrayList<>();
  93         Collections.addAll(testOpts, COMMON_OPTIONS);
  94         Collections.addAll(testOpts, extraFlags);
  95         testOpts.add(MixedGCProvoker.class.getName());
  96         System.out.println(testOpts);
  97         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(false,
  98                 testOpts.toArray(new String[testOpts.size()]));
  99         return new OutputAnalyzer(pb.start());
 100     }
 101 }
 102 




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test TestLogging
  26  * @summary Check that a mixed GC is reflected in the gc logs
  27  * @requires vm.gc=="G1" | vm.gc=="null"
  28  * @library /testlibrary /test/lib

  29  * @modules java.management
  30  * @build sun.hotspot.WhiteBox gc.g1.mixedgc.TestLogging
  31  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  32  * @run driver gc.g1.mixedgc.TestLogging
  33  */
  34 
  35 package gc.g1.mixedgc;
  36 
  37 import jdk.test.lib.OutputAnalyzer;
  38 import jdk.test.lib.ProcessTools;
  39 import jdk.test.lib.Asserts;
  40 import sun.hotspot.WhiteBox;
  41 
  42 import java.util.ArrayList;
  43 import java.util.List;
  44 import java.util.Collections;
  45 
  46 /**
  47  * Test spawns MixedGCProvoker in a separate VM and expects to find a message
  48  * telling that a mixed gc has happened


  50 public class TestLogging {
  51     private static final String[] COMMON_OPTIONS = new String[]{
  52             "-Xbootclasspath/a:.", "-XX:+UseG1GC",
  53             "-XX:+UnlockExperimentalVMOptions",
  54             "-XX:+UnlockDiagnosticVMOptions",
  55             "-XX:+WhiteBoxAPI",
  56             "-XX:SurvivorRatio=1", // Survivor-to-eden ratio is 1:1
  57             "-Xms10M", "-Xmx10M",
  58             "-XX:MaxTenuringThreshold=1", // promote objects after first gc
  59             "-XX:InitiatingHeapOccupancyPercent=0", // marking cycle happens
  60             // each time
  61             "-XX:G1MixedGCCountTarget=4",
  62             "-XX:MaxGCPauseMillis=30000", // to have enough time
  63             "-XX:G1HeapRegionSize=1m", "-XX:G1HeapWastePercent=0",
  64             "-XX:G1MixedGCLiveThresholdPercent=100"};
  65 
  66     public static final int ALLOCATION_SIZE = 20000;
  67     public static final int ALLOCATION_COUNT = 15;
  68 
  69     public static void main(String args[]) throws Exception {
  70         // Test turns logging on by giving -Xlog:gc flag
  71         test("-Xlog:gc");
  72         // Test turns logging on by giving -Xlog:gc=debug flag
  73         test("-Xlog:gc=debug");
  74     }
  75 
  76     private static void test(String vmFlag) throws Exception {
  77         System.out.println(String.format("%s: running with %s flag", TestLogging.class.getSimpleName(), vmFlag));
  78         OutputAnalyzer output = spawnMixedGCProvoker(vmFlag);
  79         System.out.println(output.getStdout());
  80         output.shouldHaveExitValue(0);
  81         output.shouldContain("Pause Mixed (G1 Evacuation Pause)");
  82     }
  83 
  84     /**
  85      * Method spawns MixedGCProvoker with addition flags set
  86      *
  87      * @parameter extraFlags -flags to be added to the common options set
  88      */
  89     private static OutputAnalyzer spawnMixedGCProvoker(String... extraFlags)
  90             throws Exception {
  91         List<String> testOpts = new ArrayList<>();
  92         Collections.addAll(testOpts, COMMON_OPTIONS);
  93         Collections.addAll(testOpts, extraFlags);
  94         testOpts.add(MixedGCProvoker.class.getName());
  95         System.out.println(testOpts);
  96         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(false,
  97                 testOpts.toArray(new String[testOpts.size()]));
  98         return new OutputAnalyzer(pb.start());
  99     }
 100 }
 101 


< prev index next >