dbuck@8280: /* dbuck@8280: * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. dbuck@8280: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. dbuck@8280: * dbuck@8280: * This code is free software; you can redistribute it and/or modify it dbuck@8280: * under the terms of the GNU General Public License version 2 only, as dbuck@8280: * published by the Free Software Foundation. dbuck@8280: * dbuck@8280: * This code is distributed in the hope that it will be useful, but WITHOUT dbuck@8280: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or dbuck@8280: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License dbuck@8280: * version 2 for more details (a copy is included in the LICENSE file that dbuck@8280: * accompanied this code). dbuck@8280: * dbuck@8280: * You should have received a copy of the GNU General Public License version dbuck@8280: * 2 along with this work; if not, write to the Free Software Foundation, dbuck@8280: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. dbuck@8280: * dbuck@8280: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA dbuck@8280: * or visit www.oracle.com if you need additional information or have any dbuck@8280: * questions. dbuck@8280: */ dbuck@8280: dbuck@8280: /* dbuck@8280: * @test TestNoEagerReclaimOfHumongousRegions dbuck@8280: * @bug 8139424 dbuck@8280: * @summary Test to check that a live humongous object is not eagerly reclaimed. This is a regression test for dbuck@8280: * 8139424 and the test will crash if an eager reclaim occur. The test is not 100% deterministic and dbuck@8280: * might pass even if there are problems in the code, but it will never crash unless there is a problem. dbuck@8280: * @requires vm.gc=="G1" | vm.gc=="null" dbuck@8280: * @key gc dbuck@8280: * @library /testlibrary /testlibrary/whitebox dbuck@8280: * @modules java.base/sun.misc dbuck@8280: * @build TestNoEagerReclaimOfHumongousRegions dbuck@8280: * @run main ClassFileInstaller sun.hotspot.WhiteBox dbuck@8280: * sun.hotspot.WhiteBox$WhiteBoxPermission dbuck@8280: * @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 dbuck@8280: */ dbuck@8280: dbuck@8280: import java.util.LinkedList; dbuck@8280: dbuck@8280: import sun.hotspot.WhiteBox; dbuck@8280: dbuck@8280: public class TestNoEagerReclaimOfHumongousRegions { dbuck@8280: // Helper class to keep reference to humongous byte[]. dbuck@8280: static class LargeRef { dbuck@8280: private byte[] _ref; dbuck@8280: dbuck@8280: LargeRef(byte[] ref) { dbuck@8280: _ref = ref; dbuck@8280: } dbuck@8280: dbuck@8280: byte[] ref() { return _ref; } dbuck@8280: } dbuck@8280: dbuck@8280: static LargeRef humongous_reference_holder; dbuck@8280: dbuck@8280: public static void main(String[] args) throws InterruptedException{ dbuck@8280: WhiteBox wb = WhiteBox.getWhiteBox(); dbuck@8280: LinkedList garbageAndRefList = new LinkedList(); dbuck@8280: // Creating a 1M large byte array. Since the test specifies the heap dbuck@8280: // region size to be 1m this will be a humongous object. We then dbuck@8280: // store a pointer to the array in the static object to keep it live dbuck@8280: // during the whole test. dbuck@8280: humongous_reference_holder = new LargeRef(new byte[1 * 1024 * 1024]); dbuck@8280: dbuck@8280: // Create some garbage and a reference to the humongous object each round. dbuck@8280: for (int i = 0; i < 32; i++) { dbuck@8280: garbageAndRefList.add(new byte[400*1000]); dbuck@8280: garbageAndRefList.add(new LargeRef(humongous_reference_holder.ref())); dbuck@8280: dbuck@8280: // Promote to old, goal is to get rem-set entries for the humongous dbuck@8280: // object from different regions. The test specifies MaxTenuringThreshold=0, dbuck@8280: // this will make sure we get objects promoted to old at once. dbuck@8280: wb.youngGC(); dbuck@8280: } dbuck@8280: // Clear the garbage and reference list. dbuck@8280: garbageAndRefList.clear(); dbuck@8280: dbuck@8280: // Run a concurrent mark cycle to mark all references but the static one as dead. dbuck@8280: wb.g1StartConcMarkCycle(); dbuck@8280: while (wb.g1InConcurrentMark()) { dbuck@8280: Thread.sleep(100); dbuck@8280: } dbuck@8280: dbuck@8280: // Run a young collection to make sure humongous object still can't be eagerly reclaimed. dbuck@8280: wb.youngGC(); dbuck@8280: // Will crash/assert if humongous object has been reclaimed. dbuck@8280: wb.fullGC(); dbuck@8280: } dbuck@8280: }