Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/6941923/Test6941923.java
32284 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test Test6941923.java25* @bug 694192326* @summary test flags for gc log rotation27* @library /testlibrary28* @run main/othervm/timeout=600 Test694192329*30*/31import com.oracle.java.testlibrary.*;32import java.io.File;33import java.io.FilenameFilter;34import java.util.ArrayList;35import java.util.Arrays;3637class GCLoggingGenerator {3839public static void main(String[] args) throws Exception {4041long sizeOfLog = Long.parseLong(args[0]);42long lines = sizeOfLog / 80;43// full.GC generates ad least 1-line which is not shorter then 80 chars44// for some GC 2 shorter lines are generated45for (long i = 0; i < lines; i++) {46System.gc();47}48}49}5051public class Test6941923 {5253static final File currentDirectory = new File(".");54static final String logFileName = "test.log";55static final int logFileSizeK = 16;56static FilenameFilter logFilter = new FilenameFilter() {57@Override58public boolean accept(File dir, String name) {59return name.startsWith(logFileName);60}61};6263public static void cleanLogs() {64for (File log : currentDirectory.listFiles(logFilter)) {65if (!log.delete()) {66throw new Error("Unable to delete " + log.getAbsolutePath());67}68}69}7071public static void runTest(int numberOfFiles) throws Exception {7273ArrayList<String> args = new ArrayList();74String[] logOpts = new String[]{75"-cp", System.getProperty("java.class.path"),76"-Xloggc:" + logFileName,77"-XX:-DisableExplicitGC", // to sure that System.gc() works78"-XX:+PrintGC", "-XX:+PrintGCDetails", "-XX:+UseGCLogFileRotation",79"-XX:NumberOfGCLogFiles=" + numberOfFiles,80"-XX:GCLogFileSize=" + logFileSizeK + "K", "-Xmx128M"};81// System.getProperty("test.java.opts") is '' if no options is set82// need to skip such empty83String[] externalVMopts = System.getProperty("test.java.opts").length() == 084? new String[0]85: System.getProperty("test.java.opts").split(" ");86args.addAll(Arrays.asList(externalVMopts));87args.addAll(Arrays.asList(logOpts));88args.add(GCLoggingGenerator.class.getName());89args.add(String.valueOf(numberOfFiles * logFileSizeK * 1024));90ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args.toArray(new String[0]));91pb.redirectErrorStream(true);92pb.redirectOutput(new File(GCLoggingGenerator.class.getName() + ".log"));93Process process = pb.start();94int result = process.waitFor();95if (result != 0) {96throw new Error("Unexpected exit code = " + result);97}98File[] logs = currentDirectory.listFiles(logFilter);99int smallFilesNumber = 0;100for (File log : logs) {101if (log.length() < logFileSizeK * 1024) {102smallFilesNumber++;103}104}105if (logs.length != numberOfFiles) {106throw new Error("There are only " + logs.length + " logs instead " + numberOfFiles);107}108if (smallFilesNumber > 1) {109throw new Error("There should maximum one log with size < " + logFileSizeK + "K");110}111}112113public static void main(String[] args) throws Exception {114cleanLogs();115runTest(1);116cleanLogs();117runTest(3);118cleanLogs();119}120}121122123