Package org.apache.groovy.runtime.indy
Class SwitchPointInvalidator
java.lang.Object
org.apache.groovy.runtime.indy.SwitchPointInvalidator
Lazily allocates a
SwitchPoint and retires it on demand.
Call sites install the switch point returned by getSwitchPoint() in
guardWithTest chains. invalidate() retires the live switch
point so linked sites fall back and re-link; the next getSwitchPoint()
allocates a fresh one.
Bulk paths (category enter/leave, custom MetaClass events) should prefer
detachLive() and a single SwitchPoint.invalidateAll(SwitchPoint[])
over many individual invalidate() calls (GROOVY-12191).
There is no permanent failover: after scoping stock invalidation to a single class, deopt storms from a process-wide SwitchPoint no longer apply, so a simpler replace-on-invalidate model is sufficient.
- Since:
- 6.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an invalidator with no live SwitchPoint until the firstgetSwitchPoint()call. -
Method Summary
Modifier and TypeMethodDescriptionAtomically detaches the live switch point for bulkSwitchPoint.invalidateAll(java.lang.invoke.SwitchPoint[])without invalidating it yet.intReturns how many live switch points have been retired.Returns a live switch point to install in a call-site guard chain.voidInvalidates the current live switch point (if any) so linked sites re-link.static voidInvalidatesspwhen non-null and still valid.
-
Constructor Details
-
SwitchPointInvalidator
public SwitchPointInvalidator()Creates an invalidator with no live SwitchPoint until the firstgetSwitchPoint()call. Field initializers own all state.
-
-
Method Details
-
getSwitchPoint
Returns a live switch point to install in a call-site guard chain. Lazily allocates on first use after construction or after retirement.- Returns:
- a live switch point (never
null)
-
invalidate
public void invalidate()Invalidates the current live switch point (if any) so linked sites re-link. A subsequentgetSwitchPoint()allocates a fresh switch point. -
detachLive
Atomically detaches the live switch point for bulkSwitchPoint.invalidateAll(java.lang.invoke.SwitchPoint[])without invalidating it yet. The caller must invalidate any non-null return value.- Returns:
- the detached live switch point, or
nullif none was live
-
getRetirementCount
public int getRetirementCount()Returns how many live switch points have been retired.- Returns:
- the retirement count
-
invalidateIfLive
Invalidatesspwhen non-null and still valid.- Parameters:
sp- candidate switch point (may benull)
-