author | vlivanov |
Wed, 10 Sep 2014 19:19:47 +0400 | |
changeset 26467 | d69abed3a07d |
parent 26464 | 65b37da18e06 |
child 26468 | 2d57604f9299 |
permissions | -rw-r--r-- |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
20535
diff
changeset
|
2 |
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
4 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
10 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
15 |
* accompanied this code). |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
16 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
20 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
23 |
* questions. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
24 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
25 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
26 |
package java.lang.invoke; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
27 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
28 |
import java.lang.annotation.*; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
29 |
import java.lang.reflect.Method; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
30 |
import java.util.Map; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
31 |
import java.util.List; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
32 |
import java.util.Arrays; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
33 |
import java.util.HashMap; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
34 |
import java.util.concurrent.ConcurrentHashMap; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
35 |
import sun.invoke.util.Wrapper; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
36 |
import java.lang.reflect.Field; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
37 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
38 |
import static java.lang.invoke.LambdaForm.BasicType.*; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
39 |
import static java.lang.invoke.MethodHandleStatics.*; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
40 |
import static java.lang.invoke.MethodHandleNatives.Constants.*; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
41 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
42 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
43 |
* The symbolic, non-executable form of a method handle's invocation semantics. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
44 |
* It consists of a series of names. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
45 |
* The first N (N=arity) names are parameters, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
46 |
* while any remaining names are temporary values. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
47 |
* Each temporary specifies the application of a function to some arguments. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
48 |
* The functions are method handles, while the arguments are mixes of |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
49 |
* constant values and local names. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
50 |
* The result of the lambda is defined as one of the names, often the last one. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
51 |
* <p> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
52 |
* Here is an approximate grammar: |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
53 |
* <blockquote><pre>{@code |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
54 |
* LambdaForm = "(" ArgName* ")=>{" TempName* Result "}" |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
55 |
* ArgName = "a" N ":" T |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
56 |
* TempName = "t" N ":" T "=" Function "(" Argument* ");" |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
57 |
* Function = ConstantValue |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
58 |
* Argument = NameRef | ConstantValue |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
59 |
* Result = NameRef | "void" |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
60 |
* NameRef = "a" N | "t" N |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
61 |
* N = (any whole number) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
62 |
* T = "L" | "I" | "J" | "F" | "D" | "V" |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
63 |
* }</pre></blockquote> |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
64 |
* Names are numbered consecutively from left to right starting at zero. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
65 |
* (The letters are merely a taste of syntax sugar.) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
66 |
* Thus, the first temporary (if any) is always numbered N (where N=arity). |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
67 |
* Every occurrence of a name reference in an argument list must refer to |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
68 |
* a name previously defined within the same lambda. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
69 |
* A lambda has a void result if and only if its result index is -1. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
70 |
* If a temporary has the type "V", it cannot be the subject of a NameRef, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
71 |
* even though possesses a number. |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
72 |
* Note that all reference types are erased to "L", which stands for {@code Object}. |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
73 |
* All subword types (boolean, byte, short, char) are erased to "I" which is {@code int}. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
74 |
* The other types stand for the usual primitive types. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
75 |
* <p> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
76 |
* Function invocation closely follows the static rules of the Java verifier. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
77 |
* Arguments and return values must exactly match when their "Name" types are |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
78 |
* considered. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
79 |
* Conversions are allowed only if they do not change the erased type. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
80 |
* <ul> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
81 |
* <li>L = Object: casts are used freely to convert into and out of reference types |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
82 |
* <li>I = int: subword types are forcibly narrowed when passed as arguments (see {@code explicitCastArguments}) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
83 |
* <li>J = long: no implicit conversions |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
84 |
* <li>F = float: no implicit conversions |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
85 |
* <li>D = double: no implicit conversions |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
86 |
* <li>V = void: a function result may be void if and only if its Name is of type "V" |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
87 |
* </ul> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
88 |
* Although implicit conversions are not allowed, explicit ones can easily be |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
89 |
* encoded by using temporary expressions which call type-transformed identity functions. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
90 |
* <p> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
91 |
* Examples: |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
92 |
* <blockquote><pre>{@code |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
93 |
* (a0:J)=>{ a0 } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
94 |
* == identity(long) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
95 |
* (a0:I)=>{ t1:V = System.out#println(a0); void } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
96 |
* == System.out#println(int) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
97 |
* (a0:L)=>{ t1:V = System.out#println(a0); a0 } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
98 |
* == identity, with printing side-effect |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
99 |
* (a0:L, a1:L)=>{ t2:L = BoundMethodHandle#argument(a0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
100 |
* t3:L = BoundMethodHandle#target(a0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
101 |
* t4:L = MethodHandle#invoke(t3, t2, a1); t4 } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
102 |
* == general invoker for unary insertArgument combination |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
103 |
* (a0:L, a1:L)=>{ t2:L = FilterMethodHandle#filter(a0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
104 |
* t3:L = MethodHandle#invoke(t2, a1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
105 |
* t4:L = FilterMethodHandle#target(a0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
106 |
* t5:L = MethodHandle#invoke(t4, t3); t5 } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
107 |
* == general invoker for unary filterArgument combination |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
108 |
* (a0:L, a1:L)=>{ ...(same as previous example)... |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
109 |
* t5:L = MethodHandle#invoke(t4, t3, a1); t5 } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
110 |
* == general invoker for unary/unary foldArgument combination |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
111 |
* (a0:L, a1:I)=>{ t2:I = identity(long).asType((int)->long)(a1); t2 } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
112 |
* == invoker for identity method handle which performs i2l |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
113 |
* (a0:L, a1:L)=>{ t2:L = BoundMethodHandle#argument(a0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
114 |
* t3:L = Class#cast(t2,a1); t3 } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
115 |
* == invoker for identity method handle which performs cast |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
116 |
* }</pre></blockquote> |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
117 |
* <p> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
118 |
* @author John Rose, JSR 292 EG |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
119 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
120 |
class LambdaForm { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
121 |
final int arity; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
122 |
final int result; |
20494
cf77ae5ff678
8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents:
14852
diff
changeset
|
123 |
@Stable final Name[] names; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
124 |
final String debugName; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
125 |
MemberName vmentry; // low-level behavior, or null if not yet prepared |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
126 |
private boolean isCompiled; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
127 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
128 |
// Caches for common structural transforms: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
129 |
LambdaForm[] bindCache; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
130 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
131 |
public static final int VOID_RESULT = -1, LAST_RESULT = -2; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
132 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
133 |
enum BasicType { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
134 |
L_TYPE('L', Object.class, Wrapper.OBJECT), // all reference types |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
135 |
I_TYPE('I', int.class, Wrapper.INT), |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
136 |
J_TYPE('J', long.class, Wrapper.LONG), |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
137 |
F_TYPE('F', float.class, Wrapper.FLOAT), |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
138 |
D_TYPE('D', double.class, Wrapper.DOUBLE), // all primitive types |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
139 |
V_TYPE('V', void.class, Wrapper.VOID); // not valid in all contexts |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
140 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
141 |
static final BasicType[] ALL_TYPES = BasicType.values(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
142 |
static final BasicType[] ARG_TYPES = Arrays.copyOf(ALL_TYPES, ALL_TYPES.length-1); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
143 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
144 |
static final int ARG_TYPE_LIMIT = ARG_TYPES.length; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
145 |
static final int TYPE_LIMIT = ALL_TYPES.length; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
146 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
147 |
private final char btChar; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
148 |
private final Class<?> btClass; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
149 |
private final Wrapper btWrapper; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
150 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
151 |
private BasicType(char btChar, Class<?> btClass, Wrapper wrapper) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
152 |
this.btChar = btChar; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
153 |
this.btClass = btClass; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
154 |
this.btWrapper = wrapper; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
155 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
156 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
157 |
char basicTypeChar() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
158 |
return btChar; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
159 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
160 |
Class<?> basicTypeClass() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
161 |
return btClass; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
162 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
163 |
Wrapper basicTypeWrapper() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
164 |
return btWrapper; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
165 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
166 |
int basicTypeSlots() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
167 |
return btWrapper.stackSlots(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
168 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
169 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
170 |
static BasicType basicType(byte type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
171 |
return ALL_TYPES[type]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
172 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
173 |
static BasicType basicType(char type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
174 |
switch (type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
175 |
case 'L': return L_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
176 |
case 'I': return I_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
177 |
case 'J': return J_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
178 |
case 'F': return F_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
179 |
case 'D': return D_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
180 |
case 'V': return V_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
181 |
// all subword types are represented as ints |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
182 |
case 'Z': |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
183 |
case 'B': |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
184 |
case 'S': |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
185 |
case 'C': |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
186 |
return I_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
187 |
default: |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
188 |
throw newInternalError("Unknown type char: '"+type+"'"); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
189 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
190 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
191 |
static BasicType basicType(Wrapper type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
192 |
char c = type.basicTypeChar(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
193 |
return basicType(c); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
194 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
195 |
static BasicType basicType(Class<?> type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
196 |
if (!type.isPrimitive()) return L_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
197 |
return basicType(Wrapper.forPrimitiveType(type)); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
198 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
199 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
200 |
static char basicTypeChar(Class<?> type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
201 |
return basicType(type).btChar; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
202 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
203 |
static BasicType[] basicTypes(List<Class<?>> types) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
204 |
BasicType[] btypes = new BasicType[types.size()]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
205 |
for (int i = 0; i < btypes.length; i++) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
206 |
btypes[i] = basicType(types.get(i)); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
207 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
208 |
return btypes; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
209 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
210 |
static BasicType[] basicTypes(String types) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
211 |
BasicType[] btypes = new BasicType[types.length()]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
212 |
for (int i = 0; i < btypes.length; i++) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
213 |
btypes[i] = basicType(types.charAt(i)); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
214 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
215 |
return btypes; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
216 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
217 |
static boolean isBasicTypeChar(char c) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
218 |
return "LIJFDV".indexOf(c) >= 0; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
219 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
220 |
static boolean isArgBasicTypeChar(char c) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
221 |
return "LIJFD".indexOf(c) >= 0; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
222 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
223 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
224 |
static { assert(checkBasicType()); } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
225 |
private static boolean checkBasicType() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
226 |
for (int i = 0; i < ARG_TYPE_LIMIT; i++) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
227 |
assert ARG_TYPES[i].ordinal() == i; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
228 |
assert ARG_TYPES[i] == ALL_TYPES[i]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
229 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
230 |
for (int i = 0; i < TYPE_LIMIT; i++) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
231 |
assert ALL_TYPES[i].ordinal() == i; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
232 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
233 |
assert ALL_TYPES[TYPE_LIMIT - 1] == V_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
234 |
assert !Arrays.asList(ARG_TYPES).contains(V_TYPE); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
235 |
return true; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
236 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
237 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
238 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
239 |
LambdaForm(String debugName, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
240 |
int arity, Name[] names, int result) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
241 |
assert(namesOK(arity, names)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
242 |
this.arity = arity; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
243 |
this.result = fixResult(result, names); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
244 |
this.names = names.clone(); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
245 |
this.debugName = fixDebugName(debugName); |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
246 |
int maxOutArity = normalize(); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
247 |
if (maxOutArity > MethodType.MAX_MH_INVOKER_ARITY) { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
248 |
// Cannot use LF interpreter on very high arity expressions. |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
249 |
assert(maxOutArity <= MethodType.MAX_JVM_ARITY); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
250 |
compileToBytecode(); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
251 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
252 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
253 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
254 |
LambdaForm(String debugName, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
255 |
int arity, Name[] names) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
256 |
this(debugName, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
257 |
arity, names, LAST_RESULT); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
258 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
259 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
260 |
LambdaForm(String debugName, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
261 |
Name[] formals, Name[] temps, Name result) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
262 |
this(debugName, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
263 |
formals.length, buildNames(formals, temps, result), LAST_RESULT); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
264 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
265 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
266 |
private static Name[] buildNames(Name[] formals, Name[] temps, Name result) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
267 |
int arity = formals.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
268 |
int length = arity + temps.length + (result == null ? 0 : 1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
269 |
Name[] names = Arrays.copyOf(formals, length); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
270 |
System.arraycopy(temps, 0, names, arity, temps.length); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
271 |
if (result != null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
272 |
names[length - 1] = result; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
273 |
return names; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
274 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
275 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
276 |
private LambdaForm(String sig) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
277 |
// Make a blank lambda form, which returns a constant zero or null. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
278 |
// It is used as a template for managing the invocation of similar forms that are non-empty. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
279 |
// Called only from getPreparedForm. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
280 |
assert(isValidSignature(sig)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
281 |
this.arity = signatureArity(sig); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
282 |
this.result = (signatureReturn(sig) == V_TYPE ? -1 : arity); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
283 |
this.names = buildEmptyNames(arity, sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
284 |
this.debugName = "LF.zero"; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
285 |
assert(nameRefsAreLegal()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
286 |
assert(isEmpty()); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
287 |
assert(sig.equals(basicTypeSignature())) : sig + " != " + basicTypeSignature(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
288 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
289 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
290 |
private static Name[] buildEmptyNames(int arity, String basicTypeSignature) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
291 |
assert(isValidSignature(basicTypeSignature)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
292 |
int resultPos = arity + 1; // skip '_' |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
293 |
if (arity < 0 || basicTypeSignature.length() != resultPos+1) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
294 |
throw new IllegalArgumentException("bad arity for "+basicTypeSignature); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
295 |
int numRes = (basicType(basicTypeSignature.charAt(resultPos)) == V_TYPE ? 0 : 1); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
296 |
Name[] names = arguments(numRes, basicTypeSignature.substring(0, arity)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
297 |
for (int i = 0; i < numRes; i++) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
298 |
Name zero = new Name(constantZero(basicType(basicTypeSignature.charAt(resultPos + i)))); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
299 |
names[arity + i] = zero.newIndex(arity + i); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
300 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
301 |
return names; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
302 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
303 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
304 |
private static int fixResult(int result, Name[] names) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
305 |
if (result == LAST_RESULT) |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
306 |
result = names.length - 1; // might still be void |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
307 |
if (result >= 0 && names[result].type == V_TYPE) |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
308 |
result = VOID_RESULT; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
309 |
return result; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
310 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
311 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
312 |
private static String fixDebugName(String debugName) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
313 |
if (DEBUG_NAME_COUNTERS != null) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
314 |
int under = debugName.indexOf('_'); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
315 |
int length = debugName.length(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
316 |
if (under < 0) under = length; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
317 |
String debugNameStem = debugName.substring(0, under); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
318 |
Integer ctr; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
319 |
synchronized (DEBUG_NAME_COUNTERS) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
320 |
ctr = DEBUG_NAME_COUNTERS.get(debugNameStem); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
321 |
if (ctr == null) ctr = 0; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
322 |
DEBUG_NAME_COUNTERS.put(debugNameStem, ctr+1); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
323 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
324 |
StringBuilder buf = new StringBuilder(debugNameStem); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
325 |
buf.append('_'); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
326 |
int leadingZero = buf.length(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
327 |
buf.append((int) ctr); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
328 |
for (int i = buf.length() - leadingZero; i < 3; i++) |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
329 |
buf.insert(leadingZero, '0'); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
330 |
if (under < length) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
331 |
++under; // skip "_" |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
332 |
while (under < length && Character.isDigit(debugName.charAt(under))) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
333 |
++under; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
334 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
335 |
if (under < length && debugName.charAt(under) == '_') ++under; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
336 |
if (under < length) |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
337 |
buf.append('_').append(debugName, under, length); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
338 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
339 |
return buf.toString(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
340 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
341 |
return debugName; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
342 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
343 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
344 |
private static boolean namesOK(int arity, Name[] names) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
345 |
for (int i = 0; i < names.length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
346 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
347 |
assert(n != null) : "n is null"; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
348 |
if (i < arity) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
349 |
assert( n.isParam()) : n + " is not param at " + i; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
350 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
351 |
assert(!n.isParam()) : n + " is param at " + i; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
352 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
353 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
354 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
355 |
|
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
356 |
/** Renumber and/or replace params so that they are interned and canonically numbered. |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
357 |
* @return maximum argument list length among the names (since we have to pass over them anyway) |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
358 |
*/ |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
359 |
private int normalize() { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
360 |
Name[] oldNames = null; |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
361 |
int maxOutArity = 0; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
362 |
int changesStart = 0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
363 |
for (int i = 0; i < names.length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
364 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
365 |
if (!n.initIndex(i)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
366 |
if (oldNames == null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
367 |
oldNames = names.clone(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
368 |
changesStart = i; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
369 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
370 |
names[i] = n.cloneWithIndex(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
371 |
} |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
372 |
if (n.arguments != null && maxOutArity < n.arguments.length) |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
373 |
maxOutArity = n.arguments.length; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
374 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
375 |
if (oldNames != null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
376 |
int startFixing = arity; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
377 |
if (startFixing <= changesStart) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
378 |
startFixing = changesStart+1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
379 |
for (int i = startFixing; i < names.length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
380 |
Name fixed = names[i].replaceNames(oldNames, names, changesStart, i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
381 |
names[i] = fixed.newIndex(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
382 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
383 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
384 |
assert(nameRefsAreLegal()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
385 |
int maxInterned = Math.min(arity, INTERNED_ARGUMENT_LIMIT); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
386 |
boolean needIntern = false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
387 |
for (int i = 0; i < maxInterned; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
388 |
Name n = names[i], n2 = internArgument(n); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
389 |
if (n != n2) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
390 |
names[i] = n2; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
391 |
needIntern = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
392 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
393 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
394 |
if (needIntern) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
395 |
for (int i = arity; i < names.length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
396 |
names[i].internArguments(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
397 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
398 |
assert(nameRefsAreLegal()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
399 |
} |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
400 |
return maxOutArity; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
401 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
402 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
403 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
404 |
* Check that all embedded Name references are localizable to this lambda, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
405 |
* and are properly ordered after their corresponding definitions. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
406 |
* <p> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
407 |
* Note that a Name can be local to multiple lambdas, as long as |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
408 |
* it possesses the same index in each use site. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
409 |
* This allows Name references to be freely reused to construct |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
410 |
* fresh lambdas, without confusion. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
411 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
412 |
private boolean nameRefsAreLegal() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
413 |
assert(arity >= 0 && arity <= names.length); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
414 |
assert(result >= -1 && result < names.length); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
415 |
// Do all names possess an index consistent with their local definition order? |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
416 |
for (int i = 0; i < arity; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
417 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
418 |
assert(n.index() == i) : Arrays.asList(n.index(), i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
419 |
assert(n.isParam()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
420 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
421 |
// Also, do all local name references |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
422 |
for (int i = arity; i < names.length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
423 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
424 |
assert(n.index() == i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
425 |
for (Object arg : n.arguments) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
426 |
if (arg instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
427 |
Name n2 = (Name) arg; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
428 |
int i2 = n2.index; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
429 |
assert(0 <= i2 && i2 < names.length) : n.debugString() + ": 0 <= i2 && i2 < names.length: 0 <= " + i2 + " < " + names.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
430 |
assert(names[i2] == n2) : Arrays.asList("-1-", i, "-2-", n.debugString(), "-3-", i2, "-4-", n2.debugString(), "-5-", names[i2].debugString(), "-6-", this); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
431 |
assert(i2 < i); // ref must come after def! |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
432 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
433 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
434 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
435 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
436 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
437 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
438 |
/** Invoke this form on the given arguments. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
439 |
// final Object invoke(Object... args) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
440 |
// // NYI: fit this into the fast path? |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
441 |
// return interpretWithArguments(args); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
442 |
// } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
443 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
444 |
/** Report the return type. */ |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
445 |
BasicType returnType() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
446 |
if (result < 0) return V_TYPE; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
447 |
Name n = names[result]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
448 |
return n.type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
449 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
450 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
451 |
/** Report the N-th argument type. */ |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
452 |
BasicType parameterType(int n) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
453 |
return parameter(n).type; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
454 |
} |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
455 |
|
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
456 |
/** Report the N-th argument name. */ |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
457 |
Name parameter(int n) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
458 |
assert(n < arity); |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
459 |
Name param = names[n]; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
460 |
assert(param.isParam()); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
461 |
return param; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
462 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
463 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
464 |
/** Report the arity. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
465 |
int arity() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
466 |
return arity; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
467 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
468 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
469 |
/** Return the method type corresponding to my basic type signature. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
470 |
MethodType methodType() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
471 |
return signatureType(basicTypeSignature()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
472 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
473 |
/** Return ABC_Z, where the ABC are parameter type characters, and Z is the return type character. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
474 |
final String basicTypeSignature() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
475 |
StringBuilder buf = new StringBuilder(arity() + 3); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
476 |
for (int i = 0, a = arity(); i < a; i++) |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
477 |
buf.append(parameterType(i).basicTypeChar()); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
478 |
return buf.append('_').append(returnType().basicTypeChar()).toString(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
479 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
480 |
static int signatureArity(String sig) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
481 |
assert(isValidSignature(sig)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
482 |
return sig.indexOf('_'); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
483 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
484 |
static BasicType signatureReturn(String sig) { |
26464
65b37da18e06
8037209: Improvements and cleanups to bytecode assembly for lambda forms
vlivanov
parents:
25859
diff
changeset
|
485 |
return basicType(sig.charAt(signatureArity(sig) + 1)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
486 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
487 |
static boolean isValidSignature(String sig) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
488 |
int arity = sig.indexOf('_'); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
489 |
if (arity < 0) return false; // must be of the form *_* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
490 |
int siglen = sig.length(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
491 |
if (siglen != arity + 2) return false; // *_X |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
492 |
for (int i = 0; i < siglen; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
493 |
if (i == arity) continue; // skip '_' |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
494 |
char c = sig.charAt(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
495 |
if (c == 'V') |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
496 |
return (i == siglen - 1 && arity == siglen - 2); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
497 |
if (!isArgBasicTypeChar(c)) return false; // must be [LIJFD] |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
498 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
499 |
return true; // [LIJFD]*_[LIJFDV] |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
500 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
501 |
static MethodType signatureType(String sig) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
502 |
Class<?>[] ptypes = new Class<?>[signatureArity(sig)]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
503 |
for (int i = 0; i < ptypes.length; i++) |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
504 |
ptypes[i] = basicType(sig.charAt(i)).btClass; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
505 |
Class<?> rtype = signatureReturn(sig).btClass; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
506 |
return MethodType.methodType(rtype, ptypes); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
507 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
508 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
509 |
/* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
510 |
* Code generation issues: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
511 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
512 |
* Compiled LFs should be reusable in general. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
513 |
* The biggest issue is how to decide when to pull a name into |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
514 |
* the bytecode, versus loading a reified form from the MH data. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
515 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
516 |
* For example, an asType wrapper may require execution of a cast |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
517 |
* after a call to a MH. The target type of the cast can be placed |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
518 |
* as a constant in the LF itself. This will force the cast type |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
519 |
* to be compiled into the bytecodes and native code for the MH. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
520 |
* Or, the target type of the cast can be erased in the LF, and |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
521 |
* loaded from the MH data. (Later on, if the MH as a whole is |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
522 |
* inlined, the data will flow into the inlined instance of the LF, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
523 |
* as a constant, and the end result will be an optimal cast.) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
524 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
525 |
* This erasure of cast types can be done with any use of |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
526 |
* reference types. It can also be done with whole method |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
527 |
* handles. Erasing a method handle might leave behind |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
528 |
* LF code that executes correctly for any MH of a given |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
529 |
* type, and load the required MH from the enclosing MH's data. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
530 |
* Or, the erasure might even erase the expected MT. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
531 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
532 |
* Also, for direct MHs, the MemberName of the target |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
533 |
* could be erased, and loaded from the containing direct MH. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
534 |
* As a simple case, a LF for all int-valued non-static |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
535 |
* field getters would perform a cast on its input argument |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
536 |
* (to non-constant base type derived from the MemberName) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
537 |
* and load an integer value from the input object |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
538 |
* (at a non-constant offset also derived from the MemberName). |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
539 |
* Such MN-erased LFs would be inlinable back to optimized |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
540 |
* code, whenever a constant enclosing DMH is available |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
541 |
* to supply a constant MN from its data. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
542 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
543 |
* The main problem here is to keep LFs reasonably generic, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
544 |
* while ensuring that hot spots will inline good instances. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
545 |
* "Reasonably generic" means that we don't end up with |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
546 |
* repeated versions of bytecode or machine code that do |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
547 |
* not differ in their optimized form. Repeated versions |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
548 |
* of machine would have the undesirable overheads of |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
549 |
* (a) redundant compilation work and (b) extra I$ pressure. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
550 |
* To control repeated versions, we need to be ready to |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
551 |
* erase details from LFs and move them into MH data, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
552 |
* whevener those details are not relevant to significant |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
553 |
* optimization. "Significant" means optimization of |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
554 |
* code that is actually hot. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
555 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
556 |
* Achieving this may require dynamic splitting of MHs, by replacing |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
557 |
* a generic LF with a more specialized one, on the same MH, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
558 |
* if (a) the MH is frequently executed and (b) the MH cannot |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
559 |
* be inlined into a containing caller, such as an invokedynamic. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
560 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
561 |
* Compiled LFs that are no longer used should be GC-able. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
562 |
* If they contain non-BCP references, they should be properly |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
563 |
* interlinked with the class loader(s) that their embedded types |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
564 |
* depend on. This probably means that reusable compiled LFs |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
565 |
* will be tabulated (indexed) on relevant class loaders, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
566 |
* or else that the tables that cache them will have weak links. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
567 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
568 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
569 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
570 |
* Make this LF directly executable, as part of a MethodHandle. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
571 |
* Invariant: Every MH which is invoked must prepare its LF |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
572 |
* before invocation. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
573 |
* (In principle, the JVM could do this very lazily, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
574 |
* as a sort of pre-invocation linkage step.) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
575 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
576 |
public void prepare() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
577 |
if (COMPILE_THRESHOLD == 0) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
578 |
compileToBytecode(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
579 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
580 |
if (this.vmentry != null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
581 |
// already prepared (e.g., a primitive DMH invoker form) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
582 |
return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
583 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
584 |
LambdaForm prep = getPreparedForm(basicTypeSignature()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
585 |
this.vmentry = prep.vmentry; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
586 |
// TO DO: Maybe add invokeGeneric, invokeWithArguments |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
587 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
588 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
589 |
/** Generate optimizable bytecode for this form. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
590 |
MemberName compileToBytecode() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
591 |
MethodType invokerType = methodType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
592 |
assert(vmentry == null || vmentry.getMethodType().basicType().equals(invokerType)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
593 |
if (vmentry != null && isCompiled) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
594 |
return vmentry; // already compiled somehow |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
595 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
596 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
597 |
vmentry = InvokerBytecodeGenerator.generateCustomizedCode(this, invokerType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
598 |
if (TRACE_INTERPRETER) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
599 |
traceInterpreter("compileToBytecode", this); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
600 |
isCompiled = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
601 |
return vmentry; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
602 |
} catch (Error | Exception ex) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
603 |
throw newInternalError(this.toString(), ex); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
604 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
605 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
606 |
|
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
607 |
private static void computeInitialPreparedForms() { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
608 |
// Find all predefined invokers and associate them with canonical empty lambda forms. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
609 |
for (MemberName m : MemberName.getFactory().getMethods(LambdaForm.class, false, null, null, null)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
610 |
if (!m.isStatic() || !m.isPackage()) continue; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
611 |
MethodType mt = m.getMethodType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
612 |
if (mt.parameterCount() > 0 && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
613 |
mt.parameterType(0) == MethodHandle.class && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
614 |
m.getName().startsWith("interpret_")) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
615 |
String sig = basicTypeSignature(mt); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
616 |
assert(m.getName().equals("interpret" + sig.substring(sig.indexOf('_')))); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
617 |
LambdaForm form = new LambdaForm(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
618 |
form.vmentry = m; |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
619 |
form = mt.form().setCachedLambdaForm(MethodTypeForm.LF_INTERPRET, form); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
620 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
621 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
622 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
623 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
624 |
// Set this false to disable use of the interpret_L methods defined in this file. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
625 |
private static final boolean USE_PREDEFINED_INTERPRET_METHODS = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
626 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
627 |
// The following are predefined exact invokers. The system must build |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
628 |
// a separate invoker for each distinct signature. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
629 |
static Object interpret_L(MethodHandle mh) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
630 |
Object[] av = {mh}; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
631 |
String sig = null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
632 |
assert(argumentTypesMatch(sig = "L_L", av)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
633 |
Object res = mh.form.interpretWithArguments(av); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
634 |
assert(returnTypesMatch(sig, av, res)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
635 |
return res; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
636 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
637 |
static Object interpret_L(MethodHandle mh, Object x1) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
638 |
Object[] av = {mh, x1}; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
639 |
String sig = null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
640 |
assert(argumentTypesMatch(sig = "LL_L", av)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
641 |
Object res = mh.form.interpretWithArguments(av); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
642 |
assert(returnTypesMatch(sig, av, res)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
643 |
return res; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
644 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
645 |
static Object interpret_L(MethodHandle mh, Object x1, Object x2) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
646 |
Object[] av = {mh, x1, x2}; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
647 |
String sig = null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
648 |
assert(argumentTypesMatch(sig = "LLL_L", av)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
649 |
Object res = mh.form.interpretWithArguments(av); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
650 |
assert(returnTypesMatch(sig, av, res)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
651 |
return res; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
652 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
653 |
private static LambdaForm getPreparedForm(String sig) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
654 |
MethodType mtype = signatureType(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
655 |
LambdaForm prep = mtype.form().cachedLambdaForm(MethodTypeForm.LF_INTERPRET); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
656 |
if (prep != null) return prep; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
657 |
assert(isValidSignature(sig)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
658 |
prep = new LambdaForm(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
659 |
prep.vmentry = InvokerBytecodeGenerator.generateLambdaFormInterpreterEntryPoint(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
660 |
return mtype.form().setCachedLambdaForm(MethodTypeForm.LF_INTERPRET, prep); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
661 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
662 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
663 |
// The next few routines are called only from assert expressions |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
664 |
// They verify that the built-in invokers process the correct raw data types. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
665 |
private static boolean argumentTypesMatch(String sig, Object[] av) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
666 |
int arity = signatureArity(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
667 |
assert(av.length == arity) : "av.length == arity: av.length=" + av.length + ", arity=" + arity; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
668 |
assert(av[0] instanceof MethodHandle) : "av[0] not instace of MethodHandle: " + av[0]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
669 |
MethodHandle mh = (MethodHandle) av[0]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
670 |
MethodType mt = mh.type(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
671 |
assert(mt.parameterCount() == arity-1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
672 |
for (int i = 0; i < av.length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
673 |
Class<?> pt = (i == 0 ? MethodHandle.class : mt.parameterType(i-1)); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
674 |
assert(valueMatches(basicType(sig.charAt(i)), pt, av[i])); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
675 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
676 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
677 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
678 |
private static boolean valueMatches(BasicType tc, Class<?> type, Object x) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
679 |
// The following line is needed because (...)void method handles can use non-void invokers |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
680 |
if (type == void.class) tc = V_TYPE; // can drop any kind of value |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
681 |
assert tc == basicType(type) : tc + " == basicType(" + type + ")=" + basicType(type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
682 |
switch (tc) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
683 |
case I_TYPE: assert checkInt(type, x) : "checkInt(" + type + "," + x +")"; break; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
684 |
case J_TYPE: assert x instanceof Long : "instanceof Long: " + x; break; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
685 |
case F_TYPE: assert x instanceof Float : "instanceof Float: " + x; break; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
686 |
case D_TYPE: assert x instanceof Double : "instanceof Double: " + x; break; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
687 |
case L_TYPE: assert checkRef(type, x) : "checkRef(" + type + "," + x + ")"; break; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
688 |
case V_TYPE: break; // allow anything here; will be dropped |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
689 |
default: assert(false); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
690 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
691 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
692 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
693 |
private static boolean returnTypesMatch(String sig, Object[] av, Object res) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
694 |
MethodHandle mh = (MethodHandle) av[0]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
695 |
return valueMatches(signatureReturn(sig), mh.type().returnType(), res); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
696 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
697 |
private static boolean checkInt(Class<?> type, Object x) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
698 |
assert(x instanceof Integer); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
699 |
if (type == int.class) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
700 |
Wrapper w = Wrapper.forBasicType(type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
701 |
assert(w.isSubwordOrInt()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
702 |
Object x1 = Wrapper.INT.wrap(w.wrap(x)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
703 |
return x.equals(x1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
704 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
705 |
private static boolean checkRef(Class<?> type, Object x) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
706 |
assert(!type.isPrimitive()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
707 |
if (x == null) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
708 |
if (type.isInterface()) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
709 |
return type.isInstance(x); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
710 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
711 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
712 |
/** If the invocation count hits the threshold we spin bytecodes and call that subsequently. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
713 |
private static final int COMPILE_THRESHOLD; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
714 |
static { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
715 |
COMPILE_THRESHOLD = Math.max(-1, MethodHandleStatics.COMPILE_THRESHOLD); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
716 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
717 |
private int invocationCounter = 0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
718 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
719 |
@Hidden |
14852 | 720 |
@DontInline |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
721 |
/** Interpretively invoke this form on the given arguments. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
722 |
Object interpretWithArguments(Object... argumentValues) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
723 |
if (TRACE_INTERPRETER) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
724 |
return interpretWithArgumentsTracing(argumentValues); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
725 |
checkInvocationCounter(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
726 |
assert(arityCheck(argumentValues)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
727 |
Object[] values = Arrays.copyOf(argumentValues, names.length); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
728 |
for (int i = argumentValues.length; i < values.length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
729 |
values[i] = interpretName(names[i], values); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
730 |
} |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
731 |
Object rv = (result < 0) ? null : values[result]; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
732 |
assert(resultCheck(argumentValues, rv)); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
733 |
return rv; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
734 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
735 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
736 |
@Hidden |
14852 | 737 |
@DontInline |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
738 |
/** Evaluate a single Name within this form, applying its function to its arguments. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
739 |
Object interpretName(Name name, Object[] values) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
740 |
if (TRACE_INTERPRETER) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
741 |
traceInterpreter("| interpretName", name.debugString(), (Object[]) null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
742 |
Object[] arguments = Arrays.copyOf(name.arguments, name.arguments.length, Object[].class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
743 |
for (int i = 0; i < arguments.length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
744 |
Object a = arguments[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
745 |
if (a instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
746 |
int i2 = ((Name)a).index(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
747 |
assert(names[i2] == a); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
748 |
a = values[i2]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
749 |
arguments[i] = a; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
750 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
751 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
752 |
return name.function.invokeWithArguments(arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
753 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
754 |
|
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
755 |
private void checkInvocationCounter() { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
756 |
if (COMPILE_THRESHOLD != 0 && |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
757 |
invocationCounter < COMPILE_THRESHOLD) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
758 |
invocationCounter++; // benign race |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
759 |
if (invocationCounter >= COMPILE_THRESHOLD) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
760 |
// Replace vmentry with a bytecode version of this LF. |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
761 |
compileToBytecode(); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
762 |
} |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
763 |
} |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
764 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
765 |
Object interpretWithArgumentsTracing(Object... argumentValues) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
766 |
traceInterpreter("[ interpretWithArguments", this, argumentValues); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
767 |
if (invocationCounter < COMPILE_THRESHOLD) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
768 |
int ctr = invocationCounter++; // benign race |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
769 |
traceInterpreter("| invocationCounter", ctr); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
770 |
if (invocationCounter >= COMPILE_THRESHOLD) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
771 |
compileToBytecode(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
772 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
773 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
774 |
Object rval; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
775 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
776 |
assert(arityCheck(argumentValues)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
777 |
Object[] values = Arrays.copyOf(argumentValues, names.length); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
778 |
for (int i = argumentValues.length; i < values.length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
779 |
values[i] = interpretName(names[i], values); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
780 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
781 |
rval = (result < 0) ? null : values[result]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
782 |
} catch (Throwable ex) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
783 |
traceInterpreter("] throw =>", ex); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
784 |
throw ex; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
785 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
786 |
traceInterpreter("] return =>", rval); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
787 |
return rval; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
788 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
789 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
790 |
//** This transform is applied (statically) to every name.function. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
791 |
/* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
792 |
private static MethodHandle eraseSubwordTypes(MethodHandle mh) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
793 |
MethodType mt = mh.type(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
794 |
if (mt.hasPrimitives()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
795 |
mt = mt.changeReturnType(eraseSubwordType(mt.returnType())); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
796 |
for (int i = 0; i < mt.parameterCount(); i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
797 |
mt = mt.changeParameterType(i, eraseSubwordType(mt.parameterType(i))); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
798 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
799 |
mh = MethodHandles.explicitCastArguments(mh, mt); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
800 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
801 |
return mh; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
802 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
803 |
private static Class<?> eraseSubwordType(Class<?> type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
804 |
if (!type.isPrimitive()) return type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
805 |
if (type == int.class) return type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
806 |
Wrapper w = Wrapper.forPrimitiveType(type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
807 |
if (w.isSubwordOrInt()) return int.class; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
808 |
return type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
809 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
810 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
811 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
812 |
static void traceInterpreter(String event, Object obj, Object... args) { |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
813 |
if (TRACE_INTERPRETER) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
814 |
System.out.println("LFI: "+event+" "+(obj != null ? obj : "")+(args != null && args.length != 0 ? Arrays.asList(args) : "")); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
815 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
816 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
817 |
static void traceInterpreter(String event, Object obj) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
818 |
traceInterpreter(event, obj, (Object[])null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
819 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
820 |
private boolean arityCheck(Object[] argumentValues) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
821 |
assert(argumentValues.length == arity) : arity+"!="+Arrays.asList(argumentValues)+".length"; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
822 |
// also check that the leading (receiver) argument is somehow bound to this LF: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
823 |
assert(argumentValues[0] instanceof MethodHandle) : "not MH: " + argumentValues[0]; |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
824 |
MethodHandle mh = (MethodHandle) argumentValues[0]; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
825 |
assert(mh.internalForm() == this); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
826 |
// note: argument #0 could also be an interface wrapper, in the future |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
827 |
argumentTypesMatch(basicTypeSignature(), argumentValues); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
828 |
return true; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
829 |
} |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
830 |
private boolean resultCheck(Object[] argumentValues, Object result) { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
831 |
MethodHandle mh = (MethodHandle) argumentValues[0]; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
832 |
MethodType mt = mh.type(); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
833 |
assert(valueMatches(returnType(), mt.returnType(), result)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
834 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
835 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
836 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
837 |
private boolean isEmpty() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
838 |
if (result < 0) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
839 |
return (names.length == arity); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
840 |
else if (result == arity && names.length == arity + 1) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
841 |
return names[arity].isConstantZero(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
842 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
843 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
844 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
845 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
846 |
public String toString() { |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
847 |
StringBuilder buf = new StringBuilder(debugName+"=Lambda("); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
848 |
for (int i = 0; i < names.length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
849 |
if (i == arity) buf.append(")=>{"); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
850 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
851 |
if (i >= arity) buf.append("\n "); |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
852 |
buf.append(n.paramString()); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
853 |
if (i < arity) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
854 |
if (i+1 < arity) buf.append(","); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
855 |
continue; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
856 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
857 |
buf.append("=").append(n.exprString()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
858 |
buf.append(";"); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
859 |
} |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
860 |
if (arity == names.length) buf.append(")=>{"); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
861 |
buf.append(result < 0 ? "void" : names[result]).append("}"); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
862 |
if (TRACE_INTERPRETER) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
863 |
// Extra verbosity: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
864 |
buf.append(":").append(basicTypeSignature()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
865 |
buf.append("/").append(vmentry); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
866 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
867 |
return buf.toString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
868 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
869 |
|
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
870 |
@Override |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
871 |
public boolean equals(Object obj) { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
872 |
return obj instanceof LambdaForm && equals((LambdaForm)obj); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
873 |
} |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
874 |
public boolean equals(LambdaForm that) { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
875 |
if (this.result != that.result) return false; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
876 |
return Arrays.equals(this.names, that.names); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
877 |
} |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
878 |
public int hashCode() { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
879 |
return result + 31 * Arrays.hashCode(names); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
880 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
881 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
882 |
LambdaForm bind(int namePos, BoundMethodHandle.SpeciesData oldData) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
883 |
Name name = names[namePos]; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
884 |
BoundMethodHandle.SpeciesData newData = oldData.extendWith(name.type); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
885 |
return bind(name, new Name(newData.getterFunction(oldData.fieldCount()), names[0]), oldData, newData); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
886 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
887 |
LambdaForm bind(Name name, Name binding, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
888 |
BoundMethodHandle.SpeciesData oldData, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
889 |
BoundMethodHandle.SpeciesData newData) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
890 |
int pos = name.index; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
891 |
assert(name.isParam()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
892 |
assert(!binding.isParam()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
893 |
assert(name.type == binding.type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
894 |
assert(0 <= pos && pos < arity && names[pos] == name); |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
895 |
assert(binding.function.memberDeclaringClassOrNull() == newData.fieldHolder()); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
896 |
assert(oldData.getterFunctions().length == newData.getterFunctions().length-1); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
897 |
if (bindCache != null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
898 |
LambdaForm form = bindCache[pos]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
899 |
if (form != null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
900 |
assert(form.contains(binding)) : "form << " + form + " >> does not contain binding << " + binding + " >>"; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
901 |
return form; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
902 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
903 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
904 |
bindCache = new LambdaForm[arity]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
905 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
906 |
assert(nameRefsAreLegal()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
907 |
int arity2 = arity-1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
908 |
Name[] names2 = names.clone(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
909 |
names2[pos] = binding; // we might move this in a moment |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
910 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
911 |
// The newly created LF will run with a different BMH. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
912 |
// Switch over any pre-existing BMH field references to the new BMH class. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
913 |
int firstOldRef = -1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
914 |
for (int i = 0; i < names2.length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
915 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
916 |
if (n.function != null && |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
917 |
n.function.memberDeclaringClassOrNull() == oldData.fieldHolder()) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
918 |
MethodHandle oldGetter = n.function.resolvedHandle; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
919 |
MethodHandle newGetter = null; |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
920 |
for (int j = 0; j < oldData.getterHandles().length; j++) { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
921 |
if (oldGetter == oldData.getterHandles()[j]) |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
922 |
newGetter = newData.getterHandles()[j]; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
923 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
924 |
if (newGetter != null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
925 |
if (firstOldRef < 0) firstOldRef = i; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
926 |
Name n2 = new Name(newGetter, n.arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
927 |
names2[i] = n2; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
928 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
929 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
930 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
931 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
932 |
// Walk over the new list of names once, in forward order. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
933 |
// Replace references to 'name' with 'binding'. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
934 |
// Replace data structure references to the old BMH species with the new. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
935 |
// This might cause a ripple effect, but it will settle in one pass. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
936 |
assert(firstOldRef < 0 || firstOldRef > pos); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
937 |
for (int i = pos+1; i < names2.length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
938 |
if (i <= arity2) continue; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
939 |
names2[i] = names2[i].replaceNames(names, names2, pos, i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
940 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
941 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
942 |
// (a0, a1, name=a2, a3, a4) => (a0, a1, a3, a4, binding) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
943 |
int insPos = pos; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
944 |
for (; insPos+1 < names2.length; insPos++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
945 |
Name n = names2[insPos+1]; |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
946 |
if (n.isParam()) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
947 |
names2[insPos] = n; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
948 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
949 |
break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
950 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
951 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
952 |
names2[insPos] = binding; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
953 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
954 |
// Since we moved some stuff, maybe update the result reference: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
955 |
int result2 = result; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
956 |
if (result2 == pos) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
957 |
result2 = insPos; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
958 |
else if (result2 > pos && result2 <= insPos) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
959 |
result2 -= 1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
960 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
961 |
return bindCache[pos] = new LambdaForm(debugName, arity2, names2, result2); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
962 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
963 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
964 |
boolean contains(Name name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
965 |
int pos = name.index(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
966 |
if (pos >= 0) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
967 |
return pos < names.length && name.equals(names[pos]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
968 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
969 |
for (int i = arity; i < names.length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
970 |
if (name.equals(names[i])) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
971 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
972 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
973 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
974 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
975 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
976 |
LambdaForm addArguments(int pos, BasicType... types) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
977 |
// names array has MH in slot 0; skip it. |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
978 |
int argpos = pos + 1; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
979 |
assert(argpos <= arity); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
980 |
int length = names.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
981 |
int inTypes = types.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
982 |
Name[] names2 = Arrays.copyOf(names, length + inTypes); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
983 |
int arity2 = arity + inTypes; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
984 |
int result2 = result; |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
985 |
if (result2 >= argpos) |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
986 |
result2 += inTypes; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
987 |
// Note: The LF constructor will rename names2[argpos...]. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
988 |
// Make space for new arguments (shift temporaries). |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
989 |
System.arraycopy(names, argpos, names2, argpos + inTypes, length - argpos); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
990 |
for (int i = 0; i < inTypes; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
991 |
names2[argpos + i] = new Name(types[i]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
992 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
993 |
return new LambdaForm(debugName, arity2, names2, result2); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
994 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
995 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
996 |
LambdaForm addArguments(int pos, List<Class<?>> types) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
997 |
return addArguments(pos, basicTypes(types)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
998 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
999 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1000 |
LambdaForm permuteArguments(int skip, int[] reorder, BasicType[] types) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1001 |
// Note: When inArg = reorder[outArg], outArg is fed by a copy of inArg. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1002 |
// The types are the types of the new (incoming) arguments. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1003 |
int length = names.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1004 |
int inTypes = types.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1005 |
int outArgs = reorder.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1006 |
assert(skip+outArgs == arity); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1007 |
assert(permutedTypesMatch(reorder, types, names, skip)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1008 |
int pos = 0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1009 |
// skip trivial first part of reordering: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1010 |
while (pos < outArgs && reorder[pos] == pos) pos += 1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1011 |
Name[] names2 = new Name[length - outArgs + inTypes]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1012 |
System.arraycopy(names, 0, names2, 0, skip+pos); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1013 |
// copy the body: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1014 |
int bodyLength = length - arity; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1015 |
System.arraycopy(names, skip+outArgs, names2, skip+inTypes, bodyLength); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1016 |
int arity2 = names2.length - bodyLength; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1017 |
int result2 = result; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1018 |
if (result2 >= 0) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1019 |
if (result2 < skip+outArgs) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1020 |
// return the corresponding inArg |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1021 |
result2 = reorder[result2-skip]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1022 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1023 |
result2 = result2 - outArgs + inTypes; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1024 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1025 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1026 |
// rework names in the body: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1027 |
for (int j = pos; j < outArgs; j++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1028 |
Name n = names[skip+j]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1029 |
int i = reorder[j]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1030 |
// replace names[skip+j] by names2[skip+i] |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1031 |
Name n2 = names2[skip+i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1032 |
if (n2 == null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1033 |
names2[skip+i] = n2 = new Name(types[i]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1034 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1035 |
assert(n2.type == types[i]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1036 |
for (int k = arity2; k < names2.length; k++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1037 |
names2[k] = names2[k].replaceName(n, n2); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1038 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1039 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1040 |
// some names are unused, but must be filled in |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1041 |
for (int i = skip+pos; i < arity2; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1042 |
if (names2[i] == null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1043 |
names2[i] = argument(i, types[i - skip]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1044 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1045 |
for (int j = arity; j < names.length; j++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1046 |
int i = j - arity + arity2; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1047 |
// replace names2[i] by names[j] |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1048 |
Name n = names[j]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1049 |
Name n2 = names2[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1050 |
if (n != n2) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1051 |
for (int k = i+1; k < names2.length; k++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1052 |
names2[k] = names2[k].replaceName(n, n2); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1053 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1054 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1055 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1056 |
return new LambdaForm(debugName, arity2, names2, result2); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1057 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1058 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1059 |
static boolean permutedTypesMatch(int[] reorder, BasicType[] types, Name[] names, int skip) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1060 |
int inTypes = types.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1061 |
int outArgs = reorder.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1062 |
for (int i = 0; i < outArgs; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1063 |
assert(names[skip+i].isParam()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1064 |
assert(names[skip+i].type == types[reorder[i]]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1065 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1066 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1067 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1068 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1069 |
static class NamedFunction { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1070 |
final MemberName member; |
20494
cf77ae5ff678
8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents:
14852
diff
changeset
|
1071 |
@Stable MethodHandle resolvedHandle; |
cf77ae5ff678
8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents:
14852
diff
changeset
|
1072 |
@Stable MethodHandle invoker; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1073 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1074 |
NamedFunction(MethodHandle resolvedHandle) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1075 |
this(resolvedHandle.internalMemberName(), resolvedHandle); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1076 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1077 |
NamedFunction(MemberName member, MethodHandle resolvedHandle) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1078 |
this.member = member; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1079 |
this.resolvedHandle = resolvedHandle; |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1080 |
// The following assert is almost always correct, but will fail for corner cases, such as PrivateInvokeTest. |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1081 |
//assert(!isInvokeBasic()); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1082 |
} |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1083 |
NamedFunction(MethodType basicInvokerType) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1084 |
assert(basicInvokerType == basicInvokerType.basicType()) : basicInvokerType; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1085 |
if (basicInvokerType.parameterSlotCount() < MethodType.MAX_MH_INVOKER_ARITY) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1086 |
this.resolvedHandle = basicInvokerType.invokers().basicInvoker(); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1087 |
this.member = resolvedHandle.internalMemberName(); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1088 |
} else { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1089 |
// necessary to pass BigArityTest |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1090 |
this.member = Invokers.invokeBasicMethod(basicInvokerType); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1091 |
} |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1092 |
assert(isInvokeBasic()); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1093 |
} |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1094 |
|
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1095 |
private boolean isInvokeBasic() { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1096 |
return member != null && |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1097 |
member.isMethodHandleInvoke() && |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1098 |
"invokeBasic".equals(member.getName()); |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1099 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1100 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1101 |
// The next 3 constructors are used to break circular dependencies on MH.invokeStatic, etc. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1102 |
// Any LambdaForm containing such a member is not interpretable. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1103 |
// This is OK, since all such LFs are prepared with special primitive vmentry points. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1104 |
// And even without the resolvedHandle, the name can still be compiled and optimized. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1105 |
NamedFunction(Method method) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1106 |
this(new MemberName(method)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1107 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1108 |
NamedFunction(Field field) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1109 |
this(new MemberName(field)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1110 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1111 |
NamedFunction(MemberName member) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1112 |
this.member = member; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1113 |
this.resolvedHandle = null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1114 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1115 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1116 |
MethodHandle resolvedHandle() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1117 |
if (resolvedHandle == null) resolve(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1118 |
return resolvedHandle; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1119 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1120 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1121 |
void resolve() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1122 |
resolvedHandle = DirectMethodHandle.make(member); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1123 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1124 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1125 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1126 |
public boolean equals(Object other) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1127 |
if (this == other) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1128 |
if (other == null) return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1129 |
if (!(other instanceof NamedFunction)) return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1130 |
NamedFunction that = (NamedFunction) other; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1131 |
return this.member != null && this.member.equals(that.member); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1132 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1133 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1134 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1135 |
public int hashCode() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1136 |
if (member != null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1137 |
return member.hashCode(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1138 |
return super.hashCode(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1139 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1140 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1141 |
// Put the predefined NamedFunction invokers into the table. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1142 |
static void initializeInvokers() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1143 |
for (MemberName m : MemberName.getFactory().getMethods(NamedFunction.class, false, null, null, null)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1144 |
if (!m.isStatic() || !m.isPackage()) continue; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1145 |
MethodType type = m.getMethodType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1146 |
if (type.equals(INVOKER_METHOD_TYPE) && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1147 |
m.getName().startsWith("invoke_")) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1148 |
String sig = m.getName().substring("invoke_".length()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1149 |
int arity = LambdaForm.signatureArity(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1150 |
MethodType srcType = MethodType.genericMethodType(arity); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1151 |
if (LambdaForm.signatureReturn(sig) == V_TYPE) |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1152 |
srcType = srcType.changeReturnType(void.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1153 |
MethodTypeForm typeForm = srcType.form(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1154 |
typeForm.namedFunctionInvoker = DirectMethodHandle.make(m); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1155 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1156 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1157 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1158 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1159 |
// The following are predefined NamedFunction invokers. The system must build |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1160 |
// a separate invoker for each distinct signature. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1161 |
/** void return type invokers. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1162 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1163 |
static Object invoke__V(MethodHandle mh, Object[] a) throws Throwable { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1164 |
assert(arityCheck(0, void.class, mh, a)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1165 |
mh.invokeBasic(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1166 |
return null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1167 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1168 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1169 |
static Object invoke_L_V(MethodHandle mh, Object[] a) throws Throwable { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1170 |
assert(arityCheck(1, void.class, mh, a)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1171 |
mh.invokeBasic(a[0]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1172 |
return null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1173 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1174 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1175 |
static Object invoke_LL_V(MethodHandle mh, Object[] a) throws Throwable { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1176 |
assert(arityCheck(2, void.class, mh, a)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1177 |
mh.invokeBasic(a[0], a[1]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1178 |
return null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1179 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1180 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1181 |
static Object invoke_LLL_V(MethodHandle mh, Object[] a) throws Throwable { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1182 |
assert(arityCheck(3, void.class, mh, a)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1183 |
mh.invokeBasic(a[0], a[1], a[2]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1184 |
return null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1185 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1186 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1187 |
static Object invoke_LLLL_V(MethodHandle mh, Object[] a) throws Throwable { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1188 |
assert(arityCheck(4, void.class, mh, a)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1189 |
mh.invokeBasic(a[0], a[1], a[2], a[3]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1190 |
return null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1191 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1192 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1193 |
static Object invoke_LLLLL_V(MethodHandle mh, Object[] a) throws Throwable { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1194 |
assert(arityCheck(5, void.class, mh, a)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1195 |
mh.invokeBasic(a[0], a[1], a[2], a[3], a[4]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1196 |
return null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1197 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1198 |
/** Object return type invokers. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1199 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1200 |
static Object invoke__L(MethodHandle mh, Object[] a) throws Throwable { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1201 |
assert(arityCheck(0, mh, a)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1202 |
return mh.invokeBasic(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1203 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1204 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1205 |
static Object invoke_L_L(MethodHandle mh, Object[] a) throws Throwable { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1206 |
assert(arityCheck(1, mh, a)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1207 |
return mh.invokeBasic(a[0]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1208 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1209 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1210 |
static Object invoke_LL_L(MethodHandle mh, Object[] a) throws Throwable { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1211 |
assert(arityCheck(2, mh, a)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1212 |
return mh.invokeBasic(a[0], a[1]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1213 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1214 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1215 |
static Object invoke_LLL_L(MethodHandle mh, Object[] a) throws Throwable { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1216 |
assert(arityCheck(3, mh, a)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1217 |
return mh.invokeBasic(a[0], a[1], a[2]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1218 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1219 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1220 |
static Object invoke_LLLL_L(MethodHandle mh, Object[] a) throws Throwable { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1221 |
assert(arityCheck(4, mh, a)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1222 |
return mh.invokeBasic(a[0], a[1], a[2], a[3]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1223 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1224 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1225 |
static Object invoke_LLLLL_L(MethodHandle mh, Object[] a) throws Throwable { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1226 |
assert(arityCheck(5, mh, a)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1227 |
return mh.invokeBasic(a[0], a[1], a[2], a[3], a[4]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1228 |
} |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1229 |
private static boolean arityCheck(int arity, MethodHandle mh, Object[] a) { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1230 |
return arityCheck(arity, Object.class, mh, a); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1231 |
} |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1232 |
private static boolean arityCheck(int arity, Class<?> rtype, MethodHandle mh, Object[] a) { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1233 |
assert(a.length == arity) |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1234 |
: Arrays.asList(a.length, arity); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1235 |
assert(mh.type().basicType() == MethodType.genericMethodType(arity).changeReturnType(rtype)) |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1236 |
: Arrays.asList(mh, rtype, arity); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1237 |
MemberName member = mh.internalMemberName(); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1238 |
if (member != null && member.getName().equals("invokeBasic") && member.isMethodHandleInvoke()) { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1239 |
assert(arity > 0); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1240 |
assert(a[0] instanceof MethodHandle); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1241 |
MethodHandle mh2 = (MethodHandle) a[0]; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1242 |
assert(mh2.type().basicType() == MethodType.genericMethodType(arity-1).changeReturnType(rtype)) |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1243 |
: Arrays.asList(member, mh2, rtype, arity); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1244 |
} |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1245 |
return true; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1246 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1247 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1248 |
static final MethodType INVOKER_METHOD_TYPE = |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1249 |
MethodType.methodType(Object.class, MethodHandle.class, Object[].class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1250 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1251 |
private static MethodHandle computeInvoker(MethodTypeForm typeForm) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1252 |
MethodHandle mh = typeForm.namedFunctionInvoker; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1253 |
if (mh != null) return mh; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1254 |
MemberName invoker = InvokerBytecodeGenerator.generateNamedFunctionInvoker(typeForm); // this could take a while |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1255 |
mh = DirectMethodHandle.make(invoker); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1256 |
MethodHandle mh2 = typeForm.namedFunctionInvoker; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1257 |
if (mh2 != null) return mh2; // benign race |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1258 |
if (!mh.type().equals(INVOKER_METHOD_TYPE)) |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1259 |
throw newInternalError(mh.debugString()); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1260 |
return typeForm.namedFunctionInvoker = mh; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1261 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1262 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1263 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1264 |
Object invokeWithArguments(Object... arguments) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1265 |
// If we have a cached invoker, call it right away. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1266 |
// NOTE: The invoker always returns a reference value. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1267 |
if (TRACE_INTERPRETER) return invokeWithArgumentsTracing(arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1268 |
assert(checkArgumentTypes(arguments, methodType())); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1269 |
return invoker().invokeBasic(resolvedHandle(), arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1270 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1271 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1272 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1273 |
Object invokeWithArgumentsTracing(Object[] arguments) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1274 |
Object rval; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1275 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1276 |
traceInterpreter("[ call", this, arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1277 |
if (invoker == null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1278 |
traceInterpreter("| getInvoker", this); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1279 |
invoker(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1280 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1281 |
if (resolvedHandle == null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1282 |
traceInterpreter("| resolve", this); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1283 |
resolvedHandle(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1284 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1285 |
assert(checkArgumentTypes(arguments, methodType())); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1286 |
rval = invoker().invokeBasic(resolvedHandle(), arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1287 |
} catch (Throwable ex) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1288 |
traceInterpreter("] throw =>", ex); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1289 |
throw ex; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1290 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1291 |
traceInterpreter("] return =>", rval); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1292 |
return rval; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1293 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1294 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1295 |
private MethodHandle invoker() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1296 |
if (invoker != null) return invoker; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1297 |
// Get an invoker and cache it. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1298 |
return invoker = computeInvoker(methodType().form()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1299 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1300 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1301 |
private static boolean checkArgumentTypes(Object[] arguments, MethodType methodType) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1302 |
if (true) return true; // FIXME |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1303 |
MethodType dstType = methodType.form().erasedType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1304 |
MethodType srcType = dstType.basicType().wrap(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1305 |
Class<?>[] ptypes = new Class<?>[arguments.length]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1306 |
for (int i = 0; i < arguments.length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1307 |
Object arg = arguments[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1308 |
Class<?> ptype = arg == null ? Object.class : arg.getClass(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1309 |
// If the dest. type is a primitive we keep the |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1310 |
// argument type. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1311 |
ptypes[i] = dstType.parameterType(i).isPrimitive() ? ptype : Object.class; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1312 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1313 |
MethodType argType = MethodType.methodType(srcType.returnType(), ptypes).wrap(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1314 |
assert(argType.isConvertibleTo(srcType)) : "wrong argument types: cannot convert " + argType + " to " + srcType; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1315 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1316 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1317 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1318 |
MethodType methodType() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1319 |
if (resolvedHandle != null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1320 |
return resolvedHandle.type(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1321 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1322 |
// only for certain internal LFs during bootstrapping |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1323 |
return member.getInvocationType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1324 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1325 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1326 |
MemberName member() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1327 |
assert(assertMemberIsConsistent()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1328 |
return member; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1329 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1330 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1331 |
// Called only from assert. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1332 |
private boolean assertMemberIsConsistent() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1333 |
if (resolvedHandle instanceof DirectMethodHandle) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1334 |
MemberName m = resolvedHandle.internalMemberName(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1335 |
assert(m.equals(member)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1336 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1337 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1338 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1339 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1340 |
Class<?> memberDeclaringClassOrNull() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1341 |
return (member == null) ? null : member.getDeclaringClass(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1342 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1343 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1344 |
BasicType returnType() { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1345 |
return basicType(methodType().returnType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1346 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1347 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1348 |
BasicType parameterType(int n) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1349 |
return basicType(methodType().parameterType(n)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1350 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1351 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1352 |
int arity() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1353 |
return methodType().parameterCount(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1354 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1355 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1356 |
public String toString() { |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1357 |
if (member == null) return String.valueOf(resolvedHandle); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1358 |
return member.getDeclaringClass().getSimpleName()+"."+member.getName(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1359 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1360 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1361 |
public boolean isIdentity() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1362 |
return this.equals(identity(returnType())); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1363 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1364 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1365 |
public boolean isConstantZero() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1366 |
return this.equals(constantZero(returnType())); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1367 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1368 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1369 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1370 |
public static String basicTypeSignature(MethodType type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1371 |
char[] sig = new char[type.parameterCount() + 2]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1372 |
int sigp = 0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1373 |
for (Class<?> pt : type.parameterList()) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1374 |
sig[sigp++] = basicTypeChar(pt); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1375 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1376 |
sig[sigp++] = '_'; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1377 |
sig[sigp++] = basicTypeChar(type.returnType()); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1378 |
assert(sigp == sig.length); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1379 |
return String.valueOf(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1380 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1381 |
public static String shortenSignature(String signature) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1382 |
// Hack to make signatures more readable when they show up in method names. |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1383 |
final int NO_CHAR = -1, MIN_RUN = 3; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1384 |
int c0, c1 = NO_CHAR, c1reps = 0; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1385 |
StringBuilder buf = null; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1386 |
int len = signature.length(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1387 |
if (len < MIN_RUN) return signature; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1388 |
for (int i = 0; i <= len; i++) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1389 |
// shift in the next char: |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1390 |
c0 = c1; c1 = (i == len ? NO_CHAR : signature.charAt(i)); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1391 |
if (c1 == c0) { ++c1reps; continue; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1392 |
// shift in the next count: |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1393 |
int c0reps = c1reps; c1reps = 1; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1394 |
// end of a character run |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1395 |
if (c0reps < MIN_RUN) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1396 |
if (buf != null) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1397 |
while (--c0reps >= 0) |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1398 |
buf.append((char)c0); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1399 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1400 |
continue; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1401 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1402 |
// found three or more in a row |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1403 |
if (buf == null) |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1404 |
buf = new StringBuilder().append(signature, 0, i - c0reps); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1405 |
buf.append((char)c0).append(c0reps); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1406 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1407 |
return (buf == null) ? signature : buf.toString(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1408 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1409 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1410 |
static final class Name { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1411 |
final BasicType type; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1412 |
private short index; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1413 |
final NamedFunction function; |
20494
cf77ae5ff678
8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents:
14852
diff
changeset
|
1414 |
@Stable final Object[] arguments; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1415 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1416 |
private Name(int index, BasicType type, NamedFunction function, Object[] arguments) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1417 |
this.index = (short)index; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1418 |
this.type = type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1419 |
this.function = function; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1420 |
this.arguments = arguments; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1421 |
assert(this.index == index); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1422 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1423 |
Name(MethodHandle function, Object... arguments) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1424 |
this(new NamedFunction(function), arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1425 |
} |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1426 |
Name(MethodType functionType, Object... arguments) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1427 |
this(new NamedFunction(functionType), arguments); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1428 |
assert(arguments[0] instanceof Name && ((Name)arguments[0]).type == L_TYPE); |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1429 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1430 |
Name(MemberName function, Object... arguments) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1431 |
this(new NamedFunction(function), arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1432 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1433 |
Name(NamedFunction function, Object... arguments) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1434 |
this(-1, function.returnType(), function, arguments = Arrays.copyOf(arguments, arguments.length, Object[].class)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1435 |
assert(arguments.length == function.arity()) : "arity mismatch: arguments.length=" + arguments.length + " == function.arity()=" + function.arity() + " in " + debugString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1436 |
for (int i = 0; i < arguments.length; i++) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1437 |
assert(typesMatch(function.parameterType(i), arguments[i])) : "types don't match: function.parameterType(" + i + ")=" + function.parameterType(i) + ", arguments[" + i + "]=" + arguments[i] + " in " + debugString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1438 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1439 |
/** Create a raw parameter of the given type, with an expected index. */ |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1440 |
Name(int index, BasicType type) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1441 |
this(index, type, null, null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1442 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1443 |
/** Create a raw parameter of the given type. */ |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1444 |
Name(BasicType type) { this(-1, type); } |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1445 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1446 |
BasicType type() { return type; } |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1447 |
int index() { return index; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1448 |
boolean initIndex(int i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1449 |
if (index != i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1450 |
if (index != -1) return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1451 |
index = (short)i; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1452 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1453 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1454 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1455 |
char typeChar() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1456 |
return type.btChar; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1457 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1458 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1459 |
void resolve() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1460 |
if (function != null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1461 |
function.resolve(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1462 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1463 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1464 |
Name newIndex(int i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1465 |
if (initIndex(i)) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1466 |
return cloneWithIndex(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1467 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1468 |
Name cloneWithIndex(int i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1469 |
Object[] newArguments = (arguments == null) ? null : arguments.clone(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1470 |
return new Name(i, type, function, newArguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1471 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1472 |
Name replaceName(Name oldName, Name newName) { // FIXME: use replaceNames uniformly |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1473 |
if (oldName == newName) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1474 |
@SuppressWarnings("LocalVariableHidesMemberVariable") |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1475 |
Object[] arguments = this.arguments; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1476 |
if (arguments == null) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1477 |
boolean replaced = false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1478 |
for (int j = 0; j < arguments.length; j++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1479 |
if (arguments[j] == oldName) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1480 |
if (!replaced) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1481 |
replaced = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1482 |
arguments = arguments.clone(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1483 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1484 |
arguments[j] = newName; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1485 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1486 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1487 |
if (!replaced) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1488 |
return new Name(function, arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1489 |
} |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1490 |
/** In the arguments of this Name, replace oldNames[i] pairwise by newNames[i]. |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1491 |
* Limit such replacements to {@code start<=i<end}. Return possibly changed self. |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1492 |
*/ |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1493 |
Name replaceNames(Name[] oldNames, Name[] newNames, int start, int end) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1494 |
if (start >= end) return this; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1495 |
@SuppressWarnings("LocalVariableHidesMemberVariable") |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1496 |
Object[] arguments = this.arguments; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1497 |
boolean replaced = false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1498 |
eachArg: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1499 |
for (int j = 0; j < arguments.length; j++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1500 |
if (arguments[j] instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1501 |
Name n = (Name) arguments[j]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1502 |
int check = n.index; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1503 |
// harmless check to see if the thing is already in newNames: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1504 |
if (check >= 0 && check < newNames.length && n == newNames[check]) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1505 |
continue eachArg; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1506 |
// n might not have the correct index: n != oldNames[n.index]. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1507 |
for (int i = start; i < end; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1508 |
if (n == oldNames[i]) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1509 |
if (n == newNames[i]) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1510 |
continue eachArg; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1511 |
if (!replaced) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1512 |
replaced = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1513 |
arguments = arguments.clone(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1514 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1515 |
arguments[j] = newNames[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1516 |
continue eachArg; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1517 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1518 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1519 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1520 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1521 |
if (!replaced) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1522 |
return new Name(function, arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1523 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1524 |
void internArguments() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1525 |
@SuppressWarnings("LocalVariableHidesMemberVariable") |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1526 |
Object[] arguments = this.arguments; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1527 |
for (int j = 0; j < arguments.length; j++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1528 |
if (arguments[j] instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1529 |
Name n = (Name) arguments[j]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1530 |
if (n.isParam() && n.index < INTERNED_ARGUMENT_LIMIT) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1531 |
arguments[j] = internArgument(n); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1532 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1533 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1534 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1535 |
boolean isParam() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1536 |
return function == null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1537 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1538 |
boolean isConstantZero() { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1539 |
return !isParam() && arguments.length == 0 && function.isConstantZero(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1540 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1541 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1542 |
public String toString() { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1543 |
return (isParam()?"a":"t")+(index >= 0 ? index : System.identityHashCode(this))+":"+typeChar(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1544 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1545 |
public String debugString() { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1546 |
String s = paramString(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1547 |
return (function == null) ? s : s + "=" + exprString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1548 |
} |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1549 |
public String paramString() { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1550 |
return toString(); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1551 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1552 |
public String exprString() { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1553 |
if (function == null) return toString(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1554 |
StringBuilder buf = new StringBuilder(function.toString()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1555 |
buf.append("("); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1556 |
String cma = ""; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1557 |
for (Object a : arguments) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1558 |
buf.append(cma); cma = ","; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1559 |
if (a instanceof Name || a instanceof Integer) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1560 |
buf.append(a); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1561 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1562 |
buf.append("(").append(a).append(")"); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1563 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1564 |
buf.append(")"); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1565 |
return buf.toString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1566 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1567 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1568 |
static boolean typesMatch(BasicType parameterType, Object object) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1569 |
if (object instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1570 |
return ((Name)object).type == parameterType; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1571 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1572 |
switch (parameterType) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1573 |
case I_TYPE: return object instanceof Integer; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1574 |
case J_TYPE: return object instanceof Long; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1575 |
case F_TYPE: return object instanceof Float; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1576 |
case D_TYPE: return object instanceof Double; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1577 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1578 |
assert(parameterType == L_TYPE); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1579 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1580 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1581 |
|
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1582 |
/** Return the index of the last occurrence of n in the argument array. |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1583 |
* Return -1 if the name is not used. |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1584 |
*/ |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1585 |
int lastUseIndex(Name n) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1586 |
if (arguments == null) return -1; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1587 |
for (int i = arguments.length; --i >= 0; ) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1588 |
if (arguments[i] == n) return i; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1589 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1590 |
return -1; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1591 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1592 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1593 |
/** Return the number of occurrences of n in the argument array. |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1594 |
* Return 0 if the name is not used. |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1595 |
*/ |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1596 |
int useCount(Name n) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1597 |
if (arguments == null) return 0; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1598 |
int count = 0; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1599 |
for (int i = arguments.length; --i >= 0; ) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1600 |
if (arguments[i] == n) ++count; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1601 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1602 |
return count; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1603 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1604 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1605 |
boolean contains(Name n) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1606 |
return this == n || lastUseIndex(n) >= 0; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1607 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1608 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1609 |
public boolean equals(Name that) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1610 |
if (this == that) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1611 |
if (isParam()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1612 |
// each parameter is a unique atom |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1613 |
return false; // this != that |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1614 |
return |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1615 |
//this.index == that.index && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1616 |
this.type == that.type && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1617 |
this.function.equals(that.function) && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1618 |
Arrays.equals(this.arguments, that.arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1619 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1620 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1621 |
public boolean equals(Object x) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1622 |
return x instanceof Name && equals((Name)x); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1623 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1624 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1625 |
public int hashCode() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1626 |
if (isParam()) |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1627 |
return index | (type.ordinal() << 8); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1628 |
return function.hashCode() ^ Arrays.hashCode(arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1629 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1630 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1631 |
|
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1632 |
/** Return the index of the last name which contains n as an argument. |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1633 |
* Return -1 if the name is not used. Return names.length if it is the return value. |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1634 |
*/ |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1635 |
int lastUseIndex(Name n) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1636 |
int ni = n.index, nmax = names.length; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1637 |
assert(names[ni] == n); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1638 |
if (result == ni) return nmax; // live all the way beyond the end |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1639 |
for (int i = nmax; --i > ni; ) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1640 |
if (names[i].lastUseIndex(n) >= 0) |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1641 |
return i; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1642 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1643 |
return -1; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1644 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1645 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1646 |
/** Return the number of times n is used as an argument or return value. */ |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1647 |
int useCount(Name n) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1648 |
int ni = n.index, nmax = names.length; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1649 |
int end = lastUseIndex(n); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1650 |
if (end < 0) return 0; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1651 |
int count = 0; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1652 |
if (end == nmax) { count++; end--; } |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1653 |
int beg = n.index() + 1; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1654 |
if (beg < arity) beg = arity; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1655 |
for (int i = beg; i <= end; i++) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1656 |
count += names[i].useCount(n); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1657 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1658 |
return count; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1659 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1660 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1661 |
static Name argument(int which, char type) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1662 |
return argument(which, basicType(type)); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1663 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1664 |
static Name argument(int which, BasicType type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1665 |
if (which >= INTERNED_ARGUMENT_LIMIT) |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1666 |
return new Name(which, type); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1667 |
return INTERNED_ARGUMENTS[type.ordinal()][which]; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1668 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1669 |
static Name internArgument(Name n) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1670 |
assert(n.isParam()) : "not param: " + n; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1671 |
assert(n.index < INTERNED_ARGUMENT_LIMIT); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1672 |
return argument(n.index, n.type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1673 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1674 |
static Name[] arguments(int extra, String types) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1675 |
int length = types.length(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1676 |
Name[] names = new Name[length + extra]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1677 |
for (int i = 0; i < length; i++) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1678 |
names[i] = argument(i, types.charAt(i)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1679 |
return names; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1680 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1681 |
static Name[] arguments(int extra, char... types) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1682 |
int length = types.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1683 |
Name[] names = new Name[length + extra]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1684 |
for (int i = 0; i < length; i++) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1685 |
names[i] = argument(i, types[i]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1686 |
return names; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1687 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1688 |
static Name[] arguments(int extra, List<Class<?>> types) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1689 |
int length = types.size(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1690 |
Name[] names = new Name[length + extra]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1691 |
for (int i = 0; i < length; i++) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1692 |
names[i] = argument(i, basicType(types.get(i))); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1693 |
return names; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1694 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1695 |
static Name[] arguments(int extra, Class<?>... types) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1696 |
int length = types.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1697 |
Name[] names = new Name[length + extra]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1698 |
for (int i = 0; i < length; i++) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1699 |
names[i] = argument(i, basicType(types[i])); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1700 |
return names; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1701 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1702 |
static Name[] arguments(int extra, MethodType types) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1703 |
int length = types.parameterCount(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1704 |
Name[] names = new Name[length + extra]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1705 |
for (int i = 0; i < length; i++) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1706 |
names[i] = argument(i, basicType(types.parameterType(i))); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1707 |
return names; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1708 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1709 |
static final int INTERNED_ARGUMENT_LIMIT = 10; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1710 |
private static final Name[][] INTERNED_ARGUMENTS |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1711 |
= new Name[ARG_TYPE_LIMIT][INTERNED_ARGUMENT_LIMIT]; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1712 |
static { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1713 |
for (BasicType type : BasicType.ARG_TYPES) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1714 |
int ord = type.ordinal(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1715 |
for (int i = 0; i < INTERNED_ARGUMENTS[ord].length; i++) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1716 |
INTERNED_ARGUMENTS[ord][i] = new Name(i, type); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1717 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1718 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1719 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1720 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1721 |
private static final MemberName.Factory IMPL_NAMES = MemberName.getFactory(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1722 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1723 |
static LambdaForm identityForm(BasicType type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1724 |
return LF_identityForm[type.ordinal()]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1725 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1726 |
static LambdaForm zeroForm(BasicType type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1727 |
return LF_zeroForm[type.ordinal()]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1728 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1729 |
static NamedFunction identity(BasicType type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1730 |
return NF_identity[type.ordinal()]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1731 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1732 |
static NamedFunction constantZero(BasicType type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1733 |
return NF_zero[type.ordinal()]; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1734 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1735 |
private static final LambdaForm[] LF_identityForm = new LambdaForm[TYPE_LIMIT]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1736 |
private static final LambdaForm[] LF_zeroForm = new LambdaForm[TYPE_LIMIT]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1737 |
private static final NamedFunction[] NF_identity = new NamedFunction[TYPE_LIMIT]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1738 |
private static final NamedFunction[] NF_zero = new NamedFunction[TYPE_LIMIT]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1739 |
private static void createIdentityForms() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1740 |
for (BasicType type : BasicType.ALL_TYPES) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1741 |
int ord = type.ordinal(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1742 |
char btChar = type.basicTypeChar(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1743 |
boolean isVoid = (type == V_TYPE); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1744 |
Class<?> btClass = type.btClass; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1745 |
MethodType zeType = MethodType.methodType(btClass); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1746 |
MethodType idType = isVoid ? zeType : zeType.appendParameterTypes(btClass); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1747 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1748 |
// Look up some symbolic names. It might not be necessary to have these, |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1749 |
// but if we need to emit direct references to bytecodes, it helps. |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1750 |
// Zero is built from a call to an identity function with a constant zero input. |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1751 |
MemberName idMem = new MemberName(LambdaForm.class, "identity_"+btChar, idType, REF_invokeStatic); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1752 |
MemberName zeMem = new MemberName(LambdaForm.class, "zero_"+btChar, zeType, REF_invokeStatic); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1753 |
try { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1754 |
zeMem = IMPL_NAMES.resolveOrFail(REF_invokeStatic, zeMem, null, NoSuchMethodException.class); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1755 |
idMem = IMPL_NAMES.resolveOrFail(REF_invokeStatic, idMem, null, NoSuchMethodException.class); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1756 |
} catch (IllegalAccessException|NoSuchMethodException ex) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
1757 |
throw newInternalError(ex); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1758 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1759 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1760 |
NamedFunction idFun = new NamedFunction(idMem); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1761 |
LambdaForm idForm; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1762 |
if (isVoid) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1763 |
Name[] idNames = new Name[] { argument(0, L_TYPE) }; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1764 |
idForm = new LambdaForm(idMem.getName(), 1, idNames, VOID_RESULT); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1765 |
} else { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1766 |
Name[] idNames = new Name[] { argument(0, L_TYPE), argument(1, type) }; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1767 |
idForm = new LambdaForm(idMem.getName(), 2, idNames, 1); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1768 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1769 |
LF_identityForm[ord] = idForm; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1770 |
NF_identity[ord] = idFun; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1771 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1772 |
NamedFunction zeFun = new NamedFunction(zeMem); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1773 |
LambdaForm zeForm; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1774 |
if (isVoid) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1775 |
zeForm = idForm; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1776 |
} else { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1777 |
Object zeValue = Wrapper.forBasicType(btChar).zero(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1778 |
Name[] zeNames = new Name[] { argument(0, L_TYPE), new Name(idFun, zeValue) }; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1779 |
zeForm = new LambdaForm(zeMem.getName(), 1, zeNames, 1); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1780 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1781 |
LF_zeroForm[ord] = zeForm; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1782 |
NF_zero[ord] = zeFun; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1783 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1784 |
assert(idFun.isIdentity()); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1785 |
assert(zeFun.isConstantZero()); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1786 |
assert(new Name(zeFun).isConstantZero()); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1787 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1788 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1789 |
// Do this in a separate pass, so that SimpleMethodHandle.make can see the tables. |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1790 |
for (BasicType type : BasicType.ALL_TYPES) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1791 |
int ord = type.ordinal(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1792 |
NamedFunction idFun = NF_identity[ord]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1793 |
LambdaForm idForm = LF_identityForm[ord]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1794 |
MemberName idMem = idFun.member; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1795 |
idFun.resolvedHandle = SimpleMethodHandle.make(idMem.getInvocationType(), idForm); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1796 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1797 |
NamedFunction zeFun = NF_zero[ord]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1798 |
LambdaForm zeForm = LF_zeroForm[ord]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1799 |
MemberName zeMem = zeFun.member; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1800 |
zeFun.resolvedHandle = SimpleMethodHandle.make(zeMem.getInvocationType(), zeForm); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1801 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1802 |
assert(idFun.isIdentity()); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1803 |
assert(zeFun.isConstantZero()); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1804 |
assert(new Name(zeFun).isConstantZero()); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1805 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1806 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1807 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1808 |
// Avoid appealing to ValueConversions at bootstrap time: |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1809 |
private static int identity_I(int x) { return x; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1810 |
private static long identity_J(long x) { return x; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1811 |
private static float identity_F(float x) { return x; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1812 |
private static double identity_D(double x) { return x; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1813 |
private static Object identity_L(Object x) { return x; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1814 |
private static void identity_V() { return; } // same as zeroV, but that's OK |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1815 |
private static int zero_I() { return 0; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1816 |
private static long zero_J() { return 0; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1817 |
private static float zero_F() { return 0; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1818 |
private static double zero_D() { return 0; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1819 |
private static Object zero_L() { return null; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1820 |
private static void zero_V() { return; } |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1821 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1822 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1823 |
* Internal marker for byte-compiled LambdaForms. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1824 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1825 |
/*non-public*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1826 |
@Target(ElementType.METHOD) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1827 |
@Retention(RetentionPolicy.RUNTIME) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1828 |
@interface Compiled { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1829 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1830 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1831 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1832 |
* Internal marker for LambdaForm interpreter frames. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1833 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1834 |
/*non-public*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1835 |
@Target(ElementType.METHOD) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1836 |
@Retention(RetentionPolicy.RUNTIME) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1837 |
@interface Hidden { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1838 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1839 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1840 |
private static final HashMap<String,Integer> DEBUG_NAME_COUNTERS; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1841 |
static { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1842 |
if (debugEnabled()) |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1843 |
DEBUG_NAME_COUNTERS = new HashMap<>(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1844 |
else |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1845 |
DEBUG_NAME_COUNTERS = null; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1846 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1847 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1848 |
// Put this last, so that previous static inits can run before. |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1849 |
static { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1850 |
createIdentityForms(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1851 |
if (USE_PREDEFINED_INTERPRET_METHODS) |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1852 |
computeInitialPreparedForms(); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1853 |
NamedFunction.initializeInvokers(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1854 |
} |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1855 |
|
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1856 |
// The following hack is necessary in order to suppress TRACE_INTERPRETER |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1857 |
// during execution of the static initializes of this class. |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1858 |
// Turning on TRACE_INTERPRETER too early will cause |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1859 |
// stack overflows and other misbehavior during attempts to trace events |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1860 |
// that occur during LambdaForm.<clinit>. |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1861 |
// Therefore, do not move this line higher in this file, and do not remove. |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1862 |
private static final boolean TRACE_INTERPRETER = MethodHandleStatics.TRACE_INTERPRETER; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1863 |
} |