Java Code Examples for jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor#isFastScope()

The following examples show how to use jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor#isFastScope() . 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: 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);
    }
}
 
Example 2
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 3
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 4
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 5
Source File: GlobalConstants.java    From openjdk-jdk9 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         = NashornCallSiteDescriptor.getOperand(desc);

    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 6
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 7
Source File: SetMethodCreator.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private boolean needsNoGuard() {
    return NashornCallSiteDescriptor.isFastScope(desc) &&
            (ObjectClassGenerator.OBJECT_FIELDS_ONLY || isPropertyTypeStable());
}
 
Example 8
Source File: SetMethodCreator.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean needsNoGuard() {
    return NashornCallSiteDescriptor.isFastScope(desc) &&
            (ObjectClassGenerator.OBJECT_FIELDS_ONLY || isPropertyTypeStable());
}
 
Example 9
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 10
Source File: SetMethodCreator.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
private boolean needsNoGuard() {
    return NashornCallSiteDescriptor.isFastScope(desc) &&
            (ObjectClassGenerator.OBJECT_FIELDS_ONLY || isPropertyTypeStable());
}