Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/compiler/6823354/Test6823354.java
32285 views
/*1* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 682335426* @summary These methods can be instrinsified by using bit scan, bit test, and population count instructions.27*28* @run main/othervm -Xcomp -XX:CompileOnly=Test6823354.lzcomp,Test6823354.tzcomp,.dolzcomp,.dotzcomp Test682335429*/3031import java.net.URLClassLoader;3233public class Test6823354 {34// Arrays of corner case values.35static final int[] ia = new int[] { 0, 1, -1, Integer.MIN_VALUE, Integer.MAX_VALUE };36static final long[] la = new long[] { 0L, 1L, -1L, Long.MIN_VALUE, Long.MAX_VALUE };3738public static void main(String[] args) throws Exception {39// Load the classes and the methods.40Integer.numberOfLeadingZeros(0);41Integer.numberOfTrailingZeros(0);42Long.numberOfLeadingZeros(0);43Long.numberOfTrailingZeros(0);4445lz();46tz();47}4849static void lz() throws Exception {50// int5152// Test corner cases.53for (int i = 0; i < ia.length; i++) {54int x = ia[i];55check(x, lzcomp(x), lzint(x));56}5758// Test all possible return values.59for (int i = 0; i < Integer.SIZE; i++) {60int x = 1 << i;61check(x, lzcomp(x), lzint(x));62}6364String classname = "Test6823354$lzconI";6566// Test Ideal optimizations (constant values).67for (int i = 0; i < ia.length; i++) {68testclass(classname, ia[i]);69}7071// Test Ideal optimizations (constant values).72for (int i = 0; i < Integer.SIZE; i++) {73int x = 1 << i;74testclass(classname, x);75}767778// long7980// Test corner cases.81for (int i = 0; i < ia.length; i++) {82long x = la[i];83check(x, lzcomp(x), lzint(x));84}8586// Test all possible return values.87for (int i = 0; i < Long.SIZE; i++) {88long x = 1L << i;89check(x, lzcomp(x), lzint(x));90}9192classname = "Test6823354$lzconL";9394// Test Ideal optimizations (constant values).95for (int i = 0; i < la.length; i++) {96testclass(classname, la[i]);97}9899// Test Ideal optimizations (constant values).100for (int i = 0; i < Long.SIZE; i++) {101long x = 1L << i;102testclass(classname, x);103}104}105106static void tz() throws Exception {107// int108109// Test corner cases.110for (int i = 0; i < ia.length; i++) {111int x = ia[i];112check(x, tzcomp(x), tzint(x));113}114115// Test all possible return values.116for (int i = 0; i < Integer.SIZE; i++) {117int x = 1 << i;118check(x, tzcomp(x), tzint(x));119}120121String classname = "Test6823354$tzconI";122123// Test Ideal optimizations (constant values).124for (int i = 0; i < ia.length; i++) {125testclass(classname, ia[i]);126}127128// Test Ideal optimizations (constant values).129for (int i = 0; i < Integer.SIZE; i++) {130int x = 1 << i;131testclass(classname, x);132}133134135// long136137// Test corner cases.138for (int i = 0; i < la.length; i++) {139long x = la[i];140check(x, tzcomp(x), tzint(x));141}142143// Test all possible return values.144for (int i = 0; i < Long.SIZE; i++) {145long x = 1L << i;146check(x, tzcomp(x), tzint(x));147}148149classname = "Test6823354$tzconL";150151// Test Ideal optimizations (constant values).152for (int i = 0; i < la.length; i++) {153testclass(classname, la[i]);154}155156// Test Ideal optimizations (constant values).157for (int i = 0; i < Long.SIZE; i++) {158long x = 1L << i;159testclass(classname, x);160}161}162163static void check(int value, int result, int expected) {164//System.out.println(value + ": " + result + ", " + expected);165if (result != expected)166throw new InternalError(value + " failed: " + result + " != " + expected);167}168169static void check(long value, long result, long expected) {170//System.out.println(value + ": " + result + ", " + expected);171if (result != expected)172throw new InternalError(value + " failed: " + result + " != " + expected);173}174175static int lzint( int i) { return Integer.numberOfLeadingZeros(i); }176static int lzcomp(int i) { return Integer.numberOfLeadingZeros(i); }177178static int lzint( long l) { return Long.numberOfLeadingZeros(l); }179static int lzcomp(long l) { return Long.numberOfLeadingZeros(l); }180181static int tzint( int i) { return Integer.numberOfTrailingZeros(i); }182static int tzcomp(int i) { return Integer.numberOfTrailingZeros(i); }183184static int tzint( long l) { return Long.numberOfTrailingZeros(l); }185static int tzcomp(long l) { return Long.numberOfTrailingZeros(l); }186187static void testclass(String classname, int x) throws Exception {188System.setProperty("value", "" + x);189loadandrunclass(classname);190}191192static void testclass(String classname, long x) throws Exception {193System.setProperty("value", "" + x);194loadandrunclass(classname);195}196197static void loadandrunclass(String classname) throws Exception {198Class cl = Class.forName(classname);199URLClassLoader apploader = (URLClassLoader) cl.getClassLoader();200ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent());201Class c = loader.loadClass(classname);202Runnable r = (Runnable) c.newInstance();203r.run();204}205206public static class lzconI implements Runnable {207static final int VALUE;208209static {210int value = 0;211try {212value = Integer.decode(System.getProperty("value"));213} catch (Throwable e) {}214VALUE = value;215}216217public void run() { check(VALUE, lzint(VALUE), dolzcomp()); }218static int dolzcomp() { return lzcomp(VALUE); }219}220221public static class lzconL implements Runnable {222static final long VALUE;223224static {225long value = 0;226try {227value = Long.decode(System.getProperty("value"));228} catch (Throwable e) {}229VALUE = value;230}231232public void run() { check(VALUE, lzint(VALUE), dolzcomp()); }233static int dolzcomp() { return lzcomp(VALUE); }234}235236public static class tzconI implements Runnable {237static final int VALUE;238239static {240int value = 0;241try {242value = Integer.decode(System.getProperty("value"));243} catch (Throwable e) {}244VALUE = value;245}246247public void run() { check(VALUE, tzint(VALUE), dotzcomp()); }248static int dotzcomp() { return tzcomp(VALUE); }249}250251public static class tzconL implements Runnable {252static final long VALUE;253254static {255long value = 0;256try {257value = Long.decode(System.getProperty("value"));258} catch (Throwable e) {}259VALUE = value;260}261262public void run() { check(VALUE, tzint(VALUE), dotzcomp()); }263static int dotzcomp() { return tzcomp(VALUE); }264}265}266267268