test/hotspot/jtreg/compiler/c2/Test6956668.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 41705 hotspot/test/compiler/c2/Test6956668.java@332239c052cc
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9966
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
     1
/*
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
     4
 *
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
     8
 *
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    13
 * accompanied this code).
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    14
 *
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    18
 *
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    21
 * questions.
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    22
 */
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    23
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    24
/**
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    25
 * @test
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    26
 * @bug 6956668
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    27
 * @summary misbehavior of XOR operator (^) with int
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    28
 *
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    29
 * @run main/othervm -Xbatch compiler.c2.Test6956668
9966
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    30
 */
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    31
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    32
package compiler.c2;
9966
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    33
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    34
public class Test6956668 {
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    35
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    36
   public static int bitTest() {
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    37
      int result = 0;
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    38
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    39
      int testValue = 73;
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    40
      int bitCount = Integer.bitCount(testValue);
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    41
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    42
      if (testValue != 0) {
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    43
         int gap = Long.numberOfTrailingZeros(testValue);
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    44
         testValue >>>= gap;
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    45
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    46
         while (testValue != 0) {
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    47
            result++;
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    48
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    49
            if ((testValue ^= 0x1) != 0) {
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    50
               gap = Long.numberOfTrailingZeros(testValue);
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    51
               testValue >>>= gap;
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    52
            }
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    53
         }
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    54
      }
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    55
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    56
      if (bitCount != result) {
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    57
         System.out.println("ERROR: " + bitCount + " != " + result);
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    58
         System.exit(97);
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    59
      }
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    60
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    61
      return (result);
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    62
   }
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    63
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    64
   public static void main(String[] args) {
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    65
      for (int i = 0; i < 100000; i++) {
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    66
         int ct = bitTest();
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    67
      }
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    68
   }
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents:
diff changeset
    69
}