author | jlaskey |
Tue, 19 Feb 2013 09:47:02 -0400 | |
changeset 16248 | e4bcc4b4f897 |
parent 15526 | 84de8685a2d0 |
child 16050 | 1eee624cddb3 |
permissions | -rw-r--r-- |
15526
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
1 |
/* |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
4 |
* |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
8 |
* |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
13 |
* accompanied this code). |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
14 |
* |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
18 |
* |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
21 |
* questions. |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
22 |
*/ |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
23 |
import java.io.File; |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
24 |
import java.nio.charset.Charset; |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
25 |
import java.nio.file.Files; |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
26 |
import java.util.ArrayList; |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
27 |
import java.util.List; |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
28 |
import static java.nio.file.StandardOpenOption.*; |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
29 |
import java.util.regex.Pattern; |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
30 |
|
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
31 |
/* |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
32 |
* @test |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
33 |
* @bug 8003549 |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
34 |
* @summary tests class files instruction formats introduced in JSR-335 |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
35 |
* @compile -XDignore.symbol.file Utils.java InstructionTests.java |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
36 |
* @run main InstructionTests |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
37 |
* @author ksrini |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
38 |
*/ |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
39 |
public class InstructionTests { |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
40 |
public static void main(String... args) throws Exception { |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
41 |
testInvokeOpCodes(); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
42 |
} |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
43 |
/* |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
44 |
* the following should produce invokestatic and invokespecial |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
45 |
* on InterfaceMethodRefs vs. MethodRefs, packer/unpacker should work |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
46 |
*/ |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
47 |
static void testInvokeOpCodes() throws Exception { |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
48 |
List<String> scratch = new ArrayList<>(); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
49 |
final String fname = "A"; |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
50 |
String javaFileName = fname + Utils.JAVA_FILE_EXT; |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
51 |
scratch.add("interface IntIterator {"); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
52 |
scratch.add(" default void forEach(){}"); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
53 |
scratch.add(" static void next() {}"); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
54 |
scratch.add("}"); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
55 |
scratch.add("class A implements IntIterator {"); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
56 |
scratch.add("public void forEach(Object o){"); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
57 |
scratch.add("IntIterator.super.forEach();"); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
58 |
scratch.add("IntIterator.next();"); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
59 |
scratch.add("}"); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
60 |
scratch.add("}"); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
61 |
File cwd = new File("."); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
62 |
File javaFile = new File(cwd, javaFileName); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
63 |
Files.write(javaFile.toPath(), scratch, Charset.defaultCharset(), |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
64 |
CREATE, TRUNCATE_EXISTING); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
65 |
|
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
66 |
// make sure we have -g so that we compare LVT and LNT entries |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
67 |
Utils.compiler("-g", javaFile.getName()); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
68 |
|
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
69 |
// jar the file up |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
70 |
File testjarFile = new File(cwd, "test" + Utils.JAR_FILE_EXT); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
71 |
Utils.jar("cvf", testjarFile.getName(), "."); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
72 |
|
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
73 |
// pack using --repack |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
74 |
File outjarFile = new File(cwd, "out" + Utils.JAR_FILE_EXT); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
75 |
scratch.clear(); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
76 |
scratch.add(Utils.getPack200Cmd()); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
77 |
scratch.add("-J-ea"); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
78 |
scratch.add("-J-esa"); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
79 |
scratch.add("--repack"); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
80 |
scratch.add(outjarFile.getName()); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
81 |
scratch.add(testjarFile.getName()); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
82 |
List<String> output = Utils.runExec(scratch); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
83 |
// TODO remove this when we get bc escapes working correctly |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
84 |
// this test anyhow would fail at that time |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
85 |
findString("WARNING: Passing.*" + fname + Utils.CLASS_FILE_EXT, |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
86 |
output); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
87 |
|
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
88 |
Utils.doCompareVerify(testjarFile, outjarFile); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
89 |
} |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
90 |
|
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
91 |
static boolean findString(String str, List<String> list) { |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
92 |
Pattern p = Pattern.compile(str); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
93 |
for (String x : list) { |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
94 |
if (p.matcher(x).matches()) |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
95 |
return true; |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
96 |
} |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
97 |
throw new RuntimeException("Error: " + str + " not found in output"); |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
98 |
} |
84de8685a2d0
8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff
changeset
|
99 |
} |