• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DynamicLinker类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PostInsertEvent类代码示例发布时间:2022-05-22
下一篇:
Java Tck类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap