public class InvocationPluginHelper extends Object implements DebugCloseable
InvocationPlugins.
It's intentionally more limited than something like GraphKit because it's rarely useful
to write explicit plugins for complex pieces of logic. They are better handled by writing a
snippet for the complex logic and having an InvocationPlugin that performs any required
null checks or range checks and then adds a node which is later lowered by the snippet. A major
reason for this is that any complex control invariably has MergeNodes which are required
to have a valid FrameStates when they comes out of the parser. For intrinsics the only
valid FrameStates is the entry state and the state after the return and it can be hard to
correctly assign states to the merges. There is also little benefit to introducing complex
intrinsic graphs early because they are rarely amenable to high level optimizations.
The recommended usage pattern is to construct the helper instance in a try/resource block, which
performs some sanity checking when the block is exited.
try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) {
}
The main idiom provided is InvocationPluginHelper.emitReturnIf(LogicNode, boolean, ValueNode, double) plus
variants. It models a side exit from a main sequence of logic. FixedWithNextNodes are
inserted in the main control flow and until the final return value is emitted with
InvocationPluginHelper.emitFinalReturn(JavaKind, ValueNode). If only a single value is returned the normal
GraphBuilderContext.addPush(JavaKind, ValueNode) can be used instead.| Modifier and Type | Field and Description |
|---|---|
protected GraphBuilderContext |
b |
VOID_CLOSEABLE| Constructor and Description |
|---|
InvocationPluginHelper(GraphBuilderContext b,
ResolvedJavaMethod targetMethod) |
| Modifier and Type | Method and Description |
|---|---|
ValueNode |
add(ValueNode x,
ValueNode y) |
protected void |
addReturnValue(EndNode end,
JavaKind kind,
ValueNode returnValueInput)
Connects an
EndNode and return value into the final control flow merge. |
ValueNode |
arrayElementPointer(ValueNode array,
JavaKind kind,
ValueNode index) |
ValueNode |
arraylength(ValueNode receiverValue) |
ValueNode |
arrayStart(ValueNode array,
JavaKind kind)
Returns the address of the first element of an array.
|
ValueNode |
asWord(long index) |
ValueNode |
asWord(ValueNode index)
Ensures a primitive type is word sized.
|
void |
close() |
LogicNode |
createCompare(ValueNode x,
CanonicalCondition cond,
ValueNode y) |
GuardingNode |
doFallbackIf(LogicNode condition,
double probability) |
GuardingNode |
doFallbackIf(ValueNode x,
Condition condition,
ValueNode y,
double returnProbability) |
GuardingNode |
doFallbackIfNot(LogicNode condition,
double probability) |
void |
emitFinalReturn(JavaKind kind,
ValueNode origReturnValue) |
AbstractBeginNode |
emitReturnIf(LogicNode condition,
ValueNode returnValue,
double returnProbability) |
AbstractBeginNode |
emitReturnIf(ValueNode x,
Condition condition,
ValueNode y,
ValueNode returnValue,
double returnProbability) |
AbstractBeginNode |
emitReturnIfNot(LogicNode condition,
ValueNode returnValue,
double returnProbability) |
ResolvedJavaField |
getField(ResolvedJavaType type,
String fieldName)
Finds a Java field by name.
|
ValueNode |
getFieldOffset(ResolvedJavaType type,
String fieldName)
Gets the offset of a field.
|
JavaKind |
getWordKind() |
GuardingNode |
intrinsicRangeCheck(ValueNode x,
Condition condition,
ValueNode y)
Performs a range check for an intrinsic.
|
ValueNode |
length(ValueNode x) |
ValueNode |
loadField(ValueNode value,
ResolvedJavaField field) |
AddressNode |
makeOffsetAddress(ValueNode base,
ValueNode offset)
Builds an
OffsetAddressNode ensuring that the offset is also converted to a
Word. |
PiNode |
piCast(ValueNode value,
GuardingNode nonnullGuard,
Stamp stamp) |
ValueNode |
scale(ValueNode index,
JavaKind kind)
Shifts
index by the proper amount based on the element kind. |
ValueNode |
shl(ValueNode node,
int shiftAmount) |
ValueNode |
shr(ValueNode node,
int shiftAmount) |
ValueNode |
sub(ValueNode x,
ValueNode y) |
ValueNode |
ushr(ValueNode node,
int shiftAmount) |
ValueNode |
xor(ValueNode x,
ValueNode y) |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetDebugprotected final GraphBuilderContext b
public InvocationPluginHelper(GraphBuilderContext b, ResolvedJavaMethod targetMethod)
public void close()
close in interface AutoCloseableclose in interface DebugCloseablepublic JavaKind getWordKind()
public PiNode piCast(ValueNode value, GuardingNode nonnullGuard, Stamp stamp)
public ValueNode arrayElementPointer(ValueNode array, JavaKind kind, ValueNode index)
public ValueNode arrayStart(ValueNode array, JavaKind kind)
public ValueNode scale(ValueNode index, JavaKind kind)
index by the proper amount based on the element kind.public AddressNode makeOffsetAddress(ValueNode base, ValueNode offset)
OffsetAddressNode ensuring that the offset is also converted to a
Word.public ValueNode asWord(long index)
public LogicNode createCompare(ValueNode x, CanonicalCondition cond, ValueNode y)
public ResolvedJavaField getField(ResolvedJavaType type,
String fieldName)
GraalError - if the field isn't found.public ValueNode getFieldOffset(ResolvedJavaType type, String fieldName)
Snippet even triggers a
plugin that uses a field offset them some extra machinery will be needed to delay the lookup.public GuardingNode intrinsicRangeCheck(ValueNode x, Condition condition, ValueNode y)
public AbstractBeginNode emitReturnIf(LogicNode condition, ValueNode returnValue, double returnProbability)
public AbstractBeginNode emitReturnIf(ValueNode x, Condition condition, ValueNode y, ValueNode returnValue, double returnProbability)
public AbstractBeginNode emitReturnIfNot(LogicNode condition, ValueNode returnValue, double returnProbability)
public void emitFinalReturn(JavaKind kind,
ValueNode origReturnValue)
protected void addReturnValue(EndNode end, JavaKind kind, ValueNode returnValueInput)
EndNode and return value into the final control flow merge.public GuardingNode doFallbackIf(ValueNode x, Condition condition, ValueNode y, double returnProbability)
public GuardingNode doFallbackIfNot(LogicNode condition, double probability)
public GuardingNode doFallbackIf(LogicNode condition, double probability)