Merge
authordfazunen
Tue, 26 Apr 2016 10:01:00 +0000
changeset 38087 377153ad27c8
parent 38081 a3bcb7197d45 (current diff)
parent 38086 b8b1e0f65aed (diff)
child 38088 aacf8f9553ab
Merge
--- a/hotspot/test/gc/TestDisableExplicitGC.java	Tue Apr 26 10:23:08 2016 +0200
+++ b/hotspot/test/gc/TestDisableExplicitGC.java	Tue Apr 26 10:01:00 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -26,6 +26,7 @@
  * @requires vm.opt.DisableExplicitGC == null
  * @summary Verify GC behavior with DisableExplicitGC flag.
  * @library /testlibrary
+ * @modules jdk.management/com.sun.management.internal
  * @run main/othervm                             -Xlog:gc=debug TestDisableExplicitGC
  * @run main/othervm/fail -XX:+DisableExplicitGC -Xlog:gc=debug TestDisableExplicitGC
  * @run main/othervm      -XX:-DisableExplicitGC -Xlog:gc=debug TestDisableExplicitGC
--- a/hotspot/test/gc/TestVerifySilently.java	Tue Apr 26 10:23:08 2016 +0200
+++ b/hotspot/test/gc/TestVerifySilently.java	Tue Apr 26 10:01:00 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -34,6 +34,7 @@
 import jdk.test.lib.ProcessTools;
 import java.util.ArrayList;
 import java.util.Collections;
+import jdk.test.lib.Utils;
 
 class RunSystemGC {
   public static void main(String args[]) throws Exception {
@@ -43,19 +44,11 @@
 
 
 public class TestVerifySilently {
-  private static String[] getTestJavaOpts() {
-    String testVmOptsStr = System.getProperty("test.java.opts");
-    if (!testVmOptsStr.isEmpty()) {
-      return testVmOptsStr.split(" ");
-    } else {
-      return new String[] {};
-    }
-  }
 
   private static OutputAnalyzer runTest(boolean verifySilently) throws Exception {
     ArrayList<String> vmOpts = new ArrayList();
 
-    Collections.addAll(vmOpts, getTestJavaOpts());
+    Collections.addAll(vmOpts, Utils.getFilteredTestJavaOpts("-Xlog.*"));
     Collections.addAll(vmOpts, new String[] {"-XX:+UnlockDiagnosticVMOptions",
                                              "-XX:+VerifyDuringStartup",
                                              "-XX:+VerifyBeforeGC",
--- a/hotspot/test/gc/TestVerifySubSet.java	Tue Apr 26 10:23:08 2016 +0200
+++ b/hotspot/test/gc/TestVerifySubSet.java	Tue Apr 26 10:01:00 2016 +0000
@@ -34,6 +34,7 @@
 import jdk.test.lib.ProcessTools;
 import java.util.ArrayList;
 import java.util.Collections;
+import jdk.test.lib.Utils;
 
 class RunSystemGC {
     public static void main(String args[]) throws Exception {
@@ -42,19 +43,11 @@
 }
 
 public class TestVerifySubSet {
-    private static String[] getTestJavaOpts() {
-        String testVmOptsStr = System.getProperty("test.java.opts");
-        if (!testVmOptsStr.isEmpty()) {
-            return testVmOptsStr.split(" ");
-        } else {
-            return new String[] {};
-        }
-    }
 
     private static OutputAnalyzer runTest(String subset) throws Exception {
         ArrayList<String> vmOpts = new ArrayList();
 
-        Collections.addAll(vmOpts, getTestJavaOpts());
+        Collections.addAll(vmOpts, Utils.getFilteredTestJavaOpts("-Xlog.*"));
         Collections.addAll(vmOpts, new String[] {"-XX:+UnlockDiagnosticVMOptions",
                                                  "-XX:+VerifyBeforeGC",
                                                  "-XX:+VerifyAfterGC",
--- a/hotspot/test/gc/g1/TestGreyReclaimedHumongousObjects.java	Tue Apr 26 10:23:08 2016 +0200
+++ b/hotspot/test/gc/g1/TestGreyReclaimedHumongousObjects.java	Tue Apr 26 10:01:00 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -27,6 +27,7 @@
  * @requires vm.gc == "G1" | vm.gc == "null"
  * @summary Test handling of marked but unscanned reclaimed humongous objects.
  * @key gc
+ * @modules jdk.management
  * @run main/othervm -XX:+UseG1GC -Xss32m -Xmx128m -XX:G1HeapRegionSize=1m
  *      -XX:+UnlockExperimentalVMOptions
  *          -XX:+G1EagerReclaimHumongousObjects
--- a/hotspot/test/gc/parallel/TestDynShrinkHeap.java	Tue Apr 26 10:23:08 2016 +0200
+++ b/hotspot/test/gc/parallel/TestDynShrinkHeap.java	Tue Apr 26 10:01:00 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -26,6 +26,7 @@
  * @bug 8016479
  * @requires vm.gc=="Parallel" | vm.gc=="null"
  * @summary Verify that the heap shrinks after full GC according to the current values of the Min/MaxHeapFreeRatio flags
+ * @modules jdk.management
  * @library /testlibrary
  * @run main/othervm -XX:+UseAdaptiveSizePolicyWithSystemGC -XX:+UseParallelGC -XX:MinHeapFreeRatio=0 -XX:MaxHeapFreeRatio=100 -Xmx1g -verbose:gc TestDynShrinkHeap
  */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/stress/TestStressG1Humongous.java	Tue Apr 26 10:01:00 2016 +0000
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 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 TestStressG1Humongous
+ * @key gc
+ * @key stress
+ * @summary Stress G1 by humongous allocations in situation near OOM
+ * @requires vm.gc=="G1" | vm.gc=="null"
+ * @run main/othervm/timeout=200 -Xlog:gc=debug -Xmx1g -XX:+UseG1GC -XX:G1HeapRegionSize=4m
+ *              -Dtimeout=120 -Dthreads=3 -Dhumongoussize=1.1 -Dregionsize=4 TestStressG1Humongous
+ * @run main/othervm/timeout=200 -Xlog:gc=debug -Xmx1g -XX:+UseG1GC -XX:G1HeapRegionSize=16m
+ *              -Dtimeout=120 -Dthreads=5 -Dhumongoussize=2.1 -Dregionsize=16 TestStressG1Humongous
+ * @run main/othervm/timeout=200 -Xlog:gc=debug -Xmx1g -XX:+UseG1GC -XX:G1HeapRegionSize=32m
+ *              -Dtimeout=120 -Dthreads=4 -Dhumongoussize=0.6 -Dregionsize=32 TestStressG1Humongous
+ * @run main/othervm/timeout=700 -Xlog:gc=debug -Xmx1g -XX:+UseG1GC -XX:G1HeapRegionSize=1m
+ *              -Dtimeout=600 -Dthreads=7 -Dhumongoussize=0.6 -Dregionsize=1 TestStressG1Humongous
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Collections;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class TestStressG1Humongous {
+
+    // Timeout in seconds
+    private static final int TIMEOUT = Integer.getInteger("timeout", 60);
+    private static final int THREAD_COUNT = Integer.getInteger("threads", 2);
+    private static final int REGION_SIZE = Integer.getInteger("regionsize", 1) * 1024 * 1024;
+    private static final int HUMONGOUS_SIZE = (int) (REGION_SIZE * Double.parseDouble(System.getProperty("humongoussize", "1.5")));
+
+    private volatile boolean isRunning;
+    private final ExecutorService threadExecutor;
+    private final AtomicInteger alocatedObjectsCount;
+    private CountDownLatch countDownLatch;
+    public static final List<Object> GARBAGE = Collections.synchronizedList(new ArrayList<>());
+
+    public static void main(String[] args) throws InterruptedException {
+        new TestStressG1Humongous().run();
+    }
+
+    public TestStressG1Humongous() {
+        isRunning = true;
+        threadExecutor = Executors.newFixedThreadPool(THREAD_COUNT + 1);
+        alocatedObjectsCount = new AtomicInteger(0);
+    }
+
+    private void run() throws InterruptedException {
+        threadExecutor.submit(new Timer());
+        int checkedAmountOfHObjects = getExpectedAmountOfObjects();
+        while (isRunning()) {
+            countDownLatch = new CountDownLatch(THREAD_COUNT);
+            startAllocationThreads(checkedAmountOfHObjects);
+            countDownLatch.await();
+            GARBAGE.clear();
+            System.out.println("Allocated " + alocatedObjectsCount.get() + " objects.");
+            alocatedObjectsCount.set(0);
+        }
+        threadExecutor.shutdown();
+        System.out.println("Done!");
+    }
+
+    /**
+     * Tries to fill available memory with humongous objects to get expected amount.
+     * @return expected amount of humongous objects
+     */
+    private int getExpectedAmountOfObjects() {
+        long maxMem = Runtime.getRuntime().maxMemory();
+        int expectedHObjects = (int) (maxMem / HUMONGOUS_SIZE);
+        // Will allocate 1 region less to give some free space for VM.
+        int checkedAmountOfHObjects = checkHeapCapacity(expectedHObjects) - 1;
+        return checkedAmountOfHObjects;
+    }
+
+    /**
+     * Starts several threads to allocate the requested amount of humongous objects.
+     * @param totalObjects total amount of object that will be created
+     */
+    private void startAllocationThreads(int totalObjects) {
+        int objectsPerThread = totalObjects / THREAD_COUNT;
+        int objectsForLastThread = objectsPerThread + totalObjects % THREAD_COUNT;
+        for (int i = 0; i < THREAD_COUNT - 1; ++i) {
+            threadExecutor.submit(new AllocationThread(countDownLatch, objectsPerThread, alocatedObjectsCount));
+        }
+        threadExecutor.submit(new AllocationThread(countDownLatch, objectsForLastThread, alocatedObjectsCount));
+    }
+
+    /**
+     * Creates a humongous object of the predefined size.
+     */
+    private void createObject() {
+        GARBAGE.add(new byte[HUMONGOUS_SIZE]);
+    }
+
+    /**
+     * Tries to create the requested amount of humongous objects.
+     * In case of OOME, stops creating and cleans the created garbage.
+     * @param expectedObjects amount of objects based on heap size
+     * @return amount of created objects
+     */
+    private int checkHeapCapacity(int expectedObjects) {
+        int allocated = 0;
+        try {
+            while (isRunning() && allocated < expectedObjects) {
+                createObject();
+                ++allocated;
+            }
+        } catch (OutOfMemoryError oome) {
+            GARBAGE.clear();
+        }
+        return allocated;
+    }
+
+    private void setDone() {
+        isRunning = false;
+    }
+
+    private boolean isRunning() {
+        return isRunning;
+    }
+
+    /**
+     * Thread which allocates requested amount of humongous objects.
+     */
+    private class AllocationThread implements Runnable {
+
+        private final int totalObjects;
+        private final CountDownLatch cdl;
+        private final AtomicInteger allocationCounter;
+
+        /**
+         * Creates allocation thread
+         * @param cdl CountDownLatch
+         * @param objects amount of objects to allocate
+         * @param counter
+         */
+        public AllocationThread(CountDownLatch cdl, int objects, AtomicInteger counter) {
+            totalObjects = objects;
+            this.cdl = cdl;
+            allocationCounter = counter;
+        }
+
+        @Override
+        public void run() {
+            int allocatedObjects = 0;
+            try {
+                while (isRunning && allocatedObjects < totalObjects) {
+                    createObject();
+                    allocatedObjects++;
+                    allocationCounter.incrementAndGet();
+                }
+
+            } catch (OutOfMemoryError oome) {
+                GARBAGE.clear();
+                System.out.print("OOME was caught.");
+                System.out.println(" Allocated in thread: " + allocatedObjects + " . Totally allocated: " + allocationCounter.get() + ".");
+            } finally {
+                cdl.countDown();
+            }
+        }
+    }
+
+    /**
+     * Simple Runnable which waits TIMEOUT and sets isRunning to false.
+     */
+    class Timer implements Runnable {
+
+        @Override
+        public void run() {
+            try {
+                Thread.sleep(TIMEOUT * 1000);
+            } catch (InterruptedException ex) {
+            }
+            setDone();
+        }
+    }
+}
--- a/hotspot/test/serviceability/dcmd/gc/FinalizerInfoTest.java	Tue Apr 26 10:23:08 2016 +0200
+++ b/hotspot/test/serviceability/dcmd/gc/FinalizerInfoTest.java	Tue Apr 26 10:01:00 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -36,6 +36,8 @@
  * @test
  * @summary
  * @library /testlibrary
+ * @modules java.xml
+ *          java.management
  * @build jdk.test.lib.*
  * @build jdk.test.lib.dcmd.*
  * @run testng FinalizerInfoTest
--- a/hotspot/test/serviceability/dcmd/gc/HeapInfoTest.java	Tue Apr 26 10:23:08 2016 +0200
+++ b/hotspot/test/serviceability/dcmd/gc/HeapInfoTest.java	Tue Apr 26 10:01:00 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -35,6 +35,8 @@
  * @test
  * @summary Test of diagnostic command GC.heap_info
  * @library /testlibrary
+ * @modules java.xml
+ *          java.management
  * @build jdk.test.lib.*
  * @build jdk.test.lib.dcmd.*
  * @run testng HeapInfoTest