Search in sources :

Example 1 with SwitchPoint

use of java.lang.invoke.SwitchPoint in project robolectric by robolectric.

the class ShadowInvalidator method invalidateClasses.

public synchronized void invalidateClasses(Collection<String> classNames) {
    if (classNames.isEmpty())
        return;
    SwitchPoint[] points = new SwitchPoint[classNames.size()];
    int i = 0;
    for (String className : classNames) {
        SwitchPoint switchPoint = switchPoints.put(className, null);
        if (switchPoint == null)
            switchPoint = DUMMY;
        points[i++] = switchPoint;
    }
    SwitchPoint.invalidateAll(points);
}
Also used : SwitchPoint(java.lang.invoke.SwitchPoint) SwitchPoint(java.lang.invoke.SwitchPoint)

Example 2 with SwitchPoint

use of java.lang.invoke.SwitchPoint in project groovy by apache.

the class ReevaluatingReference method replacePayLoad.

private T replacePayLoad() {
    T payload = valueSupplier.get();
    MethodHandle ref = MethodHandles.constant(clazzRef.get(), payload);
    SwitchPoint sp = validationSupplier.apply(payload);
    returnRef = sp.guardWithTest(ref, FALLBACK_HANDLE);
    return payload;
}
Also used : SwitchPoint(java.lang.invoke.SwitchPoint) MethodHandle(java.lang.invoke.MethodHandle)

Example 3 with SwitchPoint

use of java.lang.invoke.SwitchPoint in project robolectric by robolectric.

the class InvokeDynamicSupport method bindWithFallback.

private static MethodHandle bindWithFallback(MethodHandle mh, RoboCallSite site, MethodHandle fallback) {
    SwitchPoint switchPoint = getInvalidator(site.getCaller());
    MethodType type = site.type();
    MethodHandle boundFallback = foldArguments(exactInvoker(type), fallback.bindTo(site));
    mh = switchPoint.guardWithTest(mh.asType(type), boundFallback);
    site.setTarget(mh);
    return mh;
}
Also used : MethodType(java.lang.invoke.MethodType) SwitchPoint(java.lang.invoke.SwitchPoint) MethodHandle(java.lang.invoke.MethodHandle)

Example 4 with SwitchPoint

use of java.lang.invoke.SwitchPoint in project robolectric by robolectric.

the class SandboxClassLoaderTest method loadClass.

private Class<?> loadClass(Class<?> clazz) throws ClassNotFoundException {
    if (classLoader == null) {
        classLoader = new SandboxClassLoader(configureBuilder().build());
    }
    setStaticField(classLoader.loadClass(InvokeDynamicSupport.class.getName()), "INTERCEPTORS", new Interceptors(Collections.<Interceptor>emptyList()));
    setStaticField(classLoader.loadClass(Shadow.class.getName()), "SHADOW_IMPL", newInstance(classLoader.loadClass(ShadowImpl.class.getName())));
    ShadowInvalidator invalidator = Mockito.mock(ShadowInvalidator.class);
    when(invalidator.getSwitchPoint(any(Class.class))).thenReturn(new SwitchPoint());
    String className = RobolectricInternals.class.getName();
    Class<?> robolectricInternalsClass = ReflectionHelpers.loadClass(classLoader, className);
    ReflectionHelpers.setStaticField(robolectricInternalsClass, "classHandler", classHandler);
    ReflectionHelpers.setStaticField(robolectricInternalsClass, "shadowInvalidator", invalidator);
    return classLoader.loadClass(clazz.getName());
}
Also used : Interceptors(org.robolectric.internal.bytecode.Interceptors) ShadowInvalidator(org.robolectric.internal.bytecode.ShadowInvalidator) SwitchPoint(java.lang.invoke.SwitchPoint) ShadowImpl(org.robolectric.internal.bytecode.ShadowImpl) AnUninstrumentedClass(org.robolectric.testing.AnUninstrumentedClass) AClassThatRefersToAForgettableClass(org.robolectric.testing.AClassThatRefersToAForgettableClass) AFinalClass(org.robolectric.testing.AFinalClass) AClassThatCallsAMethodReturningAForgettableClass(org.robolectric.testing.AClassThatCallsAMethodReturningAForgettableClass) AnExampleClass(org.robolectric.testing.AnExampleClass) Matchers.anyString(org.mockito.Matchers.anyString) AnInstrumentedClassWithoutToStringWithSuperToString(org.robolectric.testing.AnInstrumentedClassWithoutToStringWithSuperToString) AClassWithoutEqualsHashCodeToString(org.robolectric.testing.AClassWithoutEqualsHashCodeToString) AClassWithEqualsHashCodeToString(org.robolectric.testing.AClassWithEqualsHashCodeToString) Interceptor(org.robolectric.internal.bytecode.Interceptor) SandboxClassLoader(org.robolectric.internal.bytecode.SandboxClassLoader)

Aggregations

SwitchPoint (java.lang.invoke.SwitchPoint)4 MethodHandle (java.lang.invoke.MethodHandle)2 MethodType (java.lang.invoke.MethodType)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Interceptor (org.robolectric.internal.bytecode.Interceptor)1 Interceptors (org.robolectric.internal.bytecode.Interceptors)1 SandboxClassLoader (org.robolectric.internal.bytecode.SandboxClassLoader)1 ShadowImpl (org.robolectric.internal.bytecode.ShadowImpl)1 ShadowInvalidator (org.robolectric.internal.bytecode.ShadowInvalidator)1 AClassThatCallsAMethodReturningAForgettableClass (org.robolectric.testing.AClassThatCallsAMethodReturningAForgettableClass)1 AClassThatRefersToAForgettableClass (org.robolectric.testing.AClassThatRefersToAForgettableClass)1 AClassWithEqualsHashCodeToString (org.robolectric.testing.AClassWithEqualsHashCodeToString)1 AClassWithoutEqualsHashCodeToString (org.robolectric.testing.AClassWithoutEqualsHashCodeToString)1 AFinalClass (org.robolectric.testing.AFinalClass)1 AnExampleClass (org.robolectric.testing.AnExampleClass)1 AnInstrumentedClassWithoutToStringWithSuperToString (org.robolectric.testing.AnInstrumentedClassWithoutToStringWithSuperToString)1 AnUninstrumentedClass (org.robolectric.testing.AnUninstrumentedClass)1