author | dholmes |
Sat, 23 Jun 2018 01:32:41 -0400 | |
changeset 50735 | 2f2af62dfac7 |
parent 49935 | 2ace90aec488 |
child 52220 | 9c260a6b6471 |
permissions | -rw-r--r-- |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1 |
/* |
49935 | 2 |
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
4 |
* |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
10 |
* |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
15 |
* accompanied this code). |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
16 |
* |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
20 |
* |
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
24 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
25 |
|
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
26 |
package java.lang.invoke; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
27 |
|
33674
566777f73c32
8140606: Update library code to use internal Unsafe
chegar
parents:
32649
diff
changeset
|
28 |
import jdk.internal.misc.Unsafe; |
35252
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34384
diff
changeset
|
29 |
import jdk.internal.vm.annotation.ForceInline; |
40211
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
30 |
import jdk.internal.vm.annotation.Stable; |
35252
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34384
diff
changeset
|
31 |
import sun.invoke.util.ValueConversions; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34384
diff
changeset
|
32 |
import sun.invoke.util.VerifyAccess; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34384
diff
changeset
|
33 |
import sun.invoke.util.VerifyType; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34384
diff
changeset
|
34 |
import sun.invoke.util.Wrapper; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34384
diff
changeset
|
35 |
|
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34384
diff
changeset
|
36 |
import java.lang.ref.WeakReference; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
37 |
import java.util.Arrays; |
35252
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34384
diff
changeset
|
38 |
import java.util.Objects; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34384
diff
changeset
|
39 |
|
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34384
diff
changeset
|
40 |
import static java.lang.invoke.LambdaForm.*; |
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
41 |
import static java.lang.invoke.LambdaForm.Kind.*; |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8821
diff
changeset
|
42 |
import static java.lang.invoke.MethodHandleNatives.Constants.*; |
35252
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34384
diff
changeset
|
43 |
import static java.lang.invoke.MethodHandleStatics.UNSAFE; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
34384
diff
changeset
|
44 |
import static java.lang.invoke.MethodHandleStatics.newInternalError; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
45 |
import static java.lang.invoke.MethodTypeForm.*; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
46 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
47 |
/** |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
48 |
* The flavor of method handle which implements a constant reference |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
49 |
* to a class member. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
50 |
* @author jrose |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
51 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
52 |
class DirectMethodHandle extends MethodHandle { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
53 |
final MemberName member; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
54 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
55 |
// Constructors and factory methods in this class *must* be package scoped or private. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
56 |
private DirectMethodHandle(MethodType mtype, LambdaForm form, MemberName member) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
57 |
super(mtype, form); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
58 |
if (!member.isResolved()) throw new InternalError(); |
16119
ca09c1ad6a45
8006179: JSR292 MethodHandles lookup with interface using findVirtual()
vlivanov
parents:
14342
diff
changeset
|
59 |
|
16484
f24cb2927b7a
8009222: java.lang.IllegalArgumentException: not invocable, no method type when attempting to get getter method handle for a static field
vlivanov
parents:
16123
diff
changeset
|
60 |
if (member.getDeclaringClass().isInterface() && |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
61 |
member.getReferenceKind() == REF_invokeInterface && |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
62 |
member.isMethod() && !member.isAbstract()) { |
16119
ca09c1ad6a45
8006179: JSR292 MethodHandles lookup with interface using findVirtual()
vlivanov
parents:
14342
diff
changeset
|
63 |
// Check for corner case: invokeinterface of Object method |
ca09c1ad6a45
8006179: JSR292 MethodHandles lookup with interface using findVirtual()
vlivanov
parents:
14342
diff
changeset
|
64 |
MemberName m = new MemberName(Object.class, member.getName(), member.getMethodType(), member.getReferenceKind()); |
ca09c1ad6a45
8006179: JSR292 MethodHandles lookup with interface using findVirtual()
vlivanov
parents:
14342
diff
changeset
|
65 |
m = MemberName.getFactory().resolveOrNull(m.getReferenceKind(), m, null); |
ca09c1ad6a45
8006179: JSR292 MethodHandles lookup with interface using findVirtual()
vlivanov
parents:
14342
diff
changeset
|
66 |
if (m != null && m.isPublic()) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
67 |
assert(member.getReferenceKind() == m.getReferenceKind()); // else this.form is wrong |
16119
ca09c1ad6a45
8006179: JSR292 MethodHandles lookup with interface using findVirtual()
vlivanov
parents:
14342
diff
changeset
|
68 |
member = m; |
ca09c1ad6a45
8006179: JSR292 MethodHandles lookup with interface using findVirtual()
vlivanov
parents:
14342
diff
changeset
|
69 |
} |
ca09c1ad6a45
8006179: JSR292 MethodHandles lookup with interface using findVirtual()
vlivanov
parents:
14342
diff
changeset
|
70 |
} |
ca09c1ad6a45
8006179: JSR292 MethodHandles lookup with interface using findVirtual()
vlivanov
parents:
14342
diff
changeset
|
71 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
72 |
this.member = member; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
73 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
74 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
75 |
// Factory methods: |
49935 | 76 |
static DirectMethodHandle make(byte refKind, Class<?> refc, MemberName member, Class<?> callerClass) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
77 |
MethodType mtype = member.getMethodOrFieldType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
78 |
if (!member.isStatic()) { |
49935 | 79 |
if (!member.getDeclaringClass().isAssignableFrom(refc) || member.isConstructor()) |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
80 |
throw new InternalError(member.toString()); |
49935 | 81 |
mtype = mtype.insertParameterTypes(0, refc); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
82 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
83 |
if (!member.isField()) { |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
84 |
// refKind reflects the original type of lookup via findSpecial or |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
85 |
// findVirtual etc. |
48557 | 86 |
switch (refKind) { |
87 |
case REF_invokeSpecial: { |
|
88 |
member = member.asSpecial(); |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
89 |
// if caller is an interface we need to adapt to get the |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
90 |
// receiver check inserted |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
91 |
if (callerClass == null) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
92 |
throw new InternalError("callerClass must not be null for REF_invokeSpecial"); |
49935 | 93 |
} |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
94 |
LambdaForm lform = preparedLambdaForm(member, callerClass.isInterface()); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
95 |
return new Special(mtype, lform, member, callerClass); |
48557 | 96 |
} |
97 |
case REF_invokeInterface: { |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
98 |
// for interfaces we always need the receiver typecheck, |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
99 |
// so we always pass 'true' to ensure we adapt if needed |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
100 |
// to include the REF_invokeSpecial case |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
101 |
LambdaForm lform = preparedLambdaForm(member, true); |
49935 | 102 |
return new Interface(mtype, lform, member, refc); |
48557 | 103 |
} |
104 |
default: { |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
105 |
LambdaForm lform = preparedLambdaForm(member); |
48557 | 106 |
return new DirectMethodHandle(mtype, lform, member); |
107 |
} |
|
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
108 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
109 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
110 |
LambdaForm lform = preparedFieldLambdaForm(member); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
111 |
if (member.isStatic()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
112 |
long offset = MethodHandleNatives.staticFieldOffset(member); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
113 |
Object base = MethodHandleNatives.staticFieldBase(member); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
114 |
return new StaticAccessor(mtype, lform, member, base, offset); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
115 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
116 |
long offset = MethodHandleNatives.objectFieldOffset(member); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
117 |
assert(offset == (int)offset); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
118 |
return new Accessor(mtype, lform, member, (int)offset); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
119 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
120 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
121 |
} |
49935 | 122 |
static DirectMethodHandle make(Class<?> refc, MemberName member) { |
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
123 |
byte refKind = member.getReferenceKind(); |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
124 |
if (refKind == REF_invokeSpecial) |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
125 |
refKind = REF_invokeVirtual; |
49935 | 126 |
return make(refKind, refc, member, null /* no callerClass context */); |
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
127 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
128 |
static DirectMethodHandle make(MemberName member) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
129 |
if (member.isConstructor()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
130 |
return makeAllocator(member); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
131 |
return make(member.getDeclaringClass(), member); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
132 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
133 |
private static DirectMethodHandle makeAllocator(MemberName ctor) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
134 |
assert(ctor.isConstructor() && ctor.getName().equals("<init>")); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
135 |
Class<?> instanceClass = ctor.getDeclaringClass(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
136 |
ctor = ctor.asConstructor(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
137 |
assert(ctor.isConstructor() && ctor.getReferenceKind() == REF_newInvokeSpecial) : ctor; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
138 |
MethodType mtype = ctor.getMethodType().changeReturnType(instanceClass); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
139 |
LambdaForm lform = preparedLambdaForm(ctor); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
140 |
MemberName init = ctor.asSpecial(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
141 |
assert(init.getMethodType().returnType() == void.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
142 |
return new Constructor(mtype, lform, ctor, init, instanceClass); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
143 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
144 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
145 |
@Override |
26472
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26470
diff
changeset
|
146 |
BoundMethodHandle rebind() { |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26470
diff
changeset
|
147 |
return BoundMethodHandle.makeReinvoker(this); |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26470
diff
changeset
|
148 |
} |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26470
diff
changeset
|
149 |
|
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26470
diff
changeset
|
150 |
@Override |
26470
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
151 |
MethodHandle copyWith(MethodType mt, LambdaForm lf) { |
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
152 |
assert(this.getClass() == DirectMethodHandle.class); // must override in subclasses |
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
153 |
return new DirectMethodHandle(mt, lf, member); |
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
154 |
} |
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
155 |
|
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
156 |
@Override |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13423
diff
changeset
|
157 |
String internalProperties() { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
26464
diff
changeset
|
158 |
return "\n& DMH.MN="+internalMemberName(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
159 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
160 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
161 |
//// Implementation methods. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
162 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
163 |
@ForceInline |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
164 |
MemberName internalMemberName() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
165 |
return member; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
166 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
167 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
168 |
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:
8822
diff
changeset
|
169 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
170 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
171 |
* Create a LF which can invoke the given method. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
172 |
* Cache and share this structure among all methods with |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
173 |
* the same basicType and refKind. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
174 |
*/ |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
175 |
private static LambdaForm preparedLambdaForm(MemberName m, boolean adaptToSpecialIfc) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
176 |
assert(m.isInvocable()) : m; // call preparedFieldLambdaForm instead |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
177 |
MethodType mtype = m.getInvocationType().basicType(); |
39754 | 178 |
assert(!m.isMethodHandleInvoke()) : m; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
179 |
int which; |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
180 |
// MemberName.getReferenceKind represents the JVM optimized form of the call |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
181 |
// as distinct from the "kind" passed to DMH.make which represents the original |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
182 |
// bytecode-equivalent request. Specifically private/final methods that use a direct |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
183 |
// call have getReferenceKind adapted to REF_invokeSpecial, even though the actual |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
184 |
// invocation mode may be invokevirtual or invokeinterface. |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
185 |
switch (m.getReferenceKind()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
186 |
case REF_invokeVirtual: which = LF_INVVIRTUAL; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
187 |
case REF_invokeStatic: which = LF_INVSTATIC; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
188 |
case REF_invokeSpecial: which = LF_INVSPECIAL; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
189 |
case REF_invokeInterface: which = LF_INVINTERFACE; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
190 |
case REF_newInvokeSpecial: which = LF_NEWINVSPECIAL; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
191 |
default: throw new InternalError(m.toString()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
192 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
193 |
if (which == LF_INVSTATIC && shouldBeInitialized(m)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
194 |
// precompute the barrier-free version: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
195 |
preparedLambdaForm(mtype, which); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
196 |
which = LF_INVSTATIC_INIT; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
197 |
} |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
198 |
if (which == LF_INVSPECIAL && adaptToSpecialIfc) { |
49935 | 199 |
which = LF_INVSPECIAL_IFC; |
200 |
} |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
201 |
LambdaForm lform = preparedLambdaForm(mtype, which); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
202 |
maybeCompile(lform, m); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
203 |
assert(lform.methodType().dropParameterTypes(0, 1) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
204 |
.equals(m.getInvocationType().basicType())) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
205 |
: Arrays.asList(m, m.getInvocationType().basicType(), lform, lform.methodType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
206 |
return lform; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
207 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
208 |
|
49935 | 209 |
private static LambdaForm preparedLambdaForm(MemberName m) { |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
49935
diff
changeset
|
210 |
return preparedLambdaForm(m, false); |
49935 | 211 |
} |
212 |
||
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
213 |
private static LambdaForm preparedLambdaForm(MethodType mtype, int which) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
214 |
LambdaForm lform = mtype.form().cachedLambdaForm(which); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
215 |
if (lform != null) return lform; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
216 |
lform = makePreparedLambdaForm(mtype, which); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
217 |
return mtype.form().setCachedLambdaForm(which, lform); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
218 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
219 |
|
40258
e6ba2e5c7a29
8163373: Rewrite GenerateJLIClassesPlugin to avoid reflective calls into java.lang.invoke
redestad
parents:
40256
diff
changeset
|
220 |
static LambdaForm makePreparedLambdaForm(MethodType mtype, int which) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
221 |
boolean needsInit = (which == LF_INVSTATIC_INIT); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
222 |
boolean doesAlloc = (which == LF_NEWINVSPECIAL); |
49935 | 223 |
boolean needsReceiverCheck = (which == LF_INVINTERFACE || |
224 |
which == LF_INVSPECIAL_IFC); |
|
225 |
||
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
226 |
String linkerName; |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
227 |
LambdaForm.Kind kind; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
228 |
switch (which) { |
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
229 |
case LF_INVVIRTUAL: linkerName = "linkToVirtual"; kind = DIRECT_INVOKE_VIRTUAL; break; |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
230 |
case LF_INVSTATIC: linkerName = "linkToStatic"; kind = DIRECT_INVOKE_STATIC; break; |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
231 |
case LF_INVSTATIC_INIT:linkerName = "linkToStatic"; kind = DIRECT_INVOKE_STATIC_INIT; break; |
49935 | 232 |
case LF_INVSPECIAL_IFC:linkerName = "linkToSpecial"; kind = DIRECT_INVOKE_SPECIAL_IFC; break; |
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
233 |
case LF_INVSPECIAL: linkerName = "linkToSpecial"; kind = DIRECT_INVOKE_SPECIAL; break; |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
234 |
case LF_INVINTERFACE: linkerName = "linkToInterface"; kind = DIRECT_INVOKE_INTERFACE; break; |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
235 |
case LF_NEWINVSPECIAL: linkerName = "linkToSpecial"; kind = DIRECT_NEW_INVOKE_SPECIAL; break; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
236 |
default: throw new InternalError("which="+which); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
237 |
} |
40211
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
238 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
239 |
MethodType mtypeWithArg = mtype.appendParameterTypes(MemberName.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
240 |
if (doesAlloc) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
241 |
mtypeWithArg = mtypeWithArg |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
242 |
.insertParameterTypes(0, Object.class) // insert newly allocated obj |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
243 |
.changeReturnType(void.class); // <init> returns void |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
244 |
MemberName linker = new MemberName(MethodHandle.class, linkerName, mtypeWithArg, REF_invokeStatic); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
245 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
246 |
linker = IMPL_NAMES.resolveOrFail(REF_invokeStatic, linker, null, NoSuchMethodException.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
247 |
} catch (ReflectiveOperationException ex) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
248 |
throw newInternalError(ex); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
249 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
250 |
final int DMH_THIS = 0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
251 |
final int ARG_BASE = 1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
252 |
final int ARG_LIMIT = ARG_BASE + mtype.parameterCount(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
253 |
int nameCursor = ARG_LIMIT; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
254 |
final int NEW_OBJ = (doesAlloc ? nameCursor++ : -1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
255 |
final int GET_MEMBER = nameCursor++; |
48557 | 256 |
final int CHECK_RECEIVER = (needsReceiverCheck ? nameCursor++ : -1); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
257 |
final int LINKER_CALL = nameCursor++; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
258 |
Name[] names = arguments(nameCursor - ARG_LIMIT, mtype.invokerType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
259 |
assert(names.length == nameCursor); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
260 |
if (doesAlloc) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
261 |
// names = { argx,y,z,... new C, init method } |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
262 |
names[NEW_OBJ] = new Name(getFunction(NF_allocateInstance), names[DMH_THIS]); |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
263 |
names[GET_MEMBER] = new Name(getFunction(NF_constructorMethod), names[DMH_THIS]); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
264 |
} else if (needsInit) { |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
265 |
names[GET_MEMBER] = new Name(getFunction(NF_internalMemberNameEnsureInit), names[DMH_THIS]); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
266 |
} else { |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
267 |
names[GET_MEMBER] = new Name(getFunction(NF_internalMemberName), names[DMH_THIS]); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
268 |
} |
26464
65b37da18e06
8037209: Improvements and cleanups to bytecode assembly for lambda forms
vlivanov
parents:
25859
diff
changeset
|
269 |
assert(findDirectMethodHandle(names[GET_MEMBER]) == names[DMH_THIS]); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
270 |
Object[] outArgs = Arrays.copyOfRange(names, ARG_BASE, GET_MEMBER+1, Object[].class); |
48557 | 271 |
if (needsReceiverCheck) { |
272 |
names[CHECK_RECEIVER] = new Name(getFunction(NF_checkReceiver), names[DMH_THIS], names[ARG_BASE]); |
|
273 |
outArgs[0] = names[CHECK_RECEIVER]; |
|
274 |
} |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
275 |
assert(outArgs[outArgs.length-1] == names[GET_MEMBER]); // look, shifted args! |
26464
65b37da18e06
8037209: Improvements and cleanups to bytecode assembly for lambda forms
vlivanov
parents:
25859
diff
changeset
|
276 |
int result = LAST_RESULT; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
277 |
if (doesAlloc) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
278 |
assert(outArgs[outArgs.length-2] == names[NEW_OBJ]); // got to move this one |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
279 |
System.arraycopy(outArgs, 0, outArgs, 1, outArgs.length-2); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
280 |
outArgs[0] = names[NEW_OBJ]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
281 |
result = NEW_OBJ; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
282 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
283 |
names[LINKER_CALL] = new Name(linker, outArgs); |
43893 | 284 |
LambdaForm lform = new LambdaForm(ARG_LIMIT, names, result, kind); |
40211
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
285 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
286 |
// This is a tricky bit of code. Don't send it through the LF interpreter. |
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
287 |
lform.compileToBytecode(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
288 |
return lform; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
289 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
290 |
|
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
291 |
/* assert */ static Object findDirectMethodHandle(Name name) { |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
292 |
if (name.function.equals(getFunction(NF_internalMemberName)) || |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
293 |
name.function.equals(getFunction(NF_internalMemberNameEnsureInit)) || |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
294 |
name.function.equals(getFunction(NF_constructorMethod))) { |
26464
65b37da18e06
8037209: Improvements and cleanups to bytecode assembly for lambda forms
vlivanov
parents:
25859
diff
changeset
|
295 |
assert(name.arguments.length == 1); |
65b37da18e06
8037209: Improvements and cleanups to bytecode assembly for lambda forms
vlivanov
parents:
25859
diff
changeset
|
296 |
return name.arguments[0]; |
65b37da18e06
8037209: Improvements and cleanups to bytecode assembly for lambda forms
vlivanov
parents:
25859
diff
changeset
|
297 |
} |
65b37da18e06
8037209: Improvements and cleanups to bytecode assembly for lambda forms
vlivanov
parents:
25859
diff
changeset
|
298 |
return null; |
65b37da18e06
8037209: Improvements and cleanups to bytecode assembly for lambda forms
vlivanov
parents:
25859
diff
changeset
|
299 |
} |
65b37da18e06
8037209: Improvements and cleanups to bytecode assembly for lambda forms
vlivanov
parents:
25859
diff
changeset
|
300 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
301 |
private static void maybeCompile(LambdaForm lform, MemberName m) { |
40272
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40258
diff
changeset
|
302 |
if (lform.vmentry == null && VerifyAccess.isSamePackage(m.getDeclaringClass(), MethodHandle.class)) |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
303 |
// Help along bootstrapping... |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
304 |
lform.compileToBytecode(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
305 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
306 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
307 |
/** Static wrapper for DirectMethodHandle.internalMemberName. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
308 |
@ForceInline |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
309 |
/*non-public*/ static Object internalMemberName(Object mh) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
310 |
return ((DirectMethodHandle)mh).member; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
311 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
312 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
313 |
/** Static wrapper for DirectMethodHandle.internalMemberName. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
314 |
* This one also forces initialization. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
315 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
316 |
/*non-public*/ static Object internalMemberNameEnsureInit(Object mh) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
317 |
DirectMethodHandle dmh = (DirectMethodHandle)mh; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
318 |
dmh.ensureInitialized(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
319 |
return dmh.member; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
320 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
321 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
322 |
/*non-public*/ static |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
323 |
boolean shouldBeInitialized(MemberName member) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
324 |
switch (member.getReferenceKind()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
325 |
case REF_invokeStatic: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
326 |
case REF_getStatic: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
327 |
case REF_putStatic: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
328 |
case REF_newInvokeSpecial: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
329 |
break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
330 |
default: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
331 |
// No need to initialize the class on this kind of member. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
332 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
333 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
334 |
Class<?> cls = member.getDeclaringClass(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
335 |
if (cls == ValueConversions.class || |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
336 |
cls == MethodHandleImpl.class || |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
337 |
cls == Invokers.class) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
338 |
// These guys have lots of <clinit> DMH creation but we know |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
339 |
// the MHs will not be used until the system is booted. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
340 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
341 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
342 |
if (VerifyAccess.isSamePackage(MethodHandle.class, cls) || |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
343 |
VerifyAccess.isSamePackage(ValueConversions.class, cls)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
344 |
// It is a system class. It is probably in the process of |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
345 |
// being initialized, but we will help it along just to be safe. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
346 |
if (UNSAFE.shouldBeInitialized(cls)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
347 |
UNSAFE.ensureClassInitialized(cls); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
348 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
349 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
350 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
351 |
return UNSAFE.shouldBeInitialized(cls); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
352 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
353 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
354 |
private static class EnsureInitialized extends ClassValue<WeakReference<Thread>> { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
355 |
@Override |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
356 |
protected WeakReference<Thread> computeValue(Class<?> type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
357 |
UNSAFE.ensureClassInitialized(type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
358 |
if (UNSAFE.shouldBeInitialized(type)) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
359 |
// If the previous call didn't block, this can happen. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
360 |
// We are executing inside <clinit>. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
361 |
return new WeakReference<>(Thread.currentThread()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
362 |
return null; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
363 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
364 |
static final EnsureInitialized INSTANCE = new EnsureInitialized(); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
365 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
366 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
367 |
private void ensureInitialized() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
368 |
if (checkInitialized(member)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
369 |
// The coast is clear. Delete the <clinit> barrier. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
370 |
if (member.isField()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
371 |
updateForm(preparedFieldLambdaForm(member)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
372 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
373 |
updateForm(preparedLambdaForm(member)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
374 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
375 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
376 |
private static boolean checkInitialized(MemberName member) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
377 |
Class<?> defc = member.getDeclaringClass(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
378 |
WeakReference<Thread> ref = EnsureInitialized.INSTANCE.get(defc); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
379 |
if (ref == null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
380 |
return true; // the final state |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
381 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
382 |
Thread clinitThread = ref.get(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
383 |
// Somebody may still be running defc.<clinit>. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
384 |
if (clinitThread == Thread.currentThread()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
385 |
// If anybody is running defc.<clinit>, it is this thread. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
386 |
if (UNSAFE.shouldBeInitialized(defc)) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
387 |
// Yes, we are running it; keep the barrier for now. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
388 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
389 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
390 |
// We are in a random thread. Block. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
391 |
UNSAFE.ensureClassInitialized(defc); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
392 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
393 |
assert(!UNSAFE.shouldBeInitialized(defc)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
394 |
// put it into the final state |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
395 |
EnsureInitialized.INSTANCE.remove(defc); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
396 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
397 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
398 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
399 |
/*non-public*/ static void ensureInitialized(Object mh) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
400 |
((DirectMethodHandle)mh).ensureInitialized(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
401 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
402 |
|
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
403 |
/** This subclass represents invokespecial instructions. */ |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
404 |
static class Special extends DirectMethodHandle { |
49935 | 405 |
private final Class<?> caller; |
406 |
private Special(MethodType mtype, LambdaForm form, MemberName member, Class<?> caller) { |
|
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
407 |
super(mtype, form, member); |
49935 | 408 |
this.caller = caller; |
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
409 |
} |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
410 |
@Override |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
411 |
boolean isInvokeSpecial() { |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
412 |
return true; |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
413 |
} |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
414 |
@Override |
26470
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
415 |
MethodHandle copyWith(MethodType mt, LambdaForm lf) { |
49935 | 416 |
return new Special(mt, lf, member, caller); |
417 |
} |
|
418 |
Object checkReceiver(Object recv) { |
|
419 |
if (!caller.isInstance(recv)) { |
|
420 |
String msg = String.format("Receiver class %s is not a subclass of caller class %s", |
|
421 |
recv.getClass().getName(), caller.getName()); |
|
422 |
throw new IncompatibleClassChangeError(msg); |
|
423 |
} |
|
424 |
return recv; |
|
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
425 |
} |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
426 |
} |
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
427 |
|
48557 | 428 |
/** This subclass represents invokeinterface instructions. */ |
429 |
static class Interface extends DirectMethodHandle { |
|
430 |
private final Class<?> refc; |
|
431 |
private Interface(MethodType mtype, LambdaForm form, MemberName member, Class<?> refc) { |
|
432 |
super(mtype, form, member); |
|
433 |
assert refc.isInterface() : refc; |
|
434 |
this.refc = refc; |
|
435 |
} |
|
436 |
@Override |
|
437 |
MethodHandle copyWith(MethodType mt, LambdaForm lf) { |
|
438 |
return new Interface(mt, lf, member, refc); |
|
439 |
} |
|
49935 | 440 |
@Override |
48557 | 441 |
Object checkReceiver(Object recv) { |
442 |
if (!refc.isInstance(recv)) { |
|
49935 | 443 |
String msg = String.format("Receiver class %s does not implement the requested interface %s", |
444 |
recv.getClass().getName(), refc.getName()); |
|
48557 | 445 |
throw new IncompatibleClassChangeError(msg); |
446 |
} |
|
447 |
return recv; |
|
448 |
} |
|
449 |
} |
|
450 |
||
49935 | 451 |
/** Used for interface receiver type checks, by Interface and Special modes. */ |
452 |
Object checkReceiver(Object recv) { |
|
453 |
throw new InternalError("Should only be invoked on a subclass"); |
|
454 |
} |
|
455 |
||
456 |
||
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
457 |
/** This subclass handles constructor references. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
458 |
static class Constructor extends DirectMethodHandle { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
459 |
final MemberName initMethod; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
460 |
final Class<?> instanceClass; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
461 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
462 |
private Constructor(MethodType mtype, LambdaForm form, MemberName constructor, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
463 |
MemberName initMethod, Class<?> instanceClass) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
464 |
super(mtype, form, constructor); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
465 |
this.initMethod = initMethod; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
466 |
this.instanceClass = instanceClass; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
467 |
assert(initMethod.isResolved()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
468 |
} |
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
469 |
@Override |
26470
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
470 |
MethodHandle copyWith(MethodType mt, LambdaForm lf) { |
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
471 |
return new Constructor(mt, lf, member, initMethod, instanceClass); |
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
472 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
473 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
474 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
475 |
/*non-public*/ static Object constructorMethod(Object mh) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
476 |
Constructor dmh = (Constructor)mh; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
477 |
return dmh.initMethod; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
478 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
479 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
480 |
/*non-public*/ static Object allocateInstance(Object mh) throws InstantiationException { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
481 |
Constructor dmh = (Constructor)mh; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
482 |
return UNSAFE.allocateInstance(dmh.instanceClass); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
483 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
484 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
485 |
/** This subclass handles non-static field references. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
486 |
static class Accessor extends DirectMethodHandle { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
487 |
final Class<?> fieldType; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
488 |
final int fieldOffset; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
489 |
private Accessor(MethodType mtype, LambdaForm form, MemberName member, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
490 |
int fieldOffset) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
491 |
super(mtype, form, member); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
492 |
this.fieldType = member.getFieldType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
493 |
this.fieldOffset = fieldOffset; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
494 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
495 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
496 |
@Override Object checkCast(Object obj) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
497 |
return fieldType.cast(obj); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
498 |
} |
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
499 |
@Override |
26470
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
500 |
MethodHandle copyWith(MethodType mt, LambdaForm lf) { |
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
501 |
return new Accessor(mt, lf, member, fieldOffset); |
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
502 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
503 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
504 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
505 |
@ForceInline |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
506 |
/*non-public*/ static long fieldOffset(Object accessorObj) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
507 |
// Note: We return a long because that is what Unsafe.getObject likes. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
508 |
// We store a plain int because it is more compact. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
509 |
return ((Accessor)accessorObj).fieldOffset; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
510 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
511 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
512 |
@ForceInline |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
513 |
/*non-public*/ static Object checkBase(Object obj) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
514 |
// Note that the object's class has already been verified, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
515 |
// since the parameter type of the Accessor method handle |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
516 |
// is either member.getDeclaringClass or a subclass. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
517 |
// This was verified in DirectMethodHandle.make. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
518 |
// Therefore, the only remaining check is for null. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
519 |
// Since this check is *not* guaranteed by Unsafe.getInt |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
520 |
// and its siblings, we need to make an explicit one here. |
29094
a4fd2b5e49f8
8073479: Replace obj.getClass hacks with Objects.requireNonNull
shade
parents:
29020
diff
changeset
|
521 |
return Objects.requireNonNull(obj); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
522 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
523 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
524 |
/** This subclass handles static field references. */ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
525 |
static class StaticAccessor extends DirectMethodHandle { |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30340
diff
changeset
|
526 |
private final Class<?> fieldType; |
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30340
diff
changeset
|
527 |
private final Object staticBase; |
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30340
diff
changeset
|
528 |
private final long staticOffset; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
529 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
530 |
private StaticAccessor(MethodType mtype, LambdaForm form, MemberName member, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
531 |
Object staticBase, long staticOffset) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
532 |
super(mtype, form, member); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
533 |
this.fieldType = member.getFieldType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
534 |
this.staticBase = staticBase; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
535 |
this.staticOffset = staticOffset; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
536 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
537 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
538 |
@Override Object checkCast(Object obj) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
539 |
return fieldType.cast(obj); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
540 |
} |
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
541 |
@Override |
26470
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
542 |
MethodHandle copyWith(MethodType mt, LambdaForm lf) { |
1586df597397
8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents:
26469
diff
changeset
|
543 |
return new StaticAccessor(mt, lf, member, staticBase, staticOffset); |
16030
265a0d86c9ff
7087570: java.lang.invoke.MemberName information wrong for method handles created with findConstructor
kmo
parents:
14342
diff
changeset
|
544 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
545 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
546 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
547 |
@ForceInline |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
548 |
/*non-public*/ static Object nullCheck(Object obj) { |
29094
a4fd2b5e49f8
8073479: Replace obj.getClass hacks with Objects.requireNonNull
shade
parents:
29020
diff
changeset
|
549 |
return Objects.requireNonNull(obj); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
550 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
551 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
552 |
@ForceInline |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
553 |
/*non-public*/ static Object staticBase(Object accessorObj) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
554 |
return ((StaticAccessor)accessorObj).staticBase; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
555 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
556 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
557 |
@ForceInline |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
558 |
/*non-public*/ static long staticOffset(Object accessorObj) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
559 |
return ((StaticAccessor)accessorObj).staticOffset; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
560 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
561 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
562 |
@ForceInline |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
563 |
/*non-public*/ static Object checkCast(Object mh, Object obj) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
564 |
return ((DirectMethodHandle) mh).checkCast(obj); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
565 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
566 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
567 |
Object checkCast(Object obj) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
568 |
return member.getReturnType().cast(obj); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
569 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
570 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
571 |
// Caching machinery for field accessors: |
40542
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
572 |
static final byte |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
573 |
AF_GETFIELD = 0, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
574 |
AF_PUTFIELD = 1, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
575 |
AF_GETSTATIC = 2, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
576 |
AF_PUTSTATIC = 3, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
577 |
AF_GETSTATIC_INIT = 4, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
578 |
AF_PUTSTATIC_INIT = 5, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
579 |
AF_LIMIT = 6; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
580 |
// Enumerate the different field kinds using Wrapper, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
581 |
// with an extra case added for checked references. |
40542
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
582 |
static final int |
40256
c5e03eaf7ba2
8163370: Reduce number of classes loaded by common usage of java.lang.invoke
redestad
parents:
40212
diff
changeset
|
583 |
FT_LAST_WRAPPER = Wrapper.COUNT-1, |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
584 |
FT_UNCHECKED_REF = Wrapper.OBJECT.ordinal(), |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
585 |
FT_CHECKED_REF = FT_LAST_WRAPPER+1, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
586 |
FT_LIMIT = FT_LAST_WRAPPER+2; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
587 |
private static int afIndex(byte formOp, boolean isVolatile, int ftypeKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
588 |
return ((formOp * FT_LIMIT * 2) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
589 |
+ (isVolatile ? FT_LIMIT : 0) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
590 |
+ ftypeKind); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
591 |
} |
40211
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
592 |
@Stable |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
593 |
private static final LambdaForm[] ACCESSOR_FORMS |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
594 |
= new LambdaForm[afIndex(AF_LIMIT, false, 0)]; |
40542
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
595 |
static int ftypeKind(Class<?> ftype) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
596 |
if (ftype.isPrimitive()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
597 |
return Wrapper.forPrimitiveType(ftype).ordinal(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
598 |
else if (VerifyType.isNullReferenceConversion(Object.class, ftype)) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
599 |
return FT_UNCHECKED_REF; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
600 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
601 |
return FT_CHECKED_REF; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
602 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
603 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
604 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
605 |
* Create a LF which can access the given field. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
606 |
* Cache and share this structure among all fields with |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
607 |
* the same basicType and refKind. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
608 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
609 |
private static LambdaForm preparedFieldLambdaForm(MemberName m) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
610 |
Class<?> ftype = m.getFieldType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
611 |
boolean isVolatile = m.isVolatile(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
612 |
byte formOp; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
613 |
switch (m.getReferenceKind()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
614 |
case REF_getField: formOp = AF_GETFIELD; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
615 |
case REF_putField: formOp = AF_PUTFIELD; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
616 |
case REF_getStatic: formOp = AF_GETSTATIC; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
617 |
case REF_putStatic: formOp = AF_PUTSTATIC; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
618 |
default: throw new InternalError(m.toString()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
619 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
620 |
if (shouldBeInitialized(m)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
621 |
// precompute the barrier-free version: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
622 |
preparedFieldLambdaForm(formOp, isVolatile, ftype); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
623 |
assert((AF_GETSTATIC_INIT - AF_GETSTATIC) == |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
624 |
(AF_PUTSTATIC_INIT - AF_PUTSTATIC)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
625 |
formOp += (AF_GETSTATIC_INIT - AF_GETSTATIC); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
626 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
627 |
LambdaForm lform = preparedFieldLambdaForm(formOp, isVolatile, ftype); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
628 |
maybeCompile(lform, m); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
629 |
assert(lform.methodType().dropParameterTypes(0, 1) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
630 |
.equals(m.getInvocationType().basicType())) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
631 |
: Arrays.asList(m, m.getInvocationType().basicType(), lform, lform.methodType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
632 |
return lform; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
633 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
634 |
private static LambdaForm preparedFieldLambdaForm(byte formOp, boolean isVolatile, Class<?> ftype) { |
40211
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
635 |
int ftypeKind = ftypeKind(ftype); |
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
636 |
int afIndex = afIndex(formOp, isVolatile, ftypeKind); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
637 |
LambdaForm lform = ACCESSOR_FORMS[afIndex]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
638 |
if (lform != null) return lform; |
40211
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
639 |
lform = makePreparedFieldLambdaForm(formOp, isVolatile, ftypeKind); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
640 |
ACCESSOR_FORMS[afIndex] = lform; // don't bother with a CAS |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
641 |
return lform; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
642 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
643 |
|
40272
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40258
diff
changeset
|
644 |
private static final Wrapper[] ALL_WRAPPERS = Wrapper.values(); |
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40258
diff
changeset
|
645 |
|
40542
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
646 |
private static Kind getFieldKind(boolean isGetter, boolean isVolatile, Wrapper wrapper) { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
647 |
if (isGetter) { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
648 |
if (isVolatile) { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
649 |
switch (wrapper) { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
650 |
case BOOLEAN: return GET_BOOLEAN_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
651 |
case BYTE: return GET_BYTE_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
652 |
case SHORT: return GET_SHORT_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
653 |
case CHAR: return GET_CHAR_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
654 |
case INT: return GET_INT_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
655 |
case LONG: return GET_LONG_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
656 |
case FLOAT: return GET_FLOAT_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
657 |
case DOUBLE: return GET_DOUBLE_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
658 |
case OBJECT: return GET_OBJECT_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
659 |
} |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
660 |
} else { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
661 |
switch (wrapper) { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
662 |
case BOOLEAN: return GET_BOOLEAN; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
663 |
case BYTE: return GET_BYTE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
664 |
case SHORT: return GET_SHORT; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
665 |
case CHAR: return GET_CHAR; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
666 |
case INT: return GET_INT; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
667 |
case LONG: return GET_LONG; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
668 |
case FLOAT: return GET_FLOAT; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
669 |
case DOUBLE: return GET_DOUBLE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
670 |
case OBJECT: return GET_OBJECT; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
671 |
} |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
672 |
} |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
673 |
} else { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
674 |
if (isVolatile) { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
675 |
switch (wrapper) { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
676 |
case BOOLEAN: return PUT_BOOLEAN_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
677 |
case BYTE: return PUT_BYTE_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
678 |
case SHORT: return PUT_SHORT_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
679 |
case CHAR: return PUT_CHAR_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
680 |
case INT: return PUT_INT_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
681 |
case LONG: return PUT_LONG_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
682 |
case FLOAT: return PUT_FLOAT_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
683 |
case DOUBLE: return PUT_DOUBLE_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
684 |
case OBJECT: return PUT_OBJECT_VOLATILE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
685 |
} |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
686 |
} else { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
687 |
switch (wrapper) { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
688 |
case BOOLEAN: return PUT_BOOLEAN; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
689 |
case BYTE: return PUT_BYTE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
690 |
case SHORT: return PUT_SHORT; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
691 |
case CHAR: return PUT_CHAR; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
692 |
case INT: return PUT_INT; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
693 |
case LONG: return PUT_LONG; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
694 |
case FLOAT: return PUT_FLOAT; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
695 |
case DOUBLE: return PUT_DOUBLE; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
696 |
case OBJECT: return PUT_OBJECT; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
697 |
} |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
698 |
} |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
699 |
} |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
700 |
throw new AssertionError("Invalid arguments"); |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
701 |
} |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
702 |
|
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
703 |
static LambdaForm makePreparedFieldLambdaForm(byte formOp, boolean isVolatile, int ftypeKind) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
704 |
boolean isGetter = (formOp & 1) == (AF_GETFIELD & 1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
705 |
boolean isStatic = (formOp >= AF_GETSTATIC); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
706 |
boolean needsInit = (formOp >= AF_GETSTATIC_INIT); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
707 |
boolean needsCast = (ftypeKind == FT_CHECKED_REF); |
40272
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40258
diff
changeset
|
708 |
Wrapper fw = (needsCast ? Wrapper.OBJECT : ALL_WRAPPERS[ftypeKind]); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
709 |
Class<?> ft = fw.primitiveType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
710 |
assert(ftypeKind(needsCast ? String.class : ft) == ftypeKind); |
40272
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40258
diff
changeset
|
711 |
|
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40258
diff
changeset
|
712 |
// getObject, putIntVolatile, etc. |
40542
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
713 |
Kind kind = getFieldKind(isGetter, isVolatile, fw); |
40272
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40258
diff
changeset
|
714 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
715 |
MethodType linkerType; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
716 |
if (isGetter) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
717 |
linkerType = MethodType.methodType(ft, Object.class, long.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
718 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
719 |
linkerType = MethodType.methodType(void.class, Object.class, long.class, ft); |
40542
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
720 |
MemberName linker = new MemberName(Unsafe.class, kind.methodName, linkerType, REF_invokeVirtual); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
721 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
722 |
linker = IMPL_NAMES.resolveOrFail(REF_invokeVirtual, linker, null, NoSuchMethodException.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
723 |
} catch (ReflectiveOperationException ex) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
724 |
throw newInternalError(ex); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
725 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
726 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
727 |
// What is the external type of the lambda form? |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
728 |
MethodType mtype; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
729 |
if (isGetter) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
730 |
mtype = MethodType.methodType(ft); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
731 |
else |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
732 |
mtype = MethodType.methodType(void.class, ft); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
733 |
mtype = mtype.basicType(); // erase short to int, etc. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
734 |
if (!isStatic) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
735 |
mtype = mtype.insertParameterTypes(0, Object.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
736 |
final int DMH_THIS = 0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
737 |
final int ARG_BASE = 1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
738 |
final int ARG_LIMIT = ARG_BASE + mtype.parameterCount(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
739 |
// if this is for non-static access, the base pointer is stored at this index: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
740 |
final int OBJ_BASE = isStatic ? -1 : ARG_BASE; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
741 |
// if this is for write access, the value to be written is stored at this index: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
742 |
final int SET_VALUE = isGetter ? -1 : ARG_LIMIT - 1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
743 |
int nameCursor = ARG_LIMIT; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
744 |
final int F_HOLDER = (isStatic ? nameCursor++ : -1); // static base if any |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
745 |
final int F_OFFSET = nameCursor++; // Either static offset or field offset. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
746 |
final int OBJ_CHECK = (OBJ_BASE >= 0 ? nameCursor++ : -1); |
40542
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
747 |
final int U_HOLDER = nameCursor++; // UNSAFE holder |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
748 |
final int INIT_BAR = (needsInit ? nameCursor++ : -1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
749 |
final int PRE_CAST = (needsCast && !isGetter ? nameCursor++ : -1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
750 |
final int LINKER_CALL = nameCursor++; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
751 |
final int POST_CAST = (needsCast && isGetter ? nameCursor++ : -1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
752 |
final int RESULT = nameCursor-1; // either the call or the cast |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
753 |
Name[] names = arguments(nameCursor - ARG_LIMIT, mtype.invokerType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
754 |
if (needsInit) |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
755 |
names[INIT_BAR] = new Name(getFunction(NF_ensureInitialized), names[DMH_THIS]); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
756 |
if (needsCast && !isGetter) |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
757 |
names[PRE_CAST] = new Name(getFunction(NF_checkCast), names[DMH_THIS], names[SET_VALUE]); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
758 |
Object[] outArgs = new Object[1 + linkerType.parameterCount()]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
759 |
assert(outArgs.length == (isGetter ? 3 : 4)); |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
760 |
outArgs[0] = names[U_HOLDER] = new Name(getFunction(NF_UNSAFE)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
761 |
if (isStatic) { |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
762 |
outArgs[1] = names[F_HOLDER] = new Name(getFunction(NF_staticBase), names[DMH_THIS]); |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
763 |
outArgs[2] = names[F_OFFSET] = new Name(getFunction(NF_staticOffset), names[DMH_THIS]); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
764 |
} else { |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
765 |
outArgs[1] = names[OBJ_CHECK] = new Name(getFunction(NF_checkBase), names[OBJ_BASE]); |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
766 |
outArgs[2] = names[F_OFFSET] = new Name(getFunction(NF_fieldOffset), names[DMH_THIS]); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
767 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
768 |
if (!isGetter) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
769 |
outArgs[3] = (needsCast ? names[PRE_CAST] : names[SET_VALUE]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
770 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
771 |
for (Object a : outArgs) assert(a != null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
772 |
names[LINKER_CALL] = new Name(linker, outArgs); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
773 |
if (needsCast && isGetter) |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
774 |
names[POST_CAST] = new Name(getFunction(NF_checkCast), names[DMH_THIS], names[LINKER_CALL]); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
775 |
for (Name n : names) assert(n != null); |
43893 | 776 |
|
777 |
LambdaForm form; |
|
40542
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
778 |
if (needsCast || needsInit) { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
779 |
// can't use the pre-generated form when casting and/or initializing |
43893 | 780 |
form = new LambdaForm(ARG_LIMIT, names, RESULT); |
40542
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
781 |
} else { |
43893 | 782 |
form = new LambdaForm(ARG_LIMIT, names, RESULT, kind); |
40542
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40408
diff
changeset
|
783 |
} |
43893 | 784 |
|
785 |
if (LambdaForm.debugNames()) { |
|
786 |
// add some detail to the lambdaForm debugname, |
|
787 |
// significant only for debugging |
|
788 |
StringBuilder nameBuilder = new StringBuilder(kind.methodName); |
|
789 |
if (isStatic) { |
|
790 |
nameBuilder.append("Static"); |
|
791 |
} else { |
|
792 |
nameBuilder.append("Field"); |
|
793 |
} |
|
794 |
if (needsCast) { |
|
795 |
nameBuilder.append("Cast"); |
|
796 |
} |
|
797 |
if (needsInit) { |
|
798 |
nameBuilder.append("Init"); |
|
799 |
} |
|
800 |
LambdaForm.associateWithDebugName(form, nameBuilder.toString()); |
|
801 |
} |
|
802 |
return form; |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
803 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
804 |
|
20495
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
16484
diff
changeset
|
805 |
/** |
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
16484
diff
changeset
|
806 |
* Pre-initialized NamedFunctions for bootstrapping purposes. |
6586c2f78d57
8024616: JSR292: lazily initialize core NamedFunctions used for bootstrapping
vlivanov
parents:
16484
diff
changeset
|
807 |
*/ |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
808 |
static final byte NF_internalMemberName = 0, |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
809 |
NF_internalMemberNameEnsureInit = 1, |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
810 |
NF_ensureInitialized = 2, |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
811 |
NF_fieldOffset = 3, |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
812 |
NF_checkBase = 4, |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
813 |
NF_staticBase = 5, |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
814 |
NF_staticOffset = 6, |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
815 |
NF_checkCast = 7, |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
816 |
NF_allocateInstance = 8, |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
817 |
NF_constructorMethod = 9, |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
818 |
NF_UNSAFE = 10, |
48557 | 819 |
NF_checkReceiver = 11, |
820 |
NF_LIMIT = 12; |
|
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
821 |
|
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
822 |
private static final @Stable NamedFunction[] NFS = new NamedFunction[NF_LIMIT]; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
823 |
|
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
824 |
private static NamedFunction getFunction(byte func) { |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
825 |
NamedFunction nf = NFS[func]; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
826 |
if (nf != null) { |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
827 |
return nf; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
828 |
} |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
829 |
// Each nf must be statically invocable or we get tied up in our bootstraps. |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
830 |
nf = NFS[func] = createFunction(func); |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
831 |
assert(InvokerBytecodeGenerator.isStaticallyInvocable(nf)); |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
832 |
return nf; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
833 |
} |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
834 |
|
47280
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
835 |
private static final MethodType OBJ_OBJ_TYPE = MethodType.methodType(Object.class, Object.class); |
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
836 |
|
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
837 |
private static final MethodType LONG_OBJ_TYPE = MethodType.methodType(long.class, Object.class); |
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
838 |
|
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
839 |
private static NamedFunction createFunction(byte func) { |
33841
1d1d1ea6a5f2
8142334: Improve lazy initialization of java.lang.invoke
redestad
parents:
33674
diff
changeset
|
840 |
try { |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
841 |
switch (func) { |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
842 |
case NF_internalMemberName: |
47280
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
843 |
return getNamedFunction("internalMemberName", OBJ_OBJ_TYPE); |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
844 |
case NF_internalMemberNameEnsureInit: |
47280
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
845 |
return getNamedFunction("internalMemberNameEnsureInit", OBJ_OBJ_TYPE); |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
846 |
case NF_ensureInitialized: |
47280
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
847 |
return getNamedFunction("ensureInitialized", MethodType.methodType(void.class, Object.class)); |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
848 |
case NF_fieldOffset: |
47280
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
849 |
return getNamedFunction("fieldOffset", LONG_OBJ_TYPE); |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
850 |
case NF_checkBase: |
47280
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
851 |
return getNamedFunction("checkBase", OBJ_OBJ_TYPE); |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
852 |
case NF_staticBase: |
47280
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
853 |
return getNamedFunction("staticBase", OBJ_OBJ_TYPE); |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
854 |
case NF_staticOffset: |
47280
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
855 |
return getNamedFunction("staticOffset", LONG_OBJ_TYPE); |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
856 |
case NF_checkCast: |
47280
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
857 |
return getNamedFunction("checkCast", MethodType.methodType(Object.class, Object.class, Object.class)); |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
858 |
case NF_allocateInstance: |
47280
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
859 |
return getNamedFunction("allocateInstance", OBJ_OBJ_TYPE); |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
860 |
case NF_constructorMethod: |
47280
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
861 |
return getNamedFunction("constructorMethod", OBJ_OBJ_TYPE); |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
862 |
case NF_UNSAFE: |
47280
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
863 |
MemberName member = new MemberName(MethodHandleStatics.class, "UNSAFE", Unsafe.class, REF_getField); |
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
864 |
return new NamedFunction( |
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
865 |
MemberName.getFactory() |
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
866 |
.resolveOrFail(REF_getField, member, DirectMethodHandle.class, NoSuchMethodException.class)); |
48557 | 867 |
case NF_checkReceiver: |
49935 | 868 |
member = new MemberName(DirectMethodHandle.class, "checkReceiver", OBJ_OBJ_TYPE, REF_invokeVirtual); |
48557 | 869 |
return new NamedFunction( |
870 |
MemberName.getFactory() |
|
49935 | 871 |
.resolveOrFail(REF_invokeVirtual, member, DirectMethodHandle.class, NoSuchMethodException.class)); |
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
872 |
default: |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
873 |
throw newInternalError("Unknown function: " + func); |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
43893
diff
changeset
|
874 |
} |
33841
1d1d1ea6a5f2
8142334: Improve lazy initialization of java.lang.invoke
redestad
parents:
33674
diff
changeset
|
875 |
} catch (ReflectiveOperationException ex) { |
1d1d1ea6a5f2
8142334: Improve lazy initialization of java.lang.invoke
redestad
parents:
33674
diff
changeset
|
876 |
throw newInternalError(ex); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8822
diff
changeset
|
877 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
878 |
} |
40211
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
879 |
|
47280
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
880 |
private static NamedFunction getNamedFunction(String name, MethodType type) |
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
881 |
throws ReflectiveOperationException |
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
882 |
{ |
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
883 |
MemberName member = new MemberName(DirectMethodHandle.class, name, type, REF_invokeStatic); |
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
884 |
return new NamedFunction( |
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
885 |
MemberName.getFactory() |
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
886 |
.resolveOrFail(REF_invokeStatic, member, DirectMethodHandle.class, NoSuchMethodException.class)); |
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
887 |
} |
95192765a858
8187826: Avoid using reflection to bootstrap NamedFunctions
redestad
parents:
47216
diff
changeset
|
888 |
|
40211
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
889 |
static { |
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
890 |
// The Holder class will contain pre-generated DirectMethodHandles resolved |
40211
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
891 |
// speculatively using MemberName.getFactory().resolveOrNull. However, that |
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
892 |
// doesn't initialize the class, which subtly breaks inlining etc. By forcing |
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
893 |
// initialization of the Holder class we avoid these issues. |
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
894 |
UNSAFE.ensureClassInitialized(Holder.class); |
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
895 |
} |
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
896 |
|
8b78c9b31244
8163369: Enable generating DMH classes at link time
redestad
parents:
39754
diff
changeset
|
897 |
/* Placeholder class for DirectMethodHandles generated ahead of time */ |
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
898 |
final class Holder {} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
899 |
} |