< prev index next >

test/compiler/c2/6603011/Test.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 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 6603011
  27  * @summary long/int division by constant
  28  *
  29  * @run main/othervm -Xcomp -Xbatch -XX:-Inline Test
  30  */
  31 
  32 //
  33 // -XX:-Inline is essential to this test so that verification functions
  34 //   divi, modi, divl and modl generate "plain" divides.
  35 // -Xcomp -Xbatch are also useful to ensure the full range of
  36 //   dividend and divisor combinations are tested
  37 //
  38 
  39 import java.net.*;
  40 
  41 class s {
  42   static int  divi(int  dividend, int  divisor) { return dividend / divisor; }
  43   static int  modi(int  dividend, int  divisor) { return dividend % divisor; }
  44   static long divl(long dividend, long divisor) { return dividend / divisor; }
  45   static long modl(long dividend, long divisor) { return dividend % divisor; }
  46 }
  47 
  48 public class Test implements Runnable {
  49   // Report verbose messages on failure; turn off to suppress
  50   // too much output with gross numbers of failures.
  51   static final boolean VERBOSE = true;
  52 
  53   // Initailize DIVISOR so that it is final in this class.
  54   static final int DIVISOR;
  55   static {
  56     int value = 0;
  57     try {
  58       value = Integer.decode(System.getProperty("divisor"));
  59     } catch (Throwable e) {


 172         total++;
 173         long dividend = ((long)i) << s;
 174         if (!checkL(dividend)) {
 175           wrong++;
 176           // Stop on the first failure
 177           // break outerloop;
 178         }
 179       }
 180     }
 181     if (wrong > 0) {
 182       System.out.println("divisor " + divisor() + ": " +
 183                          wrong + "/" + total + " wrong long divisions");
 184     }
 185 
 186   }
 187 
 188   // Reload this class with the "divisor" property set to the input parameter.
 189   // This allows the JIT to see q.DIVISOR as a final constant, and change
 190   // any divisions or mod operations into multiplies.
 191   public static void test_divisor(int divisor,
 192                                   URLClassLoader apploader) throws Exception {
 193     System.setProperty("divisor", "" + divisor);
 194     ClassLoader loader = new URLClassLoader(apploader.getURLs(),
 195                                             apploader.getParent());
 196     Class c = loader.loadClass("Test");
 197     Runnable r = (Runnable)c.newInstance();
 198     r.run();
 199   }
 200 
 201   public static void main(String[] args) throws Exception {
 202     Class cl = Class.forName("Test");
 203     URLClassLoader apploader = (URLClassLoader)cl.getClassLoader();
 204 
 205 
 206     // Test every divisor between -100 and 100.
 207     for (int i = -100; i <= 100; i++) {
 208       test_divisor(i, apploader);
 209     }
 210 
 211     // Try a few divisors outside the typical range.
 212     // The values below have been observed in rt.jar.
 213     test_divisor(101, apploader);
 214     test_divisor(400, apploader);
 215     test_divisor(1000, apploader);
 216     test_divisor(3600, apploader);
 217     test_divisor(9973, apploader);
 218     test_divisor(86400, apploader);
 219     test_divisor(1000000, apploader);
 220   }
 221 
 222 }
   1 /*
   2  * Copyright (c) 2010, 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 6603011
  27  * @summary long/int division by constant
  28  * @library /testlibrary
  29  * @run main/othervm -Xcomp -Xbatch -XX:-Inline Test
  30  */
  31 
  32 //
  33 // -XX:-Inline is essential to this test so that verification functions
  34 //   divi, modi, divl and modl generate "plain" divides.
  35 // -Xcomp -Xbatch are also useful to ensure the full range of
  36 //   dividend and divisor combinations are tested
  37 //
  38 
  39 import jdk.test.lib.Utils;
  40 
  41 class s {
  42   static int  divi(int  dividend, int  divisor) { return dividend / divisor; }
  43   static int  modi(int  dividend, int  divisor) { return dividend % divisor; }
  44   static long divl(long dividend, long divisor) { return dividend / divisor; }
  45   static long modl(long dividend, long divisor) { return dividend % divisor; }
  46 }
  47 
  48 public class Test implements Runnable {
  49   // Report verbose messages on failure; turn off to suppress
  50   // too much output with gross numbers of failures.
  51   static final boolean VERBOSE = true;
  52 
  53   // Initailize DIVISOR so that it is final in this class.
  54   static final int DIVISOR;
  55   static {
  56     int value = 0;
  57     try {
  58       value = Integer.decode(System.getProperty("divisor"));
  59     } catch (Throwable e) {


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