Snippets for calling from Java to C. This is the inverse of
CEntryPointSnippets
.
The
JavaFrameAnchor
has to be set up because the top of the stack will no longer be a
Java frame. In addition, the thread state needs to transition from being in
Java
state to being in
Native
state on the way in, and to transition the thread state from Native state to Java state
on the way out.
Among the complications is that the C function may try to return while a safepoint is in
progress, i.e., the thread state is not Native but
Safepoint
. It must not be allowed back into Java code until the safepoint is finished.
Only parts of these semantics can be implemented via snippets: The low-level code to initialize
the
JavaFrameAnchor
and to transition the thread from Java state to Native state must
only be done immediately before the call, because an accurate pointer map is necessary for the
last instruction pointer stored in the
JavaFrameAnchor
. Therefore, the
JavaFrameAnchor
is filled at the lowest possible level: during code generation as part of
the same LIR operation that emits the call to the C function. Using the same LIR instruction is
the only way to ensure that neither the instruction scheduler nor the register allocator emit any
instructions between the capture of the instruction pointer and the actual call instruction.