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