< prev index next >

src/java.base/share/classes/java/lang/invoke/SwitchPoint.java

Print this page
rev 12617 : [mq]: 8134356-gt-lt-in-code

*** 81,113 **** * <p style="font-size:smaller;"> * <em>Implementation Note:</em> * A switch point behaves as if implemented on top of {@link MutableCallSite}, * approximately as follows: * <blockquote><pre>{@code ! public class SwitchPoint { ! private static final MethodHandle ! K_true = MethodHandles.constant(boolean.class, true), ! K_false = MethodHandles.constant(boolean.class, false); ! private final MutableCallSite mcs; ! private final MethodHandle mcsInvoker; ! public SwitchPoint() { ! this.mcs = new MutableCallSite(K_true); ! this.mcsInvoker = mcs.dynamicInvoker(); ! } ! public MethodHandle guardWithTest( ! MethodHandle target, MethodHandle fallback) { ! // Note: mcsInvoker is of type ()boolean. ! // Target and fallback may take any arguments, but must have the same type. ! return MethodHandles.guardWithTest(this.mcsInvoker, target, fallback); ! } ! public static void invalidateAll(SwitchPoint[] spts) { ! List&lt;MutableCallSite&gt; mcss = new ArrayList&lt;&gt;(); ! for (SwitchPoint spt : spts) mcss.add(spt.mcs); ! for (MutableCallSite mcs : mcss) mcs.setTarget(K_false); ! MutableCallSite.syncAll(mcss.toArray(new MutableCallSite[0])); ! } ! } * }</pre></blockquote> * @author Remi Forax, JSR 292 EG */ public class SwitchPoint { private static final MethodHandle --- 81,113 ---- * <p style="font-size:smaller;"> * <em>Implementation Note:</em> * A switch point behaves as if implemented on top of {@link MutableCallSite}, * approximately as follows: * <blockquote><pre>{@code ! * public class SwitchPoint { ! * private static final MethodHandle ! * K_true = MethodHandles.constant(boolean.class, true), ! * K_false = MethodHandles.constant(boolean.class, false); ! * private final MutableCallSite mcs; ! * private final MethodHandle mcsInvoker; ! * public SwitchPoint() { ! * this.mcs = new MutableCallSite(K_true); ! * this.mcsInvoker = mcs.dynamicInvoker(); ! * } ! * public MethodHandle guardWithTest( ! * MethodHandle target, MethodHandle fallback) { ! * // Note: mcsInvoker is of type ()boolean. ! * // Target and fallback may take any arguments, but must have the same type. ! * return MethodHandles.guardWithTest(this.mcsInvoker, target, fallback); ! * } ! * public static void invalidateAll(SwitchPoint[] spts) { ! * List<MutableCallSite> mcss = new ArrayList<>(); ! * for (SwitchPoint spt : spts) mcss.add(spt.mcs); ! * for (MutableCallSite mcs : mcss) mcs.setTarget(K_false); ! * MutableCallSite.syncAll(mcss.toArray(new MutableCallSite[0])); ! * } ! * } * }</pre></blockquote> * @author Remi Forax, JSR 292 EG */ public class SwitchPoint { private static final MethodHandle
< prev index next >