< prev index next >

test/hotspot/jtreg/compiler/runtime/TestConstantsInError.java

Print this page

113 
114     static void run(String name, Class<? extends LinkageError> expectedError, Generator g) {
115         Test test = generate(name, expectedError, g);
116         for (int i = 0; i < 1000; i++) {
117             test.run();
118         }
119     }
120 
121     static class TestConstantClass extends TestConstantsInError {
122         public static void main(String[] args) {
123             run("C1", NoClassDefFoundError.class, mv -> mv.visitLdcInsn(Type.getType("LUnknownClass;")));                // non-existent class
124             run("C2",   IllegalAccessError.class, mv -> mv.visitLdcInsn(Type.getType("Ljava/lang/invoke/LambdaForm;"))); // inaccessible
125 
126             // class loader constraints?
127         }
128 
129         public void process(OutputAnalyzer results, boolean isC1) {
130             results.shouldMatch("Test_C1/.*::test \\(3 bytes\\)$")
131                    .shouldMatch("Test_C2/.*::test \\(3 bytes\\)$");
132 
133             if (isC1 && Platform.isAArch64()) { // no code patching
134                 results.shouldMatch("Test_C1/.*::test \\(3 bytes\\)   made not entrant")
135                        .shouldMatch("Test_C2/.*::test \\(3 bytes\\)   made not entrant");
136             } else {
137                 results.shouldNotContain("made not entrant");
138             }
139         }
140 
141         public void processC2(OutputAnalyzer results) {
142             results.shouldNotContain("made not entrant");
143         }
144     }
145 
146     static class TestConstantMethodHandle extends TestConstantsInError {
147         public static void main(String[] args) {
148             // Non-existent holder class
149             run("MH1", NoClassDefFoundError.class,
150                 mv -> mv.visitLdcInsn(new Handle(H_INVOKESTATIC, "UnknownClass", "ignored", "()V", false)));
151 
152             // Inaccessible holder class
153             run("MH2", IllegalAccessError.class,
154                     mv -> mv.visitLdcInsn(new Handle(H_INVOKESTATIC, "java/lang/invoke/LambdaForm", "ignored", "()V", false)));
155 
156             // Method vs InterfaceMethod mismatch
157             run("MH3", IncompatibleClassChangeError.class,
158                 mv -> mv.visitLdcInsn(new Handle(H_INVOKESTATIC, "java/lang/Object", "ignored", "()V", true)));
159 
160             // Non-existent method
161             run("MH4", NoSuchMethodError.class,
162                 mv -> mv.visitLdcInsn(new Handle(H_INVOKESTATIC, "java/lang/Object", "cast", "()V", false)));
163         }
164 
165         public void process(OutputAnalyzer results, boolean isC1) {
166             results.shouldMatch("Test_MH1/.*::test \\(3 bytes\\)$")
167                    .shouldMatch("Test_MH2/.*::test \\(3 bytes\\)$")
168                    .shouldMatch("Test_MH3/.*::test \\(3 bytes\\)$")
169                    .shouldMatch("Test_MH4/.*::test \\(3 bytes\\)$");
170 
171             if (isC1 && Platform.isAArch64()) { // no code patching
172                 results.shouldMatch("Test_MH1/.*::test \\(3 bytes\\)   made not entrant")
173                        .shouldMatch("Test_MH2/.*::test \\(3 bytes\\)   made not entrant")
174                        .shouldMatch("Test_MH3/.*::test \\(3 bytes\\)   made not entrant")
175                        .shouldMatch("Test_MH4/.*::test \\(3 bytes\\)   made not entrant");
176             } else {
177                 results.shouldNotContain("made not entrant");
178             }
179         }
180     }
181 
182     static class TestConstantMethodType extends TestConstantsInError {
183         public static void main(String[] args) {
184             run("MT1", NoClassDefFoundError.class,
185                 mv -> mv.visitLdcInsn(Type.getMethodType("(LUnknownClass;)V")));
186             run("MT2", NoClassDefFoundError.class,
187                 mv -> mv.visitLdcInsn(Type.getMethodType("()LUnknownClass;")));
188         }
189 
190         public void process(OutputAnalyzer results, boolean isC1) {
191             results.shouldMatch("Test_MT1/.*::test \\(3 bytes\\)$")
192                    .shouldMatch("Test_MT2/.*::test \\(3 bytes\\)$");
193 
194             if (isC1 && Platform.isAArch64()) { // no code patching
195                 results.shouldMatch("Test_MT1/.*::test \\(3 bytes\\)   made not entrant")
196                        .shouldMatch("Test_MT2/.*::test \\(3 bytes\\)   made not entrant");
197             } else {
198                 results.shouldNotContain("made not entrant");
199             }
200         }
201     }
202 
203     static class TestConstantDynamic extends TestConstantsInError {
204         static int bsm1() throws Exception {
205             throw new AssertionError("should not be invoked");
206         }
207 
208         static int bsm2(MethodHandles.Lookup lookup, String name, Class c) throws Exception {
209             throw new Exception("expected");
210         }
211 
212         static final Handle BSM1 = new Handle(H_INVOKESTATIC, class2desc(TestConstantDynamic.class), "bsm1", "()I", false);
213         static final Handle BSM2 = new Handle(H_INVOKESTATIC, class2desc(TestConstantDynamic.class), "bsm2",
214                 "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)I",

113 
114     static void run(String name, Class<? extends LinkageError> expectedError, Generator g) {
115         Test test = generate(name, expectedError, g);
116         for (int i = 0; i < 1000; i++) {
117             test.run();
118         }
119     }
120 
121     static class TestConstantClass extends TestConstantsInError {
122         public static void main(String[] args) {
123             run("C1", NoClassDefFoundError.class, mv -> mv.visitLdcInsn(Type.getType("LUnknownClass;")));                // non-existent class
124             run("C2",   IllegalAccessError.class, mv -> mv.visitLdcInsn(Type.getType("Ljava/lang/invoke/LambdaForm;"))); // inaccessible
125 
126             // class loader constraints?
127         }
128 
129         public void process(OutputAnalyzer results, boolean isC1) {
130             results.shouldMatch("Test_C1/.*::test \\(3 bytes\\)$")
131                    .shouldMatch("Test_C2/.*::test \\(3 bytes\\)$");
132 
133             if (isC1 && (Platform.isAArch64() || Platform.isRISCV64())) { // no code patching
134                 results.shouldMatch("Test_C1/.*::test \\(3 bytes\\)   made not entrant")
135                        .shouldMatch("Test_C2/.*::test \\(3 bytes\\)   made not entrant");
136             } else {
137                 results.shouldNotContain("made not entrant");
138             }
139         }
140 
141         public void processC2(OutputAnalyzer results) {
142             results.shouldNotContain("made not entrant");
143         }
144     }
145 
146     static class TestConstantMethodHandle extends TestConstantsInError {
147         public static void main(String[] args) {
148             // Non-existent holder class
149             run("MH1", NoClassDefFoundError.class,
150                 mv -> mv.visitLdcInsn(new Handle(H_INVOKESTATIC, "UnknownClass", "ignored", "()V", false)));
151 
152             // Inaccessible holder class
153             run("MH2", IllegalAccessError.class,
154                     mv -> mv.visitLdcInsn(new Handle(H_INVOKESTATIC, "java/lang/invoke/LambdaForm", "ignored", "()V", false)));
155 
156             // Method vs InterfaceMethod mismatch
157             run("MH3", IncompatibleClassChangeError.class,
158                 mv -> mv.visitLdcInsn(new Handle(H_INVOKESTATIC, "java/lang/Object", "ignored", "()V", true)));
159 
160             // Non-existent method
161             run("MH4", NoSuchMethodError.class,
162                 mv -> mv.visitLdcInsn(new Handle(H_INVOKESTATIC, "java/lang/Object", "cast", "()V", false)));
163         }
164 
165         public void process(OutputAnalyzer results, boolean isC1) {
166             results.shouldMatch("Test_MH1/.*::test \\(3 bytes\\)$")
167                    .shouldMatch("Test_MH2/.*::test \\(3 bytes\\)$")
168                    .shouldMatch("Test_MH3/.*::test \\(3 bytes\\)$")
169                    .shouldMatch("Test_MH4/.*::test \\(3 bytes\\)$");
170 
171             if (isC1 && (Platform.isAArch64() || Platform.isRISCV64())) { // no code patching
172                 results.shouldMatch("Test_MH1/.*::test \\(3 bytes\\)   made not entrant")
173                        .shouldMatch("Test_MH2/.*::test \\(3 bytes\\)   made not entrant")
174                        .shouldMatch("Test_MH3/.*::test \\(3 bytes\\)   made not entrant")
175                        .shouldMatch("Test_MH4/.*::test \\(3 bytes\\)   made not entrant");
176             } else {
177                 results.shouldNotContain("made not entrant");
178             }
179         }
180     }
181 
182     static class TestConstantMethodType extends TestConstantsInError {
183         public static void main(String[] args) {
184             run("MT1", NoClassDefFoundError.class,
185                 mv -> mv.visitLdcInsn(Type.getMethodType("(LUnknownClass;)V")));
186             run("MT2", NoClassDefFoundError.class,
187                 mv -> mv.visitLdcInsn(Type.getMethodType("()LUnknownClass;")));
188         }
189 
190         public void process(OutputAnalyzer results, boolean isC1) {
191             results.shouldMatch("Test_MT1/.*::test \\(3 bytes\\)$")
192                    .shouldMatch("Test_MT2/.*::test \\(3 bytes\\)$");
193 
194             if (isC1 && (Platform.isAArch64() || Platform.isRISCV64())) { // no code patching
195                 results.shouldMatch("Test_MT1/.*::test \\(3 bytes\\)   made not entrant")
196                        .shouldMatch("Test_MT2/.*::test \\(3 bytes\\)   made not entrant");
197             } else {
198                 results.shouldNotContain("made not entrant");
199             }
200         }
201     }
202 
203     static class TestConstantDynamic extends TestConstantsInError {
204         static int bsm1() throws Exception {
205             throw new AssertionError("should not be invoked");
206         }
207 
208         static int bsm2(MethodHandles.Lookup lookup, String name, Class c) throws Exception {
209             throw new Exception("expected");
210         }
211 
212         static final Handle BSM1 = new Handle(H_INVOKESTATIC, class2desc(TestConstantDynamic.class), "bsm1", "()I", false);
213         static final Handle BSM2 = new Handle(H_INVOKESTATIC, class2desc(TestConstantDynamic.class), "bsm2",
214                 "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)I",
< prev index next >