jdk/test/sun/java2d/marlin/ArrayCacheSizeTest.java
author lbourges
Sat, 09 Jan 2016 14:04:32 +0100
changeset 35665 e90002447fd5
parent 34815 81e87daa9876
child 40421 d5ee65e2b0fb
permissions -rw-r--r--
8146076: Fail of sun/java2d/marlin/CeilAndFloorTests.java with Jigsaw Summary: Added jtreg tag @modules java.desktop/sun.java2d.marlin Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34815
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
     1
/*
35665
e90002447fd5 8146076: Fail of sun/java2d/marlin/CeilAndFloorTests.java with Jigsaw
lbourges
parents: 34815
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
34815
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
     4
 *
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
     7
 * published by the Free Software Foundation.
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
     8
 *
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    13
 * accompanied this code).
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    14
 *
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    18
 *
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    21
 * questions.
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    22
 */
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    23
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    24
import sun.java2d.marlin.ArrayCache;
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    25
35665
e90002447fd5 8146076: Fail of sun/java2d/marlin/CeilAndFloorTests.java with Jigsaw
lbourges
parents: 34815
diff changeset
    26
/*
34815
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    27
 * @test
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    28
 * @bug 8144445
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    29
 * @summary Check the ArrayCache getNewLargeSize() method
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    30
 * @run main ArrayCacheSizeTest
35665
e90002447fd5 8146076: Fail of sun/java2d/marlin/CeilAndFloorTests.java with Jigsaw
lbourges
parents: 34815
diff changeset
    31
 * @modules java.desktop/sun.java2d.marlin
34815
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    32
 */
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    33
public class ArrayCacheSizeTest {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    34
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    35
    public static void main(String[] args) {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    36
        testNewSize();
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    37
        testNewLargeSize();
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    38
    }
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    39
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    40
    private static void testNewSize() {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    41
        testNewSize(0, 1);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    42
        testNewSize(0, 100000);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    43
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    44
        testNewSize(4096, 4097);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    45
        testNewSize(4096 * 16, 4096 * 16 + 1);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    46
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    47
        testNewSize(4096 * 4096 * 4, 4096 * 4096 * 4 + 1);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    48
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    49
        testNewSize(4096 * 4096 * 4, Integer.MAX_VALUE);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    50
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    51
        testNewSize(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    52
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    53
        testNewSizeExpectAIOB(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE + 1);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    54
        testNewSizeExpectAIOB(1, -1);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    55
        testNewSizeExpectAIOB(Integer.MAX_VALUE, -1);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    56
    }
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    57
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    58
    private static void testNewSizeExpectAIOB(final int curSize,
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    59
                                              final int needSize) {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    60
        try {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    61
            testNewSize(curSize, needSize);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    62
            throw new RuntimeException("ArrayIndexOutOfBoundsException not thrown");
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    63
        } catch (ArrayIndexOutOfBoundsException aiobe) {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    64
            System.out.println("ArrayIndexOutOfBoundsException expected.");
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    65
        } catch (RuntimeException re) {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    66
            throw re;
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    67
        } catch (Throwable th) {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    68
            throw new RuntimeException("Unexpected exception", th);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    69
        }
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    70
    }
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    71
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    72
    private static void testNewSize(final int curSize,
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    73
                                    final int needSize) {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    74
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    75
        int size = ArrayCache.getNewSize(curSize, needSize);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    76
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    77
        System.out.println("getNewSize(" + curSize + ", " + needSize
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    78
            + ") = " + size);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    79
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    80
        if (size < 0 || size < needSize) {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    81
            throw new IllegalStateException("Invalid getNewSize("
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    82
                + curSize + ", " + needSize + ") = " + size + " !");
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    83
        }
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    84
    }
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    85
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    86
    private static void testNewLargeSize() {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    87
        testNewLargeSize(0, 1);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    88
        testNewLargeSize(0, 100000);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    89
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    90
        testNewLargeSize(4096, 4097);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    91
        testNewLargeSize(4096 * 16, 4096 * 16 + 1);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    92
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    93
        testNewLargeSize(4096 * 4096 * 4, 4096 * 4096 * 4 + 1);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    94
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    95
        testNewLargeSize(4096 * 4096 * 4, Integer.MAX_VALUE);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    96
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    97
        testNewLargeSize(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    98
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
    99
        testNewLargeSizeExpectAIOB(Integer.MAX_VALUE - 1000, Integer.MAX_VALUE + 1L);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   100
        testNewLargeSizeExpectAIOB(1, -1L);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   101
        testNewLargeSizeExpectAIOB(Integer.MAX_VALUE, -1L);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   102
    }
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   103
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   104
    private static void testNewLargeSizeExpectAIOB(final long curSize,
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   105
                                                   final long needSize) {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   106
        try {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   107
            testNewLargeSize(curSize, needSize);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   108
            throw new RuntimeException("ArrayIndexOutOfBoundsException not thrown");
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   109
        } catch (ArrayIndexOutOfBoundsException aiobe) {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   110
            System.out.println("ArrayIndexOutOfBoundsException expected.");
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   111
        } catch (RuntimeException re) {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   112
            throw re;
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   113
        } catch (Throwable th) {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   114
            throw new RuntimeException("Unexpected exception", th);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   115
        }
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   116
    }
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   117
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   118
    private static void testNewLargeSize(final long curSize,
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   119
                                         final long needSize) {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   120
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   121
        long size = ArrayCache.getNewLargeSize(curSize, needSize);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   122
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   123
        System.out.println("getNewLargeSize(" + curSize + ", " + needSize
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   124
            + ") = " + size);
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   125
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   126
        if (size < 0 || size < needSize || size > Integer.MAX_VALUE) {
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   127
            throw new IllegalStateException("Invalid getNewLargeSize("
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   128
                + curSize + ", " + needSize + ") = " + size + " !");
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   129
        }
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   130
    }
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   131
81e87daa9876 8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
lbourges
parents:
diff changeset
   132
}