author | vlivanov |
Tue, 11 Mar 2014 19:54:33 +0400 | |
changeset 23338 | 0a84d339822a |
parent 23059 | 4aca6147df88 |
child 24572 | 5c9e5961d21c |
permissions | -rw-r--r-- |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1 |
/* |
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14852
diff
changeset
|
2 |
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
4 |
* |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
10 |
* |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
15 |
* accompanied this code). |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
16 |
* |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
20 |
* |
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
24 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
25 |
|
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
26 |
package java.lang.invoke; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
27 |
|
14222 | 28 |
import java.security.AccessController; |
29 |
import java.security.PrivilegedAction; |
|
4537 | 30 |
import java.util.Arrays; |
31 |
import java.util.HashMap; |
|
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
32 |
import sun.invoke.empty.Empty; |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
33 |
import sun.invoke.util.ValueConversions; |
14222 | 34 |
import sun.invoke.util.VerifyType; |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
35 |
import sun.invoke.util.Wrapper; |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16123
diff
changeset
|
36 |
import sun.reflect.CallerSensitive; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16123
diff
changeset
|
37 |
import sun.reflect.Reflection; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
38 |
import static java.lang.invoke.LambdaForm.*; |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
39 |
import static java.lang.invoke.MethodHandleStatics.*; |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
40 |
import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
41 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
42 |
/** |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
43 |
* Trusted implementation code for MethodHandle. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
44 |
* @author jrose |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
45 |
*/ |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
46 |
/*non-public*/ abstract class MethodHandleImpl { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
47 |
/// Factory methods to create method handles: |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
48 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
49 |
static void initStatics() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
50 |
// Trigger selected static initializations. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
51 |
MemberName.Factory.INSTANCE.getClass(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
52 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
53 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
54 |
static MethodHandle makeArrayElementAccessor(Class<?> arrayClass, boolean isSetter) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
55 |
if (!arrayClass.isArray()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
56 |
throw newIllegalArgumentException("not an array: "+arrayClass); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
57 |
MethodHandle accessor = ArrayAccessor.getAccessor(arrayClass, isSetter); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
58 |
MethodType srcType = accessor.type().erase(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
59 |
MethodType lambdaType = srcType.invokerType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
60 |
Name[] names = arguments(1, lambdaType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
61 |
Name[] args = Arrays.copyOfRange(names, 1, 1 + srcType.parameterCount()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
62 |
names[names.length - 1] = new Name(accessor.asType(srcType), (Object[]) args); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
63 |
LambdaForm form = new LambdaForm("getElement", lambdaType.parameterCount(), names); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
64 |
MethodHandle mh = SimpleMethodHandle.make(srcType, form); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
65 |
if (ArrayAccessor.needCast(arrayClass)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
66 |
mh = mh.bindTo(arrayClass); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
67 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
68 |
mh = mh.asType(ArrayAccessor.correctType(arrayClass, isSetter)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
69 |
return mh; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
70 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
71 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
72 |
static final class ArrayAccessor { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
73 |
/// Support for array element access |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
74 |
static final HashMap<Class<?>, MethodHandle> GETTER_CACHE = new HashMap<>(); // TODO use it |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
75 |
static final HashMap<Class<?>, MethodHandle> SETTER_CACHE = new HashMap<>(); // TODO use it |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
76 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
77 |
static int getElementI(int[] a, int i) { return a[i]; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
78 |
static long getElementJ(long[] a, int i) { return a[i]; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
79 |
static float getElementF(float[] a, int i) { return a[i]; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
80 |
static double getElementD(double[] a, int i) { return a[i]; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
81 |
static boolean getElementZ(boolean[] a, int i) { return a[i]; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
82 |
static byte getElementB(byte[] a, int i) { return a[i]; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
83 |
static short getElementS(short[] a, int i) { return a[i]; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
84 |
static char getElementC(char[] a, int i) { return a[i]; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
85 |
static Object getElementL(Object[] a, int i) { return a[i]; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
86 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
87 |
static void setElementI(int[] a, int i, int x) { a[i] = x; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
88 |
static void setElementJ(long[] a, int i, long x) { a[i] = x; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
89 |
static void setElementF(float[] a, int i, float x) { a[i] = x; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
90 |
static void setElementD(double[] a, int i, double x) { a[i] = x; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
91 |
static void setElementZ(boolean[] a, int i, boolean x) { a[i] = x; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
92 |
static void setElementB(byte[] a, int i, byte x) { a[i] = x; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
93 |
static void setElementS(short[] a, int i, short x) { a[i] = x; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
94 |
static void setElementC(char[] a, int i, char x) { a[i] = x; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
95 |
static void setElementL(Object[] a, int i, Object x) { a[i] = x; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
96 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
97 |
static Object getElementL(Class<?> arrayClass, Object[] a, int i) { arrayClass.cast(a); return a[i]; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
98 |
static void setElementL(Class<?> arrayClass, Object[] a, int i, Object x) { arrayClass.cast(a); a[i] = x; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
99 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
100 |
// Weakly typed wrappers of Object[] accessors: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
101 |
static Object getElementL(Object a, int i) { return getElementL((Object[])a, i); } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
102 |
static void setElementL(Object a, int i, Object x) { setElementL((Object[]) a, i, x); } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
103 |
static Object getElementL(Object arrayClass, Object a, int i) { return getElementL((Class<?>) arrayClass, (Object[])a, i); } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
104 |
static void setElementL(Object arrayClass, Object a, int i, Object x) { setElementL((Class<?>) arrayClass, (Object[])a, i, x); } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
105 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
106 |
static boolean needCast(Class<?> arrayClass) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
107 |
Class<?> elemClass = arrayClass.getComponentType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
108 |
return !elemClass.isPrimitive() && elemClass != Object.class; |
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
109 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
110 |
static String name(Class<?> arrayClass, boolean isSetter) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
111 |
Class<?> elemClass = arrayClass.getComponentType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
112 |
if (elemClass == null) throw new IllegalArgumentException(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
113 |
return (!isSetter ? "getElement" : "setElement") + Wrapper.basicTypeChar(elemClass); |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
114 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
115 |
static final boolean USE_WEAKLY_TYPED_ARRAY_ACCESSORS = false; // FIXME: decide |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
116 |
static MethodType type(Class<?> arrayClass, boolean isSetter) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
117 |
Class<?> elemClass = arrayClass.getComponentType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
118 |
Class<?> arrayArgClass = arrayClass; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
119 |
if (!elemClass.isPrimitive()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
120 |
arrayArgClass = Object[].class; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
121 |
if (USE_WEAKLY_TYPED_ARRAY_ACCESSORS) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
122 |
arrayArgClass = Object.class; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
123 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
124 |
if (!needCast(arrayClass)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
125 |
return !isSetter ? |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
126 |
MethodType.methodType(elemClass, arrayArgClass, int.class) : |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
127 |
MethodType.methodType(void.class, arrayArgClass, int.class, elemClass); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
128 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
129 |
Class<?> classArgClass = Class.class; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
130 |
if (USE_WEAKLY_TYPED_ARRAY_ACCESSORS) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
131 |
classArgClass = Object.class; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
132 |
return !isSetter ? |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
133 |
MethodType.methodType(Object.class, classArgClass, arrayArgClass, int.class) : |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
134 |
MethodType.methodType(void.class, classArgClass, arrayArgClass, int.class, Object.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
135 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
136 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
137 |
static MethodType correctType(Class<?> arrayClass, boolean isSetter) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
138 |
Class<?> elemClass = arrayClass.getComponentType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
139 |
return !isSetter ? |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
140 |
MethodType.methodType(elemClass, arrayClass, int.class) : |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
141 |
MethodType.methodType(void.class, arrayClass, int.class, elemClass); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
142 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
143 |
static MethodHandle getAccessor(Class<?> arrayClass, boolean isSetter) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
144 |
String name = name(arrayClass, isSetter); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
145 |
MethodType type = type(arrayClass, isSetter); |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
146 |
try { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
147 |
return IMPL_LOOKUP.findStatic(ArrayAccessor.class, name, type); |
8347
e5daa5772ffd
7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents:
8346
diff
changeset
|
148 |
} catch (ReflectiveOperationException ex) { |
7052
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
149 |
throw uncaughtException(ex); |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
150 |
} |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
151 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
152 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
153 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
154 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
155 |
* Create a JVM-level adapter method handle to conform the given method |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
156 |
* handle to the similar newType, using only pairwise argument conversions. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
157 |
* For each argument, convert incoming argument to the exact type needed. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
158 |
* The argument conversions allowed are casting, boxing and unboxing, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
159 |
* integral widening or narrowing, and floating point widening or narrowing. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
160 |
* @param srcType required call type |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
161 |
* @param target original method handle |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
162 |
* @param level which strength of conversion is allowed |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
163 |
* @return an adapter to the original handle with the desired new type, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
164 |
* or the original target if the types are already identical |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
165 |
* or null if the adaptation cannot be made |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
166 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
167 |
static MethodHandle makePairwiseConvert(MethodHandle target, MethodType srcType, int level) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
168 |
assert(level >= 0 && level <= 2); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
169 |
MethodType dstType = target.type(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
170 |
assert(dstType.parameterCount() == target.type().parameterCount()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
171 |
if (srcType == dstType) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
172 |
return target; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
173 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
174 |
// Calculate extra arguments (temporaries) required in the names array. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
175 |
// FIXME: Use an ArrayList<Name>. Some arguments require more than one conversion step. |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
176 |
final int INARG_COUNT = srcType.parameterCount(); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
177 |
int conversions = 0; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
178 |
boolean[] needConv = new boolean[1+INARG_COUNT]; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
179 |
for (int i = 0; i <= INARG_COUNT; i++) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
180 |
Class<?> src = (i == INARG_COUNT) ? dstType.returnType() : srcType.parameterType(i); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
181 |
Class<?> dst = (i == INARG_COUNT) ? srcType.returnType() : dstType.parameterType(i); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
182 |
if (!VerifyType.isNullConversion(src, dst) || |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
183 |
level <= 1 && dst.isInterface() && !dst.isAssignableFrom(src)) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
184 |
needConv[i] = true; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
185 |
conversions++; |
4537 | 186 |
} |
13420
62cedce8afa6
7129034: VM crash with a field setter method with a filterArguments
jrose
parents:
11534
diff
changeset
|
187 |
} |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
188 |
boolean retConv = needConv[INARG_COUNT]; |
13420
62cedce8afa6
7129034: VM crash with a field setter method with a filterArguments
jrose
parents:
11534
diff
changeset
|
189 |
|
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
190 |
final int IN_MH = 0; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
191 |
final int INARG_BASE = 1; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
192 |
final int INARG_LIMIT = INARG_BASE + INARG_COUNT; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
193 |
final int NAME_LIMIT = INARG_LIMIT + conversions + 1; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
194 |
final int RETURN_CONV = (!retConv ? -1 : NAME_LIMIT - 1); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
195 |
final int OUT_CALL = (!retConv ? NAME_LIMIT : RETURN_CONV) - 1; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
196 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
197 |
// Now build a LambdaForm. |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
198 |
MethodType lambdaType = srcType.basicType().invokerType(); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
199 |
Name[] names = arguments(NAME_LIMIT - INARG_LIMIT, lambdaType); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
200 |
|
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
201 |
// Collect the arguments to the outgoing call, maybe with conversions: |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
202 |
final int OUTARG_BASE = 0; // target MH is Name.function, name Name.arguments[0] |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
203 |
Object[] outArgs = new Object[OUTARG_BASE + INARG_COUNT]; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
204 |
|
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
205 |
int nameCursor = INARG_LIMIT; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
206 |
for (int i = 0; i < INARG_COUNT; i++) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
207 |
Class<?> src = srcType.parameterType(i); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
208 |
Class<?> dst = dstType.parameterType(i); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
209 |
|
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
210 |
if (!needConv[i]) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
211 |
// do nothing: difference is trivial |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
212 |
outArgs[OUTARG_BASE + i] = names[INARG_BASE + i]; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
213 |
continue; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
214 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
215 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
216 |
// Tricky case analysis follows. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
217 |
MethodHandle fn = null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
218 |
if (src.isPrimitive()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
219 |
if (dst.isPrimitive()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
220 |
fn = ValueConversions.convertPrimitive(src, dst); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
221 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
222 |
Wrapper w = Wrapper.forPrimitiveType(src); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
223 |
MethodHandle boxMethod = ValueConversions.box(w); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
224 |
if (dst == w.wrapperType()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
225 |
fn = boxMethod; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
226 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
227 |
fn = boxMethod.asType(MethodType.methodType(dst, src)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
228 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
229 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
230 |
if (dst.isPrimitive()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
231 |
// Caller has boxed a primitive. Unbox it for the target. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
232 |
Wrapper w = Wrapper.forPrimitiveType(dst); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
233 |
if (level == 0 || VerifyType.isNullConversion(src, w.wrapperType())) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
234 |
fn = ValueConversions.unbox(dst); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
235 |
} else if (src == Object.class || !Wrapper.isWrapperType(src)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
236 |
// Examples: Object->int, Number->int, Comparable->int; Byte->int, Character->int |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
237 |
// must include additional conversions |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
238 |
// src must be examined at runtime, to detect Byte, Character, etc. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
239 |
MethodHandle unboxMethod = (level == 1 |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
240 |
? ValueConversions.unbox(dst) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
241 |
: ValueConversions.unboxCast(dst)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
242 |
fn = unboxMethod; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
243 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
244 |
// Example: Byte->int |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
245 |
// Do this by reformulating the problem to Byte->byte. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
246 |
Class<?> srcPrim = Wrapper.forWrapperType(src).primitiveType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
247 |
MethodHandle unbox = ValueConversions.unbox(srcPrim); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
248 |
// Compose the two conversions. FIXME: should make two Names for this job |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
249 |
fn = unbox.asType(MethodType.methodType(dst, src)); |
9780
6fc3b49cfee4
7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents:
9752
diff
changeset
|
250 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
251 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
252 |
// Simple reference conversion. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
253 |
// Note: Do not check for a class hierarchy relation |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
254 |
// between src and dst. In all cases a 'null' argument |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
255 |
// will pass the cast conversion. |
23039
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
256 |
fn = ValueConversions.cast(dst, Lazy.MH_castReference); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
257 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
258 |
} |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
259 |
Name conv = new Name(fn, names[INARG_BASE + i]); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
260 |
assert(names[nameCursor] == null); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
261 |
names[nameCursor++] = conv; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
262 |
assert(outArgs[OUTARG_BASE + i] == null); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
263 |
outArgs[OUTARG_BASE + i] = conv; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
264 |
} |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
265 |
|
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
266 |
// Build argument array for the call. |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
267 |
assert(nameCursor == OUT_CALL); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
268 |
names[OUT_CALL] = new Name(target, outArgs); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
269 |
|
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
270 |
if (RETURN_CONV < 0) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
271 |
assert(OUT_CALL == names.length-1); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
272 |
} else { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
273 |
Class<?> needReturn = srcType.returnType(); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
274 |
Class<?> haveReturn = dstType.returnType(); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
275 |
MethodHandle fn; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
276 |
Object[] arg = { names[OUT_CALL] }; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
277 |
if (haveReturn == void.class) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
278 |
// synthesize a zero value for the given void |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
279 |
Object zero = Wrapper.forBasicType(needReturn).zero(); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
280 |
fn = MethodHandles.constant(needReturn, zero); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
281 |
arg = new Object[0]; // don't pass names[OUT_CALL] to conversion |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
282 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
283 |
MethodHandle identity = MethodHandles.identity(needReturn); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
284 |
MethodType needConversion = identity.type().changeParameterType(0, haveReturn); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
285 |
fn = makePairwiseConvert(identity, needConversion, level); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
286 |
} |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
287 |
assert(names[RETURN_CONV] == null); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
288 |
names[RETURN_CONV] = new Name(fn, arg); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
289 |
assert(RETURN_CONV == names.length-1); |
4537 | 290 |
} |
291 |
||
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
292 |
LambdaForm form = new LambdaForm("convert", lambdaType.parameterCount(), names); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
293 |
return SimpleMethodHandle.make(srcType, form); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
294 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
295 |
|
23039
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
296 |
/** |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
297 |
* Identity function, with reference cast. |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
298 |
* @param t an arbitrary reference type |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
299 |
* @param x an arbitrary reference value |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
300 |
* @return the same value x |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
301 |
*/ |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
302 |
@ForceInline |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
303 |
@SuppressWarnings("unchecked") |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
304 |
static <T,U> T castReference(Class<? extends T> t, U x) { |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
305 |
// inlined Class.cast because we can't ForceInline it |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
306 |
if (x != null && !t.isInstance(x)) |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
307 |
throw newClassCastException(t, x); |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
308 |
return (T) x; |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
309 |
} |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
310 |
|
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
311 |
private static ClassCastException newClassCastException(Class<?> t, Object obj) { |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
312 |
return new ClassCastException("Cannot cast " + obj.getClass().getName() + " to " + t.getName()); |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
313 |
} |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
314 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
315 |
static MethodHandle makeReferenceIdentity(Class<?> refType) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
316 |
MethodType lambdaType = MethodType.genericMethodType(1).invokerType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
317 |
Name[] names = arguments(1, lambdaType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
318 |
names[names.length - 1] = new Name(ValueConversions.identity(), names[1]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
319 |
LambdaForm form = new LambdaForm("identity", lambdaType.parameterCount(), names); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
320 |
return SimpleMethodHandle.make(MethodType.methodType(refType, refType), form); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
321 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
322 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
323 |
static MethodHandle makeVarargsCollector(MethodHandle target, Class<?> arrayType) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
324 |
MethodType type = target.type(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
325 |
int last = type.parameterCount() - 1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
326 |
if (type.parameterType(last) != arrayType) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
327 |
target = target.asType(type.changeParameterType(last, arrayType)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
328 |
target = target.asFixedArity(); // make sure this attribute is turned off |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
329 |
return new AsVarargsCollector(target, target.type(), arrayType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
330 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
331 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
332 |
static class AsVarargsCollector extends MethodHandle { |
14852 | 333 |
private final MethodHandle target; |
334 |
private final Class<?> arrayType; |
|
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20495
diff
changeset
|
335 |
private /*@Stable*/ MethodHandle asCollectorCache; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
336 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
337 |
AsVarargsCollector(MethodHandle target, MethodType type, Class<?> arrayType) { |
19804 | 338 |
super(type, reinvokerForm(target)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
339 |
this.target = target; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
340 |
this.arrayType = arrayType; |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20495
diff
changeset
|
341 |
this.asCollectorCache = target.asCollector(arrayType, 0); |
4537 | 342 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
343 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
344 |
@Override MethodHandle reinvokerTarget() { return target; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
345 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
346 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
347 |
public boolean isVarargsCollector() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
348 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
349 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
350 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
351 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
352 |
public MethodHandle asFixedArity() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
353 |
return target; |
4537 | 354 |
} |
355 |
||
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
356 |
@Override |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20495
diff
changeset
|
357 |
public MethodHandle asTypeUncached(MethodType newType) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
358 |
MethodType type = this.type(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
359 |
int collectArg = type.parameterCount() - 1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
360 |
int newArity = newType.parameterCount(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
361 |
if (newArity == collectArg+1 && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
362 |
type.parameterType(collectArg).isAssignableFrom(newType.parameterType(collectArg))) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
363 |
// if arity and trailing parameter are compatible, do normal thing |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20495
diff
changeset
|
364 |
return asTypeCache = asFixedArity().asType(newType); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
365 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
366 |
// check cache |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20495
diff
changeset
|
367 |
MethodHandle acc = asCollectorCache; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20495
diff
changeset
|
368 |
if (acc != null && acc.type().parameterCount() == newArity) |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20495
diff
changeset
|
369 |
return asTypeCache = acc.asType(newType); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
370 |
// build and cache a collector |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
371 |
int arrayLength = newArity - collectArg; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
372 |
MethodHandle collector; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
373 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
374 |
collector = asFixedArity().asCollector(arrayType, arrayLength); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
375 |
assert(collector.type().parameterCount() == newArity) : "newArity="+newArity+" but collector="+collector; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
376 |
} catch (IllegalArgumentException ex) { |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
377 |
throw new WrongMethodTypeException("cannot build collector", ex); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
378 |
} |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20495
diff
changeset
|
379 |
asCollectorCache = collector; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20495
diff
changeset
|
380 |
return asTypeCache = collector.asType(newType); |
4537 | 381 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
382 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
383 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
384 |
MethodHandle setVarargs(MemberName member) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
385 |
if (member.isVarargs()) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
386 |
return asFixedArity(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
387 |
} |
4537 | 388 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
389 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
390 |
MethodHandle viewAsType(MethodType newType) { |
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14852
diff
changeset
|
391 |
if (newType.lastParameterType() != type().lastParameterType()) |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14852
diff
changeset
|
392 |
throw new InternalError(); |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14852
diff
changeset
|
393 |
MethodHandle newTarget = asFixedArity().viewAsType(newType); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
394 |
// put back the varargs bit: |
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14852
diff
changeset
|
395 |
return new AsVarargsCollector(newTarget, newType, arrayType); |
4537 | 396 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
397 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
398 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
399 |
MemberName internalMemberName() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
400 |
return asFixedArity().internalMemberName(); |
4537 | 401 |
} |
20534
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
402 |
@Override |
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
403 |
Class<?> internalCallerClass() { |
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
404 |
return asFixedArity().internalCallerClass(); |
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
405 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
406 |
|
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14852
diff
changeset
|
407 |
/*non-public*/ |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14852
diff
changeset
|
408 |
@Override |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14852
diff
changeset
|
409 |
boolean isInvokeSpecial() { |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14852
diff
changeset
|
410 |
return asFixedArity().isInvokeSpecial(); |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14852
diff
changeset
|
411 |
} |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14852
diff
changeset
|
412 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
413 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
414 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
415 |
MethodHandle bindArgument(int pos, char basicType, Object value) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
416 |
return asFixedArity().bindArgument(pos, basicType, value); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
417 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
418 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
419 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
420 |
MethodHandle bindReceiver(Object receiver) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
421 |
return asFixedArity().bindReceiver(receiver); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
422 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
423 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
424 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
425 |
MethodHandle dropArguments(MethodType srcType, int pos, int drops) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
426 |
return asFixedArity().dropArguments(srcType, pos, drops); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
427 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
428 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
429 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
430 |
MethodHandle permuteArguments(MethodType newType, int[] reorder) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
431 |
return asFixedArity().permuteArguments(newType, reorder); |
4537 | 432 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
433 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
434 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
435 |
/** Factory method: Spread selected argument. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
436 |
static MethodHandle makeSpreadArguments(MethodHandle target, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
437 |
Class<?> spreadArgType, int spreadArgPos, int spreadArgCount) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
438 |
MethodType targetType = target.type(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
439 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
440 |
for (int i = 0; i < spreadArgCount; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
441 |
Class<?> arg = VerifyType.spreadArgElementType(spreadArgType, i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
442 |
if (arg == null) arg = Object.class; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
443 |
targetType = targetType.changeParameterType(spreadArgPos + i, arg); |
2764
2e45af54c0f9
6839839: access checking logic is wrong at three points in MethodHandles
jrose
parents:
2707
diff
changeset
|
444 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
445 |
target = target.asType(targetType); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
446 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
447 |
MethodType srcType = targetType |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
448 |
.replaceParameterTypes(spreadArgPos, spreadArgPos + spreadArgCount, spreadArgType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
449 |
// Now build a LambdaForm. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
450 |
MethodType lambdaType = srcType.invokerType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
451 |
Name[] names = arguments(spreadArgCount + 2, lambdaType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
452 |
int nameCursor = lambdaType.parameterCount(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
453 |
int[] indexes = new int[targetType.parameterCount()]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
454 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
455 |
for (int i = 0, argIndex = 1; i < targetType.parameterCount() + 1; i++, argIndex++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
456 |
Class<?> src = lambdaType.parameterType(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
457 |
if (i == spreadArgPos) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
458 |
// Spread the array. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
459 |
MethodHandle aload = MethodHandles.arrayElementGetter(spreadArgType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
460 |
Name array = names[argIndex]; |
20495
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
19804
diff
changeset
|
461 |
names[nameCursor++] = new Name(Lazy.NF_checkSpreadArgument, array, spreadArgCount); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
462 |
for (int j = 0; j < spreadArgCount; i++, j++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
463 |
indexes[i] = nameCursor; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
464 |
names[nameCursor++] = new Name(aload, array, j); |
4537 | 465 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
466 |
} else if (i < indexes.length) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
467 |
indexes[i] = argIndex; |
4537 | 468 |
} |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
8822
diff
changeset
|
469 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
470 |
assert(nameCursor == names.length-1); // leave room for the final call |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
471 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
472 |
// Build argument array for the call. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
473 |
Name[] targetArgs = new Name[targetType.parameterCount()]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
474 |
for (int i = 0; i < targetType.parameterCount(); i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
475 |
int idx = indexes[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
476 |
targetArgs[i] = names[idx]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
477 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
478 |
names[names.length - 1] = new Name(target, (Object[]) targetArgs); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
479 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
480 |
LambdaForm form = new LambdaForm("spread", lambdaType.parameterCount(), names); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
481 |
return SimpleMethodHandle.make(srcType, form); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
482 |
} |
4537 | 483 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
484 |
static void checkSpreadArgument(Object av, int n) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
485 |
if (av == null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
486 |
if (n == 0) return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
487 |
} else if (av instanceof Object[]) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
488 |
int len = ((Object[])av).length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
489 |
if (len == n) return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
490 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
491 |
int len = java.lang.reflect.Array.getLength(av); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
492 |
if (len == n) return; |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
8822
diff
changeset
|
493 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
494 |
// fall through to error: |
20530
b54a1f5cd35f
8001109: arity mismatch on a call to spreader method handle should elicit IllegalArgumentException
jrose
parents:
20527
diff
changeset
|
495 |
throw newIllegalArgumentException("array is not of length "+n); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
496 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
497 |
|
20495
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
19804
diff
changeset
|
498 |
/** |
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
19804
diff
changeset
|
499 |
* Pre-initialized NamedFunctions for bootstrapping purposes. |
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
19804
diff
changeset
|
500 |
* Factored in an inner class to delay initialization until first usage. |
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
19804
diff
changeset
|
501 |
*/ |
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
19804
diff
changeset
|
502 |
private static class Lazy { |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
503 |
private static final Class<?> MHI = MethodHandleImpl.class; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
504 |
|
20495
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
19804
diff
changeset
|
505 |
static final NamedFunction NF_checkSpreadArgument; |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
506 |
static final NamedFunction NF_guardWithCatch; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
507 |
static final NamedFunction NF_selectAlternative; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
508 |
static final NamedFunction NF_throwException; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
509 |
|
23039
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
510 |
static final MethodHandle MH_castReference; |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
511 |
|
20495
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
19804
diff
changeset
|
512 |
static { |
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
19804
diff
changeset
|
513 |
try { |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
514 |
NF_checkSpreadArgument = new NamedFunction(MHI.getDeclaredMethod("checkSpreadArgument", Object.class, int.class)); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
515 |
NF_guardWithCatch = new NamedFunction(MHI.getDeclaredMethod("guardWithCatch", MethodHandle.class, Class.class, |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
516 |
MethodHandle.class, Object[].class)); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
517 |
NF_selectAlternative = new NamedFunction(MHI.getDeclaredMethod("selectAlternative", boolean.class, MethodHandle.class, |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
518 |
MethodHandle.class)); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
519 |
NF_throwException = new NamedFunction(MHI.getDeclaredMethod("throwException", Throwable.class)); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
520 |
|
20495
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
19804
diff
changeset
|
521 |
NF_checkSpreadArgument.resolve(); |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
522 |
NF_guardWithCatch.resolve(); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
523 |
NF_selectAlternative.resolve(); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
524 |
NF_throwException.resolve(); |
23039
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
525 |
|
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
526 |
MethodType mt = MethodType.methodType(Object.class, Class.class, Object.class); |
6ee70bc18809
8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
vlivanov
parents:
23038
diff
changeset
|
527 |
MH_castReference = IMPL_LOOKUP.findStatic(MHI, "castReference", mt); |
20495
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
19804
diff
changeset
|
528 |
} catch (ReflectiveOperationException ex) { |
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
19804
diff
changeset
|
529 |
throw newInternalError(ex); |
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
19804
diff
changeset
|
530 |
} |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
8822
diff
changeset
|
531 |
} |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
8822
diff
changeset
|
532 |
} |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
8822
diff
changeset
|
533 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
534 |
/** Factory method: Collect or filter selected argument(s). */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
535 |
static MethodHandle makeCollectArguments(MethodHandle target, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
536 |
MethodHandle collector, int collectArgPos, boolean retainOriginalArgs) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
537 |
MethodType targetType = target.type(); // (a..., c, [b...])=>r |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
538 |
MethodType collectorType = collector.type(); // (b...)=>c |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
539 |
int collectArgCount = collectorType.parameterCount(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
540 |
Class<?> collectValType = collectorType.returnType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
541 |
int collectValCount = (collectValType == void.class ? 0 : 1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
542 |
MethodType srcType = targetType // (a..., [b...])=>r |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
543 |
.dropParameterTypes(collectArgPos, collectArgPos+collectValCount); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
544 |
if (!retainOriginalArgs) { // (a..., b...)=>r |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
545 |
srcType = srcType.insertParameterTypes(collectArgPos, collectorType.parameterList()); |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
8822
diff
changeset
|
546 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
547 |
// in arglist: [0: ...keep1 | cpos: collect... | cpos+cacount: keep2... ] |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
548 |
// out arglist: [0: ...keep1 | cpos: collectVal? | cpos+cvcount: keep2... ] |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
549 |
// out(retain): [0: ...keep1 | cpos: cV? coll... | cpos+cvc+cac: keep2... ] |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
8822
diff
changeset
|
550 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
551 |
// Now build a LambdaForm. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
552 |
MethodType lambdaType = srcType.invokerType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
553 |
Name[] names = arguments(2, lambdaType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
554 |
final int collectNamePos = names.length - 2; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
555 |
final int targetNamePos = names.length - 1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
556 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
557 |
Name[] collectorArgs = Arrays.copyOfRange(names, 1 + collectArgPos, 1 + collectArgPos + collectArgCount); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
558 |
names[collectNamePos] = new Name(collector, (Object[]) collectorArgs); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
559 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
560 |
// Build argument array for the target. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
561 |
// Incoming LF args to copy are: [ (mh) headArgs collectArgs tailArgs ]. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
562 |
// Output argument array is [ headArgs (collectVal)? (collectArgs)? tailArgs ]. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
563 |
Name[] targetArgs = new Name[targetType.parameterCount()]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
564 |
int inputArgPos = 1; // incoming LF args to copy to target |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
565 |
int targetArgPos = 0; // fill pointer for targetArgs |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
566 |
int chunk = collectArgPos; // |headArgs| |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
567 |
System.arraycopy(names, inputArgPos, targetArgs, targetArgPos, chunk); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
568 |
inputArgPos += chunk; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
569 |
targetArgPos += chunk; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
570 |
if (collectValType != void.class) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
571 |
targetArgs[targetArgPos++] = names[collectNamePos]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
572 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
573 |
chunk = collectArgCount; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
574 |
if (retainOriginalArgs) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
575 |
System.arraycopy(names, inputArgPos, targetArgs, targetArgPos, chunk); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
576 |
targetArgPos += chunk; // optionally pass on the collected chunk |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
577 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
578 |
inputArgPos += chunk; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
579 |
chunk = targetArgs.length - targetArgPos; // all the rest |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
580 |
System.arraycopy(names, inputArgPos, targetArgs, targetArgPos, chunk); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
581 |
assert(inputArgPos + chunk == collectNamePos); // use of rest of input args also |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
582 |
names[targetNamePos] = new Name(target, (Object[]) targetArgs); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
583 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
584 |
LambdaForm form = new LambdaForm("collect", lambdaType.parameterCount(), names); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
585 |
return SimpleMethodHandle.make(srcType, form); |
4537 | 586 |
} |
587 |
||
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
588 |
@LambdaForm.Hidden |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
589 |
static |
9730
e4b334d47f4b
7032850: MethodHandle.invokeGeneric throws unspecified RuntimeException if parameterized method is called
jrose
parents:
9646
diff
changeset
|
590 |
MethodHandle selectAlternative(boolean testResult, MethodHandle target, MethodHandle fallback) { |
e4b334d47f4b
7032850: MethodHandle.invokeGeneric throws unspecified RuntimeException if parameterized method is called
jrose
parents:
9646
diff
changeset
|
591 |
return testResult ? target : fallback; |
e4b334d47f4b
7032850: MethodHandle.invokeGeneric throws unspecified RuntimeException if parameterized method is called
jrose
parents:
9646
diff
changeset
|
592 |
} |
e4b334d47f4b
7032850: MethodHandle.invokeGeneric throws unspecified RuntimeException if parameterized method is called
jrose
parents:
9646
diff
changeset
|
593 |
|
e4b334d47f4b
7032850: MethodHandle.invokeGeneric throws unspecified RuntimeException if parameterized method is called
jrose
parents:
9646
diff
changeset
|
594 |
static |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
595 |
MethodHandle makeGuardWithTest(MethodHandle test, |
4537 | 596 |
MethodHandle target, |
597 |
MethodHandle fallback) { |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
598 |
MethodType basicType = target.type().basicType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
599 |
MethodHandle invokeBasic = MethodHandles.basicInvoker(basicType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
600 |
int arity = basicType.parameterCount(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
601 |
int extraNames = 3; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
602 |
MethodType lambdaType = basicType.invokerType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
603 |
Name[] names = arguments(extraNames, lambdaType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
604 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
605 |
Object[] testArgs = Arrays.copyOfRange(names, 1, 1 + arity, Object[].class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
606 |
Object[] targetArgs = Arrays.copyOfRange(names, 0, 1 + arity, Object[].class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
607 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
608 |
// call test |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
609 |
names[arity + 1] = new Name(test, testArgs); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
610 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
611 |
// call selectAlternative |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
612 |
Object[] selectArgs = { names[arity + 1], target, fallback }; |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
613 |
names[arity + 2] = new Name(Lazy.NF_selectAlternative, selectArgs); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
614 |
targetArgs[0] = names[arity + 2]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
615 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
616 |
// call target or fallback |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
617 |
names[arity + 3] = new Name(new NamedFunction(invokeBasic), targetArgs); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
618 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
619 |
LambdaForm form = new LambdaForm("guard", lambdaType.parameterCount(), names); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
620 |
return SimpleMethodHandle.make(target.type(), form); |
4537 | 621 |
} |
622 |
||
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
623 |
/** |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
624 |
* The LambaForm shape for catchException combinator is the following: |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
625 |
* <blockquote><pre>{@code |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
626 |
* guardWithCatch=Lambda(a0:L,a1:L,a2:L)=>{ |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
627 |
* t3:L=BoundMethodHandle$Species_LLLLL.argL0(a0:L); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
628 |
* t4:L=BoundMethodHandle$Species_LLLLL.argL1(a0:L); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
629 |
* t5:L=BoundMethodHandle$Species_LLLLL.argL2(a0:L); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
630 |
* t6:L=BoundMethodHandle$Species_LLLLL.argL3(a0:L); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
631 |
* t7:L=BoundMethodHandle$Species_LLLLL.argL4(a0:L); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
632 |
* t8:L=MethodHandle.invokeBasic(t6:L,a1:L,a2:L); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
633 |
* t9:L=MethodHandleImpl.guardWithCatch(t3:L,t4:L,t5:L,t8:L); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
634 |
* t10:I=MethodHandle.invokeBasic(t7:L,t9:L);t10:I} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
635 |
* }</pre></blockquote> |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
636 |
* |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
637 |
* argL0 and argL2 are target and catcher method handles. argL1 is exception class. |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
638 |
* argL3 and argL4 are auxiliary method handles: argL3 boxes arguments and wraps them into Object[] |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
639 |
* (ValueConversions.array()) and argL4 unboxes result if necessary (ValueConversions.unbox()). |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
640 |
* |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
641 |
* Having t8 and t10 passed outside and not hardcoded into a lambda form allows to share lambda forms |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
642 |
* among catchException combinators with the same basic type. |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
643 |
*/ |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
644 |
private static LambdaForm makeGuardWithCatchForm(MethodType basicType) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
645 |
MethodType lambdaType = basicType.invokerType(); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
646 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
647 |
LambdaForm lform = basicType.form().cachedLambdaForm(MethodTypeForm.LF_GWC); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
648 |
if (lform != null) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
649 |
return lform; |
4537 | 650 |
} |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
651 |
final int THIS_MH = 0; // the BMH_LLLLL |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
652 |
final int ARG_BASE = 1; // start of incoming arguments |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
653 |
final int ARG_LIMIT = ARG_BASE + basicType.parameterCount(); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
654 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
655 |
int nameCursor = ARG_LIMIT; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
656 |
final int GET_TARGET = nameCursor++; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
657 |
final int GET_CLASS = nameCursor++; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
658 |
final int GET_CATCHER = nameCursor++; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
659 |
final int GET_COLLECT_ARGS = nameCursor++; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
660 |
final int GET_UNBOX_RESULT = nameCursor++; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
661 |
final int BOXED_ARGS = nameCursor++; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
662 |
final int TRY_CATCH = nameCursor++; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
663 |
final int UNBOX_RESULT = nameCursor++; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
664 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
665 |
Name[] names = arguments(nameCursor - ARG_LIMIT, lambdaType); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
666 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
667 |
BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLLLL(); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
668 |
names[GET_TARGET] = new Name(data.getterFunction(0), names[THIS_MH]); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
669 |
names[GET_CLASS] = new Name(data.getterFunction(1), names[THIS_MH]); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
670 |
names[GET_CATCHER] = new Name(data.getterFunction(2), names[THIS_MH]); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
671 |
names[GET_COLLECT_ARGS] = new Name(data.getterFunction(3), names[THIS_MH]); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
672 |
names[GET_UNBOX_RESULT] = new Name(data.getterFunction(4), names[THIS_MH]); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
673 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
674 |
// FIXME: rework argument boxing/result unboxing logic for LF interpretation |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
675 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
676 |
// t_{i}:L=MethodHandle.invokeBasic(collectArgs:L,a1:L,...); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
677 |
MethodType collectArgsType = basicType.changeReturnType(Object.class); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
678 |
MethodHandle invokeBasic = MethodHandles.basicInvoker(collectArgsType); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
679 |
Object[] args = new Object[invokeBasic.type().parameterCount()]; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
680 |
args[0] = names[GET_COLLECT_ARGS]; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
681 |
System.arraycopy(names, ARG_BASE, args, 1, ARG_LIMIT-ARG_BASE); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
682 |
names[BOXED_ARGS] = new Name(new NamedFunction(invokeBasic), args); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
683 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
684 |
// t_{i+1}:L=MethodHandleImpl.guardWithCatch(target:L,exType:L,catcher:L,t_{i}:L); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
685 |
Object[] gwcArgs = new Object[] {names[GET_TARGET], names[GET_CLASS], names[GET_CATCHER], names[BOXED_ARGS]}; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
686 |
names[TRY_CATCH] = new Name(Lazy.NF_guardWithCatch, gwcArgs); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
687 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
688 |
// t_{i+2}:I=MethodHandle.invokeBasic(unbox:L,t_{i+1}:L); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
689 |
MethodHandle invokeBasicUnbox = MethodHandles.basicInvoker(MethodType.methodType(basicType.rtype(), Object.class)); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
690 |
Object[] unboxArgs = new Object[] {names[GET_UNBOX_RESULT], names[TRY_CATCH]}; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
691 |
names[UNBOX_RESULT] = new Name(new NamedFunction(invokeBasicUnbox), unboxArgs); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
692 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
693 |
lform = new LambdaForm("guardWithCatch", lambdaType.parameterCount(), names); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
694 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
695 |
basicType.form().setCachedLambdaForm(MethodTypeForm.LF_GWC, lform); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
696 |
return lform; |
4537 | 697 |
} |
698 |
||
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
699 |
static |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
700 |
MethodHandle makeGuardWithCatch(MethodHandle target, |
4537 | 701 |
Class<? extends Throwable> exType, |
702 |
MethodHandle catcher) { |
|
703 |
MethodType type = target.type(); |
|
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
704 |
LambdaForm form = makeGuardWithCatchForm(type.basicType()); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
705 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
706 |
// Prepare auxiliary method handles used during LambdaForm interpreation. |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
707 |
// Box arguments and wrap them into Object[]: ValueConversions.array(). |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
708 |
MethodType varargsType = type.changeReturnType(Object[].class); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
709 |
MethodHandle collectArgs = ValueConversions.varargsArray(type.parameterCount()) |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
710 |
.asType(varargsType); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
711 |
// Result unboxing: ValueConversions.unbox() OR ValueConversions.identity() OR ValueConversions.ignore(). |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
712 |
MethodHandle unboxResult; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
713 |
if (type.returnType().isPrimitive()) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
714 |
unboxResult = ValueConversions.unbox(type.returnType()); |
4537 | 715 |
} else { |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
716 |
unboxResult = ValueConversions.identity(); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
717 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
718 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
719 |
BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLLLL(); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
720 |
BoundMethodHandle mh; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
721 |
try { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
722 |
mh = (BoundMethodHandle) |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
723 |
data.constructor[0].invokeBasic(type, form, (Object) target, (Object) exType, (Object) catcher, |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
724 |
(Object) collectArgs, (Object) unboxResult); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
725 |
} catch (Throwable ex) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
726 |
throw uncaughtException(ex); |
4537 | 727 |
} |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
728 |
assert(mh.type() == type); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
729 |
return mh; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
730 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
731 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
732 |
/** |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
733 |
* Intrinsified during LambdaForm compilation |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
734 |
* (see {@link InvokerBytecodeGenerator#emitGuardWithCatch emitGuardWithCatch}). |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
735 |
*/ |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
736 |
@LambdaForm.Hidden |
23059
4aca6147df88
8036732: Fix raw warning in java.lang.invoke.MethodHandleImpl.java
darcy
parents:
23039
diff
changeset
|
737 |
static Object guardWithCatch(MethodHandle target, Class<? extends Throwable> exType, MethodHandle catcher, |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
738 |
Object... av) throws Throwable { |
23338
0a84d339822a
8036117: MethodHandles.catchException doesn't handle VarargsCollector right (8034120 failed)
vlivanov
parents:
23059
diff
changeset
|
739 |
// Use asFixedArity() to avoid unnecessary boxing of last argument for VarargsCollector case. |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
740 |
try { |
23338
0a84d339822a
8036117: MethodHandles.catchException doesn't handle VarargsCollector right (8034120 failed)
vlivanov
parents:
23059
diff
changeset
|
741 |
return target.asFixedArity().invokeWithArguments(av); |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
742 |
} catch (Throwable t) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
743 |
if (!exType.isInstance(t)) throw t; |
23338
0a84d339822a
8036117: MethodHandles.catchException doesn't handle VarargsCollector right (8034120 failed)
vlivanov
parents:
23059
diff
changeset
|
744 |
return catcher.asFixedArity().invokeWithArguments(prepend(t, av)); |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
745 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
746 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
747 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
748 |
/** Prepend an element {@code elem} to an {@code array}. */ |
23338
0a84d339822a
8036117: MethodHandles.catchException doesn't handle VarargsCollector right (8034120 failed)
vlivanov
parents:
23059
diff
changeset
|
749 |
@LambdaForm.Hidden |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
750 |
private static Object[] prepend(Object elem, Object[] array) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
751 |
Object[] newArray = new Object[array.length+1]; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
752 |
newArray[0] = elem; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
753 |
System.arraycopy(array, 0, newArray, 1, array.length); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
754 |
return newArray; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
755 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
756 |
|
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
757 |
static |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
758 |
MethodHandle throwException(MethodType type) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
759 |
assert(Throwable.class.isAssignableFrom(type.parameterType(0))); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
760 |
int arity = type.parameterCount(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
761 |
if (arity > 1) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
762 |
return throwException(type.dropParameterTypes(1, arity)).dropArguments(type, 1, arity-1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
763 |
} |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
21649
diff
changeset
|
764 |
return makePairwiseConvert(Lazy.NF_throwException.resolvedHandle(), type, 2); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
765 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
766 |
|
4537 | 767 |
static <T extends Throwable> Empty throwException(T t) throws T { throw t; } |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
768 |
|
19804 | 769 |
static MethodHandle[] FAKE_METHOD_HANDLE_INVOKE = new MethodHandle[2]; |
770 |
static MethodHandle fakeMethodHandleInvoke(MemberName method) { |
|
771 |
int idx; |
|
772 |
assert(method.isMethodHandleInvoke()); |
|
773 |
switch (method.getName()) { |
|
774 |
case "invoke": idx = 0; break; |
|
775 |
case "invokeExact": idx = 1; break; |
|
776 |
default: throw new InternalError(method.getName()); |
|
777 |
} |
|
778 |
MethodHandle mh = FAKE_METHOD_HANDLE_INVOKE[idx]; |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
779 |
if (mh != null) return mh; |
19804 | 780 |
MethodType type = MethodType.methodType(Object.class, UnsupportedOperationException.class, |
781 |
MethodHandle.class, Object[].class); |
|
782 |
mh = throwException(type); |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
783 |
mh = mh.bindTo(new UnsupportedOperationException("cannot reflectively invoke MethodHandle")); |
19804 | 784 |
if (!method.getInvocationType().equals(mh.type())) |
785 |
throw new InternalError(method.toString()); |
|
786 |
mh = mh.withInternalMemberName(method); |
|
787 |
mh = mh.asVarargsCollector(Object[].class); |
|
788 |
assert(method.isVarargs()); |
|
789 |
FAKE_METHOD_HANDLE_INVOKE[idx] = mh; |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
790 |
return mh; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
791 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13420
diff
changeset
|
792 |
|
14222 | 793 |
/** |
794 |
* Create an alias for the method handle which, when called, |
|
795 |
* appears to be called from the same class loader and protection domain |
|
796 |
* as hostClass. |
|
797 |
* This is an expensive no-op unless the method which is called |
|
798 |
* is sensitive to its caller. A small number of system methods |
|
799 |
* are in this category, including Class.forName and Method.invoke. |
|
800 |
*/ |
|
801 |
static |
|
802 |
MethodHandle bindCaller(MethodHandle mh, Class<?> hostClass) { |
|
803 |
return BindCaller.bindCaller(mh, hostClass); |
|
804 |
} |
|
805 |
||
806 |
// Put the whole mess into its own nested class. |
|
807 |
// That way we can lazily load the code and set up the constants. |
|
808 |
private static class BindCaller { |
|
809 |
static |
|
810 |
MethodHandle bindCaller(MethodHandle mh, Class<?> hostClass) { |
|
811 |
// Do not use this function to inject calls into system classes. |
|
16118 | 812 |
if (hostClass == null |
813 |
|| (hostClass.isArray() || |
|
14222 | 814 |
hostClass.isPrimitive() || |
815 |
hostClass.getName().startsWith("java.") || |
|
16118 | 816 |
hostClass.getName().startsWith("sun."))) { |
14222 | 817 |
throw new InternalError(); // does not happen, and should not anyway |
818 |
} |
|
819 |
// For simplicity, convert mh to a varargs-like method. |
|
820 |
MethodHandle vamh = prepareForInvoker(mh); |
|
821 |
// Cache the result of makeInjectedInvoker once per argument class. |
|
822 |
MethodHandle bccInvoker = CV_makeInjectedInvoker.get(hostClass); |
|
20534
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
823 |
return restoreToType(bccInvoker.bindTo(vamh), mh.type(), mh.internalMemberName(), hostClass); |
14222 | 824 |
} |
825 |
||
826 |
private static MethodHandle makeInjectedInvoker(Class<?> hostClass) { |
|
827 |
Class<?> bcc = UNSAFE.defineAnonymousClass(hostClass, T_BYTES, null); |
|
828 |
if (hostClass.getClassLoader() != bcc.getClassLoader()) |
|
829 |
throw new InternalError(hostClass.getName()+" (CL)"); |
|
830 |
try { |
|
831 |
if (hostClass.getProtectionDomain() != bcc.getProtectionDomain()) |
|
832 |
throw new InternalError(hostClass.getName()+" (PD)"); |
|
833 |
} catch (SecurityException ex) { |
|
834 |
// Self-check was blocked by security manager. This is OK. |
|
835 |
// In fact the whole try body could be turned into an assertion. |
|
836 |
} |
|
837 |
try { |
|
838 |
MethodHandle init = IMPL_LOOKUP.findStatic(bcc, "init", MethodType.methodType(void.class)); |
|
839 |
init.invokeExact(); // force initialization of the class |
|
840 |
} catch (Throwable ex) { |
|
841 |
throw uncaughtException(ex); |
|
842 |
} |
|
843 |
MethodHandle bccInvoker; |
|
844 |
try { |
|
845 |
MethodType invokerMT = MethodType.methodType(Object.class, MethodHandle.class, Object[].class); |
|
846 |
bccInvoker = IMPL_LOOKUP.findStatic(bcc, "invoke_V", invokerMT); |
|
847 |
} catch (ReflectiveOperationException ex) { |
|
848 |
throw uncaughtException(ex); |
|
849 |
} |
|
850 |
// Test the invoker, to ensure that it really injects into the right place. |
|
851 |
try { |
|
852 |
MethodHandle vamh = prepareForInvoker(MH_checkCallerClass); |
|
853 |
Object ok = bccInvoker.invokeExact(vamh, new Object[]{hostClass, bcc}); |
|
854 |
} catch (Throwable ex) { |
|
855 |
throw new InternalError(ex); |
|
856 |
} |
|
857 |
return bccInvoker; |
|
858 |
} |
|
859 |
private static ClassValue<MethodHandle> CV_makeInjectedInvoker = new ClassValue<MethodHandle>() { |
|
860 |
@Override protected MethodHandle computeValue(Class<?> hostClass) { |
|
861 |
return makeInjectedInvoker(hostClass); |
|
862 |
} |
|
863 |
}; |
|
864 |
||
865 |
// Adapt mh so that it can be called directly from an injected invoker: |
|
866 |
private static MethodHandle prepareForInvoker(MethodHandle mh) { |
|
867 |
mh = mh.asFixedArity(); |
|
868 |
MethodType mt = mh.type(); |
|
869 |
int arity = mt.parameterCount(); |
|
870 |
MethodHandle vamh = mh.asType(mt.generic()); |
|
871 |
vamh.internalForm().compileToBytecode(); // eliminate LFI stack frames |
|
872 |
vamh = vamh.asSpreader(Object[].class, arity); |
|
873 |
vamh.internalForm().compileToBytecode(); // eliminate LFI stack frames |
|
874 |
return vamh; |
|
875 |
} |
|
876 |
||
877 |
// Undo the adapter effect of prepareForInvoker: |
|
20534
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
878 |
private static MethodHandle restoreToType(MethodHandle vamh, MethodType type, |
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
879 |
MemberName member, |
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
880 |
Class<?> hostClass) { |
19804 | 881 |
MethodHandle mh = vamh.asCollector(Object[].class, type.parameterCount()); |
882 |
mh = mh.asType(type); |
|
20534
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
883 |
mh = new WrappedMember(mh, type, member, hostClass); |
19804 | 884 |
return mh; |
14222 | 885 |
} |
886 |
||
887 |
private static final MethodHandle MH_checkCallerClass; |
|
888 |
static { |
|
889 |
final Class<?> THIS_CLASS = BindCaller.class; |
|
890 |
assert(checkCallerClass(THIS_CLASS, THIS_CLASS)); |
|
891 |
try { |
|
892 |
MH_checkCallerClass = IMPL_LOOKUP |
|
893 |
.findStatic(THIS_CLASS, "checkCallerClass", |
|
894 |
MethodType.methodType(boolean.class, Class.class, Class.class)); |
|
895 |
assert((boolean) MH_checkCallerClass.invokeExact(THIS_CLASS, THIS_CLASS)); |
|
896 |
} catch (Throwable ex) { |
|
897 |
throw new InternalError(ex); |
|
898 |
} |
|
899 |
} |
|
900 |
||
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16123
diff
changeset
|
901 |
@CallerSensitive |
14222 | 902 |
private static boolean checkCallerClass(Class<?> expected, Class<?> expected2) { |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16123
diff
changeset
|
903 |
// This method is called via MH_checkCallerClass and so it's |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16123
diff
changeset
|
904 |
// correct to ask for the immediate caller here. |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16123
diff
changeset
|
905 |
Class<?> actual = Reflection.getCallerClass(); |
14222 | 906 |
if (actual != expected && actual != expected2) |
907 |
throw new InternalError("found "+actual.getName()+", expected "+expected.getName() |
|
908 |
+(expected == expected2 ? "" : ", or else "+expected2.getName())); |
|
909 |
return true; |
|
910 |
} |
|
911 |
||
912 |
private static final byte[] T_BYTES; |
|
913 |
static { |
|
914 |
final Object[] values = {null}; |
|
915 |
AccessController.doPrivileged(new PrivilegedAction<Void>() { |
|
916 |
public Void run() { |
|
917 |
try { |
|
918 |
Class<T> tClass = T.class; |
|
919 |
String tName = tClass.getName(); |
|
920 |
String tResource = tName.substring(tName.lastIndexOf('.')+1)+".class"; |
|
921 |
java.net.URLConnection uconn = tClass.getResource(tResource).openConnection(); |
|
922 |
int len = uconn.getContentLength(); |
|
923 |
byte[] bytes = new byte[len]; |
|
924 |
try (java.io.InputStream str = uconn.getInputStream()) { |
|
925 |
int nr = str.read(bytes); |
|
926 |
if (nr != len) throw new java.io.IOException(tResource); |
|
927 |
} |
|
928 |
values[0] = bytes; |
|
929 |
} catch (java.io.IOException ex) { |
|
930 |
throw new InternalError(ex); |
|
931 |
} |
|
932 |
return null; |
|
933 |
} |
|
934 |
}); |
|
935 |
T_BYTES = (byte[]) values[0]; |
|
936 |
} |
|
937 |
||
938 |
// The following class is used as a template for Unsafe.defineAnonymousClass: |
|
939 |
private static class T { |
|
940 |
static void init() { } // side effect: initializes this class |
|
941 |
static Object invoke_V(MethodHandle vamh, Object[] args) throws Throwable { |
|
942 |
return vamh.invokeExact(args); |
|
943 |
} |
|
944 |
} |
|
945 |
} |
|
19804 | 946 |
|
947 |
||
948 |
/** This subclass allows a wrapped method handle to be re-associated with an arbitrary member name. */ |
|
949 |
static class WrappedMember extends MethodHandle { |
|
950 |
private final MethodHandle target; |
|
951 |
private final MemberName member; |
|
20534
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
952 |
private final Class<?> callerClass; |
19804 | 953 |
|
20534
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
954 |
private WrappedMember(MethodHandle target, MethodType type, MemberName member, Class<?> callerClass) { |
19804 | 955 |
super(type, reinvokerForm(target)); |
956 |
this.target = target; |
|
957 |
this.member = member; |
|
20534
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
958 |
this.callerClass = callerClass; |
19804 | 959 |
} |
960 |
||
961 |
@Override |
|
962 |
MethodHandle reinvokerTarget() { |
|
963 |
return target; |
|
964 |
} |
|
965 |
@Override |
|
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20495
diff
changeset
|
966 |
public MethodHandle asTypeUncached(MethodType newType) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20495
diff
changeset
|
967 |
// This MH is an alias for target, except for the MemberName |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20495
diff
changeset
|
968 |
// Drop the MemberName if there is any conversion. |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20495
diff
changeset
|
969 |
return asTypeCache = target.asType(newType); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20495
diff
changeset
|
970 |
} |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20495
diff
changeset
|
971 |
@Override |
19804 | 972 |
MemberName internalMemberName() { |
973 |
return member; |
|
974 |
} |
|
975 |
@Override |
|
20534
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
976 |
Class<?> internalCallerClass() { |
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
977 |
return callerClass; |
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
978 |
} |
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
979 |
@Override |
19804 | 980 |
boolean isInvokeSpecial() { |
981 |
return target.isInvokeSpecial(); |
|
982 |
} |
|
983 |
@Override |
|
984 |
MethodHandle viewAsType(MethodType newType) { |
|
20534
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
985 |
return new WrappedMember(target, newType, member, callerClass); |
19804 | 986 |
} |
987 |
} |
|
988 |
||
989 |
static MethodHandle makeWrappedMember(MethodHandle target, MemberName member) { |
|
990 |
if (member.equals(target.internalMemberName())) |
|
991 |
return target; |
|
20534
da86f7904e6d
8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents:
20530
diff
changeset
|
992 |
return new WrappedMember(target, target.type(), member, null); |
19804 | 993 |
} |
994 |
||
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
995 |
} |