This commit is contained in:
Igor Ignatyev 2017-04-22 00:56:56 +00:00
commit 8d3d4753ec
19 changed files with 902 additions and 19 deletions

View File

@ -43,6 +43,7 @@ $(eval $(call IncludeCustomExtension, hotspot, test/JtregNative.gmk))
# Add more directories here when needed.
BUILD_HOTSPOT_JTREG_NATIVE_SRC += \
$(HOTSPOT_TOPDIR)/test/gc/stress/gclocker \
$(HOTSPOT_TOPDIR)/test/native_sanity \
$(HOTSPOT_TOPDIR)/test/runtime/jni/8025979 \
$(HOTSPOT_TOPDIR)/test/runtime/jni/8033445 \

View File

@ -130,7 +130,10 @@ hotspot_tier1_gc_closed = \
sanity/ExecuteInternalVMTests.java
hotspot_tier1_gc_gcold = \
gc/stress/TestGCOld.java
gc/stress/gcold/TestGCOldWithG1.java
gc/stress/gcold/TestGCOldWithCMS.java
gc/stress/gcold/TestGCOldWithSerial.java
gc/stress/gcold/TestGCOldWithParallel.java
hotspot_tier1_gc_gcbasher = \
gc/stress/gcbasher/TestGCBasherWithG1.java \

View File

@ -0,0 +1,224 @@
/*
* Copyright (c) 2017, 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.
*
*/
// Stress the GC locker by calling GetPrimitiveArrayCritical while
// concurrently filling up old gen.
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryUsage;
import java.nio.ByteBuffer;
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
final class ThreadUtils {
public static void sleep(long durationMS) {
try {
Thread.sleep(durationMS);
} catch (Exception e) {
}
}
}
class Filler {
private static final int SIZE = 250000;
private int[] i1 = new int[SIZE];
private int[] i2 = new int[SIZE];
private short[] s1 = new short[SIZE];
private short[] s2 = new short[SIZE];
private Map<Object, Object> map = new HashMap<>();
public Filler() {
for (int i = 0; i < 10000; i++) {
map.put(new Object(), new Object());
}
}
}
class Exitable {
private volatile boolean shouldExit = false;
protected boolean shouldExit() {
return shouldExit;
}
public void exit() {
shouldExit = true;
}
}
class MemoryWatcher {
private MemoryPoolMXBean bean;
private final int thresholdPromille = 750;
private final int criticalThresholdPromille = 800;
private final int minGCWaitMS = 1000;
private final int minFreeWaitElapsedMS = 30000;
private final int minFreeCriticalWaitMS = 500;
private int lastUsage = 0;
private long lastGCDetected = System.currentTimeMillis();
private long lastFree = System.currentTimeMillis();
public MemoryWatcher(String mxBeanName) {
List<MemoryPoolMXBean> memoryBeans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean bean : memoryBeans) {
if (bean.getName().equals(mxBeanName)) {
this.bean = bean;
break;
}
}
}
private int getMemoryUsage() {
if (bean == null) {
Runtime r = Runtime.getRuntime();
float free = (float) r.freeMemory() / r.maxMemory();
return Math.round((1 - free) * 1000);
} else {
MemoryUsage usage = bean.getUsage();
float used = (float) usage.getUsed() / usage.getCommitted();
return Math.round(used * 1000);
}
}
public synchronized boolean shouldFreeUpSpace() {
int usage = getMemoryUsage();
long now = System.currentTimeMillis();
boolean detectedGC = false;
if (usage < lastUsage) {
lastGCDetected = now;
detectedGC = true;
}
lastUsage = usage;
long elapsed = now - lastFree;
long timeSinceLastGC = now - lastGCDetected;
if (usage > criticalThresholdPromille && elapsed > minFreeCriticalWaitMS) {
lastFree = now;
return true;
} else if (usage > thresholdPromille && !detectedGC) {
if (elapsed > minFreeWaitElapsedMS || timeSinceLastGC > minGCWaitMS) {
lastFree = now;
return true;
}
}
return false;
}
}
class MemoryUser extends Exitable implements Runnable {
private final Queue<Filler> cache = new ArrayDeque<Filler>();
private final MemoryWatcher watcher;
private void load() {
if (watcher.shouldFreeUpSpace()) {
int toRemove = cache.size() / 5;
for (int i = 0; i < toRemove; i++) {
cache.remove();
}
}
cache.add(new Filler());
}
public MemoryUser(String mxBeanName) {
watcher = new MemoryWatcher(mxBeanName);
}
@Override
public void run() {
for (int i = 0; i < 200; i++) {
load();
}
while (!shouldExit()) {
load();
}
}
}
class GCLockerStresser extends Exitable implements Runnable {
static native void fillWithRandomValues(byte[] array);
@Override
public void run() {
byte[] array = new byte[1024 * 1024];
while (!shouldExit()) {
fillWithRandomValues(array);
}
}
}
public class TestGCLocker {
private static Exitable startGCLockerStresser(String name) {
GCLockerStresser task = new GCLockerStresser();
Thread thread = new Thread(task);
thread.setName(name);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
return task;
}
private static Exitable startMemoryUser(String mxBeanName) {
MemoryUser task = new MemoryUser(mxBeanName);
Thread thread = new Thread(task);
thread.setName("Memory User");
thread.start();
return task;
}
public static void main(String[] args) {
System.loadLibrary("TestGCLocker");
long durationMinutes = args.length > 0 ? Long.parseLong(args[0]) : 5;
String mxBeanName = args.length > 1 ? args[1] : null;
long startMS = System.currentTimeMillis();
Exitable stresser1 = startGCLockerStresser("GCLockerStresser1");
Exitable stresser2 = startGCLockerStresser("GCLockerStresser2");
Exitable memoryUser = startMemoryUser(mxBeanName);
long durationMS = durationMinutes * 60 * 1000;
while ((System.currentTimeMillis() - startMS) < durationMS) {
ThreadUtils.sleep(10 * 1010);
}
stresser1.exit();
stresser2.exit();
memoryUser.exit();
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2017, 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.
*
*/
/*
* @test TestGCLockerWithCMS
* @key gc
* @requires vm.gc.ConcMarkSweep
* @summary Stress CMS' GC locker by calling GetPrimitiveArrayCritical while concurrently filling up old gen.
* @run main/native/othervm/timeout=200 -Xlog:gc*=info -Xms1500m -Xmx1500m -XX:+UseConcMarkSweepGC TestGCLockerWithCMS
*/
public class TestGCLockerWithCMS {
public static void main(String[] args) {
String[] testArgs = {"2", "CMS Old Gen"};
TestGCLocker.main(testArgs);
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2017, 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.
*
*/
/*
* @test TestGCLockerWithG1
* @key gc
* @requires vm.gc.G1
* @summary Stress G1's GC locker by calling GetPrimitiveArrayCritical while concurrently filling up old gen.
* @run main/native/othervm/timeout=200 -Xlog:gc*=info -Xms1500m -Xmx1500m -XX:+UseG1GC TestGCLockerWithG1
*/
public class TestGCLockerWithG1 {
public static void main(String[] args) {
String[] testArgs = {"2", "G1 Old Gen"};
TestGCLocker.main(testArgs);
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2017, 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.
*
*/
/*
* @test TestGCLockerWithParallel
* @key gc
* @requires vm.gc.Parallel
* @summary Stress Parallel's GC locker by calling GetPrimitiveArrayCritical while concurrently filling up old gen.
* @run main/native/othervm/timeout=200 -Xlog:gc*=info -Xms1500m -Xmx1500m -XX:+UseParallelGC TestGCLockerWithParallel
*/
public class TestGCLockerWithParallel {
public static void main(String[] args) {
String[] testArgs = {"2", "PS Old Gen"};
TestGCLocker.main(testArgs);
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2017, 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.
*
*/
/*
* @test TestGCLockerWithSerial
* @key gc
* @requires vm.gc.Serial
* @summary Stress Serial's GC locker by calling GetPrimitiveArrayCritical while concurrently filling up old gen.
* @run main/native/othervm/timeout=200 -Xlog:gc*=info -Xmx1500m -Xmx1500m -XX:+UseSerialGC TestGCLockerWithSerial
*/
public class TestGCLockerWithSerial {
public static void main(String[] args) {
String[] testArgs = {"2", "Tenured Gen"};
TestGCLocker.main(testArgs);
}
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2017, 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.
*/
#include <jni.h>
JNIEXPORT void JNICALL
Java_GCLockerStresser_fillWithRandomValues(JNIEnv* env, jclass clz, jbyteArray arr) {
jsize size = (*env)->GetArrayLength(env, arr);
jbyte* p = (*env)->GetPrimitiveArrayCritical(env, arr, NULL);
jsize i;
for (i = 0; i < size; i++) {
p[i] = i % 128;
}
(*env)->ReleasePrimitiveArrayCritical(env, arr, p, 0);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2017, 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
@ -21,21 +21,6 @@
* questions.
*/
/*
* @test TestGCOld
* @key gc
* @key stress
* @requires vm.gc=="null"
* @summary Stress the GC by trying to make old objects more likely to be garbage than young objects.
* @run main/othervm -Xmx384M -XX:+UseSerialGC TestGCOld 50 1 20 10 10000
* @run main/othervm -Xmx384M -XX:+UseParallelGC TestGCOld 50 1 20 10 10000
* @run main/othervm -Xmx384M -XX:+UseParallelGC -XX:-UseParallelOldGC TestGCOld 50 1 20 10 10000
* @run main/othervm -Xmx384M -XX:+UseConcMarkSweepGC TestGCOld 50 1 20 10 10000
* @run main/othervm -Xmx384M -XX:+UseG1GC TestGCOld 50 1 20 10 10000
* @run main/othervm -Xms64m -Xmx128m -XX:+UseG1GC -XX:+UseDynamicNumberOfGCThreads -Xlog:gc,gc+task=trace TestGCOld 50 5 20 1 5000
* @run main/othervm -Xms64m -Xmx128m -XX:+UseG1GC -XX:+UseDynamicNumberOfGCThreads -XX:+UnlockDiagnosticVMOptions -XX:+InjectGCWorkerCreationFailure -Xlog:gc,gc+task=trace TestGCOld 50 5 20 1 5000
*/
import java.text.*;
import java.util.Random;

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2017, 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.
*
*/
/*
* @test TestGCOldWithCMS
* @key gc
* @requires vm.gc.ConcMarkSweep
* @summary Stress the CMS GC by trying to make old objects more likely to be garbage than young objects.
* @run main/othervm -Xmx384M -XX:+UseConcMarkSweepGC TestGCOldWithCMS 50 1 20 10 10000
*/
public class TestGCOldWithCMS {
public static void main(String[] args) {
TestGCOld.main(args);
}
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2017, 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.
*
*/
/*
* @test TestGCOldWithG1
* @key gc
* @requires vm.gc.G1
* @summary Stress the G1 GC by trying to make old objects more likely to be garbage than young objects.
* @run main/othervm -Xmx384M -XX:+UseG1GC TestGCOldWithG1 50 1 20 10 10000
* @run main/othervm -Xms64m -Xmx128m -XX:+UseG1GC -XX:+UseDynamicNumberOfGCThreads -Xlog:gc,gc+task=trace TestGCOldWithG1 50 5 20 1 5000
* @run main/othervm -Xms64m -Xmx128m -XX:+UseG1GC -XX:+UseDynamicNumberOfGCThreads -XX:+UnlockDiagnosticVMOptions -XX:+InjectGCWorkerCreationFailure -Xlog:gc,gc+task=trace TestGCOldWithG1 50 5 20 1 5000
*/
public class TestGCOldWithG1 {
public static void main(String[] args) {
TestGCOld.main(args);
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2017, 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.
*
*/
/*
* @test TestGCOldWithParallel
* @key gc
* @requires vm.gc.Parallel
* @summary Stress the Parallel GC by trying to make old objects more likely to be garbage than young objects.
* @run main/othervm -Xmx384M -XX:+UseParallelGC TestGCOld 50 1 20 10 10000
* @run main/othervm -Xmx384M -XX:+UseParallelGC -XX:-UseParallelOldGC TestGCOld 50 1 20 10 10000
*/
public class TestGCOldWithParallel {
public static void main(String[] args) {
TestGCOld.main(args);
}
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2017, 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.
*
*/
/*
* @test TestGCOldWithSerial
* @key gc
* @requires vm.gc.Serial
* @summary Stress the Serial GC by trying to make old objects more likely to be garbage than young objects.
* @run main/othervm -Xmx384M -XX:+UseSerialGC TestGCOldWithSerial 50 1 20 10 10000
*/
public class TestGCOldWithSerial {
public static void main(String[] args) {
TestGCOld.main(args);
}
}

View File

@ -0,0 +1,190 @@
/*
* Copyright (c) 2017, 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.
*/
// A test that stresses a full GC by allocating objects of different lifetimes
// and concurrently calling System.gc().
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
final class ThreadUtils {
public static void sleep(long durationMS) {
try {
Thread.sleep(durationMS);
} catch (Exception e) {
}
}
}
class Exitable {
private volatile boolean shouldExit = false;
protected boolean shouldExit() {
return shouldExit;
}
public void exit() {
shouldExit = true;
}
}
class ShortLivedAllocationTask extends Exitable implements Runnable {
private Map<String, String> map = new HashMap<>();
@Override
public void run() {
map = new HashMap<>();
while (!shouldExit()) {
for (int i = 0; i < 200; i++) {
String key = "short" + " key = " + i;
String value = "the value is " + i;
map.put(key, value);
}
}
}
}
class LongLivedAllocationTask extends Exitable implements Runnable {
private Map<String, String> map;
LongLivedAllocationTask(Map<String, String> map) {
this.map = map;
}
@Override
public void run() {
while (!shouldExit()) {
String prefix = "long" + System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
String key = prefix + " key = " + i;
String value = "the value is " + i;
map.put(key, value);
}
}
}
}
class SystemGCTask extends Exitable implements Runnable {
private long delayMS;
SystemGCTask(long delayMS) {
this.delayMS = delayMS;
}
@Override
public void run() {
while (!shouldExit()) {
System.gc();
ThreadUtils.sleep(delayMS);
}
}
}
public class TestSystemGC {
private static final int numGroups = 7;
private static final int numGCsPerGroup = 4;
private static Map<String, String> longLivedMap = new TreeMap<>();
private static void populateLongLived() {
for (int i = 0; i < 1000000; i++) {
String key = "all" + " key = " + i;
String value = "the value is " + i;
longLivedMap.put(key, value);
}
}
private static long getDelayMS(int group) {
if (group == 0) {
return 0;
}
int res = 16;
for (int i = 0; i < group; i++) {
res *= 2;
}
return res;
}
private static void doSystemGCs() {
ThreadUtils.sleep(1000);
for (int i = 0; i < numGroups; i++) {
for (int j = 0; j < numGCsPerGroup; j++) {
System.gc();
ThreadUtils.sleep(getDelayMS(i));
}
}
}
private static SystemGCTask createSystemGCTask(int group) {
long delay0 = getDelayMS(group);
long delay1 = getDelayMS(group + 1);
long delay = delay0 + (delay1 - delay0) / 2;
return new SystemGCTask(delay);
}
private static void startTask(Runnable task) {
if (task != null) {
new Thread(task).start();
}
}
private static void exitTask(Exitable task) {
if (task != null) {
task.exit();
}
}
private static void runAllPhases() {
for (int i = 0; i < 4; i++) {
SystemGCTask gcTask =
(i % 2 == 1) ? createSystemGCTask(numGroups / 3) : null;
ShortLivedAllocationTask shortTask =
(i == 1 || i == 3) ? new ShortLivedAllocationTask() : null;
LongLivedAllocationTask longTask =
(i == 2 || i == 3) ? new LongLivedAllocationTask(longLivedMap) : null;
startTask(gcTask);
startTask(shortTask);
startTask(longTask);
doSystemGCs();
exitTask(gcTask);
exitTask(shortTask);
exitTask(longTask);
ThreadUtils.sleep(1000);
}
}
public static void main(String[] args) {
// First allocate the long lived objects and then run all phases twice.
populateLongLived();
runAllPhases();
runAllPhases();
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2017, 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.
*
*/
/*
* @test TestSystemGCWithCMS
* @key gc
* @key stress
* @requires vm.gc.ConcMarkSweep
* @summary Stress the CMS GC full GC by allocating objects of different lifetimes concurrently with System.gc().
* @run main/othervm/timeout=300 -Xlog:gc*=info -Xmx512m -XX:+UseConcMarkSweepGC TestSystemGCWithCMS
*/
public class TestSystemGCWithCMS {
public static void main(String[] args) {
TestSystemGC.main(args);
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2017, 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.
*
*/
/*
* @test TestSystemGCWithG1
* @key gc
* @key stress
* @requires vm.gc.G1
* @summary Stress the G1 GC full GC by allocating objects of different lifetimes concurrently with System.gc().
* @run main/othervm/timeout=300 -Xlog:gc*=info -Xmx512m -XX:+UseG1GC TestSystemGCWithG1
*/
public class TestSystemGCWithG1 {
public static void main(String[] args) {
TestSystemGC.main(args);
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2017, 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.
*
*/
/*
* @test TestSystemGCWithParallel
* @key gc
* @key stress
* @requires vm.gc.Parallel
* @summary Stress the Parallel GC full GC by allocating objects of different lifetimes concurrently with System.gc().
* @run main/othervm/timeout=300 -Xlog:gc*=info -Xmx512m -XX:+UseParallelGC TestSystemGCWithParallel
*/
public class TestSystemGCWithParallel {
public static void main(String[] args) {
TestSystemGC.main(args);
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2017, 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.
*
*/
/*
* @test TestSystemGCWithSerial
* @key gc
* @key stress
* @requires vm.gc.Serial
* @summary Stress the Serial GC full GC by allocating objects of different lifetimes concurrently with System.gc().
* @run main/othervm/timeout=300 -Xlog:gc*=info -Xmx512m -XX:+UseSerialGC TestSystemGCWithSerial
*/
public class TestSystemGCWithSerial {
public static void main(String[] args) {
TestSystemGC.main(args);
}
}

View File

@ -62,6 +62,8 @@ public class TestInterpreterMethodEntries {
}
private static void dumpAndUseSharedArchive(String dump, String use) throws Exception {
String unlock = "-XX:+UnlockDiagnosticVMOptions";
String dumpFMA = "-XX:" + dump + "UseFMA";
String dumpCRC32 = "-XX:" + dump + "UseCRC32Intrinsics";
String dumpCRC32C = "-XX:" + dump + "UseCRC32CIntrinsics";
@ -69,10 +71,10 @@ public class TestInterpreterMethodEntries {
String useCRC32 = "-XX:" + use + "UseCRC32Intrinsics";
String useCRC32C = "-XX:" + use + "UseCRC32CIntrinsics";
CDSTestUtils.createArchiveAndCheck(dumpFMA, dumpCRC32, dumpCRC32C);
CDSTestUtils.createArchiveAndCheck(unlock, dumpFMA, dumpCRC32, dumpCRC32C);
CDSOptions opts = (new CDSOptions())
.addPrefix(useFMA, useCRC32, useCRC32C, "-showversion")
.addPrefix(unlock, useFMA, useCRC32, useCRC32C, "-showversion")
.addSuffix("TestInterpreterMethodEntries", "run")
.setUseVersion(false);
CDSTestUtils.runWithArchiveAndCheck(opts);