Class LoopConditionProfile

All Implemented Interfaces:
Cloneable

public final class LoopConditionProfile extends ConditionProfile

LoopConditionProfiles are designed to profile the outcome of loop conditions. Loop profiles can be used to profile unpredictable loops as well as predictable loops.

Arbitrary loop usage example:

 class LoopNode extends Node {

     final LoopConditionProfile loopProfile = LoopConditionProfile.createCountingProfile();

     void execute() {
         // loop count cannot be predicted
         while (loopProfile.profile(Math.random() >= 0.9)) {
             // work
         }
     }
 }
 

Counted loop usage example:

 class CountedLoopNode extends Node {

     final LoopConditionProfile loopProfile = LoopConditionProfile.createCountingProfile();

     void execute(int length) {
         // loop count can be predicted
         loopProfile.profileCounted(length);
         for (int i = 0; loopProfile.inject(i < length); i++) {
             // work
         }
     }
 }
 

The advantage of using profileCounted(long) to using profile(boolean) is that it incurs less overhead in the interpreter. Using inject(boolean) is a no-op in the interpreter while profile(boolean) needs to use a counter for each iteration.

Since:
0.10
See Also:
  • Method Details

    • profile

      public boolean profile(boolean condition)
      Overrides:
      profile in class ConditionProfile
      Since:
      0.10
    • profileCounted

      public void profileCounted(long length)
      Provides an alternative way to profile counted loops with less interpreter footprint. Please see LoopConditionProfile for an usage example.
      Since:
      0.10
      See Also:
    • inject

      public boolean inject(boolean condition)
      Provides an alternative way to profile counted loops with less interpreter footprint. Please see LoopConditionProfile for an usage example.
      Since:
      0.10
      See Also:
    • disable

      public void disable()
      Disables this profile by setting it to its generic state. After disabling it is guaranteed to never deoptimize on any invocation of a profile method.

      This method must not be called on compiled code paths. Note that disabling the profile will not invalidate existing compiled code that uses this profile.

      Overrides:
      disable in class ConditionProfile
      Since:
      22.1
    • reset

      public void reset()
      Resets this profile to its uninitialized state. Has no effect if this profile is already in its uninitialized state or a disabled version of this profile is used.

      This method must not be called on compiled code paths. Note that disabling the profile will not invalidate existing compiled code that uses this profile.

      Overrides:
      reset in class ConditionProfile
      Since:
      22.1
    • toString

      public String toString()
      Overrides:
      toString in class ConditionProfile
      Since:
      22.1
    • createCountingProfile

      @Deprecated public static LoopConditionProfile createCountingProfile()
      Deprecated.
      use create() instead.
      Since:
      0.10
    • create

      public static LoopConditionProfile create()
      Returns a LoopConditionProfile that speculates on loop conditions to be never true. It also captures loop probabilities for the compiler. Loop condition profiles are intended to be used for loop conditions.
      Since:
      21.2
    • getUncached

      public static LoopConditionProfile getUncached()
      Returns the uncached version of the profile. The uncached version of a profile does nothing.
      Since:
      19.0