author | jjg |
Wed, 29 Oct 2014 17:25:23 -0700 | |
changeset 27319 | 030080f03e4f |
parent 18731 | 38dd7ede2dfb |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
1 |
/* |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
2 |
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
4 |
* |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
8 |
* |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
13 |
* accompanied this code). |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
14 |
* |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
18 |
* |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
21 |
* questions. |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
22 |
*/ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
23 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
24 |
/* |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
25 |
* @test |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
26 |
* @bug 8013789 |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
27 |
* @summary Compiler should emit bridges in interfaces |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
28 |
* @library /tools/javac/lib |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
29 |
* @build JavacTestingAbstractProcessor BridgeHarness |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
30 |
* @run main BridgeHarness |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
31 |
*/ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
32 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
33 |
import com.sun.source.util.JavacTask; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
34 |
import com.sun.tools.classfile.AccessFlags; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
35 |
import com.sun.tools.classfile.ClassFile; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
36 |
import com.sun.tools.classfile.ConstantPool; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
37 |
import com.sun.tools.classfile.ConstantPoolException; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
38 |
import com.sun.tools.classfile.Method; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
39 |
import com.sun.tools.javac.code.Symbol.ClassSymbol; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
40 |
import com.sun.tools.javac.util.List; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
41 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
42 |
import java.io.File; |
18731
38dd7ede2dfb
8013638: Few policy tests are failing in Lambda nightly
mcimadamore
parents:
18730
diff
changeset
|
43 |
import java.io.InputStream; |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
44 |
import java.util.Arrays; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
45 |
import java.util.Collections; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
46 |
import java.util.HashMap; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
47 |
import java.util.Map; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
48 |
import java.util.Set; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
49 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
50 |
import javax.annotation.processing.RoundEnvironment; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
51 |
import javax.annotation.processing.SupportedAnnotationTypes; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
52 |
import javax.lang.model.element.Element; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
53 |
import javax.lang.model.element.TypeElement; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
54 |
import javax.tools.JavaCompiler; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
55 |
import javax.tools.JavaFileObject; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
56 |
import javax.tools.StandardJavaFileManager; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
57 |
import javax.tools.ToolProvider; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
58 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
59 |
import static javax.tools.StandardLocation.*; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
60 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
61 |
public class BridgeHarness { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
62 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
63 |
/** number of errors found (must be zero for the test to pass) */ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
64 |
static int nerrors = 0; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
65 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
66 |
/** the (shared) Java compiler used for compiling the tests */ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
67 |
static final JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
68 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
69 |
/** the (shared) file manager used by the compiler */ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
70 |
static final StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
71 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
72 |
public static void main(String[] args) throws Exception { |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
73 |
try { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
74 |
//set sourcepath |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
75 |
fm.setLocation(SOURCE_PATH, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
76 |
Arrays.asList(new File(System.getProperty("test.src"), "tests"))); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
77 |
//set output (-d) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
78 |
fm.setLocation(javax.tools.StandardLocation.CLASS_OUTPUT, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
79 |
Arrays.asList(new File(System.getProperty("user.dir")))); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
80 |
for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(JavaFileObject.Kind.SOURCE), true)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
81 |
//for each source, compile and check against annotations |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
82 |
new BridgeHarness(jfo).compileAndCheck(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
83 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
84 |
//if there were errors, fail |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
85 |
if (nerrors > 0) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
86 |
throw new AssertionError("Errors were found"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
87 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
88 |
} finally { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
18731
diff
changeset
|
89 |
fm.close(); |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
90 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
91 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
92 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
93 |
/* utility methods */ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
94 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
95 |
/** |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
96 |
* Remove an element from a list |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
97 |
*/ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
98 |
static <Z> List<Z> drop(List<Z> lz, Z z) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
99 |
if (lz.head == z) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
100 |
return drop(lz.tail, z); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
101 |
} else if (lz.isEmpty()) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
102 |
return lz; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
103 |
} else { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
104 |
return drop(lz.tail, z).prepend(lz.head); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
105 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
106 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
107 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
108 |
/** |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
109 |
* return a string representation of a bytecode method |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
110 |
*/ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
111 |
static String descriptor(Method m, ConstantPool cp) throws ConstantPoolException { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
112 |
return m.getName(cp) + m.descriptor.getValue(cp); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
113 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
114 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
115 |
/* test harness */ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
116 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
117 |
/** Test file to be compiled */ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
118 |
JavaFileObject jfo; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
119 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
120 |
/** Mapping between class name and list of bridges in class with that name */ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
121 |
Map<String, List<Bridge>> bridgesMap = new HashMap<String, List<Bridge>>(); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
122 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
123 |
protected BridgeHarness(JavaFileObject jfo) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
124 |
this.jfo = jfo; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
125 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
126 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
127 |
/** |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
128 |
* Compile a test using a custom annotation processor and check the generated |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
129 |
* bytecode against discovered annotations. |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
130 |
*/ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
131 |
protected void compileAndCheck() throws Exception { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
132 |
JavacTask ct = (JavacTask)comp.getTask(null, fm, null, null, null, Arrays.asList(jfo)); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
133 |
ct.setProcessors(Collections.singleton(new BridgeFinder())); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
134 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
135 |
for (JavaFileObject jfo : ct.generate()) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
136 |
checkBridges(jfo); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
137 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
138 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
139 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
140 |
/** |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
141 |
* Check that every bridge in the generated classfile has a matching bridge |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
142 |
* annotation in the bridge map |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
143 |
*/ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
144 |
protected void checkBridges(JavaFileObject jfo) { |
18731
38dd7ede2dfb
8013638: Few policy tests are failing in Lambda nightly
mcimadamore
parents:
18730
diff
changeset
|
145 |
try (InputStream is = jfo.openInputStream()) { |
38dd7ede2dfb
8013638: Few policy tests are failing in Lambda nightly
mcimadamore
parents:
18730
diff
changeset
|
146 |
ClassFile cf = ClassFile.read(is); |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
147 |
System.err.println("checking: " + cf.getName()); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
148 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
149 |
List<Bridge> bridgeList = bridgesMap.get(cf.getName()); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
150 |
if (bridgeList == null) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
151 |
//no bridges - nothing to check; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
152 |
bridgeList = List.nil(); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
153 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
154 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
155 |
for (Method m : cf.methods) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
156 |
if (m.access_flags.is(AccessFlags.ACC_SYNTHETIC | AccessFlags.ACC_BRIDGE)) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
157 |
//this is a bridge - see if there's a match in the bridge list |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
158 |
Bridge match = null; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
159 |
for (Bridge b : bridgeList) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
160 |
if (b.value().equals(descriptor(m, cf.constant_pool))) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
161 |
match = b; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
162 |
break; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
163 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
164 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
165 |
if (match == null) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
166 |
error("No annotation for bridge method: " + descriptor(m, cf.constant_pool)); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
167 |
} else { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
168 |
bridgeList = drop(bridgeList, match); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
169 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
170 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
171 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
172 |
if (bridgeList.nonEmpty()) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
173 |
error("Redundant bridge annotation found: " + bridgeList.head.value()); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
174 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
175 |
} catch (Exception e) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
176 |
e.printStackTrace(); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
177 |
throw new Error("error reading " + jfo.toUri() +": " + e); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
178 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
179 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
180 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
181 |
/** |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
182 |
* Log an error |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
183 |
*/ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
184 |
protected void error(String msg) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
185 |
nerrors++; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
186 |
System.err.printf("Error occurred while checking file: %s\nreason: %s\n", jfo.getName(), msg); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
187 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
188 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
189 |
/** |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
190 |
* This annotation processor is used to populate the bridge map with the |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
191 |
* contents of the annotations that are found on the tests being compiled |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
192 |
*/ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
193 |
@SupportedAnnotationTypes({"Bridges","Bridge"}) |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
194 |
class BridgeFinder extends JavacTestingAbstractProcessor { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
195 |
@Override |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
196 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
197 |
if (roundEnv.processingOver()) |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
198 |
return true; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
199 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
200 |
TypeElement bridgeAnno = elements.getTypeElement("Bridge"); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
201 |
TypeElement bridgesAnno = elements.getTypeElement("Bridges"); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
202 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
203 |
//see if there are repeated annos |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
204 |
for (Element elem: roundEnv.getElementsAnnotatedWith(bridgesAnno)) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
205 |
List<Bridge> bridgeList = List.nil(); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
206 |
Bridges bridges = elem.getAnnotation(Bridges.class); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
207 |
for (Bridge bridge : bridges.value()) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
208 |
bridgeList = bridgeList.prepend(bridge); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
209 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
210 |
bridgesMap.put(((ClassSymbol)elem).flatname.toString(), bridgeList); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
211 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
212 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
213 |
//see if there are non-repeated annos |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
214 |
for (Element elem: roundEnv.getElementsAnnotatedWith(bridgeAnno)) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
215 |
Bridge bridge = elem.getAnnotation(Bridge.class); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
216 |
bridgesMap.put(((ClassSymbol)elem).flatname.toString(), |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
217 |
List.of(bridge)); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
218 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
219 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
220 |
return true; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
221 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
222 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff
changeset
|
223 |
} |