author | lana |
Thu, 13 Apr 2017 20:35:17 +0000 | |
changeset 44599 | 942f3546b679 |
parent 44545 | 83b611b88ac8 |
parent 44591 | b9bf065070fe |
child 46867 | dbe5f2bef304 |
permissions | -rw-r--r-- |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1 |
/* |
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
38774
diff
changeset
|
2 |
* Copyright (c) 2008, 2016, 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 sun.invoke.util.BytecodeDescriptor; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
29 |
import sun.invoke.util.VerifyAccess; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
30 |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
31 |
import java.lang.reflect.Constructor; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
32 |
import java.lang.reflect.Field; |
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
38774
diff
changeset
|
33 |
import java.lang.reflect.Member; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
34 |
import java.lang.reflect.Method; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
35 |
import java.lang.reflect.Modifier; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
36 |
import java.util.ArrayList; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
37 |
import java.util.Collections; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
38 |
import java.util.Iterator; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
39 |
import java.util.List; |
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
38774
diff
changeset
|
40 |
import java.util.Objects; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
38774
diff
changeset
|
41 |
|
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
42 |
import static java.lang.invoke.MethodHandleNatives.Constants.*; |
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
38774
diff
changeset
|
43 |
import static java.lang.invoke.MethodHandleStatics.newIllegalArgumentException; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
38774
diff
changeset
|
44 |
import static java.lang.invoke.MethodHandleStatics.newInternalError; |
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 |
/** |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
47 |
* A {@code MemberName} is a compact symbolic datum which fully characterizes |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
48 |
* a method or field reference. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
49 |
* A member name refers to a field, method, constructor, or member type. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
50 |
* Every member name has a simple name (a string) and a type (either a Class or MethodType). |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
51 |
* A member name may also have a non-null declaring class, or it may be simply |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
52 |
* a naked name/type pair. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
53 |
* A member name may also have non-zero modifier flags. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
54 |
* Finally, a member name may be either resolved or unresolved. |
38774 | 55 |
* If it is resolved, the existence of the named member has been determined by the JVM. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
56 |
* <p> |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
57 |
* Whether resolved or not, a member name provides no access rights or |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
58 |
* invocation capability to its possessor. It is merely a compact |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
59 |
* representation of all symbolic information necessary to link to |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
60 |
* and properly use the named member. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
61 |
* <p> |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
62 |
* When resolved, a member name's internal implementation may include references to JVM metadata. |
25979 | 63 |
* This representation is stateless and only descriptive. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
64 |
* It provides no private information and no capability to use the member. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
65 |
* <p> |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
66 |
* By contrast, a {@linkplain java.lang.reflect.Method} contains fuller information |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
67 |
* about the internals of a method (except its bytecodes) and also |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
68 |
* allows invocation. A MemberName is much lighter than a Method, |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
69 |
* since it contains about 7 fields to the 16 of Method (plus its sub-arrays), |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
70 |
* and those seven fields omit much of the information in Method. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
71 |
* @author jrose |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
72 |
*/ |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
73 |
/*non-public*/ final class MemberName implements Member, Cloneable { |
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
74 |
private Class<?> clazz; // class in which the method is defined |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
75 |
private String name; // may be null if not yet materialized |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
76 |
private Object type; // may be null if not yet materialized |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
77 |
private int flags; // modifier bits; see reflect.Modifier |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
78 |
//@Injected JVM_Method* vmtarget; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
79 |
//@Injected int vmindex; |
40272
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40258
diff
changeset
|
80 |
Object resolution; // if null, this guy is resolved |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
81 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
82 |
/** Return the declaring class of this member. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
83 |
* In the case of a bare name and type, the declaring class will be null. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
84 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
85 |
public Class<?> getDeclaringClass() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
86 |
return clazz; |
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 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
89 |
/** Utility method producing the class loader of the declaring class. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
90 |
public ClassLoader getClassLoader() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
91 |
return clazz.getClassLoader(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
92 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
93 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
94 |
/** Return the simple name of this member. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
95 |
* For a type, it is the same as {@link Class#getSimpleName}. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
96 |
* For a method or field, it is the simple name of the member. |
32276
2d5fcc89e099
8134356: {@code} tag contains < and > sequences
igerasim
parents:
29094
diff
changeset
|
97 |
* For a constructor, it is always {@code "<init>"}. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
98 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
99 |
public String getName() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
100 |
if (name == null) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
101 |
expandFromVM(); |
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
102 |
if (name == null) { |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
103 |
return null; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
104 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
105 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
106 |
return name; |
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 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
109 |
public MethodType getMethodOrFieldType() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
110 |
if (isInvocable()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
111 |
return getMethodType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
112 |
if (isGetter()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
113 |
return MethodType.methodType(getFieldType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
114 |
if (isSetter()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
115 |
return MethodType.methodType(void.class, getFieldType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
116 |
throw new InternalError("not a method or field: "+this); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
117 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
118 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
119 |
/** Return the declared type of this member, which |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
120 |
* must be a method or constructor. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
121 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
122 |
public MethodType getMethodType() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
123 |
if (type == null) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
124 |
expandFromVM(); |
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
125 |
if (type == null) { |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
126 |
return null; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
127 |
} |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
128 |
} |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
129 |
if (!isInvocable()) { |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
130 |
throw newIllegalArgumentException("not invocable, no method type"); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
131 |
} |
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
132 |
|
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
133 |
{ |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
134 |
// Get a snapshot of type which doesn't get changed by racing threads. |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
135 |
final Object type = this.type; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
136 |
if (type instanceof MethodType) { |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
137 |
return (MethodType) type; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
138 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
139 |
} |
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
140 |
|
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
141 |
// type is not a MethodType yet. Convert it thread-safely. |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
142 |
synchronized (this) { |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
143 |
if (type instanceof String) { |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
144 |
String sig = (String) type; |
32986
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32276
diff
changeset
|
145 |
MethodType res = MethodType.fromDescriptor(sig, getClassLoader()); |
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
146 |
type = res; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
147 |
} else if (type instanceof Object[]) { |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
148 |
Object[] typeInfo = (Object[]) type; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
149 |
Class<?>[] ptypes = (Class<?>[]) typeInfo[1]; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
150 |
Class<?> rtype = (Class<?>) typeInfo[0]; |
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
40272
diff
changeset
|
151 |
MethodType res = MethodType.makeImpl(rtype, ptypes, true); |
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
152 |
type = res; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
153 |
} |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
154 |
// Make sure type is a MethodType for racing threads. |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
155 |
assert type instanceof MethodType : "bad method type " + type; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
156 |
} |
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
157 |
return (MethodType) type; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
158 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
159 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
160 |
/** Return the actual type under which this method or constructor must be invoked. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
161 |
* For non-static methods or constructors, this is the type with a leading parameter, |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
162 |
* a reference to declaring class. For static methods, it is the same as the declared type. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
163 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
164 |
public MethodType getInvocationType() { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
165 |
MethodType itype = getMethodOrFieldType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
166 |
if (isConstructor() && getReferenceKind() == REF_newInvokeSpecial) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
167 |
return itype.changeReturnType(clazz); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
168 |
if (!isStatic()) |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
169 |
return itype.insertParameterTypes(0, clazz); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
170 |
return itype; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
171 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
172 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
173 |
/** Utility method producing the parameter types of the method type. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
174 |
public Class<?>[] getParameterTypes() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
175 |
return getMethodType().parameterArray(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
176 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
177 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
178 |
/** Utility method producing the return type of the method type. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
179 |
public Class<?> getReturnType() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
180 |
return getMethodType().returnType(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
181 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
182 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
183 |
/** Return the declared type of this member, which |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
184 |
* must be a field or type. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
185 |
* If it is a type member, that type itself is returned. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
186 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
187 |
public Class<?> getFieldType() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
188 |
if (type == null) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
189 |
expandFromVM(); |
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
190 |
if (type == null) { |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
191 |
return null; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
192 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
193 |
} |
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
194 |
if (isInvocable()) { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
195 |
throw newIllegalArgumentException("not a field or nested class, no simple type"); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
196 |
} |
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
197 |
|
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
198 |
{ |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
199 |
// Get a snapshot of type which doesn't get changed by racing threads. |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
200 |
final Object type = this.type; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
201 |
if (type instanceof Class<?>) { |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
202 |
return (Class<?>) type; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
203 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
204 |
} |
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
205 |
|
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
206 |
// type is not a Class yet. Convert it thread-safely. |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
207 |
synchronized (this) { |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
208 |
if (type instanceof String) { |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
209 |
String sig = (String) type; |
32986
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32276
diff
changeset
|
210 |
MethodType mtype = MethodType.fromDescriptor("()"+sig, getClassLoader()); |
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
211 |
Class<?> res = mtype.returnType(); |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
212 |
type = res; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
213 |
} |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
214 |
// Make sure type is a Class for racing threads. |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
215 |
assert type instanceof Class<?> : "bad field type " + type; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
216 |
} |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
217 |
return (Class<?>) type; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
218 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
219 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
220 |
/** Utility method to produce either the method type or field type of this member. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
221 |
public Object getType() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
222 |
return (isInvocable() ? getMethodType() : getFieldType()); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
223 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
224 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
225 |
/** Utility method to produce the signature of this member, |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
226 |
* used within the class file format to describe its type. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
227 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
228 |
public String getSignature() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
229 |
if (type == null) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
230 |
expandFromVM(); |
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
231 |
if (type == null) { |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
232 |
return null; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
233 |
} |
2707
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 |
if (isInvocable()) |
4537 | 236 |
return BytecodeDescriptor.unparse(getMethodType()); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
237 |
else |
4537 | 238 |
return BytecodeDescriptor.unparse(getFieldType()); |
2707
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 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
241 |
/** Return the modifier flags of this member. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
242 |
* @see java.lang.reflect.Modifier |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
243 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
244 |
public int getModifiers() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
245 |
return (flags & RECOGNIZED_MODIFIERS); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
246 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
247 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
248 |
/** Return the reference kind of this member, or zero if none. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
249 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
250 |
public byte getReferenceKind() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
251 |
return (byte) ((flags >>> MN_REFERENCE_KIND_SHIFT) & MN_REFERENCE_KIND_MASK); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
252 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
253 |
private boolean referenceKindIsConsistent() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
254 |
byte refKind = getReferenceKind(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
255 |
if (refKind == REF_NONE) return isType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
256 |
if (isField()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
257 |
assert(staticIsConsistent()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
258 |
assert(MethodHandleNatives.refKindIsField(refKind)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
259 |
} else if (isConstructor()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
260 |
assert(refKind == REF_newInvokeSpecial || refKind == REF_invokeSpecial); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
261 |
} else if (isMethod()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
262 |
assert(staticIsConsistent()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
263 |
assert(MethodHandleNatives.refKindIsMethod(refKind)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
264 |
if (clazz.isInterface()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
265 |
assert(refKind == REF_invokeInterface || |
17461
84860231159b
8008687: MethodHandle code: allow static and invokespecial calls to interface methods
bharadwaj
parents:
16906
diff
changeset
|
266 |
refKind == REF_invokeStatic || |
84860231159b
8008687: MethodHandle code: allow static and invokespecial calls to interface methods
bharadwaj
parents:
16906
diff
changeset
|
267 |
refKind == REF_invokeSpecial || |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
268 |
refKind == REF_invokeVirtual && isObjectPublicMethod()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
269 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
270 |
assert(false); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
271 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
272 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
273 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
274 |
private boolean isObjectPublicMethod() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
275 |
if (clazz == Object.class) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
276 |
MethodType mtype = getMethodType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
277 |
if (name.equals("toString") && mtype.returnType() == String.class && mtype.parameterCount() == 0) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
278 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
279 |
if (name.equals("hashCode") && mtype.returnType() == int.class && mtype.parameterCount() == 0) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
280 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
281 |
if (name.equals("equals") && mtype.returnType() == boolean.class && mtype.parameterCount() == 1 && mtype.parameterType(0) == Object.class) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
282 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
283 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
284 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
285 |
/*non-public*/ boolean referenceKindIsConsistentWith(int originalRefKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
286 |
int refKind = getReferenceKind(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
287 |
if (refKind == originalRefKind) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
288 |
switch (originalRefKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
289 |
case REF_invokeInterface: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
290 |
// Looking up an interface method, can get (e.g.) Object.hashCode |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
291 |
assert(refKind == REF_invokeVirtual || |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
292 |
refKind == REF_invokeSpecial) : this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
293 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
294 |
case REF_invokeVirtual: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
295 |
case REF_newInvokeSpecial: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
296 |
// Looked up a virtual, can get (e.g.) final String.hashCode. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
297 |
assert(refKind == REF_invokeSpecial) : this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
298 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
299 |
} |
17461
84860231159b
8008687: MethodHandle code: allow static and invokespecial calls to interface methods
bharadwaj
parents:
16906
diff
changeset
|
300 |
assert(false) : this+" != "+MethodHandleNatives.refKindName((byte)originalRefKind); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
301 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
302 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
303 |
private boolean staticIsConsistent() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
304 |
byte refKind = getReferenceKind(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
305 |
return MethodHandleNatives.refKindIsStatic(refKind) == isStatic() || getModifiers() == 0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
306 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
307 |
private boolean vminfoIsConsistent() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
308 |
byte refKind = getReferenceKind(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
309 |
assert(isResolved()); // else don't call |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
310 |
Object vminfo = MethodHandleNatives.getMemberVMInfo(this); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
311 |
assert(vminfo instanceof Object[]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
312 |
long vmindex = (Long) ((Object[])vminfo)[0]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
313 |
Object vmtarget = ((Object[])vminfo)[1]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
314 |
if (MethodHandleNatives.refKindIsField(refKind)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
315 |
assert(vmindex >= 0) : vmindex + ":" + this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
316 |
assert(vmtarget instanceof Class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
317 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
318 |
if (MethodHandleNatives.refKindDoesDispatch(refKind)) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
319 |
assert(vmindex >= 0) : vmindex + ":" + this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
320 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
321 |
assert(vmindex < 0) : vmindex; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
322 |
assert(vmtarget instanceof MemberName) : vmtarget + " in " + this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
323 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
324 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
325 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
326 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
327 |
private MemberName changeReferenceKind(byte refKind, byte oldKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
328 |
assert(getReferenceKind() == oldKind); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
329 |
assert(MethodHandleNatives.refKindIsValid(refKind)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
330 |
flags += (((int)refKind - oldKind) << MN_REFERENCE_KIND_SHIFT); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
331 |
return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
332 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
333 |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
334 |
private boolean testFlags(int mask, int value) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
335 |
return (flags & mask) == value; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
336 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
337 |
private boolean testAllFlags(int mask) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
338 |
return testFlags(mask, mask); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
339 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
340 |
private boolean testAnyFlags(int mask) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
341 |
return !testFlags(mask, 0); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
342 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
343 |
|
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25991
diff
changeset
|
344 |
/** Utility method to query if this member is a method handle invocation (invoke or invokeExact). |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25991
diff
changeset
|
345 |
*/ |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
346 |
public boolean isMethodHandleInvoke() { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25991
diff
changeset
|
347 |
final int bits = MH_INVOKE_MODS &~ Modifier.PUBLIC; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
348 |
final int negs = Modifier.STATIC; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
349 |
if (testFlags(bits | negs, bits) && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
350 |
clazz == MethodHandle.class) { |
19804 | 351 |
return isMethodHandleInvokeName(name); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
352 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
353 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
354 |
} |
19804 | 355 |
public static boolean isMethodHandleInvokeName(String name) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25991
diff
changeset
|
356 |
switch (name) { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25991
diff
changeset
|
357 |
case "invoke": |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25991
diff
changeset
|
358 |
case "invokeExact": |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25991
diff
changeset
|
359 |
return true; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25991
diff
changeset
|
360 |
default: |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25991
diff
changeset
|
361 |
return false; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25991
diff
changeset
|
362 |
} |
19804 | 363 |
} |
36934 | 364 |
public boolean isVarHandleMethodInvoke() { |
365 |
final int bits = MH_INVOKE_MODS &~ Modifier.PUBLIC; |
|
366 |
final int negs = Modifier.STATIC; |
|
367 |
if (testFlags(bits | negs, bits) && |
|
368 |
clazz == VarHandle.class) { |
|
369 |
return isVarHandleMethodInvokeName(name); |
|
370 |
} |
|
371 |
return false; |
|
372 |
} |
|
373 |
public static boolean isVarHandleMethodInvokeName(String name) { |
|
374 |
try { |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36935
diff
changeset
|
375 |
VarHandle.AccessMode.valueFromMethodName(name); |
36934 | 376 |
return true; |
377 |
} catch (IllegalArgumentException e) { |
|
378 |
return false; |
|
379 |
} |
|
380 |
} |
|
19804 | 381 |
private static final int MH_INVOKE_MODS = Modifier.NATIVE | Modifier.FINAL | Modifier.PUBLIC; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
382 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
383 |
/** Utility method to query the modifier flags of this member. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
384 |
public boolean isStatic() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
385 |
return Modifier.isStatic(flags); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
386 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
387 |
/** Utility method to query the modifier flags of this member. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
388 |
public boolean isPublic() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
389 |
return Modifier.isPublic(flags); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
390 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
391 |
/** Utility method to query the modifier flags of this member. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
392 |
public boolean isPrivate() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
393 |
return Modifier.isPrivate(flags); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
394 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
395 |
/** Utility method to query the modifier flags of this member. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
396 |
public boolean isProtected() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
397 |
return Modifier.isProtected(flags); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
398 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
399 |
/** Utility method to query the modifier flags of this member. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
400 |
public boolean isFinal() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
401 |
return Modifier.isFinal(flags); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
402 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
403 |
/** Utility method to query whether this member or its defining class is final. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
404 |
public boolean canBeStaticallyBound() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
405 |
return Modifier.isFinal(flags | clazz.getModifiers()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
406 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
407 |
/** Utility method to query the modifier flags of this member. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
408 |
public boolean isVolatile() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
409 |
return Modifier.isVolatile(flags); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
410 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
411 |
/** Utility method to query the modifier flags of this member. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
412 |
public boolean isAbstract() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
413 |
return Modifier.isAbstract(flags); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
414 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
415 |
/** Utility method to query the modifier flags of this member. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
416 |
public boolean isNative() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
417 |
return Modifier.isNative(flags); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
418 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
419 |
// let the rest (native, volatile, transient, etc.) be tested via Modifier.isFoo |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
420 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
421 |
// unofficial modifier flags, used by HotSpot: |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
422 |
static final int BRIDGE = 0x00000040; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
423 |
static final int VARARGS = 0x00000080; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
424 |
static final int SYNTHETIC = 0x00001000; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
425 |
static final int ANNOTATION= 0x00002000; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
426 |
static final int ENUM = 0x00004000; |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
427 |
/** Utility method to query the modifier flags of this member; returns false if the member is not a method. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
428 |
public boolean isBridge() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
429 |
return testAllFlags(IS_METHOD | BRIDGE); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
430 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
431 |
/** Utility method to query the modifier flags of this member; returns false if the member is not a method. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
432 |
public boolean isVarargs() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
433 |
return testAllFlags(VARARGS) && isInvocable(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
434 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
435 |
/** Utility method to query the modifier flags of this member; returns false if the member is not a method. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
436 |
public boolean isSynthetic() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
437 |
return testAllFlags(SYNTHETIC); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
438 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
439 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
440 |
static final String CONSTRUCTOR_NAME = "<init>"; // the ever-popular |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
441 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
442 |
// modifiers exported by the JVM: |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
443 |
static final int RECOGNIZED_MODIFIERS = 0xFFFF; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
444 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
445 |
// private flags, not part of RECOGNIZED_MODIFIERS: |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
446 |
static final int |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14342
diff
changeset
|
447 |
IS_METHOD = MN_IS_METHOD, // method (not constructor) |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14342
diff
changeset
|
448 |
IS_CONSTRUCTOR = MN_IS_CONSTRUCTOR, // constructor |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14342
diff
changeset
|
449 |
IS_FIELD = MN_IS_FIELD, // field |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14342
diff
changeset
|
450 |
IS_TYPE = MN_IS_TYPE, // nested type |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14342
diff
changeset
|
451 |
CALLER_SENSITIVE = MN_CALLER_SENSITIVE; // @CallerSensitive annotation detected |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
452 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
453 |
static final int ALL_ACCESS = Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
454 |
static final int ALL_KINDS = IS_METHOD | IS_CONSTRUCTOR | IS_FIELD | IS_TYPE; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
455 |
static final int IS_INVOCABLE = IS_METHOD | IS_CONSTRUCTOR; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
456 |
static final int IS_FIELD_OR_METHOD = IS_METHOD | IS_FIELD; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
457 |
static final int SEARCH_ALL_SUPERS = MN_SEARCH_SUPERCLASSES | MN_SEARCH_INTERFACES; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
458 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
459 |
/** Utility method to query whether this member is a method or constructor. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
460 |
public boolean isInvocable() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
461 |
return testAnyFlags(IS_INVOCABLE); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
462 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
463 |
/** Utility method to query whether this member is a method, constructor, or field. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
464 |
public boolean isFieldOrMethod() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
465 |
return testAnyFlags(IS_FIELD_OR_METHOD); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
466 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
467 |
/** Query whether this member is a method. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
468 |
public boolean isMethod() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
469 |
return testAllFlags(IS_METHOD); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
470 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
471 |
/** Query whether this member is a constructor. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
472 |
public boolean isConstructor() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
473 |
return testAllFlags(IS_CONSTRUCTOR); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
474 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
475 |
/** Query whether this member is a field. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
476 |
public boolean isField() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
477 |
return testAllFlags(IS_FIELD); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
478 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
479 |
/** Query whether this member is a type. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
480 |
public boolean isType() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
481 |
return testAllFlags(IS_TYPE); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
482 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
483 |
/** Utility method to query whether this member is neither public, private, nor protected. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
484 |
public boolean isPackage() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
485 |
return !testAnyFlags(ALL_ACCESS); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
486 |
} |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14342
diff
changeset
|
487 |
/** Query whether this member has a CallerSensitive annotation. */ |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14342
diff
changeset
|
488 |
public boolean isCallerSensitive() { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14342
diff
changeset
|
489 |
return testAllFlags(CALLER_SENSITIVE); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14342
diff
changeset
|
490 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
491 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
492 |
/** Utility method to query whether this member is accessible from a given lookup class. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
493 |
public boolean isAccessibleFrom(Class<?> lookupClass) { |
36511 | 494 |
int mode = (ALL_ACCESS|MethodHandles.Lookup.PACKAGE|MethodHandles.Lookup.MODULE); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
495 |
return VerifyAccess.isMemberAccessible(this.getDeclaringClass(), this.getDeclaringClass(), flags, |
36511 | 496 |
lookupClass, mode); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
497 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
498 |
|
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
38774
diff
changeset
|
499 |
/** |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
38774
diff
changeset
|
500 |
* Check if MemberName is a call to a method named {@code name} in class {@code declaredClass}. |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
38774
diff
changeset
|
501 |
*/ |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
38774
diff
changeset
|
502 |
public boolean refersTo(Class<?> declc, String n) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
38774
diff
changeset
|
503 |
return clazz == declc && getName().equals(n); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
38774
diff
changeset
|
504 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
38774
diff
changeset
|
505 |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
506 |
/** Initialize a query. It is not resolved. */ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
507 |
private void init(Class<?> defClass, String name, Object type, int flags) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
508 |
// defining class is allowed to be null (for a naked name/type pair) |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
509 |
//name.toString(); // null check |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
510 |
//type.equals(type); // null check |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
511 |
// fill in fields: |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
512 |
this.clazz = defClass; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
513 |
this.name = name; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
514 |
this.type = type; |
13612
275711a5df25
7194612: api/java_lang/invoke/MethodHandles/Lookup/index.html#ExceptionsTests[findVirtualNSME] fails w/ -esa
jrose
parents:
13424
diff
changeset
|
515 |
this.flags = flags; |
275711a5df25
7194612: api/java_lang/invoke/MethodHandles/Lookup/index.html#ExceptionsTests[findVirtualNSME] fails w/ -esa
jrose
parents:
13424
diff
changeset
|
516 |
assert(testAnyFlags(ALL_KINDS)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
517 |
assert(this.resolution == null); // nobody should have touched this yet |
13612
275711a5df25
7194612: api/java_lang/invoke/MethodHandles/Lookup/index.html#ExceptionsTests[findVirtualNSME] fails w/ -esa
jrose
parents:
13424
diff
changeset
|
518 |
//assert(referenceKindIsConsistent()); // do this after resolution |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
519 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
520 |
|
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
521 |
/** |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
522 |
* Calls down to the VM to fill in the fields. This method is |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
523 |
* synchronized to avoid racing calls. |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
524 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
525 |
private void expandFromVM() { |
20472
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
526 |
if (type != null) { |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
527 |
return; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
528 |
} |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
529 |
if (!isResolved()) { |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
530 |
return; |
6adc9f6bb215
8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents:
19804
diff
changeset
|
531 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
532 |
MethodHandleNatives.expand(this); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
533 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
534 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
535 |
// Capturing information from the Core Reflection API: |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
536 |
private static int flagsMods(int flags, int mods, byte refKind) { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
537 |
assert((flags & RECOGNIZED_MODIFIERS) == 0); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
538 |
assert((mods & ~RECOGNIZED_MODIFIERS) == 0); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
539 |
assert((refKind & ~MN_REFERENCE_KIND_MASK) == 0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
540 |
return flags | mods | (refKind << MN_REFERENCE_KIND_SHIFT); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
541 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
542 |
/** Create a name for the given reflected method. The resulting name will be in a resolved state. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
543 |
public MemberName(Method m) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
544 |
this(m, false); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
545 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
546 |
@SuppressWarnings("LeakingThisInConstructor") |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
547 |
public MemberName(Method m, boolean wantSpecial) { |
29094
a4fd2b5e49f8
8073479: Replace obj.getClass hacks with Objects.requireNonNull
shade
parents:
26467
diff
changeset
|
548 |
Objects.requireNonNull(m); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
549 |
// fill in vmtarget, vmindex while we have m in hand: |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
550 |
MethodHandleNatives.init(this, m); |
19804 | 551 |
if (clazz == null) { // MHN.init failed |
552 |
if (m.getDeclaringClass() == MethodHandle.class && |
|
553 |
isMethodHandleInvokeName(m.getName())) { |
|
554 |
// The JVM did not reify this signature-polymorphic instance. |
|
555 |
// Need a special case here. |
|
556 |
// See comments on MethodHandleNatives.linkMethod. |
|
557 |
MethodType type = MethodType.methodType(m.getReturnType(), m.getParameterTypes()); |
|
558 |
int flags = flagsMods(IS_METHOD, m.getModifiers(), REF_invokeVirtual); |
|
559 |
init(MethodHandle.class, m.getName(), type, flags); |
|
560 |
if (isMethodHandleInvoke()) |
|
561 |
return; |
|
562 |
} |
|
36934 | 563 |
if (m.getDeclaringClass() == VarHandle.class && |
564 |
isVarHandleMethodInvokeName(m.getName())) { |
|
565 |
// The JVM did not reify this signature-polymorphic instance. |
|
566 |
// Need a special case here. |
|
567 |
// See comments on MethodHandleNatives.linkMethod. |
|
568 |
MethodType type = MethodType.methodType(m.getReturnType(), m.getParameterTypes()); |
|
569 |
int flags = flagsMods(IS_METHOD, m.getModifiers(), REF_invokeVirtual); |
|
570 |
init(VarHandle.class, m.getName(), type, flags); |
|
571 |
if (isVarHandleMethodInvoke()) |
|
572 |
return; |
|
573 |
} |
|
19804 | 574 |
throw new LinkageError(m.toString()); |
575 |
} |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
576 |
assert(isResolved() && this.clazz != null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
577 |
this.name = m.getName(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
578 |
if (this.type == null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
579 |
this.type = new Object[] { m.getReturnType(), m.getParameterTypes() }; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
580 |
if (wantSpecial) { |
19804 | 581 |
if (isAbstract()) |
582 |
throw new AbstractMethodError(this.toString()); |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
583 |
if (getReferenceKind() == REF_invokeVirtual) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
584 |
changeReferenceKind(REF_invokeSpecial, REF_invokeVirtual); |
17461
84860231159b
8008687: MethodHandle code: allow static and invokespecial calls to interface methods
bharadwaj
parents:
16906
diff
changeset
|
585 |
else if (getReferenceKind() == REF_invokeInterface) |
84860231159b
8008687: MethodHandle code: allow static and invokespecial calls to interface methods
bharadwaj
parents:
16906
diff
changeset
|
586 |
// invokeSpecial on a default method |
84860231159b
8008687: MethodHandle code: allow static and invokespecial calls to interface methods
bharadwaj
parents:
16906
diff
changeset
|
587 |
changeReferenceKind(REF_invokeSpecial, REF_invokeInterface); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
588 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
589 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
590 |
public MemberName asSpecial() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
591 |
switch (getReferenceKind()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
592 |
case REF_invokeSpecial: return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
593 |
case REF_invokeVirtual: return clone().changeReferenceKind(REF_invokeSpecial, REF_invokeVirtual); |
17461
84860231159b
8008687: MethodHandle code: allow static and invokespecial calls to interface methods
bharadwaj
parents:
16906
diff
changeset
|
594 |
case REF_invokeInterface: return clone().changeReferenceKind(REF_invokeSpecial, REF_invokeInterface); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
595 |
case REF_newInvokeSpecial: return clone().changeReferenceKind(REF_invokeSpecial, REF_newInvokeSpecial); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
596 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
597 |
throw new IllegalArgumentException(this.toString()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
598 |
} |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
599 |
/** If this MN is not REF_newInvokeSpecial, return a clone with that ref. kind. |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
600 |
* In that case it must already be REF_invokeSpecial. |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
601 |
*/ |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
602 |
public MemberName asConstructor() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
603 |
switch (getReferenceKind()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
604 |
case REF_invokeSpecial: return clone().changeReferenceKind(REF_newInvokeSpecial, REF_invokeSpecial); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
605 |
case REF_newInvokeSpecial: return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
606 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
607 |
throw new IllegalArgumentException(this.toString()); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
608 |
} |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
609 |
/** If this MN is a REF_invokeSpecial, return a clone with the "normal" kind |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
610 |
* REF_invokeVirtual; also switch either to REF_invokeInterface if clazz.isInterface. |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
611 |
* The end result is to get a fully virtualized version of the MN. |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
612 |
* (Note that resolving in the JVM will sometimes devirtualize, changing |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
613 |
* REF_invokeVirtual of a final to REF_invokeSpecial, and REF_invokeInterface |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
614 |
* in some corner cases to either of the previous two; this transform |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
615 |
* undoes that change under the assumption that it occurred.) |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
616 |
*/ |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
617 |
public MemberName asNormalOriginal() { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
618 |
byte normalVirtual = clazz.isInterface() ? REF_invokeInterface : REF_invokeVirtual; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
619 |
byte refKind = getReferenceKind(); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
620 |
byte newRefKind = refKind; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
621 |
MemberName result = this; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
622 |
switch (refKind) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
623 |
case REF_invokeInterface: |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
624 |
case REF_invokeVirtual: |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
625 |
case REF_invokeSpecial: |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
626 |
newRefKind = normalVirtual; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
627 |
break; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
628 |
} |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
629 |
if (newRefKind == refKind) |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
630 |
return this; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
631 |
result = clone().changeReferenceKind(newRefKind, refKind); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
632 |
assert(this.referenceKindIsConsistentWith(result.getReferenceKind())); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
633 |
return result; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
634 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
635 |
/** Create a name for the given reflected constructor. The resulting name will be in a resolved state. */ |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
636 |
@SuppressWarnings("LeakingThisInConstructor") |
11534
9949ffb8eb3a
7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents:
10419
diff
changeset
|
637 |
public MemberName(Constructor<?> ctor) { |
29094
a4fd2b5e49f8
8073479: Replace obj.getClass hacks with Objects.requireNonNull
shade
parents:
26467
diff
changeset
|
638 |
Objects.requireNonNull(ctor); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
639 |
// fill in vmtarget, vmindex while we have ctor in hand: |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
640 |
MethodHandleNatives.init(this, ctor); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
641 |
assert(isResolved() && this.clazz != null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
642 |
this.name = CONSTRUCTOR_NAME; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
643 |
if (this.type == null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
644 |
this.type = new Object[] { void.class, ctor.getParameterTypes() }; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
645 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
646 |
/** Create a name for the given reflected field. The resulting name will be in a resolved state. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
647 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
648 |
public MemberName(Field fld) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
649 |
this(fld, false); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
650 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
651 |
@SuppressWarnings("LeakingThisInConstructor") |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
652 |
public MemberName(Field fld, boolean makeSetter) { |
29094
a4fd2b5e49f8
8073479: Replace obj.getClass hacks with Objects.requireNonNull
shade
parents:
26467
diff
changeset
|
653 |
Objects.requireNonNull(fld); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
654 |
// fill in vmtarget, vmindex while we have fld in hand: |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
655 |
MethodHandleNatives.init(this, fld); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
656 |
assert(isResolved() && this.clazz != null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
657 |
this.name = fld.getName(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
658 |
this.type = fld.getType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
659 |
assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
660 |
byte refKind = this.getReferenceKind(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
661 |
assert(refKind == (isStatic() ? REF_getStatic : REF_getField)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
662 |
if (makeSetter) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
663 |
changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
664 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
665 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
666 |
public boolean isGetter() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
667 |
return MethodHandleNatives.refKindIsGetter(getReferenceKind()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
668 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
669 |
public boolean isSetter() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
670 |
return MethodHandleNatives.refKindIsSetter(getReferenceKind()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
671 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
672 |
public MemberName asSetter() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
673 |
byte refKind = getReferenceKind(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
674 |
assert(MethodHandleNatives.refKindIsGetter(refKind)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
675 |
assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
676 |
byte setterRefKind = (byte)(refKind + (REF_putField - REF_getField)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
677 |
return clone().changeReferenceKind(setterRefKind, refKind); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
678 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
679 |
/** Create a name for the given class. The resulting name will be in a resolved state. */ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
680 |
public MemberName(Class<?> type) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
681 |
init(type.getDeclaringClass(), type.getSimpleName(), type, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
682 |
flagsMods(IS_TYPE, type.getModifiers(), REF_NONE)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
683 |
initResolved(true); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
684 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
685 |
|
19804 | 686 |
/** |
687 |
* Create a name for a signature-polymorphic invoker. |
|
688 |
* This is a placeholder for a signature-polymorphic instance |
|
689 |
* (of MH.invokeExact, etc.) that the JVM does not reify. |
|
690 |
* See comments on {@link MethodHandleNatives#linkMethod}. |
|
691 |
*/ |
|
692 |
static MemberName makeMethodHandleInvoke(String name, MethodType type) { |
|
693 |
return makeMethodHandleInvoke(name, type, MH_INVOKE_MODS | SYNTHETIC); |
|
694 |
} |
|
695 |
static MemberName makeMethodHandleInvoke(String name, MethodType type, int mods) { |
|
696 |
MemberName mem = new MemberName(MethodHandle.class, name, type, REF_invokeVirtual); |
|
697 |
mem.flags |= mods; // it's not resolved, but add these modifiers anyway |
|
698 |
assert(mem.isMethodHandleInvoke()) : mem; |
|
699 |
return mem; |
|
700 |
} |
|
701 |
||
36934 | 702 |
static MemberName makeVarHandleMethodInvoke(String name, MethodType type) { |
703 |
return makeVarHandleMethodInvoke(name, type, MH_INVOKE_MODS | SYNTHETIC); |
|
704 |
} |
|
705 |
static MemberName makeVarHandleMethodInvoke(String name, MethodType type, int mods) { |
|
706 |
MemberName mem = new MemberName(VarHandle.class, name, type, REF_invokeVirtual); |
|
707 |
mem.flags |= mods; // it's not resolved, but add these modifiers anyway |
|
708 |
assert(mem.isVarHandleMethodInvoke()) : mem; |
|
709 |
return mem; |
|
710 |
} |
|
711 |
||
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
712 |
// bare-bones constructor; the JVM will fill it in |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
713 |
MemberName() { } |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
714 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
715 |
// locally useful cloner |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
716 |
@Override protected MemberName clone() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
717 |
try { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
718 |
return (MemberName) super.clone(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
719 |
} catch (CloneNotSupportedException ex) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13612
diff
changeset
|
720 |
throw newInternalError(ex); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
721 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
722 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
723 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
724 |
/** Get the definition of this member name. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
725 |
* This may be in a super-class of the declaring class of this member. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
726 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
727 |
public MemberName getDefinition() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
728 |
if (!isResolved()) throw new IllegalStateException("must be resolved: "+this); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
729 |
if (isType()) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
730 |
MemberName res = this.clone(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
731 |
res.clazz = null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
732 |
res.type = null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
733 |
res.name = null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
734 |
res.resolution = res; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
735 |
res.expandFromVM(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
736 |
assert(res.getName().equals(this.getName())); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
737 |
return res; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
738 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
739 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
740 |
@Override |
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
37343
diff
changeset
|
741 |
@SuppressWarnings("deprecation") |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
742 |
public int hashCode() { |
33649
5e51019fc94d
8141677: Improve java.lang.invoke.MemberName hashCode implementation
redestad
parents:
32986
diff
changeset
|
743 |
// Avoid autoboxing getReferenceKind(), since this is used early and will force |
5e51019fc94d
8141677: Improve java.lang.invoke.MemberName hashCode implementation
redestad
parents:
32986
diff
changeset
|
744 |
// early initialization of Byte$ByteCache |
5e51019fc94d
8141677: Improve java.lang.invoke.MemberName hashCode implementation
redestad
parents:
32986
diff
changeset
|
745 |
return Objects.hash(clazz, new Byte(getReferenceKind()), name, getType()); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
746 |
} |
33649
5e51019fc94d
8141677: Improve java.lang.invoke.MemberName hashCode implementation
redestad
parents:
32986
diff
changeset
|
747 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
748 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
749 |
public boolean equals(Object that) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
750 |
return (that instanceof MemberName && this.equals((MemberName)that)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
751 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
752 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
753 |
/** Decide if two member names have exactly the same symbolic content. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
754 |
* Does not take into account any actual class members, so even if |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
755 |
* two member names resolve to the same actual member, they may |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
756 |
* be distinct references. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
757 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
758 |
public boolean equals(MemberName that) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
759 |
if (this == that) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
760 |
if (that == null) return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
761 |
return this.clazz == that.clazz |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
762 |
&& this.getReferenceKind() == that.getReferenceKind() |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
763 |
&& Objects.equals(this.name, that.name) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
764 |
&& Objects.equals(this.getType(), that.getType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
765 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
766 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
767 |
// Construction from symbolic parts, for queries: |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
768 |
/** Create a field or type name from the given components: |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
769 |
* Declaring class, name, type, reference kind. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
770 |
* The declaring class may be supplied as null if this is to be a bare name and type. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
771 |
* The resulting name will in an unresolved state. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
772 |
*/ |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
773 |
public MemberName(Class<?> defClass, String name, Class<?> type, byte refKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
774 |
init(defClass, name, type, flagsMods(IS_FIELD, 0, refKind)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
775 |
initResolved(false); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
776 |
} |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25991
diff
changeset
|
777 |
/** Create a method or constructor name from the given components: |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25991
diff
changeset
|
778 |
* Declaring class, name, type, reference kind. |
32276
2d5fcc89e099
8134356: {@code} tag contains < and > sequences
igerasim
parents:
29094
diff
changeset
|
779 |
* It will be a constructor if and only if the name is {@code "<init>"}. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
780 |
* The declaring class may be supplied as null if this is to be a bare name and type. |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
781 |
* The last argument is optional, a boolean which requests REF_invokeSpecial. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
782 |
* The resulting name will in an unresolved state. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
783 |
*/ |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
784 |
public MemberName(Class<?> defClass, String name, MethodType type, byte refKind) { |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
785 |
int initFlags = (name != null && name.equals(CONSTRUCTOR_NAME) ? IS_CONSTRUCTOR : IS_METHOD); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
786 |
init(defClass, name, type, flagsMods(initFlags, 0, refKind)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
787 |
initResolved(false); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
788 |
} |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
789 |
/** Create a method, constructor, or field name from the given components: |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
790 |
* Reference kind, declaring class, name, type. |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
791 |
*/ |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
792 |
public MemberName(byte refKind, Class<?> defClass, String name, Object type) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
793 |
int kindFlags; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
794 |
if (MethodHandleNatives.refKindIsField(refKind)) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
795 |
kindFlags = IS_FIELD; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
796 |
if (!(type instanceof Class)) |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
797 |
throw newIllegalArgumentException("not a field type"); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
798 |
} else if (MethodHandleNatives.refKindIsMethod(refKind)) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
799 |
kindFlags = IS_METHOD; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
800 |
if (!(type instanceof MethodType)) |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
801 |
throw newIllegalArgumentException("not a method type"); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
802 |
} else if (refKind == REF_newInvokeSpecial) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
803 |
kindFlags = IS_CONSTRUCTOR; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
804 |
if (!(type instanceof MethodType) || |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
805 |
!CONSTRUCTOR_NAME.equals(name)) |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
806 |
throw newIllegalArgumentException("not a constructor type or name"); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
807 |
} else { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
808 |
throw newIllegalArgumentException("bad reference kind "+refKind); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
809 |
} |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
810 |
init(defClass, name, type, flagsMods(kindFlags, 0, refKind)); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
811 |
initResolved(false); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20472
diff
changeset
|
812 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
813 |
/** Query whether this member name is resolved to a non-static, non-final method. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
814 |
*/ |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
815 |
public boolean hasReceiverTypeDispatch() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
816 |
return MethodHandleNatives.refKindDoesDispatch(getReferenceKind()); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
817 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
818 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
819 |
/** Query whether this member name is resolved. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
820 |
* A resolved member name is one for which the JVM has found |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
821 |
* a method, constructor, field, or type binding corresponding exactly to the name. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
822 |
* (Document?) |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
823 |
*/ |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
824 |
public boolean isResolved() { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
825 |
return resolution == null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
826 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
827 |
|
40272
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40258
diff
changeset
|
828 |
void initResolved(boolean isResolved) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
829 |
assert(this.resolution == null); // not initialized yet! |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
830 |
if (!isResolved) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
831 |
this.resolution = this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
832 |
assert(isResolved() == isResolved); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
833 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
834 |
|
37585 | 835 |
void checkForTypeAlias(Class<?> refc) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
836 |
if (isInvocable()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
837 |
MethodType type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
838 |
if (this.type instanceof MethodType) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
839 |
type = (MethodType) this.type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
840 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
841 |
this.type = type = getMethodType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
842 |
if (type.erase() == type) return; |
37585 | 843 |
if (VerifyAccess.isTypeVisible(type, refc)) return; |
844 |
throw new LinkageError("bad method type alias: "+type+" not visible from "+refc); |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
845 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
846 |
Class<?> type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
847 |
if (this.type instanceof Class<?>) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
848 |
type = (Class<?>) this.type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
849 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
850 |
this.type = type = getFieldType(); |
37585 | 851 |
if (VerifyAccess.isTypeVisible(type, refc)) return; |
852 |
throw new LinkageError("bad field type alias: "+type+" not visible from "+refc); |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
853 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
854 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
855 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
856 |
|
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
857 |
/** Produce a string form of this member name. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
858 |
* For types, it is simply the type's own string (as reported by {@code toString}). |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
859 |
* For fields, it is {@code "DeclaringClass.name/type"}. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
860 |
* For methods and constructors, it is {@code "DeclaringClass.name(ptype...)rtype"}. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
861 |
* If the declaring class is null, the prefix {@code "DeclaringClass."} is omitted. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
862 |
* If the member is unresolved, a prefix {@code "*."} is prepended. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
863 |
*/ |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
864 |
@SuppressWarnings("LocalVariableHidesMemberVariable") |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
865 |
@Override |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
866 |
public String toString() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
867 |
if (isType()) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
868 |
return type.toString(); // class java.lang.String |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
869 |
// else it is a field, method, or constructor |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
870 |
StringBuilder buf = new StringBuilder(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
871 |
if (getDeclaringClass() != null) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
872 |
buf.append(getName(clazz)); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
873 |
buf.append('.'); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
874 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
875 |
String name = getName(); |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
876 |
buf.append(name == null ? "*" : name); |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
877 |
Object type = getType(); |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
878 |
if (!isInvocable()) { |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
879 |
buf.append('/'); |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
880 |
buf.append(type == null ? "*" : getName(type)); |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
881 |
} else { |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
882 |
buf.append(type == null ? "(*)*" : getName(type)); |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
883 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
884 |
byte refKind = getReferenceKind(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
885 |
if (refKind != REF_NONE) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
886 |
buf.append('/'); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
887 |
buf.append(MethodHandleNatives.refKindName(refKind)); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
888 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
889 |
//buf.append("#").append(System.identityHashCode(this)); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
890 |
return buf.toString(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
891 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
892 |
private static String getName(Object obj) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
893 |
if (obj instanceof Class<?>) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
894 |
return ((Class<?>)obj).getName(); |
4537 | 895 |
return String.valueOf(obj); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
896 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
897 |
|
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
898 |
public IllegalAccessException makeAccessException(String message, Object from) { |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
899 |
message = message + ": "+ toString(); |
36511 | 900 |
if (from != null) { |
901 |
if (from == MethodHandles.publicLookup()) { |
|
902 |
message += ", from public Lookup"; |
|
903 |
} else { |
|
904 |
Module m; |
|
905 |
if (from instanceof MethodHandles.Lookup) { |
|
906 |
MethodHandles.Lookup lookup = (MethodHandles.Lookup)from; |
|
907 |
m = lookup.lookupClass().getModule(); |
|
908 |
} else { |
|
909 |
m = from.getClass().getModule(); |
|
910 |
} |
|
911 |
message += ", from " + from + " (" + m + ")"; |
|
912 |
} |
|
913 |
} |
|
8347
e5daa5772ffd
7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents:
7052
diff
changeset
|
914 |
return new IllegalAccessException(message); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
915 |
} |
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
916 |
private String message() { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
917 |
if (isResolved()) |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
918 |
return "no access"; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
919 |
else if (isConstructor()) |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
920 |
return "no such constructor"; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
921 |
else if (isMethod()) |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
922 |
return "no such method"; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
923 |
else |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
924 |
return "no such field"; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
925 |
} |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
926 |
public ReflectiveOperationException makeAccessException() { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9646
diff
changeset
|
927 |
String message = message() + ": "+ toString(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
928 |
ReflectiveOperationException ex; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
929 |
if (isResolved() || !(resolution instanceof NoSuchMethodError || |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
930 |
resolution instanceof NoSuchFieldError)) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
931 |
ex = new IllegalAccessException(message); |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
932 |
else if (isConstructor()) |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
933 |
ex = new NoSuchMethodException(message); |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
934 |
else if (isMethod()) |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
935 |
ex = new NoSuchMethodException(message); |
8347
e5daa5772ffd
7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents:
7052
diff
changeset
|
936 |
else |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
937 |
ex = new NoSuchFieldException(message); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
938 |
if (resolution instanceof Throwable) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
939 |
ex.initCause((Throwable) resolution); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
940 |
return ex; |
7052
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
941 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
942 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
943 |
/** Actually making a query requires an access check. */ |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8347
diff
changeset
|
944 |
/*non-public*/ static Factory getFactory() { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
945 |
return Factory.INSTANCE; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
946 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
947 |
/** A factory type for resolving member names with the help of the VM. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
948 |
* TBD: Define access-safe public constructors for this factory. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
949 |
*/ |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
8822
diff
changeset
|
950 |
/*non-public*/ static class Factory { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
951 |
private Factory() { } // singleton pattern |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
952 |
static Factory INSTANCE = new Factory(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
953 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
954 |
private static int ALLOWED_FLAGS = ALL_KINDS; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
955 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
956 |
/// Queries |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
957 |
List<MemberName> getMembers(Class<?> defc, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
958 |
String matchName, Object matchType, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
959 |
int matchFlags, Class<?> lookupClass) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
960 |
matchFlags &= ALLOWED_FLAGS; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
961 |
String matchSig = null; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
962 |
if (matchType != null) { |
4537 | 963 |
matchSig = BytecodeDescriptor.unparse(matchType); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
964 |
if (matchSig.startsWith("(")) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
965 |
matchFlags &= ~(ALL_KINDS & ~IS_INVOCABLE); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
966 |
else |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
967 |
matchFlags &= ~(ALL_KINDS & ~IS_FIELD); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
968 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
969 |
final int BUF_MAX = 0x2000; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
970 |
int len1 = matchName == null ? 10 : matchType == null ? 4 : 1; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
971 |
MemberName[] buf = newMemberBuffer(len1); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
972 |
int totalCount = 0; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
973 |
ArrayList<MemberName[]> bufs = null; |
4537 | 974 |
int bufCount = 0; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
975 |
for (;;) { |
4537 | 976 |
bufCount = MethodHandleNatives.getMembers(defc, |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
977 |
matchName, matchSig, matchFlags, |
2764
2e45af54c0f9
6839839: access checking logic is wrong at three points in MethodHandles
jrose
parents:
2707
diff
changeset
|
978 |
lookupClass, |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
979 |
totalCount, buf); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
980 |
if (bufCount <= buf.length) { |
4537 | 981 |
if (bufCount < 0) bufCount = 0; |
982 |
totalCount += bufCount; |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
983 |
break; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
984 |
} |
4537 | 985 |
// JVM returned to us with an intentional overflow! |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
986 |
totalCount += buf.length; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
987 |
int excess = bufCount - buf.length; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
988 |
if (bufs == null) bufs = new ArrayList<>(1); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
989 |
bufs.add(buf); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
990 |
int len2 = buf.length; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
991 |
len2 = Math.max(len2, excess); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
992 |
len2 = Math.max(len2, totalCount / 4); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
993 |
buf = newMemberBuffer(Math.min(BUF_MAX, len2)); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
994 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
995 |
ArrayList<MemberName> result = new ArrayList<>(totalCount); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
996 |
if (bufs != null) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
997 |
for (MemberName[] buf0 : bufs) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
998 |
Collections.addAll(result, buf0); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
999 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1000 |
} |
40256
c5e03eaf7ba2
8163370: Reduce number of classes loaded by common usage of java.lang.invoke
redestad
parents:
39754
diff
changeset
|
1001 |
for (int i = 0; i < bufCount; i++) { |
c5e03eaf7ba2
8163370: Reduce number of classes loaded by common usage of java.lang.invoke
redestad
parents:
39754
diff
changeset
|
1002 |
result.add(buf[i]); |
c5e03eaf7ba2
8163370: Reduce number of classes loaded by common usage of java.lang.invoke
redestad
parents:
39754
diff
changeset
|
1003 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1004 |
// Signature matching is not the same as type matching, since |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1005 |
// one signature might correspond to several types. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1006 |
// So if matchType is a Class or MethodType, refilter the results. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1007 |
if (matchType != null && matchType != matchSig) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1008 |
for (Iterator<MemberName> it = result.iterator(); it.hasNext();) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1009 |
MemberName m = it.next(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1010 |
if (!matchType.equals(m.getType())) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1011 |
it.remove(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1012 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1013 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1014 |
return result; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1015 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1016 |
/** Produce a resolved version of the given member. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1017 |
* Super types are searched (for inherited members) if {@code searchSupers} is true. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1018 |
* Access checking is performed on behalf of the given {@code lookupClass}. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1019 |
* If lookup fails or access is not permitted, null is returned. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1020 |
* Otherwise a fresh copy of the given member is returned, with modifier bits filled in. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1021 |
*/ |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1022 |
private MemberName resolve(byte refKind, MemberName ref, Class<?> lookupClass) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1023 |
MemberName m = ref.clone(); // JVM will side-effect the ref |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1024 |
assert(refKind == m.getReferenceKind()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1025 |
try { |
37585 | 1026 |
// There are 4 entities in play here: |
1027 |
// * LC: lookupClass |
|
1028 |
// * REFC: symbolic reference class (MN.clazz before resolution); |
|
1029 |
// * DEFC: resolved method holder (MN.clazz after resolution); |
|
1030 |
// * PTYPES: parameter types (MN.type) |
|
1031 |
// |
|
1032 |
// What we care about when resolving a MemberName is consistency between DEFC and PTYPES. |
|
1033 |
// We do type alias (TA) checks on DEFC to ensure that. DEFC is not known until the JVM |
|
1034 |
// finishes the resolution, so do TA checks right after MHN.resolve() is over. |
|
1035 |
// |
|
1036 |
// All parameters passed by a caller are checked against MH type (PTYPES) on every invocation, |
|
1037 |
// so it is safe to call a MH from any context. |
|
1038 |
// |
|
1039 |
// REFC view on PTYPES doesn't matter, since it is used only as a starting point for resolution and doesn't |
|
1040 |
// participate in method selection. |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1041 |
m = MethodHandleNatives.resolve(m, lookupClass); |
37585 | 1042 |
m.checkForTypeAlias(m.getDeclaringClass()); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1043 |
m.resolution = null; |
37585 | 1044 |
} catch (ClassNotFoundException | LinkageError ex) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1045 |
// JVM reports that the "bytecode behavior" would get an error |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1046 |
assert(!m.isResolved()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1047 |
m.resolution = ex; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1048 |
return m; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1049 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1050 |
assert(m.referenceKindIsConsistent()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1051 |
m.initResolved(true); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1052 |
assert(m.vminfoIsConsistent()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1053 |
return m; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1054 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1055 |
/** Produce a resolved version of the given member. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1056 |
* Super types are searched (for inherited members) if {@code searchSupers} is true. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1057 |
* Access checking is performed on behalf of the given {@code lookupClass}. |
8347
e5daa5772ffd
7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents:
7052
diff
changeset
|
1058 |
* If lookup fails or access is not permitted, a {@linkplain ReflectiveOperationException} is thrown. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1059 |
* Otherwise a fresh copy of the given member is returned, with modifier bits filled in. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1060 |
*/ |
8347
e5daa5772ffd
7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents:
7052
diff
changeset
|
1061 |
public |
e5daa5772ffd
7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents:
7052
diff
changeset
|
1062 |
<NoSuchMemberException extends ReflectiveOperationException> |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1063 |
MemberName resolveOrFail(byte refKind, MemberName m, Class<?> lookupClass, |
8347
e5daa5772ffd
7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents:
7052
diff
changeset
|
1064 |
Class<NoSuchMemberException> nsmClass) |
e5daa5772ffd
7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents:
7052
diff
changeset
|
1065 |
throws IllegalAccessException, NoSuchMemberException { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1066 |
MemberName result = resolve(refKind, m, lookupClass); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1067 |
if (result.isResolved()) |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1068 |
return result; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1069 |
ReflectiveOperationException ex = result.makeAccessException(); |
8347
e5daa5772ffd
7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents:
7052
diff
changeset
|
1070 |
if (ex instanceof IllegalAccessException) throw (IllegalAccessException) ex; |
e5daa5772ffd
7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents:
7052
diff
changeset
|
1071 |
throw nsmClass.cast(ex); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1072 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1073 |
/** Produce a resolved version of the given member. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1074 |
* Super types are searched (for inherited members) if {@code searchSupers} is true. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1075 |
* Access checking is performed on behalf of the given {@code lookupClass}. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1076 |
* If lookup fails or access is not permitted, return null. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1077 |
* Otherwise a fresh copy of the given member is returned, with modifier bits filled in. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1078 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1079 |
public |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1080 |
MemberName resolveOrNull(byte refKind, MemberName m, Class<?> lookupClass) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1081 |
MemberName result = resolve(refKind, m, lookupClass); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1082 |
if (result.isResolved()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1083 |
return result; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1084 |
return null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13421
diff
changeset
|
1085 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1086 |
/** Return a list of all methods defined by the given class. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1087 |
* Super types are searched (for inherited members) if {@code searchSupers} is true. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1088 |
* Access checking is performed on behalf of the given {@code lookupClass}. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1089 |
* Inaccessible members are not added to the last. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1090 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1091 |
public List<MemberName> getMethods(Class<?> defc, boolean searchSupers, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1092 |
Class<?> lookupClass) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1093 |
return getMethods(defc, searchSupers, null, null, lookupClass); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1094 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1095 |
/** Return a list of matching methods defined by the given class. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1096 |
* Super types are searched (for inherited members) if {@code searchSupers} is true. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1097 |
* Returned methods will match the name (if not null) and the type (if not null). |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1098 |
* Access checking is performed on behalf of the given {@code lookupClass}. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1099 |
* Inaccessible members are not added to the last. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1100 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1101 |
public List<MemberName> getMethods(Class<?> defc, boolean searchSupers, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1102 |
String name, MethodType type, Class<?> lookupClass) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1103 |
int matchFlags = IS_METHOD | (searchSupers ? SEARCH_ALL_SUPERS : 0); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1104 |
return getMembers(defc, name, type, matchFlags, lookupClass); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1105 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1106 |
/** Return a list of all constructors defined by the given class. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1107 |
* Access checking is performed on behalf of the given {@code lookupClass}. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1108 |
* Inaccessible members are not added to the last. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1109 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1110 |
public List<MemberName> getConstructors(Class<?> defc, Class<?> lookupClass) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1111 |
return getMembers(defc, null, null, IS_CONSTRUCTOR, lookupClass); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1112 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1113 |
/** Return a list of all fields defined by the given class. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1114 |
* Super types are searched (for inherited members) if {@code searchSupers} is true. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1115 |
* Access checking is performed on behalf of the given {@code lookupClass}. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1116 |
* Inaccessible members are not added to the last. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1117 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1118 |
public List<MemberName> getFields(Class<?> defc, boolean searchSupers, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1119 |
Class<?> lookupClass) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1120 |
return getFields(defc, searchSupers, null, null, lookupClass); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1121 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1122 |
/** Return a list of all fields defined by the given class. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1123 |
* Super types are searched (for inherited members) if {@code searchSupers} is true. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1124 |
* Returned fields will match the name (if not null) and the type (if not null). |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1125 |
* Access checking is performed on behalf of the given {@code lookupClass}. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1126 |
* Inaccessible members are not added to the last. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1127 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1128 |
public List<MemberName> getFields(Class<?> defc, boolean searchSupers, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1129 |
String name, Class<?> type, Class<?> lookupClass) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1130 |
int matchFlags = IS_FIELD | (searchSupers ? SEARCH_ALL_SUPERS : 0); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1131 |
return getMembers(defc, name, type, matchFlags, lookupClass); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1132 |
} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1133 |
/** Return a list of all nested types defined by the given class. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1134 |
* Super types are searched (for inherited members) if {@code searchSupers} is true. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1135 |
* Access checking is performed on behalf of the given {@code lookupClass}. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1136 |
* Inaccessible members are not added to the last. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
1137 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1138 |
public List<MemberName> getNestedTypes(Class<?> defc, boolean searchSupers, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1139 |
Class<?> lookupClass) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1140 |
int matchFlags = IS_TYPE | (searchSupers ? SEARCH_ALL_SUPERS : 0); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1141 |
return getMembers(defc, null, null, matchFlags, lookupClass); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1142 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1143 |
private static MemberName[] newMemberBuffer(int length) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1144 |
MemberName[] buf = new MemberName[length]; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1145 |
// fill the buffer with dummy structs for the JVM to fill in |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1146 |
for (int i = 0; i < length; i++) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1147 |
buf[i] = new MemberName(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1148 |
return buf; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1149 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1150 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1151 |
} |