test/gc_implementation/g1/TestNoEagerReclaimOfHumongousRegions.java

changeset 8280
f3f2f71d2dc8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/gc_implementation/g1/TestNoEagerReclaimOfHumongousRegions.java	Tue Jan 19 18:16:40 2016 +0000
     1.3 @@ -0,0 +1,91 @@
     1.4 +/*
     1.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test TestNoEagerReclaimOfHumongousRegions
    1.29 + * @bug 8139424
    1.30 + * @summary Test to check that a live humongous object is not eagerly reclaimed. This is a regression test for
    1.31 + *          8139424 and the test will crash if an eager reclaim occur. The test is not 100% deterministic and
    1.32 + *          might pass even if there are problems in the code, but it will never crash unless there is a problem.
    1.33 + * @requires vm.gc=="G1" | vm.gc=="null"
    1.34 + * @key gc
    1.35 + * @library /testlibrary /testlibrary/whitebox
    1.36 + * @modules java.base/sun.misc
    1.37 + * @build TestNoEagerReclaimOfHumongousRegions
    1.38 + * @run main ClassFileInstaller sun.hotspot.WhiteBox
    1.39 + *                              sun.hotspot.WhiteBox$WhiteBoxPermission
    1.40 + * @run main/othervm -Xbootclasspath/a:. -XX:+PrintGC -XX:+UseG1GC -XX:MaxTenuringThreshold=0 -XX:G1RSetSparseRegionEntries=32 -XX:G1HeapRegionSize=1m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+G1TraceEagerReclaimHumongousObjects TestNoEagerReclaimOfHumongousRegions
    1.41 + */
    1.42 +
    1.43 +import java.util.LinkedList;
    1.44 +
    1.45 +import sun.hotspot.WhiteBox;
    1.46 +
    1.47 +public class TestNoEagerReclaimOfHumongousRegions {
    1.48 +    // Helper class to keep reference to humongous byte[].
    1.49 +    static class LargeRef {
    1.50 +        private byte[] _ref;
    1.51 +
    1.52 +        LargeRef(byte[] ref) {
    1.53 +            _ref = ref;
    1.54 +        }
    1.55 +
    1.56 +        byte[] ref() { return _ref; }
    1.57 +    }
    1.58 +
    1.59 +    static LargeRef humongous_reference_holder;
    1.60 +
    1.61 +    public static void main(String[] args) throws InterruptedException{
    1.62 +        WhiteBox wb = WhiteBox.getWhiteBox();
    1.63 +        LinkedList<Object> garbageAndRefList = new LinkedList<Object>();
    1.64 +        // Creating a 1M large byte array. Since the test specifies the heap
    1.65 +        // region size to be 1m this will be a humongous object. We then
    1.66 +        // store a pointer to the array in the static object to keep it live
    1.67 +        // during the whole test.
    1.68 +        humongous_reference_holder = new LargeRef(new byte[1 * 1024 * 1024]);
    1.69 +
    1.70 +        // Create some garbage and a reference to the humongous object each round.
    1.71 +        for (int i = 0; i < 32; i++) {
    1.72 +            garbageAndRefList.add(new byte[400*1000]);
    1.73 +            garbageAndRefList.add(new LargeRef(humongous_reference_holder.ref()));
    1.74 +
    1.75 +            // Promote to old, goal is to get rem-set entries for the humongous
    1.76 +            // object from different regions. The test specifies MaxTenuringThreshold=0,
    1.77 +            // this will make sure we get objects promoted to old at once.
    1.78 +            wb.youngGC();
    1.79 +        }
    1.80 +        // Clear the garbage and reference list.
    1.81 +        garbageAndRefList.clear();
    1.82 +
    1.83 +        // Run a concurrent mark cycle to mark all references but the static one as dead.
    1.84 +        wb.g1StartConcMarkCycle();
    1.85 +        while (wb.g1InConcurrentMark()) {
    1.86 +            Thread.sleep(100);
    1.87 +        }
    1.88 +
    1.89 +        // Run a young collection to make sure humongous object still can't be eagerly reclaimed.
    1.90 +        wb.youngGC();
    1.91 +        // Will crash/assert if humongous object has been reclaimed.
    1.92 +        wb.fullGC();
    1.93 +    }
    1.94 +}

mercurial