|
1 /* |
|
2 * Copyright (c) 2015, 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 8000316 |
|
27 * @summary Huge performance bottleneck in com.sun.tools.javac.comp.Check.localClassName |
|
28 * @modules jdk.compiler |
|
29 * @run main T8000316 |
|
30 */ |
|
31 |
|
32 import com.sun.source.util.JavacTask; |
|
33 import java.net.URI; |
|
34 import java.util.List; |
|
35 import java.util.ArrayList; |
|
36 import java.util.Locale; |
|
37 import javax.tools.Diagnostic; |
|
38 import javax.tools.JavaCompiler; |
|
39 import javax.tools.JavaFileObject; |
|
40 import javax.tools.SimpleJavaFileObject; |
|
41 import javax.tools.StandardJavaFileManager; |
|
42 import javax.tools.ToolProvider; |
|
43 |
|
44 public class T8000316 { |
|
45 |
|
46 final static int N_METHODS = 1024; |
|
47 final static int N_CLASSES = 8; |
|
48 |
|
49 static class TestClass extends SimpleJavaFileObject { |
|
50 |
|
51 String methTemplate = " public static Runnable get#N() {\n" + |
|
52 " return new Runnable() {\n" + |
|
53 " @Override\n" + |
|
54 " public void run() {\n" + |
|
55 " return;\n" + |
|
56 " }\n" + |
|
57 " };\n" + |
|
58 " }\n"; |
|
59 |
|
60 String classTemplate = "\n\nclass Chain#N {\n\n#M }"; |
|
61 |
|
62 String source; |
|
63 |
|
64 public TestClass() { |
|
65 super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); |
|
66 StringBuilder buf = new StringBuilder(); |
|
67 StringBuilder fileBuf = new StringBuilder(); |
|
68 |
|
69 for (int i = 0 ; i < N_CLASSES ; i++) { |
|
70 for (int j = 0; j < N_METHODS; j++) { |
|
71 buf.append(methTemplate.replace("#N", String.valueOf(j))); |
|
72 buf.append("\n"); |
|
73 } |
|
74 fileBuf.append(classTemplate.replace("#M", buf.toString()).replace("#N", String.valueOf(i))); |
|
75 buf = new StringBuilder(); |
|
76 source = fileBuf.toString(); |
|
77 } |
|
78 } |
|
79 |
|
80 @Override |
|
81 public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
|
82 return source; |
|
83 } |
|
84 } |
|
85 |
|
86 public static void main(String... args) throws Exception { |
|
87 ArrayList<JavaFileObject> sources = new ArrayList<>(); |
|
88 sources.add(new TestClass()); |
|
89 new T8000316().run(sources); |
|
90 } |
|
91 |
|
92 void run(List<JavaFileObject> sources) throws Exception { |
|
93 javax.tools.DiagnosticListener<JavaFileObject> dc = (diagnostic) -> { |
|
94 if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { |
|
95 throw new AssertionError("unexpected diagnostic: " + diagnostic.getMessage(Locale.getDefault())); |
|
96 } |
|
97 }; |
|
98 JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
|
99 try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
|
100 JavacTask ct = (JavacTask)comp.getTask(null, fm, dc, |
|
101 null, null, sources); |
|
102 ct.analyze(); |
|
103 } |
|
104 } |
|
105 } |