Class FakeConstantBoolean

java.lang.Object
dev.pfaff.altargui.util.FakeConstantBoolean

public final class FakeConstantBoolean extends Object
A wrapper for a boolean value that is stored and accessed via a MutableCallSite. The JVM should be able to optimize uses of the value more than if it were simply a non-final field.

From my testing, it appears that the Hotspot JVM has more aggressive speculative optimization of CallSites than it does non-final fields. That knowledge led to the creation of this wrapper class. Note that this technique will only be effective if the Hotspot JVM is run with -XX:+TrustFinalNonStaticFields.

  • Constructor Details

    • FakeConstantBoolean

      public FakeConstantBoolean()
      The initial value will be false.
    • FakeConstantBoolean

      public FakeConstantBoolean(boolean value)
      Parameters:
      value - the initial value
  • Method Details

    • set

      public void set(boolean value)
      Stores a new value. The call-site will only be modified if the new value differs from the stored value.
      Parameters:
      value - the new value
    • get

      public boolean get()
      Returns:
      the stored value