< prev index next >

test/compiler/codegen/6823354/Test6823354.java

Print this page


   1 /*
   2  * Copyright (c) 2009, 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 6823354
  27  * @summary These methods can be instrinsified by using bit scan, bit test, and population count instructions.
  28  *
  29  * @run main/othervm -Xcomp -XX:CompileOnly=Test6823354.lzcomp,Test6823354.tzcomp,.dolzcomp,.dotzcomp Test6823354
  30  */
  31 


  32 import java.net.URLClassLoader;

  33 
  34 public class Test6823354 {
  35     // Arrays of corner case values.
  36     static final int[]  ia = new int[]  { 0,  1,  -1,  Integer.MIN_VALUE, Integer.MAX_VALUE };
  37     static final long[] la = new long[] { 0L, 1L, -1L, Long.MIN_VALUE,    Long.MAX_VALUE    };
  38 
  39     public static void main(String[] args) throws Exception {
  40         // Load the classes and the methods.
  41         Integer.numberOfLeadingZeros(0);
  42         Integer.numberOfTrailingZeros(0);
  43         Long.numberOfLeadingZeros(0);
  44         Long.numberOfTrailingZeros(0);
  45 
  46         lz();
  47         tz();
  48     }
  49 
  50     static void lz() throws Exception {
  51         // int
  52 


 180     static int lzcomp(long l) { return Long.numberOfLeadingZeros(l); }
 181 
 182     static int tzint( int i)  { return Integer.numberOfTrailingZeros(i); }
 183     static int tzcomp(int i)  { return Integer.numberOfTrailingZeros(i); }
 184 
 185     static int tzint( long l) { return Long.numberOfTrailingZeros(l); }
 186     static int tzcomp(long l) { return Long.numberOfTrailingZeros(l); }
 187 
 188     static void testclass(String classname, int x) throws Exception {
 189         System.setProperty("value", "" + x);
 190         loadandrunclass(classname);
 191     }
 192 
 193     static void testclass(String classname, long x) throws Exception {
 194         System.setProperty("value", "" + x);
 195         loadandrunclass(classname);
 196     }
 197 
 198     static void loadandrunclass(String classname) throws Exception {
 199         Class cl = Class.forName(classname);
 200         URLClassLoader apploader = (URLClassLoader) cl.getClassLoader();
 201         ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent());

 202         Class c = loader.loadClass(classname);
 203         Runnable r = (Runnable) c.newInstance();
 204         r.run();
 205     }
 206 
 207     public static class lzconI implements Runnable {
 208         static final int VALUE;
 209 
 210         static {
 211             int value = 0;
 212             try {
 213                 value = Integer.decode(System.getProperty("value"));
 214             } catch (Throwable e) {}
 215             VALUE = value;
 216         }
 217 
 218         public void run() { check(VALUE, lzint(VALUE), dolzcomp()); }
 219         static int dolzcomp() { return lzcomp(VALUE); }
 220     }
 221 


   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 6823354
  27  * @summary These methods can be instrinsified by using bit scan, bit test, and population count instructions.
  28  * @library /testlibrary
  29  * @run main/othervm -Xcomp -XX:CompileOnly=Test6823354.lzcomp,Test6823354.tzcomp,.dolzcomp,.dotzcomp Test6823354
  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 Test6823354 {
  38     // Arrays of corner case values.
  39     static final int[]  ia = new int[]  { 0,  1,  -1,  Integer.MIN_VALUE, Integer.MAX_VALUE };
  40     static final long[] la = new long[] { 0L, 1L, -1L, Long.MIN_VALUE,    Long.MAX_VALUE    };
  41 
  42     public static void main(String[] args) throws Exception {
  43         // Load the classes and the methods.
  44         Integer.numberOfLeadingZeros(0);
  45         Integer.numberOfTrailingZeros(0);
  46         Long.numberOfLeadingZeros(0);
  47         Long.numberOfTrailingZeros(0);
  48 
  49         lz();
  50         tz();
  51     }
  52 
  53     static void lz() throws Exception {
  54         // int
  55 


 183     static int lzcomp(long l) { return Long.numberOfLeadingZeros(l); }
 184 
 185     static int tzint( int i)  { return Integer.numberOfTrailingZeros(i); }
 186     static int tzcomp(int i)  { return Integer.numberOfTrailingZeros(i); }
 187 
 188     static int tzint( long l) { return Long.numberOfTrailingZeros(l); }
 189     static int tzcomp(long l) { return Long.numberOfTrailingZeros(l); }
 190 
 191     static void testclass(String classname, int x) throws Exception {
 192         System.setProperty("value", "" + x);
 193         loadandrunclass(classname);
 194     }
 195 
 196     static void testclass(String classname, long x) throws Exception {
 197         System.setProperty("value", "" + x);
 198         loadandrunclass(classname);
 199     }
 200 
 201     static void loadandrunclass(String classname) throws Exception {
 202         Class cl = Class.forName(classname);
 203         ClassLoader apploader = cl.getClassLoader();
 204         ClassLoader loader
 205                 = Utils.getTestClassPathURLClassLoader(apploader.getParent());
 206         Class c = loader.loadClass(classname);
 207         Runnable r = (Runnable) c.newInstance();
 208         r.run();
 209     }
 210 
 211     public static class lzconI implements Runnable {
 212         static final int VALUE;
 213 
 214         static {
 215             int value = 0;
 216             try {
 217                 value = Integer.decode(System.getProperty("value"));
 218             } catch (Throwable e) {}
 219             VALUE = value;
 220         }
 221 
 222         public void run() { check(VALUE, lzint(VALUE), dolzcomp()); }
 223         static int dolzcomp() { return lzcomp(VALUE); }
 224     }
 225 


< prev index next >