< prev index next >

test/hotspot/jtreg/compiler/c1/CanonicalizeGetModifiers.java

Print this page

 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  * @author Yi Yang
 28  * @summary Canonicalizes Foo.class.getModifiers() with interpreter mode
 29  * @library /test/lib

 30  * @run main/othervm -Xint
 31  *                   -XX:CompileCommand=compileonly,*CanonicalizeGetModifiers.test
 32  *                   compiler.c1.CanonicalizeGetModifiers
 33  */
 34 
 35 /*
 36  * @test
 37  * @author Yi Yang
 38  * @summary Canonicalizes Foo.class.getModifiers() with C1 mode
 39  * @requires vm.compiler1.enabled
 40  * @library /test/lib

 41  * @run main/othervm -XX:TieredStopAtLevel=1 -XX:+TieredCompilation
 42  *                   -XX:CompileCommand=compileonly,*CanonicalizeGetModifiers.test
 43  *                   compiler.c1.CanonicalizeGetModifiers
 44  */
 45 
 46 /*
 47  * @test
 48  * @author Yi Yang
 49  * @summary Canonicalizes Foo.class.getModifiers() with C2 mode
 50  * @requires vm.compiler2.enabled
 51  * @library /test/lib

 52  * @run main/othervm -XX:-TieredCompilation
 53  *                   -XX:CompileCommand=compileonly,*CanonicalizeGetModifiers.test
 54  *                   compiler.c1.CanonicalizeGetModifiers
 55  */
 56 
 57 package compiler.c1;
 58 
 59 import java.lang.reflect.Modifier;

 60 
 61 import jdk.test.lib.Asserts;
 62 
 63 public class CanonicalizeGetModifiers {
 64     public static class T1 {
 65     }
 66 
 67     public static final class T2 {
 68     }
 69 
 70     private static class T3 {
 71     }
 72 
 73     protected static class T4 {
 74     }
 75 
 76     class T5 {
 77     }
 78 
 79     interface T6 {
 80     }
 81 
 82     static void test(Class poison) {
 83         Asserts.assertEQ(CanonicalizeGetModifiers.class.getModifiers(), Modifier.PUBLIC);
 84         Asserts.assertEQ(T1.class.getModifiers(), Modifier.PUBLIC | Modifier.STATIC);
 85         Asserts.assertEQ(T2.class.getModifiers(), Modifier.PUBLIC | Modifier.FINAL | Modifier.STATIC);
 86         Asserts.assertEQ(T3.class.getModifiers(), Modifier.PRIVATE | Modifier.STATIC);
 87         Asserts.assertEQ(T4.class.getModifiers(), Modifier.PROTECTED | Modifier.STATIC);
 88         Asserts.assertEQ(new CanonicalizeGetModifiers().new T5().getClass().getModifiers(), 0/* NONE */);
 89         Asserts.assertEQ(T6.class.getModifiers(), Modifier.ABSTRACT | Modifier.STATIC | Modifier.INTERFACE);
 90 
 91         Asserts.assertEQ(int.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
 92         Asserts.assertEQ(long.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
 93         Asserts.assertEQ(double.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
 94         Asserts.assertEQ(float.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
 95         Asserts.assertEQ(char.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
 96         Asserts.assertEQ(byte.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
 97         Asserts.assertEQ(short.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
 98         Asserts.assertEQ(void.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
 99         Asserts.assertEQ(int[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
100         Asserts.assertEQ(long[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
101         Asserts.assertEQ(double[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
102         Asserts.assertEQ(float[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
103         Asserts.assertEQ(char[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
104         Asserts.assertEQ(byte[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
105         Asserts.assertEQ(short[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
106         Asserts.assertEQ(Object[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
107         Asserts.assertEQ(CanonicalizeGetModifiers[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
108 
109         Asserts.assertEQ(new CanonicalizeGetModifiers().getClass().getModifiers(), Modifier.PUBLIC);
110         Asserts.assertEQ(new T1().getClass().getModifiers(), Modifier.PUBLIC | Modifier.STATIC);
111         Asserts.assertEQ(new T2().getClass().getModifiers(), Modifier.PUBLIC | Modifier.FINAL | Modifier.STATIC);
112         Asserts.assertEQ(new T3().getClass().getModifiers(), Modifier.PRIVATE | Modifier.STATIC);
113         Asserts.assertEQ(new T4().getClass().getModifiers(), Modifier.PROTECTED | Modifier.STATIC);
114         try {
115             // null_check
116             poison.getModifiers();
117         } catch(NullPointerException npe) {
118             // got it!
119         }
120     }
121 
122     public static void main(String... args) {
123         for (int i = 0; i < 10_000; i++) {
124             test(i == 9999 ? null : CanonicalizeGetModifiers.class);
125         }
126     }
127 }

 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  * @author Yi Yang
 28  * @summary Canonicalizes Foo.class.getModifiers() with interpreter mode
 29  * @library /test/lib
 30  * @enablePreview
 31  * @run main/othervm -Xint
 32  *                   -XX:CompileCommand=compileonly,*CanonicalizeGetModifiers.test
 33  *                   compiler.c1.CanonicalizeGetModifiers
 34  */
 35 
 36 /*
 37  * @test
 38  * @author Yi Yang
 39  * @summary Canonicalizes Foo.class.getModifiers() with C1 mode
 40  * @requires vm.compiler1.enabled
 41  * @library /test/lib
 42  * @enablePreview
 43  * @run main/othervm -XX:TieredStopAtLevel=1 -XX:+TieredCompilation
 44  *                   -XX:CompileCommand=compileonly,*CanonicalizeGetModifiers.test
 45  *                   compiler.c1.CanonicalizeGetModifiers
 46  */
 47 
 48 /*
 49  * @test
 50  * @author Yi Yang
 51  * @summary Canonicalizes Foo.class.getModifiers() with C2 mode
 52  * @requires vm.compiler2.enabled
 53  * @library /test/lib
 54  * @enablePreview
 55  * @run main/othervm -XX:-TieredCompilation
 56  *                   -XX:CompileCommand=compileonly,*CanonicalizeGetModifiers.test
 57  *                   compiler.c1.CanonicalizeGetModifiers
 58  */
 59 
 60 package compiler.c1;
 61 
 62 import java.lang.reflect.Modifier;
 63 import java.lang.reflect.AccessFlag;
 64 
 65 import jdk.test.lib.Asserts;
 66 
 67 public class CanonicalizeGetModifiers {
 68     public static class T1 {
 69     }
 70 
 71     public static final class T2 {
 72     }
 73 
 74     private static class T3 {
 75     }
 76 
 77     protected static class T4 {
 78     }
 79 
 80     class T5 {
 81     }
 82 
 83     interface T6 {
 84     }
 85 
 86     static void test(Class poison) {
 87         Asserts.assertEQ(CanonicalizeGetModifiers.class.getModifiers(), Modifier.PUBLIC | Modifier.IDENTITY);
 88         Asserts.assertEQ(T1.class.getModifiers(), Modifier.PUBLIC | Modifier.STATIC | Modifier.IDENTITY);
 89         Asserts.assertEQ(T2.class.getModifiers(), Modifier.PUBLIC | Modifier.FINAL | Modifier.STATIC | Modifier.IDENTITY);
 90         Asserts.assertEQ(T3.class.getModifiers(), Modifier.PRIVATE | Modifier.STATIC | Modifier.IDENTITY);
 91         Asserts.assertEQ(T4.class.getModifiers(), Modifier.PROTECTED | Modifier.STATIC | Modifier.IDENTITY);
 92         Asserts.assertEQ(new CanonicalizeGetModifiers().new T5().getClass().getModifiers(), 0/* NONE */ | Modifier.IDENTITY);
 93         Asserts.assertEQ(T6.class.getModifiers(), Modifier.ABSTRACT | Modifier.STATIC | Modifier.INTERFACE);
 94 
 95         Asserts.assertEQ(int.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
 96         Asserts.assertEQ(long.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
 97         Asserts.assertEQ(double.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
 98         Asserts.assertEQ(float.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
 99         Asserts.assertEQ(char.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
100         Asserts.assertEQ(byte.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
101         Asserts.assertEQ(short.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
102         Asserts.assertEQ(void.class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
103         Asserts.assertEQ(int[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
104         Asserts.assertEQ(long[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
105         Asserts.assertEQ(double[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
106         Asserts.assertEQ(float[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
107         Asserts.assertEQ(char[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
108         Asserts.assertEQ(byte[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
109         Asserts.assertEQ(short[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
110         Asserts.assertEQ(Object[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
111         Asserts.assertEQ(CanonicalizeGetModifiers[].class.getModifiers(), Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL);
112 
113         Asserts.assertEQ(new CanonicalizeGetModifiers().getClass().getModifiers(), Modifier.PUBLIC | Modifier.IDENTITY);
114         Asserts.assertEQ(new T1().getClass().getModifiers(), Modifier.PUBLIC | Modifier.STATIC | Modifier.IDENTITY);
115         Asserts.assertEQ(new T2().getClass().getModifiers(), Modifier.PUBLIC | Modifier.FINAL | Modifier.STATIC | Modifier.IDENTITY);
116         Asserts.assertEQ(new T3().getClass().getModifiers(), Modifier.PRIVATE | Modifier.STATIC | Modifier.IDENTITY);
117         Asserts.assertEQ(new T4().getClass().getModifiers(), Modifier.PROTECTED | Modifier.STATIC | Modifier.IDENTITY);
118         try {
119             // null_check
120             poison.getModifiers();
121         } catch(NullPointerException npe) {
122             // got it!
123         }
124     }
125 
126     public static void main(String... args) {
127         for (int i = 0; i < 10_000; i++) {
128             test(i == 9999 ? null : CanonicalizeGetModifiers.class);
129         }
130     }
131 }
< prev index next >