Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/klass/TestIsPrimitive.java
41153 views
/*1* Copyright (c) 2016, 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 815066926* @bug 823301927* @summary C1 intrinsic for Class.isPrimitive28* @modules java.base/jdk.internal.misc29*30* @run main/othervm -ea -Diters=200 -Xint31* compiler.intrinsics.klass.TestIsPrimitive32* @run main/othervm -ea -XX:-UseSharedSpaces -Diters=30000 -XX:TieredStopAtLevel=133* compiler.intrinsics.klass.TestIsPrimitive34* @run main/othervm -ea -Diters=30000 -XX:TieredStopAtLevel=435* compiler.intrinsics.klass.TestIsPrimitive36*/3738package compiler.intrinsics.klass;3940import java.util.concurrent.Callable;4142public class TestIsPrimitive {43static final int ITERS = Integer.getInteger("iters", 1);4445public static void main(String... args) throws Exception {46testOK(true, InlineConstants::testBoolean);47testOK(true, InlineConstants::testByte);48testOK(true, InlineConstants::testShort);49testOK(true, InlineConstants::testChar);50testOK(true, InlineConstants::testInt);51testOK(true, InlineConstants::testFloat);52testOK(true, InlineConstants::testLong);53testOK(true, InlineConstants::testDouble);54testOK(false, InlineConstants::testObject);55testOK(false, InlineConstants::testArray);56testOK(false, InlineConstants::testBooleanArray);5758testOK(true, StaticConstants::testBoolean);59testOK(true, StaticConstants::testByte);60testOK(true, StaticConstants::testShort);61testOK(true, StaticConstants::testChar);62testOK(true, StaticConstants::testInt);63testOK(true, StaticConstants::testFloat);64testOK(true, StaticConstants::testLong);65testOK(true, StaticConstants::testDouble);66testOK(false, StaticConstants::testObject);67testOK(false, StaticConstants::testArray);68testOK(false, StaticConstants::testBooleanArray);69testNPE( StaticConstants::testNull);7071testOK(true, NoConstants::testBoolean);72testOK(true, NoConstants::testByte);73testOK(true, NoConstants::testShort);74testOK(true, NoConstants::testChar);75testOK(true, NoConstants::testInt);76testOK(true, NoConstants::testFloat);77testOK(true, NoConstants::testLong);78testOK(true, NoConstants::testDouble);79testOK(false, NoConstants::testObject);80testOK(false, NoConstants::testArray);81testOK(false, NoConstants::testBooleanArray);82testNPE( NoConstants::testNull);83}8485public static void testOK(boolean expected, Callable<Object> test) throws Exception {86for (int c = 0; c < ITERS; c++) {87Object res = test.call();88if (!res.equals(expected)) {89throw new IllegalStateException("Wrong result: expected = " + expected + ", but got " + res);90}91}92}9394static volatile Object sink;9596public static void testNPE(Callable<Object> test) throws Exception {97for (int c = 0; c < ITERS; c++) {98try {99sink = test.call();100throw new IllegalStateException("Expected NPE");101} catch (NullPointerException iae) {102// expected103}104}105}106107static volatile Class<?> classBoolean = boolean.class;108static volatile Class<?> classByte = byte.class;109static volatile Class<?> classShort = short.class;110static volatile Class<?> classChar = char.class;111static volatile Class<?> classInt = int.class;112static volatile Class<?> classFloat = float.class;113static volatile Class<?> classLong = long.class;114static volatile Class<?> classDouble = double.class;115static volatile Class<?> classObject = Object.class;116static volatile Class<?> classArray = Object[].class;117static volatile Class<?> classNull = null;118static volatile Class<?> classBooleanArray = boolean[].class;119120static final Class<?> staticClassBoolean = boolean.class;121static final Class<?> staticClassByte = byte.class;122static final Class<?> staticClassShort = short.class;123static final Class<?> staticClassChar = char.class;124static final Class<?> staticClassInt = int.class;125static final Class<?> staticClassFloat = float.class;126static final Class<?> staticClassLong = long.class;127static final Class<?> staticClassDouble = double.class;128static final Class<?> staticClassObject = Object.class;129static final Class<?> staticClassArray = Object[].class;130static final Class<?> staticClassNull = null;131static final Class<?> staticClassBooleanArray = boolean[].class;132133static class InlineConstants {134static boolean testBoolean() { return boolean.class.isPrimitive(); }135static boolean testByte() { return byte.class.isPrimitive(); }136static boolean testShort() { return short.class.isPrimitive(); }137static boolean testChar() { return char.class.isPrimitive(); }138static boolean testInt() { return int.class.isPrimitive(); }139static boolean testFloat() { return float.class.isPrimitive(); }140static boolean testLong() { return long.class.isPrimitive(); }141static boolean testDouble() { return double.class.isPrimitive(); }142static boolean testObject() { return Object.class.isPrimitive(); }143static boolean testArray() { return Object[].class.isPrimitive(); }144static boolean testBooleanArray() { return boolean[].class.isPrimitive(); }145}146147static class StaticConstants {148static boolean testBoolean() { return staticClassBoolean.isPrimitive(); }149static boolean testByte() { return staticClassByte.isPrimitive(); }150static boolean testShort() { return staticClassShort.isPrimitive(); }151static boolean testChar() { return staticClassChar.isPrimitive(); }152static boolean testInt() { return staticClassInt.isPrimitive(); }153static boolean testFloat() { return staticClassFloat.isPrimitive(); }154static boolean testLong() { return staticClassLong.isPrimitive(); }155static boolean testDouble() { return staticClassDouble.isPrimitive(); }156static boolean testObject() { return staticClassObject.isPrimitive(); }157static boolean testArray() { return staticClassArray.isPrimitive(); }158static boolean testNull() { return staticClassNull.isPrimitive(); }159static boolean testBooleanArray() { return staticClassBooleanArray.isPrimitive(); }160}161162static class NoConstants {163static boolean testBoolean() { return classBoolean.isPrimitive(); }164static boolean testByte() { return classByte.isPrimitive(); }165static boolean testShort() { return classShort.isPrimitive(); }166static boolean testChar() { return classChar.isPrimitive(); }167static boolean testInt() { return classInt.isPrimitive(); }168static boolean testFloat() { return classFloat.isPrimitive(); }169static boolean testLong() { return classLong.isPrimitive(); }170static boolean testDouble() { return classDouble.isPrimitive(); }171static boolean testObject() { return classObject.isPrimitive(); }172static boolean testArray() { return classArray.isPrimitive(); }173static boolean testNull() { return classNull.isPrimitive(); }174static boolean testBooleanArray() { return classBooleanArray.isPrimitive(); }175}176177178}179180181182