author | vlivanov |
Tue, 22 Jan 2019 18:13:49 -0800 | |
changeset 53435 | ea254e9fc587 |
parent 52220 | 9c260a6b6471 |
permissions | -rw-r--r-- |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1 |
/* |
49935 | 2 |
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
4 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
10 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
15 |
* accompanied this code). |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
16 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
20 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
23 |
* questions. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
24 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
25 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
26 |
package java.lang.invoke; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
27 |
|
39483
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
28 |
import jdk.internal.perf.PerfCounter; |
35252
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34429
diff
changeset
|
29 |
import jdk.internal.vm.annotation.DontInline; |
53435
ea254e9fc587
8213234: Move LambdaForm.Hidden to jdk.internal.vm.annotation
vlivanov
parents:
52220
diff
changeset
|
30 |
import jdk.internal.vm.annotation.Hidden; |
35252
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34429
diff
changeset
|
31 |
import jdk.internal.vm.annotation.Stable; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34429
diff
changeset
|
32 |
import sun.invoke.util.Wrapper; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34429
diff
changeset
|
33 |
|
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34429
diff
changeset
|
34 |
import java.lang.annotation.ElementType; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34429
diff
changeset
|
35 |
import java.lang.annotation.Retention; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34429
diff
changeset
|
36 |
import java.lang.annotation.RetentionPolicy; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34429
diff
changeset
|
37 |
import java.lang.annotation.Target; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
38 |
import java.lang.reflect.Method; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
39 |
import java.util.Arrays; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
40 |
import java.util.HashMap; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
41 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
42 |
import static java.lang.invoke.LambdaForm.BasicType.*; |
35252
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34429
diff
changeset
|
43 |
import static java.lang.invoke.MethodHandleNatives.Constants.REF_invokeStatic; |
39483
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
44 |
import static java.lang.invoke.MethodHandleStatics.*; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
45 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
46 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
47 |
* 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
|
48 |
* 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
|
49 |
* 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
|
50 |
* 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
|
51 |
* 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
|
52 |
* 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
|
53 |
* constant values and local names. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
54 |
* 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
|
55 |
* <p> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
56 |
* Here is an approximate grammar: |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
57 |
* <blockquote><pre>{@code |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
58 |
* LambdaForm = "(" ArgName* ")=>{" TempName* Result "}" |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
59 |
* ArgName = "a" N ":" T |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
60 |
* TempName = "t" N ":" T "=" Function "(" Argument* ");" |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
61 |
* Function = ConstantValue |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
62 |
* Argument = NameRef | ConstantValue |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
63 |
* Result = NameRef | "void" |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
64 |
* NameRef = "a" N | "t" N |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
65 |
* N = (any whole number) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
66 |
* T = "L" | "I" | "J" | "F" | "D" | "V" |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
67 |
* }</pre></blockquote> |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
68 |
* 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
|
69 |
* (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
|
70 |
* 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
|
71 |
* 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
|
72 |
* 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
|
73 |
* 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
|
74 |
* 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
|
75 |
* even though possesses a number. |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
76 |
* Note that all reference types are erased to "L", which stands for {@code Object}. |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
77 |
* 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
|
78 |
* 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
|
79 |
* <p> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
80 |
* 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
|
81 |
* 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
|
82 |
* considered. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
83 |
* 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
|
84 |
* <ul> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
85 |
* <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
|
86 |
* <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
|
87 |
* <li>J = long: no implicit conversions |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
88 |
* <li>F = float: no implicit conversions |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
89 |
* <li>D = double: no implicit conversions |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
90 |
* <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
|
91 |
* </ul> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
92 |
* 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
|
93 |
* 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
|
94 |
* <p> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
95 |
* Examples: |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
96 |
* <blockquote><pre>{@code |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
97 |
* (a0:J)=>{ a0 } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
98 |
* == identity(long) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
99 |
* (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
|
100 |
* == System.out#println(int) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
101 |
* (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
|
102 |
* == identity, with printing side-effect |
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 = BoundMethodHandle#argument(a0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
104 |
* t3:L = BoundMethodHandle#target(a0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
105 |
* 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
|
106 |
* == general invoker for unary insertArgument combination |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
107 |
* (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
|
108 |
* t3:L = MethodHandle#invoke(t2, a1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
109 |
* t4:L = FilterMethodHandle#target(a0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
110 |
* 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
|
111 |
* == general invoker for unary filterArgument combination |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
112 |
* (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
|
113 |
* 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
|
114 |
* == 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
|
115 |
* (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
|
116 |
* == 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
|
117 |
* (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
|
118 |
* 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
|
119 |
* == invoker for identity method handle which performs cast |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
120 |
* }</pre></blockquote> |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
121 |
* <p> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
122 |
* @author John Rose, JSR 292 EG |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
123 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
124 |
class LambdaForm { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
125 |
final int arity; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
126 |
final int result; |
27295
8ed31033bf48
8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents:
26482
diff
changeset
|
127 |
final boolean forceInline; |
29020
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
128 |
final MethodHandle customized; |
20494
cf77ae5ff678
8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents:
14852
diff
changeset
|
129 |
@Stable final Name[] names; |
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
130 |
final Kind kind; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
131 |
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
|
132 |
private boolean isCompiled; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
133 |
|
29020
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
134 |
// Either a LambdaForm cache (managed by LambdaFormEditor) or a link to uncustomized version (for customized LF) |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
135 |
volatile Object transformCache; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
136 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
137 |
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
|
138 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
139 |
enum BasicType { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
140 |
L_TYPE('L', Object.class, Wrapper.OBJECT), // all reference types |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
141 |
I_TYPE('I', int.class, Wrapper.INT), |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
142 |
J_TYPE('J', long.class, Wrapper.LONG), |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
143 |
F_TYPE('F', float.class, Wrapper.FLOAT), |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
144 |
D_TYPE('D', double.class, Wrapper.DOUBLE), // all primitive types |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
145 |
V_TYPE('V', void.class, Wrapper.VOID); // not valid in all contexts |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
146 |
|
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
147 |
static final @Stable BasicType[] ALL_TYPES = BasicType.values(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
148 |
static final @Stable BasicType[] ARG_TYPES = Arrays.copyOf(ALL_TYPES, ALL_TYPES.length-1); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
149 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
150 |
static final int ARG_TYPE_LIMIT = ARG_TYPES.length; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
151 |
static final int TYPE_LIMIT = ALL_TYPES.length; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
152 |
|
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
153 |
// Derived int constants, which (unlike the enums) can be constant folded. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
154 |
// We can remove them when JDK-8161245 is fixed. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
155 |
static final byte |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
156 |
L_TYPE_NUM = (byte) L_TYPE.ordinal(), |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
157 |
I_TYPE_NUM = (byte) I_TYPE.ordinal(), |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
158 |
J_TYPE_NUM = (byte) J_TYPE.ordinal(), |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
159 |
F_TYPE_NUM = (byte) F_TYPE.ordinal(), |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
160 |
D_TYPE_NUM = (byte) D_TYPE.ordinal(), |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
161 |
V_TYPE_NUM = (byte) V_TYPE.ordinal(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
162 |
|
40272
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40212
diff
changeset
|
163 |
final char btChar; |
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40212
diff
changeset
|
164 |
final Class<?> btClass; |
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40212
diff
changeset
|
165 |
final Wrapper btWrapper; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
166 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
167 |
private BasicType(char btChar, Class<?> btClass, Wrapper wrapper) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
168 |
this.btChar = btChar; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
169 |
this.btClass = btClass; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
170 |
this.btWrapper = wrapper; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
171 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
172 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
173 |
char basicTypeChar() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
174 |
return btChar; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
175 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
176 |
Class<?> basicTypeClass() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
177 |
return btClass; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
178 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
179 |
Wrapper basicTypeWrapper() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
180 |
return btWrapper; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
181 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
182 |
int basicTypeSlots() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
183 |
return btWrapper.stackSlots(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
184 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
185 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
186 |
static BasicType basicType(byte type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
187 |
return ALL_TYPES[type]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
188 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
189 |
static BasicType basicType(char type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
190 |
switch (type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
191 |
case 'L': return L_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
192 |
case 'I': return I_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
193 |
case 'J': return J_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
194 |
case 'F': return F_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
195 |
case 'D': return D_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
196 |
case 'V': return V_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
197 |
// all subword types are represented as ints |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
198 |
case 'Z': |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
199 |
case 'B': |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
200 |
case 'S': |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
201 |
case 'C': |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
202 |
return I_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
203 |
default: |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
204 |
throw newInternalError("Unknown type char: '"+type+"'"); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
205 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
206 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
207 |
static BasicType basicType(Wrapper type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
208 |
char c = type.basicTypeChar(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
209 |
return basicType(c); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
210 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
211 |
static BasicType basicType(Class<?> type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
212 |
if (!type.isPrimitive()) return L_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
213 |
return basicType(Wrapper.forPrimitiveType(type)); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
214 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
215 |
static BasicType[] basicTypes(String types) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
216 |
BasicType[] btypes = new BasicType[types.length()]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
217 |
for (int i = 0; i < btypes.length; i++) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
218 |
btypes[i] = basicType(types.charAt(i)); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
219 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
220 |
return btypes; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
221 |
} |
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
222 |
static String basicTypeDesc(BasicType[] types) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
223 |
if (types == null) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
224 |
return null; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
225 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
226 |
if (types.length == 0) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
227 |
return ""; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
228 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
229 |
StringBuilder sb = new StringBuilder(); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
230 |
for (BasicType bt : types) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
231 |
sb.append(bt.basicTypeChar()); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
232 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
233 |
return sb.toString(); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
234 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
235 |
static int[] basicTypeOrds(BasicType[] types) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
236 |
if (types == null) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
237 |
return null; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
238 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
239 |
int[] a = new int[types.length]; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
240 |
for(int i = 0; i < types.length; ++i) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
241 |
a[i] = types[i].ordinal(); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
242 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
243 |
return a; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
244 |
} |
34384
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
245 |
|
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
246 |
static char basicTypeChar(Class<?> type) { |
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
247 |
return basicType(type).btChar; |
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
248 |
} |
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
249 |
|
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
250 |
static byte[] basicTypesOrd(Class<?>[] types) { |
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
251 |
byte[] ords = new byte[types.length]; |
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
252 |
for (int i = 0; i < ords.length; i++) { |
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
253 |
ords[i] = (byte)basicType(types[i]).ordinal(); |
26481
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
254 |
} |
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
255 |
return ords; |
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
256 |
} |
34384
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
257 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
258 |
static boolean isBasicTypeChar(char c) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
259 |
return "LIJFDV".indexOf(c) >= 0; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
260 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
261 |
static boolean isArgBasicTypeChar(char c) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
262 |
return "LIJFD".indexOf(c) >= 0; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
263 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
264 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
265 |
static { assert(checkBasicType()); } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
266 |
private static boolean checkBasicType() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
267 |
for (int i = 0; i < ARG_TYPE_LIMIT; i++) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
268 |
assert ARG_TYPES[i].ordinal() == i; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
269 |
assert ARG_TYPES[i] == ALL_TYPES[i]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
270 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
271 |
for (int i = 0; i < TYPE_LIMIT; i++) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
272 |
assert ALL_TYPES[i].ordinal() == i; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
273 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
274 |
assert ALL_TYPES[TYPE_LIMIT - 1] == V_TYPE; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
275 |
assert !Arrays.asList(ARG_TYPES).contains(V_TYPE); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
276 |
return true; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
277 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
278 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
279 |
|
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
280 |
enum Kind { |
43893 | 281 |
GENERIC("invoke"), |
40419
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
282 |
ZERO("zero"), |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
283 |
IDENTITY("identity"), |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
284 |
BOUND_REINVOKER("BMH.reinvoke", "reinvoke"), |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
285 |
REINVOKER("MH.reinvoke", "reinvoke"), |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
286 |
DELEGATE("MH.delegate", "delegate"), |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
287 |
EXACT_LINKER("MH.invokeExact_MT", "invokeExact_MT"), |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
288 |
EXACT_INVOKER("MH.exactInvoker", "exactInvoker"), |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
289 |
GENERIC_LINKER("MH.invoke_MT", "invoke_MT"), |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
290 |
GENERIC_INVOKER("MH.invoker", "invoker"), |
43893 | 291 |
LINK_TO_TARGET_METHOD("linkToTargetMethod"), |
292 |
LINK_TO_CALL_SITE("linkToCallSite"), |
|
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
293 |
DIRECT_INVOKE_VIRTUAL("DMH.invokeVirtual", "invokeVirtual"), |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
294 |
DIRECT_INVOKE_SPECIAL("DMH.invokeSpecial", "invokeSpecial"), |
49935 | 295 |
DIRECT_INVOKE_SPECIAL_IFC("DMH.invokeSpecialIFC", "invokeSpecialIFC"), |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
296 |
DIRECT_INVOKE_STATIC("DMH.invokeStatic", "invokeStatic"), |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
297 |
DIRECT_NEW_INVOKE_SPECIAL("DMH.newInvokeSpecial", "newInvokeSpecial"), |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
298 |
DIRECT_INVOKE_INTERFACE("DMH.invokeInterface", "invokeInterface"), |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
299 |
DIRECT_INVOKE_STATIC_INIT("DMH.invokeStaticInit", "invokeStaticInit"), |
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
49935
diff
changeset
|
300 |
GET_REFERENCE("getReference"), |
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
49935
diff
changeset
|
301 |
PUT_REFERENCE("putReference"), |
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
49935
diff
changeset
|
302 |
GET_REFERENCE_VOLATILE("getReferenceVolatile"), |
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
49935
diff
changeset
|
303 |
PUT_REFERENCE_VOLATILE("putReferenceVolatile"), |
40542
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
304 |
GET_INT("getInt"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
305 |
PUT_INT("putInt"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
306 |
GET_INT_VOLATILE("getIntVolatile"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
307 |
PUT_INT_VOLATILE("putIntVolatile"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
308 |
GET_BOOLEAN("getBoolean"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
309 |
PUT_BOOLEAN("putBoolean"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
310 |
GET_BOOLEAN_VOLATILE("getBooleanVolatile"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
311 |
PUT_BOOLEAN_VOLATILE("putBooleanVolatile"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
312 |
GET_BYTE("getByte"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
313 |
PUT_BYTE("putByte"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
314 |
GET_BYTE_VOLATILE("getByteVolatile"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
315 |
PUT_BYTE_VOLATILE("putByteVolatile"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
316 |
GET_CHAR("getChar"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
317 |
PUT_CHAR("putChar"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
318 |
GET_CHAR_VOLATILE("getCharVolatile"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
319 |
PUT_CHAR_VOLATILE("putCharVolatile"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
320 |
GET_SHORT("getShort"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
321 |
PUT_SHORT("putShort"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
322 |
GET_SHORT_VOLATILE("getShortVolatile"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
323 |
PUT_SHORT_VOLATILE("putShortVolatile"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
324 |
GET_LONG("getLong"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
325 |
PUT_LONG("putLong"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
326 |
GET_LONG_VOLATILE("getLongVolatile"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
327 |
PUT_LONG_VOLATILE("putLongVolatile"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
328 |
GET_FLOAT("getFloat"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
329 |
PUT_FLOAT("putFloat"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
330 |
GET_FLOAT_VOLATILE("getFloatVolatile"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
331 |
PUT_FLOAT_VOLATILE("putFloatVolatile"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
332 |
GET_DOUBLE("getDouble"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
333 |
PUT_DOUBLE("putDouble"), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
334 |
GET_DOUBLE_VOLATILE("getDoubleVolatile"), |
43893 | 335 |
PUT_DOUBLE_VOLATILE("putDoubleVolatile"), |
336 |
TRY_FINALLY("tryFinally"), |
|
337 |
COLLECT("collect"), |
|
338 |
CONVERT("convert"), |
|
339 |
SPREAD("spread"), |
|
340 |
LOOP("loop"), |
|
341 |
FIELD("field"), |
|
342 |
GUARD("guard"), |
|
343 |
GUARD_WITH_CATCH("guardWithCatch"), |
|
344 |
VARHANDLE_EXACT_INVOKER("VH.exactInvoker"), |
|
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
345 |
VARHANDLE_INVOKER("VH.invoker", "invoker"), |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
346 |
VARHANDLE_LINKER("VH.invoke_MT", "invoke_MT"); |
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
347 |
|
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
348 |
final String defaultLambdaName; |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
349 |
final String methodName; |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
350 |
|
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
351 |
private Kind(String defaultLambdaName) { |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
352 |
this(defaultLambdaName, defaultLambdaName); |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
353 |
} |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
354 |
|
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
355 |
private Kind(String defaultLambdaName, String methodName) { |
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
356 |
this.defaultLambdaName = defaultLambdaName; |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
357 |
this.methodName = methodName; |
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
358 |
} |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
359 |
} |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
360 |
|
43893 | 361 |
LambdaForm(int arity, Name[] names, int result) { |
362 |
this(arity, names, result, /*forceInline=*/true, /*customized=*/null, Kind.GENERIC); |
|
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
363 |
} |
43893 | 364 |
LambdaForm(int arity, Name[] names, int result, Kind kind) { |
365 |
this(arity, names, result, /*forceInline=*/true, /*customized=*/null, kind); |
|
27295
8ed31033bf48
8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents:
26482
diff
changeset
|
366 |
} |
43893 | 367 |
LambdaForm(int arity, Name[] names, int result, boolean forceInline, MethodHandle customized) { |
368 |
this(arity, names, result, forceInline, customized, Kind.GENERIC); |
|
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
369 |
} |
43893 | 370 |
LambdaForm(int arity, Name[] names, int result, boolean forceInline, MethodHandle customized, Kind kind) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
371 |
assert(namesOK(arity, names)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
372 |
this.arity = arity; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
373 |
this.result = fixResult(result, names); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
374 |
this.names = names.clone(); |
27295
8ed31033bf48
8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents:
26482
diff
changeset
|
375 |
this.forceInline = forceInline; |
29020
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
376 |
this.customized = customized; |
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
377 |
this.kind = kind; |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
378 |
int maxOutArity = normalize(); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
379 |
if (maxOutArity > MethodType.MAX_MH_INVOKER_ARITY) { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
380 |
// Cannot use LF interpreter on very high arity expressions. |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
381 |
assert(maxOutArity <= MethodType.MAX_JVM_ARITY); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
382 |
compileToBytecode(); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
383 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
384 |
} |
43893 | 385 |
LambdaForm(int arity, Name[] names) { |
386 |
this(arity, names, LAST_RESULT, /*forceInline=*/true, /*customized=*/null, Kind.GENERIC); |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
387 |
} |
43893 | 388 |
LambdaForm(int arity, Name[] names, Kind kind) { |
389 |
this(arity, names, LAST_RESULT, /*forceInline=*/true, /*customized=*/null, kind); |
|
40543
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
390 |
} |
43893 | 391 |
LambdaForm(int arity, Name[] names, boolean forceInline) { |
392 |
this(arity, names, LAST_RESULT, forceInline, /*customized=*/null, Kind.GENERIC); |
|
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
393 |
} |
43893 | 394 |
LambdaForm(int arity, Name[] names, boolean forceInline, Kind kind) { |
395 |
this(arity, names, LAST_RESULT, forceInline, /*customized=*/null, kind); |
|
27295
8ed31033bf48
8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents:
26482
diff
changeset
|
396 |
} |
43893 | 397 |
LambdaForm(Name[] formals, Name[] temps, Name result) { |
398 |
this(formals.length, buildNames(formals, temps, result), LAST_RESULT, /*forceInline=*/true, /*customized=*/null); |
|
27295
8ed31033bf48
8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents:
26482
diff
changeset
|
399 |
} |
43893 | 400 |
LambdaForm(Name[] formals, Name[] temps, Name result, boolean forceInline) { |
401 |
this(formals.length, buildNames(formals, temps, result), LAST_RESULT, forceInline, /*customized=*/null); |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
402 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
403 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
404 |
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
|
405 |
int arity = formals.length; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
406 |
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
|
407 |
Name[] names = Arrays.copyOf(formals, length); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
408 |
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
|
409 |
if (result != null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
410 |
names[length - 1] = result; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
411 |
return names; |
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 |
|
34429
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
414 |
private LambdaForm(MethodType mt) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
415 |
// 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
|
416 |
// 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
|
417 |
// Called only from getPreparedForm. |
34429
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
418 |
this.arity = mt.parameterCount(); |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
419 |
this.result = (mt.returnType() == void.class || mt.returnType() == Void.class) ? -1 : arity; |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
420 |
this.names = buildEmptyNames(arity, mt, result == -1); |
29019
a859b806c8bd
8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents:
27803
diff
changeset
|
421 |
this.forceInline = true; |
29020
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
422 |
this.customized = null; |
43893 | 423 |
this.kind = Kind.ZERO; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
424 |
assert(nameRefsAreLegal()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
425 |
assert(isEmpty()); |
34429
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
426 |
String sig = null; |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
427 |
assert(isValidSignature(sig = basicTypeSignature())); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
428 |
assert(sig.equals(basicTypeSignature())) : sig + " != " + basicTypeSignature(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
429 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
430 |
|
34429
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
431 |
private static Name[] buildEmptyNames(int arity, MethodType mt, boolean isVoid) { |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
432 |
Name[] names = arguments(isVoid ? 0 : 1, mt); |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
433 |
if (!isVoid) { |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
434 |
Name zero = new Name(constantZero(basicType(mt.returnType()))); |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
435 |
names[arity] = zero.newIndex(arity); |
13423
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 |
return names; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
438 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
439 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
440 |
private static int fixResult(int result, Name[] names) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
441 |
if (result == LAST_RESULT) |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
442 |
result = names.length - 1; // might still be void |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
443 |
if (result >= 0 && names[result].type == V_TYPE) |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
444 |
result = VOID_RESULT; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
445 |
return result; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
446 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
447 |
|
43893 | 448 |
static boolean debugNames() { |
449 |
return DEBUG_NAME_COUNTERS != null; |
|
450 |
} |
|
451 |
||
452 |
static void associateWithDebugName(LambdaForm form, String name) { |
|
453 |
assert (debugNames()); |
|
454 |
synchronized (DEBUG_NAMES) { |
|
455 |
DEBUG_NAMES.put(form, name); |
|
456 |
} |
|
457 |
} |
|
458 |
||
459 |
String lambdaName() { |
|
460 |
if (DEBUG_NAMES != null) { |
|
461 |
synchronized (DEBUG_NAMES) { |
|
462 |
String name = DEBUG_NAMES.get(this); |
|
463 |
if (name == null) { |
|
464 |
name = generateDebugName(); |
|
465 |
} |
|
466 |
return name; |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
467 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
468 |
} |
43893 | 469 |
return kind.defaultLambdaName; |
470 |
} |
|
471 |
||
472 |
private String generateDebugName() { |
|
473 |
assert (debugNames()); |
|
474 |
String debugNameStem = kind.defaultLambdaName; |
|
475 |
Integer ctr = DEBUG_NAME_COUNTERS.getOrDefault(debugNameStem, 0); |
|
476 |
DEBUG_NAME_COUNTERS.put(debugNameStem, ctr + 1); |
|
477 |
StringBuilder buf = new StringBuilder(debugNameStem); |
|
478 |
int leadingZero = buf.length(); |
|
479 |
buf.append((int) ctr); |
|
480 |
for (int i = buf.length() - leadingZero; i < 3; i++) { |
|
481 |
buf.insert(leadingZero, '0'); |
|
482 |
} |
|
483 |
buf.append('_'); |
|
484 |
buf.append(basicTypeSignature()); |
|
485 |
String name = buf.toString(); |
|
486 |
associateWithDebugName(this, name); |
|
487 |
return name; |
|
13423
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 |
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
|
491 |
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
|
492 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
493 |
assert(n != null) : "n is null"; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
494 |
if (i < arity) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
495 |
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
|
496 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
497 |
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
|
498 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
499 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
500 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
501 |
|
29020
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
502 |
/** Customize LambdaForm for a particular MethodHandle */ |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
503 |
LambdaForm customize(MethodHandle mh) { |
43893 | 504 |
LambdaForm customForm = new LambdaForm(arity, names, result, forceInline, mh, kind); |
39483
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
505 |
if (COMPILE_THRESHOLD >= 0 && isCompiled) { |
29020
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
506 |
// If shared LambdaForm has been compiled, compile customized version as well. |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
507 |
customForm.compileToBytecode(); |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
508 |
} |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
509 |
customForm.transformCache = this; // LambdaFormEditor should always use uncustomized form. |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
510 |
return customForm; |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
511 |
} |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
512 |
|
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
513 |
/** Get uncustomized flavor of the LambdaForm */ |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
514 |
LambdaForm uncustomize() { |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
515 |
if (customized == null) { |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
516 |
return this; |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
517 |
} |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
518 |
assert(transformCache != null); // Customized LambdaForm should always has a link to uncustomized version. |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
519 |
LambdaForm uncustomizedForm = (LambdaForm)transformCache; |
39483
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
520 |
if (COMPILE_THRESHOLD >= 0 && isCompiled) { |
29020
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
521 |
// If customized LambdaForm has been compiled, compile uncustomized version as well. |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
522 |
uncustomizedForm.compileToBytecode(); |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
523 |
} |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
524 |
return uncustomizedForm; |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
525 |
} |
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
526 |
|
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
527 |
/** Renumber and/or replace params so that they are interned and canonically numbered. |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
528 |
* @return maximum argument list length among the names (since we have to pass over them anyway) |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
529 |
*/ |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
530 |
private int normalize() { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
531 |
Name[] oldNames = null; |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
532 |
int maxOutArity = 0; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
533 |
int changesStart = 0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
534 |
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
|
535 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
536 |
if (!n.initIndex(i)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
537 |
if (oldNames == null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
538 |
oldNames = names.clone(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
539 |
changesStart = i; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
540 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
541 |
names[i] = n.cloneWithIndex(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
542 |
} |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
543 |
if (n.arguments != null && maxOutArity < n.arguments.length) |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
544 |
maxOutArity = n.arguments.length; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
545 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
546 |
if (oldNames != null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
547 |
int startFixing = arity; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
548 |
if (startFixing <= changesStart) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
549 |
startFixing = changesStart+1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
550 |
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
|
551 |
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
|
552 |
names[i] = fixed.newIndex(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
553 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
554 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
555 |
assert(nameRefsAreLegal()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
556 |
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
|
557 |
boolean needIntern = false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
558 |
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
|
559 |
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
|
560 |
if (n != n2) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
561 |
names[i] = n2; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
562 |
needIntern = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
563 |
} |
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 |
if (needIntern) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
566 |
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
|
567 |
names[i].internArguments(); |
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 |
} |
29020
9f6d43586ccb
8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
vlivanov
parents:
29019
diff
changeset
|
570 |
assert(nameRefsAreLegal()); |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
571 |
return maxOutArity; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
572 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
573 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
574 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
575 |
* 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
|
576 |
* 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
|
577 |
* <p> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
578 |
* 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
|
579 |
* 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
|
580 |
* 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
|
581 |
* fresh lambdas, without confusion. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
582 |
*/ |
26481
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
583 |
boolean nameRefsAreLegal() { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
584 |
assert(arity >= 0 && arity <= names.length); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
585 |
assert(result >= -1 && result < names.length); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
586 |
// 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
|
587 |
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
|
588 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
589 |
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
|
590 |
assert(n.isParam()); |
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 |
// Also, do all local name references |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
593 |
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
|
594 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
595 |
assert(n.index() == i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
596 |
for (Object arg : n.arguments) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
597 |
if (arg instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
598 |
Name n2 = (Name) arg; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
599 |
int i2 = n2.index; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
600 |
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
|
601 |
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
|
602 |
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
|
603 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
604 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
605 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
606 |
return true; |
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 |
/** 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
|
610 |
// 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
|
611 |
// // 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
|
612 |
// return interpretWithArguments(args); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
613 |
// } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
614 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
615 |
/** Report the return type. */ |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
616 |
BasicType returnType() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
617 |
if (result < 0) return V_TYPE; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
618 |
Name n = names[result]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
619 |
return n.type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
620 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
621 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
622 |
/** Report the N-th argument type. */ |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
623 |
BasicType parameterType(int n) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
624 |
return parameter(n).type; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
625 |
} |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
626 |
|
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
627 |
/** Report the N-th argument name. */ |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
628 |
Name parameter(int n) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
629 |
assert(n < arity); |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
630 |
Name param = names[n]; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
631 |
assert(param.isParam()); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
632 |
return param; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
633 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
634 |
|
26479
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
635 |
/** Report the N-th argument type constraint. */ |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
636 |
Object parameterConstraint(int n) { |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
637 |
return parameter(n).constraint; |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
638 |
} |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
639 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
640 |
/** Report the arity. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
641 |
int arity() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
642 |
return arity; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
643 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
644 |
|
26472
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26468
diff
changeset
|
645 |
/** Report the number of expressions (non-parameter names). */ |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26468
diff
changeset
|
646 |
int expressionCount() { |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26468
diff
changeset
|
647 |
return names.length - arity; |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26468
diff
changeset
|
648 |
} |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26468
diff
changeset
|
649 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
650 |
/** 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
|
651 |
MethodType methodType() { |
34429
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
652 |
Class<?>[] ptypes = new Class<?>[arity]; |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
653 |
for (int i = 0; i < arity; ++i) { |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
654 |
ptypes[i] = parameterType(i).btClass; |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
655 |
} |
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
656 |
return MethodType.makeImpl(returnType().btClass, ptypes, true); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
657 |
} |
34429
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
658 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
659 |
/** 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
|
660 |
final String basicTypeSignature() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
661 |
StringBuilder buf = new StringBuilder(arity() + 3); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
662 |
for (int i = 0, a = arity(); i < a; i++) |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
663 |
buf.append(parameterType(i).basicTypeChar()); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
664 |
return buf.append('_').append(returnType().basicTypeChar()).toString(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
665 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
666 |
static int signatureArity(String sig) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
667 |
assert(isValidSignature(sig)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
668 |
return sig.indexOf('_'); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
669 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
670 |
static BasicType signatureReturn(String sig) { |
26464
65b37da18e06
8037209: Improvements and cleanups to bytecode assembly for lambda forms
vlivanov
parents:
25859
diff
changeset
|
671 |
return basicType(sig.charAt(signatureArity(sig) + 1)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
672 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
673 |
static boolean isValidSignature(String sig) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
674 |
int arity = sig.indexOf('_'); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
675 |
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
|
676 |
int siglen = sig.length(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
677 |
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
|
678 |
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
|
679 |
if (i == arity) continue; // skip '_' |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
680 |
char c = sig.charAt(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
681 |
if (c == 'V') |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
682 |
return (i == siglen - 1 && arity == siglen - 2); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
683 |
if (!isArgBasicTypeChar(c)) return false; // must be [LIJFD] |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
684 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
685 |
return true; // [LIJFD]*_[LIJFDV] |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
686 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
687 |
static MethodType signatureType(String sig) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
688 |
Class<?>[] ptypes = new Class<?>[signatureArity(sig)]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
689 |
for (int i = 0; i < ptypes.length; i++) |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
690 |
ptypes[i] = basicType(sig.charAt(i)).btClass; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
691 |
Class<?> rtype = signatureReturn(sig).btClass; |
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
692 |
return MethodType.makeImpl(rtype, ptypes, true); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
693 |
} |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
694 |
static MethodType basicMethodType(MethodType mt) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
695 |
return signatureType(basicTypeSignature(mt)); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
696 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
697 |
|
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
698 |
/** |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
699 |
* Check if i-th name is a call to MethodHandleImpl.selectAlternative. |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
700 |
*/ |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
701 |
boolean isSelectAlternative(int pos) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
702 |
// selectAlternative idiom: |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
703 |
// t_{n}:L=MethodHandleImpl.selectAlternative(...) |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
704 |
// t_{n+1}:?=MethodHandle.invokeBasic(t_{n}, ...) |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
705 |
if (pos+1 >= names.length) return false; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
706 |
Name name0 = names[pos]; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
707 |
Name name1 = names[pos+1]; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
708 |
return name0.refersTo(MethodHandleImpl.class, "selectAlternative") && |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
709 |
name1.isInvokeBasic() && |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
710 |
name1.lastUseIndex(name0) == 0 && // t_{n+1}:?=MethodHandle.invokeBasic(t_{n}, ...) |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
711 |
lastUseIndex(name0) == pos+1; // t_{n} is local: used only in t_{n+1} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
712 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
713 |
|
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
714 |
private boolean isMatchingIdiom(int pos, String idiomName, int nArgs) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
715 |
if (pos+2 >= names.length) return false; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
716 |
Name name0 = names[pos]; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
717 |
Name name1 = names[pos+1]; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
718 |
Name name2 = names[pos+2]; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
719 |
return name1.refersTo(MethodHandleImpl.class, idiomName) && |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
720 |
name0.isInvokeBasic() && |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
721 |
name2.isInvokeBasic() && |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
722 |
name1.lastUseIndex(name0) == nArgs && // t_{n+1}:L=MethodHandleImpl.<invoker>(<args>, t_{n}); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
723 |
lastUseIndex(name0) == pos+1 && // t_{n} is local: used only in t_{n+1} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
724 |
name2.lastUseIndex(name1) == 1 && // t_{n+2}:?=MethodHandle.invokeBasic(*, t_{n+1}) |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
725 |
lastUseIndex(name1) == pos+2; // t_{n+1} is local: used only in t_{n+2} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
726 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
727 |
|
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
728 |
/** |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
729 |
* Check if i-th name is a start of GuardWithCatch idiom. |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
730 |
*/ |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
731 |
boolean isGuardWithCatch(int pos) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
732 |
// GuardWithCatch idiom: |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
733 |
// t_{n}:L=MethodHandle.invokeBasic(...) |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
734 |
// t_{n+1}:L=MethodHandleImpl.guardWithCatch(*, *, *, t_{n}); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
735 |
// t_{n+2}:?=MethodHandle.invokeBasic(*, t_{n+1}) |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
736 |
return isMatchingIdiom(pos, "guardWithCatch", 3); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
737 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
738 |
|
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
739 |
/** |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
740 |
* Check if i-th name is a start of the tryFinally idiom. |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
741 |
*/ |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
742 |
boolean isTryFinally(int pos) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
743 |
// tryFinally idiom: |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
744 |
// t_{n}:L=MethodHandle.invokeBasic(...) |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
745 |
// t_{n+1}:L=MethodHandleImpl.tryFinally(*, *, t_{n}) |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
746 |
// t_{n+2}:?=MethodHandle.invokeBasic(*, t_{n+1}) |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
747 |
return isMatchingIdiom(pos, "tryFinally", 2); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
748 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
749 |
|
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
750 |
/** |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
751 |
* Check if i-th name is a start of the loop idiom. |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
752 |
*/ |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
753 |
boolean isLoop(int pos) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
754 |
// loop idiom: |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
755 |
// t_{n}:L=MethodHandle.invokeBasic(...) |
41125
88d76c8db1fa
8161211: better inlining support for loop bytecode intrinsics
mhaupt
parents:
40550
diff
changeset
|
756 |
// t_{n+1}:L=MethodHandleImpl.loop(types, *, t_{n}) |
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
757 |
// t_{n+2}:?=MethodHandle.invokeBasic(*, t_{n+1}) |
41125
88d76c8db1fa
8161211: better inlining support for loop bytecode intrinsics
mhaupt
parents:
40550
diff
changeset
|
758 |
return isMatchingIdiom(pos, "loop", 2); |
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
759 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
760 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
761 |
/* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
762 |
* Code generation issues: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
763 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
764 |
* 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
|
765 |
* 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
|
766 |
* 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
|
767 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
768 |
* 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
|
769 |
* 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
|
770 |
* 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
|
771 |
* 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
|
772 |
* 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
|
773 |
* 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
|
774 |
* 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
|
775 |
* 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
|
776 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
777 |
* 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
|
778 |
* 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
|
779 |
* 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
|
780 |
* 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
|
781 |
* 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
|
782 |
* 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
|
783 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
784 |
* 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
|
785 |
* 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
|
786 |
* 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
|
787 |
* 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
|
788 |
* (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
|
789 |
* 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
|
790 |
* (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
|
791 |
* 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
|
792 |
* 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
|
793 |
* 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
|
794 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
795 |
* 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
|
796 |
* 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
|
797 |
* "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
|
798 |
* 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
|
799 |
* 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
|
800 |
* 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
|
801 |
* (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
|
802 |
* 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
|
803 |
* 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
|
804 |
* 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
|
805 |
* optimization. "Significant" means optimization of |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
806 |
* code that is actually hot. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
807 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
808 |
* 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
|
809 |
* 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
|
810 |
* 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
|
811 |
* 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
|
812 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
813 |
* 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
|
814 |
* 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
|
815 |
* 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
|
816 |
* 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
|
817 |
* 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
|
818 |
* 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
|
819 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
820 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
821 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
822 |
* 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
|
823 |
* 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
|
824 |
* before invocation. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
825 |
* (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
|
826 |
* 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
|
827 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
828 |
public void prepare() { |
39483
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
829 |
if (COMPILE_THRESHOLD == 0 && !forceInterpretation() && !isCompiled) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
830 |
compileToBytecode(); |
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 |
if (this.vmentry != null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
833 |
// 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
|
834 |
return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
835 |
} |
34429
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
836 |
MethodType mtype = methodType(); |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
837 |
LambdaForm prep = mtype.form().cachedLambdaForm(MethodTypeForm.LF_INTERPRET); |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
838 |
if (prep == null) { |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
839 |
assert (isValidSignature(basicTypeSignature())); |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
840 |
prep = new LambdaForm(mtype); |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
841 |
prep.vmentry = InvokerBytecodeGenerator.generateLambdaFormInterpreterEntryPoint(mtype); |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
842 |
prep = mtype.form().setCachedLambdaForm(MethodTypeForm.LF_INTERPRET, prep); |
8893c723602e
8072844: Use more efficient LambdaForm type representation
mhaupt
parents:
34384
diff
changeset
|
843 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
844 |
this.vmentry = prep.vmentry; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
845 |
// TO DO: Maybe add invokeGeneric, invokeWithArguments |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
846 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
847 |
|
39483
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
848 |
private static @Stable PerfCounter LF_FAILED; |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
849 |
|
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
850 |
private static PerfCounter failedCompilationCounter() { |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
851 |
if (LF_FAILED == null) { |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
852 |
LF_FAILED = PerfCounter.newPerfCounter("java.lang.invoke.failedLambdaFormCompilations"); |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
853 |
} |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
854 |
return LF_FAILED; |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
855 |
} |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
856 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
857 |
/** Generate optimizable bytecode for this form. */ |
39483
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
858 |
void compileToBytecode() { |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
859 |
if (forceInterpretation()) { |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
860 |
return; // this should not be compiled |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
861 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
862 |
if (vmentry != null && isCompiled) { |
39483
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
863 |
return; // already compiled somehow |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
864 |
} |
44592
6b028630b652
8178480: Wrong exception being thrown on an invalid MethodType
redestad
parents:
44591
diff
changeset
|
865 |
|
6b028630b652
8178480: Wrong exception being thrown on an invalid MethodType
redestad
parents:
44591
diff
changeset
|
866 |
// Obtain the invoker MethodType outside of the following try block. |
6b028630b652
8178480: Wrong exception being thrown on an invalid MethodType
redestad
parents:
44591
diff
changeset
|
867 |
// This ensures that an IllegalArgumentException is directly thrown if the |
6b028630b652
8178480: Wrong exception being thrown on an invalid MethodType
redestad
parents:
44591
diff
changeset
|
868 |
// type would have 256 or more parameters |
6b028630b652
8178480: Wrong exception being thrown on an invalid MethodType
redestad
parents:
44591
diff
changeset
|
869 |
MethodType invokerType = methodType(); |
6b028630b652
8178480: Wrong exception being thrown on an invalid MethodType
redestad
parents:
44591
diff
changeset
|
870 |
assert(vmentry == null || vmentry.getMethodType().basicType().equals(invokerType)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
871 |
try { |
44592
6b028630b652
8178480: Wrong exception being thrown on an invalid MethodType
redestad
parents:
44591
diff
changeset
|
872 |
vmentry = InvokerBytecodeGenerator.generateCustomizedCode(this, invokerType); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
873 |
if (TRACE_INTERPRETER) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
874 |
traceInterpreter("compileToBytecode", this); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
875 |
isCompiled = true; |
39483
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
876 |
} catch (InvokerBytecodeGenerator.BytecodeGenerationException bge) { |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
877 |
// bytecode generation failed - mark this LambdaForm as to be run in interpretation mode only |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
878 |
invocationCounter = -1; |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
879 |
failedCompilationCounter().increment(); |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
880 |
if (LOG_LF_COMPILATION_FAILURE) { |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
881 |
System.out.println("LambdaForm compilation failed: " + this); |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
882 |
bge.printStackTrace(System.out); |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
883 |
} |
42105
d04ede5f10e7
8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents:
41125
diff
changeset
|
884 |
} catch (Error e) { |
d04ede5f10e7
8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents:
41125
diff
changeset
|
885 |
// Pass through any error |
d04ede5f10e7
8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents:
41125
diff
changeset
|
886 |
throw e; |
d04ede5f10e7
8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents:
41125
diff
changeset
|
887 |
} catch (Exception e) { |
d04ede5f10e7
8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents:
41125
diff
changeset
|
888 |
// Wrap any exception |
39483
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
889 |
throw newInternalError(this.toString(), e); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
890 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
891 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
892 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
893 |
// 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
|
894 |
// 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
|
895 |
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
|
896 |
int arity = signatureArity(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
897 |
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
|
898 |
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
|
899 |
MethodHandle mh = (MethodHandle) av[0]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
900 |
MethodType mt = mh.type(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
901 |
assert(mt.parameterCount() == arity-1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
902 |
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
|
903 |
Class<?> pt = (i == 0 ? MethodHandle.class : mt.parameterType(i-1)); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
904 |
assert(valueMatches(basicType(sig.charAt(i)), pt, av[i])); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
905 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
906 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
907 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
908 |
private static boolean valueMatches(BasicType tc, Class<?> type, Object x) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
909 |
// The following line is needed because (...)void method handles can use non-void invokers |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
910 |
if (type == void.class) tc = V_TYPE; // can drop any kind of value |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
911 |
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
|
912 |
switch (tc) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
913 |
case I_TYPE: assert checkInt(type, x) : "checkInt(" + type + "," + x +")"; break; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
914 |
case J_TYPE: assert x instanceof Long : "instanceof Long: " + x; break; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
915 |
case F_TYPE: assert x instanceof Float : "instanceof Float: " + x; break; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
916 |
case D_TYPE: assert x instanceof Double : "instanceof Double: " + x; break; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
917 |
case L_TYPE: assert checkRef(type, x) : "checkRef(" + type + "," + x + ")"; break; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
918 |
case V_TYPE: break; // allow anything here; will be dropped |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
919 |
default: assert(false); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
920 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
921 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
922 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
923 |
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
|
924 |
assert(x instanceof Integer); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
925 |
if (type == int.class) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
926 |
Wrapper w = Wrapper.forBasicType(type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
927 |
assert(w.isSubwordOrInt()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
928 |
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
|
929 |
return x.equals(x1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
930 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
931 |
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
|
932 |
assert(!type.isPrimitive()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
933 |
if (x == null) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
934 |
if (type.isInterface()) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
935 |
return type.isInstance(x); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
936 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
937 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
938 |
/** 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
|
939 |
private static final int COMPILE_THRESHOLD; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
940 |
static { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
941 |
COMPILE_THRESHOLD = Math.max(-1, MethodHandleStatics.COMPILE_THRESHOLD); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
942 |
} |
39483
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
943 |
private int invocationCounter = 0; // a value of -1 indicates LambdaForm interpretation mode forever |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
944 |
|
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
945 |
private boolean forceInterpretation() { |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
946 |
return invocationCounter == -1; |
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
947 |
} |
13423
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 |
@Hidden |
14852 | 950 |
@DontInline |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
951 |
/** 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
|
952 |
Object interpretWithArguments(Object... argumentValues) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
953 |
if (TRACE_INTERPRETER) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
954 |
return interpretWithArgumentsTracing(argumentValues); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
955 |
checkInvocationCounter(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
956 |
assert(arityCheck(argumentValues)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
957 |
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
|
958 |
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
|
959 |
values[i] = interpretName(names[i], values); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
960 |
} |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
961 |
Object rv = (result < 0) ? null : values[result]; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
962 |
assert(resultCheck(argumentValues, rv)); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
963 |
return rv; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
964 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
965 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
966 |
@Hidden |
14852 | 967 |
@DontInline |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
968 |
/** 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
|
969 |
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
|
970 |
if (TRACE_INTERPRETER) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
971 |
traceInterpreter("| interpretName", name.debugString(), (Object[]) null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
972 |
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
|
973 |
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
|
974 |
Object a = arguments[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
975 |
if (a instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
976 |
int i2 = ((Name)a).index(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
977 |
assert(names[i2] == a); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
978 |
a = values[i2]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
979 |
arguments[i] = a; |
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 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
982 |
return name.function.invokeWithArguments(arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
983 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
984 |
|
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
985 |
private void checkInvocationCounter() { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
986 |
if (COMPILE_THRESHOLD != 0 && |
39483
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
987 |
!forceInterpretation() && invocationCounter < COMPILE_THRESHOLD) { |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
988 |
invocationCounter++; // benign race |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
989 |
if (invocationCounter >= COMPILE_THRESHOLD) { |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
990 |
// 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
|
991 |
compileToBytecode(); |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
992 |
} |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
993 |
} |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
994 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
995 |
Object interpretWithArgumentsTracing(Object... argumentValues) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
996 |
traceInterpreter("[ interpretWithArguments", this, argumentValues); |
39483
3a7e016ba204
8160717: MethodHandles.loop() does not check for excessive signature
mhaupt
parents:
39342
diff
changeset
|
997 |
if (!forceInterpretation() && invocationCounter < COMPILE_THRESHOLD) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
998 |
int ctr = invocationCounter++; // benign race |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
999 |
traceInterpreter("| invocationCounter", ctr); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1000 |
if (invocationCounter >= COMPILE_THRESHOLD) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1001 |
compileToBytecode(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1002 |
} |
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 |
Object rval; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1005 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1006 |
assert(arityCheck(argumentValues)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1007 |
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
|
1008 |
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
|
1009 |
values[i] = interpretName(names[i], values); |
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 |
rval = (result < 0) ? null : values[result]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1012 |
} catch (Throwable ex) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1013 |
traceInterpreter("] throw =>", ex); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1014 |
throw ex; |
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 |
traceInterpreter("] return =>", rval); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1017 |
return rval; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1018 |
} |
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 |
static void traceInterpreter(String event, Object obj, Object... args) { |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1021 |
if (TRACE_INTERPRETER) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1022 |
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
|
1023 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1024 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1025 |
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
|
1026 |
traceInterpreter(event, obj, (Object[])null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1027 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1028 |
private boolean arityCheck(Object[] argumentValues) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1029 |
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
|
1030 |
// 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
|
1031 |
assert(argumentValues[0] instanceof MethodHandle) : "not MH: " + argumentValues[0]; |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1032 |
MethodHandle mh = (MethodHandle) argumentValues[0]; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1033 |
assert(mh.internalForm() == this); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1034 |
// note: argument #0 could also be an interface wrapper, in the future |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1035 |
argumentTypesMatch(basicTypeSignature(), argumentValues); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1036 |
return true; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1037 |
} |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1038 |
private boolean resultCheck(Object[] argumentValues, Object result) { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1039 |
MethodHandle mh = (MethodHandle) argumentValues[0]; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1040 |
MethodType mt = mh.type(); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1041 |
assert(valueMatches(returnType(), mt.returnType(), result)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1042 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1043 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1044 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1045 |
private boolean isEmpty() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1046 |
if (result < 0) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1047 |
return (names.length == arity); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1048 |
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
|
1049 |
return names[arity].isConstantZero(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1050 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1051 |
return false; |
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 |
public String toString() { |
43893 | 1055 |
String lambdaName = lambdaName(); |
1056 |
StringBuilder buf = new StringBuilder(lambdaName + "=Lambda("); |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1057 |
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
|
1058 |
if (i == arity) buf.append(")=>{"); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1059 |
Name n = names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1060 |
if (i >= arity) buf.append("\n "); |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1061 |
buf.append(n.paramString()); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1062 |
if (i < arity) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1063 |
if (i+1 < arity) buf.append(","); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1064 |
continue; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1065 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1066 |
buf.append("=").append(n.exprString()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1067 |
buf.append(";"); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1068 |
} |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1069 |
if (arity == names.length) buf.append(")=>{"); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1070 |
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
|
1071 |
if (TRACE_INTERPRETER) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1072 |
// Extra verbosity: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1073 |
buf.append(":").append(basicTypeSignature()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1074 |
buf.append("/").append(vmentry); |
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 |
return buf.toString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1077 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1078 |
|
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1079 |
@Override |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1080 |
public boolean equals(Object obj) { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1081 |
return obj instanceof LambdaForm && equals((LambdaForm)obj); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1082 |
} |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1083 |
public boolean equals(LambdaForm that) { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1084 |
if (this.result != that.result) return false; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1085 |
return Arrays.equals(this.names, that.names); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1086 |
} |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1087 |
public int hashCode() { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1088 |
return result + 31 * Arrays.hashCode(names); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1089 |
} |
26481
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
1090 |
LambdaFormEditor editor() { |
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
1091 |
return LambdaFormEditor.lambdaFormEditor(this); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1092 |
} |
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 |
boolean contains(Name name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1095 |
int pos = name.index(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1096 |
if (pos >= 0) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1097 |
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
|
1098 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1099 |
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
|
1100 |
if (name.equals(names[i])) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1101 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1102 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1103 |
return false; |
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 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1106 |
static class NamedFunction { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1107 |
final MemberName member; |
33841
1d1d1ea6a5f2
8142334: Improve lazy initialization of java.lang.invoke
redestad
parents:
30035
diff
changeset
|
1108 |
private @Stable MethodHandle resolvedHandle; |
20494
cf77ae5ff678
8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents:
14852
diff
changeset
|
1109 |
@Stable MethodHandle invoker; |
45470
fad095de1919
8161207: remove extra MethodHandle subclass in MethodHandleImpl
rpressler
parents:
44592
diff
changeset
|
1110 |
private final MethodHandleImpl.Intrinsic intrinsicName; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1111 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1112 |
NamedFunction(MethodHandle resolvedHandle) { |
45470
fad095de1919
8161207: remove extra MethodHandle subclass in MethodHandleImpl
rpressler
parents:
44592
diff
changeset
|
1113 |
this(resolvedHandle.internalMemberName(), resolvedHandle, MethodHandleImpl.Intrinsic.NONE); |
fad095de1919
8161207: remove extra MethodHandle subclass in MethodHandleImpl
rpressler
parents:
44592
diff
changeset
|
1114 |
} |
fad095de1919
8161207: remove extra MethodHandle subclass in MethodHandleImpl
rpressler
parents:
44592
diff
changeset
|
1115 |
NamedFunction(MethodHandle resolvedHandle, MethodHandleImpl.Intrinsic intrinsic) { |
fad095de1919
8161207: remove extra MethodHandle subclass in MethodHandleImpl
rpressler
parents:
44592
diff
changeset
|
1116 |
this(resolvedHandle.internalMemberName(), resolvedHandle, intrinsic); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1117 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1118 |
NamedFunction(MemberName member, MethodHandle resolvedHandle) { |
45470
fad095de1919
8161207: remove extra MethodHandle subclass in MethodHandleImpl
rpressler
parents:
44592
diff
changeset
|
1119 |
this(member, resolvedHandle, MethodHandleImpl.Intrinsic.NONE); |
fad095de1919
8161207: remove extra MethodHandle subclass in MethodHandleImpl
rpressler
parents:
44592
diff
changeset
|
1120 |
} |
fad095de1919
8161207: remove extra MethodHandle subclass in MethodHandleImpl
rpressler
parents:
44592
diff
changeset
|
1121 |
NamedFunction(MemberName member, MethodHandle resolvedHandle, MethodHandleImpl.Intrinsic intrinsic) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1122 |
this.member = member; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1123 |
this.resolvedHandle = resolvedHandle; |
45470
fad095de1919
8161207: remove extra MethodHandle subclass in MethodHandleImpl
rpressler
parents:
44592
diff
changeset
|
1124 |
this.intrinsicName = intrinsic; |
fad095de1919
8161207: remove extra MethodHandle subclass in MethodHandleImpl
rpressler
parents:
44592
diff
changeset
|
1125 |
assert(resolvedHandle == null || |
fad095de1919
8161207: remove extra MethodHandle subclass in MethodHandleImpl
rpressler
parents:
44592
diff
changeset
|
1126 |
resolvedHandle.intrinsicName() == MethodHandleImpl.Intrinsic.NONE || |
fad095de1919
8161207: remove extra MethodHandle subclass in MethodHandleImpl
rpressler
parents:
44592
diff
changeset
|
1127 |
resolvedHandle.intrinsicName() == intrinsic) : resolvedHandle.intrinsicName() + " != " + intrinsic; |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1128 |
// The following assert is almost always correct, but will fail for corner cases, such as PrivateInvokeTest. |
39754 | 1129 |
//assert(!isInvokeBasic(member)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1130 |
} |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1131 |
NamedFunction(MethodType basicInvokerType) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1132 |
assert(basicInvokerType == basicInvokerType.basicType()) : basicInvokerType; |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1133 |
if (basicInvokerType.parameterSlotCount() < MethodType.MAX_MH_INVOKER_ARITY) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1134 |
this.resolvedHandle = basicInvokerType.invokers().basicInvoker(); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1135 |
this.member = resolvedHandle.internalMemberName(); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1136 |
} else { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1137 |
// necessary to pass BigArityTest |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1138 |
this.member = Invokers.invokeBasicMethod(basicInvokerType); |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1139 |
} |
45470
fad095de1919
8161207: remove extra MethodHandle subclass in MethodHandleImpl
rpressler
parents:
44592
diff
changeset
|
1140 |
this.intrinsicName = MethodHandleImpl.Intrinsic.NONE; |
39754 | 1141 |
assert(isInvokeBasic(member)); |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1142 |
} |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1143 |
|
39754 | 1144 |
private static boolean isInvokeBasic(MemberName member) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1145 |
return member != null && |
39754 | 1146 |
member.getDeclaringClass() == MethodHandle.class && |
1147 |
"invokeBasic".equals(member.getName()); |
|
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1148 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1149 |
|
34384
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
1150 |
// The next 2 constructors are used to break circular dependencies on MH.invokeStatic, etc. |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1151 |
// 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
|
1152 |
// 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
|
1153 |
// 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
|
1154 |
NamedFunction(Method method) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1155 |
this(new MemberName(method)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1156 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1157 |
NamedFunction(MemberName member) { |
34384
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
1158 |
this(member, null); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1159 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1160 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1161 |
MethodHandle resolvedHandle() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1162 |
if (resolvedHandle == null) resolve(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1163 |
return resolvedHandle; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1164 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1165 |
|
33841
1d1d1ea6a5f2
8142334: Improve lazy initialization of java.lang.invoke
redestad
parents:
30035
diff
changeset
|
1166 |
synchronized void resolve() { |
1d1d1ea6a5f2
8142334: Improve lazy initialization of java.lang.invoke
redestad
parents:
30035
diff
changeset
|
1167 |
if (resolvedHandle == null) { |
1d1d1ea6a5f2
8142334: Improve lazy initialization of java.lang.invoke
redestad
parents:
30035
diff
changeset
|
1168 |
resolvedHandle = DirectMethodHandle.make(member); |
1d1d1ea6a5f2
8142334: Improve lazy initialization of java.lang.invoke
redestad
parents:
30035
diff
changeset
|
1169 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1170 |
} |
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 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1173 |
public boolean equals(Object other) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1174 |
if (this == other) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1175 |
if (other == null) return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1176 |
if (!(other instanceof NamedFunction)) return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1177 |
NamedFunction that = (NamedFunction) other; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1178 |
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
|
1179 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1180 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1181 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1182 |
public int hashCode() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1183 |
if (member != null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1184 |
return member.hashCode(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1185 |
return super.hashCode(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1186 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1187 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1188 |
static final MethodType INVOKER_METHOD_TYPE = |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1189 |
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
|
1190 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1191 |
private static MethodHandle computeInvoker(MethodTypeForm typeForm) { |
26468 | 1192 |
typeForm = typeForm.basicType().form(); // normalize to basic type |
1193 |
MethodHandle mh = typeForm.cachedMethodHandle(MethodTypeForm.MH_NF_INV); |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1194 |
if (mh != null) return mh; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1195 |
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
|
1196 |
mh = DirectMethodHandle.make(invoker); |
26468 | 1197 |
MethodHandle mh2 = typeForm.cachedMethodHandle(MethodTypeForm.MH_NF_INV); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1198 |
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
|
1199 |
if (!mh.type().equals(INVOKER_METHOD_TYPE)) |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1200 |
throw newInternalError(mh.debugString()); |
26468 | 1201 |
return typeForm.setCachedMethodHandle(MethodTypeForm.MH_NF_INV, mh); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1202 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1203 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1204 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1205 |
Object invokeWithArguments(Object... arguments) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1206 |
// 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
|
1207 |
// 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
|
1208 |
if (TRACE_INTERPRETER) return invokeWithArgumentsTracing(arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1209 |
return invoker().invokeBasic(resolvedHandle(), arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1210 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1211 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1212 |
@Hidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1213 |
Object invokeWithArgumentsTracing(Object[] arguments) throws Throwable { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1214 |
Object rval; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1215 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1216 |
traceInterpreter("[ call", this, arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1217 |
if (invoker == null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1218 |
traceInterpreter("| getInvoker", this); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1219 |
invoker(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1220 |
} |
33841
1d1d1ea6a5f2
8142334: Improve lazy initialization of java.lang.invoke
redestad
parents:
30035
diff
changeset
|
1221 |
// resolvedHandle might be uninitialized, ok for tracing |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1222 |
if (resolvedHandle == null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1223 |
traceInterpreter("| resolve", this); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1224 |
resolvedHandle(); |
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 |
rval = invoker().invokeBasic(resolvedHandle(), arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1227 |
} catch (Throwable ex) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1228 |
traceInterpreter("] throw =>", ex); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1229 |
throw ex; |
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 |
traceInterpreter("] return =>", rval); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1232 |
return rval; |
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 |
private MethodHandle invoker() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1236 |
if (invoker != null) return invoker; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1237 |
// Get an invoker and cache it. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1238 |
return invoker = computeInvoker(methodType().form()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1239 |
} |
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 |
MethodType methodType() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1242 |
if (resolvedHandle != null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1243 |
return resolvedHandle.type(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1244 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1245 |
// 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
|
1246 |
return member.getInvocationType(); |
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 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1249 |
MemberName member() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1250 |
assert(assertMemberIsConsistent()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1251 |
return member; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1252 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1253 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1254 |
// Called only from assert. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1255 |
private boolean assertMemberIsConsistent() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1256 |
if (resolvedHandle instanceof DirectMethodHandle) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1257 |
MemberName m = resolvedHandle.internalMemberName(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1258 |
assert(m.equals(member)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1259 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1260 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1261 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1262 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1263 |
Class<?> memberDeclaringClassOrNull() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1264 |
return (member == null) ? null : member.getDeclaringClass(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1265 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1266 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1267 |
BasicType returnType() { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1268 |
return basicType(methodType().returnType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1269 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1270 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1271 |
BasicType parameterType(int n) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1272 |
return basicType(methodType().parameterType(n)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1273 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1274 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1275 |
int arity() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1276 |
return methodType().parameterCount(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1277 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1278 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1279 |
public String toString() { |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1280 |
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
|
1281 |
return member.getDeclaringClass().getSimpleName()+"."+member.getName(); |
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 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1284 |
public boolean isIdentity() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1285 |
return this.equals(identity(returnType())); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1286 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1287 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1288 |
public boolean isConstantZero() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1289 |
return this.equals(constantZero(returnType())); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1290 |
} |
26473
0abc9399a1a6
8050200: Make LambdaForm intrinsics detection more robust
vlivanov
parents:
26472
diff
changeset
|
1291 |
|
0abc9399a1a6
8050200: Make LambdaForm intrinsics detection more robust
vlivanov
parents:
26472
diff
changeset
|
1292 |
public MethodHandleImpl.Intrinsic intrinsicName() { |
45470
fad095de1919
8161207: remove extra MethodHandle subclass in MethodHandleImpl
rpressler
parents:
44592
diff
changeset
|
1293 |
return intrinsicName; |
26473
0abc9399a1a6
8050200: Make LambdaForm intrinsics detection more robust
vlivanov
parents:
26472
diff
changeset
|
1294 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1295 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1296 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1297 |
public static String basicTypeSignature(MethodType type) { |
40272
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40212
diff
changeset
|
1298 |
int params = type.parameterCount(); |
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40212
diff
changeset
|
1299 |
char[] sig = new char[params + 2]; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1300 |
int sigp = 0; |
40272
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40212
diff
changeset
|
1301 |
while (sigp < params) { |
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40212
diff
changeset
|
1302 |
sig[sigp] = basicTypeChar(type.parameterType(sigp++)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1303 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1304 |
sig[sigp++] = '_'; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1305 |
sig[sigp++] = basicTypeChar(type.returnType()); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1306 |
assert(sigp == sig.length); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1307 |
return String.valueOf(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1308 |
} |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1309 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1310 |
/** Hack to make signatures more readable when they show up in method names. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1311 |
* Signature should start with a sequence of uppercase ASCII letters. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1312 |
* Runs of three or more are replaced by a single letter plus a decimal repeat count. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1313 |
* A tail of anything other than uppercase ASCII is passed through unchanged. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1314 |
* @param signature sequence of uppercase ASCII letters with possible repetitions |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1315 |
* @return same sequence, with repetitions counted by decimal numerals |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1316 |
*/ |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1317 |
public static String shortenSignature(String signature) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1318 |
final int NO_CHAR = -1, MIN_RUN = 3; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1319 |
int c0, c1 = NO_CHAR, c1reps = 0; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1320 |
StringBuilder buf = null; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1321 |
int len = signature.length(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1322 |
if (len < MIN_RUN) return signature; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1323 |
for (int i = 0; i <= len; i++) { |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1324 |
if (c1 != NO_CHAR && !('A' <= c1 && c1 <= 'Z')) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1325 |
// wrong kind of char; bail out here |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1326 |
if (buf != null) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1327 |
buf.append(signature.substring(i - c1reps, len)); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1328 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1329 |
break; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1330 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1331 |
// shift in the next char: |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1332 |
c0 = c1; c1 = (i == len ? NO_CHAR : signature.charAt(i)); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1333 |
if (c1 == c0) { ++c1reps; continue; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1334 |
// shift in the next count: |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1335 |
int c0reps = c1reps; c1reps = 1; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1336 |
// end of a character run |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1337 |
if (c0reps < MIN_RUN) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1338 |
if (buf != null) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1339 |
while (--c0reps >= 0) |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1340 |
buf.append((char)c0); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1341 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1342 |
continue; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1343 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1344 |
// found three or more in a row |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1345 |
if (buf == null) |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1346 |
buf = new StringBuilder().append(signature, 0, i - c0reps); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1347 |
buf.append((char)c0).append(c0reps); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1348 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1349 |
return (buf == null) ? signature : buf.toString(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1350 |
} |
13423
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 |
static final class Name { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1353 |
final BasicType type; |
40272
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40212
diff
changeset
|
1354 |
@Stable short index; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1355 |
final NamedFunction function; |
26479
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1356 |
final Object constraint; // additional type information, if not null |
20494
cf77ae5ff678
8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents:
14852
diff
changeset
|
1357 |
@Stable final Object[] arguments; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1358 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1359 |
private Name(int index, BasicType type, NamedFunction function, Object[] arguments) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1360 |
this.index = (short)index; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1361 |
this.type = type; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1362 |
this.function = function; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1363 |
this.arguments = arguments; |
26479
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1364 |
this.constraint = null; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1365 |
assert(this.index == index); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1366 |
} |
26479
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1367 |
private Name(Name that, Object constraint) { |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1368 |
this.index = that.index; |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1369 |
this.type = that.type; |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1370 |
this.function = that.function; |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1371 |
this.arguments = that.arguments; |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1372 |
this.constraint = constraint; |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1373 |
assert(constraint == null || isParam()); // only params have constraints |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
1374 |
assert(constraint == null || constraint instanceof ClassSpecializer.SpeciesData || constraint instanceof Class); |
26479
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1375 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1376 |
Name(MethodHandle function, Object... arguments) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1377 |
this(new NamedFunction(function), arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1378 |
} |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1379 |
Name(MethodType functionType, Object... arguments) { |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1380 |
this(new NamedFunction(functionType), arguments); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1381 |
assert(arguments[0] instanceof Name && ((Name)arguments[0]).type == L_TYPE); |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1382 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1383 |
Name(MemberName function, Object... arguments) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1384 |
this(new NamedFunction(function), arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1385 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1386 |
Name(NamedFunction function, Object... arguments) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1387 |
this(-1, function.returnType(), function, arguments = Arrays.copyOf(arguments, arguments.length, Object[].class)); |
34384
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
1388 |
assert(typesMatch(function, arguments)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1389 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1390 |
/** Create a raw parameter of the given type, with an expected index. */ |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1391 |
Name(int index, BasicType type) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1392 |
this(index, type, null, null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1393 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1394 |
/** Create a raw parameter of the given type. */ |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1395 |
Name(BasicType type) { this(-1, type); } |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1396 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1397 |
BasicType type() { return type; } |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1398 |
int index() { return index; } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1399 |
boolean initIndex(int i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1400 |
if (index != i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1401 |
if (index != -1) return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1402 |
index = (short)i; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1403 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1404 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1405 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1406 |
char typeChar() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1407 |
return type.btChar; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1408 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1409 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1410 |
void resolve() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1411 |
if (function != null) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1412 |
function.resolve(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1413 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1414 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1415 |
Name newIndex(int i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1416 |
if (initIndex(i)) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1417 |
return cloneWithIndex(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1418 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1419 |
Name cloneWithIndex(int i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1420 |
Object[] newArguments = (arguments == null) ? null : arguments.clone(); |
26479
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1421 |
return new Name(i, type, function, newArguments).withConstraint(constraint); |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1422 |
} |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1423 |
Name withConstraint(Object constraint) { |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1424 |
if (constraint == this.constraint) return this; |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1425 |
return new Name(this, constraint); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1426 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1427 |
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
|
1428 |
if (oldName == newName) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1429 |
@SuppressWarnings("LocalVariableHidesMemberVariable") |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1430 |
Object[] arguments = this.arguments; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1431 |
if (arguments == null) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1432 |
boolean replaced = false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1433 |
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
|
1434 |
if (arguments[j] == oldName) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1435 |
if (!replaced) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1436 |
replaced = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1437 |
arguments = arguments.clone(); |
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 |
arguments[j] = newName; |
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 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1442 |
if (!replaced) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1443 |
return new Name(function, arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1444 |
} |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1445 |
/** In the arguments of this Name, replace oldNames[i] pairwise by newNames[i]. |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1446 |
* Limit such replacements to {@code start<=i<end}. Return possibly changed self. |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1447 |
*/ |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1448 |
Name replaceNames(Name[] oldNames, Name[] newNames, int start, int end) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1449 |
if (start >= end) return this; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1450 |
@SuppressWarnings("LocalVariableHidesMemberVariable") |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1451 |
Object[] arguments = this.arguments; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1452 |
boolean replaced = false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1453 |
eachArg: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1454 |
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
|
1455 |
if (arguments[j] instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1456 |
Name n = (Name) arguments[j]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1457 |
int check = n.index; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1458 |
// 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
|
1459 |
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
|
1460 |
continue eachArg; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1461 |
// 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
|
1462 |
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
|
1463 |
if (n == oldNames[i]) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1464 |
if (n == newNames[i]) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1465 |
continue eachArg; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1466 |
if (!replaced) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1467 |
replaced = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1468 |
arguments = arguments.clone(); |
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 |
arguments[j] = newNames[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1471 |
continue eachArg; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1472 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1473 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1474 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1475 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1476 |
if (!replaced) return this; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1477 |
return new Name(function, arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1478 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1479 |
void internArguments() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1480 |
@SuppressWarnings("LocalVariableHidesMemberVariable") |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1481 |
Object[] arguments = this.arguments; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1482 |
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
|
1483 |
if (arguments[j] instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1484 |
Name n = (Name) arguments[j]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1485 |
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
|
1486 |
arguments[j] = internArgument(n); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1487 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1488 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1489 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1490 |
boolean isParam() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1491 |
return function == null; |
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 |
boolean isConstantZero() { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1494 |
return !isParam() && arguments.length == 0 && function.isConstantZero(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1495 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1496 |
|
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1497 |
boolean refersTo(Class<?> declaringClass, String methodName) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1498 |
return function != null && |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1499 |
function.member() != null && function.member().refersTo(declaringClass, methodName); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1500 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1501 |
|
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1502 |
/** |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1503 |
* Check if MemberName is a call to MethodHandle.invokeBasic. |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1504 |
*/ |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1505 |
boolean isInvokeBasic() { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1506 |
if (function == null) |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1507 |
return false; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1508 |
if (arguments.length < 1) |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1509 |
return false; // must have MH argument |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1510 |
MemberName member = function.member(); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1511 |
return member != null && member.refersTo(MethodHandle.class, "invokeBasic") && |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1512 |
!member.isPublic() && !member.isStatic(); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1513 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1514 |
|
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1515 |
/** |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1516 |
* Check if MemberName is a call to MethodHandle.linkToStatic, etc. |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1517 |
*/ |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1518 |
boolean isLinkerMethodInvoke() { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1519 |
if (function == null) |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1520 |
return false; |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1521 |
if (arguments.length < 1) |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1522 |
return false; // must have MH argument |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1523 |
MemberName member = function.member(); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1524 |
return member != null && |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1525 |
member.getDeclaringClass() == MethodHandle.class && |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1526 |
!member.isPublic() && member.isStatic() && |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1527 |
member.getName().startsWith("linkTo"); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1528 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
35252
diff
changeset
|
1529 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1530 |
public String toString() { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1531 |
return (isParam()?"a":"t")+(index >= 0 ? index : System.identityHashCode(this))+":"+typeChar(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1532 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1533 |
public String debugString() { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1534 |
String s = paramString(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1535 |
return (function == null) ? s : s + "=" + exprString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1536 |
} |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1537 |
public String paramString() { |
26479
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1538 |
String s = toString(); |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1539 |
Object c = constraint; |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1540 |
if (c == null) |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1541 |
return s; |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1542 |
if (c instanceof Class) c = ((Class<?>)c).getSimpleName(); |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1543 |
return s + "/" + c; |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
1544 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1545 |
public String exprString() { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1546 |
if (function == null) return toString(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1547 |
StringBuilder buf = new StringBuilder(function.toString()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1548 |
buf.append("("); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1549 |
String cma = ""; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1550 |
for (Object a : arguments) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1551 |
buf.append(cma); cma = ","; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1552 |
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
|
1553 |
buf.append(a); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1554 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1555 |
buf.append("(").append(a).append(")"); |
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 |
buf.append(")"); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1558 |
return buf.toString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1559 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1560 |
|
34384
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
1561 |
private boolean typesMatch(NamedFunction function, Object ... arguments) { |
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
1562 |
assert(arguments.length == function.arity()) : "arity mismatch: arguments.length=" + arguments.length + " == function.arity()=" + function.arity() + " in " + debugString(); |
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
1563 |
for (int i = 0; i < arguments.length; i++) { |
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
1564 |
assert (typesMatch(function.parameterType(i), arguments[i])) : "types don't match: function.parameterType(" + i + ")=" + function.parameterType(i) + ", arguments[" + i + "]=" + arguments[i] + " in " + debugString(); |
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
1565 |
} |
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
1566 |
return true; |
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
1567 |
} |
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
1568 |
|
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
1569 |
private static boolean typesMatch(BasicType parameterType, Object object) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1570 |
if (object instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1571 |
return ((Name)object).type == parameterType; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1572 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1573 |
switch (parameterType) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1574 |
case I_TYPE: return object instanceof Integer; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1575 |
case J_TYPE: return object instanceof Long; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1576 |
case F_TYPE: return object instanceof Float; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1577 |
case D_TYPE: return object instanceof Double; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1578 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1579 |
assert(parameterType == L_TYPE); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1580 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1581 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1582 |
|
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1583 |
/** Return the index of the last occurrence of n in the argument array. |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1584 |
* Return -1 if the name is not used. |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1585 |
*/ |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1586 |
int lastUseIndex(Name n) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1587 |
if (arguments == null) return -1; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1588 |
for (int i = arguments.length; --i >= 0; ) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1589 |
if (arguments[i] == n) return i; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1590 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1591 |
return -1; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1592 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1593 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1594 |
/** Return the number of occurrences of n in the argument array. |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1595 |
* Return 0 if the name is not used. |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1596 |
*/ |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1597 |
int useCount(Name n) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1598 |
if (arguments == null) return 0; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1599 |
int count = 0; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1600 |
for (int i = arguments.length; --i >= 0; ) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1601 |
if (arguments[i] == n) ++count; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1602 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1603 |
return count; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1604 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1605 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1606 |
boolean contains(Name n) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1607 |
return this == n || lastUseIndex(n) >= 0; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1608 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1609 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1610 |
public boolean equals(Name that) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1611 |
if (this == that) return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1612 |
if (isParam()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1613 |
// each parameter is a unique atom |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1614 |
return false; // this != that |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1615 |
return |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1616 |
//this.index == that.index && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1617 |
this.type == that.type && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1618 |
this.function.equals(that.function) && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1619 |
Arrays.equals(this.arguments, that.arguments); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1620 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1621 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1622 |
public boolean equals(Object x) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1623 |
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
|
1624 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1625 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1626 |
public int hashCode() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1627 |
if (isParam()) |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1628 |
return index | (type.ordinal() << 8); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1629 |
return function.hashCode() ^ Arrays.hashCode(arguments); |
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 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1632 |
|
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1633 |
/** Return the index of the last name which contains n as an argument. |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1634 |
* Return -1 if the name is not used. Return names.length if it is the return value. |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1635 |
*/ |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1636 |
int lastUseIndex(Name n) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1637 |
int ni = n.index, nmax = names.length; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1638 |
assert(names[ni] == n); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1639 |
if (result == ni) return nmax; // live all the way beyond the end |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1640 |
for (int i = nmax; --i > ni; ) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1641 |
if (names[i].lastUseIndex(n) >= 0) |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1642 |
return i; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1643 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1644 |
return -1; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1645 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1646 |
|
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1647 |
/** Return the number of times n is used as an argument or return value. */ |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1648 |
int useCount(Name n) { |
34384
439c06c76808
8143131: Remove unused code from java.lang.invoke
redestad
parents:
33869
diff
changeset
|
1649 |
int nmax = names.length; |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1650 |
int end = lastUseIndex(n); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1651 |
if (end < 0) return 0; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1652 |
int count = 0; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1653 |
if (end == nmax) { count++; end--; } |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1654 |
int beg = n.index() + 1; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1655 |
if (beg < arity) beg = arity; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1656 |
for (int i = beg; i <= end; i++) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1657 |
count += names[i].useCount(n); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1658 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1659 |
return count; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1660 |
} |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
1661 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1662 |
static Name argument(int which, BasicType type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1663 |
if (which >= INTERNED_ARGUMENT_LIMIT) |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1664 |
return new Name(which, type); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1665 |
return INTERNED_ARGUMENTS[type.ordinal()][which]; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1666 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1667 |
static Name internArgument(Name n) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1668 |
assert(n.isParam()) : "not param: " + n; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1669 |
assert(n.index < INTERNED_ARGUMENT_LIMIT); |
26479
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26473
diff
changeset
|
1670 |
if (n.constraint != null) return n; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1671 |
return argument(n.index, n.type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1672 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1673 |
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
|
1674 |
int length = types.parameterCount(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1675 |
Name[] names = new Name[length + extra]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1676 |
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
|
1677 |
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
|
1678 |
return names; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1679 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1680 |
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
|
1681 |
private static final Name[][] INTERNED_ARGUMENTS |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1682 |
= new Name[ARG_TYPE_LIMIT][INTERNED_ARGUMENT_LIMIT]; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1683 |
static { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1684 |
for (BasicType type : BasicType.ARG_TYPES) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1685 |
int ord = type.ordinal(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1686 |
for (int i = 0; i < INTERNED_ARGUMENTS[ord].length; i++) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1687 |
INTERNED_ARGUMENTS[ord][i] = new Name(i, type); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1688 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1689 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1690 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1691 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1692 |
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
|
1693 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1694 |
static LambdaForm identityForm(BasicType type) { |
33842
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1695 |
int ord = type.ordinal(); |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1696 |
LambdaForm form = LF_identity[ord]; |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1697 |
if (form != null) { |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1698 |
return form; |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1699 |
} |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1700 |
createFormsFor(type); |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1701 |
return LF_identity[ord]; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1702 |
} |
33842
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1703 |
|
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1704 |
static LambdaForm zeroForm(BasicType type) { |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1705 |
int ord = type.ordinal(); |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1706 |
LambdaForm form = LF_zero[ord]; |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1707 |
if (form != null) { |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1708 |
return form; |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1709 |
} |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1710 |
createFormsFor(type); |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1711 |
return LF_zero[ord]; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1712 |
} |
33842
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1713 |
|
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1714 |
static NamedFunction identity(BasicType type) { |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1715 |
int ord = type.ordinal(); |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1716 |
NamedFunction function = NF_identity[ord]; |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1717 |
if (function != null) { |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1718 |
return function; |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1719 |
} |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1720 |
createFormsFor(type); |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1721 |
return NF_identity[ord]; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1722 |
} |
33842
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1723 |
|
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1724 |
static NamedFunction constantZero(BasicType type) { |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1725 |
int ord = type.ordinal(); |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1726 |
NamedFunction function = NF_zero[ord]; |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1727 |
if (function != null) { |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1728 |
return function; |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1729 |
} |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1730 |
createFormsFor(type); |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1731 |
return NF_zero[ord]; |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1732 |
} |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1733 |
|
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1734 |
private static final @Stable LambdaForm[] LF_identity = new LambdaForm[TYPE_LIMIT]; |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1735 |
private static final @Stable LambdaForm[] LF_zero = new LambdaForm[TYPE_LIMIT]; |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1736 |
private static final @Stable NamedFunction[] NF_identity = new NamedFunction[TYPE_LIMIT]; |
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1737 |
private static final @Stable NamedFunction[] NF_zero = new NamedFunction[TYPE_LIMIT]; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1738 |
|
48989
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1739 |
private static final Object createFormsLock = new Object(); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1740 |
private static void createFormsFor(BasicType type) { |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1741 |
// Avoid racy initialization during bootstrap |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1742 |
UNSAFE.ensureClassInitialized(BoundMethodHandle.class); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1743 |
synchronized (createFormsLock) { |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1744 |
final int ord = type.ordinal(); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1745 |
LambdaForm idForm = LF_identity[ord]; |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1746 |
if (idForm != null) { |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1747 |
return; |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1748 |
} |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1749 |
char btChar = type.basicTypeChar(); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1750 |
boolean isVoid = (type == V_TYPE); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1751 |
Class<?> btClass = type.btClass; |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1752 |
MethodType zeType = MethodType.methodType(btClass); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1753 |
MethodType idType = (isVoid) ? zeType : MethodType.methodType(btClass, btClass); |
33842
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1754 |
|
48989
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1755 |
// Look up symbolic names. It might not be necessary to have these, |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1756 |
// but if we need to emit direct references to bytecodes, it helps. |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1757 |
// Zero is built from a call to an identity function with a constant zero input. |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1758 |
MemberName idMem = new MemberName(LambdaForm.class, "identity_"+btChar, idType, REF_invokeStatic); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1759 |
MemberName zeMem = null; |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1760 |
try { |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1761 |
idMem = IMPL_NAMES.resolveOrFail(REF_invokeStatic, idMem, null, NoSuchMethodException.class); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1762 |
if (!isVoid) { |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1763 |
zeMem = new MemberName(LambdaForm.class, "zero_"+btChar, zeType, REF_invokeStatic); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1764 |
zeMem = IMPL_NAMES.resolveOrFail(REF_invokeStatic, zeMem, null, NoSuchMethodException.class); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1765 |
} |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1766 |
} catch (IllegalAccessException|NoSuchMethodException ex) { |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1767 |
throw newInternalError(ex); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1768 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1769 |
|
48989
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1770 |
NamedFunction idFun; |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1771 |
LambdaForm zeForm; |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1772 |
NamedFunction zeFun; |
33869
a25f84d078ab
8143232: Fix java.lang.invoke bootstrap when specifying COMPILE_THRESHOLD
redestad
parents:
33842
diff
changeset
|
1773 |
|
48989
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1774 |
// Create the LFs and NamedFunctions. Precompiling LFs to byte code is needed to break circular |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1775 |
// bootstrap dependency on this method in case we're interpreting LFs |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1776 |
if (isVoid) { |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1777 |
Name[] idNames = new Name[] { argument(0, L_TYPE) }; |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1778 |
idForm = new LambdaForm(1, idNames, VOID_RESULT, Kind.IDENTITY); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1779 |
idForm.compileToBytecode(); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1780 |
idFun = new NamedFunction(idMem, SimpleMethodHandle.make(idMem.getInvocationType(), idForm)); |
33842
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1781 |
|
48989
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1782 |
zeForm = idForm; |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1783 |
zeFun = idFun; |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1784 |
} else { |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1785 |
Name[] idNames = new Name[] { argument(0, L_TYPE), argument(1, type) }; |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1786 |
idForm = new LambdaForm(2, idNames, 1, Kind.IDENTITY); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1787 |
idForm.compileToBytecode(); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1788 |
idFun = new NamedFunction(idMem, SimpleMethodHandle.make(idMem.getInvocationType(), idForm), |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1789 |
MethodHandleImpl.Intrinsic.IDENTITY); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1790 |
|
48989
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1791 |
Object zeValue = Wrapper.forBasicType(btChar).zero(); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1792 |
Name[] zeNames = new Name[] { argument(0, L_TYPE), new Name(idFun, zeValue) }; |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1793 |
zeForm = new LambdaForm(1, zeNames, 1, Kind.ZERO); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1794 |
zeForm.compileToBytecode(); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1795 |
zeFun = new NamedFunction(zeMem, SimpleMethodHandle.make(zeMem.getInvocationType(), zeForm), |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1796 |
MethodHandleImpl.Intrinsic.ZERO); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1797 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1798 |
|
48989
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1799 |
LF_zero[ord] = zeForm; |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1800 |
NF_zero[ord] = zeFun; |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1801 |
LF_identity[ord] = idForm; |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1802 |
NF_identity[ord] = idFun; |
33842
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1803 |
|
48989
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1804 |
assert(idFun.isIdentity()); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1805 |
assert(zeFun.isConstantZero()); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1806 |
assert(new Name(zeFun).isConstantZero()); |
0b65c64c9db9
8198492: Bootstrapping java.lang.invoke can cause deadlock after JDK-8198418
redestad
parents:
47753
diff
changeset
|
1807 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1808 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1809 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1810 |
// Avoid appealing to ValueConversions at bootstrap time: |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1811 |
private static int identity_I(int x) { return x; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1812 |
private static long identity_J(long x) { return x; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1813 |
private static float identity_F(float x) { return x; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1814 |
private static double identity_D(double x) { return x; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1815 |
private static Object identity_L(Object x) { return x; } |
33842
d261fb6ab872
8142487: Cleanup sun.invoke.util.Wrapper zeroes to be both reliable and lazy
redestad
parents:
33841
diff
changeset
|
1816 |
private static void identity_V() { return; } |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1817 |
private static int zero_I() { return 0; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1818 |
private static long zero_J() { return 0; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1819 |
private static float zero_F() { return 0; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1820 |
private static double zero_D() { return 0; } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1821 |
private static Object zero_L() { return null; } |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1822 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1823 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1824 |
* Internal marker for byte-compiled LambdaForms. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1825 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1826 |
/*non-public*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1827 |
@Target(ElementType.METHOD) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1828 |
@Retention(RetentionPolicy.RUNTIME) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1829 |
@interface Compiled { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1830 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1831 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1832 |
private static final HashMap<String,Integer> DEBUG_NAME_COUNTERS; |
43893 | 1833 |
private static final HashMap<LambdaForm,String> DEBUG_NAMES; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1834 |
static { |
43893 | 1835 |
if (debugEnabled()) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1836 |
DEBUG_NAME_COUNTERS = new HashMap<>(); |
43893 | 1837 |
DEBUG_NAMES = new HashMap<>(); |
1838 |
} else { |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1839 |
DEBUG_NAME_COUNTERS = null; |
43893 | 1840 |
DEBUG_NAMES = null; |
1841 |
} |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1842 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1843 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1844 |
static { |
40419
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
1845 |
// The Holder class will contain pre-generated forms resolved |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
1846 |
// using MemberName.getFactory(). However, that doesn't initialize the |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
1847 |
// class, which subtly breaks inlining etc. By forcing |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
1848 |
// initialization of the Holder class we avoid these issues. |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
1849 |
UNSAFE.ensureClassInitialized(Holder.class); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23038
diff
changeset
|
1850 |
} |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1851 |
|
40419
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
1852 |
/* Placeholder class for zero and identity forms generated ahead of time */ |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
1853 |
final class Holder {} |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
1854 |
|
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1855 |
// 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
|
1856 |
// during execution of the static initializes of this class. |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1857 |
// Turning on TRACE_INTERPRETER too early will cause |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1858 |
// stack overflows and other misbehavior during attempts to trace events |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1859 |
// that occur during LambdaForm.<clinit>. |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
20494
diff
changeset
|
1860 |
// 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
|
1861 |
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
|
1862 |
} |