author | jrose |
Tue, 17 May 2011 19:48:14 -0700 | |
changeset 9730 | e4b334d47f4b |
parent 9646 | 5ebbe5ab084f |
child 9752 | 88ab34b6da6d |
permissions | -rw-r--r-- |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1 |
/* |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
2 |
* Copyright (c) 2008, 2011, 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.AccessibleObject; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
30 |
import java.lang.reflect.Field; |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
31 |
import static java.lang.invoke.MethodHandleNatives.Constants.*; |
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. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
36 |
* This is an interface internal and private to an implemetantion of JSR 292. |
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 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
44 |
/// MethodName support |
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); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
48 |
static native void resolve(MemberName self, Class<?> caller); |
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 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
52 |
/// MethodHandle support |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
53 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
54 |
/** Initialize the method handle to adapt the call. */ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
55 |
static native void init(AdapterMethodHandle self, MethodHandle target, int argnum); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
56 |
/** Initialize the method handle to call the correct method, directly. */ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
57 |
static native void init(BoundMethodHandle self, Object target, int argnum); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
58 |
/** Initialize the method handle to call as if by an invoke* instruction. */ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
59 |
static native void init(DirectMethodHandle self, Object ref, boolean doDispatch, Class<?> caller); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
60 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
61 |
/** Initialize a method type, once per form. */ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
62 |
static native void init(MethodType self); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
63 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
64 |
/** Tell the JVM about a class's bootstrap method. */ |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
65 |
static native void registerBootstrap(Class<?> caller, MethodHandle bootstrapMethod); |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
66 |
|
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
67 |
/** Ask the JVM about a class's bootstrap method. */ |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
68 |
static native MethodHandle getBootstrap(Class<?> caller); |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
69 |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
70 |
/** Tell the JVM that we need to change the target of an invokedynamic. */ |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
71 |
static native void setCallSiteTarget(CallSite site, MethodHandle target); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
72 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
73 |
/** Fetch the vmtarget field. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
74 |
* It will be sanitized as necessary to avoid exposing non-Java references. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
75 |
* This routine is for debugging and reflection. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
76 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
77 |
static native Object getTarget(MethodHandle self, int format); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
78 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
79 |
/** Fetch the name of the handled method, if available. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
80 |
* This routine is for debugging and reflection. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
81 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
82 |
static MemberName getMethodName(MethodHandle self) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
83 |
return (MemberName) getTarget(self, ETF_METHOD_NAME); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
84 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
85 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
86 |
/** Fetch the reflective version of the handled method, if available. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
87 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
88 |
static AccessibleObject getTargetMethod(MethodHandle self) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
89 |
return (AccessibleObject) getTarget(self, ETF_REFLECT_METHOD); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
90 |
} |
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 |
/** Fetch the target of this method handle. |
4537 | 93 |
* If it directly targets a method, return a MemberName for the method. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
94 |
* If it is chained to another method handle, return that handle. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
95 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
96 |
static Object getTargetInfo(MethodHandle self) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
97 |
return getTarget(self, ETF_HANDLE_OR_METHOD_NAME); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
98 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
99 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
100 |
static Object[] makeTarget(Class<?> defc, String name, String sig, int mods, Class<?> refc) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
101 |
return new Object[] { defc, name, sig, mods, refc }; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
102 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
103 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
104 |
/** Fetch MH-related JVM parameter. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
105 |
* which=0 retrieves MethodHandlePushLimit |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
106 |
* 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
|
107 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
108 |
static native int getConstant(int which); |
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 |
/** Java copy of MethodHandlePushLimit in range 2..255. */ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
111 |
static final int JVM_PUSH_LIMIT; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
112 |
/** JVM stack motion (in words) after one slot is pushed, usually -1. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
113 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
114 |
static final int JVM_STACK_MOVE_UNIT; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
115 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
116 |
/** Which conv-ops are implemented by the JVM? */ |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
117 |
static final int CONV_OP_IMPLEMENTED_MASK; |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
118 |
/** Derived mode flag. Only false on some old JVM implementations. */ |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
119 |
static final boolean HAVE_RICOCHET_FRAMES; |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
120 |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
121 |
private static native void registerNatives(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
122 |
static { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
123 |
int JVM_PUSH_LIMIT_; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
124 |
int JVM_STACK_MOVE_UNIT_; |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
125 |
int CONV_OP_IMPLEMENTED_MASK_; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
126 |
try { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
127 |
registerNatives(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
128 |
JVM_PUSH_LIMIT_ = getConstant(Constants.GC_JVM_PUSH_LIMIT); |
4537 | 129 |
JVM_STACK_MOVE_UNIT_ = getConstant(Constants.GC_JVM_STACK_MOVE_UNIT); |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
130 |
CONV_OP_IMPLEMENTED_MASK_ = getConstant(Constants.GC_CONV_OP_IMPLEMENTED_MASK); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
131 |
//sun.reflect.Reflection.registerMethodsToFilter(MethodHandleImpl.class, "init"); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
132 |
} catch (UnsatisfiedLinkError ee) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
133 |
// ignore; if we use init() methods later we'll see linkage errors |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
134 |
JVM_PUSH_LIMIT_ = 3; // arbitrary |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
135 |
JVM_STACK_MOVE_UNIT_ = -1; // arbitrary |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
136 |
CONV_OP_IMPLEMENTED_MASK_ = 0; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
137 |
JVM_PUSH_LIMIT = JVM_PUSH_LIMIT_; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
138 |
JVM_STACK_MOVE_UNIT = JVM_STACK_MOVE_UNIT_; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
139 |
throw ee; // just die; hopeless to try to run with an older JVM |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
140 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
141 |
JVM_PUSH_LIMIT = JVM_PUSH_LIMIT_; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
142 |
JVM_STACK_MOVE_UNIT = JVM_STACK_MOVE_UNIT_; |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
143 |
if (CONV_OP_IMPLEMENTED_MASK_ == 0) |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
144 |
CONV_OP_IMPLEMENTED_MASK_ = DEFAULT_CONV_OP_IMPLEMENTED_MASK; |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
145 |
CONV_OP_IMPLEMENTED_MASK = CONV_OP_IMPLEMENTED_MASK_; |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
146 |
HAVE_RICOCHET_FRAMES = (CONV_OP_IMPLEMENTED_MASK & (1<<OP_COLLECT_ARGS)) != 0; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
147 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
148 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
149 |
// All compile-time constants go here. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
150 |
// 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
|
151 |
static class Constants { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
152 |
Constants() { } // static only |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
153 |
// MethodHandleImpl |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
154 |
static final int // for getConstant |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
155 |
GC_JVM_PUSH_LIMIT = 0, |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
156 |
GC_JVM_STACK_MOVE_UNIT = 1, |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
157 |
GC_CONV_OP_IMPLEMENTED_MASK = 2; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
158 |
static final int |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
159 |
ETF_HANDLE_OR_METHOD_NAME = 0, // all available data (immediate MH or method) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
160 |
ETF_DIRECT_HANDLE = 1, // ultimate method handle (will be a DMH, may be self) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
161 |
ETF_METHOD_NAME = 2, // ultimate method as MemberName |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
162 |
ETF_REFLECT_METHOD = 3; // ultimate method as java.lang.reflect object (sans refClass) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
163 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
164 |
// MemberName |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
165 |
// 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
|
166 |
// Field values are simple positive offsets. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
167 |
// Ref: src/share/vm/oops/methodOop.hpp |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
168 |
// This value is negative enough to avoid such numbers, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
169 |
// but not too negative. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
170 |
static final int |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
171 |
MN_IS_METHOD = 0x00010000, // method (not constructor) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
172 |
MN_IS_CONSTRUCTOR = 0x00020000, // constructor |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
173 |
MN_IS_FIELD = 0x00040000, // field |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
174 |
MN_IS_TYPE = 0x00080000, // nested type |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
175 |
MN_SEARCH_SUPERCLASSES = 0x00100000, // for MHN.getMembers |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
176 |
MN_SEARCH_INTERFACES = 0x00200000, // for MHN.getMembers |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
177 |
VM_INDEX_UNINITIALIZED = -99; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
178 |
|
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
179 |
// BoundMethodHandle |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
180 |
/** Constants for decoding the vmargslot field, which contains 2 values. */ |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
181 |
static final int |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
182 |
ARG_SLOT_PUSH_SHIFT = 16, |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
183 |
ARG_SLOT_MASK = (1<<ARG_SLOT_PUSH_SHIFT)-1; |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
184 |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
185 |
// AdapterMethodHandle |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
186 |
/** Conversions recognized by the JVM. |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
187 |
* They must align with the constants in java.lang.invoke.AdapterMethodHandle, |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
188 |
* in the JVM file hotspot/src/share/vm/classfile/javaClasses.hpp. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
189 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
190 |
static final int |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
191 |
OP_RETYPE_ONLY = 0x0, // no argument changes; straight retype |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
192 |
OP_RETYPE_RAW = 0x1, // straight retype, trusted (void->int, Object->T) |
4537 | 193 |
OP_CHECK_CAST = 0x2, // ref-to-ref conversion; requires a Class argument |
194 |
OP_PRIM_TO_PRIM = 0x3, // converts from one primitive to another |
|
195 |
OP_REF_TO_PRIM = 0x4, // unboxes a wrapper to produce a primitive |
|
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
196 |
OP_PRIM_TO_REF = 0x5, // boxes a primitive into a wrapper |
4537 | 197 |
OP_SWAP_ARGS = 0x6, // swap arguments (vminfo is 2nd arg) |
198 |
OP_ROT_ARGS = 0x7, // rotate arguments (vminfo is displaced arg) |
|
199 |
OP_DUP_ARGS = 0x8, // duplicates one or more arguments (at TOS) |
|
200 |
OP_DROP_ARGS = 0x9, // remove one or more argument slots |
|
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
201 |
OP_COLLECT_ARGS = 0xA, // combine arguments using an auxiliary function |
4537 | 202 |
OP_SPREAD_ARGS = 0xB, // expand in place a varargs array (of known size) |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
203 |
OP_FOLD_ARGS = 0xC, // combine but do not remove arguments; prepend result |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
204 |
//OP_UNUSED_13 = 0xD, // unused code, perhaps for reified argument lists |
4537 | 205 |
CONV_OP_LIMIT = 0xE; // limit of CONV_OP enumeration |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
206 |
/** Shift and mask values for decoding the AMH.conversion field. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
207 |
* These numbers are shared with the JVM for creating AMHs. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
208 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
209 |
static final int |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
210 |
CONV_OP_MASK = 0xF00, // this nybble contains the conversion op field |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
211 |
CONV_TYPE_MASK = 0x0F, // fits T_ADDRESS and below |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
212 |
CONV_VMINFO_MASK = 0x0FF, // LSB is reserved for JVM use |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
213 |
CONV_VMINFO_SHIFT = 0, // position of bits in CONV_VMINFO_MASK |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
214 |
CONV_OP_SHIFT = 8, // position of bits in CONV_OP_MASK |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
215 |
CONV_DEST_TYPE_SHIFT = 12, // byte 2 has the adapter BasicType (if needed) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
216 |
CONV_SRC_TYPE_SHIFT = 16, // byte 2 has the source BasicType (if needed) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
217 |
CONV_STACK_MOVE_SHIFT = 20, // high 12 bits give signed SP change |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
218 |
CONV_STACK_MOVE_MASK = (1 << (32 - CONV_STACK_MOVE_SHIFT)) - 1; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
219 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
220 |
/** Which conv-ops are implemented by the JVM? */ |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
221 |
static final int DEFAULT_CONV_OP_IMPLEMENTED_MASK = |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
222 |
// Value to use if the corresponding JVM query fails. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
223 |
((1<<OP_RETYPE_ONLY) |
4537 | 224 |
|(1<<OP_RETYPE_RAW) |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
225 |
|(1<<OP_CHECK_CAST) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
226 |
|(1<<OP_PRIM_TO_PRIM) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
227 |
|(1<<OP_REF_TO_PRIM) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
228 |
|(1<<OP_SWAP_ARGS) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
229 |
|(1<<OP_ROT_ARGS) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
230 |
|(1<<OP_DUP_ARGS) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
231 |
|(1<<OP_DROP_ARGS) |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
232 |
//|(1<<OP_SPREAD_ARGS) |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
233 |
); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
234 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
235 |
/** |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
236 |
* 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
|
237 |
* 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
|
238 |
* a private interface between the JVM and this class. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
239 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
240 |
static final int |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
241 |
T_BOOLEAN = 4, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
242 |
T_CHAR = 5, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
243 |
T_FLOAT = 6, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
244 |
T_DOUBLE = 7, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
245 |
T_BYTE = 8, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
246 |
T_SHORT = 9, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
247 |
T_INT = 10, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
248 |
T_LONG = 11, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
249 |
T_OBJECT = 12, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
250 |
//T_ARRAY = 13 |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
251 |
T_VOID = 14, |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
252 |
//T_ADDRESS = 15 |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
253 |
T_ILLEGAL = 99; |
5726 | 254 |
|
255 |
/** |
|
256 |
* Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries. |
|
257 |
*/ |
|
258 |
static final int |
|
259 |
REF_getField = 1, |
|
260 |
REF_getStatic = 2, |
|
261 |
REF_putField = 3, |
|
262 |
REF_putStatic = 4, |
|
263 |
REF_invokeVirtual = 5, |
|
264 |
REF_invokeStatic = 6, |
|
265 |
REF_invokeSpecial = 7, |
|
266 |
REF_newInvokeSpecial = 8, |
|
267 |
REF_invokeInterface = 9; |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
268 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
269 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
270 |
private static native int getNamedCon(int which, Object[] name); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
271 |
static boolean verifyConstants() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
272 |
Object[] box = { null }; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
273 |
for (int i = 0; ; i++) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
274 |
box[0] = null; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
275 |
int vmval = getNamedCon(i, box); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
276 |
if (box[0] == null) break; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
277 |
String name = (String) box[0]; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
278 |
try { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
279 |
Field con = Constants.class.getDeclaredField(name); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
280 |
int jval = con.getInt(null); |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
281 |
if (jval == vmval) continue; |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
282 |
String err = (name+": JVM has "+vmval+" while Java has "+jval); |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
283 |
if (name.equals("CONV_OP_LIMIT")) { |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
284 |
System.err.println("warning: "+err); |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
285 |
continue; |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
286 |
} |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
287 |
throw new InternalError(err); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
288 |
} catch (Exception ex) { |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
289 |
if (ex instanceof NoSuchFieldException) { |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
290 |
String err = (name+": JVM has "+vmval+" which Java does not define"); |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
291 |
// ignore exotic ops the JVM cares about; we just wont issue them |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
292 |
if (name.startsWith("OP_") || name.startsWith("GC_")) { |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
293 |
System.err.println("warning: "+err); |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
294 |
continue; |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
295 |
} |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
296 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
297 |
throw new InternalError(name+": access failed, got "+ex); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
298 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
299 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
300 |
return true; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
301 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
302 |
static { |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
303 |
assert(verifyConstants()); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
304 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
305 |
|
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
306 |
// Up-calls from the JVM. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
307 |
// These must NOT be public. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
308 |
|
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
309 |
/** |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
310 |
* 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
|
311 |
*/ |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
312 |
static CallSite makeDynamicCallSite(MethodHandle bootstrapMethod, |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
313 |
String name, MethodType type, |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
314 |
Object info, |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
315 |
MemberName callerMethod, int callerBCI) { |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
316 |
return CallSite.makeSite(bootstrapMethod, name, type, info, callerMethod, callerBCI); |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
317 |
} |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
318 |
|
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
319 |
/** |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
320 |
* Called by the JVM to check the length of a spread array. |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
321 |
*/ |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
322 |
static void checkSpreadArgument(Object av, int n) { |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
323 |
MethodHandleStatics.checkSpreadArgument(av, n); |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
324 |
} |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
325 |
|
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
326 |
/** |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
327 |
* 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
|
328 |
*/ |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
329 |
static MethodType findMethodHandleType(Class<?> rtype, Class<?>[] ptypes) { |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
330 |
return MethodType.makeImpl(rtype, ptypes, true); |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
331 |
} |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
332 |
|
5726 | 333 |
/** |
9645
dabb5e4edc4c
7034977: JSR 292 MethodHandle.invokeGeneric should be renamed MethodHandle.invoke
jrose
parents:
8822
diff
changeset
|
334 |
* The JVM wants to use a MethodType with inexact invoke. Give the runtime fair warning. |
7554
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
335 |
*/ |
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
336 |
static void notifyGenericMethodType(MethodType type) { |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
337 |
type.form().notifyGenericMethodType(); |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
338 |
} |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
339 |
|
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
340 |
/** |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
341 |
* The JVM wants to raise an exception. Here's the path. |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
342 |
*/ |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
343 |
static void raiseException(int code, Object actual, Object required) { |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
344 |
String message = null; |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
345 |
switch (code) { |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
346 |
case 190: // arraylength |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
347 |
try { |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
348 |
String reqLength = ""; |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
349 |
if (required instanceof AdapterMethodHandle) { |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
350 |
int conv = ((AdapterMethodHandle)required).getConversion(); |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
351 |
int spChange = AdapterMethodHandle.extractStackMove(conv); |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
352 |
reqLength = " of length "+(spChange+1); |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
353 |
} |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
354 |
int actualLength = actual == null ? 0 : java.lang.reflect.Array.getLength(actual); |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
355 |
message = "required array"+reqLength+", but encountered wrong length "+actualLength; |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
356 |
break; |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
357 |
} catch (IllegalArgumentException ex) { |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
358 |
} |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
359 |
required = Object[].class; // should have been an array |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
360 |
code = 192; // checkcast |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
361 |
break; |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
362 |
} |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
363 |
// disregard the identity of the actual object, if it is not a class: |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
364 |
if (message == null) { |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
365 |
if (!(actual instanceof Class) && !(actual instanceof MethodType)) |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
366 |
actual = actual.getClass(); |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
367 |
if (actual != null) |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
368 |
message = "required "+required+" but encountered "+actual; |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
369 |
else |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
370 |
message = "required "+required; |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
371 |
} |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
372 |
switch (code) { |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
373 |
case 190: // arraylength |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
374 |
throw new ArrayIndexOutOfBoundsException(message); |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
375 |
case 50: //_aaload |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
376 |
throw new ClassCastException(message); |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
377 |
case 192: // checkcast |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
378 |
throw new ClassCastException(message); |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
379 |
default: |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
380 |
throw new InternalError("unexpected code "+code+": "+message); |
7554
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
381 |
} |
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
382 |
} |
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
383 |
|
8a0ad9757002
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
7052
diff
changeset
|
384 |
/** |
5726 | 385 |
* The JVM is resolving a CONSTANT_MethodHandle CP entry. And it wants our help. |
386 |
* It will make an up-call to this method. (Do not change the name or signature.) |
|
387 |
*/ |
|
388 |
static MethodHandle linkMethodHandleConstant(Class<?> callerClass, int refKind, |
|
389 |
Class<?> defc, String name, Object type) { |
|
7052
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
390 |
try { |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
391 |
Lookup lookup = IMPL_LOOKUP.in(callerClass); |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
392 |
switch (refKind) { |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
393 |
case REF_getField: return lookup.findGetter( defc, name, (Class<?>) type ); |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
394 |
case REF_getStatic: return lookup.findStaticGetter( defc, name, (Class<?>) type ); |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
395 |
case REF_putField: return lookup.findSetter( defc, name, (Class<?>) type ); |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
396 |
case REF_putStatic: return lookup.findStaticSetter( defc, name, (Class<?>) type ); |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
397 |
case REF_invokeVirtual: return lookup.findVirtual( defc, name, (MethodType) type ); |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
398 |
case REF_invokeStatic: return lookup.findStatic( defc, name, (MethodType) type ); |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
399 |
case REF_invokeSpecial: return lookup.findSpecial( defc, name, (MethodType) type, callerClass ); |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
400 |
case REF_newInvokeSpecial: return lookup.findConstructor( defc, (MethodType) type ); |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
401 |
case REF_invokeInterface: return lookup.findVirtual( defc, name, (MethodType) type ); |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
402 |
} |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
403 |
throw new IllegalArgumentException("bad MethodHandle constant "+name+" : "+type); |
8347
e5daa5772ffd
7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents:
7554
diff
changeset
|
404 |
} catch (ReflectiveOperationException ex) { |
7052
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
405 |
Error err = new IncompatibleClassChangeError(); |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
406 |
err.initCause(ex); |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5727
diff
changeset
|
407 |
throw err; |
5726 | 408 |
} |
409 |
} |
|
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
410 |
|
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
411 |
/** |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
412 |
* This assertion marks code which was written before ricochet frames were implemented. |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
413 |
* Such code will go away when the ports catch up. |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
414 |
*/ |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
415 |
static boolean workaroundWithoutRicochetFrames() { |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
416 |
assert(!HAVE_RICOCHET_FRAMES) : "this code should not be executed if `-XX:+UseRicochetFrames is enabled"; |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
417 |
return true; |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
418 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
419 |
} |