< prev index next >

test/compiler/c2/6805724/Test6805724.java

Print this page


   1 /*
   2  * Copyright (c) 2009, 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 when divisor is any (2^k-1) constant.
  28  *

  29  * @run main/othervm -Xcomp -XX:CompileOnly=Test6805724.fcomp Test6805724
  30  */
  31 
  32 import java.net.URLClassLoader;
  33 
  34 public class Test6805724 implements Runnable {
  35     // Initialize DIVISOR so that it is final in this class.
  36     static final long DIVISOR;  // 2^k-1 constant
  37 
  38     static {
  39         long value = 0;
  40         try {
  41             value = Long.decode(System.getProperty("divisor"));
  42         } catch (Throwable t) {
  43             // This one is required for the Class.forName() in main.
  44         }
  45         DIVISOR = value;
  46     }
  47 
  48     static long fint(long x) {
  49         return x % DIVISOR;
  50     }
  51 
  52     static long fcomp(long x) {
  53         return x % DIVISOR;
  54     }
  55 
  56     public void run() {
  57         long a = 0x617981E1L;
  58 
  59         long expected = fint(a);
  60         long result = fcomp(a);
  61 
  62         if (result != expected)
  63             throw new InternalError(result + " != " + expected);
  64     }
  65 
  66     public static void main(String args[]) throws Exception {
  67         Class cl = Class.forName("Test6805724");
  68         URLClassLoader apploader = (URLClassLoader) cl.getClassLoader();
  69 
  70         // Iterate over all 2^k-1 divisors.
  71         for (int k = 1; k < Long.SIZE; k++) {
  72             long divisor = (1L << k) - 1;
  73             System.setProperty("divisor", "" + divisor);
  74             ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent());

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