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