Wed, 03 Sep 2014 09:25:44 +0200
Merge
tschatzl@7012 | 1 | /* |
tschatzl@7012 | 2 | * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
tschatzl@7012 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
tschatzl@7012 | 4 | * |
tschatzl@7012 | 5 | * This code is free software; you can redistribute it and/or modify it |
tschatzl@7012 | 6 | * under the terms of the GNU General Public License version 2 only, as |
tschatzl@7012 | 7 | * published by the Free Software Foundation. |
tschatzl@7012 | 8 | * |
tschatzl@7012 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
tschatzl@7012 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
tschatzl@7012 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
tschatzl@7012 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
tschatzl@7012 | 13 | * accompanied this code). |
tschatzl@7012 | 14 | * |
tschatzl@7012 | 15 | * You should have received a copy of the GNU General Public License version |
tschatzl@7012 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
tschatzl@7012 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
tschatzl@7012 | 18 | * |
tschatzl@7012 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
tschatzl@7012 | 20 | * or visit www.oracle.com if you need additional information or have any |
tschatzl@7012 | 21 | * questions. |
tschatzl@7012 | 22 | */ |
tschatzl@7012 | 23 | |
tschatzl@7012 | 24 | /* |
tschatzl@7012 | 25 | * @test TestEagerReclaimHumongousRegions2 |
tschatzl@7012 | 26 | * @bug 8051973 |
tschatzl@7012 | 27 | * @summary Test to make sure that eager reclaim of humongous objects correctly clears |
tschatzl@7012 | 28 | * mark bitmaps at reclaim. |
tschatzl@7012 | 29 | * @key gc |
tschatzl@7012 | 30 | * @library /testlibrary |
tschatzl@7012 | 31 | */ |
tschatzl@7012 | 32 | |
tschatzl@7012 | 33 | import java.util.ArrayList; |
tschatzl@7012 | 34 | import java.util.LinkedList; |
tschatzl@7012 | 35 | import java.util.Random; |
tschatzl@7012 | 36 | |
tschatzl@7012 | 37 | import com.oracle.java.testlibrary.OutputAnalyzer; |
tschatzl@7012 | 38 | import com.oracle.java.testlibrary.ProcessTools; |
tschatzl@7012 | 39 | |
tschatzl@7012 | 40 | // An object that has a few references to other instances to slow down marking. |
tschatzl@7012 | 41 | class ObjectWithSomeRefs { |
tschatzl@7012 | 42 | public ObjectWithSomeRefs other1; |
tschatzl@7012 | 43 | public ObjectWithSomeRefs other2; |
tschatzl@7012 | 44 | public ObjectWithSomeRefs other3; |
tschatzl@7012 | 45 | public ObjectWithSomeRefs other4; |
tschatzl@7012 | 46 | } |
tschatzl@7012 | 47 | |
tschatzl@7012 | 48 | class ReclaimRegionFast { |
tschatzl@7047 | 49 | public static final long MAX_MILLIS_FOR_RUN = 50 * 1000; // The maximum runtime for the actual test. |
tschatzl@7047 | 50 | |
tschatzl@7012 | 51 | public static final int M = 1024*1024; |
tschatzl@7012 | 52 | |
tschatzl@7012 | 53 | public static LinkedList<Object> garbageList = new LinkedList<Object>(); |
tschatzl@7012 | 54 | |
tschatzl@7012 | 55 | public static void genGarbage(Object large) { |
tschatzl@7012 | 56 | for (int i = 0; i < 64*1024; i++) { |
tschatzl@7012 | 57 | Object[] garbage = new Object[50]; |
tschatzl@7012 | 58 | garbage[0] = large; |
tschatzl@7012 | 59 | garbageList.add(garbage); |
tschatzl@7012 | 60 | } |
tschatzl@7012 | 61 | garbageList.clear(); |
tschatzl@7012 | 62 | } |
tschatzl@7012 | 63 | |
tschatzl@7012 | 64 | public static ArrayList<ObjectWithSomeRefs> longList = new ArrayList<ObjectWithSomeRefs>(); |
tschatzl@7012 | 65 | |
tschatzl@7012 | 66 | public static void main(String[] args) { |
tschatzl@7012 | 67 | |
tschatzl@7012 | 68 | for (int i = 0; i < 16*1024; i++) { |
tschatzl@7012 | 69 | longList.add(new ObjectWithSomeRefs()); |
tschatzl@7012 | 70 | } |
tschatzl@7012 | 71 | |
tschatzl@7012 | 72 | Random rnd = new Random(); |
tschatzl@7012 | 73 | for (int i = 0; i < longList.size(); i++) { |
tschatzl@7012 | 74 | int len = longList.size(); |
tschatzl@7012 | 75 | longList.get(i).other1 = longList.get(rnd.nextInt(len)); |
tschatzl@7012 | 76 | longList.get(i).other2 = longList.get(rnd.nextInt(len)); |
tschatzl@7012 | 77 | longList.get(i).other3 = longList.get(rnd.nextInt(len)); |
tschatzl@7012 | 78 | longList.get(i).other4 = longList.get(rnd.nextInt(len)); |
tschatzl@7012 | 79 | } |
tschatzl@7012 | 80 | |
tschatzl@7012 | 81 | int[] large1 = new int[M]; |
tschatzl@7012 | 82 | int[] large2 = null; |
tschatzl@7012 | 83 | int[] large3 = null; |
tschatzl@7012 | 84 | int[] large4 = null; |
tschatzl@7012 | 85 | |
tschatzl@7012 | 86 | Object ref_from_stack = large1; |
tschatzl@7012 | 87 | |
tschatzl@7047 | 88 | long start_millis = System.currentTimeMillis(); |
tschatzl@7047 | 89 | |
tschatzl@7012 | 90 | for (int i = 0; i < 20; i++) { |
tschatzl@7047 | 91 | long current_millis = System.currentTimeMillis(); |
tschatzl@7047 | 92 | if ((current_millis - start_millis) > MAX_MILLIS_FOR_RUN) { |
tschatzl@7047 | 93 | System.out.println("Finishing test because maximum runtime exceeded"); |
tschatzl@7047 | 94 | break; |
tschatzl@7047 | 95 | } |
tschatzl@7012 | 96 | // A set of large objects that will be reclaimed eagerly - and hopefully marked. |
tschatzl@7012 | 97 | large1 = new int[M - 20]; |
tschatzl@7012 | 98 | large2 = new int[M - 20]; |
tschatzl@7012 | 99 | large3 = new int[M - 20]; |
tschatzl@7012 | 100 | large4 = new int[M - 20]; |
tschatzl@7012 | 101 | genGarbage(large1); |
tschatzl@7012 | 102 | // Make sure that the compiler cannot completely remove |
tschatzl@7012 | 103 | // the allocation of the large object until here. |
tschatzl@7012 | 104 | System.out.println(large1 + " " + large2 + " " + large3 + " " + large4); |
tschatzl@7012 | 105 | } |
tschatzl@7012 | 106 | |
tschatzl@7012 | 107 | // Keep the reference to the first object alive. |
tschatzl@7012 | 108 | System.out.println(ref_from_stack); |
tschatzl@7012 | 109 | } |
tschatzl@7012 | 110 | } |
tschatzl@7012 | 111 | |
tschatzl@7012 | 112 | public class TestEagerReclaimHumongousRegions2 { |
tschatzl@7012 | 113 | public static void main(String[] args) throws Exception { |
tschatzl@7012 | 114 | ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( |
tschatzl@7012 | 115 | "-XX:+UseG1GC", |
tschatzl@7012 | 116 | "-Xms128M", |
tschatzl@7012 | 117 | "-Xmx128M", |
tschatzl@7012 | 118 | "-Xmn2M", |
tschatzl@7012 | 119 | "-XX:G1HeapRegionSize=1M", |
tschatzl@7012 | 120 | "-XX:InitiatingHeapOccupancyPercent=0", // Want to have as much as possible initial marks. |
tschatzl@7012 | 121 | "-XX:+PrintGC", |
tschatzl@7012 | 122 | "-XX:+VerifyAfterGC", |
tschatzl@7012 | 123 | "-XX:ConcGCThreads=1", // Want to make marking as slow as possible. |
tschatzl@7012 | 124 | "-XX:+IgnoreUnrecognizedVMOptions", // G1VerifyBitmaps is develop only. |
tschatzl@7012 | 125 | "-XX:+G1VerifyBitmaps", |
tschatzl@7012 | 126 | ReclaimRegionFast.class.getName()); |
tschatzl@7012 | 127 | OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
tschatzl@7012 | 128 | output.shouldHaveExitValue(0); |
tschatzl@7012 | 129 | } |
tschatzl@7012 | 130 | } |
tschatzl@7012 | 131 |