author | mchung |
Tue, 16 Apr 2013 21:39:52 -0700 | |
changeset 16906 | 44dfee24cb71 |
parent 16121 | 49db59536470 |
child 19804 | 83170920c07b |
permissions | -rw-r--r-- |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1 |
/* |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
2 |
* Copyright (c) 2008, 2012, 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 |
|
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
28 |
import java.lang.invoke.MethodHandles.Lookup; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
29 |
import java.lang.reflect.Field; |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
30 |
import static java.lang.invoke.MethodHandleNatives.Constants.*; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
31 |
import static java.lang.invoke.MethodHandleStatics.*; |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
32 |
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
|
33 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
34 |
/** |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
35 |
* The JVM interface for the method handles package is all here. |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16121
diff
changeset
|
36 |
* This is an interface internal and private to an implementation of JSR 292. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
37 |
* <em>This class is not part of the JSR 292 standard.</em> |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
38 |
* @author jrose |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
39 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
40 |
class MethodHandleNatives { |
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 |
private MethodHandleNatives() { } // static only |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
43 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
44 |
/// MemberName support |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
45 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
46 |
static native void init(MemberName self, Object ref); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
47 |
static native void expand(MemberName self); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
48 |
static native MemberName resolve(MemberName self, Class<?> caller) throws LinkageError; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
49 |
static native int getMembers(Class<?> defc, String matchName, String matchSig, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
50 |
int matchFlags, Class<?> caller, int skip, MemberName[] results); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
51 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
52 |
/// Field layout queries parallel to sun.misc.Unsafe: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
53 |
static native long objectFieldOffset(MemberName self); // e.g., returns vmindex |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
54 |
static native long staticFieldOffset(MemberName self); // e.g., returns vmindex |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
55 |
static native Object staticFieldBase(MemberName self); // e.g., returns clazz |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
56 |
static native Object getMemberVMInfo(MemberName self); // returns {vmindex,vmtarget} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
57 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
58 |
/// MethodHandle support |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
59 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
60 |
/** Fetch MH-related JVM parameter. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
61 |
* which=0 retrieves MethodHandlePushLimit |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
62 |
* which=1 retrieves stack slot push size (in address units) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
63 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
64 |
static native int getConstant(int which); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
65 |
|
10615 | 66 |
static final boolean COUNT_GWT; |
67 |
||
11006
734080358bec
7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents:
10615
diff
changeset
|
68 |
/// CallSite support |
734080358bec
7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents:
10615
diff
changeset
|
69 |
|
734080358bec
7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents:
10615
diff
changeset
|
70 |
/** Tell the JVM that we need to change the target of a CallSite. */ |
734080358bec
7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents:
10615
diff
changeset
|
71 |
static native void setCallSiteTargetNormal(CallSite site, MethodHandle target); |
734080358bec
7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents:
10615
diff
changeset
|
72 |
static native void setCallSiteTargetVolatile(CallSite site, MethodHandle target); |
734080358bec
7085860: JSR 292: implement CallSite.setTargetNormal and setTargetVolatile as native methods
twisti
parents:
10615
diff
changeset
|
73 |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
74 |
private static native void registerNatives(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
75 |
static { |
9859
47e26ad535c4
7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents:
9780
diff
changeset
|
76 |
registerNatives(); |
10615 | 77 |
COUNT_GWT = getConstant(Constants.GC_COUNT_GWT) != 0; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
78 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
79 |
// The JVM calls MethodHandleNatives.<clinit>. Cascade the <clinit> calls as needed: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
80 |
MethodHandleImpl.initStatics(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
81 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
82 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
83 |
// All compile-time constants go here. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
84 |
// There is an opportunity to check them against the JVM's idea of them. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
85 |
static class Constants { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
86 |
Constants() { } // static only |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
87 |
// MethodHandleImpl |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
88 |
static final int // for getConstant |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
89 |
GC_COUNT_GWT = 4, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
90 |
GC_LAMBDA_SUPPORT = 5; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
91 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
92 |
// MemberName |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
93 |
// The JVM uses values of -2 and above for vtable indexes. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
94 |
// Field values are simple positive offsets. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
95 |
// Ref: src/share/vm/oops/methodOop.hpp |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
96 |
// This value is negative enough to avoid such numbers, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
97 |
// but not too negative. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
98 |
static final int |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
99 |
MN_IS_METHOD = 0x00010000, // method (not constructor) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
100 |
MN_IS_CONSTRUCTOR = 0x00020000, // constructor |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
101 |
MN_IS_FIELD = 0x00040000, // field |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
102 |
MN_IS_TYPE = 0x00080000, // nested type |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16121
diff
changeset
|
103 |
MN_CALLER_SENSITIVE = 0x00100000, // @CallerSensitive annotation detected |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
104 |
MN_REFERENCE_KIND_SHIFT = 24, // refKind |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
105 |
MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
106 |
// The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
107 |
MN_SEARCH_SUPERCLASSES = 0x00100000, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
108 |
MN_SEARCH_INTERFACES = 0x00200000; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
109 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
110 |
/** |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
111 |
* Basic types as encoded in the JVM. These code values are not |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
112 |
* intended for use outside this class. They are used as part of |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
113 |
* a private interface between the JVM and this class. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
114 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
115 |
static final int |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
116 |
T_BOOLEAN = 4, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
117 |
T_CHAR = 5, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
118 |
T_FLOAT = 6, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
119 |
T_DOUBLE = 7, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
120 |
T_BYTE = 8, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
121 |
T_SHORT = 9, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
122 |
T_INT = 10, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
123 |
T_LONG = 11, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
124 |
T_OBJECT = 12, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
125 |
//T_ARRAY = 13 |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
126 |
T_VOID = 14, |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
127 |
//T_ADDRESS = 15 |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
128 |
T_ILLEGAL = 99; |
5726 | 129 |
|
130 |
/** |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
131 |
* Constant pool entry types. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
132 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
133 |
static final byte |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
134 |
CONSTANT_Utf8 = 1, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
135 |
CONSTANT_Integer = 3, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
136 |
CONSTANT_Float = 4, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
137 |
CONSTANT_Long = 5, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
138 |
CONSTANT_Double = 6, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
139 |
CONSTANT_Class = 7, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
140 |
CONSTANT_String = 8, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
141 |
CONSTANT_Fieldref = 9, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
142 |
CONSTANT_Methodref = 10, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
143 |
CONSTANT_InterfaceMethodref = 11, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
144 |
CONSTANT_NameAndType = 12, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
145 |
CONSTANT_MethodHandle = 15, // JSR 292 |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
146 |
CONSTANT_MethodType = 16, // JSR 292 |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
147 |
CONSTANT_InvokeDynamic = 18, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
148 |
CONSTANT_LIMIT = 19; // Limit to tags found in classfiles |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
149 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
150 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
151 |
* Access modifier flags. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
152 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
153 |
static final char |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
154 |
ACC_PUBLIC = 0x0001, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
155 |
ACC_PRIVATE = 0x0002, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
156 |
ACC_PROTECTED = 0x0004, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
157 |
ACC_STATIC = 0x0008, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
158 |
ACC_FINAL = 0x0010, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
159 |
ACC_SYNCHRONIZED = 0x0020, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
160 |
ACC_VOLATILE = 0x0040, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
161 |
ACC_TRANSIENT = 0x0080, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
162 |
ACC_NATIVE = 0x0100, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
163 |
ACC_INTERFACE = 0x0200, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
164 |
ACC_ABSTRACT = 0x0400, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
165 |
ACC_STRICT = 0x0800, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
166 |
ACC_SYNTHETIC = 0x1000, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
167 |
ACC_ANNOTATION = 0x2000, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
168 |
ACC_ENUM = 0x4000, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
169 |
// aliases: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
170 |
ACC_SUPER = ACC_SYNCHRONIZED, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
171 |
ACC_BRIDGE = ACC_VOLATILE, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
172 |
ACC_VARARGS = ACC_TRANSIENT; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
173 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
174 |
/** |
5726 | 175 |
* Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries. |
176 |
*/ |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
177 |
static final byte |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
178 |
REF_NONE = 0, // null value |
5726 | 179 |
REF_getField = 1, |
180 |
REF_getStatic = 2, |
|
181 |
REF_putField = 3, |
|
182 |
REF_putStatic = 4, |
|
183 |
REF_invokeVirtual = 5, |
|
184 |
REF_invokeStatic = 6, |
|
185 |
REF_invokeSpecial = 7, |
|
186 |
REF_newInvokeSpecial = 8, |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
187 |
REF_invokeInterface = 9, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
188 |
REF_LIMIT = 10; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
189 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
190 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
191 |
static boolean refKindIsValid(int refKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
192 |
return (refKind > REF_NONE && refKind < REF_LIMIT); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
193 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
194 |
static boolean refKindIsField(byte refKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
195 |
assert(refKindIsValid(refKind)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
196 |
return (refKind <= REF_putStatic); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
197 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
198 |
static boolean refKindIsGetter(byte refKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
199 |
assert(refKindIsValid(refKind)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
200 |
return (refKind <= REF_getStatic); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
201 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
202 |
static boolean refKindIsSetter(byte refKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
203 |
return refKindIsField(refKind) && !refKindIsGetter(refKind); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
204 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
205 |
static boolean refKindIsMethod(byte refKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
206 |
return !refKindIsField(refKind) && (refKind != REF_newInvokeSpecial); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
207 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
208 |
static boolean refKindHasReceiver(byte refKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
209 |
assert(refKindIsValid(refKind)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
210 |
return (refKind & 1) != 0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
211 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
212 |
static boolean refKindIsStatic(byte refKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
213 |
return !refKindHasReceiver(refKind) && (refKind != REF_newInvokeSpecial); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
214 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
215 |
static boolean refKindDoesDispatch(byte refKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
216 |
assert(refKindIsValid(refKind)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
217 |
return (refKind == REF_invokeVirtual || |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
218 |
refKind == REF_invokeInterface); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
219 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
220 |
static { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
221 |
final int HR_MASK = ((1 << REF_getField) | |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
222 |
(1 << REF_putField) | |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
223 |
(1 << REF_invokeVirtual) | |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
224 |
(1 << REF_invokeSpecial) | |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
225 |
(1 << REF_invokeInterface) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
226 |
); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
227 |
for (byte refKind = REF_NONE+1; refKind < REF_LIMIT; refKind++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
228 |
assert(refKindHasReceiver(refKind) == (((1<<refKind) & HR_MASK) != 0)) : refKind; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
229 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
230 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
231 |
static String refKindName(byte refKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
232 |
assert(refKindIsValid(refKind)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
233 |
return REFERENCE_KIND_NAME[refKind]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
234 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
235 |
private static String[] REFERENCE_KIND_NAME = { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
236 |
null, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
237 |
"getField", |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
238 |
"getStatic", |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
239 |
"putField", |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
240 |
"putStatic", |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
241 |
"invokeVirtual", |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
242 |
"invokeStatic", |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
243 |
"invokeSpecial", |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
244 |
"newInvokeSpecial", |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
245 |
"invokeInterface" |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
246 |
}; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
247 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
248 |
private static native int getNamedCon(int which, Object[] name); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
249 |
static boolean verifyConstants() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
250 |
Object[] box = { null }; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
251 |
for (int i = 0; ; i++) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
252 |
box[0] = null; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
253 |
int vmval = getNamedCon(i, box); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
254 |
if (box[0] == null) break; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
255 |
String name = (String) box[0]; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
256 |
try { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
257 |
Field con = Constants.class.getDeclaredField(name); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
258 |
int jval = con.getInt(null); |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
259 |
if (jval == vmval) continue; |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
260 |
String err = (name+": JVM has "+vmval+" while Java has "+jval); |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
261 |
if (name.equals("CONV_OP_LIMIT")) { |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
262 |
System.err.println("warning: "+err); |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
263 |
continue; |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
264 |
} |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
265 |
throw new InternalError(err); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
266 |
} catch (NoSuchFieldException | IllegalAccessException ex) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
267 |
String err = (name+": JVM has "+vmval+" which Java does not define"); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
268 |
// ignore exotic ops the JVM cares about; we just wont issue them |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
269 |
//System.err.println("warning: "+err); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
270 |
continue; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
271 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
272 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
273 |
return true; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
274 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
275 |
static { |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
276 |
assert(verifyConstants()); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
277 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
278 |
|
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
279 |
// Up-calls from the JVM. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
280 |
// These must NOT be public. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
281 |
|
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
282 |
/** |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
283 |
* The JVM is linking an invokedynamic instruction. Create a reified call site for it. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
284 |
*/ |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
285 |
static MemberName linkCallSite(Object callerObj, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
286 |
Object bootstrapMethodObj, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
287 |
Object nameObj, Object typeObj, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
288 |
Object staticArguments, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
289 |
Object[] appendixResult) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
290 |
MethodHandle bootstrapMethod = (MethodHandle)bootstrapMethodObj; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
291 |
Class<?> caller = (Class<?>)callerObj; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
292 |
String name = nameObj.toString().intern(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
293 |
MethodType type = (MethodType)typeObj; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
294 |
appendixResult[0] = CallSite.makeSite(bootstrapMethod, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
295 |
name, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
296 |
type, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
297 |
staticArguments, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
298 |
caller); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
299 |
return Invokers.linkToCallSiteMethod(type); |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
300 |
} |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
301 |
|
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
302 |
/** |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
303 |
* The JVM wants a pointer to a MethodType. Oblige it by finding or creating one. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
304 |
*/ |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
305 |
static MethodType findMethodHandleType(Class<?> rtype, Class<?>[] ptypes) { |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
306 |
return MethodType.makeImpl(rtype, ptypes, true); |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
307 |
} |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
308 |
|
5726 | 309 |
/** |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
310 |
* The JVM wants to link a call site that requires a dynamic type check. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
311 |
* Name is a type-checking invoker, invokeExact or invoke. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
312 |
* Return a JVM method (MemberName) to handle the invoking. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
313 |
* The method assumes the following arguments on the stack: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
314 |
* 0: the method handle being invoked |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
315 |
* 1-N: the arguments to the method handle invocation |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
316 |
* N+1: an implicitly added type argument (the given MethodType) |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
317 |
*/ |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
318 |
static MemberName linkMethod(Class<?> callerClass, int refKind, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
319 |
Class<?> defc, String name, Object type, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
320 |
Object[] appendixResult) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
321 |
if (!TRACE_METHOD_LINKAGE) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
322 |
return linkMethodImpl(callerClass, refKind, defc, name, type, appendixResult); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
323 |
return linkMethodTracing(callerClass, refKind, defc, name, type, appendixResult); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
324 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
325 |
static MemberName linkMethodImpl(Class<?> callerClass, int refKind, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
326 |
Class<?> defc, String name, Object type, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
327 |
Object[] appendixResult) { |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
328 |
try { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
329 |
if (defc == MethodHandle.class && refKind == REF_invokeVirtual) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
330 |
switch (name) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
331 |
case "invoke": |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
332 |
return Invokers.genericInvokerMethod(fixMethodType(callerClass, type), appendixResult); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
333 |
case "invokeExact": |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
334 |
return Invokers.exactInvokerMethod(fixMethodType(callerClass, type), appendixResult); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
335 |
} |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
336 |
} |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
337 |
} catch (Throwable ex) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
338 |
if (ex instanceof LinkageError) |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
339 |
throw (LinkageError) ex; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
340 |
else |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
341 |
throw new LinkageError(ex.getMessage(), ex); |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
342 |
} |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
343 |
throw new LinkageError("no such method "+defc.getName()+"."+name+type); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
344 |
} |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
345 |
private static MethodType fixMethodType(Class<?> callerClass, Object type) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
346 |
if (type instanceof MethodType) |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
347 |
return (MethodType) type; |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
348 |
else |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
349 |
return MethodType.fromMethodDescriptorString((String)type, callerClass.getClassLoader()); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
350 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
351 |
// Tracing logic: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
352 |
static MemberName linkMethodTracing(Class<?> callerClass, int refKind, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
353 |
Class<?> defc, String name, Object type, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
354 |
Object[] appendixResult) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
355 |
System.out.println("linkMethod "+defc.getName()+"."+ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
356 |
name+type+"/"+Integer.toHexString(refKind)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
357 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
358 |
MemberName res = linkMethodImpl(callerClass, refKind, defc, name, type, appendixResult); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
359 |
System.out.println("linkMethod => "+res+" + "+appendixResult[0]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
360 |
return res; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
361 |
} catch (Throwable ex) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
362 |
System.out.println("linkMethod => throw "+ex); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
363 |
throw ex; |
7554
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
364 |
} |
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
365 |
} |
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
366 |
|
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
367 |
|
7554
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
368 |
/** |
5726 | 369 |
* The JVM is resolving a CONSTANT_MethodHandle CP entry. And it wants our help. |
370 |
* It will make an up-call to this method. (Do not change the name or signature.) |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
371 |
* The type argument is a Class for field requests and a MethodType for non-fields. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
372 |
* <p> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
373 |
* Recent versions of the JVM may also pass a resolved MemberName for the type. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
374 |
* In that case, the name is ignored and may be null. |
5726 | 375 |
*/ |
376 |
static MethodHandle linkMethodHandleConstant(Class<?> callerClass, int refKind, |
|
377 |
Class<?> defc, String name, Object type) { |
|
7052
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
378 |
try { |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
379 |
Lookup lookup = IMPL_LOOKUP.in(callerClass); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
380 |
assert(refKindIsValid(refKind)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11006
diff
changeset
|
381 |
return lookup.linkMethodHandleConstant((byte) refKind, defc, name, type); |
8347
e5daa5772ffd
7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents:
7554
diff
changeset
|
382 |
} catch (ReflectiveOperationException ex) { |
7052
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
383 |
Error err = new IncompatibleClassChangeError(); |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
384 |
err.initCause(ex); |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
385 |
throw err; |
5726 | 386 |
} |
387 |
} |
|
14222 | 388 |
|
389 |
/** |
|
390 |
* Is this method a caller-sensitive method? |
|
391 |
* I.e., does it call Reflection.getCallerClass or a similer method |
|
392 |
* to ask about the identity of its caller? |
|
393 |
*/ |
|
394 |
static boolean isCallerSensitive(MemberName mem) { |
|
16118 | 395 |
if (!mem.isInvocable()) return false; // fields are not caller sensitive |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16121
diff
changeset
|
396 |
|
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16121
diff
changeset
|
397 |
return mem.isCallerSensitive() || canBeCalledVirtual(mem); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16121
diff
changeset
|
398 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16121
diff
changeset
|
399 |
|
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16121
diff
changeset
|
400 |
static boolean canBeCalledVirtual(MemberName mem) { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16121
diff
changeset
|
401 |
assert(mem.isInvocable()); |
14222 | 402 |
Class<?> defc = mem.getDeclaringClass(); |
403 |
switch (mem.getName()) { |
|
16118 | 404 |
case "checkMemberAccess": |
405 |
return canBeCalledVirtual(mem, java.lang.SecurityManager.class); |
|
14222 | 406 |
case "getContextClassLoader": |
16118 | 407 |
return canBeCalledVirtual(mem, java.lang.Thread.class); |
14222 | 408 |
} |
409 |
return false; |
|
410 |
} |
|
14679
e1fbc33baf51
8003851: MethodHandleNatives dependency on java.sql.DriverManager
mchung
parents:
14222
diff
changeset
|
411 |
|
16118 | 412 |
static boolean canBeCalledVirtual(MemberName symbolicRef, Class<?> definingClass) { |
413 |
Class<?> symbolicRefClass = symbolicRef.getDeclaringClass(); |
|
414 |
if (symbolicRefClass == definingClass) return true; |
|
415 |
if (symbolicRef.isStatic() || symbolicRef.isPrivate()) return false; |
|
416 |
return (definingClass.isAssignableFrom(symbolicRefClass) || // Msym overrides Mdef |
|
417 |
symbolicRefClass.isInterface()); // Mdef implements Msym |
|
418 |
} |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
419 |
} |