Mon, 06 Nov 2017 16:51:47 +0800
[Code Reorganization] remove trailing whitespace to pass jcheck test
tschatzl@7828 | 1 | /* |
tschatzl@7828 | 2 | * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
tschatzl@7828 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
tschatzl@7828 | 4 | * |
tschatzl@7828 | 5 | * This code is free software; you can redistribute it and/or modify it |
tschatzl@7828 | 6 | * under the terms of the GNU General Public License version 2 only, as |
tschatzl@7828 | 7 | * published by the Free Software Foundation. |
tschatzl@7828 | 8 | * |
tschatzl@7828 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
tschatzl@7828 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
tschatzl@7828 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
tschatzl@7828 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
tschatzl@7828 | 13 | * accompanied this code). |
tschatzl@7828 | 14 | * |
tschatzl@7828 | 15 | * You should have received a copy of the GNU General Public License version |
tschatzl@7828 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
tschatzl@7828 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
tschatzl@7828 | 18 | * |
tschatzl@7828 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
tschatzl@7828 | 20 | * or visit www.oracle.com if you need additional information or have any |
tschatzl@7828 | 21 | * questions. |
tschatzl@7828 | 22 | */ |
tschatzl@7828 | 23 | |
tschatzl@7828 | 24 | /* |
tschatzl@7828 | 25 | * @test TestEagerReclaimHumongousRegionsWithRefs |
tschatzl@7828 | 26 | * @bug 8048179 |
tschatzl@7828 | 27 | * @summary Test to make sure that eager reclaim of humongous objects that have previously |
tschatzl@7828 | 28 | * been referenced by other old gen regions work. We simply try to fill |
tschatzl@7828 | 29 | * up the heap with humongous objects and create a remembered set entry from an object by |
tschatzl@7828 | 30 | * referencing that we know is in the old gen. After changing this reference, the object |
tschatzl@7828 | 31 | * should still be eagerly reclaimable to avoid Full GC. |
tschatzl@7828 | 32 | * @key gc |
tschatzl@7828 | 33 | * @library /testlibrary |
tschatzl@7828 | 34 | */ |
tschatzl@7828 | 35 | |
tschatzl@7828 | 36 | import java.util.regex.Pattern; |
tschatzl@7828 | 37 | import java.util.regex.Matcher; |
tschatzl@7828 | 38 | import java.util.LinkedList; |
tschatzl@7828 | 39 | |
tschatzl@7828 | 40 | import com.oracle.java.testlibrary.OutputAnalyzer; |
tschatzl@7828 | 41 | import com.oracle.java.testlibrary.ProcessTools; |
tschatzl@7828 | 42 | import static com.oracle.java.testlibrary.Asserts.*; |
tschatzl@7828 | 43 | |
tschatzl@7828 | 44 | class RefHolder { |
tschatzl@7828 | 45 | Object ref; |
tschatzl@7828 | 46 | } |
tschatzl@7828 | 47 | |
tschatzl@7828 | 48 | class ReclaimRegionFast { |
tschatzl@7828 | 49 | |
tschatzl@7828 | 50 | public static final int M = 1024*1024; |
tschatzl@7828 | 51 | |
tschatzl@7828 | 52 | public static LinkedList<Object> garbageList = new LinkedList<Object>(); |
tschatzl@7828 | 53 | |
tschatzl@7828 | 54 | public static void genGarbage() { |
tschatzl@7828 | 55 | for (int i = 0; i < 32*1024; i++) { |
tschatzl@7828 | 56 | garbageList.add(new int[100]); |
tschatzl@7828 | 57 | } |
tschatzl@7828 | 58 | garbageList.clear(); |
tschatzl@7828 | 59 | } |
tschatzl@7828 | 60 | |
tschatzl@7828 | 61 | |
tschatzl@7828 | 62 | // A large object referenced by a static. |
tschatzl@7828 | 63 | static int[] filler = new int[10 * M]; |
tschatzl@7828 | 64 | |
tschatzl@7828 | 65 | // Old gen object referencing the large object, generating remembered |
tschatzl@7828 | 66 | // set entries. |
tschatzl@7828 | 67 | static RefHolder fromOld = new RefHolder(); |
tschatzl@7828 | 68 | |
tschatzl@7828 | 69 | public static void main(String[] args) { |
tschatzl@7828 | 70 | |
tschatzl@7828 | 71 | int[] large = new int[M]; |
tschatzl@7828 | 72 | |
tschatzl@7828 | 73 | Object ref_from_stack = large; |
tschatzl@7828 | 74 | |
tschatzl@7828 | 75 | for (int i = 0; i < 100; i++) { |
tschatzl@7828 | 76 | // A large object that will be reclaimed eagerly. |
tschatzl@7828 | 77 | large = new int[6*M]; |
tschatzl@7828 | 78 | fromOld.ref = large; |
tschatzl@7828 | 79 | genGarbage(); |
tschatzl@7828 | 80 | } |
tschatzl@7828 | 81 | |
tschatzl@7828 | 82 | // Keep the reference to the first object alive. |
tschatzl@7828 | 83 | System.out.println(ref_from_stack); |
tschatzl@7828 | 84 | } |
tschatzl@7828 | 85 | } |
tschatzl@7828 | 86 | |
tschatzl@7828 | 87 | public class TestEagerReclaimHumongousRegionsWithRefs { |
tschatzl@7828 | 88 | |
tschatzl@7828 | 89 | public static void main(String[] args) throws Exception { |
tschatzl@7828 | 90 | ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( |
tschatzl@7828 | 91 | "-XX:+UseG1GC", |
tschatzl@7828 | 92 | "-Xms128M", |
tschatzl@7828 | 93 | "-Xmx128M", |
tschatzl@7828 | 94 | "-Xmn16M", |
tschatzl@7828 | 95 | "-XX:+PrintGC", |
tschatzl@7828 | 96 | ReclaimRegionFast.class.getName()); |
tschatzl@7828 | 97 | |
tschatzl@7828 | 98 | Pattern p = Pattern.compile("Full GC"); |
tschatzl@7828 | 99 | |
tschatzl@7828 | 100 | OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
tschatzl@7828 | 101 | |
tschatzl@7828 | 102 | int found = 0; |
tschatzl@7828 | 103 | Matcher m = p.matcher(output.getStdout()); |
tschatzl@7828 | 104 | while (m.find()) { |
tschatzl@7828 | 105 | found++; |
tschatzl@7828 | 106 | } |
tschatzl@7828 | 107 | System.out.println("Issued " + found + " Full GCs"); |
tschatzl@7828 | 108 | |
tschatzl@7828 | 109 | assertLessThan(found, 10, "Found that " + found + " Full GCs were issued. This is larger than the bound. Eager reclaim of objects once referenced from old gen seems to not work at all"); |
tschatzl@7828 | 110 | output.shouldHaveExitValue(0); |
tschatzl@7828 | 111 | } |
tschatzl@7828 | 112 | } |
tschatzl@7828 | 113 |