Wed, 03 Sep 2014 09:25:44 +0200
Merge
tschatzl@6939 | 1 | /* |
tschatzl@6939 | 2 | * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
tschatzl@6939 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
tschatzl@6939 | 4 | * |
tschatzl@6939 | 5 | * This code is free software; you can redistribute it and/or modify it |
tschatzl@6939 | 6 | * under the terms of the GNU General Public License version 2 only, as |
tschatzl@6939 | 7 | * published by the Free Software Foundation. |
tschatzl@6939 | 8 | * |
tschatzl@6939 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
tschatzl@6939 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
tschatzl@6939 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
tschatzl@6939 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
tschatzl@6939 | 13 | * accompanied this code). |
tschatzl@6939 | 14 | * |
tschatzl@6939 | 15 | * You should have received a copy of the GNU General Public License version |
tschatzl@6939 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
tschatzl@6939 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
tschatzl@6939 | 18 | * |
tschatzl@6939 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
tschatzl@6939 | 20 | * or visit www.oracle.com if you need additional information or have any |
tschatzl@6939 | 21 | * questions. |
tschatzl@6939 | 22 | */ |
tschatzl@6939 | 23 | |
tschatzl@6939 | 24 | /* |
tschatzl@6939 | 25 | * @test TestDeferredRSUpdate |
tschatzl@7013 | 26 | * @bug 8040977 8052170 |
tschatzl@6939 | 27 | * @summary Ensure that running with -XX:-G1DeferredRSUpdate does not crash the VM |
tschatzl@6939 | 28 | * @key gc |
tschatzl@6939 | 29 | * @library /testlibrary |
tschatzl@6939 | 30 | */ |
tschatzl@6939 | 31 | |
tschatzl@6939 | 32 | import com.oracle.java.testlibrary.ProcessTools; |
tschatzl@6939 | 33 | import com.oracle.java.testlibrary.OutputAnalyzer; |
tschatzl@6939 | 34 | |
tschatzl@6939 | 35 | public class TestDeferredRSUpdate { |
tschatzl@6939 | 36 | public static void main(String[] args) throws Exception { |
tschatzl@6939 | 37 | GCTest.main(args); |
tschatzl@6939 | 38 | |
tschatzl@6939 | 39 | ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC", |
tschatzl@6939 | 40 | "-Xmx10M", |
tschatzl@7013 | 41 | "-XX:+PrintGCDetails", |
tschatzl@6939 | 42 | // G1DeferredRSUpdate is a develop option, but we cannot limit execution of this test to only debug VMs. |
tschatzl@6939 | 43 | "-XX:+IgnoreUnrecognizedVMOptions", |
tschatzl@6939 | 44 | "-XX:-G1DeferredRSUpdate", |
tschatzl@6939 | 45 | GCTest.class.getName()); |
tschatzl@6939 | 46 | |
tschatzl@6939 | 47 | OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
tschatzl@6939 | 48 | output.shouldHaveExitValue(0); |
tschatzl@6939 | 49 | } |
tschatzl@6939 | 50 | |
tschatzl@6939 | 51 | static class GCTest { |
tschatzl@6939 | 52 | private static Object[] garbage = new Object[32]; |
tschatzl@6939 | 53 | |
tschatzl@6939 | 54 | public static void main(String [] args) { |
tschatzl@6939 | 55 | System.out.println("Creating garbage"); |
tschatzl@6939 | 56 | // Create 128MB of garbage. This should result in at least one minor GC, with |
tschatzl@6939 | 57 | // some objects copied to old gen. As references from old to young are installed, |
tschatzl@6939 | 58 | // the crash due to the use before initialize occurs. |
tschatzl@6939 | 59 | Object prev = null; |
tschatzl@6939 | 60 | Object prevPrev = null; |
tschatzl@6939 | 61 | for (int i = 0; i < 1024; i++) { |
tschatzl@6939 | 62 | Object[] next = new Object[32 * 1024]; |
tschatzl@6939 | 63 | next[0] = prev; |
tschatzl@6939 | 64 | next[1] = prevPrev; |
tschatzl@6939 | 65 | |
tschatzl@6939 | 66 | Object[] cur = (Object[]) garbage[i % garbage.length]; |
tschatzl@6939 | 67 | if (cur != null) { |
tschatzl@6939 | 68 | cur[0] = null; |
tschatzl@6939 | 69 | cur[1] = null; |
tschatzl@6939 | 70 | } |
tschatzl@6939 | 71 | garbage[i % garbage.length] = next; |
tschatzl@6939 | 72 | |
tschatzl@6939 | 73 | prevPrev = prev; |
tschatzl@6939 | 74 | prev = next; |
tschatzl@6939 | 75 | } |
tschatzl@6939 | 76 | System.out.println("Done"); |
tschatzl@6939 | 77 | } |
tschatzl@6939 | 78 | } |
tschatzl@6939 | 79 | } |