hotspot/test/gc/g1/TestEagerReclaimHumongousRegions.java
author thartmann
Fri, 12 Dec 2014 09:37:38 +0100
changeset 28190 5a6b07edeb21
parent 25889 221296ac4359
child 29678 dd2f3932c21e
permissions -rw-r--r--
8066433: Move Whitebox test library to top level repository Summary: Moved Whitebox test library to top level repository. Reviewed-by: iignatyev, sla, mr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25889
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
     1
/*
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
     4
 *
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
     8
 *
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    14
 *
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    18
 *
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    21
 * questions.
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    22
 */
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    23
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    24
/*
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    25
 * @test TestEagerReclaimHumongousRegions
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    26
 * @bug 8027959
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    27
 * @summary Test to make sure that eager reclaim of humongous objects work. We simply try to fill
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    28
 * up the heap with humongous objects that should be eagerly reclaimable to avoid Full GC.
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    29
 * @key gc
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    30
 * @library /testlibrary
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    31
 */
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    32
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    33
import java.util.regex.Pattern;
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    34
import java.util.regex.Matcher;
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    35
import java.util.LinkedList;
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    36
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    37
import com.oracle.java.testlibrary.OutputAnalyzer;
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    38
import com.oracle.java.testlibrary.ProcessTools;
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    39
import com.oracle.java.testlibrary.Asserts;
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    40
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    41
class ReclaimRegionFast {
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    42
    public static final int M = 1024*1024;
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    43
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    44
    public static LinkedList<Object> garbageList = new LinkedList<Object>();
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    45
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    46
    public static void genGarbage() {
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    47
        for (int i = 0; i < 32*1024; i++) {
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    48
            garbageList.add(new int[100]);
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    49
        }
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    50
        garbageList.clear();
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    51
    }
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    52
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    53
    // A large object referenced by a static.
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    54
    static int[] filler = new int[10 * M];
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    55
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    56
    public static void main(String[] args) {
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    57
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    58
        int[] large = new int[M];
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    59
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    60
        Object ref_from_stack = large;
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    61
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    62
        for (int i = 0; i < 100; i++) {
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    63
            // A large object that will be reclaimed eagerly.
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    64
            large = new int[6*M];
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    65
            genGarbage();
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    66
            // Make sure that the compiler cannot completely remove
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    67
            // the allocation of the large object until here.
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    68
            System.out.println(large);
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    69
        }
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    70
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    71
        // Keep the reference to the first object alive.
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    72
        System.out.println(ref_from_stack);
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    73
    }
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    74
}
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    75
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    76
public class TestEagerReclaimHumongousRegions {
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    77
    public static void main(String[] args) throws Exception {
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    78
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    79
            "-XX:+UseG1GC",
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    80
            "-Xms128M",
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    81
            "-Xmx128M",
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    82
            "-Xmn16M",
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    83
            "-XX:+PrintGC",
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    84
            ReclaimRegionFast.class.getName());
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    85
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    86
        Pattern p = Pattern.compile("Full GC");
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    87
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    88
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    89
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    90
        int found = 0;
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    91
        Matcher m = p.matcher(output.getStdout());
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    92
        while (m.find()) { found++; }
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    93
        System.out.println("Issued " + found + " Full GCs");
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    94
        Asserts.assertLT(found, 10, "Found that " + found + " Full GCs were issued. This is larger than the bound. Eager reclaim seems to not work at all");
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    95
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    96
        output.shouldHaveExitValue(0);
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    97
    }
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents:
diff changeset
    98
}