public final class BytecodeOSRMetadata extends Object
BytecodeOSRNode.
Performance note: We do not require the metadata field to be volatile. As long as the
field is initialized under double-checked locking (as is done in
GraalRuntimeSupport.pollBytecodeOSRBackEdge(com.oracle.truffle.api.nodes.BytecodeOSRNode), all threads will observe the same metadata
instance. The JMM guarantees that the instance's final fields will be safely initialized before
it is published; the non-final + non-volatile fields (e.g., the back edge counter) may not be,
but we tolerate this inaccuracy in order to avoid volatile accesses in the hot path.
| Modifier and Type | Field and Description |
|---|---|
static BytecodeOSRMetadata |
DISABLED |
static int |
OSR_POLL_INTERVAL |
| Modifier and Type | Method and Description |
|---|---|
int |
getBackEdgeCount() |
Map<Integer,OptimizedCallTarget> |
getOSRCompilations() |
boolean |
incrementAndPoll()
Increment back edge count and return whether compilation should be polled.
|
void |
restoreFrame(com.oracle.truffle.api.impl.FrameWithoutBoxing source,
com.oracle.truffle.api.impl.FrameWithoutBoxing target)
Transfer state from
source to target. |
void |
transferFrame(com.oracle.truffle.api.impl.FrameWithoutBoxing source,
com.oracle.truffle.api.impl.FrameWithoutBoxing target,
int bytecodeTarget,
Object targetMetadata)
Transfer state from
source to target. |
public static final BytecodeOSRMetadata DISABLED
public static final int OSR_POLL_INTERVAL
public boolean incrementAndPoll()
When the OSR threshold is reached, this method will return true after every OSR_POLL_INTERVAL back-edges. This method is thread-safe, but could under-count.
public void transferFrame(com.oracle.truffle.api.impl.FrameWithoutBoxing source,
com.oracle.truffle.api.impl.FrameWithoutBoxing target,
int bytecodeTarget,
Object targetMetadata)
source to target. Can be used to transfer state into an
OSR frame.public void restoreFrame(com.oracle.truffle.api.impl.FrameWithoutBoxing source,
com.oracle.truffle.api.impl.FrameWithoutBoxing target)
source to target. Can be used to transfer state from an
OSR frame to a parent frame. Overall less efficient than its
counterpart,
mainly due to not being able to speculate on the source tags: While entering bytecode OSR is
done through specific entry points (likely back edges), returning could be done from anywhere
within a method body (through regular returns, or exception thrown).
While we could theoretically have the same mechanism as on entries (caching encountered
return state), we could not efficiently be able to retrieve from the cache (as we do not get
the equivalent of the int osrBytecodeTarget for returns), even ignoring the potential
memory cost of such a cache.
Therefore, we are doing a best-effort of copying over source to target, reading from the
actual frames rather than a cache: If the tag cannot be constant-folded at this point, we get
a switch in compiled code. Since we are at a boundary back to interpreted code, this cost
should not be too high.public Map<Integer,OptimizedCallTarget> getOSRCompilations()
public int getBackEdgeCount()