< prev index next >

test/hotspot/jtreg/runtime/ClassFile/ClassAccessFlagsRawTest.java

Print this page

 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  * @bug 8291360
28  * @summary Test getting a class's raw access flags using java.lang.Class API
29  * @modules java.base/java.lang:open

30  * @compile classAccessFlagsRaw.jcod
31  * @run main/othervm ClassAccessFlagsRawTest
32  */
33 
34 import java.lang.reflect.*;
35 
36 public class ClassAccessFlagsRawTest {
37 
38     static Method m;
39 
40     public static void testIt(String className, int expectedResult) throws Exception {
41         Class<?> testClass = Class.forName(className);
42         int flags = (int)m.invoke(testClass);
43         if (flags != expectedResult) {
44             throw new RuntimeException(
45                 "expected 0x" + Integer.toHexString(expectedResult) + ", got 0x" + Integer.toHexString(flags) + " for class " + className);
46         }
47     }
48 
49     public static void main(String argv[]) throws Throwable {
50         Class<?> cl = java.lang.Class.class;
51         m = cl.getDeclaredMethod("getClassAccessFlagsRaw", new Class[0]);
52         m.setAccessible(true);
53 
54         testIt("SUPERset", 0x21);  // ACC_SUPER 0x20 + ACC_PUBLIC 0x1
55         testIt("SUPERnotset", Modifier.PUBLIC);

56 
57         // test primitive array.  should return ACC_ABSTRACT | ACC_FINAL | ACC_PUBLIC.
58         int flags = (int)m.invoke((new int[3]).getClass());
59         if (flags != (Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC)) {
60             throw new RuntimeException(
61                 "expected 0x411, got 0x" + Integer.toHexString(flags) + " for primitive array");
62         }
63 
64         // test object array.  should return flags of component.
65         flags = (int)m.invoke((new SUPERnotset[2]).getClass());
66         if (flags != Modifier.PUBLIC) {

67             throw new RuntimeException(
68                 "expected 0x1, got 0x" + Integer.toHexString(flags) + " for object array");
69         }
70 
71         // test multi-dimensional object array.  should return flags of component.
72         flags = (int)m.invoke((new SUPERnotset[4][2]).getClass());
73         if (flags != Modifier.PUBLIC) {

74             throw new RuntimeException(
75                 "expected 0x1, got 0x" + Integer.toHexString(flags) + " for object array");
76         }
77     }
78 }

 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  * @bug 8291360 8293448
28  * @summary Test getting a class's raw access flags using java.lang.Class API
29  * @modules java.base/java.lang:open
30  * @enablePreview
31  * @compile classAccessFlagsRaw.jcod
32  * @run main/othervm ClassAccessFlagsRawTest
33  */
34 
35 import java.lang.reflect.*;
36 
37 public class ClassAccessFlagsRawTest {
38 
39     static Method m;
40 
41     public static void testIt(String className, int expectedResult) throws Exception {
42         Class<?> testClass = Class.forName(className);
43         int flags = (int)m.invoke(testClass);
44         if (flags != expectedResult) {
45             throw new RuntimeException(
46                 "expected 0x" + Integer.toHexString(expectedResult) + ", got 0x" + Integer.toHexString(flags) + " for class " + className);
47         }
48     }
49 
50     public static void main(String argv[]) throws Throwable {
51         Class<?> cl = java.lang.Class.class;
52         m = cl.getDeclaredMethod("getClassAccessFlagsRaw", new Class[0]);
53         m.setAccessible(true);
54 
55         testIt("SUPERset", Modifier.PUBLIC | Modifier.IDENTITY);
56         // Because of the repurposing of ACC_SUPER into ACC_IDENTITY by JEP 401, the VM now fixes missing ACC_IDENTITY flags in old class files
57         testIt("SUPERnotset", Modifier.PUBLIC | Modifier.IDENTITY);
58 
59         // test primitive array.  should return ACC_ABSTRACT | ACC_FINAL | ACC_PUBLIC.
60         int flags = (int)m.invoke((new int[3]).getClass());
61         if (flags != (Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC)) {
62             throw new RuntimeException(
63                 "expected 0x411, got 0x" + Integer.toHexString(flags) + " for primitive array");
64         }
65 
66         // test object array.  should return flags of component.
67         flags = (int)m.invoke((new SUPERnotset[2]).getClass());
68         // Because of the repurposing of ACC_SUPER into ACC_IDENTITY by JEP 401, the VM now fixes missing ACC_IDENTITY flags in old class files
69         if (flags != (Modifier.PUBLIC | Modifier.IDENTITY)) {
70             throw new RuntimeException(
71                 "expected 0x1, got 0x" + Integer.toHexString(flags) + " for object array");
72         }
73 
74         // test multi-dimensional object array.  should return flags of component.
75         flags = (int)m.invoke((new SUPERnotset[4][2]).getClass());
76         // Because of the repurposing of ACC_SUPER into ACC_IDENTITY by JEP 401, the VM now fixes missing ACC_IDENTITY flags in old class files
77         if (flags != (Modifier.PUBLIC | Modifier.IDENTITY)) {
78             throw new RuntimeException(
79                 "expected 0x1, got 0x" + Integer.toHexString(flags) + " for object array");
80         }
81     }
82 }
< prev index next >