--- a/hotspot/make/test/JtregNative.gmk Wed Apr 19 16:33:37 2017 -0700
+++ b/hotspot/make/test/JtregNative.gmk Sat Apr 22 00:56:56 2017 +0000
@@ -43,6 +43,7 @@
# 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 \
--- a/hotspot/test/TEST.groups Wed Apr 19 16:33:37 2017 -0700
+++ b/hotspot/test/TEST.groups Sat Apr 22 00:56:56 2017 +0000
@@ -130,7 +130,10 @@
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 \
--- a/hotspot/test/gc/stress/TestGCOld.java Wed Apr 19 16:33:37 2017 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,419 +0,0 @@
-/*
- * Copyright (c) 2015, 2016, 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 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;
-
-class TreeNode {
- public TreeNode left, right;
- public int val; // will always be the height of the tree
-}
-
-
-/* Args:
- live-data-size: in megabytes (approximate, will be rounded down).
- work: units of mutator non-allocation work per byte allocated,
- (in unspecified units. This will affect the promotion rate
- printed at the end of the run: more mutator work per step implies
- fewer steps per second implies fewer bytes promoted per second.)
- short/long ratio: ratio of short-lived bytes allocated to long-lived
- bytes allocated.
- pointer mutation rate: number of pointer mutations per step.
- steps: number of steps to do.
-*/
-
-public class TestGCOld {
-
- // Command-line parameters.
-
- private static int size, workUnits, promoteRate, ptrMutRate, steps;
-
- // Constants.
-
- private static final int MEG = 1000000;
- private static final int INSIGNIFICANT = 999; // this many bytes don't matter
- private static final int BYTES_PER_WORD = 4;
- private static final int BYTES_PER_NODE = 20; // bytes per TreeNode
- private static final int WORDS_DEAD = 100; // size of young garbage object
-
- private final static int treeHeight = 14;
- private final static long treeSize = heightToBytes(treeHeight);
-
- private static final String msg1
- = "Usage: java TestGCOld <size> <work> <ratio> <mutation> <steps>";
- private static final String msg2
- = " where <size> is the live storage in megabytes";
- private static final String msg3
- = " <work> is the mutator work per step (arbitrary units)";
- private static final String msg4
- = " <ratio> is the ratio of short-lived to long-lived allocation";
- private static final String msg5
- = " <mutation> is the mutations per step";
- private static final String msg6
- = " <steps> is the number of steps";
-
- // Counters (and global variables that discourage optimization)
-
- private static long youngBytes = 0; // total young bytes allocated
- private static long nodes = 0; // total tree nodes allocated
- private static long actuallyMut = 0; // pointer mutations in old trees
- private static long mutatorSum = 0; // checksum to discourage optimization
- public static int[] aexport; // exported array to discourage opt
-
- // Global variables.
-
- private static TreeNode[] trees;
- private static int where = 0; // roving index into trees
- private static Random rnd = new Random();
-
- // Returns the height of the given tree.
-
- private static int height (TreeNode t) {
- if (t == null) {
- return 0;
- }
- else {
- return 1 + Math.max (height (t.left), height (t.right));
- }
- }
-
- // Returns the length of the shortest path in the given tree.
-
- private static int shortestPath (TreeNode t) {
- if (t == null) {
- return 0;
- }
- else {
- return 1 + Math.min (shortestPath (t.left), shortestPath (t.right));
- }
- }
-
- // Returns the number of nodes in a balanced tree of the given height.
-
- private static long heightToNodes (int h) {
- if (h == 0) {
- return 0;
- }
- else {
- long n = 1;
- while (h > 1) {
- n = n + n;
- h = h - 1;
- }
- return n + n - 1;
- }
- }
-
- // Returns the number of bytes in a balanced tree of the given height.
-
- private static long heightToBytes (int h) {
- return BYTES_PER_NODE * heightToNodes (h);
- }
-
- // Returns the height of the largest balanced tree
- // that has no more than the given number of nodes.
-
- private static int nodesToHeight (long nodes) {
- int h = 1;
- long n = 1;
- while (n + n - 1 <= nodes) {
- n = n + n;
- h = h + 1;
- }
- return h - 1;
- }
-
- // Returns the height of the largest balanced tree
- // that occupies no more than the given number of bytes.
-
- private static int bytesToHeight (long bytes) {
- return nodesToHeight (bytes / BYTES_PER_NODE);
- }
-
- // Returns a newly allocated balanced binary tree of height h.
-
- private static TreeNode makeTree(int h) {
- if (h == 0) return null;
- else {
- TreeNode res = new TreeNode();
- nodes++;
- res.left = makeTree(h-1);
- res.right = makeTree(h-1);
- res.val = h;
- return res;
- }
- }
-
- // Allocates approximately size megabytes of trees and stores
- // them into a global array.
-
- private static void init() {
- int ntrees = (int) ((size * MEG) / treeSize);
- trees = new TreeNode[ntrees];
-
- System.err.println("Allocating " + ntrees + " trees.");
- System.err.println(" (" + (ntrees * treeSize) + " bytes)");
- for (int i = 0; i < ntrees; i++) {
- trees[i] = makeTree(treeHeight);
- // doYoungGenAlloc(promoteRate*ntrees*treeSize, WORDS_DEAD);
- }
- System.err.println(" (" + nodes + " nodes)");
-
- /* Allow any in-progress GC to catch up... */
- // try { Thread.sleep(20000); } catch (InterruptedException x) {}
- }
-
- // Confirms that all trees are balanced and have the correct height.
-
- private static void checkTrees() {
- int ntrees = trees.length;
- for (int i = 0; i < ntrees; i++) {
- TreeNode t = trees[i];
- int h1 = height(t);
- int h2 = shortestPath(t);
- if ((h1 != treeHeight) || (h2 != treeHeight)) {
- System.err.println("*****BUG: " + h1 + " " + h2);
- }
- }
- }
-
- // Called only by replaceTree (below) and by itself.
-
- private static void replaceTreeWork(TreeNode full, TreeNode partial, boolean dir) {
- boolean canGoLeft = full.left != null && full.left.val > partial.val;
- boolean canGoRight = full.right != null && full.right.val > partial.val;
- if (canGoLeft && canGoRight) {
- if (dir)
- replaceTreeWork(full.left, partial, !dir);
- else
- replaceTreeWork(full.right, partial, !dir);
- } else if (!canGoLeft && !canGoRight) {
- if (dir)
- full.left = partial;
- else
- full.right = partial;
- } else if (!canGoLeft) {
- full.left = partial;
- } else {
- full.right = partial;
- }
- }
-
- // Given a balanced tree full and a smaller balanced tree partial,
- // replaces an appropriate subtree of full by partial, taking care
- // to preserve the shape of the full tree.
-
- private static void replaceTree(TreeNode full, TreeNode partial) {
- boolean dir = (partial.val % 2) == 0;
- actuallyMut++;
- replaceTreeWork(full, partial, dir);
- }
-
- // Allocates approximately n bytes of long-lived storage,
- // replacing oldest existing long-lived storage.
-
- private static void oldGenAlloc(long n) {
- int full = (int) (n / treeSize);
- long partial = n % treeSize;
- // System.out.println("In oldGenAlloc, doing " + full + " full trees "
- // + "and one partial tree of size " + partial);
- for (int i = 0; i < full; i++) {
- trees[where++] = makeTree(treeHeight);
- if (where == trees.length) where = 0;
- }
- while (partial > INSIGNIFICANT) {
- int h = bytesToHeight(partial);
- TreeNode newTree = makeTree(h);
- replaceTree(trees[where++], newTree);
- if (where == trees.length) where = 0;
- partial = partial - heightToBytes(h);
- }
- }
-
- // Interchanges two randomly selected subtrees (of same size and depth).
-
- private static void oldGenSwapSubtrees() {
- // Randomly pick:
- // * two tree indices
- // * A depth
- // * A path to that depth.
- int index1 = rnd.nextInt(trees.length);
- int index2 = rnd.nextInt(trees.length);
- int depth = rnd.nextInt(treeHeight);
- int path = rnd.nextInt();
- TreeNode tn1 = trees[index1];
- TreeNode tn2 = trees[index2];
- for (int i = 0; i < depth; i++) {
- if ((path & 1) == 0) {
- tn1 = tn1.left;
- tn2 = tn2.left;
- } else {
- tn1 = tn1.right;
- tn2 = tn2.right;
- }
- path >>= 1;
- }
- TreeNode tmp;
- if ((path & 1) == 0) {
- tmp = tn1.left;
- tn1.left = tn2.left;
- tn2.left = tmp;
- } else {
- tmp = tn1.right;
- tn1.right = tn2.right;
- tn2.right = tmp;
- }
- actuallyMut += 2;
- }
-
- // Update "n" old-generation pointers.
-
- private static void oldGenMut(long n) {
- for (int i = 0; i < n/2; i++) {
- oldGenSwapSubtrees();
- }
- }
-
- // Does the amount of mutator work appropriate for n bytes of young-gen
- // garbage allocation.
-
- private static void doMutWork(long n) {
- int sum = 0;
- long limit = workUnits*n/10;
- for (long k = 0; k < limit; k++) sum++;
- // We don't want dead code elimination to eliminate the loop above.
- mutatorSum = mutatorSum + sum;
- }
-
- // Allocate n bytes of young-gen garbage, in units of "nwords"
- // words.
-
- private static void doYoungGenAlloc(long n, int nwords) {
- final int nbytes = nwords*BYTES_PER_WORD;
- int allocated = 0;
- while (allocated < n) {
- aexport = new int[nwords];
- /* System.err.println("Step"); */
- allocated += nbytes;
- }
- youngBytes = youngBytes + allocated;
- }
-
- // Allocate "n" bytes of young-gen data; and do the
- // corresponding amount of old-gen allocation and pointer
- // mutation.
-
- // oldGenAlloc may perform some mutations, so this code
- // takes those mutations into account.
-
- private static void doStep(long n) {
- long mutations = actuallyMut;
-
- doYoungGenAlloc(n, WORDS_DEAD);
- doMutWork(n);
- oldGenAlloc(n / promoteRate);
- oldGenMut(Math.max(0L, (mutations + ptrMutRate) - actuallyMut));
- }
-
- public static void main(String[] args) {
- if (args.length != 5) {
- System.err.println(msg1);
- System.err.println(msg2);
- System.err.println(msg3);
- System.err.println(msg4);
- System.err.println(msg5);
- System.err.println(msg6);
- return;
- }
-
- size = Integer.parseInt(args[0]);
- workUnits = Integer.parseInt(args[1]);
- promoteRate = Integer.parseInt(args[2]);
- ptrMutRate = Integer.parseInt(args[3]);
- steps = Integer.parseInt(args[4]);
-
- System.out.println(size + " megabytes of live storage");
- System.out.println(workUnits + " work units per step");
- System.out.println("promotion ratio is 1:" + promoteRate);
- System.out.println("pointer mutation rate is " + ptrMutRate);
- System.out.println(steps + " steps");
-
- init();
-// checkTrees();
- youngBytes = 0;
- nodes = 0;
-
- System.err.println("Initialization complete...");
-
- long start = System.currentTimeMillis();
-
- for (int step = 0; step < steps; step++) {
- doStep(MEG);
- }
-
- long end = System.currentTimeMillis();
- float secs = ((float)(end-start))/1000.0F;
-
-// checkTrees();
-
- NumberFormat nf = NumberFormat.getInstance();
- nf.setMaximumFractionDigits(1);
- System.out.println("\nTook " + nf.format(secs) + " sec in steady state.");
- nf.setMaximumFractionDigits(2);
- System.out.println("Allocated " + steps + " Mb of young gen garbage"
- + " (= " + nf.format(((float)steps)/secs) +
- " Mb/sec)");
- System.out.println(" (actually allocated " +
- nf.format(((float) youngBytes)/MEG) + " megabytes)");
- float promoted = ((float)steps) / (float)promoteRate;
- System.out.println("Promoted " + promoted +
- " Mb (= " + nf.format(promoted/secs) + " Mb/sec)");
- System.out.println(" (actually promoted " +
- nf.format(((float) (nodes * BYTES_PER_NODE))/MEG) +
- " megabytes)");
- if (ptrMutRate != 0) {
- System.out.println("Mutated " + actuallyMut +
- " pointers (= " +
- nf.format(actuallyMut/secs) + " ptrs/sec)");
-
- }
- // This output serves mainly to discourage optimization.
- System.out.println("Checksum = " + (mutatorSum + aexport.length));
-
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/gclocker/TestGCLocker.java Sat Apr 22 00:56:56 2017 +0000
@@ -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();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/gclocker/TestGCLockerWithCMS.java Sat Apr 22 00:56:56 2017 +0000
@@ -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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/gclocker/TestGCLockerWithG1.java Sat Apr 22 00:56:56 2017 +0000
@@ -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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/gclocker/TestGCLockerWithParallel.java Sat Apr 22 00:56:56 2017 +0000
@@ -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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/gclocker/TestGCLockerWithSerial.java Sat Apr 22 00:56:56 2017 +0000
@@ -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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/gclocker/libTestGCLocker.c Sat Apr 22 00:56:56 2017 +0000
@@ -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);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/gcold/TestGCOld.java Sat Apr 22 00:56:56 2017 +0000
@@ -0,0 +1,404 @@
+/*
+ * 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
+ * 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.
+ */
+
+import java.text.*;
+import java.util.Random;
+
+class TreeNode {
+ public TreeNode left, right;
+ public int val; // will always be the height of the tree
+}
+
+
+/* Args:
+ live-data-size: in megabytes (approximate, will be rounded down).
+ work: units of mutator non-allocation work per byte allocated,
+ (in unspecified units. This will affect the promotion rate
+ printed at the end of the run: more mutator work per step implies
+ fewer steps per second implies fewer bytes promoted per second.)
+ short/long ratio: ratio of short-lived bytes allocated to long-lived
+ bytes allocated.
+ pointer mutation rate: number of pointer mutations per step.
+ steps: number of steps to do.
+*/
+
+public class TestGCOld {
+
+ // Command-line parameters.
+
+ private static int size, workUnits, promoteRate, ptrMutRate, steps;
+
+ // Constants.
+
+ private static final int MEG = 1000000;
+ private static final int INSIGNIFICANT = 999; // this many bytes don't matter
+ private static final int BYTES_PER_WORD = 4;
+ private static final int BYTES_PER_NODE = 20; // bytes per TreeNode
+ private static final int WORDS_DEAD = 100; // size of young garbage object
+
+ private final static int treeHeight = 14;
+ private final static long treeSize = heightToBytes(treeHeight);
+
+ private static final String msg1
+ = "Usage: java TestGCOld <size> <work> <ratio> <mutation> <steps>";
+ private static final String msg2
+ = " where <size> is the live storage in megabytes";
+ private static final String msg3
+ = " <work> is the mutator work per step (arbitrary units)";
+ private static final String msg4
+ = " <ratio> is the ratio of short-lived to long-lived allocation";
+ private static final String msg5
+ = " <mutation> is the mutations per step";
+ private static final String msg6
+ = " <steps> is the number of steps";
+
+ // Counters (and global variables that discourage optimization)
+
+ private static long youngBytes = 0; // total young bytes allocated
+ private static long nodes = 0; // total tree nodes allocated
+ private static long actuallyMut = 0; // pointer mutations in old trees
+ private static long mutatorSum = 0; // checksum to discourage optimization
+ public static int[] aexport; // exported array to discourage opt
+
+ // Global variables.
+
+ private static TreeNode[] trees;
+ private static int where = 0; // roving index into trees
+ private static Random rnd = new Random();
+
+ // Returns the height of the given tree.
+
+ private static int height (TreeNode t) {
+ if (t == null) {
+ return 0;
+ }
+ else {
+ return 1 + Math.max (height (t.left), height (t.right));
+ }
+ }
+
+ // Returns the length of the shortest path in the given tree.
+
+ private static int shortestPath (TreeNode t) {
+ if (t == null) {
+ return 0;
+ }
+ else {
+ return 1 + Math.min (shortestPath (t.left), shortestPath (t.right));
+ }
+ }
+
+ // Returns the number of nodes in a balanced tree of the given height.
+
+ private static long heightToNodes (int h) {
+ if (h == 0) {
+ return 0;
+ }
+ else {
+ long n = 1;
+ while (h > 1) {
+ n = n + n;
+ h = h - 1;
+ }
+ return n + n - 1;
+ }
+ }
+
+ // Returns the number of bytes in a balanced tree of the given height.
+
+ private static long heightToBytes (int h) {
+ return BYTES_PER_NODE * heightToNodes (h);
+ }
+
+ // Returns the height of the largest balanced tree
+ // that has no more than the given number of nodes.
+
+ private static int nodesToHeight (long nodes) {
+ int h = 1;
+ long n = 1;
+ while (n + n - 1 <= nodes) {
+ n = n + n;
+ h = h + 1;
+ }
+ return h - 1;
+ }
+
+ // Returns the height of the largest balanced tree
+ // that occupies no more than the given number of bytes.
+
+ private static int bytesToHeight (long bytes) {
+ return nodesToHeight (bytes / BYTES_PER_NODE);
+ }
+
+ // Returns a newly allocated balanced binary tree of height h.
+
+ private static TreeNode makeTree(int h) {
+ if (h == 0) return null;
+ else {
+ TreeNode res = new TreeNode();
+ nodes++;
+ res.left = makeTree(h-1);
+ res.right = makeTree(h-1);
+ res.val = h;
+ return res;
+ }
+ }
+
+ // Allocates approximately size megabytes of trees and stores
+ // them into a global array.
+
+ private static void init() {
+ int ntrees = (int) ((size * MEG) / treeSize);
+ trees = new TreeNode[ntrees];
+
+ System.err.println("Allocating " + ntrees + " trees.");
+ System.err.println(" (" + (ntrees * treeSize) + " bytes)");
+ for (int i = 0; i < ntrees; i++) {
+ trees[i] = makeTree(treeHeight);
+ // doYoungGenAlloc(promoteRate*ntrees*treeSize, WORDS_DEAD);
+ }
+ System.err.println(" (" + nodes + " nodes)");
+
+ /* Allow any in-progress GC to catch up... */
+ // try { Thread.sleep(20000); } catch (InterruptedException x) {}
+ }
+
+ // Confirms that all trees are balanced and have the correct height.
+
+ private static void checkTrees() {
+ int ntrees = trees.length;
+ for (int i = 0; i < ntrees; i++) {
+ TreeNode t = trees[i];
+ int h1 = height(t);
+ int h2 = shortestPath(t);
+ if ((h1 != treeHeight) || (h2 != treeHeight)) {
+ System.err.println("*****BUG: " + h1 + " " + h2);
+ }
+ }
+ }
+
+ // Called only by replaceTree (below) and by itself.
+
+ private static void replaceTreeWork(TreeNode full, TreeNode partial, boolean dir) {
+ boolean canGoLeft = full.left != null && full.left.val > partial.val;
+ boolean canGoRight = full.right != null && full.right.val > partial.val;
+ if (canGoLeft && canGoRight) {
+ if (dir)
+ replaceTreeWork(full.left, partial, !dir);
+ else
+ replaceTreeWork(full.right, partial, !dir);
+ } else if (!canGoLeft && !canGoRight) {
+ if (dir)
+ full.left = partial;
+ else
+ full.right = partial;
+ } else if (!canGoLeft) {
+ full.left = partial;
+ } else {
+ full.right = partial;
+ }
+ }
+
+ // Given a balanced tree full and a smaller balanced tree partial,
+ // replaces an appropriate subtree of full by partial, taking care
+ // to preserve the shape of the full tree.
+
+ private static void replaceTree(TreeNode full, TreeNode partial) {
+ boolean dir = (partial.val % 2) == 0;
+ actuallyMut++;
+ replaceTreeWork(full, partial, dir);
+ }
+
+ // Allocates approximately n bytes of long-lived storage,
+ // replacing oldest existing long-lived storage.
+
+ private static void oldGenAlloc(long n) {
+ int full = (int) (n / treeSize);
+ long partial = n % treeSize;
+ // System.out.println("In oldGenAlloc, doing " + full + " full trees "
+ // + "and one partial tree of size " + partial);
+ for (int i = 0; i < full; i++) {
+ trees[where++] = makeTree(treeHeight);
+ if (where == trees.length) where = 0;
+ }
+ while (partial > INSIGNIFICANT) {
+ int h = bytesToHeight(partial);
+ TreeNode newTree = makeTree(h);
+ replaceTree(trees[where++], newTree);
+ if (where == trees.length) where = 0;
+ partial = partial - heightToBytes(h);
+ }
+ }
+
+ // Interchanges two randomly selected subtrees (of same size and depth).
+
+ private static void oldGenSwapSubtrees() {
+ // Randomly pick:
+ // * two tree indices
+ // * A depth
+ // * A path to that depth.
+ int index1 = rnd.nextInt(trees.length);
+ int index2 = rnd.nextInt(trees.length);
+ int depth = rnd.nextInt(treeHeight);
+ int path = rnd.nextInt();
+ TreeNode tn1 = trees[index1];
+ TreeNode tn2 = trees[index2];
+ for (int i = 0; i < depth; i++) {
+ if ((path & 1) == 0) {
+ tn1 = tn1.left;
+ tn2 = tn2.left;
+ } else {
+ tn1 = tn1.right;
+ tn2 = tn2.right;
+ }
+ path >>= 1;
+ }
+ TreeNode tmp;
+ if ((path & 1) == 0) {
+ tmp = tn1.left;
+ tn1.left = tn2.left;
+ tn2.left = tmp;
+ } else {
+ tmp = tn1.right;
+ tn1.right = tn2.right;
+ tn2.right = tmp;
+ }
+ actuallyMut += 2;
+ }
+
+ // Update "n" old-generation pointers.
+
+ private static void oldGenMut(long n) {
+ for (int i = 0; i < n/2; i++) {
+ oldGenSwapSubtrees();
+ }
+ }
+
+ // Does the amount of mutator work appropriate for n bytes of young-gen
+ // garbage allocation.
+
+ private static void doMutWork(long n) {
+ int sum = 0;
+ long limit = workUnits*n/10;
+ for (long k = 0; k < limit; k++) sum++;
+ // We don't want dead code elimination to eliminate the loop above.
+ mutatorSum = mutatorSum + sum;
+ }
+
+ // Allocate n bytes of young-gen garbage, in units of "nwords"
+ // words.
+
+ private static void doYoungGenAlloc(long n, int nwords) {
+ final int nbytes = nwords*BYTES_PER_WORD;
+ int allocated = 0;
+ while (allocated < n) {
+ aexport = new int[nwords];
+ /* System.err.println("Step"); */
+ allocated += nbytes;
+ }
+ youngBytes = youngBytes + allocated;
+ }
+
+ // Allocate "n" bytes of young-gen data; and do the
+ // corresponding amount of old-gen allocation and pointer
+ // mutation.
+
+ // oldGenAlloc may perform some mutations, so this code
+ // takes those mutations into account.
+
+ private static void doStep(long n) {
+ long mutations = actuallyMut;
+
+ doYoungGenAlloc(n, WORDS_DEAD);
+ doMutWork(n);
+ oldGenAlloc(n / promoteRate);
+ oldGenMut(Math.max(0L, (mutations + ptrMutRate) - actuallyMut));
+ }
+
+ public static void main(String[] args) {
+ if (args.length != 5) {
+ System.err.println(msg1);
+ System.err.println(msg2);
+ System.err.println(msg3);
+ System.err.println(msg4);
+ System.err.println(msg5);
+ System.err.println(msg6);
+ return;
+ }
+
+ size = Integer.parseInt(args[0]);
+ workUnits = Integer.parseInt(args[1]);
+ promoteRate = Integer.parseInt(args[2]);
+ ptrMutRate = Integer.parseInt(args[3]);
+ steps = Integer.parseInt(args[4]);
+
+ System.out.println(size + " megabytes of live storage");
+ System.out.println(workUnits + " work units per step");
+ System.out.println("promotion ratio is 1:" + promoteRate);
+ System.out.println("pointer mutation rate is " + ptrMutRate);
+ System.out.println(steps + " steps");
+
+ init();
+// checkTrees();
+ youngBytes = 0;
+ nodes = 0;
+
+ System.err.println("Initialization complete...");
+
+ long start = System.currentTimeMillis();
+
+ for (int step = 0; step < steps; step++) {
+ doStep(MEG);
+ }
+
+ long end = System.currentTimeMillis();
+ float secs = ((float)(end-start))/1000.0F;
+
+// checkTrees();
+
+ NumberFormat nf = NumberFormat.getInstance();
+ nf.setMaximumFractionDigits(1);
+ System.out.println("\nTook " + nf.format(secs) + " sec in steady state.");
+ nf.setMaximumFractionDigits(2);
+ System.out.println("Allocated " + steps + " Mb of young gen garbage"
+ + " (= " + nf.format(((float)steps)/secs) +
+ " Mb/sec)");
+ System.out.println(" (actually allocated " +
+ nf.format(((float) youngBytes)/MEG) + " megabytes)");
+ float promoted = ((float)steps) / (float)promoteRate;
+ System.out.println("Promoted " + promoted +
+ " Mb (= " + nf.format(promoted/secs) + " Mb/sec)");
+ System.out.println(" (actually promoted " +
+ nf.format(((float) (nodes * BYTES_PER_NODE))/MEG) +
+ " megabytes)");
+ if (ptrMutRate != 0) {
+ System.out.println("Mutated " + actuallyMut +
+ " pointers (= " +
+ nf.format(actuallyMut/secs) + " ptrs/sec)");
+
+ }
+ // This output serves mainly to discourage optimization.
+ System.out.println("Checksum = " + (mutatorSum + aexport.length));
+
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/gcold/TestGCOldWithCMS.java Sat Apr 22 00:56:56 2017 +0000
@@ -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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/gcold/TestGCOldWithG1.java Sat Apr 22 00:56:56 2017 +0000
@@ -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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/gcold/TestGCOldWithParallel.java Sat Apr 22 00:56:56 2017 +0000
@@ -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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/gcold/TestGCOldWithSerial.java Sat Apr 22 00:56:56 2017 +0000
@@ -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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/systemgc/TestSystemGC.java Sat Apr 22 00:56:56 2017 +0000
@@ -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();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/systemgc/TestSystemGCWithCMS.java Sat Apr 22 00:56:56 2017 +0000
@@ -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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/systemgc/TestSystemGCWithG1.java Sat Apr 22 00:56:56 2017 +0000
@@ -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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/systemgc/TestSystemGCWithParallel.java Sat Apr 22 00:56:56 2017 +0000
@@ -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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/systemgc/TestSystemGCWithSerial.java Sat Apr 22 00:56:56 2017 +0000
@@ -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);
+ }
+}
--- a/hotspot/test/runtime/SharedArchiveFile/TestInterpreterMethodEntries.java Wed Apr 19 16:33:37 2017 -0700
+++ b/hotspot/test/runtime/SharedArchiveFile/TestInterpreterMethodEntries.java Sat Apr 22 00:56:56 2017 +0000
@@ -62,6 +62,8 @@
}
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 @@
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);