Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc_implementation/g1/TestNoEagerReclaimOfHumongousRegions.java
32285 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test TestNoEagerReclaimOfHumongousRegions25* @bug 813942426* @summary Test to check that a live humongous object is not eagerly reclaimed. This is a regression test for27* 8139424 and the test will crash if an eager reclaim occur. The test is not 100% deterministic and28* might pass even if there are problems in the code, but it will never crash unless there is a problem.29* @requires vm.gc=="G1" | vm.gc=="null"30* @key gc31* @library /testlibrary /testlibrary/whitebox32* @modules java.base/sun.misc33* @build TestNoEagerReclaimOfHumongousRegions34* @run main ClassFileInstaller sun.hotspot.WhiteBox35* sun.hotspot.WhiteBox$WhiteBoxPermission36* @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 TestNoEagerReclaimOfHumongousRegions37*/3839import java.util.LinkedList;4041import sun.hotspot.WhiteBox;4243public class TestNoEagerReclaimOfHumongousRegions {44// Helper class to keep reference to humongous byte[].45static class LargeRef {46private byte[] _ref;4748LargeRef(byte[] ref) {49_ref = ref;50}5152byte[] ref() { return _ref; }53}5455static LargeRef humongous_reference_holder;5657public static void main(String[] args) throws InterruptedException{58WhiteBox wb = WhiteBox.getWhiteBox();59LinkedList<Object> garbageAndRefList = new LinkedList<Object>();60// Creating a 1M large byte array. Since the test specifies the heap61// region size to be 1m this will be a humongous object. We then62// store a pointer to the array in the static object to keep it live63// during the whole test.64humongous_reference_holder = new LargeRef(new byte[1 * 1024 * 1024]);6566// Create some garbage and a reference to the humongous object each round.67for (int i = 0; i < 32; i++) {68garbageAndRefList.add(new byte[400*1000]);69garbageAndRefList.add(new LargeRef(humongous_reference_holder.ref()));7071// Promote to old, goal is to get rem-set entries for the humongous72// object from different regions. The test specifies MaxTenuringThreshold=0,73// this will make sure we get objects promoted to old at once.74wb.youngGC();75}76// Clear the garbage and reference list.77garbageAndRefList.clear();7879// Run a concurrent mark cycle to mark all references but the static one as dead.80wb.g1StartConcMarkCycle();81while (wb.g1InConcurrentMark()) {82Thread.sleep(100);83}8485// Run a young collection to make sure humongous object still can't be eagerly reclaimed.86wb.youngGC();87// Will crash/assert if humongous object has been reclaimed.88wb.fullGC();89}90}919293