Path: blob/master/test/jdk/sun/java2d/marlin/ArrayCacheSizeTest.java
41149 views
/*1* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import sun.java2d.marlin.ArrayCacheConst;2425/*26* @test27* @bug 814444528* @summary Check the ArrayCache getNewLargeSize() method29* @run main ArrayCacheSizeTest30* @modules java.desktop/sun.java2d.marlin31*/32public class ArrayCacheSizeTest {3334public static void main(String[] args) {35testNewSize();36testNewLargeSize();37}3839private static void testNewSize() {40testNewSize(0, 1);41testNewSize(0, 100000);4243testNewSize(4096, 4097);44testNewSize(4096 * 16, 4096 * 16 + 1);4546testNewSize(4096 * 4096 * 4, 4096 * 4096 * 4 + 1);4748testNewSize(4096 * 4096 * 4, Integer.MAX_VALUE);4950testNewSize(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE);5152testNewSizeExpectAIOB(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE + 1);53testNewSizeExpectAIOB(1, -1);54testNewSizeExpectAIOB(Integer.MAX_VALUE, -1);55}5657private static void testNewSizeExpectAIOB(final int curSize,58final int needSize) {59try {60testNewSize(curSize, needSize);61throw new RuntimeException("ArrayIndexOutOfBoundsException not thrown");62} catch (ArrayIndexOutOfBoundsException aiobe) {63System.out.println("ArrayIndexOutOfBoundsException expected.");64} catch (RuntimeException re) {65throw re;66} catch (Throwable th) {67throw new RuntimeException("Unexpected exception", th);68}69}7071private static void testNewSize(final int curSize,72final int needSize) {7374int size = ArrayCacheConst.getNewSize(curSize, needSize);7576System.out.println("getNewSize(" + curSize + ", " + needSize77+ ") = " + size);7879if (size < 0 || size < needSize) {80throw new IllegalStateException("Invalid getNewSize("81+ curSize + ", " + needSize + ") = " + size + " !");82}83}8485private static void testNewLargeSize() {86testNewLargeSize(0, 1);87testNewLargeSize(0, 100000);8889testNewLargeSize(4096, 4097);90testNewLargeSize(4096 * 16, 4096 * 16 + 1);9192testNewLargeSize(4096 * 4096 * 4, 4096 * 4096 * 4 + 1);9394testNewLargeSize(4096 * 4096 * 4, Integer.MAX_VALUE);9596testNewLargeSize(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE);9798testNewLargeSizeExpectAIOB(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE + 1L);99testNewLargeSizeExpectAIOB(1, -1L);100testNewLargeSizeExpectAIOB(Integer.MAX_VALUE, -1L);101}102103private static void testNewLargeSizeExpectAIOB(final long curSize,104final long needSize) {105try {106testNewLargeSize(curSize, needSize);107throw new RuntimeException("ArrayIndexOutOfBoundsException not thrown");108} catch (ArrayIndexOutOfBoundsException aiobe) {109System.out.println("ArrayIndexOutOfBoundsException expected.");110} catch (RuntimeException re) {111throw re;112} catch (Throwable th) {113throw new RuntimeException("Unexpected exception", th);114}115}116117private static void testNewLargeSize(final long curSize,118final long needSize) {119120long size = ArrayCacheConst.getNewLargeSize(curSize, needSize);121122System.out.println("getNewLargeSize(" + curSize + ", " + needSize123+ ") = " + size);124125if (size < 0 || size < needSize || size > Integer.MAX_VALUE) {126throw new IllegalStateException("Invalid getNewLargeSize("127+ curSize + ", " + needSize + ") = " + size + " !");128}129}130131}132133134