author | jrose |
Fri, 18 Jun 2010 15:12:04 -0700 | |
changeset 5738 | c24b113fe4ac |
parent 5520 | 86e4b9a9da40 |
parent 5736 | ee0850472ca1 |
child 6592 | dc56420a69bc |
permissions | -rw-r--r-- |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
1 |
/* |
5520 | 2 |
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
4 |
* |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
8 |
* |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
13 |
* accompanied this code). |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
14 |
* |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
18 |
* |
5520 | 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. |
|
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
22 |
*/ |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
23 |
|
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
24 |
/* |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
25 |
* @test |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
26 |
* @bug 6754038 |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
27 |
* @summary Generate call sites for method handle |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
28 |
* @author jrose |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
29 |
* |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
30 |
* @compile -source 7 -target 7 InvokeMH.java |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
31 |
*/ |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
32 |
|
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
33 |
/* |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
34 |
* Standalone testing: |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
35 |
* <code> |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
36 |
* $ cd $MY_REPO_DIR/langtools |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
37 |
* $ (cd make; make) |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
38 |
* $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/meth/InvokeMH.java |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
39 |
* $ javap -c -classpath dist meth.InvokeMH |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
40 |
* </code> |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
41 |
*/ |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
42 |
|
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
43 |
package meth; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
44 |
|
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
45 |
import java.dyn.MethodHandle; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
46 |
|
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
47 |
public class InvokeMH { |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
48 |
void test(MethodHandle mh_SiO, |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
49 |
MethodHandle mh_vS, |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
50 |
MethodHandle mh_vi, |
5736
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
51 |
MethodHandle mh_vv) throws Throwable { |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
52 |
Object o; String s; int i; // for return type testing |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
53 |
|
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
54 |
// next five must have sig = (String,int)Object |
5736
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
55 |
mh_SiO.invokeExact("world", 123); |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
56 |
mh_SiO.invokeExact("mundus", 456); |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
57 |
Object k = "kosmos"; |
5736
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
58 |
mh_SiO.invokeExact((String)k, 789); |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
59 |
o = mh_SiO.invokeExact((String)null, 000); |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
60 |
o = mh_SiO.<Object>invokeExact("arda", -123); |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
61 |
|
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
62 |
// sig = ()String |
5736
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
63 |
s = mh_vS.<String>invokeExact(); |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
64 |
|
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
65 |
// sig = ()int |
5736
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
66 |
i = mh_vi.<int>invokeExact(); |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
67 |
o = mh_vi.<int>invokeExact(); |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
68 |
//s = mh_vi.<int>invokeExact(); //BAD |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
69 |
mh_vi.<int>invokeExact(); |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
70 |
|
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
71 |
// sig = ()void |
5736
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
72 |
//o = mh_vv.<void>invokeExact(); //BAD |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
73 |
mh_vv.<void>invokeExact(); |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
74 |
} |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
75 |
|
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
76 |
void testGen(MethodHandle mh_SiO, |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
77 |
MethodHandle mh_vS, |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
78 |
MethodHandle mh_vi, |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
79 |
MethodHandle mh_vv) throws Throwable { |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
80 |
Object o; String s; int i; // for return type testing |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
81 |
|
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
82 |
// next five must have sig = (*,*)* |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
83 |
mh_SiO.invokeGeneric((Object)"world", (Object)123); |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
84 |
mh_SiO.<void>invokeGeneric((Object)"mundus", (Object)456); |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
85 |
Object k = "kosmos"; |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
86 |
mh_SiO.invokeGeneric(k, 789); |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
87 |
o = mh_SiO.invokeGeneric(null, 000); |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
88 |
o = mh_SiO.<Object>invokeGeneric("arda", -123); |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
89 |
|
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
90 |
// sig = ()String |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
91 |
o = mh_vS.invokeGeneric(); |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
92 |
|
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
93 |
// sig = ()int |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
94 |
i = mh_vi.<int>invokeGeneric(); |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
95 |
o = mh_vi.invokeGeneric(); |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
96 |
//s = mh_vi.<int>invokeGeneric(); //BAD |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
97 |
mh_vi.<void>invokeGeneric(); |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
98 |
|
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
99 |
// sig = ()void |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
100 |
//o = mh_vv.<void>invokeGeneric(); //BAD |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2723
diff
changeset
|
101 |
o = mh_vv.invokeGeneric(); |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
102 |
} |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff
changeset
|
103 |
} |