Class LoopConditionProfile
- All Implemented Interfaces:
Cloneable
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 Summary
Modifier and TypeMethodDescriptionstatic LoopConditionProfilecreate()Returns aLoopConditionProfilethat speculates on loop conditions to be nevertrue.static LoopConditionProfileDeprecated.voiddisable()Disables this profile by setting it to its generic state.static LoopConditionProfileReturns the uncached version of the profile.booleaninject(boolean condition) Provides an alternative way to profile counted loops with less interpreter footprint.booleanprofile(boolean condition) voidprofileCounted(long length) Provides an alternative way to profile counted loops with less interpreter footprint.voidreset()Resets this profile to its uninitialized state.toString()Methods inherited from class com.oracle.truffle.api.profiles.ConditionProfile
createBinaryProfile, inlineMethods inherited from class com.oracle.truffle.api.nodes.NodeCloneable
clone
-
Method Details
-
profile
public boolean profile(boolean condition) - Overrides:
profilein classConditionProfile- Since:
- 0.10
-
profileCounted
public void profileCounted(long length) Provides an alternative way to profile counted loops with less interpreter footprint. Please seeLoopConditionProfilefor 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 seeLoopConditionProfilefor 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 neverdeoptimizeon 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:
disablein classConditionProfile- 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:
resetin classConditionProfile- Since:
- 22.1
-
toString
- Overrides:
toStringin classConditionProfile- Since:
- 22.1
-
createCountingProfile
Deprecated.usecreate()instead.- Since:
- 0.10
-
create
Returns aLoopConditionProfilethat speculates on loop conditions to be nevertrue. It also captures loop probabilities for the compiler. Loop condition profiles are intended to be used for loop conditions.- Since:
- 21.2
-
getUncached
Returns the uncached version of the profile. The uncached version of a profile does nothing.- Since:
- 19.0
-
create()instead.