< prev index next >

test/hotspot/jtreg/compiler/intrinsics/klass/TestGetModifiers.java

Print this page

  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  * @run main/othervm -Xint
 29  *                   -XX:CompileCommand=dontinline,*TestGetModifiers.test
 30  *                   compiler.intrinsics.klass.TestGetModifiers
 31  */
 32 
 33 /*
 34  * @test
 35  * @requires vm.compiler1.enabled
 36  * @library /test/lib


 37  * @run main/othervm -XX:TieredStopAtLevel=1 -XX:+TieredCompilation
 38  *                   -XX:CompileCommand=dontinline,*TestGetModifiers.test
 39  *                   compiler.intrinsics.klass.TestGetModifiers
 40  */
 41 
 42 /*
 43  * @test
 44  * @requires vm.compiler2.enabled
 45  * @library /test/lib


 46  * @run main/othervm -XX:-TieredCompilation
 47  *                   -XX:CompileCommand=dontinline,*TestGetModifiers.test
 48  *                   compiler.intrinsics.klass.TestGetModifiers
 49  */
 50 
 51 package compiler.intrinsics.klass;
 52 
 53 import java.lang.reflect.Modifier;
 54 import static java.lang.reflect.Modifier.*;
 55 
 56 import jdk.test.lib.Asserts;

 57 
 58 public class TestGetModifiers {
 59     public static class T1 {
 60     }
 61 
 62     public static final class T2 {
 63     }
 64 
 65     private static class T3 {
 66     }
 67 
 68     protected static class T4 {
 69     }
 70 
 71     class T5 {
 72     }
 73 
 74     interface T6 {
 75     }
 76 
 77     static void test(Class cl, int expectedMods) {
 78         for (int i = 0; i < 100_000; i++) {
 79             int actualMods = cl.getModifiers();
 80             if (actualMods != expectedMods) {
 81                 throw new IllegalStateException("Error with: " + cl);
 82             }
 83         }
 84     }
 85 
 86     public static void main(String... args) {
 87         test(T1.class,                                      PUBLIC | STATIC);
 88         test(T2.class,                                      PUBLIC | FINAL | STATIC);
 89         test(T3.class,                                      PRIVATE | STATIC);
 90         test(T4.class,                                      PROTECTED | STATIC);
 91         test(new TestGetModifiers().new T5().getClass(),    0);
 92         test(T6.class,                                      ABSTRACT | STATIC | INTERFACE);
 93 
 94         test(int.class,                                     PUBLIC | ABSTRACT | FINAL);
 95         test(long.class,                                    PUBLIC | ABSTRACT | FINAL);
 96         test(double.class,                                  PUBLIC | ABSTRACT | FINAL);
 97         test(float.class,                                   PUBLIC | ABSTRACT | FINAL);
 98         test(char.class,                                    PUBLIC | ABSTRACT | FINAL);
 99         test(byte.class,                                    PUBLIC | ABSTRACT | FINAL);
100         test(short.class,                                   PUBLIC | ABSTRACT | FINAL);
101         test(void.class,                                    PUBLIC | ABSTRACT | FINAL);
102         test(int[].class,                                   PUBLIC | ABSTRACT | FINAL);
103         test(long[].class,                                  PUBLIC | ABSTRACT | FINAL);
104         test(double[].class,                                PUBLIC | ABSTRACT | FINAL);
105         test(float[].class,                                 PUBLIC | ABSTRACT | FINAL);
106         test(char[].class,                                  PUBLIC | ABSTRACT | FINAL);
107         test(byte[].class,                                  PUBLIC | ABSTRACT | FINAL);
108         test(short[].class,                                 PUBLIC | ABSTRACT | FINAL);
109         test(Object[].class,                                PUBLIC | ABSTRACT | FINAL);
110         test(TestGetModifiers[].class,                      PUBLIC | ABSTRACT | FINAL);
111 
112         test(new TestGetModifiers().getClass(),             PUBLIC);
113         test(new T1().getClass(),                           PUBLIC | STATIC);
114         test(new T2().getClass(),                           PUBLIC | FINAL | STATIC);
115         test(new T3().getClass(),                           PRIVATE | STATIC);
116         test(new T4().getClass(),                           PROTECTED | STATIC);
117     }
118 }

  1 /*
  2  * Copyright (c) 2022, Red Hat, Inc. All rights reserved.
  3  * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 /*
 27  * @test
 28  * @library /test/lib
 29  * @enablePreview
 30  * @modules java.base/jdk.internal.misc
 31  * @run main/othervm -Xint
 32  *                   -XX:CompileCommand=dontinline,*TestGetModifiers.test
 33  *                   compiler.intrinsics.klass.TestGetModifiers
 34  */
 35 
 36 /*
 37  * @test
 38  * @requires vm.compiler1.enabled
 39  * @library /test/lib
 40  * @enablePreview
 41  * @modules java.base/jdk.internal.misc
 42  * @run main/othervm -XX:TieredStopAtLevel=1 -XX:+TieredCompilation
 43  *                   -XX:CompileCommand=dontinline,*TestGetModifiers.test
 44  *                   compiler.intrinsics.klass.TestGetModifiers
 45  */
 46 
 47 /*
 48  * @test
 49  * @requires vm.compiler2.enabled
 50  * @library /test/lib
 51  * @enablePreview
 52  * @modules java.base/jdk.internal.misc
 53  * @run main/othervm -XX:-TieredCompilation
 54  *                   -XX:CompileCommand=dontinline,*TestGetModifiers.test
 55  *                   compiler.intrinsics.klass.TestGetModifiers
 56  */
 57 
 58 package compiler.intrinsics.klass;
 59 
 60 import static java.lang.classfile.ClassFile.ACC_IDENTITY;
 61 import static java.lang.reflect.Modifier.*;
 62 
 63 import jdk.test.lib.Asserts;
 64 import jdk.internal.misc.PreviewFeatures;
 65 
 66 public class TestGetModifiers {
 67     public static class T1 {
 68     }
 69 
 70     public static final class T2 {
 71     }
 72 
 73     private static class T3 {
 74     }
 75 
 76     protected static class T4 {
 77     }
 78 
 79     class T5 {
 80     }
 81 
 82     interface T6 {
 83     }
 84 
 85     static void test(Class cl, int expectedMods) {
 86         for (int i = 0; i < 100_000; i++) {
 87             int actualMods = cl.getModifiers();
 88             if (actualMods != expectedMods) {
 89                 throw new IllegalStateException("Error with: " + cl + " : " + actualMods  + " vs " + expectedMods);
 90             }
 91         }
 92     }
 93 
 94     public static void main(String... args) {
 95         test(T1.class,                                      PUBLIC | STATIC | ACC_IDENTITY);
 96         test(T2.class,                                      PUBLIC | FINAL | STATIC | ACC_IDENTITY);
 97         test(T3.class,                                      PRIVATE | STATIC | ACC_IDENTITY);
 98         test(T4.class,                                      PROTECTED | STATIC | ACC_IDENTITY);
 99         test(new TestGetModifiers().new T5().getClass(),       ACC_IDENTITY);
100         test(T6.class,                                      ABSTRACT | STATIC | INTERFACE);
101 
102         test(int.class,                                     PUBLIC | ABSTRACT | FINAL);
103         test(long.class,                                    PUBLIC | ABSTRACT | FINAL);
104         test(double.class,                                  PUBLIC | ABSTRACT | FINAL);
105         test(float.class,                                   PUBLIC | ABSTRACT | FINAL);
106         test(char.class,                                    PUBLIC | ABSTRACT | FINAL);
107         test(byte.class,                                    PUBLIC | ABSTRACT | FINAL);
108         test(short.class,                                   PUBLIC | ABSTRACT | FINAL);
109         test(void.class,                                    PUBLIC | ABSTRACT | FINAL);
110         test(int[].class,                                   PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? ACC_IDENTITY : 0));
111         test(long[].class,                                  PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? ACC_IDENTITY : 0));
112         test(double[].class,                                PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? ACC_IDENTITY : 0));
113         test(float[].class,                                 PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? ACC_IDENTITY : 0));
114         test(char[].class,                                  PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? ACC_IDENTITY : 0));
115         test(byte[].class,                                  PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? ACC_IDENTITY : 0));
116         test(short[].class,                                 PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? ACC_IDENTITY : 0));
117         test(Object[].class,                                PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? ACC_IDENTITY : 0));
118         test(TestGetModifiers[].class,                      PUBLIC | ABSTRACT | FINAL | (PreviewFeatures.isEnabled() ? ACC_IDENTITY : 0));
119 
120         test(new TestGetModifiers().getClass(),             PUBLIC | ACC_IDENTITY);
121         test(new T1().getClass(),                           PUBLIC | STATIC | ACC_IDENTITY);
122         test(new T2().getClass(),                           PUBLIC | FINAL | STATIC | ACC_IDENTITY);
123         test(new T3().getClass(),                           PRIVATE | STATIC | ACC_IDENTITY);
124         test(new T4().getClass(),                           PROTECTED | STATIC | ACC_IDENTITY);
125     }
126 }
< prev index next >