Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/klass/TestGetModifiers.java
64507 views
/*1* Copyright (c) 2022, Red Hat, Inc. 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*22*/2324/*25* @test26* @library /test/lib27* @run main/othervm -Xint28* -XX:CompileCommand=dontinline,*TestGetModifiers.test29* compiler.intrinsics.klass.TestGetModifiers30*/3132/*33* @test34* @requires vm.compiler1.enabled35* @library /test/lib36* @run main/othervm -XX:TieredStopAtLevel=1 -XX:+TieredCompilation37* -XX:CompileCommand=dontinline,*TestGetModifiers.test38* compiler.intrinsics.klass.TestGetModifiers39*/4041/*42* @test43* @requires vm.compiler2.enabled44* @library /test/lib45* @run main/othervm -XX:-TieredCompilation46* -XX:CompileCommand=dontinline,*TestGetModifiers.test47* compiler.intrinsics.klass.TestGetModifiers48*/4950package compiler.intrinsics.klass;5152import java.lang.reflect.Modifier;53import static java.lang.reflect.Modifier.*;5455import jdk.test.lib.Asserts;5657public class TestGetModifiers {58public static class T1 {59}6061public static final class T2 {62}6364private static class T3 {65}6667protected static class T4 {68}6970class T5 {71}7273interface T6 {74}7576static void test(Class cl, int expectedMods) {77for (int i = 0; i < 100_000; i++) {78int actualMods = cl.getModifiers();79if (actualMods != expectedMods) {80throw new IllegalStateException("Error with: " + cl);81}82}83}8485public static void main(String... args) {86test(T1.class, PUBLIC | STATIC);87test(T2.class, PUBLIC | FINAL | STATIC);88test(T3.class, PRIVATE | STATIC);89test(T4.class, PROTECTED | STATIC);90test(new TestGetModifiers().new T5().getClass(), 0);91test(T6.class, ABSTRACT | STATIC | INTERFACE);9293test(int.class, PUBLIC | ABSTRACT | FINAL);94test(long.class, PUBLIC | ABSTRACT | FINAL);95test(double.class, PUBLIC | ABSTRACT | FINAL);96test(float.class, PUBLIC | ABSTRACT | FINAL);97test(char.class, PUBLIC | ABSTRACT | FINAL);98test(byte.class, PUBLIC | ABSTRACT | FINAL);99test(short.class, PUBLIC | ABSTRACT | FINAL);100test(void.class, PUBLIC | ABSTRACT | FINAL);101test(int[].class, PUBLIC | ABSTRACT | FINAL);102test(long[].class, PUBLIC | ABSTRACT | FINAL);103test(double[].class, PUBLIC | ABSTRACT | FINAL);104test(float[].class, PUBLIC | ABSTRACT | FINAL);105test(char[].class, PUBLIC | ABSTRACT | FINAL);106test(byte[].class, PUBLIC | ABSTRACT | FINAL);107test(short[].class, PUBLIC | ABSTRACT | FINAL);108test(Object[].class, PUBLIC | ABSTRACT | FINAL);109test(TestGetModifiers[].class, PUBLIC | ABSTRACT | FINAL);110111test(new TestGetModifiers().getClass(), PUBLIC);112test(new T1().getClass(), PUBLIC | STATIC);113test(new T2().getClass(), PUBLIC | FINAL | STATIC);114test(new T3().getClass(), PRIVATE | STATIC);115test(new T4().getClass(), PROTECTED | STATIC);116}117}118119120