public class CyclicAssumption extends Object
Assumption
, and knows how to recreate it with the same properties on
invalidation. Used as an Assumption factory that safely invalidates the previous Assumption and
creates a new Assumption on invalidation.
Note that you should be careful that repeated invalidations do not cause a deoptimization loop in that same way that you would with any other assumption.
The Assumption instance should be obtained before doing the operation depending on it. In other words:
CyclicAssumption.getAssumption()
class MyContext {CyclicAssumption
symbolsRedefined = newCyclicAssumption
("symbols");Map
<String
,Object
> symbols = newConcurrentHashMap
<>(); public void redefineSymbol(String
symbol,Object
value) { symbols.put(symbol, value); symbolsRedefined.invalidate(); } } class SymbolLookupNode extendsNode
{ final MyContext context; finalString
symbol; @CompilerDirectives.CompilationFinal
volatile LookupResult cachedLookup; SymbolLookupNode(MyContext context,String
symbol) { this.context = context; this.symbol = symbol; } publicObject
execute() { LookupResult lookup = cachedLookup; if (lookup == null || !lookup.assumption.isValid()) {CompilerDirectives
.transferToInterpreterAndInvalidate(); cachedLookup = doLookup(symbol); } return cachedLookup.value; } private LookupResult doLookup(String
name) { // First get the AssumptionCyclicAssumption
symbolsRedefined = context.symbolsRedefined;Assumption
assumption = symbolsRedefined.getAssumption(); // Then lookup the valueObject
value = context.symbols.get(name); return new LookupResult(assumption, value); } } class LookupResult { finalAssumption
assumption; finalObject
value; LookupResult(Assumption
assumption,Object
value) { this.assumption = assumption; this.value = value; } }
Constructor and Description |
---|
CyclicAssumption(String name) |
Modifier and Type | Method and Description |
---|---|
Assumption |
getAssumption() |
void |
invalidate() |
void |
invalidate(String message) |
public CyclicAssumption(String name)
public void invalidate()
public void invalidate(String message)
public Assumption getAssumption()