jdk.internal.dynalink.CallSiteDescriptor Java Examples
The following examples show how to use
jdk.internal.dynalink.CallSiteDescriptor.
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: JSObjectLinker.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception { final LinkRequest requestWithoutContext = request.withoutRuntimeContext(); // Nashorn has no runtime context final Object self = requestWithoutContext.getReceiver(); final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor(); if (desc.getNameTokenCount() < 2 || !"dyn".equals(desc.getNameToken(CallSiteDescriptor.SCHEME))) { // We only support standard "dyn:*[:*]" operations return null; } final GuardedInvocation inv; if (self instanceof JSObject) { inv = lookup(desc); } else { throw new AssertionError(); // Should never reach here. } return Bootstrap.asType(inv, linkerServices, desc); }
Example #2
Source File: ScriptObject.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Find the appropriate GETINDEX method for an invoke dynamic call. * * @param desc the call site descriptor * @param request the link request * * @return GuardedInvocation to be invoked at call site. */ protected GuardedInvocation findGetIndexMethod(final CallSiteDescriptor desc, final LinkRequest request) { final MethodType callType = desc.getMethodType(); final Class<?> returnType = callType.returnType(); final Class<?> returnClass = returnType.isPrimitive() ? returnType : Object.class; final Class<?> keyClass = callType.parameterType(1); final boolean explicitInstanceOfCheck = explicitInstanceOfCheck(desc, request); final String name; if (returnClass.isPrimitive()) { //turn e.g. get with a double into getDouble final String returnTypeName = returnClass.getName(); name = "get" + Character.toUpperCase(returnTypeName.charAt(0)) + returnTypeName.substring(1, returnTypeName.length()); } else { name = "get"; } final MethodHandle mh = findGetIndexMethodHandle(returnClass, name, keyClass, desc); return new GuardedInvocation(mh, getScriptObjectGuard(callType, explicitInstanceOfCheck), (SwitchPoint)null, explicitInstanceOfCheck ? null : ClassCastException.class); }
Example #3
Source File: BrowserJSObjectLinker.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception { final LinkRequest requestWithoutContext = request.withoutRuntimeContext(); // Nashorn has no runtime context final Object self = requestWithoutContext.getReceiver(); final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor(); checkJSObjectClass(); if (desc.getNameTokenCount() < 2 || !"dyn".equals(desc.getNameToken(CallSiteDescriptor.SCHEME))) { // We only support standard "dyn:*[:*]" operations return null; } final GuardedInvocation inv; if (jsObjectClass.isInstance(self)) { inv = lookup(desc, request, linkerServices); } else { throw new AssertionError(); // Should never reach here. } return Bootstrap.asTypeSafeReturn(inv, linkerServices, desc); }
Example #4
Source File: JSObjectLinker.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private GuardedInvocation lookup(final CallSiteDescriptor desc, final LinkRequest request, final LinkerServices linkerServices) throws Exception { final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0); final int c = desc.getNameTokenCount(); switch (operator) { case "getProp": case "getElem": case "getMethod": if (c > 2) { return findGetMethod(desc); } // For indexed get, we want get GuardedInvocation beans linker and pass it. // JSObjectLinker.get uses this fallback getter for explicit signature method access. return findGetIndexMethod(nashornBeansLinker.getGuardedInvocation(request, linkerServices)); case "setProp": case "setElem": return c > 2 ? findSetMethod(desc) : findSetIndexMethod(); case "call": return findCallMethod(desc); case "new": return findNewMethod(desc); default: return null; } }
Example #5
Source File: ScriptObject.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Find the appropriate GETINDEX method for an invoke dynamic call. * * @param desc the call site descriptor * @param request the link request * * @return GuardedInvocation to be invoked at call site. */ protected GuardedInvocation findGetIndexMethod(final CallSiteDescriptor desc, final LinkRequest request) { final MethodType callType = desc.getMethodType(); final Class<?> returnType = callType.returnType(); final Class<?> returnClass = returnType.isPrimitive() ? returnType : Object.class; final Class<?> keyClass = callType.parameterType(1); final boolean explicitInstanceOfCheck = explicitInstanceOfCheck(desc, request); final String name; if (returnClass.isPrimitive()) { //turn e.g. get with a double into getDouble final String returnTypeName = returnClass.getName(); name = "get" + Character.toUpperCase(returnTypeName.charAt(0)) + returnTypeName.substring(1, returnTypeName.length()); } else { name = "get"; } final MethodHandle mh = findGetIndexMethodHandle(returnClass, name, keyClass, desc); return new GuardedInvocation(mh, getScriptObjectGuard(callType, explicitInstanceOfCheck), (SwitchPoint)null, explicitInstanceOfCheck ? null : ClassCastException.class); }
Example #6
Source File: JSObjectLinker.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private GuardedInvocation lookup(final CallSiteDescriptor desc, final LinkRequest request, final LinkerServices linkerServices) throws Exception { final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0); final int c = desc.getNameTokenCount(); switch (operator) { case "getProp": case "getElem": case "getMethod": if (c > 2) { return findGetMethod(desc); } // For indexed get, we want get GuardedInvocation beans linker and pass it. // JSObjectLinker.get uses this fallback getter for explicit signature method access. return findGetIndexMethod(nashornBeansLinker.getGuardedInvocation(request, linkerServices)); case "setProp": case "setElem": return c > 2 ? findSetMethod(desc) : findSetIndexMethod(); case "call": return findCallMethod(desc); case "new": return findNewMethod(desc); default: return null; } }
Example #7
Source File: CallSiteDescriptorFactory.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private static CallSiteDescriptor createPublicCallSiteDescriptor(final String[] tokenizedName, final MethodType methodType) { final int l = tokenizedName.length; if(l > 0 && tokenizedName[0] == "dyn") { if(l == 2) { return new UnnamedDynCallSiteDescriptor(tokenizedName[1], methodType); } if (l == 3) { return new NamedDynCallSiteDescriptor(tokenizedName[1], tokenizedName[2], methodType); } } return new DefaultCallSiteDescriptor(tokenizedName, methodType); }
Example #8
Source File: ScriptObject.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Fall back if a function property is not found. * @param desc The call site descriptor * @param request the link request * @return GuardedInvocation to be invoked at call site. */ public GuardedInvocation noSuchMethod(final CallSiteDescriptor desc, final LinkRequest request) { final String name = desc.getNameToken(2); final FindProperty find = findProperty(NO_SUCH_METHOD_NAME, true); final boolean scopeCall = isScope() && NashornCallSiteDescriptor.isScope(desc); if (find == null) { return noSuchProperty(desc, request); } final boolean explicitInstanceOfCheck = explicitInstanceOfCheck(desc, request); final Object value = find.getObjectValue(); if (!(value instanceof ScriptFunction)) { return createEmptyGetter(desc, explicitInstanceOfCheck, name); } final ScriptFunction func = (ScriptFunction)value; final Object thiz = scopeCall && func.isStrict() ? UNDEFINED : this; // TODO: It'd be awesome if we could bind "name" without binding "this". // Since we're binding this we must use an identity guard here. return new GuardedInvocation( MH.dropArguments( MH.constant( ScriptFunction.class, func.createBound(thiz, new Object[] { name })), 0, Object.class), NashornGuards.combineGuards( NashornGuards.getIdentityGuard(this), NashornGuards.getMapGuard(getMap(), true))); }
Example #9
Source File: ScriptObject.java From hottub with GNU General Public License v2.0 | 5 votes |
private GuardedInvocation createEmptySetMethod(final CallSiteDescriptor desc, final boolean explicitInstanceOfCheck, final String strictErrorMessage, final boolean canBeFastScope) { final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); if (NashornCallSiteDescriptor.isStrict(desc)) { throw typeError(strictErrorMessage, name, ScriptRuntime.safeToString(this)); } assert canBeFastScope || !NashornCallSiteDescriptor.isFastScope(desc); return new GuardedInvocation( Lookup.EMPTY_SETTER, NashornGuards.getMapGuard(getMap(), explicitInstanceOfCheck), getProtoSwitchPoints(name, null), explicitInstanceOfCheck ? null : ClassCastException.class); }
Example #10
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 #11
Source File: BeanLinker.java From nashorn with GNU General Public License v2.0 | 5 votes |
private static MethodHandle convertArgToInt(MethodHandle mh, LinkerServices ls, CallSiteDescriptor desc) { final Class<?> sourceType = desc.getMethodType().parameterType(1); if(TypeUtilities.isMethodInvocationConvertible(sourceType, Number.class)) { return mh; } else if(ls.canConvert(sourceType, Number.class)) { final MethodHandle converter = ls.getTypeConverter(sourceType, Number.class); return MethodHandles.filterArguments(mh, 1, converter.asType(converter.type().changeReturnType( mh.type().parameterType(1)))); } return mh; }
Example #12
Source File: NativeString.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public boolean canLink(final Object self, final CallSiteDescriptor desc, final LinkRequest request) { try { //check that it's a char sequence or throw cce final CharSequence cs = (CharSequence)self; //check that the index, representable as an int, is inside the array final int intIndex = JSType.toInteger(request.getArguments()[2]); return intIndex >= 0 && intIndex < cs.length(); //can link } catch (final ClassCastException | IndexOutOfBoundsException e) { //fallthru } return false; }
Example #13
Source File: DynamicMethodLinker.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) { final Object receiver = linkRequest.getReceiver(); if(!(receiver instanceof DynamicMethod)) { return null; } final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor(); if(desc.getNameTokenCount() != 2 && desc.getNameToken(CallSiteDescriptor.SCHEME) != "dyn") { return null; } final String operator = desc.getNameToken(CallSiteDescriptor.OPERATOR); final DynamicMethod dynMethod = (DynamicMethod)receiver; final boolean constructor = dynMethod.isConstructor(); final MethodHandle invocation; if (operator == "call" && !constructor) { invocation = dynMethod.getInvocation( CallSiteDescriptorFactory.dropParameterTypes(desc, 0, 1), linkerServices); } else if (operator == "new" && constructor) { final MethodHandle ctorInvocation = dynMethod.getInvocation(desc, linkerServices); if(ctorInvocation == null) { return null; } // Insert null for StaticClass parameter invocation = MethodHandles.insertArguments(ctorInvocation, 0, (Object)null); } else { return null; } if (invocation != null) { return new GuardedInvocation(MethodHandles.dropArguments(invocation, 0, desc.getMethodType().parameterType(0)), Guards.getIdentityGuard(receiver)); } return null; }
Example #14
Source File: NativeJSAdapter.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Override protected GuardedInvocation findCallMethodMethod(final CallSiteDescriptor desc, final LinkRequest request) { if (overrides && super.hasOwnProperty(desc.getNameToken(2))) { try { final GuardedInvocation inv = super.findCallMethodMethod(desc, request); if (inv != null) { return inv; } } catch (final Exception e) { //ignored } } return findHook(desc, __call__); }
Example #15
Source File: NativeString.java From nashorn with GNU General Public License v2.0 | 5 votes |
@Override protected GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) { final String name = desc.getNameToken(2); // if str.length(), then let the bean linker handle it if ("length".equals(name) && "getMethod".equals(operator)) { return null; } return super.findGetMethod(desc, request, operator); }
Example #16
Source File: TypedArrayData.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override public GuardedInvocation findFastGetIndexMethod(final Class<? extends ArrayData> clazz, final CallSiteDescriptor desc, final LinkRequest request) { final GuardedInvocation inv = super.findFastGetIndexMethod(clazz, desc, request); if (inv != null) { return inv; } return null; }
Example #17
Source File: TypedArrayData.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public GuardedInvocation findFastGetIndexMethod(final Class<? extends ArrayData> clazz, final CallSiteDescriptor desc, final LinkRequest request) { final GuardedInvocation inv = super.findFastGetIndexMethod(clazz, desc, request); if (inv != null) { return inv; } return null; }
Example #18
Source File: NashornLinker.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception { final LinkRequest requestWithoutContext = request.withoutRuntimeContext(); // Nashorn has no runtime context final Object self = requestWithoutContext.getReceiver(); final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor(); if (desc.getNameTokenCount() < 2 || !"dyn".equals(desc.getNameToken(CallSiteDescriptor.SCHEME))) { // We only support standard "dyn:*[:*]" operations return null; } return Bootstrap.asTypeSafeReturn(getGuardedInvocation(self, request, desc), linkerServices, desc); }
Example #19
Source File: NashornBeansLinker.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception { final Object self = linkRequest.getReceiver(); final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor(); if (self instanceof ConsString) { // In order to treat ConsString like a java.lang.String we need a link request with a string receiver. final Object[] arguments = linkRequest.getArguments(); arguments[0] = ""; final LinkRequest forgedLinkRequest = linkRequest.replaceArguments(desc, arguments); final GuardedInvocation invocation = getGuardedInvocation(beansLinker, forgedLinkRequest, linkerServices); // If an invocation is found we add a filter that makes it work for both Strings and ConsStrings. return invocation == null ? null : invocation.filterArguments(0, FILTER_CONSSTRING); } if (self != null && "call".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) { // Support dyn:call on any object that supports some @FunctionalInterface // annotated interface. This way Java method, constructor references or // implementations of java.util.function.* interfaces can be called as though // those are script functions. final String name = getFunctionalInterfaceMethodName(self.getClass()); if (name != null) { final MethodType callType = desc.getMethodType(); // drop callee (Undefined ScriptFunction) and change the request to be dyn:callMethod:<name> final NashornCallSiteDescriptor newDesc = NashornCallSiteDescriptor.get(desc.getLookup(), "dyn:callMethod:" + name, desc.getMethodType().dropParameterTypes(1, 2), NashornCallSiteDescriptor.getFlags(desc)); final GuardedInvocation gi = getGuardedInvocation(beansLinker, linkRequest.replaceArguments(newDesc, linkRequest.getArguments()), new NashornBeansLinkerServices(linkerServices)); // drop 'thiz' passed from the script. return gi.replaceMethods( MH.dropArguments(linkerServices.filterInternalObjects(gi.getInvocation()), 1, callType.parameterType(1)), gi.getGuard()); } } return getGuardedInvocation(beansLinker, linkRequest, linkerServices); }
Example #20
Source File: ArrayBufferView.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override protected GuardedInvocation findSetIndexMethod(final CallSiteDescriptor desc, final LinkRequest request) { final GuardedInvocation inv = getArray().findFastSetIndexMethod(getArray().getClass(), desc, request); if (inv != null) { return inv; } return super.findSetIndexMethod(desc, request); }
Example #21
Source File: OptimisticReturnFilters.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Given a guarded invocation and a callsite descriptor, perform return value filtering * according to the optimistic type coercion rules, using the return value from the descriptor * @param inv the invocation * @param desc the descriptor * @return filtered invocation */ public static GuardedInvocation filterOptimisticReturnValue(final GuardedInvocation inv, final CallSiteDescriptor desc) { if(!NashornCallSiteDescriptor.isOptimistic(desc)) { return inv; } return inv.replaceMethods(filterOptimisticReturnValue(inv.getInvocation(), desc.getMethodType().returnType(), NashornCallSiteDescriptor.getProgramPoint(desc)), inv.getGuard()); }
Example #22
Source File: DynamicMethodLinker.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) { final Object receiver = linkRequest.getReceiver(); if(!(receiver instanceof DynamicMethod)) { return null; } final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor(); if(desc.getNameTokenCount() != 2 && desc.getNameToken(CallSiteDescriptor.SCHEME) != "dyn") { return null; } final String operator = desc.getNameToken(CallSiteDescriptor.OPERATOR); final DynamicMethod dynMethod = (DynamicMethod)receiver; final boolean constructor = dynMethod.isConstructor(); final MethodHandle invocation; if (operator == "call" && !constructor) { invocation = dynMethod.getInvocation( CallSiteDescriptorFactory.dropParameterTypes(desc, 0, 1), linkerServices); } else if (operator == "new" && constructor) { final MethodHandle ctorInvocation = dynMethod.getInvocation(desc, linkerServices); if(ctorInvocation == null) { return null; } // Insert null for StaticClass parameter invocation = MethodHandles.insertArguments(ctorInvocation, 0, (Object)null); } else { return null; } if (invocation != null) { return new GuardedInvocation(MethodHandles.dropArguments(invocation, 0, desc.getMethodType().parameterType(0)), Guards.getIdentityGuard(receiver)); } return null; }
Example #23
Source File: DynamicMethodLinker.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) { final Object receiver = linkRequest.getReceiver(); if(!(receiver instanceof DynamicMethod)) { return null; } final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor(); if(desc.getNameTokenCount() != 2 && desc.getNameToken(CallSiteDescriptor.SCHEME) != "dyn") { return null; } final String operator = desc.getNameToken(CallSiteDescriptor.OPERATOR); final DynamicMethod dynMethod = (DynamicMethod)receiver; final boolean constructor = dynMethod.isConstructor(); final MethodHandle invocation; if (operator == "call" && !constructor) { invocation = dynMethod.getInvocation( CallSiteDescriptorFactory.dropParameterTypes(desc, 0, 1), linkerServices); } else if (operator == "new" && constructor) { final MethodHandle ctorInvocation = dynMethod.getInvocation(desc, linkerServices); if(ctorInvocation == null) { return null; } // Insert null for StaticClass parameter invocation = MethodHandles.insertArguments(ctorInvocation, 0, (Object)null); } else { return null; } if (invocation != null) { return new GuardedInvocation(MethodHandles.dropArguments(invocation, 0, desc.getMethodType().parameterType(0)), Guards.getIdentityGuard(receiver)); } return null; }
Example #24
Source File: JSObjectLinker.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private static GuardedInvocation findNewMethod(final CallSiteDescriptor desc) { final MethodHandle func = MH.asCollector(JSOBJECT_NEW, Object[].class, desc.getMethodType().parameterCount() - 1); return new GuardedInvocation(func, IS_JSOBJECT_GUARD); }
Example #25
Source File: Bootstrap.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Override public GuardedInvocation filter(final GuardedInvocation inv, final LinkRequest request, final LinkerServices linkerServices) { final CallSiteDescriptor desc = request.getCallSiteDescriptor(); return OptimisticReturnFilters.filterOptimisticReturnValue(inv, desc).asType(linkerServices, desc.getMethodType()); }
Example #26
Source File: Undefined.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private static GuardedInvocation findGetMethod(final CallSiteDescriptor desc) { return new GuardedInvocation(MH.insertArguments(GET_METHOD, 1, desc.getNameToken(2)), UNDEFINED_GUARD).asType(desc); }
Example #27
Source File: ScriptObject.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private static GuardedInvocation findMegaMorphicSetMethod(final CallSiteDescriptor desc, final String name) { final MethodType type = desc.getMethodType().insertParameterTypes(1, Object.class); final GuardedInvocation inv = findSetIndexMethod(type, NashornCallSiteDescriptor.isStrict(desc)); return inv.replaceMethods(MH.insertArguments(inv.getInvocation(), 1, name), inv.getGuard()); }
Example #28
Source File: SingleDynamicMethod.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Override MethodHandle getInvocation(final CallSiteDescriptor callSiteDescriptor, final LinkerServices linkerServices) { return getInvocation(getTarget(callSiteDescriptor.getLookup()), callSiteDescriptor.getMethodType(), linkerServices); }
Example #29
Source File: DefaultCallSiteDescriptor.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Override public CallSiteDescriptor changeMethodType(final MethodType newMethodType) { return CallSiteDescriptorFactory.getCanonicalPublicDescriptor(new DefaultCallSiteDescriptor(tokenizedName, newMethodType)); }
Example #30
Source File: GlobalConstants.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Try to turn a getter into a MethodHandle.constant, if possible * * @param find property lookup * @param receiver receiver * @param desc callsite descriptor * * @return resulting getter, or null if failed to create constant */ GuardedInvocation findGetMethod(final FindProperty find, final ScriptObject receiver, final CallSiteDescriptor desc) { // Only use constant getter for fast scope access, because the receiver may change between invocations // for slow-scope and non-scope callsites. // Also return null for user accessor properties as they may have side effects. if (invalidatedForever.get() || !NashornCallSiteDescriptor.isFastScope(desc) || (GLOBAL_ONLY && !find.getOwner().isGlobal()) || find.getProperty() instanceof UserAccessorProperty) { return null; } final boolean isOptimistic = NashornCallSiteDescriptor.isOptimistic(desc); final int programPoint = isOptimistic ? getProgramPoint(desc) : INVALID_PROGRAM_POINT; final Class<?> retType = desc.getMethodType().returnType(); final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); synchronized (this) { final Access acc = getOrCreateSwitchPoint(name); log.fine("Starting to look up object value " + name); final Object c = find.getObjectValue(); if (log.isEnabled()) { log.fine("Trying to link constant GETTER " + acc + " value = " + c); } if (acc.hasBeenInvalidated() || acc.guardFailed() || invalidatedForever.get()) { if (log.isEnabled()) { log.info("*** GET: Giving up on " + quote(name) + " - retry count has exceeded " + DynamicLinker.getLinkedCallSiteLocation()); } return null; } final MethodHandle cmh = constantGetter(c); MethodHandle mh; MethodHandle guard; if (isOptimistic) { if (JSType.getAccessorTypeIndex(cmh.type().returnType()) <= JSType.getAccessorTypeIndex(retType)) { //widen return type - this is pessimistic, so it will always work mh = MH.asType(cmh, cmh.type().changeReturnType(retType)); } else { //immediately invalidate - we asked for a too wide constant as a narrower one mh = MH.dropArguments(MH.insertArguments(JSType.THROW_UNWARRANTED.methodHandle(), 0, c, programPoint), 0, Object.class); } } else { //pessimistic return type filter mh = Lookup.filterReturnType(cmh, retType); } if (find.getOwner().isGlobal()) { guard = null; } else { guard = MH.insertArguments(RECEIVER_GUARD, 0, acc, receiver); } if (log.isEnabled()) { log.info("Linked getter " + quote(name) + " as MethodHandle.constant() -> " + c + " " + acc.getSwitchPoint()); mh = MethodHandleFactory.addDebugPrintout(log, Level.FINE, mh, "get const " + acc); } return new GuardedInvocation(mh, guard, acc.getSwitchPoint(), null); } }