1 /* 2 * Copyright (c) 2022, Red Hat, Inc. 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 /* 26 * @test 27 * @library /test/lib 28 * @enablePreview 29 * @modules java.base/jdk.internal.misc 30 * @run main/othervm -Xint 31 * -XX:CompileCommand=dontinline,*TestGetModifiers.test 32 * compiler.intrinsics.klass.TestGetModifiers 33 */ 34 35 /* 36 * @test 37 * @requires vm.compiler1.enabled 38 * @library /test/lib 39 * @enablePreview 40 * @modules java.base/jdk.internal.misc 41 * @run main/othervm -XX:TieredStopAtLevel=1 -XX:+TieredCompilation 42 * -XX:CompileCommand=dontinline,*TestGetModifiers.test 43 * compiler.intrinsics.klass.TestGetModifiers 44 */ 45 46 /* 47 * @test 48 * @requires vm.compiler2.enabled 49 * @library /test/lib 50 * @enablePreview 51 * @modules java.base/jdk.internal.misc 52 * @run main/othervm -XX:-TieredCompilation 53 * -XX:CompileCommand=dontinline,*TestGetModifiers.test 54 * compiler.intrinsics.klass.TestGetModifiers 55 */ 56 57 package compiler.intrinsics.klass; 58 59 import java.lang.reflect.Modifier; 60 import static java.lang.reflect.Modifier.*; 61 62 import jdk.test.lib.Asserts; 63 import jdk.internal.misc.PreviewFeatures; 64 65 public class TestGetModifiers { 66 public static class T1 { 67 } 68 69 public static final class T2 { 70 } 71 72 private static class T3 { 73 } 74 75 protected static class T4 { 76 } 77 78 class T5 { 79 } 80 81 interface T6 { 82 } 83 84 static void test(Class cl, int expectedMods) { 85 for (int i = 0; i < 100_000; i++) { 86 int actualMods = cl.getModifiers(); 87 if (actualMods != expectedMods) { 88 throw new IllegalStateException("Error with: " + cl + " : " + actualMods + " vs " + expectedMods); 89 } 90 } 91 } 92 93 public static void main(String... args) { 94 test(T1.class, PUBLIC | STATIC | IDENTITY); 95 test(T2.class, PUBLIC | FINAL | STATIC | IDENTITY); 96 test(T3.class, PRIVATE | STATIC | IDENTITY); 97 test(T4.class, PROTECTED | STATIC | IDENTITY); 98 test(new TestGetModifiers().new T5().getClass(), IDENTITY); 99 test(T6.class, ABSTRACT | STATIC | INTERFACE); 100 101 test(int.class, PUBLIC | ABSTRACT | FINAL); 102 test(long.class, PUBLIC | ABSTRACT | FINAL); 103 test(double.class, PUBLIC | ABSTRACT | FINAL); 104 test(float.class, PUBLIC | ABSTRACT | FINAL); 105 test(char.class, PUBLIC | ABSTRACT | FINAL); 106 test(byte.class, PUBLIC | ABSTRACT | FINAL); 107 test(short.class, PUBLIC | ABSTRACT | FINAL); 108 test(void.class, PUBLIC | ABSTRACT | FINAL); 109 test(int[].class, PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? IDENTITY : 0)); 110 test(long[].class, PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? IDENTITY : 0)); 111 test(double[].class, PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? IDENTITY : 0)); 112 test(float[].class, PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? IDENTITY : 0)); 113 test(char[].class, PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? IDENTITY : 0)); 114 test(byte[].class, PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? IDENTITY : 0)); 115 test(short[].class, PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? IDENTITY : 0)); 116 test(Object[].class, PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? IDENTITY : 0)); 117 test(TestGetModifiers[].class, PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? IDENTITY : 0)); 118 119 test(new TestGetModifiers().getClass(), PUBLIC | IDENTITY); 120 test(new T1().getClass(), PUBLIC | STATIC | IDENTITY); 121 test(new T2().getClass(), PUBLIC | FINAL | STATIC | IDENTITY); 122 test(new T3().getClass(), PRIVATE | STATIC | IDENTITY); 123 test(new T4().getClass(), PROTECTED | STATIC | IDENTITY); 124 } 125 }