当前位置: 首页>>代码示例>>Java>>正文


Java DynamicLinker类代码示例

本文整理汇总了Java中jdk.internal.dynalink.DynamicLinker的典型用法代码示例。如果您正苦于以下问题:Java DynamicLinker类的具体用法?Java DynamicLinker怎么用?Java DynamicLinker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DynamicLinker类属于jdk.internal.dynalink包,在下文中一共展示了DynamicLinker类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isOfClass

import jdk.internal.dynalink.DynamicLinker; //导入依赖的package包/类
/**
 * Creates a guard method handle with arguments of a specified type, but with boolean return value. When invoked, it
 * returns true if the first argument is of the specified class (exactly of it, not a subclass). The rest of the
 * arguments will be ignored.
 *
 * @param clazz the class of the first argument to test for
 * @param type the method type
 * @return a method handle testing whether its first argument is of the specified class.
 */
@SuppressWarnings("boxing")
public static MethodHandle isOfClass(final Class<?> clazz, final MethodType type) {
    final Class<?> declaredType = type.parameterType(0);
    if(clazz == declaredType) {
        LOG.log(Level.WARNING, "isOfClassGuardAlwaysTrue", new Object[] { clazz.getName(), 0, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantTrue(type);
    }
    if(!declaredType.isAssignableFrom(clazz)) {
        LOG.log(Level.WARNING, "isOfClassGuardAlwaysFalse", new Object[] { clazz.getName(), 0, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantFalse(type);
    }
    return getClassBoundArgumentTest(IS_OF_CLASS, clazz, 0, type);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:Guards.java

示例2: isInstance

import jdk.internal.dynalink.DynamicLinker; //导入依赖的package包/类
/**
 * Creates a method handle with arguments of a specified type, but with boolean return value. When invoked, it
 * returns true if the n'th argument is instance of the specified class or its subclass). The rest of the arguments
 * will be ignored.
 *
 * @param clazz the class of the first argument to test for
 * @param pos the position on the argument list to test
 * @param type the method type
 * @return a method handle testing whether its first argument is of the specified class or subclass.
 */
@SuppressWarnings("boxing")
public static MethodHandle isInstance(final Class<?> clazz, final int pos, final MethodType type) {
    final Class<?> declaredType = type.parameterType(pos);
    if(clazz.isAssignableFrom(declaredType)) {
        LOG.log(Level.WARNING, "isInstanceGuardAlwaysTrue", new Object[] { clazz.getName(), pos, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantTrue(type);
    }
    if(!declaredType.isAssignableFrom(clazz)) {
        LOG.log(Level.WARNING, "isInstanceGuardAlwaysFalse", new Object[] { clazz.getName(), pos, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantFalse(type);
    }
    return getClassBoundArgumentTest(IS_INSTANCE, clazz, pos, type);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:Guards.java

示例3: isArray

import jdk.internal.dynalink.DynamicLinker; //导入依赖的package包/类
/**
 * Creates a method handle that returns true if the argument in the specified position is a Java array.
 *
 * @param pos the position in the argument lit
 * @param type the method type of the handle
 * @return a method handle that returns true if the argument in the specified position is a Java array; the rest of
 * the arguments are ignored.
 */
@SuppressWarnings("boxing")
public static MethodHandle isArray(final int pos, final MethodType type) {
    final Class<?> declaredType = type.parameterType(pos);
    if(declaredType.isArray()) {
        LOG.log(Level.WARNING, "isArrayGuardAlwaysTrue", new Object[] { pos, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantTrue(type);
    }
    if(!declaredType.isAssignableFrom(Object[].class)) {
        LOG.log(Level.WARNING, "isArrayGuardAlwaysFalse", new Object[] { pos, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantFalse(type);
    }
    return asType(IS_ARRAY, pos, type);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:Guards.java

示例4: isOfClass

import jdk.internal.dynalink.DynamicLinker; //导入依赖的package包/类
/**
 * Creates a guard method handle with arguments of a specified type, but with boolean return value. When invoked, it
 * returns true if the first argument is of the specified class (exactly of it, not a subclass). The rest of the
 * arguments will be ignored.
 *
 * @param clazz the class of the first argument to test for
 * @param type the method type
 * @return a method handle testing whether its first argument is of the specified class.
 */
@SuppressWarnings("boxing")
public static MethodHandle isOfClass(Class<?> clazz, MethodType type) {
    final Class<?> declaredType = type.parameterType(0);
    if(clazz == declaredType) {
        LOG.log(Level.WARNING, "isOfClassGuardAlwaysTrue", new Object[] { clazz.getName(), 0, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantTrue(type);
    }
    if(!declaredType.isAssignableFrom(clazz)) {
        LOG.log(Level.WARNING, "isOfClassGuardAlwaysFalse", new Object[] { clazz.getName(), 0, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantFalse(type);
    }
    return getClassBoundArgumentTest(IS_OF_CLASS, clazz, 0, type);
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:23,代码来源:Guards.java

示例5: isInstance

import jdk.internal.dynalink.DynamicLinker; //导入依赖的package包/类
/**
 * Creates a method handle with arguments of a specified type, but with boolean return value. When invoked, it
 * returns true if the n'th argument is instance of the specified class or its subclass). The rest of the arguments
 * will be ignored.
 *
 * @param clazz the class of the first argument to test for
 * @param pos the position on the argument list to test
 * @param type the method type
 * @return a method handle testing whether its first argument is of the specified class or subclass.
 */
@SuppressWarnings("boxing")
public static MethodHandle isInstance(Class<?> clazz, int pos, MethodType type) {
    final Class<?> declaredType = type.parameterType(pos);
    if(clazz.isAssignableFrom(declaredType)) {
        LOG.log(Level.WARNING, "isInstanceGuardAlwaysTrue", new Object[] { clazz.getName(), pos, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantTrue(type);
    }
    if(!declaredType.isAssignableFrom(clazz)) {
        LOG.log(Level.WARNING, "isInstanceGuardAlwaysFalse", new Object[] { clazz.getName(), pos, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantFalse(type);
    }
    return getClassBoundArgumentTest(IS_INSTANCE, clazz, pos, type);
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:24,代码来源:Guards.java

示例6: isArray

import jdk.internal.dynalink.DynamicLinker; //导入依赖的package包/类
/**
 * Creates a method handle that returns true if the argument in the specified position is a Java array.
 *
 * @param pos the position in the argument lit
 * @param type the method type of the handle
 * @return a method handle that returns true if the argument in the specified position is a Java array; the rest of
 * the arguments are ignored.
 */
@SuppressWarnings("boxing")
public static MethodHandle isArray(int pos, MethodType type) {
    final Class<?> declaredType = type.parameterType(pos);
    if(declaredType.isArray()) {
        LOG.log(Level.WARNING, "isArrayGuardAlwaysTrue", new Object[] { pos, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantTrue(type);
    }
    if(!declaredType.isAssignableFrom(Object[].class)) {
        LOG.log(Level.WARNING, "isArrayGuardAlwaysFalse", new Object[] { pos, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantFalse(type);
    }
    return asType(IS_ARRAY, pos, type);
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:22,代码来源:Guards.java

示例7: getScriptLocation

import jdk.internal.dynalink.DynamicLinker; //导入依赖的package包/类
private static String getScriptLocation() {
    final StackTraceElement caller = DynamicLinker.getLinkedCallSiteLocation();
    return caller == null ? "unknown location" : (caller.getFileName() + ":" + caller.getLineNumber());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:5,代码来源:LinkerCallSite.java

示例8: findGetMethod

import jdk.internal.dynalink.DynamicLinker; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:74,代码来源:GlobalConstants.java


注:本文中的jdk.internal.dynalink.DynamicLinker类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。