23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package java.lang.invoke; |
26 package java.lang.invoke; |
27 |
27 |
|
28 import jdk.internal.vm.annotation.Stable; |
|
29 |
28 import static java.lang.invoke.LambdaForm.BasicType.*; |
30 import static java.lang.invoke.LambdaForm.BasicType.*; |
29 import static java.lang.invoke.MethodHandleStatics.*; |
31 import static java.lang.invoke.MethodHandleStatics.*; |
30 |
32 |
31 /** |
33 /** |
32 * A method handle whose behavior is determined only by its LambdaForm. |
34 * A method handle whose behavior is determined only by its LambdaForm. |
33 * @author jrose |
35 * @author jrose |
34 */ |
36 */ |
35 final class SimpleMethodHandle extends BoundMethodHandle { |
37 final class SimpleMethodHandle extends BoundMethodHandle { |
|
38 |
36 private SimpleMethodHandle(MethodType type, LambdaForm form) { |
39 private SimpleMethodHandle(MethodType type, LambdaForm form) { |
37 super(type, form); |
40 super(type, form); |
38 } |
41 } |
39 |
42 |
40 /*non-public*/ static BoundMethodHandle make(MethodType type, LambdaForm form) { |
43 /*non-public*/ static BoundMethodHandle make(MethodType type, LambdaForm form) { |
41 return new SimpleMethodHandle(type, form); |
44 return new SimpleMethodHandle(type, form); |
42 } |
45 } |
43 |
46 |
44 /*non-public*/ static final SpeciesData SPECIES_DATA = SpeciesData.EMPTY; |
47 /*non-public*/ static @Stable BoundMethodHandle.SpeciesData BMH_SPECIES; |
45 |
48 |
46 /*non-public*/ public SpeciesData speciesData() { |
49 @Override |
47 return SPECIES_DATA; |
50 /*non-public*/ BoundMethodHandle.SpeciesData speciesData() { |
|
51 return BMH_SPECIES; |
48 } |
52 } |
49 |
53 |
50 @Override |
54 @Override |
51 /*non-public*/ BoundMethodHandle copyWith(MethodType mt, LambdaForm lf) { |
55 /*non-public*/ BoundMethodHandle copyWith(MethodType mt, LambdaForm lf) { |
52 return make(mt, lf); |
56 return make(mt, lf); |
56 String internalProperties() { |
60 String internalProperties() { |
57 return "\n& Class="+getClass().getSimpleName(); |
61 return "\n& Class="+getClass().getSimpleName(); |
58 } |
62 } |
59 |
63 |
60 @Override |
64 @Override |
61 /*non-public*/ public int fieldCount() { |
|
62 return 0; |
|
63 } |
|
64 |
|
65 @Override |
|
66 /*non-public*/ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) { |
65 /*non-public*/ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) { |
67 return BoundMethodHandle.bindSingle(mt, lf, narg); // Use known fast path. |
66 return BoundMethodHandle.bindSingle(mt, lf, narg); // Use known fast path. |
68 } |
67 } |
69 @Override |
68 @Override |
70 /*non-public*/ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) { |
69 /*non-public*/ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) { |
71 try { |
70 try { |
72 return (BoundMethodHandle) SPECIES_DATA.extendWith(I_TYPE).constructor().invokeBasic(mt, lf, narg); |
71 return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE_NUM).factory().invokeBasic(mt, lf, narg); |
73 } catch (Throwable ex) { |
72 } catch (Throwable ex) { |
74 throw uncaughtException(ex); |
73 throw uncaughtException(ex); |
75 } |
74 } |
76 } |
75 } |
77 @Override |
76 @Override |
78 /*non-public*/ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) { |
77 /*non-public*/ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) { |
79 try { |
78 try { |
80 return (BoundMethodHandle) SPECIES_DATA.extendWith(J_TYPE).constructor().invokeBasic(mt, lf, narg); |
79 return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE_NUM).factory().invokeBasic(mt, lf, narg); |
81 } catch (Throwable ex) { |
80 } catch (Throwable ex) { |
82 throw uncaughtException(ex); |
81 throw uncaughtException(ex); |
83 } |
82 } |
84 } |
83 } |
85 @Override |
84 @Override |
86 /*non-public*/ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) { |
85 /*non-public*/ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) { |
87 try { |
86 try { |
88 return (BoundMethodHandle) SPECIES_DATA.extendWith(F_TYPE).constructor().invokeBasic(mt, lf, narg); |
87 return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE_NUM).factory().invokeBasic(mt, lf, narg); |
89 } catch (Throwable ex) { |
88 } catch (Throwable ex) { |
90 throw uncaughtException(ex); |
89 throw uncaughtException(ex); |
91 } |
90 } |
92 } |
91 } |
93 @Override |
92 @Override |
94 /*non-public*/ final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) { |
93 /*non-public*/ final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) { |
95 try { |
94 try { |
96 return (BoundMethodHandle) SPECIES_DATA.extendWith(D_TYPE).constructor().invokeBasic(mt, lf, narg); |
95 return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE_NUM).factory().invokeBasic(mt, lf, narg); |
97 } catch (Throwable ex) { |
96 } catch (Throwable ex) { |
98 throw uncaughtException(ex); |
97 throw uncaughtException(ex); |
99 } |
98 } |
100 } |
99 } |
101 } |
100 } |