Merge
This commit is contained in:
commit
e747db29cd
@ -30,11 +30,9 @@
|
||||
*
|
||||
* @author Mandy Chung
|
||||
*
|
||||
* @build CollectionUsageThreshold MemoryUtil
|
||||
* @run main/othervm/timeout=300 -XX:+PrintGCDetails -XX:+UseSerialGC CollectionUsageThreshold
|
||||
* @run main/othervm/timeout=300 -XX:+PrintGCDetails -XX:+UseParallelGC CollectionUsageThreshold
|
||||
* @run main/othervm/timeout=300 -XX:+PrintGCDetails -XX:+UseG1GC CollectionUsageThreshold
|
||||
* @run main/othervm/timeout=300 -XX:+PrintGCDetails -XX:+UseConcMarkSweepGC CollectionUsageThreshold
|
||||
* @library /lib/testlibrary/
|
||||
* @build CollectionUsageThreshold MemoryUtil RunUtil
|
||||
* @run main/timeout=300 CollectionUsageThreshold
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
@ -61,6 +59,20 @@ public class CollectionUsageThreshold {
|
||||
// finishes checking the low memory notification result
|
||||
private static final CyclicBarrier barrier = new CyclicBarrier(2);
|
||||
|
||||
/**
|
||||
* Run the test multiple times with different GC versions.
|
||||
* First with default command line specified by the framework.
|
||||
* Then with GC versions specified by the test.
|
||||
*/
|
||||
public static void main(String a[]) throws Throwable {
|
||||
final String main = "CollectionUsageThreshold$TestMain";
|
||||
RunUtil.runTestKeepGcOpts(main);
|
||||
RunUtil.runTestClearGcOpts(main, "-XX:+UseSerialGC");
|
||||
RunUtil.runTestClearGcOpts(main, "-XX:+UseParallelGC");
|
||||
RunUtil.runTestClearGcOpts(main, "-XX:+UseG1GC");
|
||||
RunUtil.runTestClearGcOpts(main, "-XX:+UseConcMarkSweepGC");
|
||||
}
|
||||
|
||||
static class PoolRecord {
|
||||
private final MemoryPoolMXBean pool;
|
||||
private final AtomicInteger listenerInvoked = new AtomicInteger(0);
|
||||
@ -110,6 +122,7 @@ public class CollectionUsageThreshold {
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestMain {
|
||||
public static void main(String args[]) throws Exception {
|
||||
if (args.length > 0 && args[0].equals("trace")) {
|
||||
trace = true;
|
||||
@ -179,7 +192,7 @@ public class CollectionUsageThreshold {
|
||||
pr.getPool().setCollectionUsageThreshold(0);
|
||||
}
|
||||
}
|
||||
System.out.println("Test passed.");
|
||||
System.out.println(RunUtil.successMessage);
|
||||
}
|
||||
|
||||
|
||||
@ -195,6 +208,7 @@ public class CollectionUsageThreshold {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class Checker extends Thread {
|
||||
Checker(String name) {
|
||||
|
@ -30,11 +30,9 @@
|
||||
*
|
||||
* @author Mandy Chung
|
||||
*
|
||||
* @build LowMemoryTest MemoryUtil
|
||||
* @run main/othervm/timeout=600 LowMemoryTest
|
||||
* @run main/othervm/timeout=600 -XX:+UseConcMarkSweepGC LowMemoryTest
|
||||
* @run main/othervm/timeout=600 -XX:+UseParallelGC LowMemoryTest
|
||||
* @run main/othervm/timeout=600 -XX:+UseSerialGC LowMemoryTest
|
||||
* @library /lib/testlibrary/
|
||||
* @build LowMemoryTest MemoryUtil RunUtil
|
||||
* @run main/timeout=600 LowMemoryTest
|
||||
*/
|
||||
|
||||
import java.lang.management.*;
|
||||
@ -54,6 +52,20 @@ public class LowMemoryTest {
|
||||
private static final int NUM_CHUNKS = 2;
|
||||
private static long chunkSize;
|
||||
|
||||
/**
|
||||
* Run the test multiple times with different GC versions.
|
||||
* First with default command line specified by the framework.
|
||||
* Then with GC versions specified by the test.
|
||||
*/
|
||||
public static void main(String a[]) throws Throwable {
|
||||
final String main = "LowMemoryTest$TestMain";
|
||||
RunUtil.runTestKeepGcOpts(main);
|
||||
RunUtil.runTestClearGcOpts(main, "-XX:+UseSerialGC");
|
||||
RunUtil.runTestClearGcOpts(main, "-XX:+UseParallelGC");
|
||||
RunUtil.runTestClearGcOpts(main, "-XX:+UseG1GC");
|
||||
RunUtil.runTestClearGcOpts(main, "-XX:+UseConcMarkSweepGC");
|
||||
}
|
||||
|
||||
private static volatile boolean listenerInvoked = false;
|
||||
static class SensorListener implements NotificationListener {
|
||||
@Override
|
||||
@ -107,6 +119,8 @@ public class LowMemoryTest {
|
||||
}
|
||||
|
||||
private static long newThreshold;
|
||||
|
||||
private static class TestMain {
|
||||
public static void main(String args[]) throws Exception {
|
||||
if (args.length > 0 && args[0].equals("trace")) {
|
||||
trace = true;
|
||||
@ -176,9 +190,10 @@ public class LowMemoryTest {
|
||||
if (testFailed)
|
||||
throw new RuntimeException("TEST FAILED.");
|
||||
|
||||
System.out.println("Test passed.");
|
||||
System.out.println(RunUtil.successMessage);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void goSleep(long ms) {
|
||||
try {
|
||||
|
@ -32,11 +32,9 @@
|
||||
* @summary Basic Test for MemoryPool.resetPeakUsage()
|
||||
* @author Mandy Chung
|
||||
*
|
||||
* @build ResetPeakMemoryUsage MemoryUtil
|
||||
* @run main/othervm -XX:+PrintGCDetails -XX:+UseSerialGC -Xms256m -XX:MarkSweepAlwaysCompactCount=1 -Xmn8m ResetPeakMemoryUsage
|
||||
* @run main/othervm -XX:+PrintGCDetails -XX:+UseConcMarkSweepGC -Xms256m -Xmn8m ResetPeakMemoryUsage
|
||||
* @run main/othervm -XX:+PrintGCDetails -XX:+UseParallelGC -Xms256m -Xmn8m ResetPeakMemoryUsage
|
||||
* @run main/othervm -XX:+PrintGCDetails -XX:+UseG1GC -Xms256m -Xmn8m -XX:G1HeapRegionSize=1m ResetPeakMemoryUsage
|
||||
* @library /lib/testlibrary/
|
||||
* @build ResetPeakMemoryUsage MemoryUtil RunUtil
|
||||
* @run main ResetPeakMemoryUsage
|
||||
*/
|
||||
|
||||
import java.lang.management.*;
|
||||
@ -47,6 +45,23 @@ public class ResetPeakMemoryUsage {
|
||||
// make public so that it can't be optimized away easily
|
||||
public static Object[] obj;
|
||||
|
||||
/**
|
||||
* Run the test multiple times with different GC versions.
|
||||
* First with default command line specified by the framework.
|
||||
* Then with all GC versions specified by the test.
|
||||
*/
|
||||
public static void main(String a[]) throws Throwable {
|
||||
final String main = "ResetPeakMemoryUsage$TestMain";
|
||||
final String ms = "-Xms256m";
|
||||
final String mn = "-Xmn8m";
|
||||
RunUtil.runTestClearGcOpts(main, ms, mn, "-XX:+UseConcMarkSweepGC");
|
||||
RunUtil.runTestClearGcOpts(main, ms, mn, "-XX:+UseParallelGC");
|
||||
RunUtil.runTestClearGcOpts(main, ms, mn, "-XX:+UseG1GC", "-XX:G1HeapRegionSize=1m");
|
||||
RunUtil.runTestClearGcOpts(main, ms, mn, "-XX:+UseSerialGC",
|
||||
"-XX:MarkSweepAlwaysCompactCount=1");
|
||||
}
|
||||
|
||||
private static class TestMain {
|
||||
public static void main(String[] argv) {
|
||||
List pools = ManagementFactory.getMemoryPoolMXBeans();
|
||||
ListIterator iter = pools.listIterator();
|
||||
@ -67,6 +82,7 @@ public class ResetPeakMemoryUsage {
|
||||
throw new RuntimeException("No heap pool found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void testPool(MemoryPoolMXBean mpool) {
|
||||
System.out.println("Selected memory pool: ");
|
||||
@ -142,7 +158,7 @@ public class ResetPeakMemoryUsage {
|
||||
formatSize("previous peak", peak2.getUsed()));
|
||||
}
|
||||
|
||||
System.out.println("Test passed.");
|
||||
System.out.println(RunUtil.successMessage);
|
||||
}
|
||||
|
||||
private static String INDENT = " ";
|
||||
|
84
jdk/test/java/lang/management/MemoryMXBean/RunUtil.java
Normal file
84
jdk/test/java/lang/management/MemoryMXBean/RunUtil.java
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Utility class for launching a test in a separate JVM.
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import jdk.testlibrary.OutputAnalyzer;
|
||||
import jdk.testlibrary.Utils;
|
||||
import jdk.testlibrary.ProcessTools;
|
||||
import jdk.testlibrary.JDKToolFinder;
|
||||
|
||||
public class RunUtil {
|
||||
|
||||
// Used to mark that the test has passed successfully.
|
||||
public static final String successMessage = "Test passed.";
|
||||
|
||||
public static void runTestClearGcOpts(String main, String... testOpts) throws Throwable {
|
||||
runTest(main, true, testOpts);
|
||||
}
|
||||
|
||||
public static void runTestKeepGcOpts(String main, String... testOpts) throws Throwable {
|
||||
runTest(main, false, testOpts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a test in a separate JVM.
|
||||
* command line like:
|
||||
* {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
|
||||
*
|
||||
* {defaultopts} are the default java options set by the framework.
|
||||
* Default GC options in {defaultopts} may be removed.
|
||||
* This is used when the test specifies its own GC options.
|
||||
*
|
||||
* @param main Name of the main class.
|
||||
* @param clearGcOpts true if the default GC options should be removed.
|
||||
* @param testOpts java options specified by the test.
|
||||
*/
|
||||
private static void runTest(String main, boolean clearGcOpts, String... testOpts)
|
||||
throws Throwable {
|
||||
List<String> opts = new ArrayList<>();
|
||||
opts.add(JDKToolFinder.getJDKTool("java"));
|
||||
opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
|
||||
opts.add("-cp");
|
||||
opts.add(System.getProperty("test.class.path", "test.class.path"));
|
||||
opts.add("-XX:+PrintGCDetails");
|
||||
|
||||
if (clearGcOpts) {
|
||||
opts = Utils.removeGcOpts(opts);
|
||||
}
|
||||
opts.addAll(Arrays.asList(testOpts));
|
||||
opts.add(main);
|
||||
|
||||
OutputAnalyzer output = ProcessTools.executeProcess(opts.toArray(new String[0]));
|
||||
output.shouldHaveExitValue(0);
|
||||
if (output.getStdout().indexOf(successMessage) < 0) {
|
||||
throw new Exception("output missing '" + successMessage + "'");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -119,6 +119,26 @@ public final class Utils {
|
||||
return opts.toArray(new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any options specifying which GC to use, for example "-XX:+UseG1GC".
|
||||
* Removes any options matching: -XX:(+/-)Use*GC
|
||||
* Used when a test need to set its own GC version. Then any
|
||||
* GC specified by the framework must first be removed.
|
||||
* @return A copy of given opts with all GC options removed.
|
||||
*/
|
||||
private static final Pattern useGcPattern = Pattern.compile("\\-XX\\:[\\+\\-]Use.+GC");
|
||||
public static List<String> removeGcOpts(List<String> opts) {
|
||||
List<String> optsWithoutGC = new ArrayList<String>();
|
||||
for (String opt : opts) {
|
||||
if (useGcPattern.matcher(opt).matches()) {
|
||||
System.out.println("removeGcOpts: removed " + opt);
|
||||
} else {
|
||||
optsWithoutGC.add(opt);
|
||||
}
|
||||
}
|
||||
return optsWithoutGC;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a string by white space.
|
||||
* Works like String.split(), but returns an empty array
|
||||
|
Loading…
Reference in New Issue
Block a user