Java Code Examples for jdk.internal.dynalink.beans.GuardedInvocationComponent.ValidationType#INSTANCE_OF
The following examples show how to use
jdk.internal.dynalink.beans.GuardedInvocationComponent.ValidationType#INSTANCE_OF .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeanLinker.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private GuardedInvocationComponent getLengthGetter(final CallSiteDescriptor callSiteDescriptor) { assertParameterCount(callSiteDescriptor, 1); final MethodType callSiteType = callSiteDescriptor.getMethodType(); final Class<?> declaredType = callSiteType.parameterType(0); // If declared type of receiver at the call site is already an array, collection, 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, collection, or map, but hey... if(declaredType.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType)); } else if(Collection.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType)); } else if(Map.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType)); } // Otherwise, create a binding based on the actual type of the argument with an appropriate guard. if(clazz.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType), Guards.isArray(0, callSiteType), ValidationType.IS_ARRAY); } if(Collection.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType), Guards.asType( COLLECTION_GUARD, callSiteType), Collection.class, ValidationType.INSTANCE_OF); } if(Map.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType), Guards.asType(MAP_GUARD, callSiteType), Map.class, ValidationType.INSTANCE_OF); } // Can't retrieve length for objects that are neither arrays, nor collections, nor maps. return null; }
Example 2
Source File: BeanLinker.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private GuardedInvocationComponent getLengthGetter(final CallSiteDescriptor callSiteDescriptor) { assertParameterCount(callSiteDescriptor, 1); final MethodType callSiteType = callSiteDescriptor.getMethodType(); final Class<?> declaredType = callSiteType.parameterType(0); // If declared type of receiver at the call site is already an array, collection, 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, collection, or map, but hey... if(declaredType.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType)); } else if(Collection.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType)); } else if(Map.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType)); } // Otherwise, create a binding based on the actual type of the argument with an appropriate guard. if(clazz.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType), Guards.isArray(0, callSiteType), ValidationType.IS_ARRAY); } if(Collection.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType), Guards.asType( COLLECTION_GUARD, callSiteType), Collection.class, ValidationType.INSTANCE_OF); } if(Map.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType), Guards.asType(MAP_GUARD, callSiteType), Map.class, ValidationType.INSTANCE_OF); } // Can't retrieve length for objects that are neither arrays, nor collections, nor maps. return null; }
Example 3
Source File: BeanLinker.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private GuardedInvocationComponent getLengthGetter(final CallSiteDescriptor callSiteDescriptor) { assertParameterCount(callSiteDescriptor, 1); final MethodType callSiteType = callSiteDescriptor.getMethodType(); final Class<?> declaredType = callSiteType.parameterType(0); // If declared type of receiver at the call site is already an array, collection, 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, collection, or map, but hey... if(declaredType.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType)); } else if(Collection.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType)); } else if(Map.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType)); } // Otherwise, create a binding based on the actual type of the argument with an appropriate guard. if(clazz.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType), Guards.isArray(0, callSiteType), ValidationType.IS_ARRAY); } if(Collection.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType), Guards.asType( COLLECTION_GUARD, callSiteType), Collection.class, ValidationType.INSTANCE_OF); } if(Map.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType), Guards.asType(MAP_GUARD, callSiteType), Map.class, ValidationType.INSTANCE_OF); } // Can't retrieve length for objects that are neither arrays, nor collections, nor maps. return null; }
Example 4
Source File: BeanLinker.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private GuardedInvocationComponent getLengthGetter(final CallSiteDescriptor callSiteDescriptor) { assertParameterCount(callSiteDescriptor, 1); final MethodType callSiteType = callSiteDescriptor.getMethodType(); final Class<?> declaredType = callSiteType.parameterType(0); // If declared type of receiver at the call site is already an array, collection, 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, collection, or map, but hey... if(declaredType.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType)); } else if(Collection.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType)); } else if(Map.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType)); } // Otherwise, create a binding based on the actual type of the argument with an appropriate guard. if(clazz.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType), Guards.isArray(0, callSiteType), ValidationType.IS_ARRAY); } if(Collection.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType), Guards.asType( COLLECTION_GUARD, callSiteType), Collection.class, ValidationType.INSTANCE_OF); } if(Map.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType), Guards.asType(MAP_GUARD, callSiteType), Map.class, ValidationType.INSTANCE_OF); } // Can't retrieve length for objects that are neither arrays, nor collections, nor maps. return null; }
Example 5
Source File: BeanLinker.java From hottub with GNU General Public License v2.0 | 5 votes |
private GuardedInvocationComponent getLengthGetter(final CallSiteDescriptor callSiteDescriptor) { assertParameterCount(callSiteDescriptor, 1); final MethodType callSiteType = callSiteDescriptor.getMethodType(); final Class<?> declaredType = callSiteType.parameterType(0); // If declared type of receiver at the call site is already an array, collection, 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, collection, or map, but hey... if(declaredType.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType)); } else if(Collection.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType)); } else if(Map.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType)); } // Otherwise, create a binding based on the actual type of the argument with an appropriate guard. if(clazz.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType), Guards.isArray(0, callSiteType), ValidationType.IS_ARRAY); } if(Collection.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType), Guards.asType( COLLECTION_GUARD, callSiteType), Collection.class, ValidationType.INSTANCE_OF); } if(Map.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType), Guards.asType(MAP_GUARD, callSiteType), Map.class, ValidationType.INSTANCE_OF); } // Can't retrieve length for objects that are neither arrays, nor collections, nor maps. return null; }
Example 6
Source File: BeanLinker.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private GuardedInvocationComponent getLengthGetter(CallSiteDescriptor callSiteDescriptor) { assertParameterCount(callSiteDescriptor, 1); final MethodType callSiteType = callSiteDescriptor.getMethodType(); final Class<?> declaredType = callSiteType.parameterType(0); // If declared type of receiver at the call site is already an array, collection, 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, collection, or map, but hey... if(declaredType.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType)); } else if(Collection.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType)); } else if(Map.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType)); } // Otherwise, create a binding based on the actual type of the argument with an appropriate guard. if(clazz.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType), Guards.isArray(0, callSiteType), ValidationType.IS_ARRAY); } if(Collection.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType), Guards.asType( COLLECTION_GUARD, callSiteType), Collection.class, ValidationType.INSTANCE_OF); } if(Map.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType), Guards.asType(MAP_GUARD, callSiteType), Map.class, ValidationType.INSTANCE_OF); } // Can't retrieve length for objects that are neither arrays, nor collections, nor maps. return null; }
Example 7
Source File: BeanLinker.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private GuardedInvocationComponent getLengthGetter(CallSiteDescriptor callSiteDescriptor) { assertParameterCount(callSiteDescriptor, 1); final MethodType callSiteType = callSiteDescriptor.getMethodType(); final Class<?> declaredType = callSiteType.parameterType(0); // If declared type of receiver at the call site is already an array, collection, 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, collection, or map, but hey... if(declaredType.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType)); } else if(Collection.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType)); } else if(Map.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType)); } // Otherwise, create a binding based on the actual type of the argument with an appropriate guard. if(clazz.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType), Guards.isArray(0, callSiteType), ValidationType.IS_ARRAY); } if(Collection.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType), Guards.asType( COLLECTION_GUARD, callSiteType), Collection.class, ValidationType.INSTANCE_OF); } if(Map.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType), Guards.asType(MAP_GUARD, callSiteType), Map.class, ValidationType.INSTANCE_OF); } // Can't retrieve length for objects that are neither arrays, nor collections, nor maps. return null; }
Example 8
Source File: BeanLinker.java From jdk8u_nashorn with GNU General Public License v2.0 | 5 votes |
private GuardedInvocationComponent getLengthGetter(final CallSiteDescriptor callSiteDescriptor) { assertParameterCount(callSiteDescriptor, 1); final MethodType callSiteType = callSiteDescriptor.getMethodType(); final Class<?> declaredType = callSiteType.parameterType(0); // If declared type of receiver at the call site is already an array, collection, 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, collection, or map, but hey... if(declaredType.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType)); } else if(Collection.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType)); } else if(Map.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType)); } // Otherwise, create a binding based on the actual type of the argument with an appropriate guard. if(clazz.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType), Guards.isArray(0, callSiteType), ValidationType.IS_ARRAY); } if(Collection.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType), Guards.asType( COLLECTION_GUARD, callSiteType), Collection.class, ValidationType.INSTANCE_OF); } if(Map.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType), Guards.asType(MAP_GUARD, callSiteType), Map.class, ValidationType.INSTANCE_OF); } // Can't retrieve length for objects that are neither arrays, nor collections, nor maps. return null; }
Example 9
Source File: BeanLinker.java From nashorn with GNU General Public License v2.0 | 5 votes |
private GuardedInvocationComponent getLengthGetter(CallSiteDescriptor callSiteDescriptor) { assertParameterCount(callSiteDescriptor, 1); final MethodType callSiteType = callSiteDescriptor.getMethodType(); final Class<?> declaredType = callSiteType.parameterType(0); // If declared type of receiver at the call site is already an array, collection, 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, collection, or map, but hey... if(declaredType.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType)); } else if(Collection.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType)); } else if(Map.class.isAssignableFrom(declaredType)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType)); } // Otherwise, create a binding based on the actual type of the argument with an appropriate guard. if(clazz.isArray()) { return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType), Guards.isArray(0, callSiteType), ValidationType.IS_ARRAY); } if(Collection.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType), Guards.asType( COLLECTION_GUARD, callSiteType), Collection.class, ValidationType.INSTANCE_OF); } if(Map.class.isAssignableFrom(clazz)) { return new GuardedInvocationComponent(GET_MAP_LENGTH.asType(callSiteType), Guards.asType(MAP_GUARD, callSiteType), Map.class, ValidationType.INSTANCE_OF); } // Can't retrieve length for objects that are neither arrays, nor collections, nor maps. return null; }
Example 10
Source File: BeanLinker.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private GuardedInvocationComponent getElementGetter(final CallSiteDescriptor callSiteDescriptor, final LinkerServices linkerServices, List<String> operations) throws Exception { final MethodType callSiteType = callSiteDescriptor.getMethodType(); final Class<?> declaredType = callSiteType.parameterType(0); final GuardedInvocationComponent nextComponent = getGuardedInvocationComponent(callSiteDescriptor, linkerServices, operations); // 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 GuardedInvocationComponent gic; final boolean isMap; if(declaredType.isArray()) { gic = new GuardedInvocationComponent(MethodHandles.arrayElementGetter(declaredType)); isMap = false; } else if(List.class.isAssignableFrom(declaredType)) { gic = new GuardedInvocationComponent(GET_LIST_ELEMENT); isMap = false; } else if(Map.class.isAssignableFrom(declaredType)) { gic = new GuardedInvocationComponent(GET_MAP_ELEMENT); isMap = true; } else if(clazz.isArray()) { gic = getClassGuardedInvocationComponent(MethodHandles.arrayElementGetter(clazz), callSiteType); isMap = false; } else if(List.class.isAssignableFrom(clazz)) { gic = new GuardedInvocationComponent(GET_LIST_ELEMENT, Guards.asType(LIST_GUARD, callSiteType), List.class, ValidationType.INSTANCE_OF); isMap = false; } else if(Map.class.isAssignableFrom(clazz)) { gic = new GuardedInvocationComponent(GET_MAP_ELEMENT, Guards.asType(MAP_GUARD, callSiteType), Map.class, ValidationType.INSTANCE_OF); isMap = true; } else { // Can't retrieve elements for objects that are neither arrays, nor list, nor maps. return nextComponent; } // We can have "dyn:getElem:foo", especially in composites, i.e. "dyn:getElem|getProp|getMethod: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; if(invocation == GET_LIST_ELEMENT) { checkGuard = convertArgToInt(RANGE_CHECK_LIST, linkerServices, callSiteDescriptor); } else if(invocation == GET_MAP_ELEMENT) { // TODO: A more complex solution could be devised for maps, one where we do a get() first, and fold it // into a GWT that tests if it returned null, and if it did, do another GWT with containsKey() // that returns constant null (on true), or falls back to next component (on false) checkGuard = CONTAINS_MAP; } else { checkGuard = convertArgToInt(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()); }
Example 11
Source File: BeanLinker.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
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()); }
Example 12
Source File: BeanLinker.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private GuardedInvocationComponent getElementGetter(final CallSiteDescriptor callSiteDescriptor, final LinkerServices linkerServices, List<String> operations) throws Exception { final MethodType callSiteType = callSiteDescriptor.getMethodType(); final Class<?> declaredType = callSiteType.parameterType(0); final GuardedInvocationComponent nextComponent = getGuardedInvocationComponent(callSiteDescriptor, linkerServices, operations); // 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 GuardedInvocationComponent gic; final boolean isMap; if(declaredType.isArray()) { gic = new GuardedInvocationComponent(MethodHandles.arrayElementGetter(declaredType)); isMap = false; } else if(List.class.isAssignableFrom(declaredType)) { gic = new GuardedInvocationComponent(GET_LIST_ELEMENT); isMap = false; } else if(Map.class.isAssignableFrom(declaredType)) { gic = new GuardedInvocationComponent(GET_MAP_ELEMENT); isMap = true; } else if(clazz.isArray()) { gic = getClassGuardedInvocationComponent(MethodHandles.arrayElementGetter(clazz), callSiteType); isMap = false; } else if(List.class.isAssignableFrom(clazz)) { gic = new GuardedInvocationComponent(GET_LIST_ELEMENT, Guards.asType(LIST_GUARD, callSiteType), List.class, ValidationType.INSTANCE_OF); isMap = false; } else if(Map.class.isAssignableFrom(clazz)) { gic = new GuardedInvocationComponent(GET_MAP_ELEMENT, Guards.asType(MAP_GUARD, callSiteType), Map.class, ValidationType.INSTANCE_OF); isMap = true; } else { // Can't retrieve elements for objects that are neither arrays, nor list, nor maps. return nextComponent; } // We can have "dyn:getElem:foo", especially in composites, i.e. "dyn:getElem|getProp|getMethod: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; if(invocation == GET_LIST_ELEMENT) { checkGuard = convertArgToInt(RANGE_CHECK_LIST, linkerServices, callSiteDescriptor); } else if(invocation == GET_MAP_ELEMENT) { // TODO: A more complex solution could be devised for maps, one where we do a get() first, and fold it // into a GWT that tests if it returned null, and if it did, do another GWT with containsKey() // that returns constant null (on true), or falls back to next component (on false) checkGuard = CONTAINS_MAP; } else { checkGuard = convertArgToInt(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()); }
Example 13
Source File: BeanLinker.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
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()); }
Example 14
Source File: BeanLinker.java From nashorn with GNU General Public License v2.0 | 4 votes |
private GuardedInvocationComponent getElementGetter(final CallSiteDescriptor callSiteDescriptor, final LinkerServices linkerServices, List<String> operations) throws Exception { final MethodType callSiteType = callSiteDescriptor.getMethodType(); final Class<?> declaredType = callSiteType.parameterType(0); final GuardedInvocationComponent nextComponent = getGuardedInvocationComponent(callSiteDescriptor, linkerServices, operations); // 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 GuardedInvocationComponent gic; final boolean isMap; if(declaredType.isArray()) { gic = new GuardedInvocationComponent(MethodHandles.arrayElementGetter(declaredType)); isMap = false; } else if(List.class.isAssignableFrom(declaredType)) { gic = new GuardedInvocationComponent(GET_LIST_ELEMENT); isMap = false; } else if(Map.class.isAssignableFrom(declaredType)) { gic = new GuardedInvocationComponent(GET_MAP_ELEMENT); isMap = true; } else if(clazz.isArray()) { gic = getClassGuardedInvocationComponent(MethodHandles.arrayElementGetter(clazz), callSiteType); isMap = false; } else if(List.class.isAssignableFrom(clazz)) { gic = new GuardedInvocationComponent(GET_LIST_ELEMENT, Guards.asType(LIST_GUARD, callSiteType), List.class, ValidationType.INSTANCE_OF); isMap = false; } else if(Map.class.isAssignableFrom(clazz)) { gic = new GuardedInvocationComponent(GET_MAP_ELEMENT, Guards.asType(MAP_GUARD, callSiteType), Map.class, ValidationType.INSTANCE_OF); isMap = true; } else { // Can't retrieve elements for objects that are neither arrays, nor list, nor maps. return nextComponent; } // We can have "dyn:getElem:foo", especially in composites, i.e. "dyn:getElem|getProp|getMethod: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; if(invocation == GET_LIST_ELEMENT) { checkGuard = convertArgToInt(RANGE_CHECK_LIST, linkerServices, callSiteDescriptor); } else if(invocation == GET_MAP_ELEMENT) { // TODO: A more complex solution could be devised for maps, one where we do a get() first, and fold it // into a GWT that tests if it returned null, and if it did, do another GWT with containsKey() // that returns constant null (on true), or falls back to next component (on false) checkGuard = CONTAINS_MAP; } else { checkGuard = convertArgToInt(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()); }
Example 15
Source File: BeanLinker.java From nashorn with GNU General Public License v2.0 | 4 votes |
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()); }