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


Java MutableCallSite类代码示例

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


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

示例1: registerCallSitePlugins

import java.lang.invoke.MutableCallSite; //导入依赖的package包/类
private static void registerCallSitePlugins(InvocationPlugins plugins) {
    InvocationPlugin plugin = new InvocationPlugin() {
        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            ValueNode callSite = receiver.get();
            ValueNode folded = CallSiteTargetNode.tryFold(GraphUtil.originalValue(callSite), b.getMetaAccess(), b.getAssumptions());
            if (folded != null) {
                b.addPush(JavaKind.Object, folded);
            } else {
                b.addPush(JavaKind.Object, new CallSiteTargetNode(b.getInvokeKind(), targetMethod, b.bci(), b.getInvokeReturnStamp(b.getAssumptions()), callSite));
            }
            return true;
        }

        @Override
        public boolean inlineOnly() {
            return true;
        }
    };
    plugins.register(plugin, ConstantCallSite.class, "getTarget", Receiver.class);
    plugins.register(plugin, MutableCallSite.class, "getTarget", Receiver.class);
    plugins.register(plugin, VolatileCallSite.class, "getTarget", Receiver.class);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:HotSpotGraphBuilderPlugins.java

示例2: testNonBoundCallSite

import java.lang.invoke.MutableCallSite; //导入依赖的package包/类
public static void testNonBoundCallSite() throws Throwable {
    mcs = new MutableCallSite(LOOKUP.findStatic(T.class, "f1", TYPE));

    // mcs.context == null
    MethodHandle mh = mcs.dynamicInvoker();
    execute(1, mh);

    // mcs.context == cls1
    Class<?> cls1 = UNSAFE.defineAnonymousClass(CallSiteDepContextTest.class, getClassFile("NonBound_1"), null);
    MethodHandle mh1 = LOOKUP.findStatic(cls1, METHOD_NAME, TYPE);

    execute(1, mh1);

    mcs.setTarget(LOOKUP.findStatic(T.class, "f2", TYPE));

    execute(2, mh, mh1);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:CallSiteDepContextTest.java

示例3: testNonBoundCallSite

import java.lang.invoke.MutableCallSite; //导入依赖的package包/类
public static void testNonBoundCallSite() throws Throwable {
    mcs = new MutableCallSite(LOOKUP.findStatic(T.class, "f1", TYPE));

    // mcs.context == null
    MethodHandle mh = mcs.dynamicInvoker();
    execute(1, mh);

    // mcs.context == cls1
    Class<?> cls1 = UNSAFE.defineAnonymousClass(Object.class, getClassFile("NonBound_1"), null);
    MethodHandle mh1 = LOOKUP.findStatic(cls1, METHOD_NAME, TYPE);

    execute(1, mh1);

    mcs.setTarget(LOOKUP.findStatic(T.class, "f2", TYPE));

    execute(2, mh, mh1);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:18,代码来源:CallSiteDepContextTest.java

示例4: nativeCallSetup

import java.lang.invoke.MutableCallSite; //导入依赖的package包/类
@SuppressWarnings("unused")
private static MethodHandle nativeCallSetup(MutableCallSite callsite, String name, ExecutionContext cx) {
    RuntimeContext context = cx.getRuntimeContext();
    MethodHandle target;
    try {
        MethodHandle mh = context.getNativeCallResolver().apply(name, callsite.type());
        if (mh == null) {
            throw new IllegalArgumentException();
        }
        target = adaptNativeMethodHandle(mh);
        target = adaptMethodHandle(name, callsite.type(), target);
    } catch (IllegalArgumentException e) {
        target = invalidCallHandle(name, callsite.type());
    }
    callsite.setTarget(target);
    return target;
}
 
开发者ID:anba,项目名称:es6draft,代码行数:18,代码来源:NativeCalls.java

示例5: concatSetup

import java.lang.invoke.MutableCallSite; //导入依赖的package包/类
private static void concatSetup(MutableCallSite callsite, MethodType type) {
    MethodHandle target, test, generic;
    int numberOfStrings = type.parameterCount() - 1; // CharSequence..., ExecutionContext
    if (numberOfStrings <= CONCAT_MAX_SPECIALIZATION) {
        assert numberOfStrings >= CONCAT_MIN_PARAMS;
        int index = numberOfStrings - CONCAT_MIN_PARAMS;
        target = concatMH[index];
        test = testConcatMH[index];
        generic = concatConsMH[index];
    } else {
        final int index = CONCAT_MAX_SPECIALIZATION - CONCAT_MIN_PARAMS + 1;
        target = concatMH[index].asCollector(CharSequence[].class, numberOfStrings);
        test = testConcatMH[index].asCollector(CharSequence[].class, numberOfStrings);
        generic = concatConsMH[index].asCollector(CharSequence[].class, numberOfStrings);
    }
    setCallSiteTarget(callsite, target, test, generic);
}
 
开发者ID:anba,项目名称:es6draft,代码行数:18,代码来源:Bootstrap.java

示例6: setCallSiteTarget

import java.lang.invoke.MutableCallSite; //导入依赖的package包/类
private static MethodHandle setCallSiteTarget(MutableCallSite callsite, MethodHandle target, MethodHandle test,
        MethodHandle generic) {
    MethodHandle callSiteTarget;
    if (target != null) {
        target = target.asType(callsite.type());
        if (test != null) {
            MethodHandle fallback = createFallback(callsite, generic);
            callSiteTarget = MethodHandles.guardWithTest(test, target, fallback);
        } else {
            callSiteTarget = target;
        }
    } else {
        callSiteTarget = target = generic;
    }
    callsite.setTarget(callSiteTarget);
    return target;
}
 
开发者ID:anba,项目名称:es6draft,代码行数:18,代码来源:Bootstrap.java

示例7: getOrCreateValueMethodHandle

import java.lang.invoke.MutableCallSite; //导入依赖的package包/类
public static CallSite bootstrapValue
	(Lookup lookup, String name, MethodType type)
{
	name = StringNames.toSourceName(name);

	// get or create constant method handle:
	// reuse same constant method handle instead
	// of creating a new method handle for each call site
	MethodHandle methodHandle = getOrCreateValueMethodHandle(name);

	// create and record callsite
	MutableCallSite callSite = new MutableCallSite(methodHandle);
	List<MutableCallSite> callSites = valueCallSites.get(name);
	if (callSites == null)
		callSites = new ArrayList<>();
	callSites.add(callSite);
	valueCallSites.put(name, callSites);
	return callSite;
}
 
开发者ID:turbolent,项目名称:lila,代码行数:20,代码来源:RT.java

示例8: createComposableInvoker

import java.lang.invoke.MutableCallSite; //导入依赖的package包/类
private MethodHandle createComposableInvoker(final boolean isConstructor) {
    final MethodHandle handle = getInvokerOrConstructor(isConstructor);

    // If compiled function is not optimistic, it can't ever change its invoker/constructor, so just return them
    // directly.
    if(!canBeDeoptimized()) {
        return handle;
    }

    // Otherwise, we need a new level of indirection; need to introduce a mutable call site that can relink itslef
    // to the compiled function's changed target whenever the optimistic assumptions are invalidated.
    final CallSite cs = new MutableCallSite(handle.type());
    relinkComposableInvoker(cs, this, isConstructor);
    return cs.dynamicInvoker();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:CompiledFunction.java

示例9: main

import java.lang.invoke.MutableCallSite; //导入依赖的package包/类
public static void main(String[] args) throws ReflectiveOperationException  {
    // Objects
    test(new Object());
    test("TEST");
    test(new VMAnonymousClasses());
    test(null);

    // Class
    test(String.class);

    // Arrays
    test(new boolean[0]);
    test(new byte[0]);
    test(new char[0]);
    test(new short[0]);
    test(new int[0]);
    test(new long[0]);
    test(new float[0]);
    test(new double[0]);
    test(new Object[0]);

    // Multi-dimensional arrays
    test(new byte[0][0]);
    test(new Object[0][0]);

    // MethodHandle-related
    MethodType   mt = MethodType.methodType(void.class, String[].class);
    MethodHandle mh = MethodHandles.lookup().findStatic(VMAnonymousClasses.class, "main", mt);
    test(mt);
    test(mh);
    test(new ConstantCallSite(mh));
    test(new MutableCallSite(MethodType.methodType(void.class)));
    test(new VolatileCallSite(MethodType.methodType(void.class)));

    System.out.println("TEST PASSED");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:VMAnonymousClasses.java

示例10: testSharedCallSite

import java.lang.invoke.MutableCallSite; //导入依赖的package包/类
public static void testSharedCallSite() throws Throwable {
    Class<?> cls1 = UNSAFE.defineAnonymousClass(CallSiteDepContextTest.class, getClassFile("CS_1"), null);
    Class<?> cls2 = UNSAFE.defineAnonymousClass(CallSiteDepContextTest.class, getClassFile("CS_2"), null);

    MethodHandle[] mhs = new MethodHandle[] {
            LOOKUP.findStatic(cls1, METHOD_NAME, TYPE),
            LOOKUP.findStatic(cls2, METHOD_NAME, TYPE)
    };

    mcs = new MutableCallSite(LOOKUP.findStatic(T.class, "f1", TYPE));
    execute(1, mhs);
    mcs.setTarget(LOOKUP.findStatic(T.class, "f2", TYPE));
    execute(2, mhs);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:CallSiteDepContextTest.java

示例11: createComposableInvoker

import java.lang.invoke.MutableCallSite; //导入依赖的package包/类
private MethodHandle createComposableInvoker(final boolean isConstructor) {
    final MethodHandle handle = getInvokerOrConstructor(isConstructor);

    // If compiled function is not optimistic, it can't ever change its invoker/constructor, so just return them
    // directly.
    if(!canBeDeoptimized()) {
        return handle;
    }

    // Otherwise, we need a new level of indirection; need to introduce a mutable call site that can relink itself
    // to the compiled function's changed target whenever the optimistic assumptions are invalidated.
    final CallSite cs = new MutableCallSite(handle.type());
    relinkComposableInvoker(cs, this, isConstructor);
    return cs.dynamicInvoker();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:CompiledFunction.java

示例12: relink

import java.lang.invoke.MutableCallSite; //导入依赖的package包/类
/**
 * Relinks a call site conforming to the invocation arguments.
 *
 * @param callSite the call site itself
 * @param arguments arguments to the invocation
 *
 * @return return the method handle for the invocation
 *
 * @throws Exception rethrows any exception thrown by the linkers
 */
@SuppressWarnings("unused")
private MethodHandle relink(final RelinkableCallSite callSite, final int relinkCount, final Object... arguments) throws Exception {
    final CallSiteDescriptor callSiteDescriptor = callSite.getDescriptor();
    final boolean unstableDetectionEnabled = unstableRelinkThreshold > 0;
    final boolean callSiteUnstable = unstableDetectionEnabled && relinkCount >= unstableRelinkThreshold;
    final LinkRequest linkRequest = new SimpleLinkRequest(callSiteDescriptor, callSiteUnstable, arguments);

    GuardedInvocation guardedInvocation = linkerServices.getGuardedInvocation(linkRequest);

    // None found - throw an exception
    if(guardedInvocation == null) {
        throw new NoSuchDynamicMethodException(callSiteDescriptor.toString());
    }

    // Make sure we transform the invocation before linking it into the call site. This is typically used to match the
    // return type of the invocation to the call site.
    guardedInvocation = prelinkTransformer.filter(guardedInvocation, linkRequest, linkerServices);
    Objects.requireNonNull(guardedInvocation);

    int newRelinkCount = relinkCount;
    // Note that the short-circuited "&&" evaluation below ensures we'll increment the relinkCount until
    // threshold + 1 but not beyond that. Threshold + 1 is treated as a special value to signal that resetAndRelink
    // has already executed once for the unstable call site; we only want the call site to throw away its current
    // linkage once, when it transitions to unstable.
    if(unstableDetectionEnabled && newRelinkCount <= unstableRelinkThreshold && newRelinkCount++ == unstableRelinkThreshold) {
        callSite.resetAndRelink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    } else {
        callSite.relink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount));
    }
    if(syncOnRelink) {
        MutableCallSite.syncAll(new MutableCallSite[] { (MutableCallSite)callSite });
    }
    return guardedInvocation.getInvocation();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:45,代码来源:DynamicLinker.java

示例13: testSharedCallSite

import java.lang.invoke.MutableCallSite; //导入依赖的package包/类
public static void testSharedCallSite() throws Throwable {
    Class<?> cls1 = UNSAFE.defineAnonymousClass(Object.class, getClassFile("CS_1"), null);
    Class<?> cls2 = UNSAFE.defineAnonymousClass(Object.class, getClassFile("CS_2"), null);

    MethodHandle[] mhs = new MethodHandle[] {
            LOOKUP.findStatic(cls1, METHOD_NAME, TYPE),
            LOOKUP.findStatic(cls2, METHOD_NAME, TYPE)
    };

    mcs = new MutableCallSite(LOOKUP.findStatic(T.class, "f1", TYPE));
    execute(1, mhs);
    mcs.setTarget(LOOKUP.findStatic(T.class, "f2", TYPE));
    execute(2, mhs);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:15,代码来源:CallSiteDepContextTest.java

示例14: getSelector

import java.lang.invoke.MutableCallSite; //导入依赖的package包/类
/**
 * Returns the Selector
 */
public static Selector getSelector(MutableCallSite callSite, Class sender, String methodName, int callID, boolean safeNavigation, boolean thisCall, boolean spreadCall, Object[] arguments) {
    CALL_TYPES callType = CALL_TYPES_VALUES[callID];
    switch (callType) {
        case INIT: return new InitSelector(callSite, sender, methodName, callType, safeNavigation, thisCall, spreadCall, arguments);
        case METHOD: return new MethodSelector(callSite, sender, methodName, callType, safeNavigation, thisCall, spreadCall, arguments);
        case GET: 
            return new PropertySelector(callSite, sender, methodName, callType, safeNavigation, thisCall, spreadCall, arguments);
        case SET:
            throw new GroovyBugError("your call tried to do a property set, which is not supported.");
        case CAST:  return new CastSelector(callSite, arguments);
        default: throw new GroovyBugError("unexpected call type");
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:Selector.java

示例15: MethodSelector

import java.lang.invoke.MutableCallSite; //导入依赖的package包/类
public MethodSelector(MutableCallSite callSite, Class sender, String methodName, CALL_TYPES callType, Boolean safeNavigation, Boolean thisCall, Boolean spreadCall, Object[] arguments) {
    this.callType = callType;
    this.targetType = callSite.type();
    this.name = methodName;
    this.originalArguments = arguments;
    this.args = spread(arguments, spreadCall);
    this.callSite = callSite;
    this.sender = sender;
    this.safeNavigationOrig = safeNavigation;
    this.safeNavigation = safeNavigation && arguments[0]==null;
    this.thisCall = thisCall;
    this.spread = spreadCall;
    this.cache = !spread;

    if (LOG_ENABLED) {
        StringBuilder msg =
                new StringBuilder("----------------------------------------------------" +
                        "\n\t\tinvocation of method '" + methodName + "'" +
                        "\n\t\tinvocation type: " + callType +
                        "\n\t\tsender: " + sender +
                        "\n\t\ttargetType: " + targetType +
                        "\n\t\tsafe navigation: " + safeNavigation +
                        "\n\t\tthisCall: " + thisCall +
                        "\n\t\tspreadCall: " + spreadCall +
                        "\n\t\twith " + arguments.length + " arguments");
        for (int i=0; i<arguments.length; i++) {
            msg.append("\n\t\t\targument[").append(i).append("] = ");
            if (arguments[i] == null) {
                msg.append("null");
            } else {
                msg.append(arguments[i].getClass().getName()).append("@").append(Integer.toHexString(System.identityHashCode(arguments[i])));
            }
        }
        LOG.info(msg.toString());
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:37,代码来源:Selector.java


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