author | jrose |
Sat, 05 Oct 2013 05:30:38 -0700 | |
changeset 20527 | d241258cfbcb |
parent 20494 | cf77ae5ff678 |
child 20535 | cc85c8626435 |
permissions | -rw-r--r-- |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1 |
/* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
2 |
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
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.ArrayList; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
34 |
import java.util.HashMap; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
35 |
import java.util.concurrent.ConcurrentHashMap; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
36 |
import sun.invoke.util.Wrapper; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
37 |
import static java.lang.invoke.MethodHandleStatics.*; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
38 |
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
|
39 |
import java.lang.reflect.Field; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
40 |
import java.util.Objects; |
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: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
53 |
* <pre> |
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" |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
63 |
* </pre> |
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. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
72 |
* Note that all reference types are erased to "L", which stands for {@code Object). |
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: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
92 |
* <pre> |
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 |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
116 |
* </pre> |
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 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
133 |
LambdaForm(String debugName, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
134 |
int arity, Name[] names, int result) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
135 |
assert(namesOK(arity, names)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
136 |
this.arity = arity; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
137 |
this.result = fixResult(result, names); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
138 |
this.names = names.clone(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
139 |
this.debugName = debugName; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
140 |
normalize(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
141 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
142 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
143 |
LambdaForm(String debugName, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
144 |
int arity, Name[] names) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
145 |
this(debugName, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
146 |
arity, names, LAST_RESULT); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
147 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
148 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
149 |
LambdaForm(String debugName, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
150 |
Name[] formals, Name[] temps, Name result) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
151 |
this(debugName, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
152 |
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
|
153 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
154 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
155 |
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
|
156 |
int arity = formals.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
157 |
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
|
158 |
Name[] names = Arrays.copyOf(formals, length); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
159 |
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
|
160 |
if (result != null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
161 |
names[length - 1] = result; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
162 |
return names; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
163 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
164 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
165 |
private LambdaForm(String sig) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
166 |
// 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
|
167 |
// 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
|
168 |
// Called only from getPreparedForm. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
169 |
assert(isValidSignature(sig)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
170 |
this.arity = signatureArity(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
171 |
this.result = (signatureReturn(sig) == 'V' ? -1 : arity); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
172 |
this.names = buildEmptyNames(arity, sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
173 |
this.debugName = "LF.zero"; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
174 |
assert(nameRefsAreLegal()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
175 |
assert(isEmpty()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
176 |
assert(sig.equals(basicTypeSignature())); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
177 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
178 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
179 |
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
|
180 |
assert(isValidSignature(basicTypeSignature)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
181 |
int resultPos = arity + 1; // skip '_' |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
182 |
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
|
183 |
throw new IllegalArgumentException("bad arity for "+basicTypeSignature); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
184 |
int numRes = (basicTypeSignature.charAt(resultPos) == 'V' ? 0 : 1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
185 |
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
|
186 |
for (int i = 0; i < numRes; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
187 |
names[arity + i] = constantZero(arity + i, basicTypeSignature.charAt(resultPos + i)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
188 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
189 |
return names; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
190 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
191 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
192 |
private static int fixResult(int result, Name[] names) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
193 |
if (result >= 0) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
194 |
if (names[result].type == 'V') |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
195 |
return -1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
196 |
} else if (result == LAST_RESULT) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
197 |
return names.length - 1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
198 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
199 |
return result; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
200 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
201 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
202 |
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
|
203 |
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
|
204 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
205 |
assert(n != null) : "n is null"; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
206 |
if (i < arity) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
207 |
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
|
208 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
209 |
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
|
210 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
211 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
212 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
213 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
214 |
/** Renumber and/or replace params so that they are interned and canonically numbered. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
215 |
private void normalize() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
216 |
Name[] oldNames = null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
217 |
int changesStart = 0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
218 |
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
|
219 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
220 |
if (!n.initIndex(i)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
221 |
if (oldNames == null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
222 |
oldNames = names.clone(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
223 |
changesStart = i; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
224 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
225 |
names[i] = n.cloneWithIndex(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
226 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
227 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
228 |
if (oldNames != null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
229 |
int startFixing = arity; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
230 |
if (startFixing <= changesStart) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
231 |
startFixing = changesStart+1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
232 |
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
|
233 |
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
|
234 |
names[i] = fixed.newIndex(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
235 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
236 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
237 |
assert(nameRefsAreLegal()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
238 |
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
|
239 |
boolean needIntern = false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
240 |
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
|
241 |
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
|
242 |
if (n != n2) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
243 |
names[i] = n2; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
244 |
needIntern = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
245 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
246 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
247 |
if (needIntern) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
248 |
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
|
249 |
names[i].internArguments(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
250 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
251 |
assert(nameRefsAreLegal()); |
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 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
255 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
256 |
* 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
|
257 |
* 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
|
258 |
* <p> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
259 |
* 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
|
260 |
* 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
|
261 |
* 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
|
262 |
* fresh lambdas, without confusion. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
263 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
264 |
private boolean nameRefsAreLegal() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
265 |
assert(arity >= 0 && arity <= names.length); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
266 |
assert(result >= -1 && result < names.length); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
267 |
// 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
|
268 |
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
|
269 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
270 |
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
|
271 |
assert(n.isParam()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
272 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
273 |
// Also, do all local name references |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
274 |
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
|
275 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
276 |
assert(n.index() == i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
277 |
for (Object arg : n.arguments) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
278 |
if (arg instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
279 |
Name n2 = (Name) arg; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
280 |
int i2 = n2.index; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
285 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
286 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
287 |
return true; |
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 |
/** 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
|
291 |
// 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
|
292 |
// // 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
|
293 |
// return interpretWithArguments(args); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
294 |
// } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
295 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
296 |
/** Report the return type. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
297 |
char returnType() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
298 |
if (result < 0) return 'V'; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
299 |
Name n = names[result]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
300 |
return n.type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
301 |
} |
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 |
/** Report the N-th argument type. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
304 |
char parameterType(int n) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
305 |
assert(n < arity); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
306 |
return names[n].type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
307 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
308 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
309 |
/** Report the arity. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
310 |
int arity() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
311 |
return arity; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
312 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
313 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
314 |
/** 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
|
315 |
MethodType methodType() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
316 |
return signatureType(basicTypeSignature()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
317 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
318 |
/** 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
|
319 |
final String basicTypeSignature() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
320 |
StringBuilder buf = new StringBuilder(arity() + 3); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
321 |
for (int i = 0, a = arity(); i < a; i++) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
322 |
buf.append(parameterType(i)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
323 |
return buf.append('_').append(returnType()).toString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
324 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
325 |
static int signatureArity(String sig) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
326 |
assert(isValidSignature(sig)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
327 |
return sig.indexOf('_'); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
328 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
329 |
static char signatureReturn(String sig) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
330 |
return sig.charAt(signatureArity(sig)+1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
331 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
332 |
static boolean isValidSignature(String sig) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
333 |
int arity = sig.indexOf('_'); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
334 |
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
|
335 |
int siglen = sig.length(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
336 |
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
|
337 |
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
|
338 |
if (i == arity) continue; // skip '_' |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
339 |
char c = sig.charAt(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
340 |
if (c == 'V') |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
341 |
return (i == siglen - 1 && arity == siglen - 2); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
342 |
if (ALL_TYPES.indexOf(c) < 0) return false; // must be [LIJFD] |
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 |
return true; // [LIJFD]*_[LIJFDV] |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
345 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
346 |
static Class<?> typeClass(char t) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
347 |
switch (t) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
348 |
case 'I': return int.class; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
349 |
case 'J': return long.class; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
350 |
case 'F': return float.class; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
351 |
case 'D': return double.class; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
352 |
case 'L': return Object.class; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
353 |
case 'V': return void.class; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
354 |
default: assert false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
355 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
356 |
return null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
357 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
358 |
static MethodType signatureType(String sig) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
359 |
Class<?>[] ptypes = new Class<?>[signatureArity(sig)]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
360 |
for (int i = 0; i < ptypes.length; i++) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
361 |
ptypes[i] = typeClass(sig.charAt(i)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
362 |
Class<?> rtype = typeClass(signatureReturn(sig)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
363 |
return MethodType.methodType(rtype, ptypes); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
364 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
365 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
366 |
/* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
367 |
* Code generation issues: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
368 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
369 |
* 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
|
370 |
* 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
|
371 |
* 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
|
372 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
373 |
* 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
|
374 |
* 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
|
375 |
* 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
|
376 |
* 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
|
377 |
* 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
|
378 |
* 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
|
379 |
* 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
|
380 |
* 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
|
381 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
382 |
* 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
|
383 |
* 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
|
384 |
* 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
|
385 |
* 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
|
386 |
* 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
|
387 |
* 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
|
388 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
389 |
* 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
|
390 |
* 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
|
391 |
* 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
|
392 |
* 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
|
393 |
* (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
|
394 |
* 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
|
395 |
* (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
|
396 |
* 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
|
397 |
* 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
|
398 |
* 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
|
399 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
400 |
* 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
|
401 |
* 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
|
402 |
* "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
|
403 |
* 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
|
404 |
* 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
|
405 |
* 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
|
406 |
* (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
|
407 |
* 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
|
408 |
* 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
|
409 |
* 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
|
410 |
* optimization. "Significant" means optimization of |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
411 |
* code that is actually hot. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
412 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
413 |
* 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
|
414 |
* 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
|
415 |
* 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
|
416 |
* 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
|
417 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
418 |
* 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
|
419 |
* 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
|
420 |
* 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
|
421 |
* 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
|
422 |
* 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
|
423 |
* 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
|
424 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
425 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
426 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
427 |
* 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
|
428 |
* 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
|
429 |
* before invocation. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
430 |
* (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
|
431 |
* 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
|
432 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
433 |
public void prepare() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
434 |
if (COMPILE_THRESHOLD == 0) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
435 |
compileToBytecode(); |
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 |
if (this.vmentry != null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
438 |
// 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
|
439 |
return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
440 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
441 |
LambdaForm prep = getPreparedForm(basicTypeSignature()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
442 |
this.vmentry = prep.vmentry; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
443 |
// TO DO: Maybe add invokeGeneric, invokeWithArguments |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
444 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
445 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
446 |
/** Generate optimizable bytecode for this form. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
447 |
MemberName compileToBytecode() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
448 |
MethodType invokerType = methodType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
449 |
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
|
450 |
if (vmentry != null && isCompiled) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
451 |
return vmentry; // already compiled somehow |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
452 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
453 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
454 |
vmentry = InvokerBytecodeGenerator.generateCustomizedCode(this, invokerType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
455 |
if (TRACE_INTERPRETER) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
456 |
traceInterpreter("compileToBytecode", this); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
457 |
isCompiled = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
458 |
return vmentry; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
459 |
} catch (Error | Exception ex) { |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
460 |
throw newInternalError("compileToBytecode", ex); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
461 |
} |
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 |
private static final ConcurrentHashMap<String,LambdaForm> PREPARED_FORMS; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
465 |
static { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
466 |
int capacity = 512; // expect many distinct signatures over time |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
467 |
float loadFactor = 0.75f; // normal default |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
468 |
int writers = 1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
469 |
PREPARED_FORMS = new ConcurrentHashMap<>(capacity, loadFactor, writers); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
470 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
471 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
472 |
private static Map<String,LambdaForm> computeInitialPreparedForms() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
473 |
// 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
|
474 |
HashMap<String,LambdaForm> forms = new HashMap<>(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
475 |
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
|
476 |
if (!m.isStatic() || !m.isPackage()) continue; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
477 |
MethodType mt = m.getMethodType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
478 |
if (mt.parameterCount() > 0 && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
479 |
mt.parameterType(0) == MethodHandle.class && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
480 |
m.getName().startsWith("interpret_")) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
481 |
String sig = basicTypeSignature(mt); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
482 |
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
|
483 |
LambdaForm form = new LambdaForm(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
484 |
form.vmentry = m; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
485 |
mt.form().setCachedLambdaForm(MethodTypeForm.LF_COUNTER, form); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
486 |
// FIXME: get rid of PREPARED_FORMS; use MethodTypeForm cache only |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
487 |
forms.put(sig, form); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
488 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
489 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
490 |
//System.out.println("computeInitialPreparedForms => "+forms); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
491 |
return forms; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
492 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
493 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
494 |
// 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
|
495 |
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
|
496 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
497 |
// 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
|
498 |
// 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
|
499 |
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
|
500 |
Object[] av = {mh}; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
501 |
String sig = null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
502 |
assert(argumentTypesMatch(sig = "L_L", av)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
503 |
Object res = mh.form.interpretWithArguments(av); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
504 |
assert(returnTypesMatch(sig, av, res)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
505 |
return res; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
506 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
507 |
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
|
508 |
Object[] av = {mh, x1}; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
509 |
String sig = null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
510 |
assert(argumentTypesMatch(sig = "LL_L", av)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
511 |
Object res = mh.form.interpretWithArguments(av); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
512 |
assert(returnTypesMatch(sig, av, res)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
513 |
return res; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
514 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
515 |
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
|
516 |
Object[] av = {mh, x1, x2}; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
517 |
String sig = null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
518 |
assert(argumentTypesMatch(sig = "LLL_L", av)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
519 |
Object res = mh.form.interpretWithArguments(av); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
520 |
assert(returnTypesMatch(sig, av, res)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
521 |
return res; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
522 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
523 |
private static LambdaForm getPreparedForm(String sig) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
524 |
MethodType mtype = signatureType(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
525 |
//LambdaForm prep = PREPARED_FORMS.get(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
526 |
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
|
527 |
if (prep != null) return prep; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
528 |
assert(isValidSignature(sig)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
529 |
prep = new LambdaForm(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
530 |
prep.vmentry = InvokerBytecodeGenerator.generateLambdaFormInterpreterEntryPoint(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
531 |
//LambdaForm prep2 = PREPARED_FORMS.putIfAbsent(sig.intern(), prep); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
532 |
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
|
533 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
534 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
535 |
// 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
|
536 |
// 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
|
537 |
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
|
538 |
int arity = signatureArity(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
539 |
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
|
540 |
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
|
541 |
MethodHandle mh = (MethodHandle) av[0]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
542 |
MethodType mt = mh.type(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
543 |
assert(mt.parameterCount() == arity-1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
544 |
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
|
545 |
Class<?> pt = (i == 0 ? MethodHandle.class : mt.parameterType(i-1)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
546 |
assert(valueMatches(sig.charAt(i), pt, av[i])); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
547 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
548 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
549 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
550 |
private static boolean valueMatches(char tc, Class<?> type, Object x) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
551 |
// The following line is needed because (...)void method handles can use non-void invokers |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
552 |
if (type == void.class) tc = 'V'; // can drop any kind of value |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
553 |
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
|
554 |
switch (tc) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
555 |
case 'I': assert checkInt(type, x) : "checkInt(" + type + "," + x +")"; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
556 |
case 'J': assert x instanceof Long : "instanceof Long: " + x; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
557 |
case 'F': assert x instanceof Float : "instanceof Float: " + x; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
558 |
case 'D': assert x instanceof Double : "instanceof Double: " + x; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
559 |
case 'L': assert checkRef(type, x) : "checkRef(" + type + "," + x + ")"; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
560 |
case 'V': break; // allow anything here; will be dropped |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
561 |
default: assert(false); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
562 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
563 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
564 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
565 |
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
|
566 |
MethodHandle mh = (MethodHandle) av[0]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
567 |
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
|
568 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
569 |
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
|
570 |
assert(x instanceof Integer); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
571 |
if (type == int.class) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
572 |
Wrapper w = Wrapper.forBasicType(type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
573 |
assert(w.isSubwordOrInt()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
574 |
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
|
575 |
return x.equals(x1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
576 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
577 |
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
|
578 |
assert(!type.isPrimitive()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
579 |
if (x == null) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
580 |
if (type.isInterface()) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
581 |
return type.isInstance(x); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
582 |
} |
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 |
/** 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
|
585 |
private static final int COMPILE_THRESHOLD; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
586 |
static { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
587 |
if (MethodHandleStatics.COMPILE_THRESHOLD != null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
588 |
COMPILE_THRESHOLD = MethodHandleStatics.COMPILE_THRESHOLD; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
589 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
590 |
COMPILE_THRESHOLD = 30; // default value |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
591 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
592 |
private int invocationCounter = 0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
593 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
594 |
@Hidden |
14852 | 595 |
@DontInline |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
596 |
/** 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
|
597 |
Object interpretWithArguments(Object... argumentValues) throws Throwable { |
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 |
return interpretWithArgumentsTracing(argumentValues); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
600 |
checkInvocationCounter(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
601 |
assert(arityCheck(argumentValues)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
602 |
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
|
603 |
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
|
604 |
values[i] = interpretName(names[i], values); |
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 |
return (result < 0) ? null : values[result]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
607 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
608 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
609 |
@Hidden |
14852 | 610 |
@DontInline |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
611 |
/** 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
|
612 |
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
|
613 |
if (TRACE_INTERPRETER) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
614 |
traceInterpreter("| interpretName", name.debugString(), (Object[]) null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
615 |
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
|
616 |
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
|
617 |
Object a = arguments[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
618 |
if (a instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
619 |
int i2 = ((Name)a).index(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
620 |
assert(names[i2] == a); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
621 |
a = values[i2]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
622 |
arguments[i] = a; |
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 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
625 |
return name.function.invokeWithArguments(arguments); |
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 |
|
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
628 |
private void checkInvocationCounter() { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
629 |
if (COMPILE_THRESHOLD != 0 && |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
630 |
invocationCounter < COMPILE_THRESHOLD) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
631 |
invocationCounter++; // benign race |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
632 |
if (invocationCounter >= COMPILE_THRESHOLD) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
633 |
// 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
|
634 |
compileToBytecode(); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
635 |
} |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
636 |
} |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
637 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
638 |
Object interpretWithArgumentsTracing(Object... argumentValues) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
639 |
traceInterpreter("[ interpretWithArguments", this, argumentValues); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
640 |
if (invocationCounter < COMPILE_THRESHOLD) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
641 |
int ctr = invocationCounter++; // benign race |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
642 |
traceInterpreter("| invocationCounter", ctr); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
643 |
if (invocationCounter >= COMPILE_THRESHOLD) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
644 |
compileToBytecode(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
645 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
646 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
647 |
Object rval; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
648 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
649 |
assert(arityCheck(argumentValues)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
650 |
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
|
651 |
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
|
652 |
values[i] = interpretName(names[i], values); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
653 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
654 |
rval = (result < 0) ? null : values[result]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
655 |
} catch (Throwable ex) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
656 |
traceInterpreter("] throw =>", ex); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
657 |
throw ex; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
658 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
659 |
traceInterpreter("] return =>", rval); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
660 |
return rval; |
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 |
//** 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
|
664 |
/* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
665 |
private static MethodHandle eraseSubwordTypes(MethodHandle mh) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
666 |
MethodType mt = mh.type(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
667 |
if (mt.hasPrimitives()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
668 |
mt = mt.changeReturnType(eraseSubwordType(mt.returnType())); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
669 |
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
|
670 |
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
|
671 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
672 |
mh = MethodHandles.explicitCastArguments(mh, mt); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
673 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
674 |
return mh; |
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 |
private static Class<?> eraseSubwordType(Class<?> type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
677 |
if (!type.isPrimitive()) return type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
678 |
if (type == int.class) return type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
679 |
Wrapper w = Wrapper.forPrimitiveType(type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
680 |
if (w.isSubwordOrInt()) return int.class; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
681 |
return type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
682 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
683 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
684 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
685 |
static void traceInterpreter(String event, Object obj, Object... args) { |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
686 |
if (TRACE_INTERPRETER) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
687 |
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
|
688 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
689 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
690 |
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
|
691 |
traceInterpreter(event, obj, (Object[])null); |
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 boolean arityCheck(Object[] argumentValues) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
694 |
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
|
695 |
// 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
|
696 |
assert(argumentValues[0] instanceof MethodHandle) : "not MH: " + argumentValues[0]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
697 |
assert(((MethodHandle)argumentValues[0]).internalForm() == this); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
698 |
// note: argument #0 could also be an interface wrapper, in the future |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
699 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
700 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
701 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
702 |
private boolean isEmpty() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
703 |
if (result < 0) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
704 |
return (names.length == arity); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
705 |
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
|
706 |
return names[arity].isConstantZero(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
707 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
708 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
709 |
} |
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 |
public String toString() { |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
712 |
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
|
713 |
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
|
714 |
if (i == arity) buf.append(")=>{"); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
715 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
716 |
if (i >= arity) buf.append("\n "); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
717 |
buf.append(n); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
718 |
if (i < arity) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
719 |
if (i+1 < arity) buf.append(","); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
720 |
continue; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
721 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
722 |
buf.append("=").append(n.exprString()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
723 |
buf.append(";"); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
724 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
725 |
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
|
726 |
if (TRACE_INTERPRETER) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
727 |
// Extra verbosity: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
728 |
buf.append(":").append(basicTypeSignature()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
729 |
buf.append("/").append(vmentry); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
730 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
731 |
return buf.toString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
732 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
733 |
|
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 |
* Apply immediate binding for a Name in this form indicated by its position relative to the form. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
736 |
* The first parameter to a LambdaForm, a0:L, always represents the form's method handle, so 0 is not |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
737 |
* accepted as valid. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
738 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
739 |
LambdaForm bindImmediate(int pos, char basicType, Object value) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
740 |
// must be an argument, and the types must match |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
741 |
assert pos > 0 && pos < arity && names[pos].type == basicType && Name.typesMatch(basicType, value); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
742 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
743 |
int arity2 = arity - 1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
744 |
Name[] names2 = new Name[names.length - 1]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
745 |
for (int r = 0, w = 0; r < names.length; ++r, ++w) { // (r)ead from names, (w)rite to names2 |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
746 |
Name n = names[r]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
747 |
if (n.isParam()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
748 |
if (n.index == pos) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
749 |
// do not copy over the argument that is to be replaced with a literal, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
750 |
// but adjust the write index |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
751 |
--w; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
752 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
753 |
names2[w] = new Name(w, n.type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
754 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
755 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
756 |
Object[] arguments2 = new Object[n.arguments.length]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
757 |
for (int i = 0; i < n.arguments.length; ++i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
758 |
Object arg = n.arguments[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
759 |
if (arg instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
760 |
int ni = ((Name) arg).index; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
761 |
if (ni == pos) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
762 |
arguments2[i] = value; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
763 |
} else if (ni < pos) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
764 |
// replacement position not yet passed |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
765 |
arguments2[i] = names2[ni]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
766 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
767 |
// replacement position passed |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
768 |
arguments2[i] = names2[ni - 1]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
769 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
770 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
771 |
arguments2[i] = arg; |
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 |
names2[w] = new Name(n.function, arguments2); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
775 |
names2[w].initIndex(w); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
776 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
777 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
778 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
779 |
int result2 = result == -1 ? -1 : result - 1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
780 |
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
|
781 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
782 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
783 |
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
|
784 |
Name name = names[namePos]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
785 |
BoundMethodHandle.SpeciesData newData = oldData.extendWithType(name.type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
786 |
return bind(name, newData.getterName(names[0], oldData.fieldCount()), oldData, newData); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
787 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
788 |
LambdaForm bind(Name name, Name binding, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
789 |
BoundMethodHandle.SpeciesData oldData, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
790 |
BoundMethodHandle.SpeciesData newData) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
791 |
int pos = name.index; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
792 |
assert(name.isParam()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
793 |
assert(!binding.isParam()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
794 |
assert(name.type == binding.type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
795 |
assert(0 <= pos && pos < arity && names[pos] == name); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
796 |
assert(binding.function.memberDeclaringClassOrNull() == newData.clazz); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
797 |
assert(oldData.getters.length == newData.getters.length-1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
798 |
if (bindCache != null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
799 |
LambdaForm form = bindCache[pos]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
800 |
if (form != null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
801 |
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
|
802 |
return form; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
803 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
804 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
805 |
bindCache = new LambdaForm[arity]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
806 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
807 |
assert(nameRefsAreLegal()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
808 |
int arity2 = arity-1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
809 |
Name[] names2 = names.clone(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
810 |
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
|
811 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
812 |
// 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
|
813 |
// 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
|
814 |
int firstOldRef = -1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
815 |
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
|
816 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
817 |
if (n.function != null && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
818 |
n.function.memberDeclaringClassOrNull() == oldData.clazz) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
819 |
MethodHandle oldGetter = n.function.resolvedHandle; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
820 |
MethodHandle newGetter = null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
821 |
for (int j = 0; j < oldData.getters.length; j++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
822 |
if (oldGetter == oldData.getters[j]) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
823 |
newGetter = newData.getters[j]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
824 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
825 |
if (newGetter != null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
826 |
if (firstOldRef < 0) firstOldRef = i; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
827 |
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
|
828 |
names2[i] = n2; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
829 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
830 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
831 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
832 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
833 |
// 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
|
834 |
// Replace references to 'name' with 'binding'. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
835 |
// 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
|
836 |
// 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
|
837 |
assert(firstOldRef < 0 || firstOldRef > pos); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
838 |
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
|
839 |
if (i <= arity2) continue; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
840 |
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
|
841 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
842 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
843 |
// (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
|
844 |
int insPos = pos; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
845 |
for (; insPos+1 < names2.length; insPos++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
846 |
Name n = names2[insPos+1]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
847 |
if (n.isSiblingBindingBefore(binding)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
848 |
names2[insPos] = n; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
849 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
850 |
break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
851 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
852 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
853 |
names2[insPos] = binding; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
854 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
855 |
// 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
|
856 |
int result2 = result; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
857 |
if (result2 == pos) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
858 |
result2 = insPos; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
859 |
else if (result2 > pos && result2 <= insPos) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
860 |
result2 -= 1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
861 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
862 |
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
|
863 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
864 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
865 |
boolean contains(Name name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
866 |
int pos = name.index(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
867 |
if (pos >= 0) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
868 |
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
|
869 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
870 |
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
|
871 |
if (name.equals(names[i])) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
872 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
873 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
874 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
875 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
876 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
877 |
LambdaForm addArguments(int pos, char... types) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
878 |
assert(pos <= arity); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
879 |
int length = names.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
880 |
int inTypes = types.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
881 |
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
|
882 |
int arity2 = arity + inTypes; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
883 |
int result2 = result; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
884 |
if (result2 >= arity) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
885 |
result2 += inTypes; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
886 |
// names array has MH in slot 0; skip it. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
887 |
int argpos = pos + 1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
888 |
// 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
|
889 |
// 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
|
890 |
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
|
891 |
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
|
892 |
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
|
893 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
894 |
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
|
895 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
896 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
897 |
LambdaForm addArguments(int pos, List<Class<?>> types) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
898 |
char[] basicTypes = new char[types.size()]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
899 |
for (int i = 0; i < basicTypes.length; i++) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
900 |
basicTypes[i] = basicType(types.get(i)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
901 |
return addArguments(pos, basicTypes); |
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 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
904 |
LambdaForm permuteArguments(int skip, int[] reorder, char[] types) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
905 |
// 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
|
906 |
// 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
|
907 |
int length = names.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
908 |
int inTypes = types.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
909 |
int outArgs = reorder.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
910 |
assert(skip+outArgs == arity); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
911 |
assert(permutedTypesMatch(reorder, types, names, skip)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
912 |
int pos = 0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
913 |
// skip trivial first part of reordering: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
914 |
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
|
915 |
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
|
916 |
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
|
917 |
// copy the body: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
918 |
int bodyLength = length - arity; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
919 |
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
|
920 |
int arity2 = names2.length - bodyLength; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
921 |
int result2 = result; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
922 |
if (result2 >= 0) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
923 |
if (result2 < skip+outArgs) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
924 |
// return the corresponding inArg |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
925 |
result2 = reorder[result2-skip]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
926 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
927 |
result2 = result2 - outArgs + inTypes; |
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 |
// rework names in the body: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
931 |
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
|
932 |
Name n = names[skip+j]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
933 |
int i = reorder[j]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
934 |
// 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
|
935 |
Name n2 = names2[skip+i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
936 |
if (n2 == null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
937 |
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
|
938 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
939 |
assert(n2.type == types[i]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
940 |
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
|
941 |
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
|
942 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
943 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
944 |
// 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
|
945 |
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
|
946 |
if (names2[i] == null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
947 |
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
|
948 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
949 |
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
|
950 |
int i = j - arity + arity2; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
951 |
// replace names2[i] by names[j] |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
952 |
Name n = names[j]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
953 |
Name n2 = names2[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
954 |
if (n != n2) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
955 |
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
|
956 |
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
|
957 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
958 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
959 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
960 |
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
|
961 |
} |
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 |
static boolean permutedTypesMatch(int[] reorder, char[] types, Name[] names, int skip) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
964 |
int inTypes = types.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
965 |
int outArgs = reorder.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
966 |
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
|
967 |
assert(names[skip+i].isParam()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
968 |
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
|
969 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
970 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
971 |
} |
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 |
static class NamedFunction { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
974 |
final MemberName member; |
20494
cf77ae5ff678
8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents:
14852
diff
changeset
|
975 |
@Stable MethodHandle resolvedHandle; |
cf77ae5ff678
8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents:
14852
diff
changeset
|
976 |
@Stable MethodHandle invoker; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
977 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
978 |
NamedFunction(MethodHandle resolvedHandle) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
979 |
this(resolvedHandle.internalMemberName(), resolvedHandle); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
980 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
981 |
NamedFunction(MemberName member, MethodHandle resolvedHandle) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
982 |
this.member = member; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
983 |
//resolvedHandle = eraseSubwordTypes(resolvedHandle); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
984 |
this.resolvedHandle = resolvedHandle; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
985 |
} |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
986 |
NamedFunction(MethodType basicInvokerType) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
987 |
assert(basicInvokerType == basicInvokerType.basicType()) : basicInvokerType; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
988 |
if (basicInvokerType.parameterSlotCount() < MethodType.MAX_MH_INVOKER_ARITY) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
989 |
this.resolvedHandle = basicInvokerType.invokers().basicInvoker(); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
990 |
this.member = resolvedHandle.internalMemberName(); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
991 |
} else { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
992 |
// necessary to pass BigArityTest |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
993 |
this.member = Invokers.invokeBasicMethod(basicInvokerType); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
994 |
} |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
995 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
996 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
997 |
// 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
|
998 |
// 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
|
999 |
// 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
|
1000 |
// 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
|
1001 |
NamedFunction(Method method) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1002 |
this(new MemberName(method)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1003 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1004 |
NamedFunction(Field field) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1005 |
this(new MemberName(field)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1006 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1007 |
NamedFunction(MemberName member) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1008 |
this.member = member; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1009 |
this.resolvedHandle = null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1010 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1011 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1012 |
MethodHandle resolvedHandle() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1013 |
if (resolvedHandle == null) resolve(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1014 |
return resolvedHandle; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1015 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1016 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1017 |
void resolve() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1018 |
resolvedHandle = DirectMethodHandle.make(member); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1019 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1020 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1021 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1022 |
public boolean equals(Object other) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1023 |
if (this == other) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1024 |
if (other == null) return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1025 |
if (!(other instanceof NamedFunction)) return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1026 |
NamedFunction that = (NamedFunction) other; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1027 |
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
|
1028 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1029 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1030 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1031 |
public int hashCode() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1032 |
if (member != null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1033 |
return member.hashCode(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1034 |
return super.hashCode(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1035 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1036 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1037 |
// 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
|
1038 |
static void initializeInvokers() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1039 |
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
|
1040 |
if (!m.isStatic() || !m.isPackage()) continue; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1041 |
MethodType type = m.getMethodType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1042 |
if (type.equals(INVOKER_METHOD_TYPE) && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1043 |
m.getName().startsWith("invoke_")) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1044 |
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
|
1045 |
int arity = LambdaForm.signatureArity(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1046 |
MethodType srcType = MethodType.genericMethodType(arity); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1047 |
if (LambdaForm.signatureReturn(sig) == 'V') |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1048 |
srcType = srcType.changeReturnType(void.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1049 |
MethodTypeForm typeForm = srcType.form(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1050 |
typeForm.namedFunctionInvoker = DirectMethodHandle.make(m); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1051 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1052 |
} |
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 |
// 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
|
1056 |
// 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
|
1057 |
/** void return type invokers. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1058 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1059 |
static Object invoke__V(MethodHandle mh, Object[] a) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1060 |
assert(a.length == 0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1061 |
mh.invokeBasic(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1062 |
return null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1063 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1064 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1065 |
static Object invoke_L_V(MethodHandle mh, Object[] a) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1066 |
assert(a.length == 1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1067 |
mh.invokeBasic(a[0]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1068 |
return null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1069 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1070 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1071 |
static Object invoke_LL_V(MethodHandle mh, Object[] a) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1072 |
assert(a.length == 2); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1073 |
mh.invokeBasic(a[0], a[1]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1074 |
return null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1075 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1076 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1077 |
static Object invoke_LLL_V(MethodHandle mh, Object[] a) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1078 |
assert(a.length == 3); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1079 |
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
|
1080 |
return null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1081 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1082 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1083 |
static Object invoke_LLLL_V(MethodHandle mh, Object[] a) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1084 |
assert(a.length == 4); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1085 |
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
|
1086 |
return null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1087 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1088 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1089 |
static Object invoke_LLLLL_V(MethodHandle mh, Object[] a) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1090 |
assert(a.length == 5); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1091 |
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
|
1092 |
return null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1093 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1094 |
/** Object return type invokers. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1095 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1096 |
static Object invoke__L(MethodHandle mh, Object[] a) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1097 |
assert(a.length == 0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1098 |
return mh.invokeBasic(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1099 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1100 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1101 |
static Object invoke_L_L(MethodHandle mh, Object[] a) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1102 |
assert(a.length == 1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1103 |
return mh.invokeBasic(a[0]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1104 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1105 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1106 |
static Object invoke_LL_L(MethodHandle mh, Object[] a) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1107 |
assert(a.length == 2); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1108 |
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
|
1109 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1110 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1111 |
static Object invoke_LLL_L(MethodHandle mh, Object[] a) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1112 |
assert(a.length == 3); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1113 |
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
|
1114 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1115 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1116 |
static Object invoke_LLLL_L(MethodHandle mh, Object[] a) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1117 |
assert(a.length == 4); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1118 |
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
|
1119 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1120 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1121 |
static Object invoke_LLLLL_L(MethodHandle mh, Object[] a) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1122 |
assert(a.length == 5); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1123 |
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
|
1124 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1125 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1126 |
static final MethodType INVOKER_METHOD_TYPE = |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1127 |
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
|
1128 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1129 |
private static MethodHandle computeInvoker(MethodTypeForm typeForm) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1130 |
MethodHandle mh = typeForm.namedFunctionInvoker; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1131 |
if (mh != null) return mh; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1132 |
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
|
1133 |
mh = DirectMethodHandle.make(invoker); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1134 |
MethodHandle mh2 = typeForm.namedFunctionInvoker; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1135 |
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
|
1136 |
if (!mh.type().equals(INVOKER_METHOD_TYPE)) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1137 |
throw new InternalError(mh.debugString()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1138 |
return typeForm.namedFunctionInvoker = mh; |
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 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1142 |
Object invokeWithArguments(Object... arguments) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1143 |
// 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
|
1144 |
// 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
|
1145 |
if (TRACE_INTERPRETER) return invokeWithArgumentsTracing(arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1146 |
assert(checkArgumentTypes(arguments, methodType())); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1147 |
return invoker().invokeBasic(resolvedHandle(), arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1148 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1149 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1150 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1151 |
Object invokeWithArgumentsTracing(Object[] arguments) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1152 |
Object rval; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1153 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1154 |
traceInterpreter("[ call", this, arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1155 |
if (invoker == null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1156 |
traceInterpreter("| getInvoker", this); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1157 |
invoker(); |
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 |
if (resolvedHandle == null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1160 |
traceInterpreter("| resolve", this); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1161 |
resolvedHandle(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1162 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1163 |
assert(checkArgumentTypes(arguments, methodType())); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1164 |
rval = invoker().invokeBasic(resolvedHandle(), arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1165 |
} catch (Throwable ex) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1166 |
traceInterpreter("] throw =>", ex); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1167 |
throw ex; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1168 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1169 |
traceInterpreter("] return =>", rval); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1170 |
return rval; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1171 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1172 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1173 |
private MethodHandle invoker() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1174 |
if (invoker != null) return invoker; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1175 |
// Get an invoker and cache it. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1176 |
return invoker = computeInvoker(methodType().form()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1177 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1178 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1179 |
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
|
1180 |
if (true) return true; // FIXME |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1181 |
MethodType dstType = methodType.form().erasedType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1182 |
MethodType srcType = dstType.basicType().wrap(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1183 |
Class<?>[] ptypes = new Class<?>[arguments.length]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1184 |
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
|
1185 |
Object arg = arguments[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1186 |
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
|
1187 |
// 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
|
1188 |
// argument type. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1189 |
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
|
1190 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1191 |
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
|
1192 |
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
|
1193 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1194 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1195 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1196 |
String basicTypeSignature() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1197 |
//return LambdaForm.basicTypeSignature(resolvedHandle.type()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1198 |
return LambdaForm.basicTypeSignature(methodType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1199 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1200 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1201 |
MethodType methodType() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1202 |
if (resolvedHandle != null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1203 |
return resolvedHandle.type(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1204 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1205 |
// 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
|
1206 |
return member.getInvocationType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1207 |
} |
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 |
MemberName member() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1210 |
assert(assertMemberIsConsistent()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1211 |
return member; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1212 |
} |
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 |
// Called only from assert. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1215 |
private boolean assertMemberIsConsistent() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1216 |
if (resolvedHandle instanceof DirectMethodHandle) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1217 |
MemberName m = resolvedHandle.internalMemberName(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1218 |
assert(m.equals(member)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1219 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1220 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1221 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1222 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1223 |
Class<?> memberDeclaringClassOrNull() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1224 |
return (member == null) ? null : member.getDeclaringClass(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1225 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1226 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1227 |
char returnType() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1228 |
return basicType(methodType().returnType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1229 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1230 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1231 |
char parameterType(int n) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1232 |
return basicType(methodType().parameterType(n)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1233 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1234 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1235 |
int arity() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1236 |
//int siglen = member.getMethodType().parameterCount(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1237 |
//if (!member.isStatic()) siglen += 1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1238 |
//return siglen; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1239 |
return methodType().parameterCount(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1240 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1241 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1242 |
public String toString() { |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1243 |
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
|
1244 |
return member.getDeclaringClass().getSimpleName()+"."+member.getName(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1245 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1246 |
} |
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 |
void resolve() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1249 |
for (Name n : names) n.resolve(); |
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 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1252 |
public static char basicType(Class<?> type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1253 |
char c = Wrapper.basicTypeChar(type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1254 |
if ("ZBSC".indexOf(c) >= 0) c = 'I'; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1255 |
assert("LIJFDV".indexOf(c) >= 0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1256 |
return c; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1257 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1258 |
public static char[] basicTypes(List<Class<?>> types) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1259 |
char[] btypes = new char[types.size()]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1260 |
for (int i = 0; i < btypes.length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1261 |
btypes[i] = basicType(types.get(i)); |
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 |
return btypes; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1264 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1265 |
public static String basicTypeSignature(MethodType type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1266 |
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
|
1267 |
int sigp = 0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1268 |
for (Class<?> pt : type.parameterList()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1269 |
sig[sigp++] = basicType(pt); |
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 |
sig[sigp++] = '_'; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1272 |
sig[sigp++] = basicType(type.returnType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1273 |
assert(sigp == sig.length); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1274 |
return String.valueOf(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1275 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1276 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1277 |
static final class Name { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1278 |
final char type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1279 |
private short index; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1280 |
final NamedFunction function; |
20494
cf77ae5ff678
8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents:
14852
diff
changeset
|
1281 |
@Stable final Object[] arguments; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1282 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1283 |
private Name(int index, char type, NamedFunction function, Object[] arguments) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1284 |
this.index = (short)index; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1285 |
this.type = type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1286 |
this.function = function; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1287 |
this.arguments = arguments; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1288 |
assert(this.index == index); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1289 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1290 |
Name(MethodHandle function, Object... arguments) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1291 |
this(new NamedFunction(function), arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1292 |
} |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1293 |
Name(MethodType functionType, Object... arguments) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1294 |
this(new NamedFunction(functionType), arguments); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1295 |
assert(arguments[0] instanceof Name && ((Name)arguments[0]).type == 'L'); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1296 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1297 |
Name(MemberName function, Object... arguments) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1298 |
this(new NamedFunction(function), arguments); |
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 |
Name(NamedFunction function, Object... arguments) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1301 |
this(-1, function.returnType(), function, arguments = arguments.clone()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1302 |
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
|
1303 |
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
|
1304 |
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
|
1305 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1306 |
Name(int index, char type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1307 |
this(index, type, null, null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1308 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1309 |
Name(char type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1310 |
this(-1, type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1311 |
} |
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 |
char type() { return type; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1314 |
int index() { return index; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1315 |
boolean initIndex(int i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1316 |
if (index != i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1317 |
if (index != -1) return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1318 |
index = (short)i; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1319 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1320 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1321 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1322 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1323 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1324 |
void resolve() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1325 |
if (function != null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1326 |
function.resolve(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1327 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1328 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1329 |
Name newIndex(int i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1330 |
if (initIndex(i)) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1331 |
return cloneWithIndex(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1332 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1333 |
Name cloneWithIndex(int i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1334 |
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
|
1335 |
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
|
1336 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1337 |
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
|
1338 |
if (oldName == newName) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1339 |
@SuppressWarnings("LocalVariableHidesMemberVariable") |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1340 |
Object[] arguments = this.arguments; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1341 |
if (arguments == null) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1342 |
boolean replaced = false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1343 |
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
|
1344 |
if (arguments[j] == oldName) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1345 |
if (!replaced) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1346 |
replaced = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1347 |
arguments = arguments.clone(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1348 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1349 |
arguments[j] = newName; |
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 |
if (!replaced) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1353 |
return new Name(function, arguments); |
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 |
Name replaceNames(Name[] oldNames, Name[] newNames, int start, int end) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1356 |
@SuppressWarnings("LocalVariableHidesMemberVariable") |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1357 |
Object[] arguments = this.arguments; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1358 |
boolean replaced = false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1359 |
eachArg: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1360 |
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
|
1361 |
if (arguments[j] instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1362 |
Name n = (Name) arguments[j]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1363 |
int check = n.index; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1364 |
// 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
|
1365 |
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
|
1366 |
continue eachArg; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1367 |
// 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
|
1368 |
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
|
1369 |
if (n == oldNames[i]) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1370 |
if (n == newNames[i]) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1371 |
continue eachArg; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1372 |
if (!replaced) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1373 |
replaced = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1374 |
arguments = arguments.clone(); |
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 |
arguments[j] = newNames[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1377 |
continue eachArg; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1378 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1379 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1380 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1381 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1382 |
if (!replaced) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1383 |
return new Name(function, arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1384 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1385 |
void internArguments() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1386 |
@SuppressWarnings("LocalVariableHidesMemberVariable") |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1387 |
Object[] arguments = this.arguments; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1388 |
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
|
1389 |
if (arguments[j] instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1390 |
Name n = (Name) arguments[j]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1391 |
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
|
1392 |
arguments[j] = internArgument(n); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1393 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1394 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1395 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1396 |
boolean isParam() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1397 |
return function == null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1398 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1399 |
boolean isConstantZero() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1400 |
return !isParam() && arguments.length == 0 && function.equals(constantZero(0, type).function); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1401 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1402 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1403 |
public String toString() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1404 |
return (isParam()?"a":"t")+(index >= 0 ? index : System.identityHashCode(this))+":"+type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1405 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1406 |
public String debugString() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1407 |
String s = toString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1408 |
return (function == null) ? s : s + "=" + exprString(); |
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 |
public String exprString() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1411 |
if (function == null) return "null"; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1412 |
StringBuilder buf = new StringBuilder(function.toString()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1413 |
buf.append("("); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1414 |
String cma = ""; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1415 |
for (Object a : arguments) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1416 |
buf.append(cma); cma = ","; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1417 |
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
|
1418 |
buf.append(a); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1419 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1420 |
buf.append("(").append(a).append(")"); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1421 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1422 |
buf.append(")"); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1423 |
return buf.toString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1424 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1425 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1426 |
private static boolean typesMatch(char parameterType, Object object) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1427 |
if (object instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1428 |
return ((Name)object).type == parameterType; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1429 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1430 |
switch (parameterType) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1431 |
case 'I': return object instanceof Integer; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1432 |
case 'J': return object instanceof Long; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1433 |
case 'F': return object instanceof Float; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1434 |
case 'D': return object instanceof Double; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1435 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1436 |
assert(parameterType == 'L'); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1437 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1438 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1439 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1440 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1441 |
* Does this Name precede the given binding node in some canonical order? |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1442 |
* This predicate is used to order data bindings (via insertion sort) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1443 |
* with some stability. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1444 |
* @param binding |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1445 |
* @return |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1446 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1447 |
boolean isSiblingBindingBefore(Name binding) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1448 |
assert(!binding.isParam()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1449 |
if (isParam()) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1450 |
if (function.equals(binding.function) && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1451 |
arguments.length == binding.arguments.length) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1452 |
boolean sawInt = false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1453 |
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
|
1454 |
Object a1 = arguments[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1455 |
Object a2 = binding.arguments[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1456 |
if (!a1.equals(a2)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1457 |
if (a1 instanceof Integer && a2 instanceof Integer) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1458 |
if (sawInt) continue; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1459 |
sawInt = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1460 |
if ((int)a1 < (int)a2) continue; // still might be true |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1461 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1462 |
return false; |
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 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1465 |
return sawInt; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1466 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1467 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1468 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1469 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1470 |
public boolean equals(Name that) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1471 |
if (this == that) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1472 |
if (isParam()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1473 |
// each parameter is a unique atom |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1474 |
return false; // this != that |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1475 |
return |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1476 |
//this.index == that.index && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1477 |
this.type == that.type && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1478 |
this.function.equals(that.function) && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1479 |
Arrays.equals(this.arguments, that.arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1480 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1481 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1482 |
public boolean equals(Object x) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1483 |
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
|
1484 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1485 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1486 |
public int hashCode() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1487 |
if (isParam()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1488 |
return index | (type << 8); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1489 |
return function.hashCode() ^ Arrays.hashCode(arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1490 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1491 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1492 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1493 |
static Name argument(int which, char type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1494 |
int tn = ALL_TYPES.indexOf(type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1495 |
if (tn < 0 || which >= INTERNED_ARGUMENT_LIMIT) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1496 |
return new Name(which, type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1497 |
return INTERNED_ARGUMENTS[tn][which]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1498 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1499 |
static Name internArgument(Name n) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1500 |
assert(n.isParam()) : "not param: " + n; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1501 |
assert(n.index < INTERNED_ARGUMENT_LIMIT); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1502 |
return argument(n.index, n.type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1503 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1504 |
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
|
1505 |
int length = types.length(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1506 |
Name[] names = new Name[length + extra]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1507 |
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
|
1508 |
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
|
1509 |
return names; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1510 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1511 |
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
|
1512 |
int length = types.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1513 |
Name[] names = new Name[length + extra]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1514 |
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
|
1515 |
names[i] = argument(i, types[i]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1516 |
return names; |
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 |
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
|
1519 |
int length = types.size(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1520 |
Name[] names = new Name[length + extra]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1521 |
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
|
1522 |
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
|
1523 |
return names; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1524 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1525 |
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
|
1526 |
int length = types.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1527 |
Name[] names = new Name[length + extra]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1528 |
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
|
1529 |
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
|
1530 |
return names; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1531 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1532 |
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
|
1533 |
int length = types.parameterCount(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1534 |
Name[] names = new Name[length + extra]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1535 |
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
|
1536 |
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
|
1537 |
return names; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1538 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1539 |
static final String ALL_TYPES = "LIJFD"; // omit V, not an argument type |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1540 |
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
|
1541 |
private static final Name[][] INTERNED_ARGUMENTS |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1542 |
= new Name[ALL_TYPES.length()][INTERNED_ARGUMENT_LIMIT]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1543 |
static { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1544 |
for (int tn = 0; tn < ALL_TYPES.length(); tn++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1545 |
for (int i = 0; i < INTERNED_ARGUMENTS[tn].length; i++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1546 |
char type = ALL_TYPES.charAt(tn); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1547 |
INTERNED_ARGUMENTS[tn][i] = new Name(i, type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1548 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1549 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1550 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1551 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1552 |
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
|
1553 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1554 |
static Name constantZero(int which, char type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1555 |
return CONSTANT_ZERO[ALL_TYPES.indexOf(type)].newIndex(which); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1556 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1557 |
private static final Name[] CONSTANT_ZERO |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1558 |
= new Name[ALL_TYPES.length()]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1559 |
static { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1560 |
for (int tn = 0; tn < ALL_TYPES.length(); tn++) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1561 |
char bt = ALL_TYPES.charAt(tn); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1562 |
Wrapper wrap = Wrapper.forBasicType(bt); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1563 |
MemberName zmem = new MemberName(LambdaForm.class, "zero"+bt, MethodType.methodType(wrap.primitiveType()), REF_invokeStatic); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1564 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1565 |
zmem = IMPL_NAMES.resolveOrFail(REF_invokeStatic, zmem, null, NoSuchMethodException.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1566 |
} catch (IllegalAccessException|NoSuchMethodException ex) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
1567 |
throw newInternalError(ex); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1568 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1569 |
NamedFunction zcon = new NamedFunction(zmem); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1570 |
Name n = new Name(zcon).newIndex(0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1571 |
assert(n.type == ALL_TYPES.charAt(tn)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1572 |
CONSTANT_ZERO[tn] = n; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1573 |
assert(n.isConstantZero()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1574 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1575 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1576 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1577 |
// Avoid appealing to ValueConversions at bootstrap time: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1578 |
private static int zeroI() { return 0; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1579 |
private static long zeroJ() { return 0; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1580 |
private static float zeroF() { return 0; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1581 |
private static double zeroD() { return 0; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1582 |
private static Object zeroL() { return null; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1583 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1584 |
// Put this last, so that previous static inits can run before. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1585 |
static { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1586 |
if (USE_PREDEFINED_INTERPRET_METHODS) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1587 |
PREPARED_FORMS.putAll(computeInitialPreparedForms()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1588 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1589 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1590 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1591 |
* Internal marker for byte-compiled LambdaForms. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1592 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1593 |
/*non-public*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1594 |
@Target(ElementType.METHOD) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1595 |
@Retention(RetentionPolicy.RUNTIME) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1596 |
@interface Compiled { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1597 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1598 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1599 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1600 |
* Internal marker for LambdaForm interpreter frames. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1601 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1602 |
/*non-public*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1603 |
@Target(ElementType.METHOD) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1604 |
@Retention(RetentionPolicy.RUNTIME) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1605 |
@interface Hidden { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1606 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1607 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1608 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1609 |
/* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1610 |
// Smoke-test for the invokers used in this file. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1611 |
static void testMethodHandleLinkers() throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1612 |
MemberName.Factory lookup = MemberName.getFactory(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1613 |
MemberName asList_MN = new MemberName(Arrays.class, "asList", |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1614 |
MethodType.methodType(List.class, Object[].class), |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1615 |
REF_invokeStatic); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1616 |
//MethodHandleNatives.resolve(asList_MN, null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1617 |
asList_MN = lookup.resolveOrFail(asList_MN, REF_invokeStatic, null, NoSuchMethodException.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1618 |
System.out.println("about to call "+asList_MN); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1619 |
Object[] abc = { "a", "bc" }; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1620 |
List<?> lst = (List<?>) MethodHandle.linkToStatic(abc, asList_MN); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1621 |
System.out.println("lst="+lst); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1622 |
MemberName toString_MN = new MemberName(Object.class.getMethod("toString")); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1623 |
String s1 = (String) MethodHandle.linkToVirtual(lst, toString_MN); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1624 |
toString_MN = new MemberName(Object.class.getMethod("toString"), true); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1625 |
String s2 = (String) MethodHandle.linkToSpecial(lst, toString_MN); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1626 |
System.out.println("[s1,s2,lst]="+Arrays.asList(s1, s2, lst.toString())); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1627 |
MemberName toArray_MN = new MemberName(List.class.getMethod("toArray")); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1628 |
Object[] arr = (Object[]) MethodHandle.linkToInterface(lst, toArray_MN); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1629 |
System.out.println("toArray="+Arrays.toString(arr)); |
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 |
static { try { testMethodHandleLinkers(); } catch (Throwable ex) { throw new RuntimeException(ex); } } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1632 |
// Requires these definitions in MethodHandle: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1633 |
static final native Object linkToStatic(Object x1, MemberName mn) throws Throwable; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1634 |
static final native Object linkToVirtual(Object x1, MemberName mn) throws Throwable; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1635 |
static final native Object linkToSpecial(Object x1, MemberName mn) throws Throwable; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1636 |
static final native Object linkToInterface(Object x1, MemberName mn) throws Throwable; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1637 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1638 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1639 |
static { NamedFunction.initializeInvokers(); } |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1640 |
|
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1641 |
// 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
|
1642 |
// during execution of the static initializes of this class. |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1643 |
// Turning on TRACE_INTERPRETER too early will cause |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1644 |
// stack overflows and other misbehavior during attempts to trace events |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1645 |
// that occur during LambdaForm.<clinit>. |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1646 |
// 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
|
1647 |
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
|
1648 |
} |