Java Code Examples for jdk.nashorn.internal.lookup.Lookup#filterReturnType()

The following examples show how to use jdk.nashorn.internal.lookup.Lookup#filterReturnType() . 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: ContinuousArrayData.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return element getter for a {@link ContinuousArrayData}
 * @param clazz        clazz for exact type guard
 * @param getHas       has getter
 * @param returnType   return type
 * @param programPoint program point
 * @return method handle for element setter
 */
protected MethodHandle getContinuousElementGetter(final Class<? extends ContinuousArrayData> clazz, final MethodHandle getHas, final Class<?> returnType, final int programPoint) {
    final boolean isOptimistic = isValid(programPoint);
    final int     fti          = getAccessorTypeIndex(getHas.type().returnType());
    final int     ti           = getAccessorTypeIndex(returnType);
    MethodHandle  mh           = getHas;

    if (isOptimistic) {
        if (ti < fti) {
            mh = MH.insertArguments(ArrayData.THROW_UNWARRANTED.methodHandle(), 1, programPoint);
        }
    }
    mh = MH.asType(mh, mh.type().changeReturnType(returnType).changeParameterType(0, clazz));

    if (!isOptimistic) {
        //for example a & array[17];
        return Lookup.filterReturnType(mh, returnType);
    }
    return mh;
}
 
Example 2
Source File: ContinuousArrayData.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return element getter for a {@link ContinuousArrayData}
 * @param clazz        clazz for exact type guard
 * @param getHas       has getter
 * @param returnType   return type
 * @param programPoint program point
 * @return method handle for element setter
 */
protected MethodHandle getContinuousElementGetter(final Class<? extends ContinuousArrayData> clazz, final MethodHandle getHas, final Class<?> returnType, final int programPoint) {
    final boolean isOptimistic = isValid(programPoint);
    final int     fti          = getAccessorTypeIndex(getHas.type().returnType());
    final int     ti           = getAccessorTypeIndex(returnType);
    MethodHandle  mh           = getHas;

    if (isOptimistic) {
        if (ti < fti) {
            mh = MH.insertArguments(ArrayData.THROW_UNWARRANTED.methodHandle(), 1, programPoint);
        }
    }
    mh = MH.asType(mh, mh.type().changeReturnType(returnType).changeParameterType(0, clazz));

    if (!isOptimistic) {
        //for example a & array[17];
        return Lookup.filterReturnType(mh, returnType);
    }
    return mh;
}
 
Example 3
Source File: ContinuousArrayData.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return element getter for a {@link ContinuousArrayData}
 * @param clazz        clazz for exact type guard
 * @param getHas       has getter
 * @param returnType   return type
 * @param programPoint program point
 * @return method handle for element setter
 */
protected MethodHandle getContinuousElementGetter(final Class<? extends ContinuousArrayData> clazz, final MethodHandle getHas, final Class<?> returnType, final int programPoint) {
    final boolean isOptimistic = isValid(programPoint);
    final int     fti          = getAccessorTypeIndex(getHas.type().returnType());
    final int     ti           = getAccessorTypeIndex(returnType);
    MethodHandle  mh           = getHas;

    if (isOptimistic) {
        if (ti < fti) {
            mh = MH.insertArguments(ArrayData.THROW_UNWARRANTED.methodHandle(), 1, programPoint);
        }
    }
    mh = MH.asType(mh, mh.type().changeReturnType(returnType).changeParameterType(0, clazz));

    if (!isOptimistic) {
        //for example a & array[17];
        return Lookup.filterReturnType(mh, returnType);
    }
    return mh;
}
 
Example 4
Source File: ContinuousArrayData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return element getter for a {@link ContinuousArrayData}
 * @param clazz        clazz for exact type guard
 * @param getHas       has getter
 * @param returnType   return type
 * @param programPoint program point
 * @return method handle for element setter
 */
protected MethodHandle getContinuousElementGetter(final Class<? extends ContinuousArrayData> clazz, final MethodHandle getHas, final Class<?> returnType, final int programPoint) {
    final boolean isOptimistic = isValid(programPoint);
    final int     fti          = getAccessorTypeIndex(getHas.type().returnType());
    final int     ti           = getAccessorTypeIndex(returnType);
    MethodHandle  mh           = getHas;

    if (isOptimistic) {
        if (ti < fti) {
            mh = MH.insertArguments(ArrayData.THROW_UNWARRANTED.methodHandle(), 1, programPoint);
        }
    }
    mh = MH.asType(mh, mh.type().changeReturnType(returnType).changeParameterType(0, clazz));

    if (!isOptimistic) {
        //for example a & array[17];
        return Lookup.filterReturnType(mh, returnType);
    }
    return mh;
}
 
Example 5
Source File: TypedArrayData.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public MethodHandle getElementGetter(final Class<?> returnType, final int programPoint) {
    final MethodHandle getter = getContinuousElementGetter(getClass(), getGetElem(), returnType, programPoint);
    if (getter != null) {
        return Lookup.filterReturnType(getter, returnType);
    }
    return getter;
}
 
Example 6
Source File: TypedArrayData.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public MethodHandle getElementGetter(final Class<?> returnType, final int programPoint) {
    final MethodHandle getter = getContinuousElementGetter(getClass(), getGetElem(), returnType, programPoint);
    if (getter != null) {
        return Lookup.filterReturnType(getter, returnType);
    }
    return getter;
}
 
Example 7
Source File: TypedArrayData.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public MethodHandle getElementGetter(final Class<?> returnType, final int programPoint) {
    final MethodHandle getter = getContinuousElementGetter(getClass(), getGetElem(), returnType, programPoint);
    if (getter != null) {
        return Lookup.filterReturnType(getter, returnType);
    }
    return getter;
}
 
Example 8
Source File: UserAccessorProperty.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MethodHandle getGetter(final Class<?> type) {
    //this returns a getter on the format (Accessors, Object receiver)
    return Lookup.filterReturnType(INVOKE_OBJECT_GETTER, type);
}
 
Example 9
Source File: UserAccessorProperty.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MethodHandle getGetter(final Class<?> type) {
    //this returns a getter on the format (Accessors, Object receiver)
    return Lookup.filterReturnType(INVOKE_OBJECT_GETTER, type);
}
 
Example 10
Source File: UserAccessorProperty.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MethodHandle getGetter(final Class<?> type) {
    //this returns a getter on the format (Accessors, Object receiver)
    return Lookup.filterReturnType(INVOKE_OBJECT_GETTER, type);
}
 
Example 11
Source File: GlobalConstants.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example 12
Source File: UserAccessorProperty.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MethodHandle getGetter(final Class<?> type) {
    return Lookup.filterReturnType(USER_ACCESSOR_GETTER.methodHandle(), type);
}
 
Example 13
Source File: GlobalConstants.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example 14
Source File: GlobalConstants.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example 15
Source File: GlobalConstants.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example 16
Source File: UserAccessorProperty.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MethodHandle getGetter(final Class<?> type) {
    //this returns a getter on the format (Accessors, Object receiver)
    return Lookup.filterReturnType(INVOKE_OBJECT_GETTER, type);
}
 
Example 17
Source File: GlobalConstants.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example 18
Source File: UserAccessorProperty.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MethodHandle getGetter(final Class<?> type) {
    //this returns a getter on the format (Accessors, Object receiver)
    return Lookup.filterReturnType(INVOKE_OBJECT_GETTER, type);
}
 
Example 19
Source File: UserAccessorProperty.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MethodHandle getGetter(final Class<?> type) {
    //this returns a getter on the format (Accessors, Object receiver)
    return Lookup.filterReturnType(INVOKE_OBJECT_GETTER, type);
}
 
Example 20
Source File: GlobalConstants.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
    }
}