author | jrose |
Sat, 05 Oct 2013 05:30:38 -0700 | |
changeset 20528 | 0b1e2130d3f7 |
parent 18766 | 28c62f5e9a47 |
child 23010 | 6dadb192ad81 |
permissions | -rw-r--r-- |
7558 | 1 |
/* |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8345
diff
changeset
|
2 |
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. |
7558 | 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 |
||
24 |
/* @test |
|
18766
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
25 |
* @bug 7050328 8007035 |
7558 | 26 |
* @summary smoke test for invokedynamic instructions |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7562
diff
changeset
|
27 |
* @build indify.Indify |
7558 | 28 |
* @compile InvokeDynamicPrintArgs.java |
9033
a88f5656f05d
6817525: turn on method handle functionality by default for JSR 292
jrose
parents:
8822
diff
changeset
|
29 |
* @run main/othervm |
7558 | 30 |
* indify.Indify |
9033
a88f5656f05d
6817525: turn on method handle functionality by default for JSR 292
jrose
parents:
8822
diff
changeset
|
31 |
* --verify-specifier-count=3 |
7558 | 32 |
* --expand-properties --classpath ${test.classes} |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8345
diff
changeset
|
33 |
* --java test.java.lang.invoke.InvokeDynamicPrintArgs --check-output |
9780
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
34 |
* @run main/othervm |
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
35 |
* indify.Indify |
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
36 |
* --expand-properties --classpath ${test.classes} |
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
37 |
* --java test.java.lang.invoke.InvokeDynamicPrintArgs --security-manager |
7558 | 38 |
*/ |
39 |
||
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8345
diff
changeset
|
40 |
package test.java.lang.invoke; |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7562
diff
changeset
|
41 |
|
7558 | 42 |
import java.util.*; |
43 |
import java.io.*; |
|
44 |
||
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8345
diff
changeset
|
45 |
import java.lang.invoke.*; |
18766
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
46 |
import java.security.*; |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8345
diff
changeset
|
47 |
import static java.lang.invoke.MethodHandles.*; |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8345
diff
changeset
|
48 |
import static java.lang.invoke.MethodType.*; |
7558 | 49 |
|
50 |
public class InvokeDynamicPrintArgs { |
|
51 |
public static void main(String... av) throws Throwable { |
|
9780
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
52 |
if (av.length > 0 && av[0].equals("--check-output")) openBuf(); |
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
53 |
if (av.length > 0 && av[0].equals("--security-manager")) setSM(); |
7558 | 54 |
System.out.println("Printing some argument lists, starting with a empty one:"); |
55 |
INDY_nothing().invokeExact(); // BSM specifier #0 = {bsm} |
|
56 |
INDY_bar().invokeExact("bar arg", 1); // BSM specifier #1 = {bsm2, Void.class, "void type"} |
|
57 |
INDY_bar2().invokeExact("bar2 arg", 222); // BSM specifier #1 = (same) |
|
58 |
INDY_baz().invokeExact("baz arg", 2, 3.14); // BSM specifier #2 = {bsm2, 1234.5} |
|
59 |
INDY_foo().invokeExact("foo arg"); // BSM specifier #0 = (same) |
|
60 |
// Hence, BSM specifier count should be 3. See "--verify-specifier-count=3" above. |
|
61 |
System.out.println("Done printing argument lists."); |
|
62 |
closeBuf(); |
|
9780
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
63 |
checkConstantRefs(); |
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
64 |
} |
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
65 |
|
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
66 |
private static void checkConstantRefs() throws Throwable { |
18766
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
67 |
// check some constant references to its self class |
9780
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
68 |
assertEquals(MT_bsm(), MH_bsm().type()); |
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
69 |
assertEquals(MT_bsm2(), MH_bsm2().type()); |
18766
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
70 |
assertEquals(MT_bsm(), non_MH_bsm().type()); |
9780
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
71 |
} |
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
72 |
private static void assertEquals(Object exp, Object act) { |
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
73 |
if (exp == act || (exp != null && exp.equals(act))) return; |
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
74 |
throw new AssertionError("not equal: "+exp+", "+act); |
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
75 |
} |
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
76 |
|
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
77 |
private static void setSM() { |
18766
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
78 |
Policy.setPolicy(new TestPolicy()); |
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
79 |
System.setSecurityManager(new SecurityManager()); |
7558 | 80 |
} |
81 |
||
82 |
private static PrintStream oldOut; |
|
83 |
private static ByteArrayOutputStream buf; |
|
84 |
private static void openBuf() { |
|
85 |
oldOut = System.out; |
|
86 |
buf = new ByteArrayOutputStream(); |
|
87 |
System.setOut(new PrintStream(buf)); |
|
88 |
} |
|
89 |
private static void closeBuf() { |
|
90 |
if (buf == null) return; |
|
91 |
System.out.flush(); |
|
92 |
System.setOut(oldOut); |
|
93 |
String[] haveLines = new String(buf.toByteArray()).split("[\n\r]+"); |
|
94 |
for (String line : haveLines) System.out.println(line); |
|
95 |
Iterator<String> iter = Arrays.asList(haveLines).iterator(); |
|
96 |
for (String want : EXPECT_OUTPUT) { |
|
97 |
String have = iter.hasNext() ? iter.next() : "[EOF]"; |
|
98 |
if (want.equals(have)) continue; |
|
99 |
System.err.println("want line: "+want); |
|
100 |
System.err.println("have line: "+have); |
|
101 |
throw new AssertionError("unexpected output: "+have); |
|
102 |
} |
|
103 |
if (iter.hasNext()) |
|
104 |
throw new AssertionError("unexpected output: "+iter.next()); |
|
105 |
} |
|
106 |
private static final String[] EXPECT_OUTPUT = { |
|
107 |
"Printing some argument lists, starting with a empty one:", |
|
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8345
diff
changeset
|
108 |
"[test.java.lang.invoke.InvokeDynamicPrintArgs, nothing, ()void][]", |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8345
diff
changeset
|
109 |
"[test.java.lang.invoke.InvokeDynamicPrintArgs, bar, (String,int)void, class java.lang.Void, void type!, 1, 234.5, 67.5, 89][bar arg, 1]", |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8345
diff
changeset
|
110 |
"[test.java.lang.invoke.InvokeDynamicPrintArgs, bar2, (String,int)void, class java.lang.Void, void type!, 1, 234.5, 67.5, 89][bar2 arg, 222]", |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8345
diff
changeset
|
111 |
"[test.java.lang.invoke.InvokeDynamicPrintArgs, baz, (String,int,double)void, 1234.5][baz arg, 2, 3.14]", |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8345
diff
changeset
|
112 |
"[test.java.lang.invoke.InvokeDynamicPrintArgs, foo, (String)void][foo arg]", |
7558 | 113 |
"Done printing argument lists." |
114 |
}; |
|
115 |
||
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
116 |
private static boolean doPrint = true; |
7558 | 117 |
private static void printArgs(Object bsmInfo, Object... args) { |
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
118 |
String message = bsmInfo+Arrays.deepToString(args); |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
119 |
if (doPrint) System.out.println(message); |
7558 | 120 |
} |
121 |
private static MethodHandle MH_printArgs() throws ReflectiveOperationException { |
|
122 |
shouldNotCallThis(); |
|
123 |
return lookup().findStatic(lookup().lookupClass(), |
|
124 |
"printArgs", methodType(void.class, Object.class, Object[].class)); |
|
125 |
} |
|
126 |
||
127 |
private static CallSite bsm(Lookup caller, String name, MethodType type) throws ReflectiveOperationException { |
|
128 |
// ignore caller and name, but match the type: |
|
129 |
Object bsmInfo = Arrays.asList(caller, name, type); |
|
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7558
diff
changeset
|
130 |
return new ConstantCallSite(MH_printArgs().bindTo(bsmInfo).asCollector(Object[].class, type.parameterCount()).asType(type)); |
7558 | 131 |
} |
132 |
private static MethodType MT_bsm() { |
|
133 |
shouldNotCallThis(); |
|
134 |
return methodType(CallSite.class, Lookup.class, String.class, MethodType.class); |
|
135 |
} |
|
136 |
private static MethodHandle MH_bsm() throws ReflectiveOperationException { |
|
137 |
shouldNotCallThis(); |
|
138 |
return lookup().findStatic(lookup().lookupClass(), "bsm", MT_bsm()); |
|
139 |
} |
|
9780
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
140 |
private static MethodHandle non_MH_bsm() throws ReflectiveOperationException { |
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
141 |
return lookup().findStatic(lookup().lookupClass(), "bsm", MT_bsm()); |
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
142 |
} |
7558 | 143 |
|
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
144 |
/* Example of a constant call site with user-data. |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
145 |
* In this case, the user data is exactly the BSM data. |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
146 |
* Note that a CCS with user data must use the "hooked" constructor |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
147 |
* to bind the CCS itself into the resulting target. |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
148 |
* A normal constructor would not allow a circular relation |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
149 |
* between the CCS and its target. |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
150 |
*/ |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
151 |
public static class PrintingCallSite extends ConstantCallSite { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
152 |
final Lookup caller; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
153 |
final String name; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
154 |
final Object[] staticArgs; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
155 |
|
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
156 |
PrintingCallSite(Lookup caller, String name, MethodType type, Object... staticArgs) throws Throwable { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
157 |
super(type, MH_createTarget()); |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
158 |
this.caller = caller; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
159 |
this.name = name; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
160 |
this.staticArgs = staticArgs; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
161 |
} |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
162 |
|
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
163 |
public MethodHandle createTarget() { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
164 |
try { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
165 |
return lookup().bind(this, "runTarget", genericMethodType(0, true)).asType(type()); |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
166 |
} catch (ReflectiveOperationException ex) { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
167 |
throw new RuntimeException(ex); |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
168 |
} |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
169 |
} |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
170 |
|
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
171 |
public Object runTarget(Object... dynamicArgs) { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
172 |
List<Object> bsmInfo = new ArrayList<>(Arrays.asList(caller, name, type())); |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
173 |
bsmInfo.addAll(Arrays.asList(staticArgs)); |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
174 |
printArgs(bsmInfo, dynamicArgs); |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
175 |
return null; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
176 |
} |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
177 |
|
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
178 |
private static MethodHandle MH_createTarget() throws ReflectiveOperationException { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
179 |
shouldNotCallThis(); |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
180 |
return lookup().findVirtual(lookup().lookupClass(), "createTarget", methodType(MethodHandle.class)); |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
181 |
} |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
182 |
} |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
183 |
private static CallSite bsm2(Lookup caller, String name, MethodType type, Object... arg) throws Throwable { |
7558 | 184 |
// ignore caller and name, but match the type: |
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
185 |
return new PrintingCallSite(caller, name, type, arg); |
7558 | 186 |
} |
187 |
private static MethodType MT_bsm2() { |
|
188 |
shouldNotCallThis(); |
|
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7562
diff
changeset
|
189 |
return methodType(CallSite.class, Lookup.class, String.class, MethodType.class, Object[].class); |
7558 | 190 |
} |
191 |
private static MethodHandle MH_bsm2() throws ReflectiveOperationException { |
|
192 |
shouldNotCallThis(); |
|
193 |
return lookup().findStatic(lookup().lookupClass(), "bsm2", MT_bsm2()); |
|
194 |
} |
|
195 |
||
196 |
private static MethodHandle INDY_nothing() throws Throwable { |
|
197 |
shouldNotCallThis(); |
|
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
198 |
return ((CallSite) MH_bsm().invoke(lookup(), |
7558 | 199 |
"nothing", methodType(void.class) |
200 |
)).dynamicInvoker(); |
|
201 |
} |
|
202 |
private static MethodHandle INDY_foo() throws Throwable { |
|
203 |
shouldNotCallThis(); |
|
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
204 |
return ((CallSite) MH_bsm().invoke(lookup(), |
7558 | 205 |
"foo", methodType(void.class, String.class) |
206 |
)).dynamicInvoker(); |
|
207 |
} |
|
208 |
private static MethodHandle INDY_bar() throws Throwable { |
|
209 |
shouldNotCallThis(); |
|
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
210 |
return ((CallSite) MH_bsm2().invoke(lookup(), |
7558 | 211 |
"bar", methodType(void.class, String.class, int.class) |
9033
a88f5656f05d
6817525: turn on method handle functionality by default for JSR 292
jrose
parents:
8822
diff
changeset
|
212 |
, Void.class, "void type!", 1, 234.5F, 67.5, (long)89 |
7558 | 213 |
)).dynamicInvoker(); |
214 |
} |
|
215 |
private static MethodHandle INDY_bar2() throws Throwable { |
|
216 |
shouldNotCallThis(); |
|
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
217 |
return ((CallSite) MH_bsm2().invoke(lookup(), |
7558 | 218 |
"bar2", methodType(void.class, String.class, int.class) |
9033
a88f5656f05d
6817525: turn on method handle functionality by default for JSR 292
jrose
parents:
8822
diff
changeset
|
219 |
, Void.class, "void type!", 1, 234.5F, 67.5, (long)89 |
7558 | 220 |
)).dynamicInvoker(); |
221 |
} |
|
222 |
private static MethodHandle INDY_baz() throws Throwable { |
|
223 |
shouldNotCallThis(); |
|
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9033
diff
changeset
|
224 |
return ((CallSite) MH_bsm2().invoke(lookup(), |
7558 | 225 |
"baz", methodType(void.class, String.class, int.class, double.class) |
226 |
, 1234.5 |
|
227 |
)).dynamicInvoker(); |
|
228 |
} |
|
229 |
||
230 |
private static void shouldNotCallThis() { |
|
231 |
// if this gets called, the transformation has not taken place |
|
232 |
if (System.getProperty("InvokeDynamicPrintArgs.allow-untransformed") != null) return; |
|
233 |
throw new AssertionError("this code should be statically transformed away by Indify"); |
|
234 |
} |
|
18766
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
235 |
|
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
236 |
static class TestPolicy extends Policy { |
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
237 |
final PermissionCollection permissions = new Permissions(); |
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
238 |
TestPolicy() { |
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
239 |
permissions.add(new java.io.FilePermission("<<ALL FILES>>", "read")); |
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
240 |
} |
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
241 |
public PermissionCollection getPermissions(ProtectionDomain domain) { |
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
242 |
return permissions; |
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
243 |
} |
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
244 |
|
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
245 |
public PermissionCollection getPermissions(CodeSource codesource) { |
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
246 |
return permissions; |
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
247 |
} |
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
248 |
|
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
249 |
public boolean implies(ProtectionDomain domain, Permission perm) { |
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
250 |
return permissions.implies(perm); |
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
251 |
} |
28c62f5e9a47
8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents:
11007
diff
changeset
|
252 |
} |
7558 | 253 |
} |