hotspot/test/compiler/intrinsics/string/TestHasNegatives.java
author hseigel
Wed, 01 Mar 2017 08:00:02 -0500
changeset 46194 5596e6f63072
parent 40631 ed82623d7831
permissions -rw-r--r--
8172307: Remove ununsed JVM API JVM_GetModuleByPackageName() Summary: Remove get_module_by_package_name() etc., and unneeded test. Reviewed-by: sspitsyn, gtriantafill
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36808
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
     1
/*
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
     4
 *
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    10
 *
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    15
 * accompanied this code).
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    16
 *
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    20
 *
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    23
 * questions.
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    24
 */
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    25
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    26
/*
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    27
 * @test
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    28
 * @bug 8054307
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    29
 * @summary Validates StringCoding.hasNegatives intrinsic with a small range of tests.
36841
94b23329b108 8152636: TestHasNegatives.java fails after Jigsaw changes were integrated
iignatyev
parents: 36813
diff changeset
    30
 * @library /compiler/patches
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36841
diff changeset
    31
 *
36841
94b23329b108 8152636: TestHasNegatives.java fails after Jigsaw changes were integrated
iignatyev
parents: 36813
diff changeset
    32
 * @build java.base/java.lang.Helper
94b23329b108 8152636: TestHasNegatives.java fails after Jigsaw changes were integrated
iignatyev
parents: 36813
diff changeset
    33
 * @run main compiler.intrinsics.string.TestHasNegatives
36808
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    34
 */
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36841
diff changeset
    35
36841
94b23329b108 8152636: TestHasNegatives.java fails after Jigsaw changes were integrated
iignatyev
parents: 36813
diff changeset
    36
package compiler.intrinsics.string;
36808
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    37
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    38
/*
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    39
 * @summary Validates StringCoding.hasNegatives intrinsic with a small
36841
94b23329b108 8152636: TestHasNegatives.java fails after Jigsaw changes were integrated
iignatyev
parents: 36813
diff changeset
    40
 *          range of tests.
36808
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    41
 */
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    42
public class TestHasNegatives {
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    43
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    44
    private static byte[] tBa = new byte[4096 + 16];
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    45
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    46
    /**
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    47
     * Completely initialize the test array, preparing it for tests of the
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    48
     * StringCoding.hasNegatives method with a given array segment offset,
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    49
     * length, and number of negative bytes.
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    50
     */
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    51
    public static void initialize(int off, int len, int neg) {
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    52
        assert (len + off <= tBa.length);
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    53
        // insert "canary" (negative) values before offset
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    54
        for (int i = 0; i < off; ++i) {
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    55
            tBa[i] = (byte) (((i + 15) & 0x7F) | 0x80);
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    56
        }
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    57
        // fill the array segment
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    58
        for (int i = off; i < len + off; ++i) {
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    59
            tBa[i] = (byte) (((i - off + 15) & 0x7F));
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    60
        }
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    61
        if (neg != 0) {
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    62
            // modify a number (neg) disparate array bytes inside
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    63
            // segment to be negative.
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    64
            int div = (neg > 1) ? (len - 1) / (neg - 1) : 0;
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    65
            int idx;
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    66
            for (int i = 0; i < neg; ++i) {
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    67
                idx = off + (len - 1) - div * i;
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    68
                tBa[idx] = (byte) (0x80 | tBa[idx]);
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    69
            }
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    70
        }
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    71
        // insert "canary" negative values after array segment
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    72
        for (int i = len + off; i < tBa.length; ++i) {
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    73
            tBa[i] = (byte) (((i + 15) & 0x7F) | 0x80);
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    74
        }
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    75
    }
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    76
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    77
    /** Sizes of array segments to test. */
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    78
    private static int sizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 13, 17, 19, 23, 37, 61, 131,
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    79
            4099 };
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    80
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    81
    /**
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    82
     * Test different array segment sizes, offsets, and number of negative
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    83
     * bytes.
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    84
     */
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    85
    public static void test_hasNegatives() throws Exception {
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    86
        int len, off;
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    87
        int ng;
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    88
        boolean r;
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    89
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    90
        for (ng = 0; ng < 57; ++ng) { // number of negatives in array segment
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    91
            for (off = 0; off < 8; ++off) { // starting offset of array segment
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    92
                for (int i = 0; i < sizes.length; ++i) { // array segment size
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    93
                                                         // choice
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    94
                    len = sizes[i];
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    95
                    if (len + off > tBa.length)
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    96
                        continue;
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    97
                    initialize(off, len, ng);
36841
94b23329b108 8152636: TestHasNegatives.java fails after Jigsaw changes were integrated
iignatyev
parents: 36813
diff changeset
    98
                    r = Helper.StringCodingHasNegatives(tBa, off, len);
36808
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
    99
                    if (r ^ ((ng == 0) ? false : true)) {
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   100
                        throw new Exception("Failed test hasNegatives " + "offset: " + off + " "
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   101
                                + "length: " + len + " " + "return: " + r + " " + "negatives: "
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   102
                                + ng);
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   103
                    }
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   104
                }
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   105
            }
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   106
        }
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   107
    }
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   108
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   109
    public void run() throws Exception {
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   110
        // iterate to eventually get intrinsic inlined
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   111
        for (int j = 0; j < 1000; ++j) {
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   112
            test_hasNegatives();
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   113
        }
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   114
    }
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   115
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   116
    public static void main(String[] args) throws Exception {
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   117
        (new TestHasNegatives()).run();
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   118
        System.out.println("hasNegatives validated");
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   119
    }
bae14ddeff3b 8144693: Intrinsify StringCoding.hasNegatives() on SPARC
thartmann
parents:
diff changeset
   120
}