test/hotspot/jtreg/gc/stress/gclocker/TestGCLocker.java
author jiangli
Fri, 02 Nov 2018 19:30:31 -0400
changeset 52397 1322829d1501
parent 47216 71c04702a3d5
child 53523 4c5184c56dc2
permissions -rw-r--r--
8209564: runtime/appcds/CDSandJFR.java timeout on tier6 on sparc Summary: Set timeout 500 in CDSandJFR.java Reviewed-by: dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46397
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
     1
/*
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
     4
 *
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
     8
 *
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    13
 * accompanied this code).
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    14
 *
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    18
 *
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    21
 * questions.
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    22
 *
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    23
 */
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    24
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    25
// Stress the GC locker by calling GetPrimitiveArrayCritical while
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    26
// concurrently filling up old gen.
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    27
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    28
import java.lang.management.MemoryPoolMXBean;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    29
import java.lang.management.ManagementFactory;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    30
import java.lang.management.MemoryUsage;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    31
import java.nio.ByteBuffer;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    32
import java.util.ArrayDeque;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    33
import java.util.HashMap;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    34
import java.util.List;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    35
import java.util.Map;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    36
import java.util.Queue;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    37
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    38
final class ThreadUtils {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    39
    public static void sleep(long durationMS) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    40
        try {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    41
            Thread.sleep(durationMS);
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    42
        } catch (Exception e) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    43
        }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    44
    }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    45
}
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    46
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    47
class Filler {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    48
    private static final int SIZE = 250000;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    49
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    50
    private int[] i1 = new int[SIZE];
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    51
    private int[] i2 = new int[SIZE];
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    52
    private short[] s1 = new short[SIZE];
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    53
    private short[] s2 = new short[SIZE];
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    54
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    55
    private Map<Object, Object> map = new HashMap<>();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    56
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    57
    public Filler() {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    58
        for (int i = 0; i < 10000; i++) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    59
            map.put(new Object(), new Object());
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    60
        }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    61
    }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    62
}
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    63
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    64
class Exitable {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    65
    private volatile boolean shouldExit = false;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    66
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    67
    protected boolean shouldExit() {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    68
        return shouldExit;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    69
    }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    70
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    71
    public void exit() {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    72
        shouldExit = true;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    73
    }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    74
}
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    75
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    76
class MemoryWatcher {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    77
    private MemoryPoolMXBean bean;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    78
    private final int thresholdPromille = 750;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    79
    private final int criticalThresholdPromille = 800;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    80
    private final int minGCWaitMS = 1000;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    81
    private final int minFreeWaitElapsedMS = 30000;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    82
    private final int minFreeCriticalWaitMS = 500;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    83
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    84
    private int lastUsage = 0;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    85
    private long lastGCDetected = System.currentTimeMillis();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    86
    private long lastFree = System.currentTimeMillis();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    87
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    88
    public MemoryWatcher(String mxBeanName) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    89
        List<MemoryPoolMXBean> memoryBeans = ManagementFactory.getMemoryPoolMXBeans();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    90
        for (MemoryPoolMXBean bean : memoryBeans) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    91
            if (bean.getName().equals(mxBeanName)) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    92
                this.bean = bean;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    93
                break;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    94
            }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    95
        }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    96
    }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    97
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    98
    private int getMemoryUsage() {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
    99
        if (bean == null) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   100
            Runtime r = Runtime.getRuntime();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   101
            float free = (float) r.freeMemory() / r.maxMemory();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   102
            return Math.round((1 - free) * 1000);
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   103
        } else {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   104
            MemoryUsage usage = bean.getUsage();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   105
            float used = (float) usage.getUsed() / usage.getCommitted();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   106
            return Math.round(used * 1000);
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   107
        }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   108
    }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   109
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   110
    public synchronized boolean shouldFreeUpSpace() {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   111
        int usage = getMemoryUsage();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   112
        long now = System.currentTimeMillis();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   113
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   114
        boolean detectedGC = false;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   115
        if (usage < lastUsage) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   116
            lastGCDetected = now;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   117
            detectedGC = true;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   118
        }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   119
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   120
        lastUsage = usage;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   121
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   122
        long elapsed = now - lastFree;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   123
        long timeSinceLastGC = now - lastGCDetected;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   124
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   125
        if (usage > criticalThresholdPromille && elapsed > minFreeCriticalWaitMS) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   126
            lastFree = now;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   127
            return true;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   128
        } else if (usage > thresholdPromille && !detectedGC) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   129
            if (elapsed > minFreeWaitElapsedMS || timeSinceLastGC > minGCWaitMS) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   130
                lastFree = now;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   131
                return true;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   132
            }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   133
        }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   134
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   135
        return false;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   136
    }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   137
}
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   138
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   139
class MemoryUser extends Exitable implements Runnable {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   140
    private final Queue<Filler> cache = new ArrayDeque<Filler>();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   141
    private final MemoryWatcher watcher;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   142
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   143
    private void load() {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   144
        if (watcher.shouldFreeUpSpace()) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   145
            int toRemove = cache.size() / 5;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   146
            for (int i = 0; i < toRemove; i++) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   147
                cache.remove();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   148
            }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   149
        }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   150
        cache.add(new Filler());
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   151
    }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   152
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   153
    public MemoryUser(String mxBeanName) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   154
        watcher = new MemoryWatcher(mxBeanName);
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   155
    }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   156
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   157
    @Override
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   158
    public void run() {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   159
        for (int i = 0; i < 200; i++) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   160
            load();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   161
        }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   162
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   163
        while (!shouldExit()) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   164
            load();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   165
        }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   166
    }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   167
}
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   168
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   169
class GCLockerStresser extends Exitable implements Runnable {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   170
    static native void fillWithRandomValues(byte[] array);
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   171
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   172
    @Override
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   173
    public void run() {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   174
        byte[] array = new byte[1024 * 1024];
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   175
        while (!shouldExit()) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   176
            fillWithRandomValues(array);
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   177
        }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   178
    }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   179
}
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   180
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   181
public class TestGCLocker {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   182
    private static Exitable startGCLockerStresser(String name) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   183
        GCLockerStresser task = new GCLockerStresser();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   184
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   185
        Thread thread = new Thread(task);
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   186
        thread.setName(name);
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   187
        thread.setPriority(Thread.MIN_PRIORITY);
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   188
        thread.start();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   189
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   190
        return task;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   191
    }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   192
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   193
    private static Exitable startMemoryUser(String mxBeanName) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   194
        MemoryUser task = new MemoryUser(mxBeanName);
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   195
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   196
        Thread thread = new Thread(task);
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   197
        thread.setName("Memory User");
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   198
        thread.start();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   199
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   200
        return task;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   201
    }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   202
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   203
    public static void main(String[] args) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   204
        System.loadLibrary("TestGCLocker");
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   205
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   206
        long durationMinutes = args.length > 0 ? Long.parseLong(args[0]) : 5;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   207
        String mxBeanName = args.length > 1 ? args[1] : null;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   208
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   209
        long startMS = System.currentTimeMillis();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   210
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   211
        Exitable stresser1 = startGCLockerStresser("GCLockerStresser1");
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   212
        Exitable stresser2 = startGCLockerStresser("GCLockerStresser2");
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   213
        Exitable memoryUser = startMemoryUser(mxBeanName);
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   214
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   215
        long durationMS = durationMinutes * 60 * 1000;
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   216
        while ((System.currentTimeMillis() - startMS) < durationMS) {
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   217
            ThreadUtils.sleep(10 * 1010);
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   218
        }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   219
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   220
        stresser1.exit();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   221
        stresser2.exit();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   222
        memoryUser.exit();
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   223
    }
2dd13ff72976 8177968: Add GC stress test TestGCLocker
ehelin
parents:
diff changeset
   224
}