Thu, 19 Sep 2013 09:36:51 -0700
Added tag jdk8-b108 for changeset 85072013aad4
mnunez@3808 | 1 | /* |
mnunez@3808 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
mnunez@3808 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mnunez@3808 | 4 | * |
mnunez@3808 | 5 | * This code is free software; you can redistribute it and/or modify it |
mnunez@3808 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mnunez@3808 | 7 | * published by the Free Software Foundation. |
mnunez@3808 | 8 | * |
mnunez@3808 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mnunez@3808 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mnunez@3808 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mnunez@3808 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
mnunez@3808 | 13 | * accompanied this code). |
mnunez@3808 | 14 | * |
mnunez@3808 | 15 | * You should have received a copy of the GNU General Public License version |
mnunez@3808 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
mnunez@3808 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mnunez@3808 | 18 | * |
mnunez@3808 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
mnunez@3808 | 20 | * or visit www.oracle.com if you need additional information or have any |
mnunez@3808 | 21 | * questions. |
mnunez@3808 | 22 | */ |
mnunez@3808 | 23 | |
mnunez@3808 | 24 | /* |
mnunez@3808 | 25 | * @test Humongous.java |
mnunez@3808 | 26 | * @bug 7168848 |
mnunez@3808 | 27 | * @summary G1: humongous object allocations should initiate marking cycles when necessary |
mnunez@3808 | 28 | * @run main/othervm -Xms100m -Xmx100m -XX:+PrintGC -XX:G1HeapRegionSize=1m -XX:+UseG1GC HumongousAlloc |
mnunez@3808 | 29 | * |
mnunez@3808 | 30 | */ |
mnunez@3808 | 31 | import java.lang.management.GarbageCollectorMXBean; |
mnunez@3808 | 32 | import java.lang.management.ManagementFactory; |
mnunez@3808 | 33 | import java.util.List; |
mnunez@3808 | 34 | |
mnunez@3808 | 35 | public class HumongousAlloc { |
mnunez@3808 | 36 | |
mnunez@3808 | 37 | public static byte[] dummy; |
mnunez@3808 | 38 | private static int sleepFreq = 40; |
mnunez@3808 | 39 | private static int sleepTime = 1000; |
mnunez@3808 | 40 | private static double size = 0.75; |
mnunez@3808 | 41 | private static int iterations = 50; |
mnunez@3808 | 42 | private static int MB = 1024 * 1024; |
mnunez@3808 | 43 | |
mnunez@3808 | 44 | public static void allocate(int size, int sleepTime, int sleepFreq) throws InterruptedException { |
mnunez@3808 | 45 | System.out.println("Will allocate objects of size: " + size |
mnunez@3808 | 46 | + " bytes and sleep for " + sleepTime |
mnunez@3808 | 47 | + " ms after every " + sleepFreq + "th allocation."); |
mnunez@3808 | 48 | int count = 0; |
mnunez@3808 | 49 | while (count < iterations) { |
mnunez@3808 | 50 | for (int i = 0; i < sleepFreq; i++) { |
mnunez@3808 | 51 | dummy = new byte[size - 16]; |
mnunez@3808 | 52 | } |
mnunez@3808 | 53 | Thread.sleep(sleepTime); |
mnunez@3808 | 54 | count++; |
mnunez@3808 | 55 | } |
mnunez@3808 | 56 | } |
mnunez@3808 | 57 | |
mnunez@3808 | 58 | public static void main(String[] args) throws InterruptedException { |
mnunez@3808 | 59 | allocate((int) (size * MB), sleepTime, sleepFreq); |
mnunez@3808 | 60 | List<GarbageCollectorMXBean> collectors = ManagementFactory.getGarbageCollectorMXBeans(); |
mnunez@3808 | 61 | for (GarbageCollectorMXBean collector : collectors) { |
mnunez@3808 | 62 | if (collector.getName().contains("G1 Old")) { |
mnunez@3808 | 63 | long count = collector.getCollectionCount(); |
mnunez@3808 | 64 | if (count > 0) { |
mnunez@3808 | 65 | throw new RuntimeException("Failed: FullGCs should not have happened. The number of FullGC run is " + count); |
mnunez@3808 | 66 | } |
mnunez@3808 | 67 | else { |
mnunez@3808 | 68 | System.out.println("Passed."); |
mnunez@3808 | 69 | } |
mnunez@3808 | 70 | } |
mnunez@3808 | 71 | } |
mnunez@3808 | 72 | } |
mnunez@3808 | 73 | } |
mnunez@3808 | 74 |