< prev index next >

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

Print this page

 25 /**
 26  * @test
 27  * @bug 8291360
 28  * @summary Test getting the class file version for java.lang.Class API
 29  * @modules java.base/java.lang:open
 30  * @compile classFileVersions.jcod
 31  * @compile --enable-preview -source ${jdk.version} ClassFileVersionTest.java
 32  * @run main/othervm --enable-preview ClassFileVersionTest
 33  */
 34 
 35 import java.lang.reflect.*;
 36 
 37 public class ClassFileVersionTest {
 38     public static final int LOWER_16 = 0x0000_FFFF;
 39     /*
 40      * Include a use of a preview API so that the minor class file
 41      * version of the class file for this class gets set during
 42      * compilation. If a particular class becomes non-preview, any
 43      * currently preview class can be substituted in.
 44      */
 45     private static final Class<?> PREVIEW_API = java.lang.foreign.MemorySegment.class;
 46     static Method m;
 47 
 48     public static void testIt(String className, int expectedResult) throws Exception {
 49         testIt(Class.forName(className), expectedResult);
 50     }
 51 
 52     public static void testIt(Class<?> testClass, int expectedResult) throws Exception {
 53         int ver = (int)m.invoke(testClass);
 54         if (ver != expectedResult) {
 55             int exp_minor = (expectedResult >> 16) & LOWER_16;
 56             int exp_major = expectedResult & LOWER_16;
 57             int got_minor = (ver >> 16) & LOWER_16;
 58             int got_major = ver & LOWER_16;
 59             throw new RuntimeException(
 60                 "Expected " + exp_minor + ":" + exp_major + " but got " + got_minor + ":" + got_major);
 61         }
 62     }
 63 
 64     public static void main(String argv[]) throws Throwable {
 65         Class<?> cl = java.lang.Class.class;

 25 /**
 26  * @test
 27  * @bug 8291360
 28  * @summary Test getting the class file version for java.lang.Class API
 29  * @modules java.base/java.lang:open
 30  * @compile classFileVersions.jcod
 31  * @compile --enable-preview -source ${jdk.version} ClassFileVersionTest.java
 32  * @run main/othervm --enable-preview ClassFileVersionTest
 33  */
 34 
 35 import java.lang.reflect.*;
 36 
 37 public class ClassFileVersionTest {
 38     public static final int LOWER_16 = 0x0000_FFFF;
 39     /*
 40      * Include a use of a preview API so that the minor class file
 41      * version of the class file for this class gets set during
 42      * compilation. If a particular class becomes non-preview, any
 43      * currently preview class can be substituted in.
 44      */
 45     private static final Class<?> PREVIEW_API = java.lang.ScopedValue.class;
 46     static Method m;
 47 
 48     public static void testIt(String className, int expectedResult) throws Exception {
 49         testIt(Class.forName(className), expectedResult);
 50     }
 51 
 52     public static void testIt(Class<?> testClass, int expectedResult) throws Exception {
 53         int ver = (int)m.invoke(testClass);
 54         if (ver != expectedResult) {
 55             int exp_minor = (expectedResult >> 16) & LOWER_16;
 56             int exp_major = expectedResult & LOWER_16;
 57             int got_minor = (ver >> 16) & LOWER_16;
 58             int got_major = ver & LOWER_16;
 59             throw new RuntimeException(
 60                 "Expected " + exp_minor + ":" + exp_major + " but got " + got_minor + ":" + got_major);
 61         }
 62     }
 63 
 64     public static void main(String argv[]) throws Throwable {
 65         Class<?> cl = java.lang.Class.class;
< prev index next >