// Wrap ExecuteSwitchImpl in assembly method which specifies DEX PC for unwinding.
// Argument 0: RDI: The context pointer for ExecuteSwitchImpl.
// Argument 1: RSI: Pointer to the templated ExecuteSwitchImpl to call.
// Argument 2: RDX: The value of DEX PC (memory address of the methods bytecode).
DEFINE_FUNCTION ExecuteSwitchImplAsm
PUSH rbx // Spill RBX
movq %rdx, %rbx // RBX = DEX PC (callee save register)
CFI_DEFINE_DEX_PC_WITH_OFFSET(0/* RAX */, 3 /* RBX */, 0)
call *%rsi // Call the wrapped function
POP rbx // Restore RBX
ret
END_FUNCTION ExecuteSwitchImplAsm
/* *Jnidlsymlookupstub.
*/
DEFINE_FUNCTION art_jni_dlsym_lookup_stub
// Save callee and GPR args.
PUSH_ARG r9 // Arg.
PUSH_ARG r8 // Arg.
PUSH_ARG rdi // Arg. (JniEnv for normal and @FastNative)
PUSH_ARG rsi // Arg.
PUSH_ARG rdx // Arg.
PUSH_ARG rcx // Arg.
// Create space for FPR args, plus padding for alignment
INCREASE_FRAME 72
// Save FPRs.
movq %xmm0, 0(%rsp)
movq %xmm1, 8(%rsp)
movq %xmm2, 16(%rsp)
movq %xmm3, 24(%rsp)
movq %xmm4, 32(%rsp)
movq %xmm5, 40(%rsp)
movq %xmm6, 48(%rsp)
movq %xmm7, 56(%rsp)
// prepare call
movq %gs:THREAD_SELF_OFFSET, %rdi // RDI := Thread::Current()
// Call artFindNativeMethod() for normal native and artFindNativeMethodRunnable()
// for @FastNative or @CriticalNative.
movq THREAD_TOP_QUICK_FRAME_OFFSET(%rdi), %rax // uintptr_t tagged_quick_frame
andq LITERAL(TAGGED_JNI_SP_MASK_TOGGLED64), %rax // ArtMethod** sp
movq (%rax), %rax // ArtMethod* method
#ifdef ART_USE_RESTRICTED_MODE
// Critical native methods are disabled and treated as normal native methods instead.
testl LITERAL(ACCESS_FLAGS_METHOD_IS_FAST_NATIVE), \
ART_METHOD_ACCESS_FLAGS_OFFSET(%rax)
#else
testl LITERAL(ACCESS_FLAGS_METHOD_IS_FAST_NATIVE | ACCESS_FLAGS_METHOD_IS_CRITICAL_NATIVE), \
ART_METHOD_ACCESS_FLAGS_OFFSET(%rax)
#endif
jne .Llookup_stub_fast_or_critical_native
call SYMBOL(artFindNativeMethod) // (Thread*)
jmp .Llookup_stub_continue
.Llookup_stub_fast_or_critical_native:
call SYMBOL(artFindNativeMethodRunnable) // (Thread*)
.Llookup_stub_continue:
// restore arguments
movq 0(%rsp), %xmm0
movq 8(%rsp), %xmm1
movq 16(%rsp), %xmm2
movq 24(%rsp), %xmm3
movq 32(%rsp), %xmm4
movq 40(%rsp), %xmm5
movq 48(%rsp), %xmm6
movq 56(%rsp), %xmm7
DECREASE_FRAME 72
POP_ARG rcx // Arg.
POP_ARG rdx // Arg.
POP_ARG rsi // Arg.
POP_ARG rdi // Arg. (JniEnv for normal and @FastNative)
POP_ARG r8 // Arg.
POP_ARG r9 // Arg.
testq %rax, %rax // check if returned method code is null
jz .Lno_native_code_found // if null, jump to return to handle
jmp *%rax // otherwise, tail call to intended method
.Lno_native_code_found:
ret
END_FUNCTION art_jni_dlsym_lookup_stub
// prepare for memcpy call
// (native stack ptr, simulator reserved area ptr, length of reserved area)
movq %rsp, %rdi // pass SP to param 0
// The simulated reserved area is still in rsi which is passed as param 1
movq LITERAL(GENERIC_JNI_TRAMPOLINE_RESERVED_AREA), %rdx // pass the length of memory to copy
call SYMBOL(memcpy)
// 120 bytes is the constant offset from the top of the reserved area to the pointer which
// points to the JNI stack args on the simulated stack. Space is always reserved for the
// maximum number of arguments so we can always load them all, even if some are unused.
//
// See a diagram near art_quick_generic_jni_trampoline and the number of native args from
// BuildNativeCallFrameStateMachine:
// 8 FP regs, 6 GP regs, Hidden arg = 120 bytes
movq (120)(%rsp), %r12
// def r12: delta between JNI stack args on the simulated stack and the simulated reserved area
// ptr.
subq 24(%rbp), %r12
// Save call target in scratch register.
movq (32)(%rbp), %r11
// Load hidden arg (rax) for @CriticalNative.
movq 112(%rsp), %rax
// Increase rsp from the reserved area pointer on the hardware stack, to point to the JNI stack
// args on the hardware stack.
addq %r12, %rsp
// native call
call *%r11
// Tear down the reserved area on the hardware stack. The reserved area on the simulated stack
// will be torn down after we return to art_quick_generic_jni_trampoline.
movq %rbp, %rsp
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.