author | redestad |
Tue, 11 Apr 2017 18:57:46 +0200 | |
changeset 44591 | b9bf065070fe |
parent 44590 | 15a77e5b7612 |
permissions | -rw-r--r-- |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1 |
/* |
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
2 |
* Copyright (c) 2008, 2016, 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 |
|
36757
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
28 |
import jdk.internal.loader.BootLoader; |
35252
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
33646
diff
changeset
|
29 |
import jdk.internal.org.objectweb.asm.ClassWriter; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
33646
diff
changeset
|
30 |
import jdk.internal.org.objectweb.asm.FieldVisitor; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
33646
diff
changeset
|
31 |
import jdk.internal.org.objectweb.asm.MethodVisitor; |
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
32 |
import jdk.internal.vm.annotation.Stable; |
35252
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
33646
diff
changeset
|
33 |
import sun.invoke.util.ValueConversions; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
33646
diff
changeset
|
34 |
import sun.invoke.util.Wrapper; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
35 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
36 |
import java.lang.invoke.LambdaForm.NamedFunction; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
37 |
import java.lang.invoke.MethodHandles.Lookup; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
38 |
import java.lang.reflect.Field; |
35252
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
33646
diff
changeset
|
39 |
import java.util.concurrent.ConcurrentHashMap; |
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
40 |
import java.util.concurrent.ConcurrentMap; |
35252
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
33646
diff
changeset
|
41 |
import java.util.function.Function; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
42 |
|
35252
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
33646
diff
changeset
|
43 |
import static java.lang.invoke.LambdaForm.BasicType; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
33646
diff
changeset
|
44 |
import static java.lang.invoke.LambdaForm.BasicType.*; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
33646
diff
changeset
|
45 |
import static java.lang.invoke.MethodHandleStatics.*; |
754852fba784
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
33646
diff
changeset
|
46 |
import static jdk.internal.org.objectweb.asm.Opcodes.*; |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
47 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
48 |
/** |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
49 |
* The flavor of method handle which emulates an invoke instruction |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
50 |
* on a predetermined argument. The JVM dispatches to the correct method |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
51 |
* when the handle is created, not when it is invoked. |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
52 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
53 |
* All bound arguments are encapsulated in dedicated species. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
54 |
*/ |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
55 |
/*non-public*/ abstract class BoundMethodHandle extends MethodHandle { |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
56 |
|
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
57 |
/*non-public*/ BoundMethodHandle(MethodType type, LambdaForm form) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
58 |
super(type, form); |
26481
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
59 |
assert(speciesData() == speciesData(form)); |
4537 | 60 |
} |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
61 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
62 |
// |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
63 |
// BMH API and internals |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
64 |
// |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
65 |
|
26469
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
66 |
static BoundMethodHandle bindSingle(MethodType type, LambdaForm form, BasicType xtype, Object x) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
67 |
// for some type signatures, there exist pre-defined concrete BMH classes |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
68 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
69 |
switch (xtype) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
70 |
case L_TYPE: |
26469
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
71 |
return bindSingle(type, form, x); // Use known fast path. |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
72 |
case I_TYPE: |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
73 |
return (BoundMethodHandle) SpeciesData.EMPTY.extendWith(I_TYPE).constructor().invokeBasic(type, form, ValueConversions.widenSubword(x)); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
74 |
case J_TYPE: |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
75 |
return (BoundMethodHandle) SpeciesData.EMPTY.extendWith(J_TYPE).constructor().invokeBasic(type, form, (long) x); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
76 |
case F_TYPE: |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
77 |
return (BoundMethodHandle) SpeciesData.EMPTY.extendWith(F_TYPE).constructor().invokeBasic(type, form, (float) x); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
78 |
case D_TYPE: |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
79 |
return (BoundMethodHandle) SpeciesData.EMPTY.extendWith(D_TYPE).constructor().invokeBasic(type, form, (double) x); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
80 |
default : throw newInternalError("unexpected xtype: " + xtype); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
81 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
82 |
} catch (Throwable t) { |
42105
d04ede5f10e7
8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents:
41125
diff
changeset
|
83 |
throw uncaughtException(t); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
84 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
85 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
86 |
|
26481
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
87 |
/*non-public*/ |
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
88 |
LambdaFormEditor editor() { |
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
89 |
return form.editor(); |
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
90 |
} |
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
91 |
|
26469
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
92 |
static BoundMethodHandle bindSingle(MethodType type, LambdaForm form, Object x) { |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
93 |
return Species_L.make(type, form, x); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
94 |
} |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
95 |
|
26469
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
96 |
@Override // there is a default binder in the super class, for 'L' types only |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
97 |
/*non-public*/ |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
98 |
BoundMethodHandle bindArgumentL(int pos, Object value) { |
26481
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
99 |
return editor().bindArgumentL(this, pos, value); |
26469
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
100 |
} |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
101 |
/*non-public*/ |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
102 |
BoundMethodHandle bindArgumentI(int pos, int value) { |
26481
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
103 |
return editor().bindArgumentI(this, pos, value); |
26469
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
104 |
} |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
105 |
/*non-public*/ |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
106 |
BoundMethodHandle bindArgumentJ(int pos, long value) { |
26481
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
107 |
return editor().bindArgumentJ(this, pos, value); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
108 |
} |
26469
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
109 |
/*non-public*/ |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
110 |
BoundMethodHandle bindArgumentF(int pos, float value) { |
26481
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
111 |
return editor().bindArgumentF(this, pos, value); |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
112 |
} |
26469
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
113 |
/*non-public*/ |
e6bc14fae1cf
8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents:
26467
diff
changeset
|
114 |
BoundMethodHandle bindArgumentD(int pos, double value) { |
26481
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
115 |
return editor().bindArgumentD(this, pos, value); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
116 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
117 |
|
26472
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
118 |
@Override |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
119 |
BoundMethodHandle rebind() { |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
120 |
if (!tooComplex()) { |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
121 |
return this; |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
122 |
} |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
123 |
return makeReinvoker(this); |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
124 |
} |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
125 |
|
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
126 |
private boolean tooComplex() { |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
127 |
return (fieldCount() > FIELD_COUNT_THRESHOLD || |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
128 |
form.expressionCount() > FORM_EXPRESSION_THRESHOLD); |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
129 |
} |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
130 |
private static final int FIELD_COUNT_THRESHOLD = 12; // largest convenient BMH field count |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
131 |
private static final int FORM_EXPRESSION_THRESHOLD = 24; // largest convenient BMH expression count |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
132 |
|
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
133 |
/** |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
134 |
* A reinvoker MH has this form: |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
135 |
* {@code lambda (bmh, arg*) { thismh = bmh[0]; invokeBasic(thismh, arg*) }} |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
136 |
*/ |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
137 |
static BoundMethodHandle makeReinvoker(MethodHandle target) { |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
138 |
LambdaForm form = DelegatingMethodHandle.makeReinvokerForm( |
26479
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26472
diff
changeset
|
139 |
target, MethodTypeForm.LF_REBIND, |
a60a19ec5ce5
8057657: Annotate LambdaForm parameters with types
vlivanov
parents:
26472
diff
changeset
|
140 |
Species_L.SPECIES_DATA, Species_L.SPECIES_DATA.getterFunction(0)); |
26472
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
141 |
return Species_L.make(target.type(), form, target); |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
142 |
} |
71b6a6f208c0
8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents:
26469
diff
changeset
|
143 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
144 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
145 |
* Return the {@link SpeciesData} instance representing this BMH species. All subclasses must provide a |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
146 |
* static field containing this value, and they must accordingly implement this method. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
147 |
*/ |
23918 | 148 |
/*non-public*/ abstract SpeciesData speciesData(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
149 |
|
26481
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
150 |
/*non-public*/ static SpeciesData speciesData(LambdaForm form) { |
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
151 |
Object c = form.names[0].constraint; |
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
152 |
if (c instanceof SpeciesData) |
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
153 |
return (SpeciesData) c; |
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
154 |
// if there is no BMH constraint, then use the null constraint |
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
155 |
return SpeciesData.EMPTY; |
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
156 |
} |
c5b74a88a3c0
8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents:
26479
diff
changeset
|
157 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
158 |
/** |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
159 |
* Return the number of fields in this BMH. Equivalent to speciesData().fieldCount(). |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
160 |
*/ |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
161 |
/*non-public*/ abstract int fieldCount(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
162 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
163 |
@Override |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
164 |
Object internalProperties() { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
165 |
return "\n& BMH="+internalValues(); |
13610
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13424
diff
changeset
|
166 |
} |
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13424
diff
changeset
|
167 |
|
28122b96858e
7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents:
13424
diff
changeset
|
168 |
@Override |
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
169 |
final String internalValues() { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
170 |
int count = speciesData().fieldCount(); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
171 |
if (count == 1) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
172 |
return "[" + arg(0) + "]"; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
173 |
} |
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
174 |
StringBuilder sb = new StringBuilder("["); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
175 |
for (int i = 0; i < count; ++i) { |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
176 |
sb.append("\n ").append(i).append(": ( ").append(arg(i)).append(" )"); |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
177 |
} |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
178 |
return sb.append("\n]").toString(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
179 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
180 |
|
23918 | 181 |
/*non-public*/ final Object arg(int i) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
182 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
183 |
switch (speciesData().fieldType(i)) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
184 |
case L_TYPE: return speciesData().getters[i].invokeBasic(this); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
185 |
case I_TYPE: return (int) speciesData().getters[i].invokeBasic(this); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
186 |
case J_TYPE: return (long) speciesData().getters[i].invokeBasic(this); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
187 |
case F_TYPE: return (float) speciesData().getters[i].invokeBasic(this); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
188 |
case D_TYPE: return (double) speciesData().getters[i].invokeBasic(this); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
189 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
190 |
} catch (Throwable ex) { |
42105
d04ede5f10e7
8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents:
41125
diff
changeset
|
191 |
throw uncaughtException(ex); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
192 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
193 |
throw new InternalError("unexpected type: " + speciesData().typeChars+"."+i); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
194 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
195 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
196 |
// |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
197 |
// cloning API |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
198 |
// |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
199 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
200 |
/*non-public*/ abstract BoundMethodHandle copyWith(MethodType mt, LambdaForm lf); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
201 |
/*non-public*/ abstract BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
202 |
/*non-public*/ abstract BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
203 |
/*non-public*/ abstract BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
204 |
/*non-public*/ abstract BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
205 |
/*non-public*/ abstract BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
206 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
207 |
// |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
208 |
// concrete BMH classes required to close bootstrap loops |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
209 |
// |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
210 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
211 |
private // make it private to force users to access the enclosing class first |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
212 |
static final class Species_L extends BoundMethodHandle { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
213 |
final Object argL0; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
214 |
private Species_L(MethodType mt, LambdaForm lf, Object argL0) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
215 |
super(mt, lf); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
216 |
this.argL0 = argL0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
217 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
218 |
@Override |
23918 | 219 |
/*non-public*/ SpeciesData speciesData() { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
220 |
return SPECIES_DATA; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
221 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
222 |
@Override |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
223 |
/*non-public*/ int fieldCount() { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
224 |
return 1; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
225 |
} |
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
226 |
/*non-public*/ static final SpeciesData SPECIES_DATA = new SpeciesData("L", Species_L.class); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
227 |
/*non-public*/ static BoundMethodHandle make(MethodType mt, LambdaForm lf, Object argL0) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
228 |
return new Species_L(mt, lf, argL0); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
229 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
230 |
@Override |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
231 |
/*non-public*/ final BoundMethodHandle copyWith(MethodType mt, LambdaForm lf) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
232 |
return new Species_L(mt, lf, argL0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
233 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
234 |
@Override |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
235 |
/*non-public*/ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
236 |
try { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
237 |
return (BoundMethodHandle) SPECIES_DATA.extendWith(L_TYPE).constructor().invokeBasic(mt, lf, argL0, narg); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
238 |
} catch (Throwable ex) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
239 |
throw uncaughtException(ex); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
240 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
241 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
242 |
@Override |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
243 |
/*non-public*/ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
244 |
try { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
245 |
return (BoundMethodHandle) SPECIES_DATA.extendWith(I_TYPE).constructor().invokeBasic(mt, lf, argL0, narg); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
246 |
} catch (Throwable ex) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
247 |
throw uncaughtException(ex); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
248 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
249 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
250 |
@Override |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
251 |
/*non-public*/ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
252 |
try { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
253 |
return (BoundMethodHandle) SPECIES_DATA.extendWith(J_TYPE).constructor().invokeBasic(mt, lf, argL0, narg); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
254 |
} catch (Throwable ex) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
255 |
throw uncaughtException(ex); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
256 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
257 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
258 |
@Override |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
259 |
/*non-public*/ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
260 |
try { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
261 |
return (BoundMethodHandle) SPECIES_DATA.extendWith(F_TYPE).constructor().invokeBasic(mt, lf, argL0, narg); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
262 |
} catch (Throwable ex) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
263 |
throw uncaughtException(ex); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
264 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
265 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
266 |
@Override |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
267 |
/*non-public*/ final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
268 |
try { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
269 |
return (BoundMethodHandle) SPECIES_DATA.extendWith(D_TYPE).constructor().invokeBasic(mt, lf, argL0, narg); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
270 |
} catch (Throwable ex) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
271 |
throw uncaughtException(ex); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
272 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
273 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
274 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
275 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
276 |
// |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
277 |
// BMH species meta-data |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
278 |
// |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
279 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
280 |
/** |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
281 |
* Meta-data wrapper for concrete BMH types. |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
282 |
* Each BMH type corresponds to a given sequence of basic field types (LIJFD). |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
283 |
* The fields are immutable; their values are fully specified at object construction. |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
284 |
* Each BMH type supplies an array of getter functions which may be used in lambda forms. |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
285 |
* A BMH is constructed by cloning a shorter BMH and adding one or more new field values. |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
286 |
* The shortest possible BMH has zero fields; its class is SimpleMethodHandle. |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
287 |
* BMH species are not interrelated by subtyping, even though it would appear that |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
288 |
* a shorter BMH could serve as a supertype of a longer one which extends it. |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
289 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
290 |
static class SpeciesData { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
291 |
private final String typeChars; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
292 |
private final BasicType[] typeCodes; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
293 |
private final Class<? extends BoundMethodHandle> clazz; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
294 |
// Bootstrapping requires circular relations MH -> BMH -> SpeciesData -> MH |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
295 |
// Therefore, we need a non-final link in the chain. Use array elements. |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
296 |
@Stable private final MethodHandle[] constructor; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
297 |
@Stable private final MethodHandle[] getters; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
298 |
@Stable private final NamedFunction[] nominalGetters; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
299 |
@Stable private final SpeciesData[] extensions; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
300 |
|
23918 | 301 |
/*non-public*/ int fieldCount() { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
302 |
return typeCodes.length; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
303 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
304 |
/*non-public*/ BasicType fieldType(int i) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
305 |
return typeCodes[i]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
306 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
307 |
/*non-public*/ char fieldTypeChar(int i) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
308 |
return typeChars.charAt(i); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
309 |
} |
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40272
diff
changeset
|
310 |
String fieldSignature() { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
311 |
return typeChars; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
312 |
} |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
313 |
public Class<? extends BoundMethodHandle> fieldHolder() { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
314 |
return clazz; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
315 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
316 |
public String toString() { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
317 |
return "SpeciesData<"+fieldSignature()+">"; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
318 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
319 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
320 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
321 |
* Return a {@link LambdaForm.Name} containing a {@link LambdaForm.NamedFunction} that |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
322 |
* represents a MH bound to a generic invoker, which in turn forwards to the corresponding |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
323 |
* getter. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
324 |
*/ |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
16906
diff
changeset
|
325 |
NamedFunction getterFunction(int i) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
326 |
NamedFunction nf = nominalGetters[i]; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
327 |
assert(nf.memberDeclaringClassOrNull() == fieldHolder()); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
328 |
assert(nf.returnType() == fieldType(i)); |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
329 |
return nf; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
330 |
} |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
331 |
|
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
332 |
NamedFunction[] getterFunctions() { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
333 |
return nominalGetters; |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
334 |
} |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
335 |
|
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
336 |
MethodHandle[] getterHandles() { return getters; } |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
337 |
|
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
338 |
MethodHandle constructor() { |
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
339 |
return constructor[0]; |
20527
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
16906
diff
changeset
|
340 |
} |
d241258cfbcb
8024761: JSR 292 improve performance of generic invocation
jrose
parents:
16906
diff
changeset
|
341 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
342 |
static final SpeciesData EMPTY = new SpeciesData("", BoundMethodHandle.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
343 |
|
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
344 |
SpeciesData(String types, Class<? extends BoundMethodHandle> clazz) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
345 |
this.typeChars = types; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
346 |
this.typeCodes = basicTypes(types); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
347 |
this.clazz = clazz; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
348 |
if (!INIT_DONE) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
349 |
this.constructor = new MethodHandle[1]; // only one ctor |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
350 |
this.getters = new MethodHandle[types.length()]; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
351 |
this.nominalGetters = new NamedFunction[types.length()]; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
352 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
353 |
this.constructor = Factory.makeCtors(clazz, types, null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
354 |
this.getters = Factory.makeGetters(clazz, types, null); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
355 |
this.nominalGetters = Factory.makeNominalGetters(types, null, this.getters); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
356 |
} |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
357 |
this.extensions = new SpeciesData[ARG_TYPE_LIMIT]; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
358 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
359 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
360 |
private void initForBootstrap() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
361 |
assert(!INIT_DONE); |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
362 |
if (constructor() == null) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
363 |
String types = typeChars; |
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
364 |
CACHE.put(types, this); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
365 |
Factory.makeCtors(clazz, types, this.constructor); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
366 |
Factory.makeGetters(clazz, types, this.getters); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
367 |
Factory.makeNominalGetters(types, this.nominalGetters, this.getters); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
368 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
369 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
370 |
|
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
371 |
private static final ConcurrentMap<String, SpeciesData> CACHE = new ConcurrentHashMap<>(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
372 |
private static final boolean INIT_DONE; // set after <clinit> finishes... |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
373 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
374 |
SpeciesData extendWith(byte type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
375 |
return extendWith(BasicType.basicType(type)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
376 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
377 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
378 |
SpeciesData extendWith(BasicType type) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
379 |
int ord = type.ordinal(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
380 |
SpeciesData d = extensions[ord]; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
381 |
if (d != null) return d; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
382 |
extensions[ord] = d = get(typeChars+type.basicTypeChar()); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
383 |
return d; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
384 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
385 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
386 |
private static SpeciesData get(String types) { |
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
387 |
return CACHE.computeIfAbsent(types, new Function<String, SpeciesData>() { |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
388 |
@Override |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
389 |
public SpeciesData apply(String types) { |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
390 |
Class<? extends BoundMethodHandle> bmhcl = Factory.getConcreteBMHClass(types); |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
391 |
// SpeciesData instantiation may throw VirtualMachineError because of |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
392 |
// code cache overflow... |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
393 |
SpeciesData speciesData = new SpeciesData(types, bmhcl); |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
394 |
// CHM.computeIfAbsent ensures only one SpeciesData will be set |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
395 |
// successfully on the concrete BMH class if ever |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
396 |
Factory.setSpeciesDataToConcreteBMHClass(bmhcl, speciesData); |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
397 |
// the concrete BMH class is published via SpeciesData instance |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
398 |
// returned here only after it's SPECIES_DATA field is set |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
399 |
return speciesData; |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
400 |
} |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
401 |
}); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
402 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
403 |
|
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
404 |
/** |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
405 |
* This is to be called when assertions are enabled. It checks whether SpeciesData for all of the statically |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
406 |
* defined species subclasses of BoundMethodHandle has been added to the SpeciesData cache. See below in the |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
407 |
* static initializer for |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
408 |
*/ |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
409 |
static boolean speciesDataCachePopulated() { |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
410 |
Class<BoundMethodHandle> rootCls = BoundMethodHandle.class; |
42105
d04ede5f10e7
8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents:
41125
diff
changeset
|
411 |
for (Class<?> c : rootCls.getDeclaredClasses()) { |
d04ede5f10e7
8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents:
41125
diff
changeset
|
412 |
if (rootCls.isAssignableFrom(c)) { |
d04ede5f10e7
8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents:
41125
diff
changeset
|
413 |
final Class<? extends BoundMethodHandle> cbmh = c.asSubclass(BoundMethodHandle.class); |
d04ede5f10e7
8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents:
41125
diff
changeset
|
414 |
SpeciesData d = Factory.getSpeciesDataFromConcreteBMHClass(cbmh); |
d04ede5f10e7
8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents:
41125
diff
changeset
|
415 |
assert(d != null) : cbmh.getName(); |
d04ede5f10e7
8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents:
41125
diff
changeset
|
416 |
assert(d.clazz == cbmh); |
d04ede5f10e7
8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents:
41125
diff
changeset
|
417 |
assert(CACHE.get(d.typeChars) == d); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
418 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
419 |
} |
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
420 |
return true; |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
421 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
422 |
|
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
423 |
static { |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
424 |
// Pre-fill the BMH species-data cache with EMPTY and all BMH's inner subclasses. |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
425 |
EMPTY.initForBootstrap(); |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
426 |
Species_L.SPECIES_DATA.initForBootstrap(); |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
427 |
// check that all static SpeciesData instances have been initialized |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
428 |
assert speciesDataCachePopulated(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
429 |
// Note: Do not simplify this, because INIT_DONE must not be |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
430 |
// a compile-time constant during bootstrapping. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
431 |
INIT_DONE = Boolean.TRUE; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
432 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
433 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
434 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
435 |
static SpeciesData getSpeciesData(String types) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
436 |
return SpeciesData.get(types); |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
437 |
} |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
438 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
439 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
440 |
* Generation of concrete BMH classes. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
441 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
442 |
* A concrete BMH species is fit for binding a number of values adhering to a |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
443 |
* given type pattern. Reference types are erased. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
444 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
445 |
* BMH species are cached by type pattern. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
446 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
447 |
* A BMH species has a number of fields with the concrete (possibly erased) types of |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
448 |
* bound values. Setters are provided as an API in BMH. Getters are exposed as MHs, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
449 |
* which can be included as names in lambda forms. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
450 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
451 |
static class Factory { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
452 |
|
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
453 |
private static final String JLO_SIG = "Ljava/lang/Object;"; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
454 |
private static final String MH = "java/lang/invoke/MethodHandle"; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
455 |
private static final String MH_SIG = "L"+MH+";"; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
456 |
private static final String BMH = "java/lang/invoke/BoundMethodHandle"; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
457 |
private static final String BMH_NAME = "java.lang.invoke.BoundMethodHandle"; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
458 |
private static final String BMH_SIG = "L"+BMH+";"; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
459 |
private static final String SPECIES_DATA = "java/lang/invoke/BoundMethodHandle$SpeciesData"; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
460 |
private static final String SPECIES_DATA_SIG = "L"+SPECIES_DATA+";"; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
461 |
private static final String STABLE_SIG = "Ljdk/internal/vm/annotation/Stable;"; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
462 |
|
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
463 |
private static final String SPECIES_PREFIX_NAME = "Species_"; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
464 |
private static final String SPECIES_PREFIX_PATH = BMH + "$" + SPECIES_PREFIX_NAME; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
465 |
private static final String SPECIES_CLASS_PREFIX = BMH_NAME + "$" + SPECIES_PREFIX_NAME; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
466 |
|
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
467 |
private static final String BMHSPECIES_DATA_EWI_SIG = "(B)" + SPECIES_DATA_SIG; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
468 |
private static final String MYSPECIES_DATA_SIG = "()" + SPECIES_DATA_SIG; |
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
469 |
private static final String INT_SIG = "()I"; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
470 |
|
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
471 |
private static final String SIG_INCIPIT = "(Ljava/lang/invoke/MethodType;Ljava/lang/invoke/LambdaForm;"; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
472 |
|
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
473 |
private static final String[] E_THROWABLE = new String[] { "java/lang/Throwable" }; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
474 |
|
44590
15a77e5b7612
8178384: Reduce work in java.lang.invoke initializers
redestad
parents:
42105
diff
changeset
|
475 |
private static final ConcurrentMap<String, Class<? extends BoundMethodHandle>> CLASS_CACHE = new ConcurrentHashMap<>(); |
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
476 |
|
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
477 |
/** |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
478 |
* Get a concrete subclass of BMH for a given combination of bound types. |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
479 |
* |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
480 |
* @param types the type signature, wherein reference types are erased to 'L' |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
481 |
* @return the concrete BMH class |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
482 |
*/ |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
483 |
static Class<? extends BoundMethodHandle> getConcreteBMHClass(String types) { |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
484 |
// CHM.computeIfAbsent ensures generateConcreteBMHClass is called |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
485 |
// only once per key. |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
486 |
return CLASS_CACHE.computeIfAbsent( |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
487 |
types, new Function<String, Class<? extends BoundMethodHandle>>() { |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
488 |
@Override |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
489 |
public Class<? extends BoundMethodHandle> apply(String types) { |
36757
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
490 |
String shortTypes = LambdaForm.shortenSignature(types); |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
491 |
String className = SPECIES_CLASS_PREFIX + shortTypes; |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
492 |
Class<?> c = BootLoader.loadClassOrNull(className); |
40559
e727ba540ee6
8163371: Enable tracing which JLI classes can be pre-generated
redestad
parents:
40408
diff
changeset
|
493 |
if (TRACE_RESOLVE) { |
e727ba540ee6
8163371: Enable tracing which JLI classes can be pre-generated
redestad
parents:
40408
diff
changeset
|
494 |
System.out.println("[BMH_RESOLVE] " + shortTypes + |
e727ba540ee6
8163371: Enable tracing which JLI classes can be pre-generated
redestad
parents:
40408
diff
changeset
|
495 |
(c != null ? " (success)" : " (fail)") ); |
e727ba540ee6
8163371: Enable tracing which JLI classes can be pre-generated
redestad
parents:
40408
diff
changeset
|
496 |
} |
36757
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
497 |
if (c != null) { |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
498 |
return c.asSubclass(BoundMethodHandle.class); |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
499 |
} else { |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
500 |
// Not pregenerated, generate the class |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
501 |
return generateConcreteBMHClass(shortTypes, types); |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
502 |
} |
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
503 |
} |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
504 |
}); |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
505 |
} |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
506 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
507 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
508 |
* Generate a concrete subclass of BMH for a given combination of bound types. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
509 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
510 |
* A concrete BMH species adheres to the following schema: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
511 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
512 |
* <pre> |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
513 |
* class Species_[[types]] extends BoundMethodHandle { |
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
514 |
* [[fields]] |
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
515 |
* final SpeciesData speciesData() { return SpeciesData.get("[[types]]"); } |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
516 |
* } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
517 |
* </pre> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
518 |
* |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
519 |
* The {@code [[types]]} signature is precisely the string that is passed to this |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
520 |
* method. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
521 |
* |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
522 |
* The {@code [[fields]]} section consists of one field definition per character in |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
523 |
* the type signature, adhering to the naming schema described in the definition of |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
20527
diff
changeset
|
524 |
* {@link #makeFieldName}. |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
525 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
526 |
* For example, a concrete BMH species for two reference and one integral bound values |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
527 |
* would have the following shape: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
528 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
529 |
* <pre> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
530 |
* class BoundMethodHandle { ... private static |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
531 |
* final class Species_LLI extends BoundMethodHandle { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
532 |
* final Object argL0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
533 |
* final Object argL1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
534 |
* final int argI2; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
535 |
* private Species_LLI(MethodType mt, LambdaForm lf, Object argL0, Object argL1, int argI2) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
536 |
* super(mt, lf); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
537 |
* this.argL0 = argL0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
538 |
* this.argL1 = argL1; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
539 |
* this.argI2 = argI2; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
540 |
* } |
23918 | 541 |
* final SpeciesData speciesData() { return SPECIES_DATA; } |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
542 |
* final int fieldCount() { return 3; } |
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
543 |
* @Stable static SpeciesData SPECIES_DATA; // injected afterwards |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
544 |
* static BoundMethodHandle make(MethodType mt, LambdaForm lf, Object argL0, Object argL1, int argI2) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
545 |
* return new Species_LLI(mt, lf, argL0, argL1, argI2); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
546 |
* } |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
547 |
* final BoundMethodHandle copyWith(MethodType mt, LambdaForm lf) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
548 |
* return new Species_LLI(mt, lf, argL0, argL1, argI2); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
549 |
* } |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
550 |
* final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
551 |
* return SPECIES_DATA.extendWith(L_TYPE).constructor().invokeBasic(mt, lf, argL0, argL1, argI2, narg); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
552 |
* } |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
553 |
* final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
554 |
* return SPECIES_DATA.extendWith(I_TYPE).constructor().invokeBasic(mt, lf, argL0, argL1, argI2, narg); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
555 |
* } |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
556 |
* final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
557 |
* return SPECIES_DATA.extendWith(J_TYPE).constructor().invokeBasic(mt, lf, argL0, argL1, argI2, narg); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
558 |
* } |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
559 |
* final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
560 |
* return SPECIES_DATA.extendWith(F_TYPE).constructor().invokeBasic(mt, lf, argL0, argL1, argI2, narg); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
561 |
* } |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
562 |
* public final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) { |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
563 |
* return SPECIES_DATA.extendWith(D_TYPE).constructor().invokeBasic(mt, lf, argL0, argL1, argI2, narg); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
564 |
* } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
565 |
* } |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
566 |
* </pre> |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
567 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
568 |
* @param types the type signature, wherein reference types are erased to 'L' |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
569 |
* @return the generated concrete BMH class |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
570 |
*/ |
36757
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
571 |
static Class<? extends BoundMethodHandle> generateConcreteBMHClass(String shortTypes, |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
572 |
String types) { |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
573 |
final String className = speciesInternalClassName(shortTypes); |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
574 |
byte[] classFile = generateConcreteBMHClassBytes(shortTypes, types, className); |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
575 |
|
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
576 |
// load class |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
577 |
InvokerBytecodeGenerator.maybeDump(className, classFile); |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
578 |
Class<? extends BoundMethodHandle> bmhClass = |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
579 |
UNSAFE.defineClass(className, classFile, 0, classFile.length, |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
580 |
BoundMethodHandle.class.getClassLoader(), null) |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
581 |
.asSubclass(BoundMethodHandle.class); |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
582 |
|
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
583 |
return bmhClass; |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
584 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
585 |
|
40258
e6ba2e5c7a29
8163373: Rewrite GenerateJLIClassesPlugin to avoid reflective calls into java.lang.invoke
redestad
parents:
39342
diff
changeset
|
586 |
static String speciesInternalClassName(String shortTypes) { |
36757
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
587 |
return SPECIES_PREFIX_PATH + shortTypes; |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
588 |
} |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
589 |
|
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
590 |
static byte[] generateConcreteBMHClassBytes(final String shortTypes, |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
591 |
final String types, final String className) { |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
592 |
final String sourceFile = SPECIES_PREFIX_NAME + shortTypes; |
36757
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
593 |
|
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
594 |
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES); |
23918 | 595 |
final int NOT_ACC_PUBLIC = 0; // not ACC_PUBLIC |
596 |
cw.visit(V1_6, NOT_ACC_PUBLIC + ACC_FINAL + ACC_SUPER, className, null, BMH, null); |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
597 |
cw.visitSource(sourceFile, null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
598 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
599 |
// emit static types and SPECIES_DATA fields |
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
600 |
FieldVisitor fw = cw.visitField(NOT_ACC_PUBLIC + ACC_STATIC, "SPECIES_DATA", SPECIES_DATA_SIG, null, null); |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
601 |
fw.visitAnnotation(STABLE_SIG, true); |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
602 |
fw.visitEnd(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
603 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
604 |
// emit bound argument fields |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
605 |
for (int i = 0; i < types.length(); ++i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
606 |
final char t = types.charAt(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
607 |
final String fieldName = makeFieldName(types, i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
608 |
final String fieldDesc = t == 'L' ? JLO_SIG : String.valueOf(t); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
609 |
cw.visitField(ACC_FINAL, fieldName, fieldDesc, null, null).visitEnd(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
610 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
611 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
612 |
MethodVisitor mv; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
613 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
614 |
// emit constructor |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
615 |
mv = cw.visitMethod(ACC_PRIVATE, "<init>", makeSignature(types, true), null, null); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
616 |
mv.visitCode(); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
617 |
mv.visitVarInsn(ALOAD, 0); // this |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
618 |
mv.visitVarInsn(ALOAD, 1); // type |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
619 |
mv.visitVarInsn(ALOAD, 2); // form |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
620 |
|
22297 | 621 |
mv.visitMethodInsn(INVOKESPECIAL, BMH, "<init>", makeSignature("", true), false); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
622 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
623 |
for (int i = 0, j = 0; i < types.length(); ++i, ++j) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
624 |
// i counts the arguments, j counts corresponding argument slots |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
625 |
char t = types.charAt(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
626 |
mv.visitVarInsn(ALOAD, 0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
627 |
mv.visitVarInsn(typeLoadOp(t), j + 3); // parameters start at 3 |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
628 |
mv.visitFieldInsn(PUTFIELD, className, makeFieldName(types, i), typeSig(t)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
629 |
if (t == 'J' || t == 'D') { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
630 |
++j; // adjust argument register access |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
631 |
} |
4537 | 632 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
633 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
634 |
mv.visitInsn(RETURN); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
635 |
mv.visitMaxs(0, 0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
636 |
mv.visitEnd(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
637 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
638 |
// emit implementation of speciesData() |
23918 | 639 |
mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "speciesData", MYSPECIES_DATA_SIG, null, null); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
640 |
mv.visitCode(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
641 |
mv.visitFieldInsn(GETSTATIC, className, "SPECIES_DATA", SPECIES_DATA_SIG); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
642 |
mv.visitInsn(ARETURN); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
643 |
mv.visitMaxs(0, 0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
644 |
mv.visitEnd(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
645 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
646 |
// emit implementation of fieldCount() |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
647 |
mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "fieldCount", INT_SIG, null, null); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
648 |
mv.visitCode(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
649 |
int fc = types.length(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
650 |
if (fc <= (ICONST_5 - ICONST_0)) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
651 |
mv.visitInsn(ICONST_0 + fc); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
652 |
} else { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
653 |
mv.visitIntInsn(SIPUSH, fc); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
654 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
655 |
mv.visitInsn(IRETURN); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
656 |
mv.visitMaxs(0, 0); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
657 |
mv.visitEnd(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
658 |
// emit make() ...factory method wrapping constructor |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
659 |
mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_STATIC, "make", makeSignature(types, false), null, null); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
660 |
mv.visitCode(); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
661 |
// make instance |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
662 |
mv.visitTypeInsn(NEW, className); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
663 |
mv.visitInsn(DUP); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
664 |
// load mt, lf |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
665 |
mv.visitVarInsn(ALOAD, 0); // type |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
666 |
mv.visitVarInsn(ALOAD, 1); // form |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
667 |
// load factory method arguments |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
668 |
for (int i = 0, j = 0; i < types.length(); ++i, ++j) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
669 |
// i counts the arguments, j counts corresponding argument slots |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
670 |
char t = types.charAt(i); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
671 |
mv.visitVarInsn(typeLoadOp(t), j + 2); // parameters start at 3 |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
672 |
if (t == 'J' || t == 'D') { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
673 |
++j; // adjust argument register access |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
674 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
675 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
676 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
677 |
// finally, invoke the constructor and return |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
678 |
mv.visitMethodInsn(INVOKESPECIAL, className, "<init>", makeSignature(types, true), false); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
679 |
mv.visitInsn(ARETURN); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
680 |
mv.visitMaxs(0, 0); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
681 |
mv.visitEnd(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
682 |
|
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
683 |
// emit copyWith() |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
684 |
mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "copyWith", makeSignature("", false), null, null); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
685 |
mv.visitCode(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
686 |
// make instance |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
687 |
mv.visitTypeInsn(NEW, className); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
688 |
mv.visitInsn(DUP); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
689 |
// load mt, lf |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
690 |
mv.visitVarInsn(ALOAD, 1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
691 |
mv.visitVarInsn(ALOAD, 2); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
692 |
// put fields on the stack |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
693 |
emitPushFields(types, className, mv); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
694 |
// finally, invoke the constructor and return |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
695 |
mv.visitMethodInsn(INVOKESPECIAL, className, "<init>", makeSignature(types, true), false); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
696 |
mv.visitInsn(ARETURN); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
697 |
mv.visitMaxs(0, 0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
698 |
mv.visitEnd(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
699 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
700 |
// for each type, emit copyWithExtendT() |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
701 |
for (BasicType type : BasicType.ARG_TYPES) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
702 |
int ord = type.ordinal(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
703 |
char btChar = type.basicTypeChar(); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
704 |
mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "copyWithExtend" + btChar, makeSignature(String.valueOf(btChar), false), null, E_THROWABLE); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
705 |
mv.visitCode(); |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
706 |
// return SPECIES_DATA.extendWith(t).constructor().invokeBasic(mt, lf, argL0, ..., narg) |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
707 |
// obtain constructor |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
708 |
mv.visitFieldInsn(GETSTATIC, className, "SPECIES_DATA", SPECIES_DATA_SIG); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
709 |
int iconstInsn = ICONST_0 + ord; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
710 |
assert(iconstInsn <= ICONST_5); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
711 |
mv.visitInsn(iconstInsn); |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
712 |
mv.visitMethodInsn(INVOKEVIRTUAL, SPECIES_DATA, "extendWith", BMHSPECIES_DATA_EWI_SIG, false); |
26467
d69abed3a07d
8050052: Small cleanups in java.lang.invoke code
vlivanov
parents:
25859
diff
changeset
|
713 |
mv.visitMethodInsn(INVOKEVIRTUAL, SPECIES_DATA, "constructor", "()" + MH_SIG, false); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
714 |
// load mt, lf |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
715 |
mv.visitVarInsn(ALOAD, 1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
716 |
mv.visitVarInsn(ALOAD, 2); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
717 |
// put fields on the stack |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
718 |
emitPushFields(types, className, mv); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
719 |
// put narg on stack |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
720 |
mv.visitVarInsn(typeLoadOp(btChar), 3); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
721 |
// finally, invoke the constructor and return |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
722 |
mv.visitMethodInsn(INVOKEVIRTUAL, MH, "invokeBasic", makeSignature(types + btChar, false), false); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
723 |
mv.visitInsn(ARETURN); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
724 |
mv.visitMaxs(0, 0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
725 |
mv.visitEnd(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
726 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
727 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
728 |
cw.visitEnd(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
729 |
|
36757
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
36511
diff
changeset
|
730 |
return cw.toByteArray(); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
731 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
732 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
733 |
private static int typeLoadOp(char t) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
734 |
switch (t) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
735 |
case 'L': return ALOAD; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
736 |
case 'I': return ILOAD; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
737 |
case 'J': return LLOAD; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
738 |
case 'F': return FLOAD; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
739 |
case 'D': return DLOAD; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
740 |
default : throw newInternalError("unrecognized type " + t); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
741 |
} |
4537 | 742 |
} |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
743 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
744 |
private static void emitPushFields(String types, String className, MethodVisitor mv) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
745 |
for (int i = 0; i < types.length(); ++i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
746 |
char tc = types.charAt(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
747 |
mv.visitVarInsn(ALOAD, 0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
748 |
mv.visitFieldInsn(GETFIELD, className, makeFieldName(types, i), typeSig(tc)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
749 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
750 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
751 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
752 |
static String typeSig(char t) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
753 |
return t == 'L' ? JLO_SIG : String.valueOf(t); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
754 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
755 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
756 |
// |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
757 |
// Getter MH generation. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
758 |
// |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
759 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
760 |
private static MethodHandle makeGetter(Class<?> cbmhClass, String types, int index) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
761 |
String fieldName = makeFieldName(types, index); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
762 |
Class<?> fieldType = Wrapper.forBasicType(types.charAt(index)).primitiveType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
763 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
764 |
return LOOKUP.findGetter(cbmhClass, fieldName, fieldType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
765 |
} catch (NoSuchFieldException | IllegalAccessException e) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
766 |
throw newInternalError(e); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
767 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
768 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
769 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
770 |
static MethodHandle[] makeGetters(Class<?> cbmhClass, String types, MethodHandle[] mhs) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
771 |
if (mhs == null) mhs = new MethodHandle[types.length()]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
772 |
for (int i = 0; i < mhs.length; ++i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
773 |
mhs[i] = makeGetter(cbmhClass, types, i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
774 |
assert(mhs[i].internalMemberName().getDeclaringClass() == cbmhClass); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
775 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
776 |
return mhs; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
777 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
778 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
779 |
static MethodHandle[] makeCtors(Class<? extends BoundMethodHandle> cbmh, String types, MethodHandle mhs[]) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
780 |
if (mhs == null) mhs = new MethodHandle[1]; |
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
781 |
if (types.equals("")) return mhs; // hack for empty BMH species |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
782 |
mhs[0] = makeCbmhCtor(cbmh, types); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
783 |
return mhs; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
784 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
785 |
|
24572
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
786 |
static NamedFunction[] makeNominalGetters(String types, NamedFunction[] nfs, MethodHandle[] getters) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
787 |
if (nfs == null) nfs = new NamedFunction[types.length()]; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
788 |
for (int i = 0; i < nfs.length; ++i) { |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
789 |
nfs[i] = new NamedFunction(getters[i]); |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
790 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
791 |
return nfs; |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
792 |
} |
5c9e5961d21c
8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents:
23918
diff
changeset
|
793 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
794 |
// |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
795 |
// Auxiliary methods. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
796 |
// |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
797 |
|
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
798 |
static SpeciesData getSpeciesDataFromConcreteBMHClass(Class<? extends BoundMethodHandle> cbmh) { |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
799 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
800 |
Field F_SPECIES_DATA = cbmh.getDeclaredField("SPECIES_DATA"); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
801 |
return (SpeciesData) F_SPECIES_DATA.get(null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
802 |
} catch (ReflectiveOperationException ex) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
803 |
throw newInternalError(ex); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
804 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
805 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
806 |
|
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
807 |
static void setSpeciesDataToConcreteBMHClass(Class<? extends BoundMethodHandle> cbmh, SpeciesData speciesData) { |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
808 |
try { |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
809 |
Field F_SPECIES_DATA = cbmh.getDeclaredField("SPECIES_DATA"); |
36511 | 810 |
// ## FIXME: annotation parser can't create proxy classes until module system is fully initialzed |
811 |
// assert F_SPECIES_DATA.getDeclaredAnnotation(Stable.class) != null; |
|
33646
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
812 |
F_SPECIES_DATA.set(null, speciesData); |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
813 |
} catch (ReflectiveOperationException ex) { |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
814 |
throw newInternalError(ex); |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
815 |
} |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
816 |
} |
aeed9f07a50c
8131129: Attempt to define a duplicate BMH$Species class
plevart
parents:
33312
diff
changeset
|
817 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
818 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
819 |
* Field names in concrete BMHs adhere to this pattern: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
820 |
* arg + type + index |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
821 |
* where type is a single character (L, I, J, F, D). |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
822 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
823 |
private static String makeFieldName(String types, int index) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
824 |
assert index >= 0 && index < types.length(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
825 |
return "arg" + types.charAt(index) + index; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
826 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
827 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
828 |
private static String makeSignature(String types, boolean ctor) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
829 |
StringBuilder buf = new StringBuilder(SIG_INCIPIT); |
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
830 |
int len = types.length(); |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
831 |
for (int i = 0; i < len; i++) { |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
832 |
buf.append(typeSig(types.charAt(i))); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
833 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
834 |
return buf.append(')').append(ctor ? "V" : BMH_SIG).toString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
835 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
836 |
|
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
837 |
private static MethodType makeConstructorType(String types) { |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
838 |
int length = types.length(); |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
839 |
Class<?> ptypes[] = new Class<?>[length + 2]; |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
840 |
ptypes[0] = MethodType.class; |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
841 |
ptypes[1] = LambdaForm.class; |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
842 |
for (int i = 0; i < length; i++) { |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
843 |
ptypes[i + 2] = BasicType.basicType(types.charAt(i)).basicTypeClass(); |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
844 |
} |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
845 |
return MethodType.makeImpl(BoundMethodHandle.class, ptypes, true); |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
846 |
} |
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
847 |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
848 |
static MethodHandle makeCbmhCtor(Class<? extends BoundMethodHandle> cbmh, String types) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
849 |
try { |
44591
b9bf065070fe
8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents:
44590
diff
changeset
|
850 |
return LOOKUP.findStatic(cbmh, "make", makeConstructorType(types)); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
851 |
} catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | TypeNotPresentException e) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
852 |
throw newInternalError(e); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
853 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
854 |
} |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
855 |
} |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7554
diff
changeset
|
856 |
|
40272
6af4511ee5a4
8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents:
40258
diff
changeset
|
857 |
static final Lookup LOOKUP = Lookup.IMPL_LOOKUP; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
858 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
859 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
860 |
* All subclasses must provide such a value describing their type signature. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
861 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9752
diff
changeset
|
862 |
static final SpeciesData SPECIES_DATA = SpeciesData.EMPTY; |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
863 |
|
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
864 |
private static final SpeciesData[] SPECIES_DATA_CACHE = new SpeciesData[6]; |
23038
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
865 |
private static SpeciesData checkCache(int size, String types) { |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
866 |
int idx = size - 1; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
867 |
SpeciesData data = SPECIES_DATA_CACHE[idx]; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
868 |
if (data != null) return data; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
869 |
SPECIES_DATA_CACHE[idx] = data = getSpeciesData(types); |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
870 |
return data; |
bb8b3b23af3a
8027827: Improve performance of catchException combinator
vlivanov
parents:
23010
diff
changeset
|
871 |
} |
39342
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
872 |
static SpeciesData speciesData_L() { return checkCache(1, "L"); } |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
873 |
static SpeciesData speciesData_LL() { return checkCache(2, "LL"); } |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
874 |
static SpeciesData speciesData_LLL() { return checkCache(3, "LLL"); } |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
875 |
static SpeciesData speciesData_LLLL() { return checkCache(4, "LLLL"); } |
f66a89ed6fca
8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents:
36757
diff
changeset
|
876 |
static SpeciesData speciesData_LLLLL() { return checkCache(5, "LLLLL"); } |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
877 |
} |