author | redestad |
Sat, 07 Sep 2019 15:44:04 +0200 | |
changeset 58038 | aa3715655834 |
parent 57956 | e0b8b019d2f5 |
child 58078 | 41f119856e7c |
permissions | -rw-r--r-- |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1 |
/* |
57956
e0b8b019d2f5
8229997: Apply java.io.Serial annotations in java.base
darcy
parents:
52914
diff
changeset
|
2 |
* Copyright (c) 2008, 2019, 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 |
|
52914 | 28 |
import java.lang.constant.ClassDesc; |
29 |
import java.lang.constant.Constable; |
|
30 |
import java.lang.constant.MethodTypeDesc; |
|
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
31 |
import java.lang.ref.Reference; |
13422 | 32 |
import java.lang.ref.ReferenceQueue; |
52914 | 33 |
import java.lang.ref.WeakReference; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
34 |
import java.util.Arrays; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
35 |
import java.util.Collections; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
36 |
import java.util.List; |
52914 | 37 |
import java.util.NoSuchElementException; |
21604
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
38 |
import java.util.Objects; |
52914 | 39 |
import java.util.Optional; |
26219
1a19360ff122
8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents:
25859
diff
changeset
|
40 |
import java.util.StringJoiner; |
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
41 |
import java.util.concurrent.ConcurrentHashMap; |
52914 | 42 |
import java.util.concurrent.ConcurrentMap; |
43 |
import java.util.stream.Stream; |
|
44 |
||
45 |
import jdk.internal.vm.annotation.Stable; |
|
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
46 |
import sun.invoke.util.BytecodeDescriptor; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
47 |
import sun.invoke.util.VerifyType; |
52914 | 48 |
import sun.invoke.util.Wrapper; |
49 |
||
50 |
import static java.lang.invoke.MethodHandleStatics.UNSAFE; |
|
51 |
import static java.lang.invoke.MethodHandleStatics.newIllegalArgumentException; |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
52 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
53 |
/** |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
54 |
* A method type represents the arguments and return type accepted and |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
55 |
* returned by a method handle, or the arguments and return type passed |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
56 |
* and expected by a method handle caller. Method types must be properly |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
57 |
* matched between a method handle and all its callers, |
7052
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
58 |
* and the JVM's operations enforce this matching at, specifically |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
59 |
* during calls to {@link MethodHandle#invokeExact MethodHandle.invokeExact} |
9645
dabb5e4edc4c
7034977: JSR 292 MethodHandle.invokeGeneric should be renamed MethodHandle.invoke
jrose
parents:
8822
diff
changeset
|
60 |
* and {@link MethodHandle#invoke MethodHandle.invoke}, and during execution |
7052
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
61 |
* of {@code invokedynamic} instructions. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
62 |
* <p> |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
63 |
* The structure is a return type accompanied by any number of parameter types. |
7052
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
64 |
* The types (primitive, {@code void}, and reference) are represented by {@link Class} objects. |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
65 |
* (For ease of exposition, we treat {@code void} as if it were a type. |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
66 |
* In fact, it denotes the absence of a return type.) |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
67 |
* <p> |
7052
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
68 |
* All instances of {@code MethodType} are immutable. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
69 |
* Two instances are completely interchangeable if they compare equal. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
70 |
* Equality depends on pairwise correspondence of the return and parameter types and on nothing else. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
71 |
* <p> |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
72 |
* This type can be created only by factory methods. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
73 |
* All factory methods may cache values, though caching is not guaranteed. |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
74 |
* Some factory methods are static, while others are virtual methods which |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
75 |
* modify precursor method types, e.g., by changing a selected parameter. |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
76 |
* <p> |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
77 |
* Factory methods which operate on groups of parameter types |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
78 |
* are systematically presented in two versions, so that both Java arrays and |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
79 |
* Java lists can be used to work with groups of parameter types. |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
80 |
* The query methods {@code parameterArray} and {@code parameterList} |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
81 |
* also provide a choice between arrays and lists. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
82 |
* <p> |
7052
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
83 |
* {@code MethodType} objects are sometimes derived from bytecode instructions |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
84 |
* such as {@code invokedynamic}, specifically from the type descriptor strings associated |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
85 |
* with the instructions in a class file's constant pool. |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
86 |
* <p> |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
87 |
* Like classes and strings, method types can also be represented directly |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
88 |
* in a class file's constant pool as constants. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
89 |
* A method type may be loaded by an {@code ldc} instruction which refers |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
90 |
* to a suitable {@code CONSTANT_MethodType} constant pool entry. |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
91 |
* The entry refers to a {@code CONSTANT_Utf8} spelling for the descriptor string. |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20494
diff
changeset
|
92 |
* (For full details on method type constants, |
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20494
diff
changeset
|
93 |
* see sections 4.4.8 and 5.4.3.5 of the Java Virtual Machine Specification.) |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
94 |
* <p> |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
95 |
* When the JVM materializes a {@code MethodType} from a descriptor string, |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
96 |
* all classes named in the descriptor must be accessible, and will be loaded. |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
97 |
* (But the classes need not be initialized, as is the case with a {@code CONSTANT_Class}.) |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
98 |
* This loading may occur at any time before the {@code MethodType} object is first derived. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
99 |
* @author John Rose, JSR 292 EG |
44255
515cf13d7791
8176566: @since value errors in types of java.base module
mli
parents:
43194
diff
changeset
|
100 |
* @since 1.7 |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
101 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
102 |
public final |
52914 | 103 |
class MethodType |
104 |
implements Constable, |
|
105 |
TypeDescriptor.OfMethod<Class<?>, MethodType>, |
|
106 |
java.io.Serializable { |
|
57956
e0b8b019d2f5
8229997: Apply java.io.Serial annotations in java.base
darcy
parents:
52914
diff
changeset
|
107 |
@java.io.Serial |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
108 |
private static final long serialVersionUID = 292L; // {rtype, {ptype...}} |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
109 |
|
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
110 |
// The rtype and ptypes fields define the structural identity of the method type: |
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
111 |
private final @Stable Class<?> rtype; |
36934 | 112 |
private final @Stable Class<?>[] ptypes; |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
113 |
|
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
114 |
// The remaining fields are caches of various sorts: |
20494
cf77ae5ff678
8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents:
18569
diff
changeset
|
115 |
private @Stable MethodTypeForm form; // erased form, plus cached data about primitives |
cf77ae5ff678
8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents:
18569
diff
changeset
|
116 |
private @Stable MethodType wrapAlt; // alternative wrapped/unwrapped version |
cf77ae5ff678
8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents:
18569
diff
changeset
|
117 |
private @Stable Invokers invokers; // cache of handy higher-order adapters |
21604
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
118 |
private @Stable String methodDescriptor; // cache for toMethodDescriptorString |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
119 |
|
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
120 |
/** |
48250
739aa297c260
8187254: MethodType allows unvalidated parameter types
psandoz
parents:
47250
diff
changeset
|
121 |
* Constructor that performs no copying or validation. |
739aa297c260
8187254: MethodType allows unvalidated parameter types
psandoz
parents:
47250
diff
changeset
|
122 |
* Should only be called from the factory method makeImpl |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
123 |
*/ |
48250
739aa297c260
8187254: MethodType allows unvalidated parameter types
psandoz
parents:
47250
diff
changeset
|
124 |
private MethodType(Class<?> rtype, Class<?>[] ptypes) { |
21604
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
125 |
this.rtype = rtype; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
126 |
this.ptypes = ptypes; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
127 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
128 |
|
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8348
diff
changeset
|
129 |
/*trusted*/ MethodTypeForm form() { return form; } |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8348
diff
changeset
|
130 |
/*trusted*/ Class<?> rtype() { return rtype; } |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8348
diff
changeset
|
131 |
/*trusted*/ Class<?>[] ptypes() { return ptypes; } |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8348
diff
changeset
|
132 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
133 |
void setForm(MethodTypeForm f) { form = f; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
134 |
|
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
135 |
/** This number, mandated by the JVM spec as 255, |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
136 |
* is the maximum number of <em>slots</em> |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
137 |
* that any Java method can receive in its argument list. |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
138 |
* It limits both JVM signatures and method type objects. |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
139 |
* The longest possible invocation will look like |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
140 |
* {@code staticMethod(arg1, arg2, ..., arg255)} or |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
141 |
* {@code x.virtualMethod(arg1, arg2, ..., arg254)}. |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
142 |
*/ |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
143 |
/*non-public*/ static final int MAX_JVM_ARITY = 255; // this is mandated by the JVM spec. |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
144 |
|
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
145 |
/** This number is the maximum arity of a method handle, 254. |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
146 |
* It is derived from the absolute JVM-imposed arity by subtracting one, |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
147 |
* which is the slot occupied by the method handle itself at the |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
148 |
* beginning of the argument list used to invoke the method handle. |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
149 |
* The longest possible invocation will look like |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
150 |
* {@code mh.invoke(arg1, arg2, ..., arg254)}. |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
151 |
*/ |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
152 |
// Issue: Should we allow MH.invokeWithArguments to go to the full 255? |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
153 |
/*non-public*/ static final int MAX_MH_ARITY = MAX_JVM_ARITY-1; // deduct one for mh receiver |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
154 |
|
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
155 |
/** This number is the maximum arity of a method handle invoker, 253. |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
156 |
* It is derived from the absolute JVM-imposed arity by subtracting two, |
20877
83ea903d5cf1
8026183: minor documentation problems in java.lang.invoke
rriggs
parents:
20535
diff
changeset
|
157 |
* which are the slots occupied by invoke method handle, and the |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
158 |
* target method handle, which are both at the beginning of the argument |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
159 |
* list used to invoke the target method handle. |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
160 |
* The longest possible invocation will look like |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
161 |
* {@code invokermh.invoke(targetmh, arg1, arg2, ..., arg253)}. |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
162 |
*/ |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
163 |
/*non-public*/ static final int MAX_MH_INVOKER_ARITY = MAX_MH_ARITY-1; // deduct one more for invoker |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
164 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
165 |
private static void checkRtype(Class<?> rtype) { |
21604
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
166 |
Objects.requireNonNull(rtype); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
167 |
} |
21604
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
168 |
private static void checkPtype(Class<?> ptype) { |
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
169 |
Objects.requireNonNull(ptype); |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
170 |
if (ptype == void.class) |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
171 |
throw newIllegalArgumentException("parameter type cannot be void"); |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
172 |
} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
173 |
/** Return number of extra slots (count of long/double args). */ |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
174 |
private static int checkPtypes(Class<?>[] ptypes) { |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
175 |
int slots = 0; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
176 |
for (Class<?> ptype : ptypes) { |
21604
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
177 |
checkPtype(ptype); |
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
178 |
if (ptype == double.class || ptype == long.class) { |
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
179 |
slots++; |
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
180 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
181 |
} |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
182 |
checkSlotCount(ptypes.length + slots); |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
183 |
return slots; |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
184 |
} |
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
185 |
|
34384
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33874
diff
changeset
|
186 |
static { |
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33874
diff
changeset
|
187 |
// MAX_JVM_ARITY must be power of 2 minus 1 for following code trick to work: |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
188 |
assert((MAX_JVM_ARITY & (MAX_JVM_ARITY+1)) == 0); |
34384
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33874
diff
changeset
|
189 |
} |
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33874
diff
changeset
|
190 |
static void checkSlotCount(int count) { |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
191 |
if ((count & MAX_JVM_ARITY) != count) |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
192 |
throw newIllegalArgumentException("bad parameter count "+count); |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
193 |
} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
194 |
private static IndexOutOfBoundsException newIndexOutOfBoundsException(Object num) { |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
195 |
if (num instanceof Integer) num = "bad index: "+num; |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
196 |
return new IndexOutOfBoundsException(num.toString()); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
197 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
198 |
|
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
199 |
static final ConcurrentWeakInternSet<MethodType> internTable = new ConcurrentWeakInternSet<>(); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
200 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
201 |
static final Class<?>[] NO_PTYPES = {}; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
202 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
203 |
/** |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
204 |
* Finds or creates an instance of the given method type. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
205 |
* @param rtype the return type |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
206 |
* @param ptypes the parameter types |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
207 |
* @return a method type with the given components |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
208 |
* @throws NullPointerException if {@code rtype} or {@code ptypes} or any element of {@code ptypes} is null |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
209 |
* @throws IllegalArgumentException if any element of {@code ptypes} is {@code void.class} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
210 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
211 |
public static |
4537 | 212 |
MethodType methodType(Class<?> rtype, Class<?>[] ptypes) { |
213 |
return makeImpl(rtype, ptypes, false); |
|
214 |
} |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
215 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
216 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
217 |
* Finds or creates a method type with the given components. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
218 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
18569 | 219 |
* @param rtype the return type |
220 |
* @param ptypes the parameter types |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
221 |
* @return a method type with the given components |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
222 |
* @throws NullPointerException if {@code rtype} or {@code ptypes} or any element of {@code ptypes} is null |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
223 |
* @throws IllegalArgumentException if any element of {@code ptypes} is {@code void.class} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
224 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
225 |
public static |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
226 |
MethodType methodType(Class<?> rtype, List<Class<?>> ptypes) { |
4537 | 227 |
boolean notrust = false; // random List impl. could return evil ptypes array |
9731
d0f7a3e441c4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
9646
diff
changeset
|
228 |
return makeImpl(rtype, listToArray(ptypes), notrust); |
d0f7a3e441c4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
9646
diff
changeset
|
229 |
} |
d0f7a3e441c4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
9646
diff
changeset
|
230 |
|
d0f7a3e441c4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
9646
diff
changeset
|
231 |
private static Class<?>[] listToArray(List<Class<?>> ptypes) { |
d0f7a3e441c4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
9646
diff
changeset
|
232 |
// sanity check the size before the toArray call, since size might be huge |
d0f7a3e441c4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
9646
diff
changeset
|
233 |
checkSlotCount(ptypes.size()); |
d0f7a3e441c4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
9646
diff
changeset
|
234 |
return ptypes.toArray(NO_PTYPES); |
4537 | 235 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
236 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
237 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
238 |
* Finds or creates a method type with the given components. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
239 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
240 |
* The leading parameter type is prepended to the remaining array. |
18569 | 241 |
* @param rtype the return type |
242 |
* @param ptype0 the first parameter type |
|
243 |
* @param ptypes the remaining parameter types |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
244 |
* @return a method type with the given components |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
245 |
* @throws NullPointerException if {@code rtype} or {@code ptype0} or {@code ptypes} or any element of {@code ptypes} is null |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
246 |
* @throws IllegalArgumentException if {@code ptype0} or {@code ptypes} or any element of {@code ptypes} is {@code void.class} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
247 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
248 |
public static |
4537 | 249 |
MethodType methodType(Class<?> rtype, Class<?> ptype0, Class<?>... ptypes) { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
250 |
Class<?>[] ptypes1 = new Class<?>[1+ptypes.length]; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
251 |
ptypes1[0] = ptype0; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
252 |
System.arraycopy(ptypes, 0, ptypes1, 1, ptypes.length); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
253 |
return makeImpl(rtype, ptypes1, true); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
254 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
255 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
256 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
257 |
* Finds or creates a method type with the given components. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
258 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
259 |
* The resulting method has no parameter types. |
18569 | 260 |
* @param rtype the return type |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
261 |
* @return a method type with the given return value |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
262 |
* @throws NullPointerException if {@code rtype} is null |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
263 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
264 |
public static |
4537 | 265 |
MethodType methodType(Class<?> rtype) { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
266 |
return makeImpl(rtype, NO_PTYPES, true); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
267 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
268 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
269 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
270 |
* Finds or creates a method type with the given components. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
271 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
272 |
* The resulting method has the single given parameter type. |
18569 | 273 |
* @param rtype the return type |
274 |
* @param ptype0 the parameter type |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
275 |
* @return a method type with the given return value and parameter type |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
276 |
* @throws NullPointerException if {@code rtype} or {@code ptype0} is null |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
277 |
* @throws IllegalArgumentException if {@code ptype0} is {@code void.class} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
278 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
279 |
public static |
4537 | 280 |
MethodType methodType(Class<?> rtype, Class<?> ptype0) { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
281 |
return makeImpl(rtype, new Class<?>[]{ ptype0 }, true); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
282 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
283 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
284 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
285 |
* Finds or creates a method type with the given components. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
286 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
287 |
* The resulting method has the same parameter types as {@code ptypes}, |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
288 |
* and the specified return type. |
18569 | 289 |
* @param rtype the return type |
290 |
* @param ptypes the method type which supplies the parameter types |
|
291 |
* @return a method type with the given components |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
292 |
* @throws NullPointerException if {@code rtype} or {@code ptypes} is null |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
293 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
294 |
public static |
4537 | 295 |
MethodType methodType(Class<?> rtype, MethodType ptypes) { |
296 |
return makeImpl(rtype, ptypes.ptypes, true); |
|
297 |
} |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
298 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
299 |
/** |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
300 |
* Sole factory method to find or create an interned method type. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
301 |
* @param rtype desired return type |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
302 |
* @param ptypes desired parameter types |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
303 |
* @param trusted whether the ptypes can be used without cloning |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
304 |
* @return the unique method type of the desired structure |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
305 |
*/ |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8348
diff
changeset
|
306 |
/*trusted*/ static |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
307 |
MethodType makeImpl(Class<?> rtype, Class<?>[] ptypes, boolean trusted) { |
9731
d0f7a3e441c4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
9646
diff
changeset
|
308 |
if (ptypes.length == 0) { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
309 |
ptypes = NO_PTYPES; trusted = true; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
310 |
} |
48250
739aa297c260
8187254: MethodType allows unvalidated parameter types
psandoz
parents:
47250
diff
changeset
|
311 |
MethodType primordialMT = new MethodType(rtype, ptypes); |
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
312 |
MethodType mt = internTable.get(primordialMT); |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
313 |
if (mt != null) |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
314 |
return mt; |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
315 |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
316 |
// promote the object to the Real Thing, and reprobe |
48250
739aa297c260
8187254: MethodType allows unvalidated parameter types
psandoz
parents:
47250
diff
changeset
|
317 |
MethodType.checkRtype(rtype); |
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
318 |
if (trusted) { |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
319 |
MethodType.checkPtypes(ptypes); |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
320 |
mt = primordialMT; |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
321 |
} else { |
48250
739aa297c260
8187254: MethodType allows unvalidated parameter types
psandoz
parents:
47250
diff
changeset
|
322 |
// Make defensive copy then validate |
739aa297c260
8187254: MethodType allows unvalidated parameter types
psandoz
parents:
47250
diff
changeset
|
323 |
ptypes = Arrays.copyOf(ptypes, ptypes.length); |
739aa297c260
8187254: MethodType allows unvalidated parameter types
psandoz
parents:
47250
diff
changeset
|
324 |
MethodType.checkPtypes(ptypes); |
739aa297c260
8187254: MethodType allows unvalidated parameter types
psandoz
parents:
47250
diff
changeset
|
325 |
mt = new MethodType(rtype, ptypes); |
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
326 |
} |
21604
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
327 |
mt.form = MethodTypeForm.findForm(mt); |
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
328 |
return internTable.add(mt); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
329 |
} |
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
330 |
private static final @Stable MethodType[] objectOnlyTypes = new MethodType[20]; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
331 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
332 |
/** |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
333 |
* Finds or creates a method type whose components are {@code Object} with an optional trailing {@code Object[]} array. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
334 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
4537 | 335 |
* All parameters and the return type will be {@code Object}, |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
336 |
* except the final array parameter if any, which will be {@code Object[]}. |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
337 |
* @param objectArgCount number of parameters (excluding the final array parameter if any) |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
338 |
* @param finalArray whether there will be a trailing array parameter, of type {@code Object[]} |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
339 |
* @return a generally applicable method type, for all calls of the given fixed argument count and a collected array of further arguments |
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
340 |
* @throws IllegalArgumentException if {@code objectArgCount} is negative or greater than 255 (or 254, if {@code finalArray} is true) |
4537 | 341 |
* @see #genericMethodType(int) |
2707
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 |
public static |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
344 |
MethodType genericMethodType(int objectArgCount, boolean finalArray) { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
345 |
MethodType mt; |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
346 |
checkSlotCount(objectArgCount); |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
347 |
int ivarargs = (!finalArray ? 0 : 1); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
348 |
int ootIndex = objectArgCount*2 + ivarargs; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
349 |
if (ootIndex < objectOnlyTypes.length) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
350 |
mt = objectOnlyTypes[ootIndex]; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
351 |
if (mt != null) return mt; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
352 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
353 |
Class<?>[] ptypes = new Class<?>[objectArgCount + ivarargs]; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
354 |
Arrays.fill(ptypes, Object.class); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
355 |
if (ivarargs != 0) ptypes[objectArgCount] = Object[].class; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
356 |
mt = makeImpl(Object.class, ptypes, true); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
357 |
if (ootIndex < objectOnlyTypes.length) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
358 |
objectOnlyTypes[ootIndex] = mt; // cache it here also! |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
359 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
360 |
return mt; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
361 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
362 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
363 |
/** |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
364 |
* Finds or creates a method type whose components are all {@code Object}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
365 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
366 |
* All parameters and the return type will be Object. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
367 |
* @param objectArgCount number of parameters |
9645
dabb5e4edc4c
7034977: JSR 292 MethodHandle.invokeGeneric should be renamed MethodHandle.invoke
jrose
parents:
8822
diff
changeset
|
368 |
* @return a generally applicable method type, for all calls of the given argument count |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
369 |
* @throws IllegalArgumentException if {@code objectArgCount} is negative or greater than 255 |
4537 | 370 |
* @see #genericMethodType(int, boolean) |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
371 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
372 |
public static |
4537 | 373 |
MethodType genericMethodType(int objectArgCount) { |
374 |
return genericMethodType(objectArgCount, false); |
|
375 |
} |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
376 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
377 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
378 |
* Finds or creates a method type with a single different parameter type. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
379 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
380 |
* @param num the index (zero-based) of the parameter type to change |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
381 |
* @param nptype a new parameter type to replace the old one with |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
382 |
* @return the same type, except with the selected parameter changed |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
383 |
* @throws IndexOutOfBoundsException if {@code num} is not a valid index into {@code parameterArray()} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
384 |
* @throws IllegalArgumentException if {@code nptype} is {@code void.class} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
385 |
* @throws NullPointerException if {@code nptype} is null |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
386 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
387 |
public MethodType changeParameterType(int num, Class<?> nptype) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
388 |
if (parameterType(num) == nptype) return this; |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
389 |
checkPtype(nptype); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
390 |
Class<?>[] nptypes = ptypes.clone(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
391 |
nptypes[num] = nptype; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
392 |
return makeImpl(rtype, nptypes, true); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
393 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
394 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
395 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
396 |
* Finds or creates a method type with additional parameter types. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
397 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
4537 | 398 |
* @param num the position (zero-based) of the inserted parameter type(s) |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
399 |
* @param ptypesToInsert zero or more new parameter types to insert into the parameter list |
4537 | 400 |
* @return the same type, except with the selected parameter(s) inserted |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
401 |
* @throws IndexOutOfBoundsException if {@code num} is negative or greater than {@code parameterCount()} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
402 |
* @throws IllegalArgumentException if any element of {@code ptypesToInsert} is {@code void.class} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
403 |
* or if the resulting method type would have more than 255 parameter slots |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
404 |
* @throws NullPointerException if {@code ptypesToInsert} or any of its elements is null |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
405 |
*/ |
4537 | 406 |
public MethodType insertParameterTypes(int num, Class<?>... ptypesToInsert) { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
407 |
int len = ptypes.length; |
4537 | 408 |
if (num < 0 || num > len) |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
409 |
throw newIndexOutOfBoundsException(num); |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
410 |
int ins = checkPtypes(ptypesToInsert); |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
411 |
checkSlotCount(parameterSlotCount() + ptypesToInsert.length + ins); |
4537 | 412 |
int ilen = ptypesToInsert.length; |
413 |
if (ilen == 0) return this; |
|
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
414 |
Class<?>[] nptypes = new Class<?>[len + ilen]; |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
415 |
if (num > 0) { |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
416 |
System.arraycopy(ptypes, 0, nptypes, 0, num); |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
417 |
} |
4537 | 418 |
System.arraycopy(ptypesToInsert, 0, nptypes, num, ilen); |
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
419 |
if (num < len) { |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
420 |
System.arraycopy(ptypes, num, nptypes, num+ilen, len-num); |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
421 |
} |
4537 | 422 |
return makeImpl(rtype, nptypes, true); |
423 |
} |
|
424 |
||
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
425 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
426 |
* Finds or creates a method type with additional parameter types. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
427 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
428 |
* @param ptypesToInsert zero or more new parameter types to insert after the end of the parameter list |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7052
diff
changeset
|
429 |
* @return the same type, except with the selected parameter(s) appended |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
430 |
* @throws IllegalArgumentException if any element of {@code ptypesToInsert} is {@code void.class} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
431 |
* or if the resulting method type would have more than 255 parameter slots |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
432 |
* @throws NullPointerException if {@code ptypesToInsert} or any of its elements is null |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7052
diff
changeset
|
433 |
*/ |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7052
diff
changeset
|
434 |
public MethodType appendParameterTypes(Class<?>... ptypesToInsert) { |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7052
diff
changeset
|
435 |
return insertParameterTypes(parameterCount(), ptypesToInsert); |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7052
diff
changeset
|
436 |
} |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7052
diff
changeset
|
437 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
438 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
439 |
* Finds or creates a method type with additional parameter types. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
440 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
441 |
* @param num the position (zero-based) of the inserted parameter type(s) |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
442 |
* @param ptypesToInsert zero or more new parameter types to insert into the parameter list |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
443 |
* @return the same type, except with the selected parameter(s) inserted |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
444 |
* @throws IndexOutOfBoundsException if {@code num} is negative or greater than {@code parameterCount()} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
445 |
* @throws IllegalArgumentException if any element of {@code ptypesToInsert} is {@code void.class} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
446 |
* or if the resulting method type would have more than 255 parameter slots |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
447 |
* @throws NullPointerException if {@code ptypesToInsert} or any of its elements is null |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
448 |
*/ |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
449 |
public MethodType insertParameterTypes(int num, List<Class<?>> ptypesToInsert) { |
9731
d0f7a3e441c4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
9646
diff
changeset
|
450 |
return insertParameterTypes(num, listToArray(ptypesToInsert)); |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
451 |
} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
452 |
|
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
453 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
454 |
* Finds or creates a method type with additional parameter types. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
455 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
456 |
* @param ptypesToInsert zero or more new parameter types to insert after the end of the parameter list |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
457 |
* @return the same type, except with the selected parameter(s) appended |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
458 |
* @throws IllegalArgumentException if any element of {@code ptypesToInsert} is {@code void.class} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
459 |
* or if the resulting method type would have more than 255 parameter slots |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
460 |
* @throws NullPointerException if {@code ptypesToInsert} or any of its elements is null |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
461 |
*/ |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
462 |
public MethodType appendParameterTypes(List<Class<?>> ptypesToInsert) { |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
463 |
return insertParameterTypes(parameterCount(), ptypesToInsert); |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
464 |
} |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
465 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
466 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
467 |
* Finds or creates a method type with modified parameter types. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
468 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
469 |
* @param start the position (zero-based) of the first replaced parameter type(s) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
470 |
* @param end the position (zero-based) after the last replaced parameter type(s) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
471 |
* @param ptypesToInsert zero or more new parameter types to insert into the parameter list |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
472 |
* @return the same type, except with the selected parameter(s) replaced |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
473 |
* @throws IndexOutOfBoundsException if {@code start} is negative or greater than {@code parameterCount()} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
474 |
* or if {@code end} is negative or greater than {@code parameterCount()} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
475 |
* or if {@code start} is greater than {@code end} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
476 |
* @throws IllegalArgumentException if any element of {@code ptypesToInsert} is {@code void.class} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
477 |
* or if the resulting method type would have more than 255 parameter slots |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
478 |
* @throws NullPointerException if {@code ptypesToInsert} or any of its elements is null |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
479 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
480 |
/*non-public*/ MethodType replaceParameterTypes(int start, int end, Class<?>... ptypesToInsert) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
481 |
if (start == end) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
482 |
return insertParameterTypes(start, ptypesToInsert); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
483 |
int len = ptypes.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
484 |
if (!(0 <= start && start <= end && end <= len)) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
485 |
throw newIndexOutOfBoundsException("start="+start+" end="+end); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
486 |
int ilen = ptypesToInsert.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
487 |
if (ilen == 0) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
488 |
return dropParameterTypes(start, end); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
489 |
return dropParameterTypes(start, end).insertParameterTypes(start, ptypesToInsert); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
490 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
491 |
|
26468 | 492 |
/** Replace the last arrayLength parameter types with the component type of arrayType. |
493 |
* @param arrayType any array type |
|
33874
46651fd30c0b
8139885: implement JEP 274: enhanced method handles
mhaupt
parents:
33526
diff
changeset
|
494 |
* @param pos position at which to spread |
26468 | 495 |
* @param arrayLength the number of parameter types to change |
496 |
* @return the resulting type |
|
497 |
*/ |
|
33874
46651fd30c0b
8139885: implement JEP 274: enhanced method handles
mhaupt
parents:
33526
diff
changeset
|
498 |
/*non-public*/ MethodType asSpreaderType(Class<?> arrayType, int pos, int arrayLength) { |
26468 | 499 |
assert(parameterCount() >= arrayLength); |
33874
46651fd30c0b
8139885: implement JEP 274: enhanced method handles
mhaupt
parents:
33526
diff
changeset
|
500 |
int spreadPos = pos; |
26468 | 501 |
if (arrayLength == 0) return this; // nothing to change |
502 |
if (arrayType == Object[].class) { |
|
503 |
if (isGeneric()) return this; // nothing to change |
|
504 |
if (spreadPos == 0) { |
|
505 |
// no leading arguments to preserve; go generic |
|
506 |
MethodType res = genericMethodType(arrayLength); |
|
507 |
if (rtype != Object.class) { |
|
508 |
res = res.changeReturnType(rtype); |
|
509 |
} |
|
510 |
return res; |
|
511 |
} |
|
512 |
} |
|
513 |
Class<?> elemType = arrayType.getComponentType(); |
|
514 |
assert(elemType != null); |
|
33874
46651fd30c0b
8139885: implement JEP 274: enhanced method handles
mhaupt
parents:
33526
diff
changeset
|
515 |
for (int i = spreadPos; i < spreadPos + arrayLength; i++) { |
26468 | 516 |
if (ptypes[i] != elemType) { |
517 |
Class<?>[] fixedPtypes = ptypes.clone(); |
|
33874
46651fd30c0b
8139885: implement JEP 274: enhanced method handles
mhaupt
parents:
33526
diff
changeset
|
518 |
Arrays.fill(fixedPtypes, i, spreadPos + arrayLength, elemType); |
26468 | 519 |
return methodType(rtype, fixedPtypes); |
520 |
} |
|
521 |
} |
|
522 |
return this; // arguments check out; no change |
|
523 |
} |
|
524 |
||
26469
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26468
diff
changeset
|
525 |
/** Return the leading parameter type, which must exist and be a reference. |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26468
diff
changeset
|
526 |
* @return the leading parameter type, after error checks |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26468
diff
changeset
|
527 |
*/ |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26468
diff
changeset
|
528 |
/*non-public*/ Class<?> leadingReferenceParameter() { |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26468
diff
changeset
|
529 |
Class<?> ptype; |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26468
diff
changeset
|
530 |
if (ptypes.length == 0 || |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26468
diff
changeset
|
531 |
(ptype = ptypes[0]).isPrimitive()) |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26468
diff
changeset
|
532 |
throw newIllegalArgumentException("no leading reference parameter"); |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26468
diff
changeset
|
533 |
return ptype; |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26468
diff
changeset
|
534 |
} |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26468
diff
changeset
|
535 |
|
26475
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
536 |
/** Delete the last parameter type and replace it with arrayLength copies of the component type of arrayType. |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
537 |
* @param arrayType any array type |
33874
46651fd30c0b
8139885: implement JEP 274: enhanced method handles
mhaupt
parents:
33526
diff
changeset
|
538 |
* @param pos position at which to insert parameters |
26475
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
539 |
* @param arrayLength the number of parameter types to insert |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
540 |
* @return the resulting type |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
541 |
*/ |
33874
46651fd30c0b
8139885: implement JEP 274: enhanced method handles
mhaupt
parents:
33526
diff
changeset
|
542 |
/*non-public*/ MethodType asCollectorType(Class<?> arrayType, int pos, int arrayLength) { |
26475
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
543 |
assert(parameterCount() >= 1); |
33874
46651fd30c0b
8139885: implement JEP 274: enhanced method handles
mhaupt
parents:
33526
diff
changeset
|
544 |
assert(pos < ptypes.length); |
46651fd30c0b
8139885: implement JEP 274: enhanced method handles
mhaupt
parents:
33526
diff
changeset
|
545 |
assert(ptypes[pos].isAssignableFrom(arrayType)); |
26475
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
546 |
MethodType res; |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
547 |
if (arrayType == Object[].class) { |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
548 |
res = genericMethodType(arrayLength); |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
549 |
if (rtype != Object.class) { |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
550 |
res = res.changeReturnType(rtype); |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
551 |
} |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
552 |
} else { |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
553 |
Class<?> elemType = arrayType.getComponentType(); |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
554 |
assert(elemType != null); |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
555 |
res = methodType(rtype, Collections.nCopies(arrayLength, elemType)); |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
556 |
} |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
557 |
if (ptypes.length == 1) { |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
558 |
return res; |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
559 |
} else { |
33874
46651fd30c0b
8139885: implement JEP 274: enhanced method handles
mhaupt
parents:
33526
diff
changeset
|
560 |
// insert after (if need be), then before |
40272
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
36934
diff
changeset
|
561 |
if (pos < ptypes.length - 1) { |
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
36934
diff
changeset
|
562 |
res = res.insertParameterTypes(arrayLength, Arrays.copyOfRange(ptypes, pos + 1, ptypes.length)); |
33874
46651fd30c0b
8139885: implement JEP 274: enhanced method handles
mhaupt
parents:
33526
diff
changeset
|
563 |
} |
40272
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
36934
diff
changeset
|
564 |
return res.insertParameterTypes(0, Arrays.copyOf(ptypes, pos)); |
26475
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
565 |
} |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
566 |
} |
acf0c98309d3
8050884: Intrinsify ValueConversions.identity() functions
vlivanov
parents:
26470
diff
changeset
|
567 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
568 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
569 |
* Finds or creates a method type with some parameter types omitted. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
570 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
4537 | 571 |
* @param start the index (zero-based) of the first parameter type to remove |
572 |
* @param end the index (greater than {@code start}) of the first parameter type after not to remove |
|
573 |
* @return the same type, except with the selected parameter(s) removed |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
574 |
* @throws IndexOutOfBoundsException if {@code start} is negative or greater than {@code parameterCount()} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
575 |
* or if {@code end} is negative or greater than {@code parameterCount()} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
576 |
* or if {@code start} is greater than {@code end} |
4537 | 577 |
*/ |
578 |
public MethodType dropParameterTypes(int start, int end) { |
|
579 |
int len = ptypes.length; |
|
580 |
if (!(0 <= start && start <= end && end <= len)) |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
581 |
throw newIndexOutOfBoundsException("start="+start+" end="+end); |
4537 | 582 |
if (start == end) return this; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
583 |
Class<?>[] nptypes; |
4537 | 584 |
if (start == 0) { |
585 |
if (end == len) { |
|
586 |
// drop all parameters |
|
587 |
nptypes = NO_PTYPES; |
|
588 |
} else { |
|
589 |
// drop initial parameter(s) |
|
590 |
nptypes = Arrays.copyOfRange(ptypes, end, len); |
|
591 |
} |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
592 |
} else { |
4537 | 593 |
if (end == len) { |
594 |
// drop trailing parameter(s) |
|
595 |
nptypes = Arrays.copyOfRange(ptypes, 0, start); |
|
596 |
} else { |
|
597 |
int tail = len - end; |
|
598 |
nptypes = Arrays.copyOfRange(ptypes, 0, start + tail); |
|
599 |
System.arraycopy(ptypes, end, nptypes, start, tail); |
|
600 |
} |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
601 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
602 |
return makeImpl(rtype, nptypes, true); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
603 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
604 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
605 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
606 |
* Finds or creates a method type with a different return type. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
607 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
608 |
* @param nrtype a return parameter type to replace the old one with |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
609 |
* @return the same type, except with the return type change |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
610 |
* @throws NullPointerException if {@code nrtype} is null |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
611 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
612 |
public MethodType changeReturnType(Class<?> nrtype) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
613 |
if (returnType() == nrtype) return this; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
614 |
return makeImpl(nrtype, ptypes, true); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
615 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
616 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
617 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
618 |
* Reports if this type contains a primitive argument or return value. |
4537 | 619 |
* The return type {@code void} counts as a primitive. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
620 |
* @return true if any of the types are primitives |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
621 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
622 |
public boolean hasPrimitives() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
623 |
return form.hasPrimitives(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
624 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
625 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
626 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
627 |
* Reports if this type contains a wrapper argument or return value. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
628 |
* Wrappers are types which box primitive values, such as {@link Integer}. |
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
629 |
* The reference type {@code java.lang.Void} counts as a wrapper, |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
630 |
* if it occurs as a return type. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
631 |
* @return true if any of the types are wrappers |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
632 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
633 |
public boolean hasWrappers() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
634 |
return unwrap() != this; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
635 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
636 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
637 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
638 |
* Erases all reference types to {@code Object}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
639 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
4537 | 640 |
* All primitive types (including {@code void}) will remain unchanged. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
641 |
* @return a version of the original type with all reference types replaced |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
642 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
643 |
public MethodType erase() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
644 |
return form.erasedType(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
645 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
646 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
647 |
/** |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
648 |
* Erases all reference types to {@code Object}, and all subword types to {@code int}. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
649 |
* This is the reduced type polymorphism used by private methods |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
650 |
* such as {@link MethodHandle#invokeBasic invokeBasic}. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
651 |
* @return a version of the original type with all reference and subword types replaced |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
652 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
653 |
/*non-public*/ MethodType basicType() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
654 |
return form.basicType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
655 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
656 |
|
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
657 |
private static final @Stable Class<?>[] METHOD_HANDLE_ARRAY |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
658 |
= new Class<?>[] { MethodHandle.class }; |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
659 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
660 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
661 |
* @return a version of the original type with MethodHandle prepended as the first argument |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
662 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
663 |
/*non-public*/ MethodType invokerType() { |
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44255
diff
changeset
|
664 |
return insertParameterTypes(0, METHOD_HANDLE_ARRAY); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
665 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
666 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
667 |
/** |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
668 |
* Converts all types, both reference and primitive, to {@code Object}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
669 |
* Convenience method for {@link #genericMethodType(int) genericMethodType}. |
4537 | 670 |
* The expression {@code type.wrap().erase()} produces the same value |
671 |
* as {@code type.generic()}. |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
672 |
* @return a version of the original type with all types replaced |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
673 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
674 |
public MethodType generic() { |
4537 | 675 |
return genericMethodType(parameterCount()); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
676 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
677 |
|
26468 | 678 |
/*non-public*/ boolean isGeneric() { |
679 |
return this == erase() && !hasPrimitives(); |
|
680 |
} |
|
681 |
||
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
682 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
683 |
* Converts all primitive types to their corresponding wrapper types. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
684 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
4537 | 685 |
* All reference types (including wrapper types) will remain unchanged. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
686 |
* A {@code void} return type is changed to the type {@code java.lang.Void}. |
4537 | 687 |
* The expression {@code type.wrap().erase()} produces the same value |
688 |
* as {@code type.generic()}. |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
689 |
* @return a version of the original type with all primitive types replaced |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
690 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
691 |
public MethodType wrap() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
692 |
return hasPrimitives() ? wrapWithPrims(this) : this; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
693 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
694 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
695 |
/** |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
696 |
* Converts all wrapper types to their corresponding primitive types. |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
697 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
4537 | 698 |
* All primitive types (including {@code void}) will remain unchanged. |
2763 | 699 |
* A return type of {@code java.lang.Void} is changed to {@code void}. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
700 |
* @return a version of the original type with all wrapper types replaced |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
701 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
702 |
public MethodType unwrap() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
703 |
MethodType noprims = !hasPrimitives() ? this : wrapWithPrims(this); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
704 |
return unwrapWithNoPrims(noprims); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
705 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
706 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
707 |
private static MethodType wrapWithPrims(MethodType pt) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
708 |
assert(pt.hasPrimitives()); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
709 |
MethodType wt = pt.wrapAlt; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
710 |
if (wt == null) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
711 |
// fill in lazily |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8348
diff
changeset
|
712 |
wt = MethodTypeForm.canonicalize(pt, MethodTypeForm.WRAP, MethodTypeForm.WRAP); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
713 |
assert(wt != null); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
714 |
pt.wrapAlt = wt; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
715 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
716 |
return wt; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
717 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
718 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
719 |
private static MethodType unwrapWithNoPrims(MethodType wt) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
720 |
assert(!wt.hasPrimitives()); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
721 |
MethodType uwt = wt.wrapAlt; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
722 |
if (uwt == null) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
723 |
// fill in lazily |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8348
diff
changeset
|
724 |
uwt = MethodTypeForm.canonicalize(wt, MethodTypeForm.UNWRAP, MethodTypeForm.UNWRAP); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
725 |
if (uwt == null) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
726 |
uwt = wt; // type has no wrappers or prims at all |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
727 |
wt.wrapAlt = uwt; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
728 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
729 |
return uwt; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
730 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
731 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
732 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
733 |
* Returns the parameter type at the specified index, within this method type. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
734 |
* @param num the index (zero-based) of the desired parameter type |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
735 |
* @return the selected parameter type |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
736 |
* @throws IndexOutOfBoundsException if {@code num} is not a valid index into {@code parameterArray()} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
737 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
738 |
public Class<?> parameterType(int num) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
739 |
return ptypes[num]; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
740 |
} |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
741 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
742 |
* Returns the number of parameter types in this method type. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
743 |
* @return the number of parameter types |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
744 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
745 |
public int parameterCount() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
746 |
return ptypes.length; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
747 |
} |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
748 |
/** |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
749 |
* Returns the return type of this method type. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
750 |
* @return the return type |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
751 |
*/ |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
752 |
public Class<?> returnType() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
753 |
return rtype; |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
754 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
755 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
756 |
/** |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
757 |
* Presents the parameter types as a list (a convenience method). |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
758 |
* The list will be immutable. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
759 |
* @return the parameter types (as an immutable list) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
760 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
761 |
public List<Class<?>> parameterList() { |
27071
887188b74516
8041529: Better parameterization of parameter lists
kizune
parents:
26625
diff
changeset
|
762 |
return Collections.unmodifiableList(Arrays.asList(ptypes.clone())); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
763 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
764 |
|
47250
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
765 |
/** |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
766 |
* Returns the last parameter type of this method type. |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
767 |
* If this type has no parameters, the sentinel value |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
768 |
* {@code void.class} is returned instead. |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
769 |
* @apiNote |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
770 |
* <p> |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
771 |
* The sentinel value is chosen so that reflective queries can be |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
772 |
* made directly against the result value. |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
773 |
* The sentinel value cannot be confused with a real parameter, |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
774 |
* since {@code void} is never acceptable as a parameter type. |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
775 |
* For variable arity invocation modes, the expression |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
776 |
* {@link Class#getComponentType lastParameterType().getComponentType()} |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
777 |
* is useful to query the type of the "varargs" parameter. |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
778 |
* @return the last parameter type if any, else {@code void.class} |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
779 |
* @since 10 |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
780 |
*/ |
a0f26f0da4f1
8185993: MethodHandle.invokeWithArguments jumbo-arity
jrose
parents:
47216
diff
changeset
|
781 |
public Class<?> lastParameterType() { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
782 |
int len = ptypes.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
783 |
return len == 0 ? void.class : ptypes[len-1]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
784 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
785 |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
786 |
/** |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
787 |
* Presents the parameter types as an array (a convenience method). |
4537 | 788 |
* Changes to the array will not result in changes to the type. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
789 |
* @return the parameter types (as a fresh copy if necessary) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
790 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
791 |
public Class<?>[] parameterArray() { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
792 |
return ptypes.clone(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
793 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
794 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
795 |
/** |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
796 |
* Compares the specified object with this type for equality. |
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
28059
diff
changeset
|
797 |
* That is, it returns {@code true} if and only if the specified object |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
798 |
* is also a method type with exactly the same parameters and return type. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
799 |
* @param x object to compare |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
800 |
* @see Object#equals(Object) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
801 |
*/ |
51445
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
802 |
// This implementation may also return true if x is a WeakEntry containing |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
803 |
// a method type that is equal to this. This is an internal implementation |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
804 |
// detail to allow for faster method type lookups. |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
805 |
// See ConcurrentWeakInternSet.WeakEntry#equals(Object) |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
806 |
@Override |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
807 |
public boolean equals(Object x) { |
51445
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
808 |
if (this == x) { |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
809 |
return true; |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
810 |
} |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
811 |
if (x instanceof MethodType) { |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
812 |
return equals((MethodType)x); |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
813 |
} |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
814 |
if (x instanceof ConcurrentWeakInternSet.WeakEntry) { |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
815 |
Object o = ((ConcurrentWeakInternSet.WeakEntry)x).get(); |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
816 |
if (o instanceof MethodType) { |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
817 |
return equals((MethodType)o); |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
818 |
} |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
819 |
} |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
820 |
return false; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
821 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
822 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
823 |
private boolean equals(MethodType that) { |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
824 |
return this.rtype == that.rtype |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
825 |
&& Arrays.equals(this.ptypes, that.ptypes); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
826 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
827 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
828 |
/** |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
829 |
* Returns the hash code value for this method type. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
830 |
* It is defined to be the same as the hashcode of a List |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
831 |
* whose elements are the return type followed by the |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
832 |
* parameter types. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
833 |
* @return the hash code value for this method type |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
834 |
* @see Object#hashCode() |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
835 |
* @see #equals(Object) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
836 |
* @see List#hashCode() |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
837 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
838 |
@Override |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
839 |
public int hashCode() { |
51445
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
840 |
int hashCode = 31 + rtype.hashCode(); |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
841 |
for (Class<?> ptype : ptypes) |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
842 |
hashCode = 31 * hashCode + ptype.hashCode(); |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
843 |
return hashCode; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
844 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
845 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
846 |
/** |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
847 |
* Returns a string representation of the method type, |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
848 |
* of the form {@code "(PT0,PT1...)RT"}. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
849 |
* The string representation of a method type is a |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
850 |
* parenthesis enclosed, comma separated list of type names, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
851 |
* followed immediately by the return type. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
852 |
* <p> |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
853 |
* Each type is represented by its |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7555
diff
changeset
|
854 |
* {@link java.lang.Class#getSimpleName simple name}. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
855 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
856 |
@Override |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
857 |
public String toString() { |
26219
1a19360ff122
8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents:
25859
diff
changeset
|
858 |
StringJoiner sj = new StringJoiner(",", "(", |
1a19360ff122
8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents:
25859
diff
changeset
|
859 |
")" + rtype.getSimpleName()); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
860 |
for (int i = 0; i < ptypes.length; i++) { |
26219
1a19360ff122
8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents:
25859
diff
changeset
|
861 |
sj.add(ptypes[i].getSimpleName()); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
862 |
} |
26219
1a19360ff122
8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents:
25859
diff
changeset
|
863 |
return sj.toString(); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
864 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
865 |
|
41207
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
866 |
/** True if my parameter list is effectively identical to the given full list, |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
867 |
* after skipping the given number of my own initial parameters. |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
868 |
* In other words, after disregarding {@code skipPos} parameters, |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
869 |
* my remaining parameter list is no longer than the {@code fullList}, and |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
870 |
* is equal to the same-length initial sublist of {@code fullList}. |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
871 |
*/ |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
872 |
/*non-public*/ |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
873 |
boolean effectivelyIdenticalParameters(int skipPos, List<Class<?>> fullList) { |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
874 |
int myLen = ptypes.length, fullLen = fullList.size(); |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
875 |
if (skipPos > myLen || myLen - skipPos > fullLen) |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
876 |
return false; |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
877 |
List<Class<?>> myList = Arrays.asList(ptypes); |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
878 |
if (skipPos != 0) { |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
879 |
myList = myList.subList(skipPos, myLen); |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
880 |
myLen -= skipPos; |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
881 |
} |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
882 |
if (fullLen == myLen) |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
883 |
return myList.equals(fullList); |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
884 |
else |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
885 |
return myList.equals(fullList.subList(0, myLen)); |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
886 |
} |
813a335bcb0c
8151179: address issues raised by JCK team on JEP 274 API
mhaupt
parents:
40272
diff
changeset
|
887 |
|
26470
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
888 |
/** True if the old return type can always be viewed (w/o casting) under new return type, |
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
889 |
* and the new parameters can be viewed (w/o casting) under the old parameter types. |
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
890 |
*/ |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
891 |
/*non-public*/ |
26470
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
892 |
boolean isViewableAs(MethodType newType, boolean keepInterfaces) { |
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
893 |
if (!VerifyType.isNullConversion(returnType(), newType.returnType(), keepInterfaces)) |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
894 |
return false; |
26470
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
895 |
if (form == newType.form && form.erasedType == this) |
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
896 |
return true; // my reference parameters are all Object |
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
897 |
if (ptypes == newType.ptypes) |
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
898 |
return true; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
899 |
int argc = parameterCount(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
900 |
if (argc != newType.parameterCount()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
901 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
902 |
for (int i = 0; i < argc; i++) { |
26470
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
903 |
if (!VerifyType.isNullConversion(newType.parameterType(i), parameterType(i), keepInterfaces)) |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
904 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
905 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
906 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
907 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
908 |
/*non-public*/ |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
909 |
boolean isConvertibleTo(MethodType newType) { |
26478
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
910 |
MethodTypeForm oldForm = this.form(); |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
911 |
MethodTypeForm newForm = newType.form(); |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
912 |
if (oldForm == newForm) |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
913 |
// same parameter count, same primitive/object mix |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
914 |
return true; |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
915 |
if (!canConvert(returnType(), newType.returnType())) |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
916 |
return false; |
26478
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
917 |
Class<?>[] srcTypes = newType.ptypes; |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
918 |
Class<?>[] dstTypes = ptypes; |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
919 |
if (srcTypes == dstTypes) |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
920 |
return true; |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
921 |
int argc; |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
922 |
if ((argc = srcTypes.length) != dstTypes.length) |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
923 |
return false; |
26478
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
924 |
if (argc <= 1) { |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
925 |
if (argc == 1 && !canConvert(srcTypes[0], dstTypes[0])) |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
926 |
return false; |
26478
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
927 |
return true; |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
928 |
} |
58038 | 929 |
if ((!oldForm.hasPrimitives() && oldForm.erasedType == this) || |
930 |
(!newForm.hasPrimitives() && newForm.erasedType == newType)) { |
|
26478
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
931 |
// Somewhat complicated test to avoid a loop of 2 or more trips. |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
932 |
// If either type has only Object parameters, we know we can convert. |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
933 |
assert(canConvertParameters(srcTypes, dstTypes)); |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
934 |
return true; |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
935 |
} |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
936 |
return canConvertParameters(srcTypes, dstTypes); |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
937 |
} |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
938 |
|
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
939 |
/** Returns true if MHs.explicitCastArguments produces the same result as MH.asType. |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
940 |
* If the type conversion is impossible for either, the result should be false. |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
941 |
*/ |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
942 |
/*non-public*/ |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
943 |
boolean explicitCastEquivalentToAsType(MethodType newType) { |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
944 |
if (this == newType) return true; |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
945 |
if (!explicitCastEquivalentToAsType(rtype, newType.rtype)) { |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
946 |
return false; |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
947 |
} |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
948 |
Class<?>[] srcTypes = newType.ptypes; |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
949 |
Class<?>[] dstTypes = ptypes; |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
950 |
if (dstTypes == srcTypes) { |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
951 |
return true; |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
952 |
} |
26625
cbeb3711fa94
8058291: Missing some checks during parameter validation
vlivanov
parents:
26478
diff
changeset
|
953 |
assert(dstTypes.length == srcTypes.length); |
26478
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
954 |
for (int i = 0; i < dstTypes.length; i++) { |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
955 |
if (!explicitCastEquivalentToAsType(srcTypes[i], dstTypes[i])) { |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
956 |
return false; |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
957 |
} |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
958 |
} |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
959 |
return true; |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
960 |
} |
26478
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
961 |
|
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
962 |
/** Reports true if the src can be converted to the dst, by both asType and MHs.eCE, |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
963 |
* and with the same effect. |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
964 |
* MHs.eCA has the following "upgrades" to MH.asType: |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
965 |
* 1. interfaces are unchecked (that is, treated as if aliased to Object) |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
966 |
* Therefore, {@code Object->CharSequence} is possible in both cases but has different semantics |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
967 |
* 2. the full matrix of primitive-to-primitive conversions is supported |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
968 |
* Narrowing like {@code long->byte} and basic-typing like {@code boolean->int} |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
969 |
* are not supported by asType, but anything supported by asType is equivalent |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
970 |
* with MHs.eCE. |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
971 |
* 3a. unboxing conversions can be followed by the full matrix of primitive conversions |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
972 |
* 3b. unboxing of null is permitted (creates a zero primitive value) |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
973 |
* Other than interfaces, reference-to-reference conversions are the same. |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
974 |
* Boxing primitives to references is the same for both operators. |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
975 |
*/ |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
976 |
private static boolean explicitCastEquivalentToAsType(Class<?> src, Class<?> dst) { |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
977 |
if (src == dst || dst == Object.class || dst == void.class) return true; |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
978 |
if (src.isPrimitive()) { |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
979 |
// Could be a prim/prim conversion, where casting is a strict superset. |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
980 |
// Or a boxing conversion, which is always to an exact wrapper class. |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
981 |
return canConvert(src, dst); |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
982 |
} else if (dst.isPrimitive()) { |
27196
fe9dbab34d1d
8060483: NPE with explicitCastArguments unboxing null
vlivanov
parents:
27071
diff
changeset
|
983 |
// Unboxing behavior is different between MHs.eCA & MH.asType (see 3b). |
fe9dbab34d1d
8060483: NPE with explicitCastArguments unboxing null
vlivanov
parents:
27071
diff
changeset
|
984 |
return false; |
26478
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
985 |
} else { |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
986 |
// R->R always works, but we have to avoid a check-cast to an interface. |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
987 |
return !dst.isInterface() || dst.isAssignableFrom(src); |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
988 |
} |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
989 |
} |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
990 |
|
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
991 |
private boolean canConvertParameters(Class<?>[] srcTypes, Class<?>[] dstTypes) { |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
992 |
for (int i = 0; i < srcTypes.length; i++) { |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
993 |
if (!canConvert(srcTypes[i], dstTypes[i])) { |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
994 |
return false; |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
995 |
} |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
996 |
} |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
997 |
return true; |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
998 |
} |
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
999 |
|
9731
d0f7a3e441c4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
9646
diff
changeset
|
1000 |
/*non-public*/ |
d0f7a3e441c4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
9646
diff
changeset
|
1001 |
static boolean canConvert(Class<?> src, Class<?> dst) { |
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1002 |
// short-circuit a few cases: |
26478
285691ed55e4
8057656: Improve MethodType.isCastableTo() & MethodType.isConvertibleTo() checks
vlivanov
parents:
26475
diff
changeset
|
1003 |
if (src == dst || src == Object.class || dst == Object.class) return true; |
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1004 |
// the remainder of this logic is documented in MethodHandle.asType |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1005 |
if (src.isPrimitive()) { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1006 |
// can force void to an explicit null, a la reflect.Method.invoke |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1007 |
// can also force void to a primitive zero, by analogy |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1008 |
if (src == void.class) return true; //or !dst.isPrimitive()? |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1009 |
Wrapper sw = Wrapper.forPrimitiveType(src); |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1010 |
if (dst.isPrimitive()) { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1011 |
// P->P must widen |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1012 |
return Wrapper.forPrimitiveType(dst).isConvertibleFrom(sw); |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1013 |
} else { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1014 |
// P->R must box and widen |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1015 |
return dst.isAssignableFrom(sw.wrapperType()); |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1016 |
} |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1017 |
} else if (dst.isPrimitive()) { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1018 |
// any value can be dropped |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1019 |
if (dst == void.class) return true; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1020 |
Wrapper dw = Wrapper.forPrimitiveType(dst); |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1021 |
// R->P must be able to unbox (from a dynamically chosen type) and widen |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1022 |
// For example: |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1023 |
// Byte/Number/Comparable/Object -> dw:Byte -> byte. |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1024 |
// Character/Comparable/Object -> dw:Character -> char |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1025 |
// Boolean/Comparable/Object -> dw:Boolean -> boolean |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1026 |
// This means that dw must be cast-compatible with src. |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1027 |
if (src.isAssignableFrom(dw.wrapperType())) { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1028 |
return true; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1029 |
} |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1030 |
// The above does not work if the source reference is strongly typed |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1031 |
// to a wrapper whose primitive must be widened. For example: |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1032 |
// Byte -> unbox:byte -> short/int/long/float/double |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1033 |
// Character -> unbox:char -> int/long/float/double |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1034 |
if (Wrapper.isWrapperType(src) && |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1035 |
dw.isConvertibleFrom(Wrapper.forWrapperType(src))) { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1036 |
// can unbox from src and then widen to dst |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1037 |
return true; |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1038 |
} |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1039 |
// We have already covered cases which arise due to runtime unboxing |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1040 |
// of a reference type which covers several wrapper types: |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1041 |
// Object -> cast:Integer -> unbox:int -> long/float/double |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1042 |
// Serializable -> cast:Byte -> unbox:byte -> byte/short/int/long/float/double |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1043 |
// An marginal case is Number -> dw:Character -> char, which would be OK if there were a |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1044 |
// subclass of Number which wraps a value that can convert to char. |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1045 |
// Since there is none, we don't need an extra check here to cover char or boolean. |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
1046 |
return false; |
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1047 |
} else { |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1048 |
// R->R always works, since null is always valid dynamically |
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1049 |
return true; |
9646
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
1050 |
} |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
1051 |
} |
5ebbe5ab084f
6939861: JVM should handle more conversion operations
jrose
parents:
9645
diff
changeset
|
1052 |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1053 |
/// Queries which have to do with the bytecode architecture |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1054 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
1055 |
/** Reports the number of JVM stack slots required to invoke a method |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
1056 |
* of this type. Note that (for historical reasons) the JVM requires |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1057 |
* a second stack slot to pass long and double arguments. |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
1058 |
* So this method returns {@link #parameterCount() parameterCount} plus the |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1059 |
* number of long and double parameters (if any). |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1060 |
* <p> |
21278 | 1061 |
* This method is included for the benefit of applications that must |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1062 |
* generate bytecodes that process method handles and invokedynamic. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1063 |
* @return the number of JVM stack slots for this type's parameters |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1064 |
*/ |
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8348
diff
changeset
|
1065 |
/*non-public*/ int parameterSlotCount() { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1066 |
return form.parameterSlotCount(); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1067 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1068 |
|
8821
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8348
diff
changeset
|
1069 |
/*non-public*/ Invokers invokers() { |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8348
diff
changeset
|
1070 |
Invokers inv = invokers; |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8348
diff
changeset
|
1071 |
if (inv != null) return inv; |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8348
diff
changeset
|
1072 |
invokers = inv = new Invokers(this); |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8348
diff
changeset
|
1073 |
return inv; |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8348
diff
changeset
|
1074 |
} |
2836ee97ee27
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8348
diff
changeset
|
1075 |
|
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
1076 |
/** |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
1077 |
* Finds or creates an instance of a method type, given the spelling of its bytecode descriptor. |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
1078 |
* Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
7052
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
1079 |
* Any class or interface name embedded in the descriptor string |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1080 |
* will be resolved by calling {@link ClassLoader#loadClass(java.lang.String)} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1081 |
* on the given loader (or if it is null, on the system class loader). |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1082 |
* <p> |
7052
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
1083 |
* Note that it is possible to encounter method types which cannot be |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1084 |
* constructed by this method, because their component types are |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1085 |
* not all reachable from a common class loader. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1086 |
* <p> |
21278 | 1087 |
* This method is included for the benefit of applications that must |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
1088 |
* generate bytecodes that process method handles and {@code invokedynamic}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
1089 |
* @param descriptor a bytecode-level type descriptor string "(T...)T" |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1090 |
* @param loader the class loader in which to look up the types |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
1091 |
* @return a method type matching the bytecode-level type descriptor |
9752
88ab34b6da6d
7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents:
9731
diff
changeset
|
1092 |
* @throws NullPointerException if the string is null |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1093 |
* @throws IllegalArgumentException if the string is not well-formed |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1094 |
* @throws TypeNotPresentException if a named type cannot be found |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1095 |
*/ |
4537 | 1096 |
public static MethodType fromMethodDescriptorString(String descriptor, ClassLoader loader) |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1097 |
throws IllegalArgumentException, TypeNotPresentException |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1098 |
{ |
32986
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1099 |
return fromDescriptor(descriptor, |
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1100 |
(loader == null) ? ClassLoader.getSystemClassLoader() : loader); |
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1101 |
} |
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1102 |
|
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1103 |
/** |
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1104 |
* Same as {@link #fromMethodDescriptorString(String, ClassLoader)}, but |
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1105 |
* {@code null} ClassLoader means the bootstrap loader is used here. |
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1106 |
* <p> |
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1107 |
* IMPORTANT: This method is preferable for JDK internal use as it more |
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1108 |
* correctly interprets {@code null} ClassLoader than |
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1109 |
* {@link #fromMethodDescriptorString(String, ClassLoader)}. |
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1110 |
* Use of this method also avoids early initialization issues when system |
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1111 |
* ClassLoader is not initialized yet. |
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1112 |
*/ |
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1113 |
static MethodType fromDescriptor(String descriptor, ClassLoader loader) |
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1114 |
throws IllegalArgumentException, TypeNotPresentException |
ea54ac8672e7
8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents:
32033
diff
changeset
|
1115 |
{ |
9731
d0f7a3e441c4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
9646
diff
changeset
|
1116 |
if (!descriptor.startsWith("(") || // also generates NPE if needed |
d0f7a3e441c4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
9646
diff
changeset
|
1117 |
descriptor.indexOf(')') < 0 || |
d0f7a3e441c4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
9646
diff
changeset
|
1118 |
descriptor.indexOf('.') >= 0) |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1119 |
throw newIllegalArgumentException("not a method descriptor: "+descriptor); |
4537 | 1120 |
List<Class<?>> types = BytecodeDescriptor.parseMethod(descriptor, loader); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1121 |
Class<?> rtype = types.remove(types.size() - 1); |
9731
d0f7a3e441c4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
9646
diff
changeset
|
1122 |
Class<?>[] ptypes = listToArray(types); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1123 |
return makeImpl(rtype, ptypes, true); |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1124 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1125 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1126 |
/** |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
1127 |
* Produces a bytecode descriptor representation of the method type. |
7052
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
1128 |
* <p> |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
1129 |
* Note that this is not a strict inverse of {@link #fromMethodDescriptorString fromMethodDescriptorString}. |
7052
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
1130 |
* Two distinct classes which share a common name but have different class loaders |
963a5baf2ba3
6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents:
5725
diff
changeset
|
1131 |
* will appear identical when viewed within descriptor strings. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1132 |
* <p> |
21278 | 1133 |
* This method is included for the benefit of applications that must |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
1134 |
* generate bytecodes that process method handles and {@code invokedynamic}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
1135 |
* {@link #fromMethodDescriptorString(java.lang.String, java.lang.ClassLoader) fromMethodDescriptorString}, |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1136 |
* because the latter requires a suitable class loader argument. |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
7668
diff
changeset
|
1137 |
* @return the bytecode type descriptor representation |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1138 |
*/ |
4537 | 1139 |
public String toMethodDescriptorString() { |
21604
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
1140 |
String desc = methodDescriptor; |
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
1141 |
if (desc == null) { |
43194
3c8c3c61ae92
8172905: Minor startup cleanup of CallSite and MethodType
redestad
parents:
41207
diff
changeset
|
1142 |
desc = BytecodeDescriptor.unparseMethod(this.rtype, this.ptypes); |
21604
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
1143 |
methodDescriptor = desc; |
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
1144 |
} |
2ad6b165b7d8
8024635: Caching MethodType's descriptor string improves lambda linkage performance
jrose
parents:
20877
diff
changeset
|
1145 |
return desc; |
4537 | 1146 |
} |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1147 |
|
52914 | 1148 |
/** |
1149 |
* Return a field type descriptor string for this type |
|
1150 |
* |
|
1151 |
* @return the descriptor string |
|
1152 |
* @jvms 4.3.2 Field Descriptors |
|
1153 |
* @since 12 |
|
1154 |
*/ |
|
1155 |
@Override |
|
1156 |
public String descriptorString() { |
|
1157 |
return toMethodDescriptorString(); |
|
1158 |
} |
|
1159 |
||
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
1160 |
/*non-public*/ static String toFieldDescriptorString(Class<?> cls) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
1161 |
return BytecodeDescriptor.unparse(cls); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
1162 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13422
diff
changeset
|
1163 |
|
52914 | 1164 |
/** |
1165 |
* Return a nominal descriptor for this instance, if one can be |
|
1166 |
* constructed, or an empty {@link Optional} if one cannot be. |
|
1167 |
* |
|
1168 |
* @return An {@link Optional} containing the resulting nominal descriptor, |
|
1169 |
* or an empty {@link Optional} if one cannot be constructed. |
|
1170 |
* @since 12 |
|
1171 |
*/ |
|
1172 |
@Override |
|
1173 |
public Optional<MethodTypeDesc> describeConstable() { |
|
1174 |
try { |
|
1175 |
return Optional.of(MethodTypeDesc.of(returnType().describeConstable().orElseThrow(), |
|
1176 |
Stream.of(parameterArray()) |
|
1177 |
.map(p -> p.describeConstable().orElseThrow()) |
|
1178 |
.toArray(ClassDesc[]::new))); |
|
1179 |
} |
|
1180 |
catch (NoSuchElementException e) { |
|
1181 |
return Optional.empty(); |
|
1182 |
} |
|
1183 |
} |
|
1184 |
||
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1185 |
/// Serialization. |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1186 |
|
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1187 |
/** |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1188 |
* There are no serializable fields for {@code MethodType}. |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1189 |
*/ |
57956
e0b8b019d2f5
8229997: Apply java.io.Serial annotations in java.base
darcy
parents:
52914
diff
changeset
|
1190 |
@java.io.Serial |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1191 |
private static final java.io.ObjectStreamField[] serialPersistentFields = { }; |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1192 |
|
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1193 |
/** |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1194 |
* Save the {@code MethodType} instance to a stream. |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1195 |
* |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1196 |
* @serialData |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1197 |
* For portability, the serialized format does not refer to named fields. |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1198 |
* Instead, the return type and parameter type arrays are written directly |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1199 |
* from the {@code writeObject} method, using two calls to {@code s.writeObject} |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1200 |
* as follows: |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20494
diff
changeset
|
1201 |
* <blockquote><pre>{@code |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1202 |
s.writeObject(this.returnType()); |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1203 |
s.writeObject(this.parameterArray()); |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20494
diff
changeset
|
1204 |
* }</pre></blockquote> |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1205 |
* <p> |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1206 |
* The deserialized field values are checked as if they were |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1207 |
* provided to the factory method {@link #methodType(Class,Class[]) methodType}. |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1208 |
* For example, null values, or {@code void} parameter types, |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1209 |
* will lead to exceptions during deserialization. |
18569 | 1210 |
* @param s the stream to write the object to |
1211 |
* @throws java.io.IOException if there is a problem writing the object |
|
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1212 |
*/ |
57956
e0b8b019d2f5
8229997: Apply java.io.Serial annotations in java.base
darcy
parents:
52914
diff
changeset
|
1213 |
@java.io.Serial |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1214 |
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1215 |
s.defaultWriteObject(); // requires serialPersistentFields to be an empty array |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1216 |
s.writeObject(returnType()); |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1217 |
s.writeObject(parameterArray()); |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1218 |
} |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1219 |
|
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1220 |
/** |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1221 |
* Reconstitute the {@code MethodType} instance from a stream (that is, |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1222 |
* deserialize it). |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1223 |
* This instance is a scratch object with bogus final fields. |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1224 |
* It provides the parameters to the factory method called by |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1225 |
* {@link #readResolve readResolve}. |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1226 |
* After that call it is discarded. |
18569 | 1227 |
* @param s the stream to read the object from |
1228 |
* @throws java.io.IOException if there is a problem reading the object |
|
1229 |
* @throws ClassNotFoundException if one of the component classes cannot be resolved |
|
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1230 |
* @see #readResolve |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1231 |
* @see #writeObject |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1232 |
*/ |
57956
e0b8b019d2f5
8229997: Apply java.io.Serial annotations in java.base
darcy
parents:
52914
diff
changeset
|
1233 |
@java.io.Serial |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1234 |
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { |
49780 | 1235 |
// Assign temporary defaults in case this object escapes |
1236 |
MethodType_init(void.class, NO_PTYPES); |
|
1237 |
||
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1238 |
s.defaultReadObject(); // requires serialPersistentFields to be an empty array |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1239 |
|
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1240 |
Class<?> returnType = (Class<?>) s.readObject(); |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1241 |
Class<?>[] parameterArray = (Class<?>[]) s.readObject(); |
49780 | 1242 |
parameterArray = parameterArray.clone(); // make sure it is unshared |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1243 |
|
49780 | 1244 |
// Assign deserialized values |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1245 |
MethodType_init(returnType, parameterArray); |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1246 |
} |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1247 |
|
49780 | 1248 |
// Initialization of state for deserialization only |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1249 |
private void MethodType_init(Class<?> rtype, Class<?>[] ptypes) { |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1250 |
// In order to communicate these values to readResolve, we must |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1251 |
// store them into the implementation-specific final fields. |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1252 |
checkRtype(rtype); |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1253 |
checkPtypes(ptypes); |
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
51445
diff
changeset
|
1254 |
UNSAFE.putReference(this, OffsetHolder.rtypeOffset, rtype); |
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
51445
diff
changeset
|
1255 |
UNSAFE.putReference(this, OffsetHolder.ptypesOffset, ptypes); |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1256 |
} |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1257 |
|
33526
e6ea816cd6c6
8141536: MethodType field offset calculation could be lazy
redestad
parents:
32986
diff
changeset
|
1258 |
// Support for resetting final fields while deserializing. Implement Holder |
e6ea816cd6c6
8141536: MethodType field offset calculation could be lazy
redestad
parents:
32986
diff
changeset
|
1259 |
// pattern to make the rarely needed offset calculation lazy. |
e6ea816cd6c6
8141536: MethodType field offset calculation could be lazy
redestad
parents:
32986
diff
changeset
|
1260 |
private static class OffsetHolder { |
46873
7ac2f551b0d6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
44591
diff
changeset
|
1261 |
static final long rtypeOffset |
7ac2f551b0d6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
44591
diff
changeset
|
1262 |
= UNSAFE.objectFieldOffset(MethodType.class, "rtype"); |
7ac2f551b0d6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
44591
diff
changeset
|
1263 |
|
7ac2f551b0d6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
44591
diff
changeset
|
1264 |
static final long ptypesOffset |
7ac2f551b0d6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
44591
diff
changeset
|
1265 |
= UNSAFE.objectFieldOffset(MethodType.class, "ptypes"); |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1266 |
} |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1267 |
|
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1268 |
/** |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1269 |
* Resolves and initializes a {@code MethodType} object |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1270 |
* after serialization. |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1271 |
* @return the fully initialized {@code MethodType} object |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1272 |
*/ |
57956
e0b8b019d2f5
8229997: Apply java.io.Serial annotations in java.base
darcy
parents:
52914
diff
changeset
|
1273 |
@java.io.Serial |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1274 |
private Object readResolve() { |
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1275 |
// Do not use a trusted path for deserialization: |
49780 | 1276 |
// return makeImpl(rtype, ptypes, true); |
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1277 |
// Verify all operands, and make sure ptypes is unshared: |
49780 | 1278 |
try { |
1279 |
return methodType(rtype, ptypes); |
|
1280 |
} finally { |
|
1281 |
// Re-assign defaults in case this object escapes |
|
1282 |
MethodType_init(void.class, NO_PTYPES); |
|
1283 |
} |
|
8348
3b2ac15dfc16
7016261: JSR 292 MethodType objects should be serializable
jrose
parents:
8346
diff
changeset
|
1284 |
} |
13422 | 1285 |
|
1286 |
/** |
|
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1287 |
* Simple implementation of weak concurrent intern set. |
13422 | 1288 |
* |
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1289 |
* @param <T> interned type |
13422 | 1290 |
*/ |
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1291 |
private static class ConcurrentWeakInternSet<T> { |
13422 | 1292 |
|
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1293 |
private final ConcurrentMap<WeakEntry<T>, WeakEntry<T>> map; |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1294 |
private final ReferenceQueue<T> stale; |
13422 | 1295 |
|
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1296 |
public ConcurrentWeakInternSet() { |
43194
3c8c3c61ae92
8172905: Minor startup cleanup of CallSite and MethodType
redestad
parents:
41207
diff
changeset
|
1297 |
this.map = new ConcurrentHashMap<>(512); |
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1298 |
this.stale = new ReferenceQueue<>(); |
13422 | 1299 |
} |
1300 |
||
1301 |
/** |
|
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1302 |
* Get the existing interned element. |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1303 |
* This method returns null if no element is interned. |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1304 |
* |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1305 |
* @param elem element to look up |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1306 |
* @return the interned element |
13422 | 1307 |
*/ |
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1308 |
public T get(T elem) { |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1309 |
if (elem == null) throw new NullPointerException(); |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1310 |
expungeStaleElements(); |
13422 | 1311 |
|
51445
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
1312 |
WeakEntry<T> value = map.get(elem); |
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1313 |
if (value != null) { |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1314 |
T res = value.get(); |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1315 |
if (res != null) { |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1316 |
return res; |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1317 |
} |
13422 | 1318 |
} |
1319 |
return null; |
|
1320 |
} |
|
1321 |
||
1322 |
/** |
|
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1323 |
* Interns the element. |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1324 |
* Always returns non-null element, matching the one in the intern set. |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1325 |
* Under the race against another add(), it can return <i>different</i> |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1326 |
* element, if another thread beats us to interning it. |
13422 | 1327 |
* |
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1328 |
* @param elem element to add |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1329 |
* @return element that was actually added |
13422 | 1330 |
*/ |
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1331 |
public T add(T elem) { |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1332 |
if (elem == null) throw new NullPointerException(); |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1333 |
|
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1334 |
// Playing double race here, and so spinloop is required. |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1335 |
// First race is with two concurrent updaters. |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1336 |
// Second race is with GC purging weak ref under our feet. |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1337 |
// Hopefully, we almost always end up with a single pass. |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1338 |
T interned; |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1339 |
WeakEntry<T> e = new WeakEntry<>(elem, stale); |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1340 |
do { |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1341 |
expungeStaleElements(); |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1342 |
WeakEntry<T> exist = map.putIfAbsent(e, e); |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1343 |
interned = (exist == null) ? elem : exist.get(); |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1344 |
} while (interned == null); |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1345 |
return interned; |
13422 | 1346 |
} |
1347 |
||
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1348 |
private void expungeStaleElements() { |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1349 |
Reference<? extends T> reference; |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1350 |
while ((reference = stale.poll()) != null) { |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1351 |
map.remove(reference); |
13422 | 1352 |
} |
1353 |
} |
|
1354 |
||
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1355 |
private static class WeakEntry<T> extends WeakReference<T> { |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1356 |
|
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1357 |
public final int hashcode; |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1358 |
|
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1359 |
public WeakEntry(T key, ReferenceQueue<T> queue) { |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1360 |
super(key, queue); |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1361 |
hashcode = key.hashCode(); |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1362 |
} |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1363 |
|
51445
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
1364 |
/** |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
1365 |
* This implementation returns {@code true} if {@code obj} is another |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
1366 |
* {@code WeakEntry} whose referent is equals to this referent, or |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
1367 |
* if {@code obj} is equals to the referent of this. This allows |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
1368 |
* lookups to be made without wrapping in a {@code WeakEntry}. |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
1369 |
* |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
1370 |
* @param obj the object to compare |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
1371 |
* @return true if {@code obj} is equals to this or the referent of this |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
1372 |
* @see MethodType#equals(Object) |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
1373 |
* @see Object#equals(Object) |
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
1374 |
*/ |
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1375 |
@Override |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1376 |
public boolean equals(Object obj) { |
51445
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
1377 |
Object mine = get(); |
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1378 |
if (obj instanceof WeakEntry) { |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1379 |
Object that = ((WeakEntry) obj).get(); |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1380 |
return (that == null || mine == null) ? (this == obj) : mine.equals(that); |
13422 | 1381 |
} |
51445
2c4aaa0d56f4
8209633: Avoid creating WeakEntry wrappers when looking up cached MethodType
redestad
parents:
49780
diff
changeset
|
1382 |
return (mine == null) ? (obj == null) : mine.equals(obj); |
13422 | 1383 |
} |
1384 |
||
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1385 |
@Override |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1386 |
public int hashCode() { |
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1387 |
return hashcode; |
13422 | 1388 |
} |
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1389 |
|
13422 | 1390 |
} |
1391 |
} |
|
18180
e0b8c923f35d
7177472: JSR292: MethodType interning penalizes scalability
twisti
parents:
13610
diff
changeset
|
1392 |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1393 |
} |