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 LoopConditionProfile
create()
Returns aLoopConditionProfile
that speculates on loop conditions to be nevertrue
.static LoopConditionProfile
Deprecated.void
disable()
Disables this profile by setting it to its generic state.static LoopConditionProfile
Returns the uncached version of the profile.boolean
inject
(boolean condition) Provides an alternative way to profile counted loops with less interpreter footprint.boolean
profile
(boolean condition) void
profileCounted
(long length) Provides an alternative way to profile counted loops with less interpreter footprint.void
reset()
Resets this profile to its uninitialized state.toString()
Methods inherited from class com.oracle.truffle.api.profiles.ConditionProfile
createBinaryProfile, inline
Methods inherited from class com.oracle.truffle.api.nodes.NodeCloneable
clone
-
Method Details
-
profile
public boolean profile(boolean condition) - Overrides:
profile
in classConditionProfile
- Since:
- 0.10
-
profileCounted
public void profileCounted(long length) Provides an alternative way to profile counted loops with less interpreter footprint. Please seeLoopConditionProfile
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 seeLoopConditionProfile
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 neverdeoptimize
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 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:
reset
in classConditionProfile
- Since:
- 22.1
-
toString
- Overrides:
toString
in classConditionProfile
- Since:
- 22.1
-
createCountingProfile
Deprecated.usecreate()
instead.- Since:
- 0.10
-
create
Returns aLoopConditionProfile
that 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.