< prev index next >

test/gc/stress/TestStressG1Humongous.java

Print this page

        

*** 19,29 **** * 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 --- 19,29 ---- * 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
*** 40,51 **** 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 --- 40,49 ----
*** 54,90 **** 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 static final int NUMBER_OF_FREE_REGIONS = 2; 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. --- 52,87 ---- 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 static final int NUMBER_OF_FREE_REGIONS = 2; private volatile boolean isRunning; ! private final Thread[] threads; 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; ! threads = new Thread[THREAD_COUNT]; alocatedObjectsCount = new AtomicInteger(0); } private void run() throws InterruptedException { ! new Thread(new Timer()).start(); 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); } System.out.println("Done!"); } /** * Tries to fill available memory with humongous objects to get expected amount.
*** 108,120 **** */ 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. */ --- 105,120 ---- */ 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) { ! threads[i] = new Thread(new AllocationThread(countDownLatch, objectsPerThread, alocatedObjectsCount)); ! } ! threads[THREAD_COUNT - 1] = new Thread(new AllocationThread(countDownLatch, objectsForLastThread, alocatedObjectsCount)); ! for (int i = 0; i < THREAD_COUNT; ++i) { ! threads[i].start(); } } /** * Creates a humongous object of the predefined size. */
< prev index next >