< prev index next >

src/java.base/share/classes/java/lang/invoke/ValueBootstrapMethods.java

Print this page




 144                 NEW_ARRAY = IMPL_LOOKUP.findStatic(ValueBsmFactory.class, "newObjectArray",
 145                             methodType(Object[].class, MethodHandle[].class));
 146             } catch (ReflectiveOperationException e) {
 147                 throw new BootstrapMethodError(e);
 148             }
 149         }
 150 
 151         /*
 152          * Produce a MethodHandle that returns
 153          *    new Object[] { Class, field1, field2, ... }
 154          *
 155          * int size = getters.length;
 156          * Object[] result = new Object[size];
 157          * for (int i=0; i < size; ++i) {
 158          *     result[i] = getters.invoke(obj);
 159          * }
 160          * return result;
 161          */
 162         static MethodHandle build(MethodHandles.Lookup lookup) {
 163             // build a MethodHandle[] { Class, getter1, getter2, ...} for the lookup class
 164             Class<?> c = lookup.lookupClass();
 165             MethodHandle valueClass =
 166                 MethodHandles.dropArguments(MethodHandles.constant(Class.class, c), 0, Object.class);
 167             MethodHandle[] getters = Stream.concat(Stream.of(valueClass), fields(lookup))
 168                                            .toArray(MethodHandle[]::new);
 169 
 170             MethodHandle iterations =
 171                 MethodHandles.dropArguments(MethodHandles.constant(int.class, getters.length), 0, Object.class);
 172             MethodHandle init = ValueBsmFactory.NEW_ARRAY.bindTo(getters);
 173             MethodHandle body = ValueBsmFactory.GET_FIELD_VALUE.bindTo(getters);
 174             return MethodHandles.countedLoop(iterations, init, body);
 175         }
 176 
 177         static Object[] newObjectArray(MethodHandle[] getters) {
 178             return new Object[getters.length];
 179         }
 180 
 181         /*
 182          * Set the value of the field value at index {@code i} in the given
 183          * {@code values} array.
 184          */




 144                 NEW_ARRAY = IMPL_LOOKUP.findStatic(ValueBsmFactory.class, "newObjectArray",
 145                             methodType(Object[].class, MethodHandle[].class));
 146             } catch (ReflectiveOperationException e) {
 147                 throw new BootstrapMethodError(e);
 148             }
 149         }
 150 
 151         /*
 152          * Produce a MethodHandle that returns
 153          *    new Object[] { Class, field1, field2, ... }
 154          *
 155          * int size = getters.length;
 156          * Object[] result = new Object[size];
 157          * for (int i=0; i < size; ++i) {
 158          *     result[i] = getters.invoke(obj);
 159          * }
 160          * return result;
 161          */
 162         static MethodHandle build(MethodHandles.Lookup lookup) {
 163             // build a MethodHandle[] { Class, getter1, getter2, ...} for the lookup class
 164             Class<?> c = lookup.lookupClass().asValueType();
 165             MethodHandle valueClass =
 166                 MethodHandles.dropArguments(MethodHandles.constant(Class.class, c), 0, Object.class);
 167             MethodHandle[] getters = Stream.concat(Stream.of(valueClass), fields(lookup))
 168                                            .toArray(MethodHandle[]::new);
 169 
 170             MethodHandle iterations =
 171                 MethodHandles.dropArguments(MethodHandles.constant(int.class, getters.length), 0, Object.class);
 172             MethodHandle init = ValueBsmFactory.NEW_ARRAY.bindTo(getters);
 173             MethodHandle body = ValueBsmFactory.GET_FIELD_VALUE.bindTo(getters);
 174             return MethodHandles.countedLoop(iterations, init, body);
 175         }
 176 
 177         static Object[] newObjectArray(MethodHandle[] getters) {
 178             return new Object[getters.length];
 179         }
 180 
 181         /*
 182          * Set the value of the field value at index {@code i} in the given
 183          * {@code values} array.
 184          */


< prev index next >