1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 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 package gc.g1.plab.lib; 24 25 import java.util.ArrayList; 26 import java.util.Arrays; 27 import java.util.Collections; 28 import java.util.List; 29 import jdk.test.lib.OutputAnalyzer; 30 import jdk.test.lib.Utils; 31 32 /** 33 * Utilities for PLAB testing. 34 */ 35 public class PLABUtils { 36 37 /** 38 * PLAB tests default options list 39 */ 40 private final static String[] GC_TUNE_OPTIONS = { 41 "-XX:+UseG1GC", 42 "-XX:G1HeapRegionSize=1m", 43 "-XX:OldSize=64m", 44 "-XX:-UseAdaptiveSizePolicy", 45 "-XX:MaxTenuringThreshold=1", 46 "-XX:-UseTLAB", 47 "-XX:SurvivorRatio=1" 48 }; 49 50 /** 51 * GC logging options list. 52 */ 53 private final static String G1_PLAB_LOGGING_OPTIONS[] = { 54 "-Xlog:gc=debug,gc+plab=debug,gc+heap=debug" 55 }; 56 57 /** 58 * List of options required to use WhiteBox. 59 */ 60 private final static String WB_DIAGNOSTIC_OPTIONS[] = { 61 "-Xbootclasspath/a:.", 62 "-XX:+UnlockDiagnosticVMOptions", 63 "-XX:+WhiteBoxAPI" 64 }; 65 66 /** 67 * Prepares options for testing. 68 * 69 * @param options - additional options for testing 70 * @return List of options 71 */ 72 public static List<String> prepareOptions(List<String> options) { 73 if (options == null) { 74 throw new IllegalArgumentException("Options cannot be null"); 75 } 76 List<String> executionOtions = new ArrayList<>( 77 Arrays.asList(Utils.getTestJavaOpts()) 78 ); 79 Collections.addAll(executionOtions, WB_DIAGNOSTIC_OPTIONS); 80 Collections.addAll(executionOtions, G1_PLAB_LOGGING_OPTIONS); 81 Collections.addAll(executionOtions, GC_TUNE_OPTIONS); 82 executionOtions.addAll(options); 83 return executionOtions; 84 } 85 86 /** 87 * Common check for test PLAB application's results. 88 * @param out OutputAnalyzer for checking 89 * @throws RuntimeException 90 */ 91 public static void commonCheck(OutputAnalyzer out) throws RuntimeException { 92 if (out.getExitValue() != 0) { 93 System.out.println(out.getOutput()); 94 throw new RuntimeException("Exit code is not 0"); 95 } 96 // Test expects only WhiteBox initiated GC. 97 out.shouldNotContain("Pause Young (G1 Evacuation Pause)"); 98 } 99 }