Big.java revision 2362
0N/A/*
2362N/A * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 5045582
0N/A * @summary arrays larger than 1<<30
0N/A * @author Martin Buchholz
0N/A */
0N/A
0N/A// A proper regression test for 5045582 requires too much memory.
0N/A// If you have a really big machine, run like this:
0N/A// java -d64 -Xms25g -Xmx25g Big 30
0N/A
0N/Aimport java.util.*;
0N/A
0N/Apublic class Big {
0N/A
0N/A private static void realMain(String[] args) throws Throwable {
0N/A final int shift = intArg(args, 0, 10); // "30" is real test
0N/A final int tasks = intArg(args, 1, ~0); // all tasks
0N/A final int n = (1<<shift) + 47;
0N/A
0N/A // To test byte arrays larger than 1<<30, you need 1600MB. Run like:
0N/A // java -Xms1600m -Xmx1600m Big 30 1
0N/A if ((tasks & 0x1) != 0) {
0N/A System.out.println("byte[]");
0N/A System.gc();
0N/A byte[] a = new byte[n];
0N/A a[0] = (byte) -44;
0N/A a[1] = (byte) -43;
0N/A a[n-2] = (byte) +43;
0N/A a[n-1] = (byte) +44;
0N/A for (int i : new int[] { 0, 1, n-2, n-1 })
0N/A try { equal(i, Arrays.binarySearch(a, a[i])); }
0N/A catch (Throwable t) { unexpected(t); }
0N/A for (int i : new int[] { n-2, n-1 })
0N/A try { equal(i, Arrays.binarySearch(a, n-5, n, a[i])); }
0N/A catch (Throwable t) { unexpected(t); }
0N/A
0N/A a[n-19] = (byte) 45;
0N/A try { Arrays.sort(a, n-29, n); }
0N/A catch (Throwable t) { unexpected(t); }
0N/A equal(a[n-1], (byte) 45);
0N/A equal(a[n-2], (byte) 44);
0N/A equal(a[n-3], (byte) 43);
0N/A equal(a[n-4], (byte) 0);
0N/A }
0N/A
0N/A // To test Object arrays larger than 1<<30, you need 13GB. Run like:
0N/A // java -d64 -Xms13g -Xmx13g Big 30 2
0N/A if ((tasks & 0x2) != 0) {
0N/A System.out.println("Integer[]");
0N/A System.gc();
0N/A Integer[] a = new Integer[n];
0N/A Integer ZERO = 0;
0N/A Arrays.fill(a, ZERO);
0N/A a[0] = -44;
0N/A a[1] = -43;
0N/A a[n-2] = +43;
0N/A a[n-1] = +44;
0N/A for (int i : new int[] { 0, 1, n-2, n-1 })
0N/A try { equal(i, Arrays.binarySearch(a, a[i])); }
0N/A catch (Throwable t) { unexpected(t); }
0N/A for (int i : new int[] { n-2, n-1 })
0N/A try { equal(i, Arrays.binarySearch(a, n-5, n, a[i])); }
0N/A catch (Throwable t) { unexpected(t); }
0N/A
0N/A a[n-19] = 45;
0N/A try { Arrays.sort(a, n-29, n); }
0N/A catch (Throwable t) { unexpected(t); }
0N/A equal(a[n-1], 45);
0N/A equal(a[n-2], 44);
0N/A equal(a[n-3], 43);
0N/A equal(a[n-4], 0);
0N/A }
0N/A }
0N/A
0N/A //--------------------- Infrastructure ---------------------------
0N/A static volatile int passed = 0, failed = 0;
0N/A static void pass() {passed++;}
0N/A static void fail() {failed++; Thread.dumpStack();}
0N/A static void fail(String msg) {System.out.println(msg); fail();}
0N/A static void unexpected(Throwable t) {failed++; t.printStackTrace();}
0N/A static void check(boolean cond) {if (cond) pass(); else fail();}
0N/A static void equal(Object x, Object y) {
0N/A if (x == null ? y == null : x.equals(y)) pass();
0N/A else fail(x + " not equal to " + y);}
0N/A public static void main(String[] args) throws Throwable {
0N/A try {realMain(args);} catch (Throwable t) {unexpected(t);}
0N/A System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
0N/A if (failed > 0) throw new AssertionError("Some tests failed");}
0N/A static int intArg(String[] args, int i, int defaultValue) {
0N/A return args.length > i ? Integer.parseInt(args[i]) : defaultValue;}
0N/A}