Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/java2d/marlin/ArrayCacheSizeTest.java
38838 views
/*1* Copyright (c) 2015, 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.ArrayCache;2425/**26* @test27* @bug 814444528* @summary Check the ArrayCache getNewLargeSize() method29* @run main ArrayCacheSizeTest30*/31public class ArrayCacheSizeTest {3233public static void main(String[] args) {34testNewSize();35testNewLargeSize();36}3738private static void testNewSize() {39testNewSize(0, 1);40testNewSize(0, 100000);4142testNewSize(4096, 4097);43testNewSize(4096 * 16, 4096 * 16 + 1);4445testNewSize(4096 * 4096 * 4, 4096 * 4096 * 4 + 1);4647testNewSize(4096 * 4096 * 4, Integer.MAX_VALUE);4849testNewSize(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE);5051testNewSizeExpectAIOB(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE + 1);52testNewSizeExpectAIOB(1, -1);53testNewSizeExpectAIOB(Integer.MAX_VALUE, -1);54}5556private static void testNewSizeExpectAIOB(final int curSize,57final int needSize) {58try {59testNewSize(curSize, needSize);60throw new RuntimeException("ArrayIndexOutOfBoundsException not thrown");61} catch (ArrayIndexOutOfBoundsException aiobe) {62System.out.println("ArrayIndexOutOfBoundsException expected.");63} catch (RuntimeException re) {64throw re;65} catch (Throwable th) {66throw new RuntimeException("Unexpected exception", th);67}68}6970private static void testNewSize(final int curSize,71final int needSize) {7273int size = ArrayCache.getNewSize(curSize, needSize);7475System.out.println("getNewSize(" + curSize + ", " + needSize76+ ") = " + size);7778if (size < 0 || size < needSize) {79throw new IllegalStateException("Invalid getNewSize("80+ curSize + ", " + needSize + ") = " + size + " !");81}82}8384private static void testNewLargeSize() {85testNewLargeSize(0, 1);86testNewLargeSize(0, 100000);8788testNewLargeSize(4096, 4097);89testNewLargeSize(4096 * 16, 4096 * 16 + 1);9091testNewLargeSize(4096 * 4096 * 4, 4096 * 4096 * 4 + 1);9293testNewLargeSize(4096 * 4096 * 4, Integer.MAX_VALUE);9495testNewLargeSize(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE);9697testNewLargeSizeExpectAIOB(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE + 1L);98testNewLargeSizeExpectAIOB(1, -1L);99testNewLargeSizeExpectAIOB(Integer.MAX_VALUE, -1L);100}101102private static void testNewLargeSizeExpectAIOB(final long curSize,103final long needSize) {104try {105testNewLargeSize(curSize, needSize);106throw new RuntimeException("ArrayIndexOutOfBoundsException not thrown");107} catch (ArrayIndexOutOfBoundsException aiobe) {108System.out.println("ArrayIndexOutOfBoundsException expected.");109} catch (RuntimeException re) {110throw re;111} catch (Throwable th) {112throw new RuntimeException("Unexpected exception", th);113}114}115116private static void testNewLargeSize(final long curSize,117final long needSize) {118119long size = ArrayCache.getNewLargeSize(curSize, needSize);120121System.out.println("getNewLargeSize(" + curSize + ", " + needSize122+ ") = " + size);123124if (size < 0 || size < needSize || size > Integer.MAX_VALUE) {125throw new IllegalStateException("Invalid getNewLargeSize("126+ curSize + ", " + needSize + ") = " + size + " !");127}128}129130}131132133