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 jdk.test.lib.Utils; 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 ClassLoader apploader = cl.getClassLoader(); 201 ClassLoader loader 202 = Utils.getTestClassPathURLClassLoader(apploader.getParent()); 203 Class c = loader.loadClass(classname); 204 Runnable r = (Runnable) c.newInstance(); 205 r.run(); 206 } 207 208 public static class lzconI implements Runnable { 209 static final int VALUE; 210 211 static { 212 int value = 0; 213 try { 214 value = Integer.decode(System.getProperty("value")); 215 } catch (Throwable e) {} 216 VALUE = value; 217 } 218 219 public void run() { check(VALUE, lzint(VALUE), dolzcomp()); } 220 static int dolzcomp() { return lzcomp(VALUE); } 221 } 222 |