Tue, 03 Mar 2020 12:57:23 +0000
Merge
dbuck@8280 | 1 | /* |
dbuck@8280 | 2 | * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
dbuck@8280 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
dbuck@8280 | 4 | * |
dbuck@8280 | 5 | * This code is free software; you can redistribute it and/or modify it |
dbuck@8280 | 6 | * under the terms of the GNU General Public License version 2 only, as |
dbuck@8280 | 7 | * published by the Free Software Foundation. |
dbuck@8280 | 8 | * |
dbuck@8280 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
dbuck@8280 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
dbuck@8280 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
dbuck@8280 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
dbuck@8280 | 13 | * accompanied this code). |
dbuck@8280 | 14 | * |
dbuck@8280 | 15 | * You should have received a copy of the GNU General Public License version |
dbuck@8280 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
dbuck@8280 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
dbuck@8280 | 18 | * |
dbuck@8280 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
dbuck@8280 | 20 | * or visit www.oracle.com if you need additional information or have any |
dbuck@8280 | 21 | * questions. |
dbuck@8280 | 22 | */ |
dbuck@8280 | 23 | |
dbuck@8280 | 24 | /* |
dbuck@8280 | 25 | * @test TestNoEagerReclaimOfHumongousRegions |
dbuck@8280 | 26 | * @bug 8139424 |
dbuck@8280 | 27 | * @summary Test to check that a live humongous object is not eagerly reclaimed. This is a regression test for |
dbuck@8280 | 28 | * 8139424 and the test will crash if an eager reclaim occur. The test is not 100% deterministic and |
dbuck@8280 | 29 | * might pass even if there are problems in the code, but it will never crash unless there is a problem. |
dbuck@8280 | 30 | * @requires vm.gc=="G1" | vm.gc=="null" |
dbuck@8280 | 31 | * @key gc |
dbuck@8280 | 32 | * @library /testlibrary /testlibrary/whitebox |
dbuck@8280 | 33 | * @modules java.base/sun.misc |
dbuck@8280 | 34 | * @build TestNoEagerReclaimOfHumongousRegions |
dbuck@8280 | 35 | * @run main ClassFileInstaller sun.hotspot.WhiteBox |
dbuck@8280 | 36 | * sun.hotspot.WhiteBox$WhiteBoxPermission |
dbuck@8280 | 37 | * @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 | 38 | */ |
dbuck@8280 | 39 | |
dbuck@8280 | 40 | import java.util.LinkedList; |
dbuck@8280 | 41 | |
dbuck@8280 | 42 | import sun.hotspot.WhiteBox; |
dbuck@8280 | 43 | |
dbuck@8280 | 44 | public class TestNoEagerReclaimOfHumongousRegions { |
dbuck@8280 | 45 | // Helper class to keep reference to humongous byte[]. |
dbuck@8280 | 46 | static class LargeRef { |
dbuck@8280 | 47 | private byte[] _ref; |
dbuck@8280 | 48 | |
dbuck@8280 | 49 | LargeRef(byte[] ref) { |
dbuck@8280 | 50 | _ref = ref; |
dbuck@8280 | 51 | } |
dbuck@8280 | 52 | |
dbuck@8280 | 53 | byte[] ref() { return _ref; } |
dbuck@8280 | 54 | } |
dbuck@8280 | 55 | |
dbuck@8280 | 56 | static LargeRef humongous_reference_holder; |
dbuck@8280 | 57 | |
dbuck@8280 | 58 | public static void main(String[] args) throws InterruptedException{ |
dbuck@8280 | 59 | WhiteBox wb = WhiteBox.getWhiteBox(); |
dbuck@8280 | 60 | LinkedList<Object> garbageAndRefList = new LinkedList<Object>(); |
dbuck@8280 | 61 | // Creating a 1M large byte array. Since the test specifies the heap |
dbuck@8280 | 62 | // region size to be 1m this will be a humongous object. We then |
dbuck@8280 | 63 | // store a pointer to the array in the static object to keep it live |
dbuck@8280 | 64 | // during the whole test. |
dbuck@8280 | 65 | humongous_reference_holder = new LargeRef(new byte[1 * 1024 * 1024]); |
dbuck@8280 | 66 | |
dbuck@8280 | 67 | // Create some garbage and a reference to the humongous object each round. |
dbuck@8280 | 68 | for (int i = 0; i < 32; i++) { |
dbuck@8280 | 69 | garbageAndRefList.add(new byte[400*1000]); |
dbuck@8280 | 70 | garbageAndRefList.add(new LargeRef(humongous_reference_holder.ref())); |
dbuck@8280 | 71 | |
dbuck@8280 | 72 | // Promote to old, goal is to get rem-set entries for the humongous |
dbuck@8280 | 73 | // object from different regions. The test specifies MaxTenuringThreshold=0, |
dbuck@8280 | 74 | // this will make sure we get objects promoted to old at once. |
dbuck@8280 | 75 | wb.youngGC(); |
dbuck@8280 | 76 | } |
dbuck@8280 | 77 | // Clear the garbage and reference list. |
dbuck@8280 | 78 | garbageAndRefList.clear(); |
dbuck@8280 | 79 | |
dbuck@8280 | 80 | // Run a concurrent mark cycle to mark all references but the static one as dead. |
dbuck@8280 | 81 | wb.g1StartConcMarkCycle(); |
dbuck@8280 | 82 | while (wb.g1InConcurrentMark()) { |
dbuck@8280 | 83 | Thread.sleep(100); |
dbuck@8280 | 84 | } |
dbuck@8280 | 85 | |
dbuck@8280 | 86 | // Run a young collection to make sure humongous object still can't be eagerly reclaimed. |
dbuck@8280 | 87 | wb.youngGC(); |
dbuck@8280 | 88 | // Will crash/assert if humongous object has been reclaimed. |
dbuck@8280 | 89 | wb.fullGC(); |
dbuck@8280 | 90 | } |
dbuck@8280 | 91 | } |