1 /*
   2  * Copyright (c) 2009, 2015, 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 6805724
  27  * @summary ModLNode::Ideal() generates functionally incorrect graph
  28  *          when divisor is any (2^k-1) constant.
  29  * @modules java.base/jdk.internal.misc
  30  * @library /testlibrary
  31  * @run main/othervm -Xcomp -XX:CompileOnly=Test6805724.fcomp Test6805724
  32  */
  33 
  34 import jdk.test.lib.Utils;
  35 
  36 public class Test6805724 implements Runnable {
  37     // Initialize DIVISOR so that it is final in this class.
  38     static final long DIVISOR;  // 2^k-1 constant
  39 
  40     static {
  41         long value = 0;
  42         try {
  43             value = Long.decode(System.getProperty("divisor"));
  44         } catch (Throwable t) {
  45             // This one is required for the Class.forName() in main.
  46         }
  47         DIVISOR = value;
  48     }
  49 
  50     static long fint(long x) {
  51         return x % DIVISOR;
  52     }
  53 
  54     static long fcomp(long x) {
  55         return x % DIVISOR;
  56     }
  57 
  58     public void run() {
  59         long a = 0x617981E1L;
  60 
  61         long expected = fint(a);
  62         long result = fcomp(a);
  63 
  64         if (result != expected)
  65             throw new InternalError(result + " != " + expected);
  66     }
  67 
  68     public static void main(String args[]) throws Exception {
  69         Class cl = Class.forName("Test6805724");
  70         ClassLoader apploader = cl.getClassLoader();
  71 
  72         // Iterate over all 2^k-1 divisors.
  73         for (int k = 1; k < Long.SIZE; k++) {
  74             long divisor = (1L << k) - 1;
  75             System.setProperty("divisor", "" + divisor);
  76             ClassLoader loader
  77                     = Utils.getTestClassPathURLClassLoader(apploader.getParent());
  78             Class c = loader.loadClass("Test6805724");
  79             Runnable r = (Runnable) c.newInstance();
  80             r.run();
  81         }
  82     }
  83 }