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 6800154 27 * @summary Add comments to long_by_long_mulhi() for better understandability 28 * @library /testlibrary 29 * @run main/othervm -Xcomp -XX:CompileOnly=Test6800154.divcomp Test6800154 30 */ 31 32 import java.io.File; 33 import java.net.URL; 34 import java.net.URLClassLoader; 35 import jdk.test.lib.Utils; 36 37 public class Test6800154 implements Runnable { 38 static final long[] DIVIDENDS = { 39 0, 40 1, 41 2, 42 1423487, 43 4444441, 44 4918923241323L, 45 -1, 46 -24351, 47 0x3333, 48 0x0000000080000000L, 49 0x7fffffffffffffffL, 50 0x8000000000000000L 51 }; 52 53 static final long[] DIVISORS = { 54 1, 55 2, 56 17, 57 12342, 58 24123, 59 143444, 60 123444442344L, 61 -1, 62 -2, 63 -4423423234231423L, 64 0x0000000080000000L, 65 0x7fffffffffffffffL, 66 0x8000000000000000L 67 }; 68 69 // Initialize DIVISOR so that it is final in this class. 70 static final long DIVISOR; 71 72 static { 73 long value = 0; 74 try { 75 value = Long.decode(System.getProperty("divisor")); 76 } catch (Throwable e) { 77 } 78 DIVISOR = value; 79 } 80 81 public static void main(String[] args) throws Exception 82 { 83 Class cl = Class.forName("Test6800154"); 84 ClassLoader apploader = cl.getClassLoader(); 85 86 // Iterate over all divisors. 87 for (int i = 0; i < DIVISORS.length; i++) { 88 System.setProperty("divisor", "" + DIVISORS[i]); 89 ClassLoader loader 90 = Utils.getTestClassPathURLClassLoader(apploader.getParent()); 91 Class c = loader.loadClass("Test6800154"); 92 Runnable r = (Runnable) c.newInstance(); 93 r.run(); 94 } 95 } 96 97 public void run() 98 { 99 // Iterate over all dividends. 100 for (int i = 0; i < DIVIDENDS.length; i++) { 101 long dividend = DIVIDENDS[i]; 102 103 long expected = divint(dividend); 104 long result = divcomp(dividend); 105 106 if (result != expected) 107 throw new InternalError(dividend + " / " + DIVISOR + " failed: " + result + " != " + expected); 108 } 109 } 110 111 static long divint(long a) { return a / DIVISOR; } 112 static long divcomp(long a) { return a / DIVISOR; } 113 }