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 = new CyclicAssumption("symbols");
Map<String, Object> symbols = new ConcurrentHashMap<>();
public void redefineSymbol(String symbol, Object value) {
symbols.put(symbol, value);
symbolsRedefined.invalidate();
}
}
class SymbolLookupNode extends Node {
final MyContext context;
final String symbol;
@CompilerDirectives.CompilationFinal volatile LookupResult cachedLookup;
SymbolLookupNode(MyContext context, String symbol) {
this.context = context;
this.symbol = symbol;
}
public Object 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 Assumption
CyclicAssumption symbolsRedefined = context.symbolsRedefined;
Assumption assumption = symbolsRedefined.getAssumption();
// Then lookup the value
Object value = context.symbols.get(name);
return new LookupResult(assumption, value);
}
}
class LookupResult {
final Assumption assumption;
final Object 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()