void setValue(boolean value) { synchronized(lock) { SwitchPoint switchPoint = this.switchPoint; this.value = value; this.switchPoint = new SwitchPoint(); SwitchPoint.invalidateAll(new SwitchPoint[] {switchPoint}); } } }
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; }
public synchronized SwitchPoint getSwitchPoint(String className) { SwitchPoint switchPoint = switchPoints.get(className); if (switchPoint == null) switchPoints.put(className, switchPoint = new SwitchPoint()); return switchPoint; }
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); } }
/** * Returns true if and only if this guarded invocation has at least one invalidated switch point. * @return true if and only if this guarded invocation has at least one invalidated switch point. */ public boolean hasBeenInvalidated() { for (final SwitchPoint sp : switchPoints) { if (sp.hasBeenInvalidated()) { return true; } } return false; }
AlmostFinalCallSite(AlmostFinalValue volatileFinalValue) { super(MethodType.methodType(Boolean.TYPE)); Object lock = new Object(); MethodHandle fallback = FALLBACK.bindTo(this); synchronized(lock) { value = null; switchPoint = new SwitchPoint(); setTarget(fallback); } this.volatileFinalValue = volatileFinalValue; this.lock = lock; this.fallback = fallback; }
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); } }
/** * Returns true if and only if this guarded invocation has a switchpoint, and that switchpoint has been invalidated. * @return true if and only if this guarded invocation has a switchpoint, and that switchpoint has been invalidated. */ public boolean hasBeenInvalidated() { return switchPoint != null && switchPoint.hasBeenInvalidated(); }
boolean fallback() { synchronized(lock) { Boolean value = this.value; if (value == NONE) { value = volatileFinalValue.initialValue(); } MethodHandle target = switchPoint.guardWithTest(MethodHandles.constant(Boolean.TYPE, value), fallback); setTarget(target); return value; } }
/** * Callback for constant meta class update change */ protected static void invalidateSwitchPoints() { if (LOG_ENABLED) { LOG.info("invalidating switch point"); } synchronized(IndyInterface.class) { SwitchPoint old = switchPoint; switchPoint = new SwitchPoint(); SwitchPoint.invalidateAll(new SwitchPoint[]{old}); } }
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()); } }
public void invalidateAll(List<Invalidator> invalidators) { SwitchPoint[] switchPoints = new SwitchPoint[invalidators.size()]; for (int i = 0; i < invalidators.size(); i++) { Invalidator invalidator = invalidators.get(i); assert invalidator instanceof FailoverSwitchPointInvalidator; switchPoints[i] = ((FailoverSwitchPointInvalidator)invalidator).replaceSwitchPoint(); } SwitchPoint.invalidateAll(switchPoints); }
private static MethodHandle bindWithFallback(RoboCallSite site, MethodHandle mh, MethodHandle fallback) { SwitchPoint switchPoint = getInvalidator(site.getTheClass()); MethodType type = site.type(); MethodHandle boundFallback = foldArguments(exactInvoker(type), fallback.bindTo(site)); try { mh = switchPoint.guardWithTest(mh.asType(type), boundFallback); } catch (WrongMethodTypeException e) { if (site instanceof MethodCallSite) { MethodCallSite methodCallSite = (MethodCallSite) site; throw new RuntimeException("failed to bind " + methodCallSite.thisType() + "." + methodCallSite.getName(), e); } else { throw e; } } site.setTarget(mh); return mh; }
public synchronized void invalidate() { if (switchPoint == DUMMY) return; failures += 1; // if we have failed too many times, set it to DUMMY and leave it if (failures > maxFailures) { SwitchPoint.invalidateAll(new SwitchPoint[]{switchPoint}); switchPoint = DUMMY; return; } SwitchPoint.invalidateAll(new SwitchPoint[]{switchPoint}); switchPoint = new SwitchPoint(); }
public synchronized SwitchPoint replaceSwitchPoint() { if (switchPoint == DUMMY || failures > maxFailures) return DUMMY; SwitchPoint oldSwitchPoint = switchPoint; switchPoint = new SwitchPoint(); return oldSwitchPoint; } }
public void invalidateAll(List<Invalidator> invalidators) { SwitchPoint[] switchPoints = new SwitchPoint[invalidators.size()]; for (int i = 0; i < invalidators.size(); i++) { Invalidator invalidator = invalidators.get(i); assert invalidator instanceof SwitchPointInvalidator; switchPoints[i] = ((SwitchPointInvalidator)invalidator).replaceSwitchPoint(); } SwitchPoint.invalidateAll(switchPoints); }
handle = switchPoint.guardWithTest(handle, fallback); if (LOG_ENABLED) LOG.info("added switch point guard");
void setValue(V value) { synchronized(lock) { SwitchPoint switchPoint = this.switchPoint; this.value = value; this.switchPoint = new SwitchPoint(); SwitchPoint.invalidateAll(new SwitchPoint[] {switchPoint}); } } }
public synchronized SwitchPoint replaceSwitchPoint() { SwitchPoint switchPoint = this.switchPoint; if (switchPoint == DUMMY) return switchPoint; SwitchPoint oldSwitchPoint = switchPoint; this.switchPoint = new SwitchPoint(); return oldSwitchPoint; } }
public void invalidateAll(List<Invalidator> invalidators) { SwitchPoint[] switchPoints = new SwitchPoint[invalidators.size()]; for (int i = 0; i < invalidators.size(); i++) { Invalidator invalidator = invalidators.get(i); assert invalidator instanceof SwitchPointInvalidator; switchPoints[i] = ((SwitchPointInvalidator)invalidator).replaceSwitchPoint(); } SwitchPoint.invalidateAll(switchPoints); }