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