< prev index next >

test/compiler/c2/Test6603011.java

Print this page




  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 6603011
  27  * @summary long/int division by constant
  28  * @modules java.base/jdk.internal.misc
  29  * @library /testlibrary
  30  * @run main/othervm -Xcomp -Xbatch -XX:-Inline Test

  31  */
  32 
  33 //
  34 // -XX:-Inline is essential to this test so that verification functions
  35 //   divi, modi, divl and modl generate "plain" divides.
  36 // -Xcomp -Xbatch are also useful to ensure the full range of
  37 //   dividend and divisor combinations are tested
  38 //
  39 


  40 import jdk.test.lib.Utils;
  41 
  42 class s {

  43   static int  divi(int  dividend, int  divisor) { return dividend / divisor; }
  44   static int  modi(int  dividend, int  divisor) { return dividend % divisor; }
  45   static long divl(long dividend, long divisor) { return dividend / divisor; }
  46   static long modl(long dividend, long divisor) { return dividend % divisor; }
  47 }
  48 
  49 public class Test implements Runnable {
  50   // Report verbose messages on failure; turn off to suppress
  51   // too much output with gross numbers of failures.
  52   static final boolean VERBOSE = true;
  53 
  54   // Initailize DIVISOR so that it is final in this class.
  55   static final int DIVISOR;
  56   static {
  57     int value = 0;
  58     try {
  59       value = Integer.decode(System.getProperty("divisor"));
  60     } catch (Throwable e) {
  61     }
  62     DIVISOR = value;
  63   }
  64 
  65   // The methods of interest. We want the JIT to compile these
  66   // and convert the divide into a multiply.
  67   public int divbyI (int dividend)   { return dividend / DIVISOR; }
  68   public int modbyI (int dividend)   { return dividend % DIVISOR; }
  69   public long divbyL (long dividend) { return dividend / DIVISOR; }


 177           // Stop on the first failure
 178           // break outerloop;
 179         }
 180       }
 181     }
 182     if (wrong > 0) {
 183       System.out.println("divisor " + divisor() + ": " +
 184                          wrong + "/" + total + " wrong long divisions");
 185     }
 186 
 187   }
 188 
 189   // Reload this class with the "divisor" property set to the input parameter.
 190   // This allows the JIT to see q.DIVISOR as a final constant, and change
 191   // any divisions or mod operations into multiplies.
 192   public static void test_divisor(int divisor,
 193                                   ClassLoader apploader) throws Exception {
 194     System.setProperty("divisor", "" + divisor);
 195     ClassLoader loader
 196                 = Utils.getTestClassPathURLClassLoader(apploader.getParent());
 197     Class c = loader.loadClass("Test");
 198     Runnable r = (Runnable)c.newInstance();
 199     r.run();
 200   }
 201 
 202   public static void main(String[] args) throws Exception {
 203     Class cl = Class.forName("Test");
 204     ClassLoader apploader = cl.getClassLoader();
 205 
 206 
 207     // Test every divisor between -100 and 100.
 208     for (int i = -100; i <= 100; i++) {
 209       test_divisor(i, apploader);
 210     }
 211 
 212     // Try a few divisors outside the typical range.
 213     // The values below have been observed in rt.jar.
 214     test_divisor(101, apploader);
 215     test_divisor(400, apploader);
 216     test_divisor(1000, apploader);
 217     test_divisor(3600, apploader);
 218     test_divisor(9973, apploader);
 219     test_divisor(86400, apploader);
 220     test_divisor(1000000, apploader);
 221   }
 222 
 223 }


  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 6603011
  27  * @summary long/int division by constant
  28  * @modules java.base/jdk.internal.misc
  29  * @library /testlibrary
  30  *
  31  * @run main/othervm -Xcomp -Xbatch -XX:-Inline compiler.c2.Test6603011
  32  */
  33 
  34 //
  35 // -XX:-Inline is essential to this test so that verification functions
  36 //   divi, modi, divl and modl generate "plain" divides.
  37 // -Xcomp -Xbatch are also useful to ensure the full range of
  38 //   dividend and divisor combinations are tested
  39 //
  40 
  41 package compiler.c2;
  42 
  43 import jdk.test.lib.Utils;
  44 
  45 public class Test6603011 implements Runnable {
  46   static class s {
  47     static int  divi(int  dividend, int  divisor) { return dividend / divisor; }
  48     static int  modi(int  dividend, int  divisor) { return dividend % divisor; }
  49     static long divl(long dividend, long divisor) { return dividend / divisor; }
  50     static long modl(long dividend, long divisor) { return dividend % divisor; }
  51   }


  52   // Report verbose messages on failure; turn off to suppress
  53   // too much output with gross numbers of failures.
  54   static final boolean VERBOSE = true;
  55 
  56   // Initailize DIVISOR so that it is final in this class.
  57   static final int DIVISOR;
  58   static {
  59     int value = 0;
  60     try {
  61       value = Integer.decode(System.getProperty("divisor"));
  62     } catch (Throwable e) {
  63     }
  64     DIVISOR = value;
  65   }
  66 
  67   // The methods of interest. We want the JIT to compile these
  68   // and convert the divide into a multiply.
  69   public int divbyI (int dividend)   { return dividend / DIVISOR; }
  70   public int modbyI (int dividend)   { return dividend % DIVISOR; }
  71   public long divbyL (long dividend) { return dividend / DIVISOR; }


 179           // Stop on the first failure
 180           // break outerloop;
 181         }
 182       }
 183     }
 184     if (wrong > 0) {
 185       System.out.println("divisor " + divisor() + ": " +
 186                          wrong + "/" + total + " wrong long divisions");
 187     }
 188 
 189   }
 190 
 191   // Reload this class with the "divisor" property set to the input parameter.
 192   // This allows the JIT to see q.DIVISOR as a final constant, and change
 193   // any divisions or mod operations into multiplies.
 194   public static void test_divisor(int divisor,
 195                                   ClassLoader apploader) throws Exception {
 196     System.setProperty("divisor", "" + divisor);
 197     ClassLoader loader
 198                 = Utils.getTestClassPathURLClassLoader(apploader.getParent());
 199     Class c = loader.loadClass(Test6603011.class.getName());
 200     Runnable r = (Runnable)c.newInstance();
 201     r.run();
 202   }
 203 
 204   public static void main(String[] args) throws Exception {
 205     Class cl = Test6603011.class;
 206     ClassLoader apploader = cl.getClassLoader();
 207 
 208 
 209     // Test every divisor between -100 and 100.
 210     for (int i = -100; i <= 100; i++) {
 211       test_divisor(i, apploader);
 212     }
 213 
 214     // Try a few divisors outside the typical range.
 215     // The values below have been observed in rt.jar.
 216     test_divisor(101, apploader);
 217     test_divisor(400, apploader);
 218     test_divisor(1000, apploader);
 219     test_divisor(3600, apploader);
 220     test_divisor(9973, apploader);
 221     test_divisor(86400, apploader);
 222     test_divisor(1000000, apploader);
 223   }
 224 
 225 }
< prev index next >