author | ysuenaga |
Wed, 30 Mar 2016 21:05:13 +0900 | |
changeset 37218 | c7241bc368bf |
parent 36496 | f21702a00d31 |
permissions | -rw-r--r-- |
35424 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016, 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 |
||
36496
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
24 |
import com.sun.tools.classfile.*; |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
25 |
import com.sun.tools.classfile.BootstrapMethods_attribute.BootstrapMethodSpecifier; |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
26 |
import com.sun.tools.classfile.ConstantPool.CONSTANT_InvokeDynamic_info; |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
27 |
import com.sun.tools.classfile.ConstantPool.CONSTANT_MethodHandle_info; |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
28 |
|
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
29 |
import java.io.File; |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
30 |
|
35424 | 31 |
/* |
32 |
* @test |
|
36496
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
33 |
* @bug 8148483 8151516 8151223 |
35424 | 34 |
* @summary Test that StringConcat is working for JDK >= 9 |
36496
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
35 |
* @modules jdk.jdeps/com.sun.tools.classfile |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
36 |
* |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
37 |
* @clean TestIndyStringConcat* |
35424 | 38 |
* @compile -source 6 -target 6 TestIndyStringConcat.java |
39 |
* @run main TestIndyStringConcat false |
|
36496
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
40 |
* |
35424 | 41 |
* @clean TestIndyStringConcat* |
42 |
* @compile -source 7 -target 7 TestIndyStringConcat.java |
|
43 |
* @run main TestIndyStringConcat false |
|
36496
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
44 |
* |
35424 | 45 |
* @clean TestIndyStringConcat* |
46 |
* @compile -source 8 -target 8 TestIndyStringConcat.java |
|
47 |
* @run main TestIndyStringConcat false |
|
36496
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
48 |
* |
35424 | 49 |
* @clean TestIndyStringConcat* |
50 |
* @compile -XDstringConcat=inline -source 9 -target 9 TestIndyStringConcat.java |
|
51 |
* @run main TestIndyStringConcat false |
|
36496
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
52 |
* |
35424 | 53 |
* @clean TestIndyStringConcat* |
54 |
* @compile -XDstringConcat=indy -source 9 -target 9 TestIndyStringConcat.java |
|
55 |
* @run main TestIndyStringConcat true |
|
36496
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
56 |
* |
35424 | 57 |
* @clean TestIndyStringConcat* |
58 |
* @compile -XDstringConcat=indyWithConstants -source 9 -target 9 TestIndyStringConcat.java |
|
59 |
* @run main TestIndyStringConcat true |
|
60 |
*/ |
|
61 |
public class TestIndyStringConcat { |
|
62 |
||
36496
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
63 |
static String other; |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
64 |
|
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
65 |
public static String test() { |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
66 |
return "Foo" + other; |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
67 |
} |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
68 |
|
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
69 |
public static void main(String[] args) throws Exception { |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
70 |
boolean expected = Boolean.valueOf(args[0]); |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
71 |
boolean actual = hasStringConcatFactoryCall("test"); |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
72 |
if (expected != actual) { |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
73 |
throw new AssertionError("expected = " + expected + ", actual = " + actual); |
35424 | 74 |
} |
75 |
} |
|
76 |
||
36496
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
77 |
public static boolean hasStringConcatFactoryCall(String methodName) throws Exception { |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
78 |
ClassFile classFile = ClassFile.read(new File(System.getProperty("test.classes", "."), |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
79 |
TestIndyStringConcat.class.getName() + ".class")); |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
80 |
ConstantPool constantPool = classFile.constant_pool; |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
81 |
|
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
82 |
BootstrapMethods_attribute bsm_attr = |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
83 |
(BootstrapMethods_attribute)classFile |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
84 |
.getAttribute(Attribute.BootstrapMethods); |
35424 | 85 |
|
36496
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
86 |
for (Method method : classFile.methods) { |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
87 |
if (method.getName(constantPool).equals(methodName)) { |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
88 |
Code_attribute code = (Code_attribute) method.attributes |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
89 |
.get(Attribute.Code); |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
90 |
for (Instruction i : code.getInstructions()) { |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
91 |
if (i.getOpcode() == Opcode.INVOKEDYNAMIC) { |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
92 |
CONSTANT_InvokeDynamic_info indyInfo = |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
93 |
(CONSTANT_InvokeDynamic_info) constantPool.get(i.getUnsignedShort(1)); |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
94 |
|
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
95 |
BootstrapMethodSpecifier bsmSpec = |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
96 |
bsm_attr.bootstrap_method_specifiers[indyInfo.bootstrap_method_attr_index]; |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
97 |
|
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
98 |
CONSTANT_MethodHandle_info bsmInfo = |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
99 |
(CONSTANT_MethodHandle_info) constantPool.get(bsmSpec.bootstrap_method_ref); |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
100 |
|
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
101 |
if (bsmInfo.getCPRefInfo().getClassName().equals("java/lang/invoke/StringConcatFactory")) { |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
102 |
return true; |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
103 |
} |
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
104 |
} |
35424 | 105 |
} |
106 |
} |
|
107 |
} |
|
36496
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
108 |
return false; |
35424 | 109 |
} |
36496
f21702a00d31
8151516: test/tools/javac/TestIndyStringConcat depends on runtime JDK details
shade
parents:
36041
diff
changeset
|
110 |
|
35424 | 111 |
} |