< prev index next >

test/compiler/intrinsics/string/TestHasNegatives.java

Print this page
rev 10528 : 8152636: TestHasNegatives.java fails after Jigsaw changes were integrated
Reviewed-by:


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * @test
  28  * @bug 8054307
  29  * @ignore 8152636
  30  * @summary Validates StringCoding.hasNegatives intrinsic with a small range of tests.
  31  * @run main/bootclasspath java.lang.TestHasNegatives



  32  */
  33 package java.lang;
  34 
  35 import java.lang.StringCoding;
  36 
  37 /*
  38  * @summary Validates StringCoding.hasNegatives intrinsic with a small
  39  *          range of tests.  Must be run with modified bootclasspath
  40  *          to allow existence in java.lang package.
  41  */
  42 public class TestHasNegatives {
  43 
  44     private static byte[] tBa = new byte[4096 + 16];
  45 
  46     /**
  47      * Completely initialize the test array, preparing it for tests of the
  48      * StringCoding.hasNegatives method with a given array segment offset,
  49      * length, and number of negative bytes.
  50      */
  51     public static void initialize(int off, int len, int neg) {
  52         assert (len + off <= tBa.length);
  53         // insert "canary" (negative) values before offset
  54         for (int i = 0; i < off; ++i) {
  55             tBa[i] = (byte) (((i + 15) & 0x7F) | 0x80);
  56         }
  57         // fill the array segment
  58         for (int i = off; i < len + off; ++i) {
  59             tBa[i] = (byte) (((i - off + 15) & 0x7F));
  60         }


  78     private static int sizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 13, 17, 19, 23, 37, 61, 131,
  79             4099 };
  80 
  81     /**
  82      * Test different array segment sizes, offsets, and number of negative
  83      * bytes.
  84      */
  85     public static void test_hasNegatives() throws Exception {
  86         int len, off;
  87         int ng;
  88         boolean r;
  89 
  90         for (ng = 0; ng < 57; ++ng) { // number of negatives in array segment
  91             for (off = 0; off < 8; ++off) { // starting offset of array segment
  92                 for (int i = 0; i < sizes.length; ++i) { // array segment size
  93                                                          // choice
  94                     len = sizes[i];
  95                     if (len + off > tBa.length)
  96                         continue;
  97                     initialize(off, len, ng);
  98                     r = StringCoding.hasNegatives(tBa, off, len);
  99                     if (r ^ ((ng == 0) ? false : true)) {
 100                         throw new Exception("Failed test hasNegatives " + "offset: " + off + " "
 101                                 + "length: " + len + " " + "return: " + r + " " + "negatives: "
 102                                 + ng);
 103                     }
 104                 }
 105             }
 106         }
 107     }
 108 
 109     public void run() throws Exception {
 110         // iterate to eventually get intrinsic inlined
 111         for (int j = 0; j < 1000; ++j) {
 112             test_hasNegatives();
 113         }
 114     }
 115 
 116     public static void main(String[] args) throws Exception {
 117         (new TestHasNegatives()).run();
 118         System.out.println("hasNegatives validated");


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * @test
  28  * @bug 8054307

  29  * @summary Validates StringCoding.hasNegatives intrinsic with a small range of tests.
  30  * @library /compiler/patches
  31  * @build java.base/java.lang.Helper
  32  * @build compiler.intrinsics.string.TestHasNegatives
  33  * @run main compiler.intrinsics.string.TestHasNegatives
  34  */
  35 package compiler.intrinsics.string;
  36 
  37 import java.lang.Helper;
  38 
  39 /*
  40  * @summary Validates StringCoding.hasNegatives intrinsic with a small
  41  *          range of tests.

  42  */
  43 public class TestHasNegatives {
  44 
  45     private static byte[] tBa = new byte[4096 + 16];
  46 
  47     /**
  48      * Completely initialize the test array, preparing it for tests of the
  49      * StringCoding.hasNegatives method with a given array segment offset,
  50      * length, and number of negative bytes.
  51      */
  52     public static void initialize(int off, int len, int neg) {
  53         assert (len + off <= tBa.length);
  54         // insert "canary" (negative) values before offset
  55         for (int i = 0; i < off; ++i) {
  56             tBa[i] = (byte) (((i + 15) & 0x7F) | 0x80);
  57         }
  58         // fill the array segment
  59         for (int i = off; i < len + off; ++i) {
  60             tBa[i] = (byte) (((i - off + 15) & 0x7F));
  61         }


  79     private static int sizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 13, 17, 19, 23, 37, 61, 131,
  80             4099 };
  81 
  82     /**
  83      * Test different array segment sizes, offsets, and number of negative
  84      * bytes.
  85      */
  86     public static void test_hasNegatives() throws Exception {
  87         int len, off;
  88         int ng;
  89         boolean r;
  90 
  91         for (ng = 0; ng < 57; ++ng) { // number of negatives in array segment
  92             for (off = 0; off < 8; ++off) { // starting offset of array segment
  93                 for (int i = 0; i < sizes.length; ++i) { // array segment size
  94                                                          // choice
  95                     len = sizes[i];
  96                     if (len + off > tBa.length)
  97                         continue;
  98                     initialize(off, len, ng);
  99                     r = Helper.StringCodingHasNegatives(tBa, off, len);
 100                     if (r ^ ((ng == 0) ? false : true)) {
 101                         throw new Exception("Failed test hasNegatives " + "offset: " + off + " "
 102                                 + "length: " + len + " " + "return: " + r + " " + "negatives: "
 103                                 + ng);
 104                     }
 105                 }
 106             }
 107         }
 108     }
 109 
 110     public void run() throws Exception {
 111         // iterate to eventually get intrinsic inlined
 112         for (int j = 0; j < 1000; ++j) {
 113             test_hasNegatives();
 114         }
 115     }
 116 
 117     public static void main(String[] args) throws Exception {
 118         (new TestHasNegatives()).run();
 119         System.out.println("hasNegatives validated");
< prev index next >