test/compiler/6896617/Test6896617.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff test/compiler/6896617

test/compiler/6896617/Test6896617.java

Print this page
rev 7259 : 8044186: Introduce a reproducible random generator
Reviewed-by: iignatyev
Contributed-by: sergei.kovalev@oracle.com
   1 /*
   2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6896617
  27  * @summary Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() with SSE instructions on x86

  28  * @run main/othervm/timeout=1200 -Xbatch -Xmx256m Test6896617
  29  *
  30  */
  31 
  32 import java.util.*;
  33 import java.nio.*;
  34 import java.nio.charset.*;






  35 
  36 public class Test6896617 {
  37     final static int SIZE = 256;
  38 
  39     public static void main(String[] args) {
  40         String csn = "ISO-8859-1";
  41         Charset cs = Charset.forName(csn);
  42         CharsetEncoder enc = cs.newEncoder();
  43         enc.onMalformedInput(CodingErrorAction.REPLACE)
  44            .onUnmappableCharacter(CodingErrorAction.REPLACE);
  45         CharsetDecoder dec = cs.newDecoder();
  46         dec.onMalformedInput(CodingErrorAction.REPLACE)
  47            .onUnmappableCharacter(CodingErrorAction.REPLACE);
  48 
  49         byte repl = (byte)'?';
  50         enc.replaceWith(new byte[] { repl });
  51 
  52         // Use internal API for tests.
  53         sun.nio.cs.ArrayEncoder arrenc = (sun.nio.cs.ArrayEncoder)enc;
  54         sun.nio.cs.ArrayDecoder arrdec = (sun.nio.cs.ArrayDecoder)dec;
  55 
  56         // Populate char[] with chars which can be encoded by ISO_8859_1 (<= 0xFF)
  57         Random rnd = new Random(0);
  58         int maxchar = 0xFF;
  59         char[] a = new char[SIZE];
  60         byte[] b = new byte[SIZE];
  61         char[] at = new char[SIZE];
  62         byte[] bt = new byte[SIZE];
  63         for (int i = 0; i < SIZE; i++) {
  64             char c = (char) rnd.nextInt(maxchar);
  65             if (!enc.canEncode(c)) {
  66                 System.out.printf("Something wrong: can't encode c=%03x\n", (int)c);
  67                 System.exit(97);
  68             }
  69             a[i] = c;
  70             b[i] = (byte)c;
  71             at[i] = (char)-1;
  72             bt[i] = (byte)-1;
  73         }
  74         if (arrenc.encode(a, 0, SIZE, bt) != SIZE || !Arrays.equals(b, bt)) {
  75             System.out.println("Something wrong: ArrayEncoder.encode failed");
  76             System.exit(97);
  77         }


   1 /*
   2  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6896617
  27  * @summary Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() with SSE instructions on x86
  28  * @library /testlibrary
  29  * @run main/othervm/timeout=1200 -Xbatch -Xmx256m Test6896617
  30  *
  31  */
  32 
  33 import com.oracle.java.testlibrary.Utils;
  34 import java.nio.ByteBuffer;
  35 import java.nio.CharBuffer;
  36 import java.nio.charset.Charset;
  37 import java.nio.charset.CharsetDecoder;
  38 import java.nio.charset.CharsetEncoder;
  39 import java.nio.charset.CodingErrorAction;
  40 import java.util.Arrays;
  41 import java.util.Random;
  42 
  43 public class Test6896617 {
  44     final static int SIZE = 256;
  45 
  46     public static void main(String[] args) {
  47         String csn = "ISO-8859-1";
  48         Charset cs = Charset.forName(csn);
  49         CharsetEncoder enc = cs.newEncoder();
  50         enc.onMalformedInput(CodingErrorAction.REPLACE)
  51            .onUnmappableCharacter(CodingErrorAction.REPLACE);
  52         CharsetDecoder dec = cs.newDecoder();
  53         dec.onMalformedInput(CodingErrorAction.REPLACE)
  54            .onUnmappableCharacter(CodingErrorAction.REPLACE);
  55 
  56         byte repl = (byte)'?';
  57         enc.replaceWith(new byte[] { repl });
  58 
  59         // Use internal API for tests.
  60         sun.nio.cs.ArrayEncoder arrenc = (sun.nio.cs.ArrayEncoder)enc;
  61         sun.nio.cs.ArrayDecoder arrdec = (sun.nio.cs.ArrayDecoder)dec;
  62 
  63         // Populate char[] with chars which can be encoded by ISO_8859_1 (<= 0xFF)
  64         Random rnd = Utils.getRandomInstance();
  65         int maxchar = 0xFF;
  66         char[] a = new char[SIZE];
  67         byte[] b = new byte[SIZE];
  68         char[] at = new char[SIZE];
  69         byte[] bt = new byte[SIZE];
  70         for (int i = 0; i < SIZE; i++) {
  71             char c = (char) rnd.nextInt(maxchar);
  72             if (!enc.canEncode(c)) {
  73                 System.out.printf("Something wrong: can't encode c=%03x\n", (int)c);
  74                 System.exit(97);
  75             }
  76             a[i] = c;
  77             b[i] = (byte)c;
  78             at[i] = (char)-1;
  79             bt[i] = (byte)-1;
  80         }
  81         if (arrenc.encode(a, 0, SIZE, bt) != SIZE || !Arrays.equals(b, bt)) {
  82             System.out.println("Something wrong: ArrayEncoder.encode failed");
  83             System.exit(97);
  84         }


test/compiler/6896617/Test6896617.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File