19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.lang.invoke;
27
28 import jdk.internal.loader.BootLoader;
29 import jdk.internal.org.objectweb.asm.ClassWriter;
30 import jdk.internal.org.objectweb.asm.FieldVisitor;
31 import jdk.internal.org.objectweb.asm.MethodVisitor;
32 import jdk.internal.vm.annotation.Stable;
33 import sun.invoke.util.ValueConversions;
34 import sun.invoke.util.Wrapper;
35
36 import java.lang.invoke.LambdaForm.NamedFunction;
37 import java.lang.invoke.MethodHandles.Lookup;
38 import java.lang.reflect.Field;
39 import java.util.Map;
40 import java.util.concurrent.ConcurrentHashMap;
41 import java.util.concurrent.ConcurrentMap;
42 import java.util.function.Function;
43
44 import static java.lang.invoke.LambdaForm.BasicType;
45 import static java.lang.invoke.LambdaForm.BasicType.*;
46 import static java.lang.invoke.MethodHandleStatics.*;
47 import static jdk.internal.org.objectweb.asm.Opcodes.*;
48
49 /**
50 * The flavor of method handle which emulates an invoke instruction
51 * on a predetermined argument. The JVM dispatches to the correct method
52 * when the handle is created, not when it is invoked.
53 *
54 * All bound arguments are encapsulated in dedicated species.
55 */
56 /*non-public*/ abstract class BoundMethodHandle extends MethodHandle {
57
58 /*non-public*/ BoundMethodHandle(MethodType type, LambdaForm form) {
59 super(type, form);
291 static class SpeciesData {
292 private final String typeChars;
293 private final BasicType[] typeCodes;
294 private final Class<? extends BoundMethodHandle> clazz;
295 // Bootstrapping requires circular relations MH -> BMH -> SpeciesData -> MH
296 // Therefore, we need a non-final link in the chain. Use array elements.
297 @Stable private final MethodHandle[] constructor;
298 @Stable private final MethodHandle[] getters;
299 @Stable private final NamedFunction[] nominalGetters;
300 @Stable private final SpeciesData[] extensions;
301
302 /*non-public*/ int fieldCount() {
303 return typeCodes.length;
304 }
305 /*non-public*/ BasicType fieldType(int i) {
306 return typeCodes[i];
307 }
308 /*non-public*/ char fieldTypeChar(int i) {
309 return typeChars.charAt(i);
310 }
311 Object fieldSignature() {
312 return typeChars;
313 }
314 public Class<? extends BoundMethodHandle> fieldHolder() {
315 return clazz;
316 }
317 public String toString() {
318 return "SpeciesData<"+fieldSignature()+">";
319 }
320
321 /**
322 * Return a {@link LambdaForm.Name} containing a {@link LambdaForm.NamedFunction} that
323 * represents a MH bound to a generic invoker, which in turn forwards to the corresponding
324 * getter.
325 */
326 NamedFunction getterFunction(int i) {
327 NamedFunction nf = nominalGetters[i];
328 assert(nf.memberDeclaringClassOrNull() == fieldHolder());
329 assert(nf.returnType() == fieldType(i));
330 return nf;
331 }
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.lang.invoke;
27
28 import jdk.internal.loader.BootLoader;
29 import jdk.internal.org.objectweb.asm.ClassWriter;
30 import jdk.internal.org.objectweb.asm.FieldVisitor;
31 import jdk.internal.org.objectweb.asm.MethodVisitor;
32 import jdk.internal.vm.annotation.Stable;
33 import sun.invoke.util.ValueConversions;
34 import sun.invoke.util.Wrapper;
35
36 import java.lang.invoke.LambdaForm.NamedFunction;
37 import java.lang.invoke.MethodHandles.Lookup;
38 import java.lang.reflect.Field;
39 import java.util.concurrent.ConcurrentHashMap;
40 import java.util.concurrent.ConcurrentMap;
41 import java.util.function.Function;
42
43 import static java.lang.invoke.LambdaForm.BasicType;
44 import static java.lang.invoke.LambdaForm.BasicType.*;
45 import static java.lang.invoke.MethodHandleStatics.*;
46 import static jdk.internal.org.objectweb.asm.Opcodes.*;
47
48 /**
49 * The flavor of method handle which emulates an invoke instruction
50 * on a predetermined argument. The JVM dispatches to the correct method
51 * when the handle is created, not when it is invoked.
52 *
53 * All bound arguments are encapsulated in dedicated species.
54 */
55 /*non-public*/ abstract class BoundMethodHandle extends MethodHandle {
56
57 /*non-public*/ BoundMethodHandle(MethodType type, LambdaForm form) {
58 super(type, form);
290 static class SpeciesData {
291 private final String typeChars;
292 private final BasicType[] typeCodes;
293 private final Class<? extends BoundMethodHandle> clazz;
294 // Bootstrapping requires circular relations MH -> BMH -> SpeciesData -> MH
295 // Therefore, we need a non-final link in the chain. Use array elements.
296 @Stable private final MethodHandle[] constructor;
297 @Stable private final MethodHandle[] getters;
298 @Stable private final NamedFunction[] nominalGetters;
299 @Stable private final SpeciesData[] extensions;
300
301 /*non-public*/ int fieldCount() {
302 return typeCodes.length;
303 }
304 /*non-public*/ BasicType fieldType(int i) {
305 return typeCodes[i];
306 }
307 /*non-public*/ char fieldTypeChar(int i) {
308 return typeChars.charAt(i);
309 }
310 String fieldSignature() {
311 return typeChars;
312 }
313 public Class<? extends BoundMethodHandle> fieldHolder() {
314 return clazz;
315 }
316 public String toString() {
317 return "SpeciesData<"+fieldSignature()+">";
318 }
319
320 /**
321 * Return a {@link LambdaForm.Name} containing a {@link LambdaForm.NamedFunction} that
322 * represents a MH bound to a generic invoker, which in turn forwards to the corresponding
323 * getter.
324 */
325 NamedFunction getterFunction(int i) {
326 NamedFunction nf = nominalGetters[i];
327 assert(nf.memberDeclaringClassOrNull() == fieldHolder());
328 assert(nf.returnType() == fieldType(i));
329 return nf;
330 }
|