1 /*
 2  * Copyright (c) 2019, 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 /*
25  * @test
26  * @bug 8222634
27  * @summary Check array creation with V and V.ref
28  * @modules jdk.compiler/com.sun.tools.javac.util jdk.jdeps/com.sun.tools.javap
29  * @compile ArrayCreationWithQuestion.java
30  * @run main/othervm -Xverify:none ArrayCreationWithQuestion
31  * @modules jdk.compiler
32  */
33 
34 import java.io.PrintWriter;
35 import java.io.StringWriter;
36 import java.nio.file.Paths;
37 
38 public class ArrayCreationWithQuestion {
39 
40     static primitive class VT {
41         VT.ref[] a1 = new VT.ref[42];
42         VT.ref[] a2 = new VT.ref[42];
43         VT[] a3 = new VT[42];
44         VT[] a4 = new VT[42];
45     }
46 
47     public static void main(String[] args) {
48         new ArrayCreationWithQuestion().run();
49     }
50 
51     void run() {
52         String [] params = new String [] { "-v",
53                                             Paths.get(System.getProperty("test.classes"),
54                                                 "ArrayCreationWithQuestion$VT.class").toString() };
55         runCheck(params, new String [] {
56         "         6: anewarray     #1                  // class ArrayCreationWithQuestion$VT",
57         "        17: anewarray     #1                  // class ArrayCreationWithQuestion$VT",
58         "        28: anewarray     #10                 // class \"QArrayCreationWithQuestion$VT;\"",
59         "        39: anewarray     #10                 // class \"QArrayCreationWithQuestion$VT;\"",
60          });
61 
62      }
63 
64      void runCheck(String [] params, String [] expectedOut) {
65         StringWriter s;
66         String out;
67 
68         try (PrintWriter pw = new PrintWriter(s = new StringWriter())) {
69             com.sun.tools.javap.Main.run(params, pw);
70             out = s.toString();
71         }
72         int errors = 0;
73         for (String eo: expectedOut) {
74             if (!out.contains(eo)) {
75                 System.err.println("Match not found for string: " + eo);
76                 errors++;
77             }
78         }
79          if (errors > 0) {
80              throw new AssertionError("Unexpected javap output: " + out);
81          }
82     }
83 }