Mercurial > hg > truffle
comparison test/runtime/verifier/TestMultiANewArray.java @ 17888:c4bc6b5c6f25
8038076: constraint on multianewarray instruction is not checked since class version 50.
Summary: No VerifiyError generated if multianewarray bytecode's array type descriptor was 1 dimension smaller than dimensions specified.
Reviewed-by: hseigel, ctornqvi, coleenp, kamg
author | lfoltan |
---|---|
date | Mon, 14 Apr 2014 10:13:03 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17887:cd3c534f8f4a | 17888:c4bc6b5c6f25 |
---|---|
1 /* | |
2 * Copyright (c) 2014, Oracle and/or its affiliates. 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 import java.io.File; | |
25 import java.io.FileOutputStream; | |
26 import jdk.internal.org.objectweb.asm.ClassWriter; | |
27 import jdk.internal.org.objectweb.asm.MethodVisitor; | |
28 import static jdk.internal.org.objectweb.asm.Opcodes.*; | |
29 import com.oracle.java.testlibrary.*; | |
30 | |
31 /* | |
32 * @test TestMultiANewArray | |
33 * @bug 8038076 | |
34 * @library /testlibrary | |
35 * @compile -XDignore.symbol.file TestMultiANewArray.java | |
36 * @run main/othervm TestMultiANewArray 49 | |
37 * @run main/othervm TestMultiANewArray 50 | |
38 * @run main/othervm TestMultiANewArray 51 | |
39 * @run main/othervm TestMultiANewArray 52 | |
40 */ | |
41 | |
42 public class TestMultiANewArray { | |
43 public static void main(String... args) throws Exception { | |
44 int cfv = Integer.parseInt(args[0]); | |
45 writeClassFile(cfv); | |
46 System.err.println("Running with cfv: " + cfv); | |
47 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-cp", ".", "ClassFile"); | |
48 OutputAnalyzer output = new OutputAnalyzer(pb.start()); | |
49 output.shouldContain("VerifyError"); | |
50 output.shouldHaveExitValue(1); | |
51 } | |
52 | |
53 public static void writeClassFile(int cfv) throws Exception { | |
54 ClassWriter cw = new ClassWriter(0); | |
55 MethodVisitor mv; | |
56 | |
57 cw.visit(cfv, ACC_PUBLIC + ACC_SUPER, "ClassFile", null, "java/lang/Object", null); | |
58 mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); | |
59 mv.visitCode(); | |
60 mv.visitVarInsn(ALOAD, 0); | |
61 mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); | |
62 mv.visitInsn(RETURN); | |
63 mv.visitMaxs(1, 1); | |
64 mv.visitEnd(); | |
65 | |
66 mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); | |
67 mv.visitCode(); | |
68 mv.visitInsn(ICONST_1); | |
69 mv.visitInsn(ICONST_2); | |
70 mv.visitMultiANewArrayInsn("[I", 2); | |
71 mv.visitVarInsn(ASTORE, 1); | |
72 mv.visitInsn(RETURN); | |
73 mv.visitMaxs(2, 2); | |
74 mv.visitEnd(); | |
75 | |
76 cw.visitEnd(); | |
77 | |
78 try (FileOutputStream fos = new FileOutputStream(new File("ClassFile.class"))) { | |
79 fos.write(cw.toByteArray()); | |
80 } | |
81 } | |
82 } |