java.lang.invoke.MethodHandles#arrayElementSetter ( )源码实例Demo

下面列出了java.lang.invoke.MethodHandles#arrayElementSetter ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: groovy   文件: IndyArrayAccess.java
private static MethodHandle buildSetter(Class<?> arrayClass) {
    MethodHandle set = MethodHandles.arrayElementSetter(arrayClass);
    MethodHandle fallback = MethodHandles.explicitCastArguments(set, set.type().changeParameterType(0, Object.class));

    fallback = MethodHandles.dropArguments(fallback, 3, int.class);
    MethodType reorderType = fallback.type().
            insertParameterTypes(0, int.class).
            dropParameterTypes(4, 5);
    fallback = MethodHandles.permuteArguments(fallback, reorderType, 1, 0, 3, 0);

    fallback = MethodHandles.foldArguments(fallback, normalizeIndex);
    fallback = MethodHandles.explicitCastArguments(fallback, set.type());

    MethodHandle guard = MethodHandles.dropArguments(notNegative, 0, arrayClass);
    MethodHandle handle = MethodHandles.guardWithTest(guard, set, fallback);
    return handle;
}
 
源代码2 项目: baratine   文件: BaseRunner.java
public Object[] fillParams(Object... v)
  throws Throwable
{
  Method method = getMethod();
  Class<?>[] types = method.getParameterTypes();

  Annotation[][] parameterAnnotations = method.getParameterAnnotations();

  if (v.length == types.length)
    return v;

  Object[] args = new Object[types.length];

  int vStart = types.length - v.length;

  System.arraycopy(v, 0, args, vStart, v.length);

  for (int i = 0; i < vStart; i++) {
    Class type = types[i];
    Annotation[] annotations = parameterAnnotations[i];

    MethodHandle handle = MethodHandles.arrayElementSetter(Object[].class);
    T ip = createInjectionPoint(type, annotations, handle);
    Object obj = resolve(ip);
    ip.inject(args, i, obj);
  }

  return args;
}
 
源代码3 项目: TencentKona-8   文件: MethodHandleFactory.java
@Override
public MethodHandle arrayElementSetter(final Class<?> type) {
    final MethodHandle mh = MethodHandles.arrayElementSetter(type);
    return debug(mh, "arrayElementSetter", type);
}
 
源代码4 项目: jdk8u60   文件: MethodHandleFactory.java
@Override
public MethodHandle arrayElementSetter(final Class<?> type) {
    final MethodHandle mh = MethodHandles.arrayElementSetter(type);
    return debug(mh, "arrayElementSetter", type);
}
 
源代码5 项目: openjdk-jdk8u   文件: MethodHandleFactory.java
@Override
public MethodHandle arrayElementSetter(final Class<?> type) {
    final MethodHandle mh = MethodHandles.arrayElementSetter(type);
    return debug(mh, "arrayElementSetter", type);
}
 
@Override
public MethodHandle arrayElementSetter(final Class<?> type) {
    final MethodHandle mh = MethodHandles.arrayElementSetter(type);
    return debug(mh, "arrayElementSetter", type);
}
 
源代码7 项目: openjdk-jdk9   文件: MethodHandleFactory.java
@Override
public MethodHandle arrayElementSetter(final Class<?> type) {
    final MethodHandle mh = MethodHandles.arrayElementSetter(type);
    return debug(mh, "arrayElementSetter", type);
}
 
源代码8 项目: hottub   文件: MethodHandleFactory.java
@Override
public MethodHandle arrayElementSetter(final Class<?> type) {
    final MethodHandle mh = MethodHandles.arrayElementSetter(type);
    return debug(mh, "arrayElementSetter", type);
}
 
源代码9 项目: openjdk-8-source   文件: MethodHandleFactory.java
@Override
public MethodHandle arrayElementSetter(final Class<?> type) {
    return MethodHandles.arrayElementSetter(type);
}
 
源代码10 项目: openjdk-8-source   文件: BeanLinker.java
private GuardedInvocationComponent getElementSetter(CallSiteDescriptor callSiteDescriptor,
        LinkerServices linkerServices, List<String> operations) throws Exception {
    final MethodType callSiteType = callSiteDescriptor.getMethodType();
    final Class<?> declaredType = callSiteType.parameterType(0);

    final GuardedInvocationComponent gic;
    // If declared type of receiver at the call site is already an array, a list or map, bind without guard. Thing
    // is, it'd be quite stupid of a call site creator to go though invokedynamic when it knows in advance they're
    // dealing with an array, or a list or map, but hey...
    // Note that for arrays and lists, using LinkerServices.asType() will ensure that any language specific linkers
    // in use will get a chance to perform any (if there's any) implicit conversion to integer for the indices.
    final boolean isMap;
    if(declaredType.isArray()) {
        gic = new GuardedInvocationComponent(MethodHandles.arrayElementSetter(declaredType));
        isMap = false;
    } else if(List.class.isAssignableFrom(declaredType)) {
        gic = new GuardedInvocationComponent(SET_LIST_ELEMENT);
        isMap = false;
    } else if(Map.class.isAssignableFrom(declaredType)) {
        gic = new GuardedInvocationComponent(PUT_MAP_ELEMENT);
        isMap = true;
    } else if(clazz.isArray()) {
        gic = getClassGuardedInvocationComponent(MethodHandles.arrayElementSetter(clazz), callSiteType);
        isMap = false;
    } else if(List.class.isAssignableFrom(clazz)) {
        gic = new GuardedInvocationComponent(SET_LIST_ELEMENT, Guards.asType(LIST_GUARD, callSiteType), List.class,
                ValidationType.INSTANCE_OF);
        isMap = false;
    } else if(Map.class.isAssignableFrom(clazz)) {
        gic = new GuardedInvocationComponent(PUT_MAP_ELEMENT, Guards.asType(MAP_GUARD, callSiteType), Map.class,
                ValidationType.INSTANCE_OF);
        isMap = true;
    } else {
        // Can't set elements for objects that are neither arrays, nor list, nor maps.
        gic = null;
        isMap = false;
    }

    // In contrast to, say, getElementGetter, we only compute the nextComponent if the target object is not a map,
    // as maps will always succeed in setting the element and will never need to fall back to the next component
    // operation.
    final GuardedInvocationComponent nextComponent = isMap ? null : getGuardedInvocationComponent(
            callSiteDescriptor, linkerServices, operations);
    if(gic == null) {
        return nextComponent;
    }

    // We can have "dyn:setElem:foo", especially in composites, i.e. "dyn:setElem|setProp:foo"
    final String fixedKey = getFixedKey(callSiteDescriptor);
    // Convert the key to a number if we're working with a list or array
    final Object typedFixedKey;
    if(!isMap && fixedKey != null) {
        typedFixedKey = convertKeyToInteger(fixedKey, linkerServices);
        if(typedFixedKey == null) {
            // key is not numeric, it can never succeed
            return nextComponent;
        }
    } else {
        typedFixedKey = fixedKey;
    }

    final GuardedInvocation gi = gic.getGuardedInvocation();
    final Binder binder = new Binder(linkerServices, callSiteType, typedFixedKey);
    final MethodHandle invocation = gi.getInvocation();

    if(nextComponent == null) {
        return gic.replaceInvocation(binder.bind(invocation));
    }

    final MethodHandle checkGuard = convertArgToInt(invocation == SET_LIST_ELEMENT ? RANGE_CHECK_LIST :
        RANGE_CHECK_ARRAY, linkerServices, callSiteDescriptor);
    return nextComponent.compose(MethodHandles.guardWithTest(binder.bindTest(checkGuard),
            binder.bind(invocation), nextComponent.getGuardedInvocation().getInvocation()), gi.getGuard(),
            gic.getValidatorClass(), gic.getValidationType());
}
 
源代码11 项目: openjdk-8   文件: MethodHandleFactory.java
@Override
public MethodHandle arrayElementSetter(final Class<?> type) {
    return MethodHandles.arrayElementSetter(type);
}
 
源代码12 项目: openjdk-8   文件: BeanLinker.java
private GuardedInvocationComponent getElementSetter(CallSiteDescriptor callSiteDescriptor,
        LinkerServices linkerServices, List<String> operations) throws Exception {
    final MethodType callSiteType = callSiteDescriptor.getMethodType();
    final Class<?> declaredType = callSiteType.parameterType(0);

    final GuardedInvocationComponent gic;
    // If declared type of receiver at the call site is already an array, a list or map, bind without guard. Thing
    // is, it'd be quite stupid of a call site creator to go though invokedynamic when it knows in advance they're
    // dealing with an array, or a list or map, but hey...
    // Note that for arrays and lists, using LinkerServices.asType() will ensure that any language specific linkers
    // in use will get a chance to perform any (if there's any) implicit conversion to integer for the indices.
    final boolean isMap;
    if(declaredType.isArray()) {
        gic = new GuardedInvocationComponent(MethodHandles.arrayElementSetter(declaredType));
        isMap = false;
    } else if(List.class.isAssignableFrom(declaredType)) {
        gic = new GuardedInvocationComponent(SET_LIST_ELEMENT);
        isMap = false;
    } else if(Map.class.isAssignableFrom(declaredType)) {
        gic = new GuardedInvocationComponent(PUT_MAP_ELEMENT);
        isMap = true;
    } else if(clazz.isArray()) {
        gic = getClassGuardedInvocationComponent(MethodHandles.arrayElementSetter(clazz), callSiteType);
        isMap = false;
    } else if(List.class.isAssignableFrom(clazz)) {
        gic = new GuardedInvocationComponent(SET_LIST_ELEMENT, Guards.asType(LIST_GUARD, callSiteType), List.class,
                ValidationType.INSTANCE_OF);
        isMap = false;
    } else if(Map.class.isAssignableFrom(clazz)) {
        gic = new GuardedInvocationComponent(PUT_MAP_ELEMENT, Guards.asType(MAP_GUARD, callSiteType), Map.class,
                ValidationType.INSTANCE_OF);
        isMap = true;
    } else {
        // Can't set elements for objects that are neither arrays, nor list, nor maps.
        gic = null;
        isMap = false;
    }

    // In contrast to, say, getElementGetter, we only compute the nextComponent if the target object is not a map,
    // as maps will always succeed in setting the element and will never need to fall back to the next component
    // operation.
    final GuardedInvocationComponent nextComponent = isMap ? null : getGuardedInvocationComponent(
            callSiteDescriptor, linkerServices, operations);
    if(gic == null) {
        return nextComponent;
    }

    // We can have "dyn:setElem:foo", especially in composites, i.e. "dyn:setElem|setProp:foo"
    final String fixedKey = getFixedKey(callSiteDescriptor);
    // Convert the key to a number if we're working with a list or array
    final Object typedFixedKey;
    if(!isMap && fixedKey != null) {
        typedFixedKey = convertKeyToInteger(fixedKey, linkerServices);
        if(typedFixedKey == null) {
            // key is not numeric, it can never succeed
            return nextComponent;
        }
    } else {
        typedFixedKey = fixedKey;
    }

    final GuardedInvocation gi = gic.getGuardedInvocation();
    final Binder binder = new Binder(linkerServices, callSiteType, typedFixedKey);
    final MethodHandle invocation = gi.getInvocation();

    if(nextComponent == null) {
        return gic.replaceInvocation(binder.bind(invocation));
    }

    final MethodHandle checkGuard = convertArgToInt(invocation == SET_LIST_ELEMENT ? RANGE_CHECK_LIST :
        RANGE_CHECK_ARRAY, linkerServices, callSiteDescriptor);
    return nextComponent.compose(MethodHandles.guardWithTest(binder.bindTest(checkGuard),
            binder.bind(invocation), nextComponent.getGuardedInvocation().getInvocation()), gi.getGuard(),
            gic.getValidatorClass(), gic.getValidationType());
}
 
源代码13 项目: jdk8u_nashorn   文件: MethodHandleFactory.java
@Override
public MethodHandle arrayElementSetter(final Class<?> type) {
    final MethodHandle mh = MethodHandles.arrayElementSetter(type);
    return debug(mh, "arrayElementSetter", type);
}
 
源代码14 项目: nashorn   文件: MethodHandleFactory.java
@Override
public MethodHandle arrayElementSetter(final Class<?> type) {
    return MethodHandles.arrayElementSetter(type);
}
 
源代码15 项目: nashorn   文件: BeanLinker.java
private GuardedInvocationComponent getElementSetter(CallSiteDescriptor callSiteDescriptor,
        LinkerServices linkerServices, List<String> operations) throws Exception {
    final MethodType callSiteType = callSiteDescriptor.getMethodType();
    final Class<?> declaredType = callSiteType.parameterType(0);

    final GuardedInvocationComponent gic;
    // If declared type of receiver at the call site is already an array, a list or map, bind without guard. Thing
    // is, it'd be quite stupid of a call site creator to go though invokedynamic when it knows in advance they're
    // dealing with an array, or a list or map, but hey...
    // Note that for arrays and lists, using LinkerServices.asType() will ensure that any language specific linkers
    // in use will get a chance to perform any (if there's any) implicit conversion to integer for the indices.
    final boolean isMap;
    if(declaredType.isArray()) {
        gic = new GuardedInvocationComponent(MethodHandles.arrayElementSetter(declaredType));
        isMap = false;
    } else if(List.class.isAssignableFrom(declaredType)) {
        gic = new GuardedInvocationComponent(SET_LIST_ELEMENT);
        isMap = false;
    } else if(Map.class.isAssignableFrom(declaredType)) {
        gic = new GuardedInvocationComponent(PUT_MAP_ELEMENT);
        isMap = true;
    } else if(clazz.isArray()) {
        gic = getClassGuardedInvocationComponent(MethodHandles.arrayElementSetter(clazz), callSiteType);
        isMap = false;
    } else if(List.class.isAssignableFrom(clazz)) {
        gic = new GuardedInvocationComponent(SET_LIST_ELEMENT, Guards.asType(LIST_GUARD, callSiteType), List.class,
                ValidationType.INSTANCE_OF);
        isMap = false;
    } else if(Map.class.isAssignableFrom(clazz)) {
        gic = new GuardedInvocationComponent(PUT_MAP_ELEMENT, Guards.asType(MAP_GUARD, callSiteType), Map.class,
                ValidationType.INSTANCE_OF);
        isMap = true;
    } else {
        // Can't set elements for objects that are neither arrays, nor list, nor maps.
        gic = null;
        isMap = false;
    }

    // In contrast to, say, getElementGetter, we only compute the nextComponent if the target object is not a map,
    // as maps will always succeed in setting the element and will never need to fall back to the next component
    // operation.
    final GuardedInvocationComponent nextComponent = isMap ? null : getGuardedInvocationComponent(
            callSiteDescriptor, linkerServices, operations);
    if(gic == null) {
        return nextComponent;
    }

    // We can have "dyn:setElem:foo", especially in composites, i.e. "dyn:setElem|setProp:foo"
    final String fixedKey = getFixedKey(callSiteDescriptor);
    // Convert the key to a number if we're working with a list or array
    final Object typedFixedKey;
    if(!isMap && fixedKey != null) {
        typedFixedKey = convertKeyToInteger(fixedKey, linkerServices);
        if(typedFixedKey == null) {
            // key is not numeric, it can never succeed
            return nextComponent;
        }
    } else {
        typedFixedKey = fixedKey;
    }

    final GuardedInvocation gi = gic.getGuardedInvocation();
    final Binder binder = new Binder(linkerServices, callSiteType, typedFixedKey);
    final MethodHandle invocation = gi.getInvocation();

    if(nextComponent == null) {
        return gic.replaceInvocation(binder.bind(invocation));
    }

    final MethodHandle checkGuard = convertArgToInt(invocation == SET_LIST_ELEMENT ? RANGE_CHECK_LIST :
        RANGE_CHECK_ARRAY, linkerServices, callSiteDescriptor);
    return nextComponent.compose(MethodHandles.guardWithTest(binder.bindTest(checkGuard),
            binder.bind(invocation), nextComponent.getGuardedInvocation().getInvocation()), gi.getGuard(),
            gic.getValidatorClass(), gic.getValidationType());
}