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