author | mchung |
Mon, 22 Oct 2018 17:00:04 -0700 | |
changeset 52220 | 9c260a6b6471 |
parent 52015 | 821bfc24d750 |
child 54677 | beca9f8524c1 |
permissions | -rw-r--r-- |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1 |
/* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
4 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
10 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
15 |
* accompanied this code). |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
16 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
20 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
23 |
* questions. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
24 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
25 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
26 |
package java.lang.invoke; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
27 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
28 |
import jdk.internal.loader.BootLoader; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
29 |
import jdk.internal.org.objectweb.asm.ClassWriter; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
30 |
import jdk.internal.org.objectweb.asm.FieldVisitor; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
31 |
import jdk.internal.org.objectweb.asm.MethodVisitor; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
32 |
import jdk.internal.vm.annotation.Stable; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
33 |
import sun.invoke.util.BytecodeName; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
34 |
|
49885
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
35 |
import java.lang.reflect.Constructor; |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
36 |
import java.lang.reflect.Field; |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
37 |
import java.lang.reflect.Modifier; |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
38 |
import java.security.AccessController; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
39 |
import java.security.PrivilegedAction; |
49885
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
40 |
import java.util.ArrayList; |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
41 |
import java.util.Collections; |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
42 |
import java.util.List; |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
43 |
import java.util.Objects; |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
44 |
import java.util.concurrent.ConcurrentHashMap; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
45 |
import java.util.function.Function; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
46 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
47 |
import static java.lang.invoke.LambdaForm.*; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
48 |
import static java.lang.invoke.MethodHandleNatives.Constants.REF_getStatic; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
49 |
import static java.lang.invoke.MethodHandleNatives.Constants.REF_putStatic; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
50 |
import static java.lang.invoke.MethodHandleStatics.*; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
51 |
import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
52 |
import static jdk.internal.org.objectweb.asm.Opcodes.*; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
53 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
54 |
/** |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
55 |
* Class specialization code. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
56 |
* @param <T> top class under which species classes are created. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
57 |
* @param <K> key which identifies individual specializations. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
58 |
* @param <S> species data type. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
59 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
60 |
/*non-public*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
61 |
abstract class ClassSpecializer<T,K,S extends ClassSpecializer<T,K,S>.SpeciesData> { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
62 |
private final Class<T> topClass; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
63 |
private final Class<K> keyType; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
64 |
private final Class<S> metaType; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
65 |
private final MemberName sdAccessor; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
66 |
private final String sdFieldName; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
67 |
private final List<MemberName> transformMethods; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
68 |
private final MethodType baseConstructorType; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
69 |
private final S topSpecies; |
50050
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
70 |
private final ConcurrentHashMap<K, Object> cache = new ConcurrentHashMap<>(); |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
71 |
private final Factory factory; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
72 |
private @Stable boolean topClassIsSuper; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
73 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
74 |
/** Return the top type mirror, for type {@code T} */ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
75 |
public final Class<T> topClass() { return topClass; } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
76 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
77 |
/** Return the key type mirror, for type {@code K} */ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
78 |
public final Class<K> keyType() { return keyType; } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
79 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
80 |
/** Return the species metadata type mirror, for type {@code S} */ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
81 |
public final Class<S> metaType() { return metaType; } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
82 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
83 |
/** Report the leading arguments (if any) required by every species factory. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
84 |
* Every species factory adds its own field types as additional arguments, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
85 |
* but these arguments always come first, in every factory method. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
86 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
87 |
protected MethodType baseConstructorType() { return baseConstructorType; } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
88 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
89 |
/** Return the trivial species for the null sequence of arguments. */ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
90 |
protected final S topSpecies() { return topSpecies; } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
91 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
92 |
/** Return the list of transform methods originally given at creation of this specializer. */ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
93 |
protected final List<MemberName> transformMethods() { return transformMethods; } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
94 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
95 |
/** Return the factory object used to build and load concrete species code. */ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
96 |
protected final Factory factory() { return factory; } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
97 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
98 |
/** |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
99 |
* Constructor for this class specializer. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
100 |
* @param topClass type mirror for T |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
101 |
* @param keyType type mirror for K |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
102 |
* @param metaType type mirror for S |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
103 |
* @param baseConstructorType principal constructor type |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
104 |
* @param sdAccessor the method used to get the speciesData |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
105 |
* @param sdFieldName the name of the species data field, inject the speciesData object |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
106 |
* @param transformMethods optional list of transformMethods |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
107 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
108 |
protected ClassSpecializer(Class<T> topClass, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
109 |
Class<K> keyType, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
110 |
Class<S> metaType, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
111 |
MethodType baseConstructorType, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
112 |
MemberName sdAccessor, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
113 |
String sdFieldName, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
114 |
List<MemberName> transformMethods) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
115 |
this.topClass = topClass; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
116 |
this.keyType = keyType; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
117 |
this.metaType = metaType; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
118 |
this.sdAccessor = sdAccessor; |
49885
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
119 |
this.transformMethods = List.copyOf(transformMethods); |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
120 |
this.sdFieldName = sdFieldName; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
121 |
this.baseConstructorType = baseConstructorType.changeReturnType(void.class); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
122 |
this.factory = makeFactory(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
123 |
K tsk = topSpeciesKey(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
124 |
S topSpecies = null; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
125 |
if (tsk != null && topSpecies == null) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
126 |
// if there is a key, build the top species if needed: |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
127 |
topSpecies = findSpecies(tsk); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
128 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
129 |
this.topSpecies = topSpecies; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
130 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
131 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
132 |
// Utilities for subclass constructors: |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
133 |
protected static <T> Constructor<T> reflectConstructor(Class<T> defc, Class<?>... ptypes) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
134 |
try { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
135 |
return defc.getDeclaredConstructor(ptypes); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
136 |
} catch (NoSuchMethodException ex) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
137 |
throw newIAE(defc.getName()+"("+MethodType.methodType(void.class, ptypes)+")", ex); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
138 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
139 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
140 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
141 |
protected static Field reflectField(Class<?> defc, String name) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
142 |
try { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
143 |
return defc.getDeclaredField(name); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
144 |
} catch (NoSuchFieldException ex) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
145 |
throw newIAE(defc.getName()+"."+name, ex); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
146 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
147 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
148 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
149 |
private static RuntimeException newIAE(String message, Throwable cause) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
150 |
return new IllegalArgumentException(message, cause); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
151 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
152 |
|
50050
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
153 |
private static final Function<Object, Object> CREATE_RESERVATION = new Function<>() { |
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
154 |
@Override |
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
155 |
public Object apply(Object key) { |
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
156 |
return new Object(); |
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
157 |
} |
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
158 |
}; |
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
159 |
|
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
160 |
public final S findSpecies(K key) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
161 |
// Note: Species instantiation may throw VirtualMachineError because of |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
162 |
// code cache overflow. If this happens the species bytecode may be |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
163 |
// loaded but not linked to its species metadata (with MH's etc). |
50050
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
164 |
// That will cause a throw out of Factory.loadSpecies. |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
165 |
// |
50050
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
166 |
// In a later attempt to get the same species, the already-loaded |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
167 |
// class will be present in the system dictionary, causing an |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
168 |
// error when the species generator tries to reload it. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
169 |
// We try to detect this case and link the pre-existing code. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
170 |
// |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
171 |
// Although it would be better to start fresh by loading a new |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
172 |
// copy, we have to salvage the previously loaded but broken code. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
173 |
// (As an alternative, we might spin a new class with a new name, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
174 |
// or use the anonymous class mechanism.) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
175 |
// |
50050
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
176 |
// In the end, as long as everybody goes through this findSpecies method, |
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
177 |
// it will ensure only one SpeciesData will be set successfully on a |
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
178 |
// concrete class if ever. |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
179 |
// The concrete class is published via SpeciesData instance |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
180 |
// returned here only after the class and species data are linked together. |
50050
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
181 |
Object speciesDataOrReservation = cache.computeIfAbsent(key, CREATE_RESERVATION); |
49885
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
182 |
// Separating the creation of a placeholder SpeciesData instance above |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
183 |
// from the loading and linking a real one below ensures we can never |
50050
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
184 |
// accidentally call computeIfAbsent recursively. |
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
185 |
S speciesData; |
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
186 |
if (speciesDataOrReservation.getClass() == Object.class) { |
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
187 |
synchronized (speciesDataOrReservation) { |
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
188 |
Object existingSpeciesData = cache.get(key); |
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
189 |
if (existingSpeciesData == speciesDataOrReservation) { // won the race |
49885
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
190 |
// create a new SpeciesData... |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
191 |
speciesData = newSpeciesData(key); |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
192 |
// load and link it... |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
193 |
speciesData = factory.loadSpecies(speciesData); |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
194 |
if (!cache.replace(key, existingSpeciesData, speciesData)) { |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
195 |
throw newInternalError("Concurrent loadSpecies"); |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
196 |
} |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
197 |
} else { // lost the race; the retrieved existingSpeciesData is the final |
50050
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
198 |
speciesData = metaType.cast(existingSpeciesData); |
49885
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
199 |
} |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
200 |
} |
50050
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
201 |
} else { |
0d4920ac269c
8202548: Use reservation Object when creating SpeciesData
redestad
parents:
49885
diff
changeset
|
202 |
speciesData = metaType.cast(speciesDataOrReservation); |
49885
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
203 |
} |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
204 |
assert(speciesData != null && speciesData.isResolved()); |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
205 |
return speciesData; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
206 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
207 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
208 |
/** |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
209 |
* Meta-data wrapper for concrete subtypes of the top class. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
210 |
* Each concrete subtype corresponds to a given sequence of basic field types (LIJFD). |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
211 |
* The fields are immutable; their values are fully specified at object construction. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
212 |
* Each species supplies an array of getter functions which may be used in lambda forms. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
213 |
* A concrete value is always constructed from the full tuple of its field values, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
214 |
* accompanied by the required constructor parameters. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
215 |
* There *may* also be transforms which cloning a species instance and |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
216 |
* either replace a constructor parameter or add one or more new field values. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
217 |
* The shortest possible species has zero fields. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
218 |
* Subtypes are not interrelated among themselves by subtyping, even though |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
219 |
* it would appear that a shorter species could serve as a supertype of a |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
220 |
* longer one which extends it. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
221 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
222 |
public abstract class SpeciesData { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
223 |
// Bootstrapping requires circular relations Class -> SpeciesData -> Class |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
224 |
// Therefore, we need non-final links in the chain. Use @Stable fields. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
225 |
private final K key; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
226 |
private final List<Class<?>> fieldTypes; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
227 |
@Stable private Class<? extends T> speciesCode; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
228 |
@Stable private List<MethodHandle> factories; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
229 |
@Stable private List<MethodHandle> getters; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
230 |
@Stable private List<LambdaForm.NamedFunction> nominalGetters; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
231 |
@Stable private final MethodHandle[] transformHelpers = new MethodHandle[transformMethods.size()]; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
232 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
233 |
protected SpeciesData(K key) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
234 |
this.key = keyType.cast(Objects.requireNonNull(key)); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
235 |
List<Class<?>> types = deriveFieldTypes(key); |
49885
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
236 |
this.fieldTypes = List.copyOf(types); |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
237 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
238 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
239 |
public final K key() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
240 |
return key; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
241 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
242 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
243 |
protected final List<Class<?>> fieldTypes() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
244 |
return fieldTypes; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
245 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
246 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
247 |
protected final int fieldCount() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
248 |
return fieldTypes.size(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
249 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
250 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
251 |
protected ClassSpecializer<T,K,S> outer() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
252 |
return ClassSpecializer.this; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
253 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
254 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
255 |
protected final boolean isResolved() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
256 |
return speciesCode != null && factories != null && !factories.isEmpty(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
257 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
258 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
259 |
@Override public String toString() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
260 |
return metaType.getSimpleName() + "[" + key.toString() + " => " + (isResolved() ? speciesCode.getSimpleName() : "UNRESOLVED") + "]"; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
261 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
262 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
263 |
@Override |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
264 |
public int hashCode() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
265 |
return key.hashCode(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
266 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
267 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
268 |
@Override |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
269 |
public boolean equals(Object obj) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
270 |
if (!(obj instanceof ClassSpecializer.SpeciesData)) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
271 |
return false; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
272 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
273 |
@SuppressWarnings("rawtypes") |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
274 |
ClassSpecializer.SpeciesData that = (ClassSpecializer.SpeciesData) obj; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
275 |
return this.outer() == that.outer() && this.key.equals(that.key); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
276 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
277 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
278 |
/** Throws NPE if this species is not yet resolved. */ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
279 |
protected final Class<? extends T> speciesCode() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
280 |
return Objects.requireNonNull(speciesCode); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
281 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
282 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
283 |
/** |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
284 |
* Return a {@link MethodHandle} which can get the indexed field of this species. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
285 |
* The return type is the type of the species field it accesses. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
286 |
* The argument type is the {@code fieldHolder} class of this species. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
287 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
288 |
protected MethodHandle getter(int i) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
289 |
return getters.get(i); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
290 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
291 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
292 |
/** |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
293 |
* Return a {@link LambdaForm.Name} containing a {@link LambdaForm.NamedFunction} that |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
294 |
* represents a MH bound to a generic invoker, which in turn forwards to the corresponding |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
295 |
* getter. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
296 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
297 |
protected LambdaForm.NamedFunction getterFunction(int i) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
298 |
LambdaForm.NamedFunction nf = nominalGetters.get(i); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
299 |
assert(nf.memberDeclaringClassOrNull() == speciesCode()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
300 |
assert(nf.returnType() == BasicType.basicType(fieldTypes.get(i))); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
301 |
return nf; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
302 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
303 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
304 |
protected List<LambdaForm.NamedFunction> getterFunctions() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
305 |
return nominalGetters; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
306 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
307 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
308 |
protected List<MethodHandle> getters() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
309 |
return getters; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
310 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
311 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
312 |
protected MethodHandle factory() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
313 |
return factories.get(0); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
314 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
315 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
316 |
protected MethodHandle transformHelper(int whichtm) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
317 |
MethodHandle mh = transformHelpers[whichtm]; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
318 |
if (mh != null) return mh; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
319 |
mh = deriveTransformHelper(transformMethods().get(whichtm), whichtm); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
320 |
// Do a little type checking before we start using the MH. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
321 |
// (It will be called with invokeBasic, so this is our only chance.) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
322 |
final MethodType mt = transformHelperType(whichtm); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
323 |
mh = mh.asType(mt); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
324 |
return transformHelpers[whichtm] = mh; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
325 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
326 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
327 |
private final MethodType transformHelperType(int whichtm) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
328 |
MemberName tm = transformMethods().get(whichtm); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
329 |
ArrayList<Class<?>> args = new ArrayList<>(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
330 |
ArrayList<Class<?>> fields = new ArrayList<>(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
331 |
Collections.addAll(args, tm.getParameterTypes()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
332 |
fields.addAll(fieldTypes()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
333 |
List<Class<?>> helperArgs = deriveTransformHelperArguments(tm, whichtm, args, fields); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
334 |
return MethodType.methodType(tm.getReturnType(), helperArgs); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
335 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
336 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
337 |
// Hooks for subclasses: |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
338 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
339 |
/** |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
340 |
* Given a key, derive the list of field types, which all instances of this |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
341 |
* species must store. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
342 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
343 |
protected abstract List<Class<?>> deriveFieldTypes(K key); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
344 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
345 |
/** |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
346 |
* Given the index of a method in the transforms list, supply a factory |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
347 |
* method that takes the arguments of the transform, plus the local fields, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
348 |
* and produce a value of the required type. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
349 |
* You can override this to return null or throw if there are no transforms. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
350 |
* This method exists so that the transforms can be "grown" lazily. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
351 |
* This is necessary if the transform *adds* a field to an instance, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
352 |
* which sometimtes requires the creation, on the fly, of an extended species. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
353 |
* This method is only called once for any particular parameter. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
354 |
* The species caches the result in a private array. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
355 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
356 |
* @param transform the transform being implemented |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
357 |
* @param whichtm the index of that transform in the original list of transforms |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
358 |
* @return the method handle which creates a new result from a mix of transform |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
359 |
* arguments and field values |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
360 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
361 |
protected abstract MethodHandle deriveTransformHelper(MemberName transform, int whichtm); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
362 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
363 |
/** |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
364 |
* During code generation, this method is called once per transform to determine |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
365 |
* what is the mix of arguments to hand to the transform-helper. The bytecode |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
366 |
* which marshals these arguments is open-coded in the species-specific transform. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
367 |
* The two lists are of opaque objects, which you shouldn't do anything with besides |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
368 |
* reordering them into the output list. (They are both mutable, to make editing |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
369 |
* easier.) The imputed types of the args correspond to the transform's parameter |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
370 |
* list, while the imputed types of the fields correspond to the species field types. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
371 |
* After code generation, this method may be called occasionally by error-checking code. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
372 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
373 |
* @param transform the transform being implemented |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
374 |
* @param whichtm the index of that transform in the original list of transforms |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
375 |
* @param args a list of opaque objects representing the incoming transform arguments |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
376 |
* @param fields a list of opaque objects representing the field values of the receiver |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
377 |
* @param <X> the common element type of the various lists |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
378 |
* @return a new list |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
379 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
380 |
protected abstract <X> List<X> deriveTransformHelperArguments(MemberName transform, int whichtm, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
381 |
List<X> args, List<X> fields); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
382 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
383 |
/** Given a key, generate the name of the class which implements the species for that key. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
384 |
* This algorithm must be stable. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
385 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
386 |
* @return class name, which by default is {@code outer().topClass().getName() + "$Species_" + deriveTypeString(key)} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
387 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
388 |
protected String deriveClassName() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
389 |
return outer().topClass().getName() + "$Species_" + deriveTypeString(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
390 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
391 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
392 |
/** |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
393 |
* Default implementation collects basic type characters, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
394 |
* plus possibly type names, if some types don't correspond |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
395 |
* to basic types. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
396 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
397 |
* @return a string suitable for use in a class name |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
398 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
399 |
protected String deriveTypeString() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
400 |
List<Class<?>> types = fieldTypes(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
401 |
StringBuilder buf = new StringBuilder(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
402 |
StringBuilder end = new StringBuilder(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
403 |
for (Class<?> type : types) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
404 |
BasicType basicType = BasicType.basicType(type); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
405 |
if (basicType.basicTypeClass() == type) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
406 |
buf.append(basicType.basicTypeChar()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
407 |
} else { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
408 |
buf.append('V'); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
409 |
end.append(classSig(type)); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
410 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
411 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
412 |
String typeString; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
413 |
if (end.length() > 0) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
414 |
typeString = BytecodeName.toBytecodeName(buf.append("_").append(end).toString()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
415 |
} else { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
416 |
typeString = buf.toString(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
417 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
418 |
return LambdaForm.shortenSignature(typeString); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
419 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
420 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
421 |
/** |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
422 |
* Report what immediate super-class to use for the concrete class of this species. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
423 |
* Normally this is {@code topClass}, but if that is an interface, the factory must override. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
424 |
* The super-class must provide a constructor which takes the {@code baseConstructorType} arguments, if any. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
425 |
* This hook also allows the code generator to use more than one canned supertype for species. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
426 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
427 |
* @return the super-class of the class to be generated |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
428 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
429 |
protected Class<? extends T> deriveSuperClass() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
430 |
final Class<T> topc = topClass(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
431 |
if (!topClassIsSuper) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
432 |
try { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
433 |
final Constructor<T> con = reflectConstructor(topc, baseConstructorType().parameterArray()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
434 |
if (!topc.isInterface() && !Modifier.isPrivate(con.getModifiers())) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
435 |
topClassIsSuper = true; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
436 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
437 |
} catch (Exception|InternalError ex) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
438 |
// fall through... |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
439 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
440 |
if (!topClassIsSuper) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
441 |
throw newInternalError("must override if the top class cannot serve as a super class"); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
442 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
443 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
444 |
return topc; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
445 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
446 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
447 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
448 |
protected abstract S newSpeciesData(K key); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
449 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
450 |
protected K topSpeciesKey() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
451 |
return null; // null means don't report a top species |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
452 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
453 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
454 |
/** |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
455 |
* Code generation support for instances. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
456 |
* Subclasses can modify the behavior. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
457 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
458 |
public class Factory { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
459 |
/** |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
460 |
* Get a concrete subclass of the top class for a given combination of bound types. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
461 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
462 |
* @param speciesData the species requiring the class, not yet linked |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
463 |
* @return a linked version of the same species |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
464 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
465 |
S loadSpecies(S speciesData) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
466 |
String className = speciesData.deriveClassName(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
467 |
assert(className.indexOf('/') < 0) : className; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
468 |
Class<?> salvage = null; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
469 |
try { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
470 |
salvage = BootLoader.loadClassOrNull(className); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
471 |
if (TRACE_RESOLVE && salvage != null) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
472 |
// Used by jlink species pregeneration plugin, see |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
473 |
// jdk.tools.jlink.internal.plugins.GenerateJLIClassesPlugin |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
474 |
System.out.println("[SPECIES_RESOLVE] " + className + " (salvaged)"); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
475 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
476 |
} catch (Error ex) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
477 |
if (TRACE_RESOLVE) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
478 |
System.out.println("[SPECIES_FRESOLVE] " + className + " (Error) " + ex.getMessage()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
479 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
480 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
481 |
final Class<? extends T> speciesCode; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
482 |
if (salvage != null) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
483 |
speciesCode = salvage.asSubclass(topClass()); |
49885
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
484 |
linkSpeciesDataToCode(speciesData, speciesCode); |
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
485 |
linkCodeToSpeciesData(speciesCode, speciesData, true); |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
486 |
} else { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
487 |
// Not pregenerated, generate the class |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
488 |
try { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
489 |
speciesCode = generateConcreteSpeciesCode(className, speciesData); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
490 |
if (TRACE_RESOLVE) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
491 |
// Used by jlink species pregeneration plugin, see |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
492 |
// jdk.tools.jlink.internal.plugins.GenerateJLIClassesPlugin |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
493 |
System.out.println("[SPECIES_RESOLVE] " + className + " (generated)"); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
494 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
495 |
// This operation causes a lot of churn: |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
496 |
linkSpeciesDataToCode(speciesData, speciesCode); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
497 |
// This operation commits the relation, but causes little churn: |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
498 |
linkCodeToSpeciesData(speciesCode, speciesData, false); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
499 |
} catch (Error ex) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
500 |
if (TRACE_RESOLVE) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
501 |
System.out.println("[SPECIES_RESOLVE] " + className + " (Error #2)" ); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
502 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
503 |
// We can get here if there is a race condition loading a class. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
504 |
// Or maybe we are out of resources. Back out of the CHM.get and retry. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
505 |
throw ex; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
506 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
507 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
508 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
509 |
if (!speciesData.isResolved()) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
510 |
throw newInternalError("bad species class linkage for " + className + ": " + speciesData); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
511 |
} |
49885
b2e74972c7d4
8202184: Reduce time blocking the ClassSpecializer cache creating SpeciesData
redestad
parents:
47753
diff
changeset
|
512 |
assert(speciesData == loadSpeciesDataFromCode(speciesCode)); |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
513 |
return speciesData; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
514 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
515 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
516 |
/** |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
517 |
* Generate a concrete subclass of the top class for a given combination of bound types. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
518 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
519 |
* A concrete species subclass roughly matches the following schema: |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
520 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
521 |
* <pre> |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
522 |
* class Species_[[types]] extends [[T]] { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
523 |
* final [[S]] speciesData() { return ... } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
524 |
* static [[T]] make([[fields]]) { return ... } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
525 |
* [[fields]] |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
526 |
* final [[T]] transform([[args]]) { return ... } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
527 |
* } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
528 |
* </pre> |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
529 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
530 |
* The {@code [[types]]} signature is precisely the key for the species. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
531 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
532 |
* The {@code [[fields]]} section consists of one field definition per character in |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
533 |
* the type signature, adhering to the naming schema described in the definition of |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
534 |
* {@link #chooseFieldName}. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
535 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
536 |
* For example, a concrete species for two references and one integral bound value |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
537 |
* has a shape like the following: |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
538 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
539 |
* <pre> |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
540 |
* class TopClass { ... private static |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
541 |
* final class Species_LLI extends TopClass { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
542 |
* final Object argL0; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
543 |
* final Object argL1; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
544 |
* final int argI2; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
545 |
* private Species_LLI(CT ctarg, ..., Object argL0, Object argL1, int argI2) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
546 |
* super(ctarg, ...); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
547 |
* this.argL0 = argL0; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
548 |
* this.argL1 = argL1; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
549 |
* this.argI2 = argI2; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
550 |
* } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
551 |
* final SpeciesData speciesData() { return BMH_SPECIES; } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
552 |
* @Stable static SpeciesData BMH_SPECIES; // injected afterwards |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
553 |
* static TopClass make(CT ctarg, ..., Object argL0, Object argL1, int argI2) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
554 |
* return new Species_LLI(ctarg, ..., argL0, argL1, argI2); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
555 |
* } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
556 |
* final TopClass copyWith(CT ctarg, ...) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
557 |
* return new Species_LLI(ctarg, ..., argL0, argL1, argI2); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
558 |
* } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
559 |
* // two transforms, for the sake of illustration: |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
560 |
* final TopClass copyWithExtendL(CT ctarg, ..., Object narg) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
561 |
* return BMH_SPECIES.transform(L_TYPE).invokeBasic(ctarg, ..., argL0, argL1, argI2, narg); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
562 |
* } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
563 |
* final TopClass copyWithExtendI(CT ctarg, ..., int narg) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
564 |
* return BMH_SPECIES.transform(I_TYPE).invokeBasic(ctarg, ..., argL0, argL1, argI2, narg); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
565 |
* } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
566 |
* } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
567 |
* </pre> |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
568 |
* |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
569 |
* @param className of the species |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
570 |
* @param speciesData what species we are generating |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
571 |
* @return the generated concrete TopClass class |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
572 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
573 |
Class<? extends T> generateConcreteSpeciesCode(String className, ClassSpecializer<T,K,S>.SpeciesData speciesData) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
574 |
byte[] classFile = generateConcreteSpeciesCodeFile(className, speciesData); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
575 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
576 |
// load class |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
577 |
InvokerBytecodeGenerator.maybeDump(classBCName(className), classFile); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
578 |
Class<?> speciesCode; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
579 |
|
52015
821bfc24d750
8181443: Replace usages of jdk.internal.misc.Unsafe with MethodHandles.Lookup.defineClass
mchung
parents:
50050
diff
changeset
|
580 |
MethodHandles.Lookup lookup = IMPL_LOOKUP.in(topClass()); |
821bfc24d750
8181443: Replace usages of jdk.internal.misc.Unsafe with MethodHandles.Lookup.defineClass
mchung
parents:
50050
diff
changeset
|
581 |
speciesCode = AccessController.doPrivileged(new PrivilegedAction<>() { |
821bfc24d750
8181443: Replace usages of jdk.internal.misc.Unsafe with MethodHandles.Lookup.defineClass
mchung
parents:
50050
diff
changeset
|
582 |
@Override |
821bfc24d750
8181443: Replace usages of jdk.internal.misc.Unsafe with MethodHandles.Lookup.defineClass
mchung
parents:
50050
diff
changeset
|
583 |
public Class<?> run() { |
821bfc24d750
8181443: Replace usages of jdk.internal.misc.Unsafe with MethodHandles.Lookup.defineClass
mchung
parents:
50050
diff
changeset
|
584 |
try { |
821bfc24d750
8181443: Replace usages of jdk.internal.misc.Unsafe with MethodHandles.Lookup.defineClass
mchung
parents:
50050
diff
changeset
|
585 |
return lookup.defineClass(classFile); |
821bfc24d750
8181443: Replace usages of jdk.internal.misc.Unsafe with MethodHandles.Lookup.defineClass
mchung
parents:
50050
diff
changeset
|
586 |
} catch (Exception ex) { |
821bfc24d750
8181443: Replace usages of jdk.internal.misc.Unsafe with MethodHandles.Lookup.defineClass
mchung
parents:
50050
diff
changeset
|
587 |
throw newInternalError(ex); |
821bfc24d750
8181443: Replace usages of jdk.internal.misc.Unsafe with MethodHandles.Lookup.defineClass
mchung
parents:
50050
diff
changeset
|
588 |
} |
821bfc24d750
8181443: Replace usages of jdk.internal.misc.Unsafe with MethodHandles.Lookup.defineClass
mchung
parents:
50050
diff
changeset
|
589 |
} |
821bfc24d750
8181443: Replace usages of jdk.internal.misc.Unsafe with MethodHandles.Lookup.defineClass
mchung
parents:
50050
diff
changeset
|
590 |
}); |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
591 |
return speciesCode.asSubclass(topClass()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
592 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
593 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
594 |
// These are named like constants because there is only one per specialization scheme: |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
595 |
private final String SPECIES_DATA = classBCName(metaType); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
596 |
private final String SPECIES_DATA_SIG = classSig(SPECIES_DATA); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
597 |
private final String SPECIES_DATA_NAME = sdAccessor.getName(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
598 |
private final int SPECIES_DATA_MODS = sdAccessor.getModifiers(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
599 |
private final List<String> TRANSFORM_NAMES; // derived from transformMethods |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
600 |
private final List<MethodType> TRANSFORM_TYPES; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
601 |
private final List<Integer> TRANSFORM_MODS; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
602 |
{ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
603 |
// Tear apart transformMethods to get the names, types, and modifiers. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
604 |
List<String> tns = new ArrayList<>(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
605 |
List<MethodType> tts = new ArrayList<>(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
606 |
List<Integer> tms = new ArrayList<>(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
607 |
for (int i = 0; i < transformMethods.size(); i++) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
608 |
MemberName tm = transformMethods.get(i); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
609 |
tns.add(tm.getName()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
610 |
final MethodType tt = tm.getMethodType(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
611 |
tts.add(tt); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
612 |
tms.add(tm.getModifiers()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
613 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
614 |
TRANSFORM_NAMES = List.of(tns.toArray(new String[0])); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
615 |
TRANSFORM_TYPES = List.of(tts.toArray(new MethodType[0])); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
616 |
TRANSFORM_MODS = List.of(tms.toArray(new Integer[0])); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
617 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
618 |
private static final int ACC_PPP = ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
619 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
620 |
/*non-public*/ byte[] generateConcreteSpeciesCodeFile(String className0, ClassSpecializer<T,K,S>.SpeciesData speciesData) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
621 |
final String className = classBCName(className0); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
622 |
final String superClassName = classBCName(speciesData.deriveSuperClass()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
623 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
624 |
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
625 |
final int NOT_ACC_PUBLIC = 0; // not ACC_PUBLIC |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
626 |
cw.visit(V1_6, NOT_ACC_PUBLIC + ACC_FINAL + ACC_SUPER, className, null, superClassName, null); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
627 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
628 |
final String sourceFile = className.substring(className.lastIndexOf('.')+1); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
629 |
cw.visitSource(sourceFile, null); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
630 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
631 |
// emit static types and BMH_SPECIES fields |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
632 |
FieldVisitor fw = cw.visitField(NOT_ACC_PUBLIC + ACC_STATIC, sdFieldName, SPECIES_DATA_SIG, null, null); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
633 |
fw.visitAnnotation(STABLE_SIG, true); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
634 |
fw.visitEnd(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
635 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
636 |
// handy holder for dealing with groups of typed values (ctor arguments and fields) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
637 |
class Var { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
638 |
final int index; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
639 |
final String name; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
640 |
final Class<?> type; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
641 |
final String desc; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
642 |
final BasicType basicType; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
643 |
final int slotIndex; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
644 |
Var(int index, int slotIndex) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
645 |
this.index = index; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
646 |
this.slotIndex = slotIndex; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
647 |
name = null; type = null; desc = null; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
648 |
basicType = BasicType.V_TYPE; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
649 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
650 |
Var(String name, Class<?> type, Var prev) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
651 |
int slotIndex = prev.nextSlotIndex(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
652 |
int index = prev.nextIndex(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
653 |
if (name == null) name = "x"; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
654 |
if (name.endsWith("#")) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
655 |
name = name.substring(0, name.length()-1) + index; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
656 |
assert(!type.equals(void.class)); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
657 |
String desc = classSig(type); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
658 |
BasicType basicType = BasicType.basicType(type); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
659 |
this.index = index; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
660 |
this.name = name; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
661 |
this.type = type; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
662 |
this.desc = desc; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
663 |
this.basicType = basicType; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
664 |
this.slotIndex = slotIndex; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
665 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
666 |
Var lastOf(List<Var> vars) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
667 |
int n = vars.size(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
668 |
return (n == 0 ? this : vars.get(n-1)); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
669 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
670 |
<X> List<Var> fromTypes(List<X> types) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
671 |
Var prev = this; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
672 |
ArrayList<Var> result = new ArrayList<>(types.size()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
673 |
int i = 0; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
674 |
for (X x : types) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
675 |
String vn = name; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
676 |
Class<?> vt; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
677 |
if (x instanceof Class) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
678 |
vt = (Class<?>) x; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
679 |
// make the names friendlier if debugging |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
680 |
assert((vn = vn + "_" + (i++)) != null); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
681 |
} else { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
682 |
@SuppressWarnings("unchecked") |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
683 |
Var v = (Var) x; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
684 |
vn = v.name; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
685 |
vt = v.type; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
686 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
687 |
prev = new Var(vn, vt, prev); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
688 |
result.add(prev); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
689 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
690 |
return result; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
691 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
692 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
693 |
int slotSize() { return basicType.basicTypeSlots(); } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
694 |
int nextIndex() { return index + (slotSize() == 0 ? 0 : 1); } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
695 |
int nextSlotIndex() { return slotIndex >= 0 ? slotIndex + slotSize() : slotIndex; } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
696 |
boolean isInHeap() { return slotIndex < 0; } |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
697 |
void emitVarInstruction(int asmop, MethodVisitor mv) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
698 |
if (asmop == ALOAD) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
699 |
asmop = typeLoadOp(basicType.basicTypeChar()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
700 |
else |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
701 |
throw new AssertionError("bad op="+asmop+" for desc="+desc); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
702 |
mv.visitVarInsn(asmop, slotIndex); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
703 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
704 |
public void emitFieldInsn(int asmop, MethodVisitor mv) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
705 |
mv.visitFieldInsn(asmop, className, name, desc); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
706 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
707 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
708 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
709 |
final Var NO_THIS = new Var(0, 0), |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
710 |
AFTER_THIS = new Var(0, 1), |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
711 |
IN_HEAP = new Var(0, -1); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
712 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
713 |
// figure out the field types |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
714 |
final List<Class<?>> fieldTypes = speciesData.fieldTypes(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
715 |
final List<Var> fields = new ArrayList<>(fieldTypes.size()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
716 |
{ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
717 |
Var nextF = IN_HEAP; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
718 |
for (Class<?> ft : fieldTypes) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
719 |
String fn = chooseFieldName(ft, nextF.nextIndex()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
720 |
nextF = new Var(fn, ft, nextF); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
721 |
fields.add(nextF); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
722 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
723 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
724 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
725 |
// emit bound argument fields |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
726 |
for (Var field : fields) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
727 |
cw.visitField(ACC_FINAL, field.name, field.desc, null, null).visitEnd(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
728 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
729 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
730 |
MethodVisitor mv; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
731 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
732 |
// emit implementation of speciesData() |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
733 |
mv = cw.visitMethod((SPECIES_DATA_MODS & ACC_PPP) + ACC_FINAL, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
734 |
SPECIES_DATA_NAME, "()" + SPECIES_DATA_SIG, null, null); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
735 |
mv.visitCode(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
736 |
mv.visitFieldInsn(GETSTATIC, className, sdFieldName, SPECIES_DATA_SIG); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
737 |
mv.visitInsn(ARETURN); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
738 |
mv.visitMaxs(0, 0); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
739 |
mv.visitEnd(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
740 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
741 |
// figure out the constructor arguments |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
742 |
MethodType superCtorType = ClassSpecializer.this.baseConstructorType(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
743 |
MethodType thisCtorType = superCtorType.appendParameterTypes(fieldTypes); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
744 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
745 |
// emit constructor |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
746 |
{ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
747 |
mv = cw.visitMethod(ACC_PRIVATE, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
748 |
"<init>", methodSig(thisCtorType), null, null); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
749 |
mv.visitCode(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
750 |
mv.visitVarInsn(ALOAD, 0); // this |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
751 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
752 |
final List<Var> ctorArgs = AFTER_THIS.fromTypes(superCtorType.parameterList()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
753 |
for (Var ca : ctorArgs) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
754 |
ca.emitVarInstruction(ALOAD, mv); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
755 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
756 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
757 |
// super(ca...) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
758 |
mv.visitMethodInsn(INVOKESPECIAL, superClassName, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
759 |
"<init>", methodSig(superCtorType), false); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
760 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
761 |
// store down fields |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
762 |
Var lastFV = AFTER_THIS.lastOf(ctorArgs); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
763 |
for (Var f : fields) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
764 |
// this.argL1 = argL1 |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
765 |
mv.visitVarInsn(ALOAD, 0); // this |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
766 |
lastFV = new Var(f.name, f.type, lastFV); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
767 |
lastFV.emitVarInstruction(ALOAD, mv); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
768 |
f.emitFieldInsn(PUTFIELD, mv); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
769 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
770 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
771 |
mv.visitInsn(RETURN); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
772 |
mv.visitMaxs(0, 0); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
773 |
mv.visitEnd(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
774 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
775 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
776 |
// emit make() ...factory method wrapping constructor |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
777 |
{ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
778 |
MethodType ftryType = thisCtorType.changeReturnType(topClass()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
779 |
mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_STATIC, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
780 |
"make", methodSig(ftryType), null, null); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
781 |
mv.visitCode(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
782 |
// make instance |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
783 |
mv.visitTypeInsn(NEW, className); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
784 |
mv.visitInsn(DUP); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
785 |
// load factory method arguments: ctarg... and arg... |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
786 |
for (Var v : NO_THIS.fromTypes(ftryType.parameterList())) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
787 |
v.emitVarInstruction(ALOAD, mv); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
788 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
789 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
790 |
// finally, invoke the constructor and return |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
791 |
mv.visitMethodInsn(INVOKESPECIAL, className, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
792 |
"<init>", methodSig(thisCtorType), false); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
793 |
mv.visitInsn(ARETURN); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
794 |
mv.visitMaxs(0, 0); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
795 |
mv.visitEnd(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
796 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
797 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
798 |
// For each transform, emit the customized override of the transform method. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
799 |
// This method mixes together some incoming arguments (from the transform's |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
800 |
// static type signature) with the field types themselves, and passes |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
801 |
// the resulting mish-mosh of values to a method handle produced by |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
802 |
// the species itself. (Typically this method handle is the factory |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
803 |
// method of this species or a related one.) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
804 |
for (int whichtm = 0; whichtm < TRANSFORM_NAMES.size(); whichtm++) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
805 |
final String TNAME = TRANSFORM_NAMES.get(whichtm); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
806 |
final MethodType TTYPE = TRANSFORM_TYPES.get(whichtm); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
807 |
final int TMODS = TRANSFORM_MODS.get(whichtm); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
808 |
mv = cw.visitMethod((TMODS & ACC_PPP) | ACC_FINAL, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
809 |
TNAME, TTYPE.toMethodDescriptorString(), null, E_THROWABLE); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
810 |
mv.visitCode(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
811 |
// return a call to the corresponding "transform helper", something like this: |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
812 |
// MY_SPECIES.transformHelper(whichtm).invokeBasic(ctarg, ..., argL0, ..., xarg) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
813 |
mv.visitFieldInsn(GETSTATIC, className, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
814 |
sdFieldName, SPECIES_DATA_SIG); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
815 |
emitIntConstant(whichtm, mv); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
816 |
mv.visitMethodInsn(INVOKEVIRTUAL, SPECIES_DATA, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
817 |
"transformHelper", "(I)" + MH_SIG, false); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
818 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
819 |
List<Var> targs = AFTER_THIS.fromTypes(TTYPE.parameterList()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
820 |
List<Var> tfields = new ArrayList<>(fields); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
821 |
// mix them up and load them for the transform helper: |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
822 |
List<Var> helperArgs = speciesData.deriveTransformHelperArguments(transformMethods.get(whichtm), whichtm, targs, tfields); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
823 |
List<Class<?>> helperTypes = new ArrayList<>(helperArgs.size()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
824 |
for (Var ha : helperArgs) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
825 |
helperTypes.add(ha.basicType.basicTypeClass()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
826 |
if (ha.isInHeap()) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
827 |
assert(tfields.contains(ha)); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
828 |
mv.visitVarInsn(ALOAD, 0); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
829 |
ha.emitFieldInsn(GETFIELD, mv); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
830 |
} else { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
831 |
assert(targs.contains(ha)); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
832 |
ha.emitVarInstruction(ALOAD, mv); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
833 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
834 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
835 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
836 |
// jump into the helper (which is probably a factory method) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
837 |
final Class<?> rtype = TTYPE.returnType(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
838 |
final BasicType rbt = BasicType.basicType(rtype); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
839 |
MethodType invokeBasicType = MethodType.methodType(rbt.basicTypeClass(), helperTypes); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
840 |
mv.visitMethodInsn(INVOKEVIRTUAL, MH, |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
841 |
"invokeBasic", methodSig(invokeBasicType), false); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
842 |
if (rbt == BasicType.L_TYPE) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
843 |
mv.visitTypeInsn(CHECKCAST, classBCName(rtype)); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
844 |
mv.visitInsn(ARETURN); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
845 |
} else { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
846 |
throw newInternalError("NYI: transform of type "+rtype); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
847 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
848 |
mv.visitMaxs(0, 0); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
849 |
mv.visitEnd(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
850 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
851 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
852 |
cw.visitEnd(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
853 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
854 |
return cw.toByteArray(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
855 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
856 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
857 |
private int typeLoadOp(char t) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
858 |
switch (t) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
859 |
case 'L': return ALOAD; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
860 |
case 'I': return ILOAD; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
861 |
case 'J': return LLOAD; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
862 |
case 'F': return FLOAD; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
863 |
case 'D': return DLOAD; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
864 |
default : throw newInternalError("unrecognized type " + t); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
865 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
866 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
867 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
868 |
private void emitIntConstant(int con, MethodVisitor mv) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
869 |
if (ICONST_M1 - ICONST_0 <= con && con <= ICONST_5 - ICONST_0) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
870 |
mv.visitInsn(ICONST_0 + con); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
871 |
else if (con == (byte) con) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
872 |
mv.visitIntInsn(BIPUSH, con); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
873 |
else if (con == (short) con) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
874 |
mv.visitIntInsn(SIPUSH, con); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
875 |
else { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
876 |
mv.visitLdcInsn(con); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
877 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
878 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
879 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
880 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
881 |
// |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
882 |
// Getter MH generation. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
883 |
// |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
884 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
885 |
private MethodHandle findGetter(Class<?> speciesCode, List<Class<?>> types, int index) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
886 |
Class<?> fieldType = types.get(index); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
887 |
String fieldName = chooseFieldName(fieldType, index); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
888 |
try { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
889 |
return IMPL_LOOKUP.findGetter(speciesCode, fieldName, fieldType); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
890 |
} catch (NoSuchFieldException | IllegalAccessException e) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
891 |
throw newInternalError(e); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
892 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
893 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
894 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
895 |
private List<MethodHandle> findGetters(Class<?> speciesCode, List<Class<?>> types) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
896 |
MethodHandle[] mhs = new MethodHandle[types.size()]; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
897 |
for (int i = 0; i < mhs.length; ++i) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
898 |
mhs[i] = findGetter(speciesCode, types, i); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
899 |
assert(mhs[i].internalMemberName().getDeclaringClass() == speciesCode); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
900 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
901 |
return List.of(mhs); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
902 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
903 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
904 |
private List<MethodHandle> findFactories(Class<? extends T> speciesCode, List<Class<?>> types) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
905 |
MethodHandle[] mhs = new MethodHandle[1]; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
906 |
mhs[0] = findFactory(speciesCode, types); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
907 |
return List.of(mhs); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
908 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
909 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
910 |
List<LambdaForm.NamedFunction> makeNominalGetters(List<Class<?>> types, List<MethodHandle> getters) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
911 |
LambdaForm.NamedFunction[] nfs = new LambdaForm.NamedFunction[types.size()]; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
912 |
for (int i = 0; i < nfs.length; ++i) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
913 |
nfs[i] = new LambdaForm.NamedFunction(getters.get(i)); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
914 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
915 |
return List.of(nfs); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
916 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
917 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
918 |
// |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
919 |
// Auxiliary methods. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
920 |
// |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
921 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
922 |
protected void linkSpeciesDataToCode(ClassSpecializer<T,K,S>.SpeciesData speciesData, Class<? extends T> speciesCode) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
923 |
speciesData.speciesCode = speciesCode.asSubclass(topClass); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
924 |
final List<Class<?>> types = speciesData.fieldTypes; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
925 |
speciesData.factories = this.findFactories(speciesCode, types); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
926 |
speciesData.getters = this.findGetters(speciesCode, types); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
927 |
speciesData.nominalGetters = this.makeNominalGetters(types, speciesData.getters); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
928 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
929 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
930 |
private Field reflectSDField(Class<? extends T> speciesCode) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
931 |
final Field field = reflectField(speciesCode, sdFieldName); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
932 |
assert(field.getType() == metaType); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
933 |
assert(Modifier.isStatic(field.getModifiers())); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
934 |
return field; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
935 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
936 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
937 |
private S readSpeciesDataFromCode(Class<? extends T> speciesCode) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
938 |
try { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
939 |
MemberName sdField = IMPL_LOOKUP.resolveOrFail(REF_getStatic, speciesCode, sdFieldName, metaType); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
940 |
Object base = MethodHandleNatives.staticFieldBase(sdField); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
941 |
long offset = MethodHandleNatives.staticFieldOffset(sdField); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
942 |
UNSAFE.loadFence(); |
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
52015
diff
changeset
|
943 |
return metaType.cast(UNSAFE.getReference(base, offset)); |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
944 |
} catch (Error err) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
945 |
throw err; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
946 |
} catch (Exception ex) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
947 |
throw newInternalError("Failed to load speciesData from speciesCode: " + speciesCode.getName(), ex); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
948 |
} catch (Throwable t) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
949 |
throw uncaughtException(t); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
950 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
951 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
952 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
953 |
protected S loadSpeciesDataFromCode(Class<? extends T> speciesCode) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
954 |
if (speciesCode == topClass()) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
955 |
return topSpecies; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
956 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
957 |
S result = readSpeciesDataFromCode(speciesCode); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
958 |
if (result.outer() != ClassSpecializer.this) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
959 |
throw newInternalError("wrong class"); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
960 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
961 |
return result; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
962 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
963 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
964 |
protected void linkCodeToSpeciesData(Class<? extends T> speciesCode, ClassSpecializer<T,K,S>.SpeciesData speciesData, boolean salvage) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
965 |
try { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
966 |
assert(readSpeciesDataFromCode(speciesCode) == null || |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
967 |
(salvage && readSpeciesDataFromCode(speciesCode).equals(speciesData))); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
968 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
969 |
MemberName sdField = IMPL_LOOKUP.resolveOrFail(REF_putStatic, speciesCode, sdFieldName, metaType); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
970 |
Object base = MethodHandleNatives.staticFieldBase(sdField); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
971 |
long offset = MethodHandleNatives.staticFieldOffset(sdField); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
972 |
UNSAFE.storeFence(); |
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
52015
diff
changeset
|
973 |
UNSAFE.putReference(base, offset, speciesData); |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
974 |
UNSAFE.storeFence(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
975 |
} catch (Error err) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
976 |
throw err; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
977 |
} catch (Exception ex) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
978 |
throw newInternalError("Failed to link speciesData to speciesCode: " + speciesCode.getName(), ex); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
979 |
} catch (Throwable t) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
980 |
throw uncaughtException(t); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
981 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
982 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
983 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
984 |
/** |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
985 |
* Field names in concrete species classes adhere to this pattern: |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
986 |
* type + index, where type is a single character (L, I, J, F, D). |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
987 |
* The factory subclass can customize this. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
988 |
* The name is purely cosmetic, since it applies to a private field. |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
989 |
*/ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
990 |
protected String chooseFieldName(Class<?> type, int index) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
991 |
BasicType bt = BasicType.basicType(type); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
992 |
return "" + bt.basicTypeChar() + index; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
993 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
994 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
995 |
MethodHandle findFactory(Class<? extends T> speciesCode, List<Class<?>> types) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
996 |
final MethodType type = baseConstructorType().changeReturnType(topClass()).appendParameterTypes(types); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
997 |
try { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
998 |
return IMPL_LOOKUP.findStatic(speciesCode, "make", type); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
999 |
} catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | TypeNotPresentException e) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1000 |
throw newInternalError(e); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1001 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1002 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1003 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1004 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1005 |
/** Hook that virtualizes the Factory class, allowing subclasses to extend it. */ |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1006 |
protected Factory makeFactory() { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1007 |
return new Factory(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1008 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1009 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1010 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1011 |
// Other misc helpers: |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1012 |
private static final String MH = "java/lang/invoke/MethodHandle"; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1013 |
private static final String MH_SIG = "L" + MH + ";"; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1014 |
private static final String STABLE = "jdk/internal/vm/annotation/Stable"; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1015 |
private static final String STABLE_SIG = "L" + STABLE + ";"; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1016 |
private static final String[] E_THROWABLE = new String[] { "java/lang/Throwable" }; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1017 |
static { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1018 |
assert(MH_SIG.equals(classSig(MethodHandle.class))); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1019 |
assert(MH.equals(classBCName(MethodHandle.class))); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1020 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1021 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1022 |
static String methodSig(MethodType mt) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1023 |
return mt.toMethodDescriptorString(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1024 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1025 |
static String classSig(Class<?> cls) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1026 |
if (cls.isPrimitive() || cls.isArray()) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1027 |
return MethodType.methodType(cls).toMethodDescriptorString().substring(2); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1028 |
return classSig(classBCName(cls)); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1029 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1030 |
static String classSig(String bcName) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1031 |
assert(bcName.indexOf('.') < 0); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1032 |
assert(!bcName.endsWith(";")); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1033 |
assert(!bcName.startsWith("[")); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1034 |
return "L" + bcName + ";"; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1035 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1036 |
static String classBCName(Class<?> cls) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1037 |
return classBCName(className(cls)); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1038 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1039 |
static String classBCName(String str) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1040 |
assert(str.indexOf('/') < 0) : str; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1041 |
return str.replace('.', '/'); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1042 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1043 |
static String className(Class<?> cls) { |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1044 |
assert(!cls.isArray() && !cls.isPrimitive()); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1045 |
return cls.getName(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1046 |
} |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
diff
changeset
|
1047 |
} |