1 /* 2 * Copyright (c) 2012, 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 7142086 27 * @summary performance problem in Check.checkOverrideClashes(...) 28 * @modules jdk.compiler 29 * @run main/timeout=10 T7142086 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 T7142086 { 45 46 final static int N_METHODS = 1000; 47 48 static class TestClass extends SimpleJavaFileObject { 49 50 String methTemplate = "abstract void m(A#N p);"; 51 String classTemplate = "abstract class Test { #M }"; 52 53 String source; 54 TestClass()55 public TestClass() { 56 super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 57 StringBuilder buf = new StringBuilder(); 58 for (int i = 0 ; i < N_METHODS ; i++) { 59 buf.append(methTemplate.replace("#N", String.valueOf(i))); 60 buf.append("\n"); 61 } 62 source = classTemplate.replace("#M", buf.toString()); 63 } 64 65 @Override getCharContent(boolean ignoreEncodingErrors)66 public CharSequence getCharContent(boolean ignoreEncodingErrors) { 67 return source; 68 } 69 } 70 71 static class AnSource extends SimpleJavaFileObject { 72 73 String classTemplate = "abstract class A#N { }"; 74 75 String source; 76 AnSource(int n)77 public AnSource(int n) { 78 super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 79 source = classTemplate.replace("#N", String.valueOf(n)); 80 } 81 82 @Override getCharContent(boolean ignoreEncodingErrors)83 public CharSequence getCharContent(boolean ignoreEncodingErrors) { 84 return source; 85 } 86 } 87 main(String... args)88 public static void main(String... args) throws Exception { 89 ArrayList<JavaFileObject> sources = new ArrayList<>(); 90 for (int i = 0 ; i < N_METHODS ; i++) { 91 sources.add(new AnSource(i)); 92 } 93 sources.add(new TestClass()); 94 new T7142086().run(sources); 95 } 96 run(List<JavaFileObject> sources)97 void run(List<JavaFileObject> sources) throws Exception { 98 DiagnosticChecker dc = new DiagnosticChecker(); 99 JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); 100 try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { 101 JavacTask ct = (JavacTask)comp.getTask(null, fm, dc, 102 null, null, sources); 103 ct.analyze(); 104 } 105 } 106 107 static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { 108 109 boolean errorFound; 110 report(Diagnostic<? extends JavaFileObject> diagnostic)111 public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 112 if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { 113 throw new AssertionError("unexpected diagnostic: " + diagnostic.getMessage(Locale.getDefault())); 114 } 115 } 116 } 117 } 118