public abstract class SLAddNode extends SLBinaryNode
Type specialization on the input values is essential for the performance. This is achieved via
node rewriting: specialized subclasses handle just a single type, so that the generic node that
can handle all types is used only in cases where different types were encountered. The subclasses
are automatically generated by the Truffle DSL. In addition, a factory class
is generated that provides, e.g., node creation.
| Constructor and Description |
|---|
SLAddNode() |
| Modifier and Type | Method and Description |
|---|---|
protected long |
add(long left,
long right)
Specialization for primitive
long values. |
protected com.oracle.truffle.api.strings.TruffleString |
add(Object left,
Object right,
SLToTruffleStringNode toTruffleStringNodeLeft,
SLToTruffleStringNode toTruffleStringNodeRight,
com.oracle.truffle.api.strings.TruffleString.ConcatNode concatNode)
Specialization for TruffleString concatenation.
|
protected SLBigNumber |
add(SLBigNumber left,
SLBigNumber right)
This is the slow path of the arbitrary-precision arithmetic.
|
protected boolean |
isString(Object a,
Object b)
Guard for TruffleString concatenation: returns true if either the left or the right operand
is a
TruffleString. |
protected Object |
typeError(Object left,
Object right) |
addExpressionTag, createWrapper, executeBoolean, executeGeneric, executeLong, executeVoid, hasTagaddRootTag, addStatementTag, formatSourceSection, getSourceCharIndex, getSourceEndIndex, getSourceLength, getSourceSection, hasSource, isInstrumentable, setSourceSection, setUnavailableSourceSection, toStringfindBlock, getVisibleVariablesIndexOnEnter, hasScope, setVisibleVariablesIndexOnEnter, setVisibleVariablesIndexOnExitaccept, adoptChildren, atomic, atomic, copy, deepCopy, getChildren, getCost, getDebugProperties, getDescription, getEncapsulatingSourceSection, getLock, getParent, getRootNode, insert, insert, isAdoptable, isSafelyReplaceableBy, notifyInserted, onReplace, replace, replace, reportPolymorphicSpecializeprotected long add(long left,
long right)
long values. This is the fast path of the
arbitrary-precision arithmetic. We need to check for overflows of the addition, and switch to
the slow path. Therefore, we use an
addition method that throws an exception on overflow. The
rewriteOn attribute on the Specialization annotation automatically triggers
the node rewriting on the exception.
In compiled code, addExact is compiled to efficient machine
code that uses the processor's overflow flag. Therefore, this method is compiled to only two
machine code instructions on the fast path.
This specialization is automatically selected by the Truffle DSL if both the left and right
operand are long values.
protected SLBigNumber add(SLBigNumber left, SLBigNumber right)
SLBigNumber type of
Java is doing everything we need.
This specialization is automatically selected by the Truffle DSL if both the left and right
operand are SLBigNumber values. Because the type system defines an
implicit conversion from long to SLBigNumber in
SLTypes.castBigNumber(long), this specialization is also taken if the left or the
right operand is a long value. Because the long
specialization} has the rewriteOn attribute, this specialization is also taken if
both input values are long values but the primitive addition overflows.
protected com.oracle.truffle.api.strings.TruffleString add(Object left, Object right, SLToTruffleStringNode toTruffleStringNodeLeft, SLToTruffleStringNode toTruffleStringNodeRight, com.oracle.truffle.api.strings.TruffleString.ConcatNode concatNode)
To implement these semantics, we tell the Truffle DSL to use a custom guard. The guard
function is defined in this class, but could also be in any superclass.
protected boolean isString(Object a, Object b)
TruffleString.