hotspot/test/compiler/6661247/Test.java
changeset 243 79b67a7a584a
child 603 0e934fae2fc2
equal deleted inserted replaced
242:f4a8c30a53b0 243:79b67a7a584a
       
     1 /*
       
     2  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
       
     3  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
       
     4  *
       
     5  *
       
     6  *
       
     7  *
       
     8  *
       
     9  *
       
    10  *
       
    11  *
       
    12  *
       
    13  *
       
    14  *
       
    15  *
       
    16  *
       
    17  *
       
    18  *
       
    19  *
       
    20  *
       
    21  *
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 6661247
       
    27  * @summary Internal bug in 32-bit HotSpot optimizer while bit manipulations
       
    28  */
       
    29 
       
    30 import java.util.Random;
       
    31 import java.nio.*;
       
    32 
       
    33 // This isn't a completely reliable test for 6661247 since the results
       
    34 // depend on what the local schedule looks like but it does reproduce
       
    35 // the issue in current builds.
       
    36 
       
    37 public class Test {
       
    38 
       
    39     public static void test(boolean[] src, int srcPos, LongBuffer dest, long destPos, int count) {
       
    40         int countStart = (destPos & 63) == 0 ? 0 : 64 - (int)(destPos & 63);
       
    41         if (countStart > count)
       
    42             countStart = count;
       
    43         for (int srcPosMax = srcPos + countStart; srcPos < srcPosMax; srcPos++, destPos++) {
       
    44             if (src[srcPos])
       
    45                 dest.put((int)(destPos >>> 6), dest.get((int)(destPos >>> 6)) | 1L << (destPos & 63));
       
    46             else
       
    47                 dest.put((int)(destPos >>> 6), dest.get((int)(destPos >>> 6)) & ~(1L << (destPos & 63)));
       
    48         }
       
    49         count -= countStart;
       
    50         int cnt = count >>> 6;
       
    51         for (int k = (int)(destPos >>> 6), kMax = k + cnt; k < kMax; k++) {
       
    52             int low = (src[srcPos] ? 1 : 0)
       
    53                 | (src[srcPos + 1] ? 1 << 1 : 0)
       
    54                 | (src[srcPos + 2] ? 1 << 2 : 0)
       
    55                 | (src[srcPos + 3] ? 1 << 3 : 0)
       
    56                 | (src[srcPos + 4] ? 1 << 4 : 0)
       
    57                 | (src[srcPos + 5] ? 1 << 5 : 0)
       
    58                 | (src[srcPos + 6] ? 1 << 6 : 0)
       
    59                 | (src[srcPos + 7] ? 1 << 7 : 0)
       
    60                 | (src[srcPos + 8] ? 1 << 8 : 0)
       
    61                 | (src[srcPos + 9] ? 1 << 9 : 0)
       
    62                 | (src[srcPos + 10] ? 1 << 10 : 0)
       
    63                 | (src[srcPos + 11] ? 1 << 11 : 0)
       
    64                 | (src[srcPos + 12] ? 1 << 12 : 0)
       
    65                 | (src[srcPos + 13] ? 1 << 13 : 0)
       
    66                 | (src[srcPos + 14] ? 1 << 14 : 0)
       
    67                 | (src[srcPos + 15] ? 1 << 15 : 0)
       
    68                 | (src[srcPos + 16] ? 1 << 16 : 0)
       
    69                 | (src[srcPos + 17] ? 1 << 17 : 0)
       
    70                 | (src[srcPos + 18] ? 1 << 18 : 0)
       
    71                 | (src[srcPos + 19] ? 1 << 19 : 0)
       
    72                 | (src[srcPos + 20] ? 1 << 20 : 0)
       
    73                 | (src[srcPos + 21] ? 1 << 21 : 0)
       
    74                 | (src[srcPos + 22] ? 1 << 22 : 0)
       
    75                 | (src[srcPos + 23] ? 1 << 23 : 0)
       
    76                 | (src[srcPos + 24] ? 1 << 24 : 0)
       
    77                 | (src[srcPos + 25] ? 1 << 25 : 0)
       
    78                 | (src[srcPos + 26] ? 1 << 26 : 0)
       
    79                 | (src[srcPos + 27] ? 1 << 27 : 0)
       
    80                 | (src[srcPos + 28] ? 1 << 28 : 0)
       
    81                 | (src[srcPos + 29] ? 1 << 29 : 0)
       
    82                 | (src[srcPos + 30] ? 1 << 30 : 0)
       
    83                 | (src[srcPos + 31] ? 1 << 31 : 0)
       
    84                 ;
       
    85             srcPos += 32;
       
    86             int high = (src[srcPos] ? 1 : 0)        // PROBLEM!
       
    87                 | (src[srcPos + 1] ? 1 << 1 : 0)
       
    88                 | (src[srcPos + 2] ? 1 << 2 : 0)
       
    89                 | (src[srcPos + 3] ? 1 << 3 : 0)
       
    90                 | (src[srcPos + 4] ? 1 << 4 : 0)
       
    91                 | (src[srcPos + 5] ? 1 << 5 : 0)
       
    92                 | (src[srcPos + 6] ? 1 << 6 : 0)
       
    93                 | (src[srcPos + 7] ? 1 << 7 : 0)
       
    94                 | (src[srcPos + 8] ? 1 << 8 : 0)
       
    95                 | (src[srcPos + 9] ? 1 << 9 : 0)
       
    96                 | (src[srcPos + 10] ? 1 << 10 : 0)
       
    97                 | (src[srcPos + 11] ? 1 << 11 : 0)
       
    98                 | (src[srcPos + 12] ? 1 << 12 : 0)
       
    99                 | (src[srcPos + 13] ? 1 << 13 : 0)
       
   100                 | (src[srcPos + 14] ? 1 << 14 : 0)
       
   101                 | (src[srcPos + 15] ? 1 << 15 : 0)
       
   102                 | (src[srcPos + 16] ? 1 << 16 : 0)
       
   103                 | (src[srcPos + 17] ? 1 << 17 : 0)
       
   104                 | (src[srcPos + 18] ? 1 << 18 : 0)
       
   105                 | (src[srcPos + 19] ? 1 << 19 : 0)
       
   106                 | (src[srcPos + 20] ? 1 << 20 : 0)
       
   107                 | (src[srcPos + 21] ? 1 << 21 : 0)
       
   108                 | (src[srcPos + 22] ? 1 << 22 : 0)
       
   109                 | (src[srcPos + 23] ? 1 << 23 : 0)
       
   110                 | (src[srcPos + 24] ? 1 << 24 : 0)
       
   111                 | (src[srcPos + 25] ? 1 << 25 : 0)
       
   112                 | (src[srcPos + 26] ? 1 << 26 : 0)
       
   113                 | (src[srcPos + 27] ? 1 << 27 : 0)
       
   114                 | (src[srcPos + 28] ? 1 << 28 : 0)
       
   115                 | (src[srcPos + 29] ? 1 << 29 : 0)
       
   116                 | (src[srcPos + 30] ? 1 << 30 : 0)
       
   117                 | (src[srcPos + 31] ? 1 << 31 : 0)
       
   118                 ;
       
   119             srcPos += 32;
       
   120             dest.put(k, ((long)low & 0xFFFFFFFFL) | (((long)high) << 32));
       
   121             destPos += 64;
       
   122         }
       
   123         int countFinish = count & 63;
       
   124         for (int srcPosMax = srcPos + countFinish; srcPos < srcPosMax; srcPos++, destPos++) {
       
   125             if (src[srcPos])
       
   126                 dest.put((int)(destPos >>> 6), dest.get((int)(destPos >>> 6)) | 1L << (destPos & 63));
       
   127             else
       
   128                 dest.put((int)(destPos >>> 6), dest.get((int)(destPos >>> 6)) & ~(1L << (destPos & 63)));
       
   129         }
       
   130     }
       
   131     public static void main(String[] args) {
       
   132         Random r = new Random();
       
   133         int entries = 1000;
       
   134         boolean[] src = new boolean[entries * 64];
       
   135         long[] dest = new long[entries];
       
   136         long[] result = new long[entries];
       
   137 
       
   138         for (int c = 0; c < 2000; c++) {
       
   139             for (int i = 0; i < entries; i++) {
       
   140                 long l = r.nextLong();
       
   141                 for (int bit = 0; bit < 64; bit++) {
       
   142                     src[i * 64 + bit] = (l & (1L << bit)) != 0;
       
   143                 }
       
   144                 dest[i] = 0;
       
   145                 result[i] = l;
       
   146             }
       
   147             test(src, 0, LongBuffer.wrap(dest, 0, dest.length), 0, src.length);
       
   148             for (int i = 0; i < entries; i++) {
       
   149                 if (dest[i] != result[i]) {
       
   150                     throw new InternalError(i + ": " + Long.toHexString(dest[i]) + " != " + Long.toHexString(result[i]));
       
   151                 }
       
   152             }
       
   153         }
       
   154     }
       
   155 }