test/gc/6941923/Test6941923.java

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 */
aoqi@0 23
aoqi@0 24 /*
aoqi@0 25 * @test Test6941923.java
aoqi@0 26 * @bug 6941923
aoqi@0 27 * @summary test flags for gc log rotation
aoqi@0 28 * @library /testlibrary
aoqi@0 29 * @run main/othervm/timeout=600 Test6941923
aoqi@0 30 *
aoqi@0 31 */
aoqi@0 32 import com.oracle.java.testlibrary.*;
aoqi@0 33 import java.io.File;
aoqi@0 34 import java.io.FilenameFilter;
aoqi@0 35 import java.util.ArrayList;
aoqi@0 36 import java.util.Arrays;
aoqi@0 37
aoqi@0 38 class GCLoggingGenerator {
aoqi@0 39
aoqi@0 40 public static void main(String[] args) throws Exception {
aoqi@0 41
aoqi@0 42 long sizeOfLog = Long.parseLong(args[0]);
aoqi@0 43 long lines = sizeOfLog / 80;
aoqi@0 44 // full.GC generates ad least 1-line which is not shorter then 80 chars
aoqi@0 45 // for some GC 2 shorter lines are generated
aoqi@0 46 for (long i = 0; i < lines; i++) {
aoqi@0 47 System.gc();
aoqi@0 48 }
aoqi@0 49 }
aoqi@0 50 }
aoqi@0 51
aoqi@0 52 public class Test6941923 {
aoqi@0 53
aoqi@0 54 static final File currentDirectory = new File(".");
aoqi@0 55 static final String logFileName = "test.log";
aoqi@0 56 static final int logFileSizeK = 16;
aoqi@0 57 static FilenameFilter logFilter = new FilenameFilter() {
aoqi@0 58 @Override
aoqi@0 59 public boolean accept(File dir, String name) {
aoqi@0 60 return name.startsWith(logFileName);
aoqi@0 61 }
aoqi@0 62 };
aoqi@0 63
aoqi@0 64 public static void cleanLogs() {
aoqi@0 65 for (File log : currentDirectory.listFiles(logFilter)) {
aoqi@0 66 if (!log.delete()) {
aoqi@0 67 throw new Error("Unable to delete " + log.getAbsolutePath());
aoqi@0 68 }
aoqi@0 69 }
aoqi@0 70 }
aoqi@0 71
aoqi@0 72 public static void runTest(int numberOfFiles) throws Exception {
aoqi@0 73
aoqi@0 74 ArrayList<String> args = new ArrayList();
aoqi@0 75 String[] logOpts = new String[]{
aoqi@0 76 "-cp", System.getProperty("java.class.path"),
aoqi@0 77 "-Xloggc:" + logFileName,
aoqi@0 78 "-XX:-DisableExplicitGC", // to sure that System.gc() works
aoqi@0 79 "-XX:+PrintGC", "-XX:+PrintGCDetails", "-XX:+UseGCLogFileRotation",
aoqi@0 80 "-XX:NumberOfGCLogFiles=" + numberOfFiles,
aoqi@0 81 "-XX:GCLogFileSize=" + logFileSizeK + "K", "-Xmx128M"};
aoqi@0 82 // System.getProperty("test.java.opts") is '' if no options is set
aoqi@0 83 // need to skip such empty
aoqi@0 84 String[] externalVMopts = System.getProperty("test.java.opts").length() == 0
aoqi@0 85 ? new String[0]
aoqi@0 86 : System.getProperty("test.java.opts").split(" ");
aoqi@0 87 args.addAll(Arrays.asList(externalVMopts));
aoqi@0 88 args.addAll(Arrays.asList(logOpts));
aoqi@0 89 args.add(GCLoggingGenerator.class.getName());
aoqi@0 90 args.add(String.valueOf(numberOfFiles * logFileSizeK * 1024));
aoqi@0 91 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args.toArray(new String[0]));
aoqi@0 92 pb.redirectErrorStream(true);
aoqi@0 93 pb.redirectOutput(new File(GCLoggingGenerator.class.getName() + ".log"));
aoqi@0 94 Process process = pb.start();
aoqi@0 95 int result = process.waitFor();
aoqi@0 96 if (result != 0) {
aoqi@0 97 throw new Error("Unexpected exit code = " + result);
aoqi@0 98 }
aoqi@0 99 File[] logs = currentDirectory.listFiles(logFilter);
aoqi@0 100 int smallFilesNumber = 0;
aoqi@0 101 for (File log : logs) {
aoqi@0 102 if (log.length() < logFileSizeK * 1024) {
aoqi@0 103 smallFilesNumber++;
aoqi@0 104 }
aoqi@0 105 }
aoqi@0 106 if (logs.length != numberOfFiles) {
aoqi@0 107 throw new Error("There are only " + logs.length + " logs instead " + numberOfFiles);
aoqi@0 108 }
aoqi@0 109 if (smallFilesNumber > 1) {
aoqi@0 110 throw new Error("There should maximum one log with size < " + logFileSizeK + "K");
aoqi@0 111 }
aoqi@0 112 }
aoqi@0 113
aoqi@0 114 public static void main(String[] args) throws Exception {
aoqi@0 115 cleanLogs();
aoqi@0 116 runTest(1);
aoqi@0 117 cleanLogs();
aoqi@0 118 runTest(3);
aoqi@0 119 cleanLogs();
aoqi@0 120 }
aoqi@0 121 }

mercurial