Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8249787: Make TestGCLocker more resilient with concurrent GCs
Reviewed-by: eosterlund, tschatzl
  • Loading branch information
rkennke committed Jul 23, 2020
1 parent 54ad4f9 commit a28f4100ce7fb3aaa260131989d487e8acb5c551
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
@@ -80,13 +80,14 @@ class MemoryWatcher {
private final int criticalThresholdPromille = 800;
private final int minGCWaitMS = 1000;
private final int minFreeWaitElapsedMS = 30000;
private final int minFreeCriticalWaitMS = 500;
private final int minFreeCriticalWaitMS;

private int lastUsage = 0;
private long lastGCDetected = System.currentTimeMillis();
private long lastFree = System.currentTimeMillis();

public MemoryWatcher(String mxBeanName) {
public MemoryWatcher(String mxBeanName, int minFreeCriticalWaitMS) {
this.minFreeCriticalWaitMS = minFreeCriticalWaitMS;
List<MemoryPoolMXBean> memoryBeans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean bean : memoryBeans) {
if (bean.getName().equals(mxBeanName)) {
@@ -151,8 +152,8 @@ private void load() {
cache.add(new Filler());
}

public MemoryUser(String mxBeanName) {
watcher = new MemoryWatcher(mxBeanName);
public MemoryUser(String mxBeanName, int minFreeCriticalWaitMS) {
watcher = new MemoryWatcher(mxBeanName, minFreeCriticalWaitMS);
}

@Override
@@ -191,8 +192,8 @@ private static Exitable startGCLockerStresser(String name) {
return task;
}

private static Exitable startMemoryUser(String mxBeanName) {
MemoryUser task = new MemoryUser(mxBeanName);
private static Exitable startMemoryUser(String mxBeanName, int minFreeCriticalWaitMS) {
MemoryUser task = new MemoryUser(mxBeanName, minFreeCriticalWaitMS);

Thread thread = new Thread(task);
thread.setName("Memory User");
@@ -206,12 +207,13 @@ public static void main(String[] args) {

long durationMinutes = args.length > 0 ? Long.parseLong(args[0]) : 5;
String mxBeanName = args.length > 1 ? args[1] : null;
int minFreeCriticalWaitMS = args.length > 2 ? Integer.parseInt(args[2]) : 500;

long startMS = System.currentTimeMillis();

Exitable stresser1 = startGCLockerStresser("GCLockerStresser1");
Exitable stresser2 = startGCLockerStresser("GCLockerStresser2");
Exitable memoryUser = startMemoryUser(mxBeanName);
Exitable memoryUser = startMemoryUser(mxBeanName, minFreeCriticalWaitMS);

long durationMS = durationMinutes * 60 * 1000;
while ((System.currentTimeMillis() - startMS) < durationMS) {
@@ -51,7 +51,7 @@
*/
public class TestGCLockerWithShenandoah {
public static void main(String[] args) {
String[] testArgs = {"2", "Shenandoah heap"};
String[] testArgs = {"2", "Shenandoah", "0"};
TestGCLocker.main(testArgs);
}
}

0 comments on commit a28f410

Please sign in to comment.