author | lana |
Thu, 13 Apr 2017 20:35:17 +0000 | |
changeset 44599 | 942f3546b679 |
parent 40543 | 629f1f599595 |
permissions | -rw-r--r-- |
40259 | 1 |
/* |
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
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. |
|
24 |
*/ |
|
25 |
||
26 |
package java.lang.invoke; |
|
27 |
||
28 |
import java.util.Map; |
|
29 |
import jdk.internal.org.objectweb.asm.ClassWriter; |
|
30 |
import jdk.internal.org.objectweb.asm.Opcodes; |
|
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
31 |
import java.util.ArrayList; |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
32 |
import java.util.HashSet; |
40542
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
33 |
import sun.invoke.util.Wrapper; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
34 |
|
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
35 |
import static java.lang.invoke.MethodHandleNatives.Constants.*; |
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
36 |
|
40259 | 37 |
/** |
38 |
* Helper class to assist the GenerateJLIClassesPlugin to get access to |
|
39 |
* generate classes ahead of time. |
|
40 |
*/ |
|
41 |
class GenerateJLIClassesHelper { |
|
42 |
||
40419
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
43 |
static byte[] generateBasicFormsClassBytes(String className) { |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
44 |
ArrayList<LambdaForm> forms = new ArrayList<>(); |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
45 |
ArrayList<String> names = new ArrayList<>(); |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
46 |
HashSet<String> dedupSet = new HashSet<>(); |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
47 |
for (LambdaForm.BasicType type : LambdaForm.BasicType.values()) { |
40461
e372330c0d8c
8164525: Re-examine zero form link time pre-generation
redestad
parents:
40450
diff
changeset
|
48 |
LambdaForm zero = LambdaForm.zeroForm(type); |
e372330c0d8c
8164525: Re-examine zero form link time pre-generation
redestad
parents:
40450
diff
changeset
|
49 |
String name = zero.kind.defaultLambdaName |
e372330c0d8c
8164525: Re-examine zero form link time pre-generation
redestad
parents:
40450
diff
changeset
|
50 |
+ "_" + zero.returnType().basicTypeChar(); |
e372330c0d8c
8164525: Re-examine zero form link time pre-generation
redestad
parents:
40450
diff
changeset
|
51 |
if (dedupSet.add(name)) { |
e372330c0d8c
8164525: Re-examine zero form link time pre-generation
redestad
parents:
40450
diff
changeset
|
52 |
names.add(name); |
e372330c0d8c
8164525: Re-examine zero form link time pre-generation
redestad
parents:
40450
diff
changeset
|
53 |
forms.add(zero); |
e372330c0d8c
8164525: Re-examine zero form link time pre-generation
redestad
parents:
40450
diff
changeset
|
54 |
} |
e372330c0d8c
8164525: Re-examine zero form link time pre-generation
redestad
parents:
40450
diff
changeset
|
55 |
|
40419
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
56 |
LambdaForm identity = LambdaForm.identityForm(type); |
40461
e372330c0d8c
8164525: Re-examine zero form link time pre-generation
redestad
parents:
40450
diff
changeset
|
57 |
name = identity.kind.defaultLambdaName |
40419
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
58 |
+ "_" + identity.returnType().basicTypeChar(); |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
59 |
if (dedupSet.add(name)) { |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
60 |
names.add(name); |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
61 |
forms.add(identity); |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
62 |
} |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
63 |
} |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
64 |
return generateCodeBytesForLFs(className, |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
65 |
names.toArray(new String[0]), |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
66 |
forms.toArray(new LambdaForm[0])); |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
67 |
} |
20e2e4b25a40
8164451: Generate all zero and identity forms at link time
redestad
parents:
40408
diff
changeset
|
68 |
|
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
69 |
static byte[] generateDirectMethodHandleHolderClassBytes(String className, |
40259 | 70 |
MethodType[] methodTypes, int[] types) { |
40542
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
71 |
ArrayList<LambdaForm> forms = new ArrayList<>(); |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
72 |
ArrayList<String> names = new ArrayList<>(); |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
73 |
for (int i = 0; i < methodTypes.length; i++) { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
74 |
LambdaForm form = DirectMethodHandle |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
75 |
.makePreparedLambdaForm(methodTypes[i], types[i]); |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
76 |
forms.add(form); |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
77 |
names.add(form.kind.defaultLambdaName); |
40259 | 78 |
} |
40542
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
79 |
for (Wrapper wrapper : Wrapper.values()) { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
80 |
if (wrapper == Wrapper.VOID) { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
81 |
continue; |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
82 |
} |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
83 |
for (byte b = DirectMethodHandle.AF_GETFIELD; b < DirectMethodHandle.AF_LIMIT; b++) { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
84 |
int ftype = DirectMethodHandle.ftypeKind(wrapper.primitiveType()); |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
85 |
LambdaForm form = DirectMethodHandle |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
86 |
.makePreparedFieldLambdaForm(b, /*isVolatile*/false, ftype); |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
87 |
if (form.kind != LambdaForm.Kind.GENERIC) { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
88 |
forms.add(form); |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
89 |
names.add(form.kind.defaultLambdaName); |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
90 |
} |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
91 |
// volatile |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
92 |
form = DirectMethodHandle |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
93 |
.makePreparedFieldLambdaForm(b, /*isVolatile*/true, ftype); |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
94 |
if (form.kind != LambdaForm.Kind.GENERIC) { |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
95 |
forms.add(form); |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
96 |
names.add(form.kind.defaultLambdaName); |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
97 |
} |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
98 |
} |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
99 |
} |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
100 |
return generateCodeBytesForLFs(className, |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
101 |
names.toArray(new String[0]), |
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
102 |
forms.toArray(new LambdaForm[0])); |
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
103 |
} |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
104 |
|
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
105 |
static byte[] generateDelegatingMethodHandleHolderClassBytes(String className, |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
106 |
MethodType[] methodTypes) { |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
107 |
|
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
108 |
HashSet<MethodType> dedupSet = new HashSet<>(); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
109 |
ArrayList<LambdaForm> forms = new ArrayList<>(); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
110 |
ArrayList<String> names = new ArrayList<>(); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
111 |
for (int i = 0; i < methodTypes.length; i++) { |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
112 |
// generate methods representing the DelegatingMethodHandle |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
113 |
if (dedupSet.add(methodTypes[i])) { |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
114 |
// reinvokers are variant with the associated SpeciesData |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
115 |
// and shape of the target LF, but we can easily pregenerate |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
116 |
// the basic reinvokers associated with Species_L. Ultimately we |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
117 |
// may want to consider pregenerating more of these, which will |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
118 |
// require an even more complex naming scheme |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
119 |
LambdaForm reinvoker = makeReinvokerFor(methodTypes[i]); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
120 |
forms.add(reinvoker); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
121 |
String speciesSig = BoundMethodHandle |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
122 |
.speciesData(reinvoker).fieldSignature(); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
123 |
assert(speciesSig.equals("L")); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
124 |
names.add(reinvoker.kind.defaultLambdaName + "_" + speciesSig); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
125 |
|
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
126 |
LambdaForm delegate = makeDelegateFor(methodTypes[i]); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
127 |
forms.add(delegate); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
128 |
names.add(delegate.kind.defaultLambdaName); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
129 |
} |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
130 |
} |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
131 |
return generateCodeBytesForLFs(className, |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
132 |
names.toArray(new String[0]), |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
133 |
forms.toArray(new LambdaForm[0])); |
40259 | 134 |
} |
135 |
||
40543
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
136 |
static byte[] generateInvokersHolderClassBytes(String className, |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
137 |
MethodType[] methodTypes) { |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
138 |
|
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
139 |
HashSet<MethodType> dedupSet = new HashSet<>(); |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
140 |
ArrayList<LambdaForm> forms = new ArrayList<>(); |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
141 |
ArrayList<String> names = new ArrayList<>(); |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
142 |
int[] types = { |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
143 |
MethodTypeForm.LF_EX_LINKER, |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
144 |
MethodTypeForm.LF_EX_INVOKER, |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
145 |
MethodTypeForm.LF_GEN_LINKER, |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
146 |
MethodTypeForm.LF_GEN_INVOKER |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
147 |
}; |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
148 |
for (int i = 0; i < methodTypes.length; i++) { |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
149 |
// generate methods representing invokers of the specified type |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
150 |
if (dedupSet.add(methodTypes[i])) { |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
151 |
for (int type : types) { |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
152 |
LambdaForm invokerForm = Invokers.invokeHandleForm(methodTypes[i], |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
153 |
/*customized*/false, type); |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
154 |
forms.add(invokerForm); |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
155 |
names.add(invokerForm.kind.defaultLambdaName); |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
156 |
} |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
157 |
} |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
158 |
} |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
159 |
return generateCodeBytesForLFs(className, |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
160 |
names.toArray(new String[0]), |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
161 |
forms.toArray(new LambdaForm[0])); |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
162 |
} |
629f1f599595
8164569: Generate non-customized invoker forms at link time
redestad
parents:
40542
diff
changeset
|
163 |
|
40259 | 164 |
/* |
165 |
* Generate customized code for a set of LambdaForms of specified types into |
|
166 |
* a class with a specified name. |
|
167 |
*/ |
|
168 |
private static byte[] generateCodeBytesForLFs(String className, |
|
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
169 |
String[] names, LambdaForm[] forms) { |
40259 | 170 |
|
171 |
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES); |
|
172 |
cw.visit(Opcodes.V1_8, Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, |
|
173 |
className, null, InvokerBytecodeGenerator.INVOKER_SUPER_NAME, null); |
|
174 |
cw.visitSource(className.substring(className.lastIndexOf('/') + 1), null); |
|
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
175 |
|
40259 | 176 |
for (int i = 0; i < forms.length; i++) { |
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
177 |
addMethod(className, names[i], forms[i], |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
178 |
forms[i].methodType(), cw); |
40259 | 179 |
} |
180 |
return cw.toByteArray(); |
|
181 |
} |
|
182 |
||
40408
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
183 |
private static void addMethod(String className, String methodName, LambdaForm form, |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
184 |
MethodType type, ClassWriter cw) { |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
185 |
InvokerBytecodeGenerator g |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
186 |
= new InvokerBytecodeGenerator(className, methodName, form, type); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
187 |
g.setClassWriter(cw); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
188 |
g.addMethod(); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
189 |
} |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
190 |
|
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
191 |
private static LambdaForm makeReinvokerFor(MethodType type) { |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
192 |
MethodHandle emptyHandle = MethodHandles.empty(type); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
193 |
return DelegatingMethodHandle.makeReinvokerForm(emptyHandle, |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
194 |
MethodTypeForm.LF_REBIND, |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
195 |
BoundMethodHandle.speciesData_L(), |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
196 |
BoundMethodHandle.speciesData_L().getterFunction(0)); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
197 |
} |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
198 |
|
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
199 |
private static LambdaForm makeDelegateFor(MethodType type) { |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
200 |
MethodHandle handle = MethodHandles.empty(type); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
201 |
return DelegatingMethodHandle.makeReinvokerForm( |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
202 |
handle, |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
203 |
MethodTypeForm.LF_DELEGATE, |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
204 |
DelegatingMethodHandle.class, |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
205 |
DelegatingMethodHandle.NF_getTarget); |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
206 |
} |
cf7e826d4d63
8164044: Generate corresponding simple DelegatingMethodHandles when generating a DirectMethodHandle at link time
redestad
parents:
40259
diff
changeset
|
207 |
|
40259 | 208 |
static Map.Entry<String, byte[]> generateConcreteBMHClassBytes( |
209 |
final String types) { |
|
210 |
for (char c : types.toCharArray()) { |
|
211 |
if ("LIJFD".indexOf(c) < 0) { |
|
212 |
throw new IllegalArgumentException("All characters must " |
|
213 |
+ "correspond to a basic field type: LIJFD"); |
|
214 |
} |
|
215 |
} |
|
216 |
String shortTypes = LambdaForm.shortenSignature(types); |
|
217 |
final String className = |
|
218 |
BoundMethodHandle.Factory.speciesInternalClassName(shortTypes); |
|
219 |
return Map.entry(className, |
|
220 |
BoundMethodHandle.Factory.generateConcreteBMHClassBytes( |
|
221 |
shortTypes, types, className)); |
|
222 |
} |
|
40542
e7be26f852fa
8164483: Generate field lambda forms at link time
redestad
parents:
40461
diff
changeset
|
223 |
|
40259 | 224 |
} |