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 8027232
27 * @summary ensures that j.l.i.InvokerByteCodeGenerator and ASM visitMethodInsn
28 * generate bytecodes with correct constant pool references
29 * @compile -XDignore.symbol.file LambdaAsm.java LUtils.java
30 * @run main/othervm LambdaAsm
31 */
32 import com.sun.tools.classfile.Attribute;
33 import com.sun.tools.classfile.ClassFile;
34 import com.sun.tools.classfile.Code_attribute;
35 import com.sun.tools.classfile.ConstantPool;
36 import com.sun.tools.classfile.ConstantPool.CPInfo;
37 import com.sun.tools.classfile.Instruction;
38 import com.sun.tools.classfile.Method;
39 import java.io.ByteArrayInputStream;
40 import java.io.File;
41 import java.util.ArrayList;
42 import java.nio.file.DirectoryStream;
43 import java.nio.file.Path;
44 import jdk.internal.org.objectweb.asm.ClassWriter;
45 import jdk.internal.org.objectweb.asm.MethodVisitor;
46
47 import static java.nio.file.Files.*;
48 import static jdk.internal.org.objectweb.asm.Opcodes.*;
116 for (Method m : cf.methods) {
117 String mname = m.getName(cf.constant_pool);
118 if (mname.equals(mthd)) {
119 for (Attribute a : m.attributes) {
120 if ("Code".equals(a.getName(cf.constant_pool))) {
121 count++;
122 checkMethod(cf.getName(), mname, cf.constant_pool,
123 (Code_attribute) a);
124 }
125 }
126 }
127 }
128 return count;
129 }
130
131 static void verifyInvokerBytecodeGenerator() throws Exception {
132 int count = 0;
133 int mcount = 0;
134 try (DirectoryStream<Path> ds = newDirectoryStream(new File(".").toPath(),
135 // filter in lambda proxy classes
136 "A$I$$Lambda$?.class")) {
137 for (Path p : ds) {
138 System.out.println(p.toFile());
139 ClassFile cf = ClassFile.read(p.toFile());
140 // Check those methods implementing Supplier.get
141 mcount += checkMethod(cf, "get");
142 count++;
143 }
144 }
145 if (count < 3) {
146 throw new RuntimeException("unexpected number of files, "
147 + "expected atleast 3 files, but got only " + count);
148 }
149 if (mcount < 3) {
150 throw new RuntimeException("unexpected number of methods, "
151 + "expected atleast 3 methods, but got only " + mcount);
152 }
153 }
154
155 static void verifyASM() throws Exception {
156 ClassWriter cw = new ClassWriter(0);
|
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 8027232
27 * @summary ensures that j.l.i.InvokerByteCodeGenerator and ASM visitMethodInsn
28 * generate bytecodes with correct constant pool references
29 * @modules java.base/jdk.internal.org.objectweb.asm
30 * jdk.compiler/com.sun.tools.classfile
31 * @compile -XDignore.symbol.file LambdaAsm.java LUtils.java
32 * @run main/othervm LambdaAsm
33 */
34 import com.sun.tools.classfile.Attribute;
35 import com.sun.tools.classfile.ClassFile;
36 import com.sun.tools.classfile.Code_attribute;
37 import com.sun.tools.classfile.ConstantPool;
38 import com.sun.tools.classfile.ConstantPool.CPInfo;
39 import com.sun.tools.classfile.Instruction;
40 import com.sun.tools.classfile.Method;
41 import java.io.ByteArrayInputStream;
42 import java.io.File;
43 import java.util.ArrayList;
44 import java.nio.file.DirectoryStream;
45 import java.nio.file.Path;
46 import jdk.internal.org.objectweb.asm.ClassWriter;
47 import jdk.internal.org.objectweb.asm.MethodVisitor;
48
49 import static java.nio.file.Files.*;
50 import static jdk.internal.org.objectweb.asm.Opcodes.*;
118 for (Method m : cf.methods) {
119 String mname = m.getName(cf.constant_pool);
120 if (mname.equals(mthd)) {
121 for (Attribute a : m.attributes) {
122 if ("Code".equals(a.getName(cf.constant_pool))) {
123 count++;
124 checkMethod(cf.getName(), mname, cf.constant_pool,
125 (Code_attribute) a);
126 }
127 }
128 }
129 }
130 return count;
131 }
132
133 static void verifyInvokerBytecodeGenerator() throws Exception {
134 int count = 0;
135 int mcount = 0;
136 try (DirectoryStream<Path> ds = newDirectoryStream(new File(".").toPath(),
137 // filter in lambda proxy classes
138 "A$I$$Lambda$*.class")) {
139 for (Path p : ds) {
140 System.out.println(p.toFile());
141 ClassFile cf = ClassFile.read(p.toFile());
142 // Check those methods implementing Supplier.get
143 mcount += checkMethod(cf, "get");
144 count++;
145 }
146 }
147 if (count < 3) {
148 throw new RuntimeException("unexpected number of files, "
149 + "expected atleast 3 files, but got only " + count);
150 }
151 if (mcount < 3) {
152 throw new RuntimeException("unexpected number of methods, "
153 + "expected atleast 3 methods, but got only " + mcount);
154 }
155 }
156
157 static void verifyASM() throws Exception {
158 ClassWriter cw = new ClassWriter(0);
|