jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor Java Examples

The following examples show how to use jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor. 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: Global.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final String name = NashornCallSiteDescriptor.getOperand(desc);
    final boolean isScope = NashornCallSiteDescriptor.isScope(desc);

    if (lexicalScope != null && isScope && !NashornCallSiteDescriptor.isApplyToCall(desc)) {
        if (lexicalScope.hasOwnProperty(name)) {
            return lexicalScope.findGetMethod(desc, request);
        }
    }

    final GuardedInvocation invocation =  super.findGetMethod(desc, request);

    // We want to avoid adding our generic lexical scope switchpoint to global constant invocations,
    // because those are invalidated per-key in the addBoundProperties method above.
    // We therefore check if the invocation does already have a switchpoint and the property is non-inherited,
    // assuming this only applies to global constants. If other non-inherited properties will
    // start using switchpoints some time in the future we'll have to revisit this.
    if (isScope && context.getEnv()._es6 && (invocation.getSwitchPoints() == null || !hasOwnProperty(name))) {
        return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
    }

    return invocation;
}
 
Example #2
Source File: Global.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) {
    final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
    final boolean isScope = NashornCallSiteDescriptor.isScope(desc);

    if (lexicalScope != null && isScope && !NashornCallSiteDescriptor.isApplyToCall(desc)) {
        if (lexicalScope.hasOwnProperty(name)) {
            return lexicalScope.findGetMethod(desc, request, operator);
        }
    }

    final GuardedInvocation invocation =  super.findGetMethod(desc, request, operator);

    // We want to avoid adding our generic lexical scope switchpoint to global constant invocations,
    // because those are invalidated per-key in the addBoundProperties method above.
    // We therefore check if the invocation does already have a switchpoint and the property is non-inherited,
    // assuming this only applies to global constants. If other non-inherited properties will
    // start using switchpoints some time in the future we'll have to revisit this.
    if (isScope && context.getEnv()._es6 && (invocation.getSwitchPoints() == null || !hasOwnProperty(name))) {
        return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
    }

    return invocation;
}
 
Example #3
Source File: ScriptObject.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused")
private static void setSpillWithNew(final CallSiteDescriptor desc, final PropertyMap oldMap, final PropertyMap newMap, final int index, final Object self, final Object value) {
    final ScriptObject obj      = (ScriptObject)self;
    final boolean      isStrict = NashornCallSiteDescriptor.isStrict(desc);

    if (!obj.isExtensible()) {
        if (isStrict) {
            throw typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj));
        }
    } else if (obj.compareAndSetMap(oldMap, newMap)) {
        obj.spill = new Object[SPILL_RATE];
        obj.spill[index] = value;
    } else {
        obj.set(desc.getNameToken(2), value, isStrict);
    }
}
 
Example #4
Source File: ScriptObject.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused")
private static void setSpillWithGrow(final CallSiteDescriptor desc, final PropertyMap oldMap, final PropertyMap newMap, final int index, final int newLength, final Object self, final Object value) {
    final ScriptObject obj      = (ScriptObject)self;
    final boolean      isStrict = NashornCallSiteDescriptor.isStrict(desc);

    if (!obj.isExtensible()) {
        if (isStrict) {
            throw typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj));
        }
    } else if (obj.compareAndSetMap(oldMap, newMap)) {
        final int oldLength = obj.spill.length;
        final Object[] newSpill = new Object[newLength];
        System.arraycopy(obj.spill, 0, newSpill, 0, oldLength);
        obj.spill = newSpill;
        obj.spill[index] = value;
    } else {
        obj.set(desc.getNameToken(2), value, isStrict);
    }
}
 
Example #5
Source File: WithObject.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
private static GuardedInvocation fixExpressionCallSite(final NashornCallSiteDescriptor desc, final GuardedInvocation link) {
    // If it's not a getMethod, just add an expression filter that converts WithObject in "this" position to its
    // expression.
    if(!"getMethod".equals(desc.getFirstOperator())) {
        return fixReceiverType(link, WITHEXPRESSIONFILTER).filterArguments(0, WITHEXPRESSIONFILTER);
    }

    final MethodHandle linkInvocation = link.getInvocation();
    final MethodType linkType = linkInvocation.type();
    final boolean linkReturnsFunction = ScriptFunction.class.isAssignableFrom(linkType.returnType());
    return link.replaceMethods(
            // Make sure getMethod will bind the script functions it receives to WithObject.expression
            MH.foldArguments(linkReturnsFunction ? BIND_TO_EXPRESSION_FN : BIND_TO_EXPRESSION_OBJ,
                    filter(linkInvocation.asType(linkType.changeReturnType(
                            linkReturnsFunction ? ScriptFunction.class : Object.class)), WITHEXPRESSIONFILTER)),
            // No clever things for the guard -- it is still identically filtered.
            filterGuard(link, WITHEXPRESSIONFILTER));
}
 
Example #6
Source File: Global.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final boolean isScope = NashornCallSiteDescriptor.isScope(desc);

    if (lexicalScope != null && isScope) {
        final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
        if (lexicalScope.hasOwnProperty(name)) {
            return lexicalScope.findSetMethod(desc, request);
        }
    }

    final GuardedInvocation invocation = super.findSetMethod(desc, request);

    if (isScope && context.getEnv()._es6) {
        return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
    }

    return invocation;
}
 
Example #7
Source File: Global.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final boolean isScope = NashornCallSiteDescriptor.isScope(desc);

    if (lexicalScope != null && isScope) {
        final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
        if (lexicalScope.hasOwnProperty(name)) {
            return lexicalScope.findSetMethod(desc, request);
        }
    }

    final GuardedInvocation invocation = super.findSetMethod(desc, request);

    if (isScope && context.getEnv()._es6) {
        return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
    }

    return invocation;
}
 
Example #8
Source File: ScriptObject.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 Object value = getObjectValue(find);
    if (! (value instanceof ScriptFunction)) {
        return createEmptyGetter(desc, name);
    }

    final ScriptFunction func = (ScriptFunction)value;
    final Object thiz = scopeCall && func.isStrict() ? ScriptRuntime.UNDEFINED : this;
    // TODO: It'd be awesome if we could bind "name" without binding "this".
    return new GuardedInvocation(MH.dropArguments(MH.constant(ScriptFunction.class,
            func.makeBoundFunction(thiz, new Object[] { name })), 0, Object.class),
            null, NashornGuards.getMapGuard(getMap()));
}
 
Example #9
Source File: WithObject.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static GuardedInvocation fixExpressionCallSite(final NashornCallSiteDescriptor desc, final GuardedInvocation link) {
    // If it's not a getMethod, just add an expression filter that converts WithObject in "this" position to its
    // expression.
    if(!"getMethod".equals(desc.getFirstOperator())) {
        return fixReceiverType(link, WITHEXPRESSIONFILTER).filterArguments(0, WITHEXPRESSIONFILTER);
    }

    final MethodHandle linkInvocation = link.getInvocation();
    final MethodType linkType = linkInvocation.type();
    final boolean linkReturnsFunction = ScriptFunction.class.isAssignableFrom(linkType.returnType());
    return link.replaceMethods(
            // Make sure getMethod will bind the script functions it receives to WithObject.expression
            MH.foldArguments(linkReturnsFunction ? BIND_TO_EXPRESSION_FN : BIND_TO_EXPRESSION_OBJ,
                    filter(linkInvocation.asType(linkType.changeReturnType(
                            linkReturnsFunction ? ScriptFunction.class : Object.class)), WITHEXPRESSIONFILTER)),
            // No clever things for the guard -- it is still identically filtered.
            filterGuard(link, WITHEXPRESSIONFILTER));
}
 
Example #10
Source File: ContinuousArrayData.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a fast linked array getter, or null if we have to dispatch to super class
 * @param desc     descriptor
 * @param request  link request
 * @return invocation or null if needs to be sent to slow relink
 */
@Override
public GuardedInvocation findFastGetIndexMethod(final Class<? extends ArrayData> clazz, final CallSiteDescriptor desc, final LinkRequest request) {
    final MethodType callType   = desc.getMethodType();
    final Class<?>   indexType  = callType.parameterType(1);
    final Class<?>   returnType = callType.returnType();

    if (ContinuousArrayData.class.isAssignableFrom(clazz) && indexType == int.class) {
        final Object[] args  = request.getArguments();
        final int      index = (int)args[args.length - 1];

        if (has(index)) {
            final MethodHandle getArray     = ScriptObject.GET_ARRAY.methodHandle();
            final int          programPoint = NashornCallSiteDescriptor.isOptimistic(desc) ? NashornCallSiteDescriptor.getProgramPoint(desc) : INVALID_PROGRAM_POINT;
            MethodHandle       getElement   = getElementGetter(returnType, programPoint);
            if (getElement != null) {
                getElement = MH.filterArguments(getElement, 0, MH.asType(getArray, getArray.type().changeReturnType(clazz)));
                final MethodHandle guard = MH.insertArguments(FAST_ACCESS_GUARD, 0, clazz);
                return new GuardedInvocation(getElement, guard, (SwitchPoint)null, ClassCastException.class);
            }
        }
    }

    return null;
}
 
Example #11
Source File: ScriptObject.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 Object value = getObjectValue(find);
    if (! (value instanceof ScriptFunction)) {
        return createEmptyGetter(desc, name);
    }

    final ScriptFunction func = (ScriptFunction)value;
    final Object thiz = scopeCall && func.isStrict() ? ScriptRuntime.UNDEFINED : this;
    // TODO: It'd be awesome if we could bind "name" without binding "this".
    return new GuardedInvocation(MH.dropArguments(MH.constant(ScriptFunction.class,
            func.makeBoundFunction(thiz, new Object[] { name })), 0, Object.class),
            null, NashornGuards.getMapGuard(getMap()));
}
 
Example #12
Source File: ScriptObject.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 Object value = getObjectValue(find);
    if (! (value instanceof ScriptFunction)) {
        return createEmptyGetter(desc, name);
    }

    final ScriptFunction func = (ScriptFunction)value;
    final Object thiz = scopeCall && func.isStrict() ? ScriptRuntime.UNDEFINED : this;
    // TODO: It'd be awesome if we could bind "name" without binding "this".
    return new GuardedInvocation(MH.dropArguments(MH.constant(ScriptFunction.class,
            func.makeBoundFunction(thiz, new Object[] { name })), 0, Object.class),
            null, NashornGuards.getMapGuard(getMap()));
}
 
Example #13
Source File: OptimisticReturnFilters.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #14
Source File: SetMethodCreator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void checkStrictCreateNewVariable() {
    // In strict mode, assignment can not create a new variable.
    // See also ECMA Annex C item 4. ReferenceError is thrown.
    if (NashornCallSiteDescriptor.isScope(desc) && NashornCallSiteDescriptor.isStrict(desc)) {
        throw referenceError("not.defined", getName());
    }
}
 
Example #15
Source File: ScriptObject.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find a handle for a getIndex method
 * @param returnType     return type for getter
 * @param name           name
 * @param elementType    index type for getter
 * @param desc           call site descriptor
 * @return method handle for getter
 */
private static MethodHandle findGetIndexMethodHandle(final Class<?> returnType, final String name, final Class<?> elementType, final CallSiteDescriptor desc) {
    if (!returnType.isPrimitive()) {
        return findOwnMH_V(name, returnType, elementType);
    }

    return MH.insertArguments(
            findOwnMH_V(name, returnType, elementType, int.class),
            2,
            NashornCallSiteDescriptor.isOptimistic(desc) ?
                    NashornCallSiteDescriptor.getProgramPoint(desc) :
                    INVALID_PROGRAM_POINT);
}
 
Example #16
Source File: SetMethodCreator.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private void checkStrictCreateNewVariable() {
    // In strict mode, assignment can not create a new variable.
    // See also ECMA Annex C item 4. ReferenceError is thrown.
    if (NashornCallSiteDescriptor.isScope(desc) && NashornCallSiteDescriptor.isStrict(desc)) {
        throw referenceError("not.defined", getName());
    }
}
 
Example #17
Source File: ScriptObject.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private GuardedInvocation createEmptyGetter(final CallSiteDescriptor desc, final boolean explicitInstanceOfCheck, final String name) {
    if (NashornCallSiteDescriptor.isOptimistic(desc)) {
        throw new UnwarrantedOptimismException(UNDEFINED, NashornCallSiteDescriptor.getProgramPoint(desc), Type.OBJECT);
    }

    return new GuardedInvocation(Lookup.emptyGetter(desc.getMethodType().returnType()),
            NashornGuards.getMapGuard(getMap(), explicitInstanceOfCheck), getProtoSwitchPoints(name, null),
            explicitInstanceOfCheck ? null : ClassCastException.class);
}
 
Example #18
Source File: ScriptObject.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #19
Source File: Undefined.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Lookup the appropriate method for an invoke dynamic call.
 * @param desc The invoke dynamic callsite descriptor.
 * @return GuardedInvocation to be invoked at call site.
 */
public static GuardedInvocation lookup(final CallSiteDescriptor desc) {
    final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);

    switch (operator) {
    case "new":
    case "call": {
        final String name = NashornCallSiteDescriptor.getFunctionDescription(desc);
        final String msg = name != null? "not.a.function" : "cant.call.undefined";
        throw typeError(msg, name);
    }

    case "callMethod":
        throw lookupTypeError("cant.read.property.of.undefined", desc);
    // NOTE: we support getElem and setItem as JavaScript doesn't distinguish items from properties. Nashorn itself
    // emits "dyn:getProp:identifier" for "<expr>.<identifier>" and "dyn:getElem" for "<expr>[<expr>]", but we are
    // more flexible here and dispatch not on operation name (getProp vs. getElem), but rather on whether the
    // operation has an associated name or not.
    case "getProp":
    case "getElem":
    case "getMethod":
        if (desc.getNameTokenCount() < 3) {
            return findGetIndexMethod(desc);
        }
        return findGetMethod(desc);
    case "setProp":
    case "setElem":
        if (desc.getNameTokenCount() < 3) {
            return findSetIndexMethod(desc);
        }
        return findSetMethod(desc);
    default:
        break;
    }

    return null;
}
 
Example #20
Source File: ScriptObject.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private GuardedInvocation createEmptyGetter(final CallSiteDescriptor desc, final boolean explicitInstanceOfCheck, final String name) {
    if (NashornCallSiteDescriptor.isOptimistic(desc)) {
        throw new UnwarrantedOptimismException(UNDEFINED, NashornCallSiteDescriptor.getProgramPoint(desc), Type.OBJECT);
    }

    return new GuardedInvocation(Lookup.emptyGetter(desc.getMethodType().returnType()),
            NashornGuards.getMapGuard(getMap(), explicitInstanceOfCheck), getProtoSwitchPoints(name, null),
            explicitInstanceOfCheck ? null : ClassCastException.class);
}
 
Example #21
Source File: ScriptObject.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Fall back if a property is not found.
 * @param desc the call site descriptor.
 * @param request the link request
 * @return GuardedInvocation to be invoked at call site.
 */
@SuppressWarnings("null")
public GuardedInvocation noSuchProperty(final CallSiteDescriptor desc, final LinkRequest request) {
    final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
    final FindProperty find = findProperty(NO_SUCH_PROPERTY_NAME, true);
    final boolean scopeAccess = isScope() && NashornCallSiteDescriptor.isScope(desc);

    if (find != null) {
        final Object   value        = getObjectValue(find);
        ScriptFunction func         = null;
        MethodHandle   methodHandle = null;

        if (value instanceof ScriptFunction) {
            func = (ScriptFunction)value;
            methodHandle = getCallMethodHandle(func, desc.getMethodType(), name);
        }

        if (methodHandle != null) {
            if (scopeAccess && func.isStrict()) {
                methodHandle = bindTo(methodHandle, UNDEFINED);
            }
            return new GuardedInvocation(methodHandle,
                    find.isInherited()? getMap().getProtoGetSwitchPoint(proto, NO_SUCH_PROPERTY_NAME) : null,
                    getKnownFunctionPropertyGuard(getMap(), find.getGetter(Object.class), find.getOwner(), func));
        }
    }

    if (scopeAccess) {
        throw referenceError("not.defined", name);
    }

    return createEmptyGetter(desc, name);
}
 
Example #22
Source File: ScriptObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #23
Source File: NativeDebug.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static LinkedList<RuntimeEvent<?>> getEventQueue(final Object self) {
    final ScriptObject sobj = (ScriptObject)self;
    LinkedList<RuntimeEvent<?>> q;
    if (sobj.has(EVENT_QUEUE)) {
        q = (LinkedList<RuntimeEvent<?>>)((ScriptObject)self).get(EVENT_QUEUE);
    } else {
        ((ScriptObject)self).set(EVENT_QUEUE, q = new LinkedList<>(), NashornCallSiteDescriptor.CALLSITE_STRICT);
    }
    return q;
}
 
Example #24
Source File: Undefined.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Lookup the appropriate method for an invoke dynamic call.
 * @param desc The invoke dynamic callsite descriptor.
 * @return GuardedInvocation to be invoked at call site.
 */
public static GuardedInvocation lookup(final CallSiteDescriptor desc) {
    final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);

    switch (operator) {
    case "new":
    case "call": {
        final String name = NashornCallSiteDescriptor.getFunctionDescription(desc);
        final String msg = name != null? "not.a.function" : "cant.call.undefined";
        throw typeError(msg, name);
    }

    case "callMethod":
        throw lookupTypeError("cant.read.property.of.undefined", desc);
    // NOTE: we support getElem and setItem as JavaScript doesn't distinguish items from properties. Nashorn itself
    // emits "dyn:getProp:identifier" for "<expr>.<identifier>" and "dyn:getElem" for "<expr>[<expr>]", but we are
    // more flexible here and dispatch not on operation name (getProp vs. getElem), but rather on whether the
    // operation has an associated name or not.
    case "getProp":
    case "getElem":
    case "getMethod":
        if (desc.getNameTokenCount() < 3) {
            return findGetIndexMethod(desc);
        }
        return findGetMethod(desc);
    case "setProp":
    case "setElem":
        if (desc.getNameTokenCount() < 3) {
            return findSetIndexMethod(desc);
        }
        return findSetMethod(desc);
    default:
        break;
    }

    return null;
}
 
Example #25
Source File: MethodEmitter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate a dynamic call
 *
 * @param returnType return type
 * @param argCount   number of arguments
 * @param flags      callsite flags
 * @param msg        additional message to be used when reporting error
 *
 * @return the method emitter
 */
MethodEmitter dynamicCall(final Type returnType, final int argCount, final int flags, final String msg) {
    debug("dynamic_call", "args=", argCount, "returnType=", returnType);
    final String signature = getDynamicSignature(returnType, argCount); // +1 because the function itself is the 1st parameter for dynamic calls (what you call - call target)
    debug("   signature", signature);
    method.visitInvokeDynamicInsn(
            msg != null && msg.length() < LARGE_STRING_THRESHOLD? NameCodec.encode(msg) : EMPTY_NAME,
            signature, LINKERBOOTSTRAP, flags | NashornCallSiteDescriptor.CALL);
    pushType(returnType);

    return this;
}
 
Example #26
Source File: Undefined.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Lookup the appropriate method for an invoke dynamic call.
 * @param desc The invoke dynamic callsite descriptor.
 * @return GuardedInvocation to be invoked at call site.
 */
public static GuardedInvocation lookup(final CallSiteDescriptor desc) {
    final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);

    switch (operator) {
    case "new":
    case "call": {
        final String name = NashornCallSiteDescriptor.getFunctionDescription(desc);
        final String msg = name != null? "not.a.function" : "cant.call.undefined";
        throw typeError(msg, name);
    }

    case "callMethod":
        throw lookupTypeError("cant.read.property.of.undefined", desc);
    // NOTE: we support getElem and setItem as JavaScript doesn't distinguish items from properties. Nashorn itself
    // emits "dyn:getProp:identifier" for "<expr>.<identifier>" and "dyn:getElem" for "<expr>[<expr>]", but we are
    // more flexible here and dispatch not on operation name (getProp vs. getElem), but rather on whether the
    // operation has an associated name or not.
    case "getProp":
    case "getElem":
    case "getMethod":
        if (desc.getNameTokenCount() < 3) {
            return findGetIndexMethod(desc);
        }
        return findGetMethod(desc);
    case "setProp":
    case "setElem":
        if (desc.getNameTokenCount() < 3) {
            return findSetIndexMethod(desc);
        }
        return findSetMethod(desc);
    default:
        break;
    }

    return null;
}
 
Example #27
Source File: UserAccessorProperty.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static MethodHandle getINVOKE_UA_GETTER(final Class<?> returnType, final int programPoint) {
    if (UnwarrantedOptimismException.isValid(programPoint)) {
        final int flags = NashornCallSiteDescriptor.CALLSITE_OPTIMISTIC | programPoint << CALLSITE_PROGRAM_POINT_SHIFT;
        return Bootstrap.createDynamicInvoker("dyn:call", flags, returnType, Object.class, Object.class);
    } else {
        return Bootstrap.createDynamicInvoker("dyn:call", Object.class, Object.class, Object.class);
    }
}
 
Example #28
Source File: SetMethodCreator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void checkStrictCreateNewVariable() {
    // In strict mode, assignment can not create a new variable.
    // See also ECMA Annex C item 4. ReferenceError is thrown.
    if (NashornCallSiteDescriptor.isScope(desc) && NashornCallSiteDescriptor.isStrict(desc)) {
        throw referenceError("not.defined", getName());
    }
}
 
Example #29
Source File: WithObject.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static GuardedInvocation fixExpressionCallSite(final NashornCallSiteDescriptor desc, final GuardedInvocation link) {
    // If it's not a getMethod, just add an expression filter that converts WithObject in "this" position to its
    // expression.
    if (!"getMethod".equals(desc.getFirstOperator())) {
        return fixReceiverType(link, WITHEXPRESSIONFILTER).filterArguments(0, WITHEXPRESSIONFILTER);
    }

    final MethodHandle linkInvocation      = link.getInvocation();
    final MethodType   linkType            = linkInvocation.type();
    final boolean      linkReturnsFunction = ScriptFunction.class.isAssignableFrom(linkType.returnType());

    return link.replaceMethods(
            // Make sure getMethod will bind the script functions it receives to WithObject.expression
            MH.foldArguments(
                    linkReturnsFunction ?
                            BIND_TO_EXPRESSION_FN :
                            BIND_TO_EXPRESSION_OBJ,
                    filterReceiver(
                            linkInvocation.asType(
                                    linkType.changeReturnType(
                                            linkReturnsFunction ?
                                                    ScriptFunction.class :
                                                    Object.class).
                                                        changeParameterType(
                                                                0,
                                                                Object.class)),
                                    WITHEXPRESSIONFILTER)),
                     filterGuardReceiver(link, WITHEXPRESSIONFILTER));
 // No clever things for the guard -- it is still identically filtered.

}
 
Example #30
Source File: NativeJavaPackage.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handle creation of new attribute.
 * @param desc the call site descriptor
 * @param request the link request
 * @return Link to be invoked at call site.
 */
@Override
public GuardedInvocation noSuchProperty(final CallSiteDescriptor desc, final LinkRequest request) {
    final String propertyName = NashornCallSiteDescriptor.getOperand(desc);
    createProperty(propertyName);
    return super.lookup(desc, request);
}