Java Code Examples for jdk.internal.dynalink.linker.LinkerServices

The following examples show how to use jdk.internal.dynalink.linker.LinkerServices. These examples are extracted from open source projects. 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 Project: TencentKona-8   Author: Tencent   File: JSObjectLinker.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 #2
Source Project: TencentKona-8   Author: Tencent   File: AbstractJavaLinker.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices)
        throws Exception {
    final LinkRequest ncrequest = request.withoutRuntimeContext();
    // BeansLinker already checked that the name is at least 2 elements long and the first element is "dyn".
    final CallSiteDescriptor callSiteDescriptor = ncrequest.getCallSiteDescriptor();
    final String op = callSiteDescriptor.getNameToken(CallSiteDescriptor.OPERATOR);
    // Either dyn:callMethod:name(this[,args]) or dyn:callMethod(this,name[,args]).
    if("callMethod" == op) {
        return getCallPropWithThis(callSiteDescriptor, linkerServices);
    }
    List<String> operations = CallSiteDescriptorFactory.tokenizeOperators(callSiteDescriptor);
    while(!operations.isEmpty()) {
        final GuardedInvocationComponent gic = getGuardedInvocationComponent(callSiteDescriptor, linkerServices,
                operations);
        if(gic != null) {
            return gic.getGuardedInvocation();
        }
        operations = pop(operations);
    }
    return null;
}
 
Example #3
Source Project: TencentKona-8   Author: Tencent   File: AbstractJavaLinker.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected GuardedInvocationComponent getGuardedInvocationComponent(final CallSiteDescriptor callSiteDescriptor,
        final LinkerServices linkerServices, final List<String> operations) throws Exception {
    if(operations.isEmpty()) {
        return null;
    }
    final String op = operations.get(0);
    // Either dyn:getProp:name(this) or dyn:getProp(this, name)
    if("getProp".equals(op)) {
        return getPropertyGetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    // Either dyn:setProp:name(this, value) or dyn:setProp(this, name, value)
    if("setProp".equals(op)) {
        return getPropertySetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    // Either dyn:getMethod:name(this), or dyn:getMethod(this, name)
    if("getMethod".equals(op)) {
        return getMethodGetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    return null;
}
 
Example #4
Source Project: openjdk-8-source   Author: keerath   File: AbstractJavaLinker.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected GuardedInvocationComponent getGuardedInvocationComponent(CallSiteDescriptor callSiteDescriptor,
        LinkerServices linkerServices, List<String> operations) throws Exception {
    if(operations.isEmpty()) {
        return null;
    }
    final String op = operations.get(0);
    // Either dyn:getProp:name(this) or dyn:getProp(this, name)
    if("getProp".equals(op)) {
        return getPropertyGetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    // Either dyn:setProp:name(this, value) or dyn:setProp(this, name, value)
    if("setProp".equals(op)) {
        return getPropertySetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    // Either dyn:getMethod:name(this), or dyn:getMethod(this, name)
    if("getMethod".equals(op)) {
        return getMethodGetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    return null;
}
 
Example #5
Source Project: openjdk-8   Author: bpupadhyaya   File: BeansLinker.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(LinkRequest request, final LinkerServices linkerServices)
        throws Exception {
    final CallSiteDescriptor callSiteDescriptor = request.getCallSiteDescriptor();
    final int l = callSiteDescriptor.getNameTokenCount();
    // All names conforming to the dynalang MOP should have at least two tokens, the first one being "dyn"
    if(l < 2 || "dyn" != callSiteDescriptor.getNameToken(CallSiteDescriptor.SCHEME)) {
        return null;
    }

    final Object receiver = request.getReceiver();
    if(receiver == null) {
        // Can't operate on null
        return null;
    }
    return getLinkerForClass(receiver.getClass()).getGuardedInvocation(request, linkerServices);
}
 
Example #6
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: NashornPrimitiveLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest origRequest, final LinkerServices linkerServices)
        throws Exception {
    final LinkRequest request = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context

    final Object self = request.getReceiver();
    final NashornCallSiteDescriptor desc = (NashornCallSiteDescriptor) request.getCallSiteDescriptor();

    return Bootstrap.asTypeSafeReturn(Global.primitiveLookup(request, self), linkerServices, desc);
}
 
Example #7
Source Project: nashorn   Author: ynsn   File: CompositeGuardingDynamicLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest, final LinkerServices linkerServices)
        throws Exception {
    for(final GuardingDynamicLinker linker: linkers) {
        final GuardedInvocation invocation = linker.getGuardedInvocation(linkRequest, linkerServices);
        if(invocation != null) {
            return invocation;
        }
    }
    return null;
}
 
Example #8
Source Project: hottub   Author: dsrg-uoft   File: DynamicMethodLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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 #9
Source Project: hottub   Author: dsrg-uoft   File: NashornBottomLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices)
        throws Exception {
    final Object self = linkRequest.getReceiver();

    if (self == null) {
        return linkNull(linkRequest);
    }

    // None of the objects that can be linked by NashornLinker should ever reach here. Basically, anything below
    // this point is a generic Java bean. Therefore, reaching here with a ScriptObject is a Nashorn bug.
    assert isExpectedObject(self) : "Couldn't link " + linkRequest.getCallSiteDescriptor() + " for " + self.getClass().getName();

    return linkBean(linkRequest, linkerServices);
}
 
Example #10
Source Project: nashorn   Author: ynsn   File: ClassString.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns all methods that are applicable to actual parameter classes represented by this ClassString object.
 */
LinkedList<MethodHandle> getApplicables(List<MethodHandle> methods, LinkerServices linkerServices, boolean varArg) {
    final LinkedList<MethodHandle> list = new LinkedList<>();
    for(final MethodHandle member: methods) {
        if(isApplicable(member, linkerServices, varArg)) {
            list.add(member);
        }
    }
    return list;
}
 
Example #11
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison compare(final Class<?> c1, final Class<?> c2, final Class<?>[] argTypes, final int i, final LinkerServices cmp) {
    if(cmp != null) {
        final Comparison c = cmp.compareConversion(argTypes[i], c1, c2);
        if(c != Comparison.INDETERMINATE) {
            return c;
        }
    }
    if(TypeUtilities.isSubtype(c1, c2)) {
        return Comparison.TYPE_1_BETTER;
    } if(TypeUtilities.isSubtype(c2, c1)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #12
Source Project: TencentKona-8   Author: Tencent   File: OverloadedMethod.java    License: GNU General Public License v2.0 5 votes vote down vote up
OverloadedMethod(final List<MethodHandle> methodHandles, final OverloadedDynamicMethod parent, final MethodType callSiteType,
        final LinkerServices linkerServices) {
    this.parent = parent;
    final Class<?> commonRetType = getCommonReturnType(methodHandles);
    this.callSiteType = callSiteType.changeReturnType(commonRetType);
    this.linkerServices = linkerServices;

    fixArgMethods = new ArrayList<>(methodHandles.size());
    varArgMethods = new ArrayList<>(methodHandles.size());
    final int argNum = callSiteType.parameterCount();
    for(MethodHandle mh: methodHandles) {
        if(mh.isVarargsCollector()) {
            final MethodHandle asFixed = mh.asFixedArity();
            if(argNum == asFixed.type().parameterCount()) {
                fixArgMethods.add(asFixed);
            }
            varArgMethods.add(mh);
        } else {
            fixArgMethods.add(mh);
        }
    }
    fixArgMethods.trimToSize();
    varArgMethods.trimToSize();

    final MethodHandle bound = SELECT_METHOD.bindTo(this);
    final MethodHandle collecting = SingleDynamicMethod.collectArguments(bound, argNum).asType(
            callSiteType.changeReturnType(MethodHandle.class));
    invoker = linkerServices.asTypeLosslessReturn(MethodHandles.foldArguments(
            MethodHandles.exactInvoker(this.callSiteType), collecting), callSiteType);
}
 
Example #13
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ClassString.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if the supplied method is applicable to actual parameter classes represented by this ClassString
 * object.
 *
 */
private boolean isApplicable(final MethodHandle method, final LinkerServices linkerServices, final boolean varArg) {
    final Class<?>[] formalTypes = method.type().parameterArray();
    final int cl = classes.length;
    final int fl = formalTypes.length - (varArg ? 1 : 0);
    if(varArg) {
        if(cl < fl) {
            return false;
        }
    } else {
        if(cl != fl) {
            return false;
        }
    }
    // Starting from 1 as we ignore the receiver type
    for(int i = 1; i < fl; ++i) {
        if(!canConvert(linkerServices, classes[i], formalTypes[i])) {
            return false;
        }
    }
    if(varArg) {
        final Class<?> varArgType = formalTypes[fl].getComponentType();
        for(int i = fl; i < cl; ++i) {
            if(!canConvert(linkerServices, classes[i], varArgType)) {
                return false;
            }
        }
    }
    return true;
}
 
Example #14
Source Project: jdk8u_nashorn   Author: JetBrains   File: BeanLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static MethodHandle convertArgToInt(final MethodHandle mh, final LinkerServices ls, final 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 #15
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: CompositeTypeBasedGuardingDynamicLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices)
        throws Exception {
    final Object obj = linkRequest.getReceiver();
    if(obj == null) {
        return null;
    }
    for(final TypeBasedGuardingDynamicLinker linker: classToLinker.get(obj.getClass())) {
        final GuardedInvocation invocation = linker.getGuardedInvocation(linkRequest, linkerServices);
        if(invocation != null) {
            return invocation;
        }
    }
    return null;
}
 
Example #16
Source Project: openjdk-8-source   Author: keerath   File: StaticClassLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(LinkRequest request, LinkerServices linkerServices) throws Exception {
    final Object receiver = request.getReceiver();
    if(receiver instanceof StaticClass) {
        return linkers.get(((StaticClass)receiver).getRepresentedClass()).getGuardedInvocation(request,
                linkerServices);
    }
    return null;
}
 
Example #17
Source Project: openjdk-8-source   Author: keerath   File: BeanLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
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 #18
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: NashornBeansLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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 #19
Source Project: TencentKona-8   Author: Tencent   File: ClassString.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if the supplied method is applicable to actual parameter classes represented by this ClassString
 * object.
 *
 */
private boolean isApplicable(final MethodHandle method, final LinkerServices linkerServices, final boolean varArg) {
    final Class<?>[] formalTypes = method.type().parameterArray();
    final int cl = classes.length;
    final int fl = formalTypes.length - (varArg ? 1 : 0);
    if(varArg) {
        if(cl < fl) {
            return false;
        }
    } else {
        if(cl != fl) {
            return false;
        }
    }
    // Starting from 1 as we ignore the receiver type
    for(int i = 1; i < fl; ++i) {
        if(!canConvert(linkerServices, classes[i], formalTypes[i])) {
            return false;
        }
    }
    if(varArg) {
        final Class<?> varArgType = formalTypes[fl].getComponentType();
        for(int i = fl; i < cl; ++i) {
            if(!canConvert(linkerServices, classes[i], varArgType)) {
                return false;
            }
        }
    }
    return true;
}
 
Example #20
Source Project: jdk8u_nashorn   Author: JetBrains   File: ScriptUtils.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert the given object to the given type.
 *
 * @param obj object to be converted
 * @param type destination type to convert to. type is either a Class
 * or nashorn representation of a Java type returned by Java.type() call in script.
 * @return converted object
 */
public static Object convert(final Object obj, final Object type) {
    if (obj == null) {
        return null;
    }

    final Class<?> clazz;
    if (type instanceof Class) {
        clazz = (Class<?>)type;
    } else if (type instanceof StaticClass) {
        clazz = ((StaticClass)type).getRepresentedClass();
    } else {
        throw new IllegalArgumentException("type expected");
    }

    final LinkerServices linker = Bootstrap.getLinkerServices();
    final Object objToConvert = unwrap(obj);
    final MethodHandle converter = linker.getTypeConverter(objToConvert.getClass(),  clazz);
    if (converter == null) {
        // no supported conversion!
        throw new UnsupportedOperationException("conversion not supported");
    }

    try {
        return converter.invoke(objToConvert);
    } catch (final RuntimeException | Error e) {
        throw e;
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    }
}
 
Example #21
Source Project: TencentKona-8   Author: Tencent   File: BeanLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected GuardedInvocationComponent getGuardedInvocationComponent(final CallSiteDescriptor callSiteDescriptor,
        final LinkerServices linkerServices, final List<String> operations) throws Exception {
    final GuardedInvocationComponent superGic = super.getGuardedInvocationComponent(callSiteDescriptor,
            linkerServices, operations);
    if(superGic != null) {
        return superGic;
    }
    if(operations.isEmpty()) {
        return null;
    }
    final String op = operations.get(0);
    // dyn:getElem(this, id)
    // id is typically either an int (for arrays and lists) or an object (for maps). linkerServices can provide
    // conversion from call site argument type though.
    if("getElem".equals(op)) {
        return getElementGetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    if("setElem".equals(op)) {
        return getElementSetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    // dyn:getLength(this) (works on Java arrays, collections, and maps)
    if("getLength".equals(op)) {
        return getLengthGetter(callSiteDescriptor);
    }
    return null;
}
 
Example #22
@Override
public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest, final LinkerServices linkerServices)
        throws Exception {
    final Object obj = linkRequest.getReceiver();
    if(obj == null) {
        return null;
    }
    for(TypeBasedGuardingDynamicLinker linker: classToLinker.get(obj.getClass())) {
        final GuardedInvocation invocation = linker.getGuardedInvocation(linkRequest, linkerServices);
        if(invocation != null) {
            return invocation;
        }
    }
    return null;
}
 
Example #23
Source Project: openjdk-8   Author: bpupadhyaya   File: OverloadedMethod.java    License: GNU General Public License v2.0 5 votes vote down vote up
OverloadedMethod(List<MethodHandle> methodHandles, OverloadedDynamicMethod parent, MethodType callSiteType,
        LinkerServices linkerServices) {
    this.parent = parent;
    this.callSiteType = callSiteType;
    this.linkerServices = linkerServices;

    fixArgMethods = new ArrayList<>(methodHandles.size());
    varArgMethods = new ArrayList<>(methodHandles.size());
    final int argNum = callSiteType.parameterCount();
    for(MethodHandle mh: methodHandles) {
        if(mh.isVarargsCollector()) {
            final MethodHandle asFixed = mh.asFixedArity();
            if(argNum == asFixed.type().parameterCount()) {
                fixArgMethods.add(asFixed);
            }
            varArgMethods.add(mh);
        } else {
            fixArgMethods.add(mh);
        }
    }
    fixArgMethods.trimToSize();
    varArgMethods.trimToSize();

    final MethodHandle bound = SELECT_METHOD.bindTo(this);
    final MethodHandle collecting = SingleDynamicMethod.collectArguments(bound, argNum).asType(
            callSiteType.changeReturnType(MethodHandle.class));
    invoker = MethodHandles.foldArguments(MethodHandles.exactInvoker(callSiteType), collecting);
}
 
Example #24
Source Project: hottub   Author: dsrg-uoft   File: DynamicLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new dynamic linker.
 *
 * @param linkerServices the linkerServices used by the linker, created by the factory.
 * @param prelinkFilter see {@link DynamicLinkerFactory#setPrelinkFilter(GuardedInvocationFilter)}
 * @param runtimeContextArgCount see {@link DynamicLinkerFactory#setRuntimeContextArgCount(int)}
 */
DynamicLinker(final LinkerServices linkerServices, final GuardedInvocationFilter prelinkFilter, final int runtimeContextArgCount,
        final boolean syncOnRelink, final int unstableRelinkThreshold) {
    if(runtimeContextArgCount < 0) {
        throw new IllegalArgumentException("runtimeContextArgCount < 0");
    }
    if(unstableRelinkThreshold < 0) {
        throw new IllegalArgumentException("unstableRelinkThreshold < 0");
    }
    this.linkerServices = linkerServices;
    this.prelinkFilter = prelinkFilter;
    this.runtimeContextArgCount = runtimeContextArgCount;
    this.syncOnRelink = syncOnRelink;
    this.unstableRelinkThreshold = unstableRelinkThreshold;
}
 
Example #25
Source Project: jdk8u60   Author: chenghanpeng   File: BeanLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected GuardedInvocationComponent getGuardedInvocationComponent(final CallSiteDescriptor callSiteDescriptor,
        final LinkerServices linkerServices, final List<String> operations) throws Exception {
    final GuardedInvocationComponent superGic = super.getGuardedInvocationComponent(callSiteDescriptor,
            linkerServices, operations);
    if(superGic != null) {
        return superGic;
    }
    if(operations.isEmpty()) {
        return null;
    }
    final String op = operations.get(0);
    // dyn:getElem(this, id)
    // id is typically either an int (for arrays and lists) or an object (for maps). linkerServices can provide
    // conversion from call site argument type though.
    if("getElem".equals(op)) {
        return getElementGetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    if("setElem".equals(op)) {
        return getElementSetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    // dyn:getLength(this) (works on Java arrays, collections, and maps)
    if("getLength".equals(op)) {
        return getLengthGetter(callSiteDescriptor);
    }
    return null;
}
 
Example #26
Source Project: jdk8u_nashorn   Author: JetBrains   File: ReflectionCheckLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest origRequest, final LinkerServices linkerServices)
        throws Exception {
    checkLinkRequest(origRequest);
    // let the next linker deal with actual linking
    return null;
}
 
Example #27
Source Project: jdk8u60   Author: chenghanpeng   File: NashornBottomLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices)
        throws Exception {
    final Object self = linkRequest.getReceiver();

    if (self == null) {
        return linkNull(linkRequest);
    }

    // None of the objects that can be linked by NashornLinker should ever reach here. Basically, anything below
    // this point is a generic Java bean. Therefore, reaching here with a ScriptObject is a Nashorn bug.
    assert isExpectedObject(self) : "Couldn't link " + linkRequest.getCallSiteDescriptor() + " for " + self.getClass().getName();

    return linkBean(linkRequest, linkerServices);
}
 
Example #28
Source Project: openjdk-8   Author: bpupadhyaya   File: BeanLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected GuardedInvocationComponent getGuardedInvocationComponent(CallSiteDescriptor callSiteDescriptor,
        LinkerServices linkerServices, List<String> operations) throws Exception {
    final GuardedInvocationComponent superGic = super.getGuardedInvocationComponent(callSiteDescriptor,
            linkerServices, operations);
    if(superGic != null) {
        return superGic;
    }
    if(operations.isEmpty()) {
        return null;
    }
    final String op = operations.get(0);
    // dyn:getElem(this, id)
    // id is typically either an int (for arrays and lists) or an object (for maps). linkerServices can provide
    // conversion from call site argument type though.
    if("getElem".equals(op)) {
        return getElementGetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    if("setElem".equals(op)) {
        return getElementSetter(callSiteDescriptor, linkerServices, pop(operations));
    }
    // dyn:getLength(this) (works on Java arrays, collections, and maps)
    if("getLength".equals(op)) {
        return getLengthGetter(callSiteDescriptor);
    }
    return null;
}
 
Example #29
Source Project: TencentKona-8   Author: Tencent   File: StaticClassLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception {
    final Object receiver = request.getReceiver();
    if(receiver instanceof StaticClass) {
        return linkers.get(((StaticClass)receiver).getRepresentedClass()).getGuardedInvocation(request,
                linkerServices);
    }
    return null;
}
 
Example #30
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison isMoreSpecific(final MethodType t1, final MethodType t2, final boolean varArgs, final Class<?>[] argTypes,
        final LinkerServices ls) {
    final int pc1 = t1.parameterCount();
    final int pc2 = t2.parameterCount();
    assert varArgs || (pc1 == pc2) && (argTypes == null || argTypes.length == pc1);
    assert (argTypes == null) == (ls == null);
    final int maxPc = Math.max(Math.max(pc1, pc2), argTypes == null ? 0 : argTypes.length);
    boolean t1MoreSpecific = false;
    boolean t2MoreSpecific = false;
    // NOTE: Starting from 1 as overloaded method resolution doesn't depend on 0th element, which is the type of
    // 'this'. We're only dealing with instance methods here, not static methods. Actually, static methods will have
    // a fake 'this' of type StaticClass.
    for(int i = 1; i < maxPc; ++i) {
        final Class<?> c1 = getParameterClass(t1, pc1, i, varArgs);
        final Class<?> c2 = getParameterClass(t2, pc2, i, varArgs);
        if(c1 != c2) {
            final Comparison cmp = compare(c1, c2, argTypes, i, ls);
            if(cmp == Comparison.TYPE_1_BETTER && !t1MoreSpecific) {
                t1MoreSpecific = true;
                if(t2MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
            if(cmp == Comparison.TYPE_2_BETTER && !t2MoreSpecific) {
                t2MoreSpecific = true;
                if(t1MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
        }
    }
    if(t1MoreSpecific) {
        return Comparison.TYPE_1_BETTER;
    } else if(t2MoreSpecific) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}