/* Deliver the given exception */
.extern artDeliverExceptionFromCode /* Deliver an exception pending on a thread */
.extern artDeliverPendingException
.macro SETUP_SAVE_REFS_AND_ARGS_FRAME rTemp
SETUP_SAVE_REFS_AND_ARGS_FRAME_REGISTERS_ONLY
LOAD_RUNTIME_INSTANCE \rTemp @ Load Runtime::Current into rTemp.
@ Load kSaveRefsAndArgs Method* into rTemp.
ldr \rTemp, [\rTemp, #RUNTIME_SAVE_REFS_AND_ARGS_METHOD_OFFSET]
str \rTemp, [sp, #0] @ Place Method* at bottom of stack.
str sp, [rSELF, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
.endm
.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_R0
SETUP_SAVE_REFS_AND_ARGS_FRAME_REGISTERS_ONLY
str r0, [sp, #0] @ Store ArtMethod* to bottom of stack.
str sp, [rSELF, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
.endm
/* *Macrothatsetsupthecalleesaveframetoconformwith *Runtime::CreateCalleeSaveMethod(kSaveEverything) *whencoreregistersarealreadysaved.
*/
.macro SETUP_SAVE_EVERYTHING_FRAME_CORE_REGS_SAVED rTemp, runtime_method_offset = RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET
@ 14 words of callee saves and args already saved.
vpush {d0-d15} @ 32 words, 2 for each of the 16 saved doubles.
.cfi_adjust_cfa_offset 128 sub sp, #8 @ 2 words of space, alignment padding and Method*
.cfi_adjust_cfa_offset 8
LOAD_RUNTIME_INSTANCE \rTemp @ Load Runtime::Current into rTemp.
@ Load kSaveEverything Method* into rTemp.
ldr \rTemp, [\rTemp, #\runtime_method_offset]
str \rTemp, [sp, #0] @ Place Method* at bottom of stack.
str sp, [rSELF, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
// Ugly compile-time check, but we only have the preprocessor.
#if (FRAME_SIZE_SAVE_EVERYTHING != 56 + 128 + 8)
#error "FRAME_SIZE_SAVE_EVERYTHING(ARM) size not as expected."
#endif
.endm
.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
.extern \cxx_name
ENTRY \c_name
SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r0 @ save all registers as basis for long jump context
mov r0, rSELF @ pass Thread::Current
bl \cxx_name @ \cxx_name(Thread*)
bl art_quick_do_long_jump @ (Context*)
bkpt // Unreached
END \c_name
.endm
.macro NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING c_name, cxx_name
.extern \cxx_name
ENTRY \c_name
SETUP_SAVE_EVERYTHING_FRAME r0 @ save all registers as basis for long jump context
mov r0, rSELF @ pass Thread::Current
bl \cxx_name @ \cxx_name(Thread*)
bl art_quick_do_long_jump @ (Context*)
bkpt // Unreached
END \c_name
.endm
.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
.extern \cxx_name
ENTRY \c_name
SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r1 @ save all registers as basis for long jump context
mov r1, rSELF @ pass Thread::Current
bl \cxx_name @ \cxx_name(Thread*)
bl art_quick_do_long_jump @ (Context*)
bkpt // Unreached
END \c_name
.endm
.macro TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING c_name, cxx_name
.extern \cxx_name
ENTRY \c_name
SETUP_SAVE_EVERYTHING_FRAME r2 @ save all registers as basis for long jump context
mov r2, rSELF @ pass Thread::Current
bl \cxx_name @ \cxx_name(Thread*)
bl art_quick_do_long_jump @ (Context*)
bkpt // Unreached
END \c_name
.endm
.macro RETURN_OR_DEOPT_IF_INT_RESULT_IS_ZERO_OR_DELIVER
CFI_REMEMBER_STATE
cbnz r0, 1f @ result non-zero branch over
DEOPT_OR_RETURN r1 1:
CFI_RESTORE_STATE_AND_DEF_CFA sp, 0
DELIVER_PENDING_EXCEPTION
.endm
.macro RETURN_OR_DEOPT_IF_RESULT_IS_NON_NULL_OR_DELIVER
CFI_REMEMBER_STATE
cbz r0, 1f @ result zero branch over
DEOPT_OR_RETURN r1, /* is_ref= */ 1 1:
CFI_RESTORE_STATE_AND_DEF_CFA sp, 0
DELIVER_PENDING_EXCEPTION
.endm
// Macros taking opportunity of code similarities for downcalls.
// Used for field and allocation entrypoints.
.macro N_ARG_DOWNCALL n, name, entrypoint, return
.extern \entrypoint
ENTRY \name
SETUP_SAVE_REFS_ONLY_FRAME r\n @ save callee saves in case of GC
mov r\n, rSELF @ pass Thread::Current
bl \entrypoint @ (<args>, Thread*)
RESTORE_SAVE_REFS_ONLY_FRAME
REFRESH_MARKING_REGISTER
\return
END \name
.endm
/* *CallinstalledbyasignalhandlertocreateanddeliveraNullPointerException.
*/
.extern art_quick_throw_null_pointer_exception_from_signal
ENTRY art_quick_throw_null_pointer_exception_from_signal
// The fault handler pushes the gc map address, i.e. "return address", to stack
// and passes the fault address in LR. So we need to set up the CFI info accordingly.
.cfi_def_cfa_offset __SIZEOF_POINTER__
.cfi_rel_offset lr, 0
push {r0-r12} @ 13 words of callee saves and args; LR already saved.
.cfi_adjust_cfa_offset 52
.cfi_rel_offset r0, 0
.cfi_rel_offset r1, 4
.cfi_rel_offset r2, 8
.cfi_rel_offset r3, 12
.cfi_rel_offset r4, 16
.cfi_rel_offset r5, 20
.cfi_rel_offset r6, 24
.cfi_rel_offset r7, 28
.cfi_rel_offset r8, 32
.cfi_rel_offset r9, 36
.cfi_rel_offset r10, 40
.cfi_rel_offset r11, 44
.cfi_rel_offset ip, 48
@ save all registers as basis for long jump context
SETUP_SAVE_EVERYTHING_FRAME_CORE_REGS_SAVED r1
mov r0, lr @ pass the fault address stored in LR by the fault handler.
mov r1, rSELF @ pass Thread::Current
bl artThrowNullPointerExceptionFromSignal @ (Thread*)
bl art_quick_do_long_jump @ (Context*)
bkpt // Unreached
END art_quick_throw_null_pointer_exception_from_signal
add r4, r2, #4 @ create space for method pointer in frame sub r4, sp, r4 @ reserve & align *stack* to 16 bytes: native calling
and r4, #0xFFFFFFF0 @ convention only aligns to 8B, so we have to ensure ART
mov sp, r4 @ 16B alignment ourselves.
mov r4, r0 @ save method*
add r0, sp, #4 @ pass stack pointer + method ptr as dest for memcpy
bl memcpy @ memcpy (dest, src, bytes)
mov ip, #0 @ set ip to 0
str ip, [sp] @ store null for method* at bottom of frame
ldr ip, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32] @ get pointer to the code
blx ip @ call the method
mov sp, r11 @ restore the stack pointer
.cfi_def_cfa_register sp
ldr r4, [sp, #40] @ load result_is_float
ldr r9, [sp, #36] @ load the result pointer
cmp r4, #0
ite eq
strdeq r0, [r9] @ store r0/r1 into result pointer
vstrne d0, [r9] @ store s0-s1/d0 into result pointer
pop {r4, r5, r6, r7, r8, r9, r10, r11, pc} @ restore spill regs
END art_quick_invoke_stub_internal
/* *Onstackreplacementstub. *Onentry: *r0=stacktocopy *r1=sizeofstack *r2=pctocall *r3=JValue*result *[sp]=shorty *[sp+4]=thread
*/
ENTRY art_quick_osr_stub
SPILL_ALL_CALLEE_SAVE_GPRS @ Spill regs (9)
vpush {s16-s31} @ Spill fp-regs (16)
.cfi_adjust_cfa_offset 64
SAVE_SIZE=(9*4+16*4)
mov r11, sp @ Save the stack pointer
.cfi_def_cfa r11, SAVE_SIZE @ CFA = r11 + SAVE_SIZE
CFI_REMEMBER_STATE
mov r10, r1 @ Save size of stack
ldr r9, [r11, #(SAVE_SIZE+4)] @ Move managed thread pointer into r9
REFRESH_MARKING_REGISTER
mov r6, r2 @ Save the pc to call sub r7, sp, #12 @ Reserve space for stack pointer,
@ JValue* result, and ArtMethod* slot.
and r7, #0xFFFFFFF0 @ Align stack pointer
mov sp, r7 @ Update stack pointer
str r11, [sp, #4] @ Save old stack pointer
str r3, [sp, #8] @ Save JValue* result
mov ip, #0
str ip, [sp] @ Store null for ArtMethod* at bottom of frame
// r11 isn't properly spilled in the osr method, so we need use DWARF expression.
// NB: the CFI must be before the call since this is the address gdb will lookup.
// NB: gdb expects that cfa_expression returns the CFA value (not address to it).
.cfi_escape /* CFA = [sp + 4] + SAVE_SIZE */ \ 0x0f, 6, /* DW_CFA_def_cfa_expression(len) */ \ 0x92, 13, 4, /* DW_OP_bregx(reg,offset) */ \ 0x06, /* DW_OP_deref */ \ 0x23, SAVE_SIZE /* DW_OP_plus_uconst(val) */
bl .Losr_entry @ Call the method
ldr r10, [sp, #8] @ Restore JValue* result
ldr sp, [sp, #4] @ Restore saved stack pointer
.cfi_def_cfa sp, SAVE_SIZE @ CFA = sp + SAVE_SIZE
strd r0, [r10] @ Store r0/r1 into result pointer
vpop {s16-s31}
.cfi_adjust_cfa_offset -64
pop {r4, r5, r6, r7, r8, r9, r10, r11, pc}
.Losr_entry:
CFI_RESTORE_STATE_AND_DEF_CFA r11, SAVE_SIZE @ CFA = r11 + SAVE_SIZE sub sp, sp, r10 @ Reserve space for callee stack sub r10, r10, #4
str lr, [sp, r10] @ Store link register per the compiler ABI
mov r2, r10
mov r1, r0
mov r0, sp
bl memcpy @ memcpy (dest r0, src r1, bytes r2)
bx r6
END art_quick_osr_stub
/* *Onentryr0isthelongjumpcontext.Thisisexpectedtobereturnedfromaprevious *entrypointcallwhichthrewanexceptionordeoptimized. *Ther12(IP)shallbeclobberedratherthanretrievedfromgprs_.
*/
ARM_ENTRY art_quick_do_long_jump
// We don't use the LR, but it is needed for unwinding.
str lr, [sp, #-8]!
.cfi_adjust_cfa_offset 8
.cfi_rel_offset lr, 0
// Reserve space for the gprs + fprs;
INCREASE_FRAME ARM_LONG_JUMP_CONTEXT_SIZE
vldm r0, {s0-s31} @ Load all fprs from argument fprs_.
@ Do not access fprs_ from now, they may be below SP.
ldm sp, {r0-r11} @ load r0-r11 from gprs_.
ldr r12, [sp, #60] @ Load the value of PC (r15) from gprs_ (60 = 4 * 15) into IP (r12).
ldr lr, [sp, #56] @ Load LR from gprs_, 56 = 4 * 14.
ldr sp, [sp, #52] @ Load SP from gprs_ 52 = 4 * 13.
@ Do not access gprs_ from now, they are below SP.
.cfi_def_cfa_offset 0
.cfi_register lr, r12
REFRESH_MARKING_REGISTER
bx r12 @ Do long jump.
END art_quick_do_long_jump
/* *Entryfrommanagedcodethattriestolocktheobjectinafastpathand *calls`artLockObjectFromCode()`forthedifficultcases,mayblockforGC. *r0holdsthepossiblynullobjecttolock.
*/
ENTRY art_quick_lock_object
// Note: the slow path is actually the art_quick_lock_object_no_inline (tail call).
LOCK_OBJECT_FAST_PATH r0, r1, r2, r3, .Llock_object_slow, /*can_be_null*/ 1
END art_quick_lock_object
/* *Entryfrommanagedcodethatcalls`artLockObjectFromCode()`,mayblockforGC. *r0holdsthepossiblynullobjecttolock.
*/
.extern artLockObjectFromCode
ENTRY art_quick_lock_object_no_inline
// This is also the slow path for art_quick_lock_object.
// Note that we need a local label as the assembler emits bad instructions
// for CBZ/CBNZ if we try to jump to `art_quick_lock_object_no_inline`.
.Llock_object_slow:
SETUP_SAVE_REFS_ONLY_FRAME r1 @ save callee saves in case we block
mov r1, rSELF @ pass Thread::Current
bl artLockObjectFromCode @ (Object* obj, Thread*)
RESTORE_SAVE_REFS_ONLY_FRAME
REFRESH_MARKING_REGISTER
RETURN_OR_DEOPT_IF_INT_RESULT_IS_ZERO_OR_DELIVER
END art_quick_lock_object_no_inline
/* *Entryfrommanagedcodethattriestounlocktheobjectinafastpathandcalls *`artUnlockObjectFromCode()`forthedifficultcasesanddeliversexceptiononfailure. *r0holdsthepossiblynullobjecttounlock.
*/
ENTRY art_quick_unlock_object
// Note: the slow path is actually the art_quick_unlock_object_no_inline (tail call).
UNLOCK_OBJECT_FAST_PATH r0, r1, r2, r3, .Lunlock_object_slow, /*can_be_null*/ 1
END art_quick_unlock_object
/* *Entryfrommanagedcodethatcalls`artUnlockObjectFromCode()` *anddeliversexceptiononfailure. *r0holdsthepossiblynullobjecttounlock.
*/
.extern artUnlockObjectFromCode
ENTRY art_quick_unlock_object_no_inline
// This is also the slow path for art_quick_unlock_object.
// Note that we need a local label as the assembler emits bad instructions
// for CBZ/CBNZ if we try to jump to `art_quick_unlock_object_no_inline`.
.Lunlock_object_slow:
@ save callee saves in case exception allocation triggers GC
SETUP_SAVE_REFS_ONLY_FRAME r1
mov r1, rSELF @ pass Thread::Current
bl artUnlockObjectFromCode @ (Object* obj, Thread*)
RESTORE_SAVE_REFS_ONLY_FRAME
REFRESH_MARKING_REGISTER
RETURN_OR_DEOPT_IF_INT_RESULT_IS_ZERO_OR_DELIVER
END art_quick_unlock_object_no_inline
/* *EntryfrommanagedcodethatcallsartInstanceOfFromCodeandonfailurecalls *artThrowClassCastExceptionForObject.
*/
.extern artInstanceOfFromCode
.extern artThrowClassCastExceptionForObject
ENTRY art_quick_check_instance_of
// Type check using the bit string passes null as the target class. In that case just throw.
cbz r1, .Lthrow_class_cast_exception_for_bitstring_check
push {r0-r2, lr} @ save arguments, padding (r2) and link register
.cfi_adjust_cfa_offset 16
.cfi_rel_offset r0, 0
.cfi_rel_offset r1, 4
.cfi_rel_offset r2, 8
.cfi_rel_offset lr, 12
bl artInstanceOfFromCode
cbz r0, .Lthrow_class_cast_exception
pop {r0-r2, pc}
.Lthrow_class_cast_exception:
pop {r0-r2, lr}
.cfi_adjust_cfa_offset -16
.cfi_restore r0
.cfi_restore r1
.cfi_restore r2
.cfi_restore lr
.Lthrow_class_cast_exception_for_bitstring_check:
SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r2 @ save all registers as basis for long jump context
mov r2, rSELF @ pass Thread::Current
bl artThrowClassCastExceptionForObject @ (Object*, Class*, Thread*)
bl art_quick_do_long_jump @ (Context*)
bkpt // Unreached
END art_quick_check_instance_of
// Restore rReg's value from [sp, #offset] if rReg is not the same as rExclude.
.macro POP_REG_NE rReg, offset, rExclude
.ifnc \rReg, \rExclude
ldr \rReg, [sp, #\offset] @ restore rReg
.cfi_restore \rReg
.endif
.endm
// Save rReg's value to [sp, #offset].
.macro PUSH_REG rReg, offset
str \rReg, [sp, #\offset] @ save rReg
.cfi_rel_offset \rReg, \offset
.endm
cmp r3, r4 @ value's type == array's component type - trivial assignability
// All registers are set up for correctly `.Laput_obj_check_assignability`.
bne .Laput_obj_check_assignability
b .Laput_obj_store
.Laput_obj_mark_array_class:
BAKER_RB_LOAD_AND_MARK r3, r0, MIRROR_OBJECT_CLASS_OFFSET, art_quick_read_barrier_mark_reg03
b .Laput_obj_mark_array_class_continue
.Laput_obj_mark_array_element:
BAKER_RB_LOAD_AND_MARK \
r3, r3, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, art_quick_read_barrier_mark_reg03
b .Laput_obj_mark_array_element_continue
.Laput_obj_mark_object_class:
BAKER_RB_LOAD_AND_MARK r4, r2, MIRROR_OBJECT_CLASS_OFFSET, art_quick_read_barrier_mark_reg04
b .Laput_obj_mark_object_class_continue
#endif // defined(USE_READ_BARRIER) && defined(USE_BAKER_READ_BARRIER)
END art_quick_aput_obj
/* *MacroforresolutionandinitializationofindexedDEXfile *constantssuchasclassesandstrings.
*/
.macro ONE_ARG_SAVE_EVERYTHING_DOWNCALL name, entrypoint, runtime_method_offset = RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET
.extern \entrypoint
ENTRY \name
SETUP_SAVE_EVERYTHING_FRAME r1, \runtime_method_offset @ save everything in case of GC
mov r1, rSELF @ pass Thread::Current
bl \entrypoint @ (uint32_t index, Thread*)
cbz r0, 1f @ If result is null, deliver the OOME.
str r0, [sp, #136] @ store result in the frame
DEOPT_OR_RESTORE_SAVE_EVERYTHING_FRAME_AND_RETURN_R0 r1, /* is_ref= */ 1 1:
DELIVER_PENDING_EXCEPTION_FRAME_READY
END \name
.endm
// Note: Functions `art{Get,Set}<Kind>{Static,Instance}FromCompiledCode` are
// defined with a macro in runtime/entrypoints/quick/quick_field_entrypoints.cc.
GENERATE_STATIC_FIELD_GETTERS
GENERATE_INSTANCE_FIELD_GETTERS
GENERATE_STATIC_FIELD_SETTERS /* emit64= */ 0
GENERATE_INSTANCE_FIELD_SETTERS /* emit64= */ 0
/* *Calledbymanagedcodetoresolveaninstancefieldandstoreawidevalue.
*/
.extern artSet64InstanceFromCompiledCode
ENTRY art_quick_set64_instance
SETUP_SAVE_REFS_ONLY_FRAME r12 @ save callee saves in case of GC
@ r2:r3 contain the wide argument
str rSELF, [sp, #-16]! @ expand the frame and pass Thread::Current
.cfi_adjust_cfa_offset 16
bl artSet64InstanceFromCompiledCode @ (field_idx, Object*, new_val, Thread*)
add sp, #16 @ release out args
.cfi_adjust_cfa_offset -16
RESTORE_SAVE_REFS_ONLY_FRAME @ TODO: we can clearly save an add here
REFRESH_MARKING_REGISTER
RETURN_OR_DEOPT_IF_INT_RESULT_IS_ZERO_OR_DELIVER
END art_quick_set64_instance
.extern artSet64StaticFromCompiledCode
ENTRY art_quick_set64_static
SETUP_SAVE_REFS_ONLY_FRAME r12 @ save callee saves in case of GC
@ r2:r3 contain the wide argument
str rSELF, [sp, #-16]! @ expand the frame and pass Thread::Current
.cfi_adjust_cfa_offset 16
bl artSet64StaticFromCompiledCode @ (field_idx, new_val, Thread*)
add sp, #16 @ release out args
.cfi_adjust_cfa_offset -16
RESTORE_SAVE_REFS_ONLY_FRAME @ TODO: we can clearly save an add here
REFRESH_MARKING_REGISTER
RETURN_OR_DEOPT_IF_INT_RESULT_IS_ZERO_OR_DELIVER
END art_quick_set64_static
// Generate the allocation entrypoints for each allocator.
GENERATE_ALLOC_ENTRYPOINTS_FOR_NON_TLAB_ALLOCATORS
// Comment out allocators that have arm specific asm.
// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_tlab, RegionTLAB)
// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_region_tlab, RegionTLAB)
GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_OBJECT(_region_tlab, RegionTLAB)
// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_region_tlab, RegionTLAB)
// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED8(_region_tlab, RegionTLAB)
// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED16(_region_tlab, RegionTLAB)
// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED32(_region_tlab, RegionTLAB)
// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED64(_region_tlab, RegionTLAB)
GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_region_tlab, RegionTLAB)
GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_region_tlab, RegionTLAB)
GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_region_tlab, RegionTLAB)
// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_RESOLVED_OBJECT(_rosalloc, RosAlloc).
//
// If isInitialized=1 then the compiler assumes the object's class has already been initialized.
// If isInitialized=0 the compiler can only assume it's been at least resolved.
.macro ART_QUICK_ALLOC_OBJECT_ROSALLOC c_name, cxx_name, isInitialized
ENTRY \c_name
// Fast path rosalloc allocation.
// r0: type/return value, rSELF (r9): Thread::Current
// r1, r2, r3, r12: free.
ldr r3, [rSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
// allocation stack has room.
// TODO: consider using ldrd.
ldr r12, [rSELF, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
cmp r3, r12
bhs .Lslow_path\c_name
ldr r3, [r0, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (r3)
cmp r3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
// local allocation.
// If the class is not yet visibly initialized, or it is finalizable,
// the object size will be very large to force the branch below to be taken.
//
// See Class::SetStatus() in class.cc for more details.
bhs .Lslow_path\c_name
// Compute the rosalloc bracket index
// from the size. Since the size is
// already aligned we can combine the
// two shifts together.
add r12, rSELF, r3, lsr #(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT - POINTER_SIZE_SHIFT)
// Subtract pointer size since there
// are no runs for 0 byte allocations
// and the size is already aligned.
// Load the rosalloc run (r12)
ldr r12, [r12, #(THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)]
// Load the free list head (r3). This
// will be the return val.
ldr r3, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
cbz r3, .Lslow_path\c_name
// "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
ldr r1, [r3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
// and update the list head with the
// next pointer.
str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
// Store the class pointer in the
// header. This also overwrites the
// next pointer. The offsets are
// asserted to match.
#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
#error "Class pointer needs to overwrite next pointer."
#endif
POISON_HEAP_REF r0
str r0, [r3, #MIRROR_OBJECT_CLASS_OFFSET]
// Push the new object onto the thread
// local allocation stack and
// increment the thread local
// allocation stack top.
ldr r1, [rSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
str r3, [r1], #COMPRESSED_REFERENCE_SIZE // (Increment r1 as a side effect.)
str r1, [rSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
// Decrement the size of the free list
// After this "STR" the object is published to the thread local allocation stack,
// and it will be observable from a runtime internal (eg. Heap::VisitObjects) point of view.
// It is not yet visible to the running (user) compiled code until after the return.
//
// To avoid the memory barrier prior to the "STR", a trick is employed, by differentiating
// the state of the allocation stack slot. It can be a pointer to one of:
// 0) Null entry, because the stack was bumped but the new pointer wasn't written yet.
// (The stack initial state is "null" pointers).
// 1) A partially valid object, with an invalid class pointer to the next free rosalloc slot.
// 2) A fully valid object, with a valid class pointer pointing to a real class.
// Other states are not allowed.
//
// An object that is invalid only temporarily, and will eventually become valid.
// The internal runtime code simply checks if the object is not null or is partial and then
// ignores it.
//
// (Note: The actual check is done by seeing if a non-null object has a class pointer pointing
// to ClassClass, and that the ClassClass's class pointer is self-cyclic. A rosalloc free slot
// "next" pointer is not-cyclic.)
//
// See also b/28790624 for a listing of CLs dealing with this race.
ldr r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)] sub r1, #1
// TODO: consider combining this store
// and the list head store above using
// strd.
str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
mov r0, r3 // Set the return value and return.
// No barrier. The class is already observably initialized (otherwise the fast
// path size check above would fail) and new-instance allocations are protected
// from publishing by the compiler which inserts its own StoreStore barrier.
bx lr
.Lslow_path\c_name:
SETUP_SAVE_REFS_ONLY_FRAME r2 @ save callee saves in case of GC
mov r1, rSELF @ pass Thread::Current
bl \cxx_name @ (mirror::Class* cls, Thread*)
RESTORE_SAVE_REFS_ONLY_FRAME
REFRESH_MARKING_REGISTER
RETURN_OR_DEOPT_IF_RESULT_IS_NON_NULL_OR_DELIVER
END \c_name
.endm
// The common fast path code for art_quick_alloc_object_resolved/initialized_tlab
// and art_quick_alloc_object_resolved/initialized_region_tlab.
//
// r0: type, rSELF (r9): Thread::Current, r1, r2, r3, r12: free.
// Need to preserve r0 to the slow path.
//
// If isInitialized=1 then the compiler assumes the object's class has already been initialized.
// If isInitialized=0 the compiler can only assume it's been at least resolved.
.macro ALLOC_OBJECT_RESOLVED_TLAB_FAST_PATH slowPathLabel isInitialized
// Load thread_local_pos (r12) and
// thread_local_end (r3) with ldrd.
// Check constraints for ldrd.
#if !((THREAD_LOCAL_POS_OFFSET + 4 == THREAD_LOCAL_END_OFFSET) && (THREAD_LOCAL_POS_OFFSET % 8 == 0))
#error "Thread::thread_local_pos/end must be consecutive and are 8 byte aligned for performance"
#endif
ldrd r12, r3, [rSELF, #THREAD_LOCAL_POS_OFFSET] sub r12, r3, r12 // Compute the remaining buf size.
ldr r3, [r0, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (r3).
cmp r3, r12 // Check if it fits.
// If the class is not yet visibly initialized, or it is finalizable,
// the object size will be very large to force the branch below to be taken.
//
// See Class::SetStatus() in class.cc for more details.
bhi \slowPathLabel
// "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
// Reload old thread_local_pos (r0)
// for the return value.
ldr r2, [rSELF, #THREAD_LOCAL_POS_OFFSET]
add r1, r2, r3
str r1, [rSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
// After this "STR" the object is published to the thread local allocation stack,
// and it will be observable from a runtime internal (eg. Heap::VisitObjects) point of view.
// It is not yet visible to the running (user) compiled code until after the return.
//
// To avoid the memory barrier prior to the "STR", a trick is employed, by differentiating
// the state of the object. It can be either:
// 1) A partially valid object, with a null class pointer
// (because the initial state of TLAB buffers is all 0s/nulls).
// 2) A fully valid object, with a valid class pointer pointing to a real class.
// Other states are not allowed.
//
// An object that is invalid only temporarily, and will eventually become valid.
// The internal runtime code simply checks if the object is not null or is partial and then
// ignores it.
//
// (Note: The actual check is done by checking that the object's class pointer is non-null.
// Also, unlike rosalloc, the object can never be observed as null).
POISON_HEAP_REF r0
str r0, [r2, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
mov r0, r2
// No barrier. The class is already observably initialized (otherwise the fast
// path size check above would fail) and new-instance allocations are protected
// from publishing by the compiler which inserts its own StoreStore barrier.
bx lr
.endm
// The common code for art_quick_alloc_object_*region_tlab
// Currently the implementation ignores isInitialized. TODO(b/172087402): clean this up.
// Caller must execute a constructor fence after this.
.macro GENERATE_ALLOC_OBJECT_RESOLVED_TLAB name, entrypoint, isInitialized
ENTRY \name
// Fast path tlab allocation.
// r0: type, rSELF (r9): Thread::Current
// r1, r2, r3, r12: free.
ALLOC_OBJECT_RESOLVED_TLAB_FAST_PATH .Lslow_path\name, \isInitialized
.Lslow_path\name:
SETUP_SAVE_REFS_ONLY_FRAME r2 // Save callee saves in case of GC.
mov r1, rSELF // Pass Thread::Current.
bl \entrypoint // (mirror::Class* klass, Thread*)
RESTORE_SAVE_REFS_ONLY_FRAME
REFRESH_MARKING_REGISTER
RETURN_OR_DEOPT_IF_RESULT_IS_NON_NULL_OR_DELIVER
END \name
.endm
// The common fast path code for art_quick_alloc_array_resolved/initialized_tlab
// and art_quick_alloc_array_resolved/initialized_region_tlab.
//
// r0: type, r1: component_count, r2: total_size, rSELF (r9): Thread::Current, r3, r12: free.
// Need to preserve r0 and r1 to the slow path.
.macro ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED_WITH_SIZE slowPathLabel
and r2, r2, #OBJECT_ALIGNMENT_MASK_TOGGLED // Apply alignment mask
// (addr + 7) & ~7.
// Load thread_local_pos (r3) and
// thread_local_end (r12) with ldrd.
// Check constraints for ldrd.
#if !((THREAD_LOCAL_POS_OFFSET + 4 == THREAD_LOCAL_END_OFFSET) && (THREAD_LOCAL_POS_OFFSET % 8 == 0))
#error "Thread::thread_local_pos/end must be consecutive and are 8 byte aligned for performance"
#endif
ldrd r3, r12, [rSELF, #THREAD_LOCAL_POS_OFFSET] sub r12, r12, r3 // Compute the remaining buf size.
cmp r2, r12 // Check if the total_size fits.
// The array class is always initialized here. Unlike new-instance,
// this does not act as a double test.
bhi \slowPathLabel
// "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
add r2, r2, r3
str r2, [rSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
POISON_HEAP_REF r0
str r0, [r3, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
str r1, [r3, #MIRROR_ARRAY_LENGTH_OFFSET] // Store the array length.
mov r0, r3
// new-array is special. The class is loaded and immediately goes to the Initialized state
// before it is published. Therefore the only fence needed is for the publication of the object.
// See ClassLinker::CreateArrayClass() for more details.
// For publication of the new array, we don't need a 'dmb ishst' here.
// The compiler generates 'dmb ishst' for all new-array insts.
bx lr
.endm
// Caller must execute a constructor fence after this.
.macro GENERATE_ALLOC_ARRAY_TLAB name, entrypoint, size_setup
ENTRY \name
// Fast path array allocation for region tlab allocation.
// r0: mirror::Class* type
// r1: int32_t component_count
// rSELF (r9): thread
// r2, r3, r12: free.
\size_setup .Lslow_path\name
ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED_WITH_SIZE .Lslow_path\name
.Lslow_path\name:
// r0: mirror::Class* klass
// r1: int32_t component_count
// r2: Thread* self
SETUP_SAVE_REFS_ONLY_FRAME r2 // save callee saves in case of GC
mov r2, rSELF // pass Thread::Current
bl \entrypoint
RESTORE_SAVE_REFS_ONLY_FRAME
REFRESH_MARKING_REGISTER
RETURN_OR_DEOPT_IF_RESULT_IS_NON_NULL_OR_DELIVER
END \name
.endm
.macro COMPUTE_ARRAY_SIZE_UNKNOWN slow_path
movw r2, #((MIN_LARGE_OBJECT_THRESHOLD - MIRROR_WIDE_ARRAY_DATA_OFFSET) / 8)
cmp r1, r2
bhi \slow_path
// Array classes are never finalizable
// or uninitialized, no need to check.
ldr r3, [r0, #MIRROR_CLASS_COMPONENT_TYPE_OFFSET] // Load component type
UNPOISON_HEAP_REF r3
ldr r3, [r3, #MIRROR_CLASS_OBJECT_PRIMITIVE_TYPE_OFFSET]
lsr r3, r3, #PRIMITIVE_TYPE_SIZE_SHIFT_SHIFT // Component size shift is in high 16
// bits.
lsl r2, r1, r3 // Calculate datasize
// Add array data offset and alignment.
add r2, r2, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
#if MIRROR_WIDE_ARRAY_DATA_OFFSET != MIRROR_INT_ARRAY_DATA_OFFSET + 4
#error Long array data offset must be 4 greater than int array data offset.
#endif
add r3, r3, #1 // Add 4 to the length only if the
// component size shift is 3
// (for 64 bit alignment).
and r3, r3, #4
add r2, r2, r3
.endm
.macro COMPUTE_ARRAY_SIZE_8 slow_path
// Possibly a large object, go slow.
// Also does negative array size check.
movw r2, #(MIN_LARGE_OBJECT_THRESHOLD - MIRROR_INT_ARRAY_DATA_OFFSET)
cmp r1, r2
bhi \slow_path
// Add array data offset and alignment.
add r2, r1, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
.endm
.macro COMPUTE_ARRAY_SIZE_16 slow_path
// Possibly a large object, go slow.
// Also does negative array size check.
movw r2, #((MIN_LARGE_OBJECT_THRESHOLD - MIRROR_INT_ARRAY_DATA_OFFSET) / 2)
cmp r1, r2
bhi \slow_path
lsl r2, r1, #1
// Add array data offset and alignment.
add r2, r2, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
.endm
.macro COMPUTE_ARRAY_SIZE_32 slow_path
// Possibly a large object, go slow.
// Also does negative array size check.
movw r2, #((MIN_LARGE_OBJECT_THRESHOLD - MIRROR_INT_ARRAY_DATA_OFFSET) / 4)
cmp r1, r2
bhi \slow_path
lsl r2, r1, #2
// Add array data offset and alignment.
add r2, r2, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
.endm
.macro COMPUTE_ARRAY_SIZE_64 slow_path
// Possibly a large object, go slow.
// Also does negative array size check.
movw r2, #((MIN_LARGE_OBJECT_THRESHOLD - MIRROR_LONG_ARRAY_DATA_OFFSET) / 8)
cmp r1, r2
bhi \slow_path
lsl r2, r1, #3
// Add array data offset and alignment.
add r2, r2, #(MIRROR_WIDE_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
.endm
/* *Calledbymanagedcodethatisattemptingtocallamethodonaproxyclass.Onentry *r0holdstheproxymethodandr1holdsthereceiver;r2andr3maycontainarguments.The *framesizeoftheinvokedproxymethodagreeswitharefandargscalleesaveframe.
*/
.extern artQuickProxyInvokeHandler
ENTRY art_quick_proxy_invoke_handler
SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_R0
mov r2, rSELF @ pass Thread::Current
mov r3, sp @ pass SP
blx artQuickProxyInvokeHandler @ (Method* proxy method, receiver, Thread*, SP)
ldr r2, [rSELF, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
// Tear down the callee-save frame. Skip arg registers.
add sp, #(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
.cfi_adjust_cfa_offset -(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
RESTORE_SAVE_REFS_ONLY_FRAME
REFRESH_MARKING_REGISTER
cbnz r2, 1f @ success if no exception is pending
vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
bx lr @ return on success 1:
DELIVER_PENDING_EXCEPTION
END art_quick_proxy_invoke_handler
/* *Calledtoresolveanimtconflict. *r0istheconflictArtMethod. *r12isahiddenargumentthatholdsthetargetinterfacemethod. * *Notethatthisstubwritestor0,r4,andr12.
*/
ENTRY art_quick_imt_conflict_trampoline
ldr r0, [r0, #ART_METHOD_JNI_OFFSET_32] // Load ImtConflictTable
ldr r4, [r0] // Load first entry in ImtConflictTable.
.Limt_table_iterate:
cmp r4, r12
// Branch if found. Benchmarks have shown doing a branch here is better.
beq .Limt_table_found
// If the entry is null, the interface method is not in the ImtConflictTable.
cbz r4, .Lconflict_trampoline
// Iterate over the entries of the ImtConflictTable.
ldr r4, [r0, #(2 * __SIZEOF_POINTER__)]!
b .Limt_table_iterate
.Limt_table_found:
// We successfully hit an entry in the table. Load the target method
// and jump to it.
ldr r0, [r0, #__SIZEOF_POINTER__]
ldr pc, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32]
.Lconflict_trampoline:
// Pass interface method to the trampoline.
mov r0, r12
INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
END art_quick_imt_conflict_trampoline
// Save rSELF
mov r11, rSELF
// Save SP , so we can have static CFI info. r10 is saved in ref_and_args.
mov r10, sp
.cfi_def_cfa_register r10
sub sp, sp, #GENERIC_JNI_TRAMPOLINE_RESERVED_AREA
// prepare for artQuickGenericJniTrampoline call
// (Thread*, managed_sp, reserved_area)
// r0 r1 r2 <= C calling convention
// rSELF r10 sp <= where they are
mov r0, rSELF // Thread*
mov r1, r10 // SP for the managed frame.
mov r2, sp // reserved area for arguments and other saved data (up to managed frame)
blx artQuickGenericJniTrampoline // (Thread*, managed_sp, reserved_area)
// The C call will have registered the complete save-frame on success.
// The result of the call is:
// r0: pointer to native code, 0 on error.
// The bottom of the reserved area contains values for arg registers,
// hidden arg register and SP for out args for the call.
// Check for error (class init check or locking for synchronized native method can throw).
cbz r0, .Lexception_in_native
// Save the code pointer
mov lr, r0
// Load parameters from frame into registers r0-r3 (soft-float),
// hidden arg (r4) for @CriticalNative and SP for out args.
pop {r0-r3, r4, ip}
// Apply the new SP for out args, releasing unneeded reserved area.
mov sp, ip
// Softfloat.
// TODO: Change to hardfloat when supported.
blx lr // native call.
// result sign extension is handled in C code
// prepare for artQuickGenericJniEndTrampoline call
// (Thread*, result, result_f)
// r0 r2,r3 stack <= C calling convention
// r11 r0,r1 r0,r1 <= where they are sub sp, sp, #8 // Stack alignment.
.Lexception_in_native:
ldr ip, [rSELF, #THREAD_TOP_QUICK_FRAME_OFFSET]
add ip, ip, #-1 // Remove the GenericJNI tag. ADD/SUB writing directly to SP is UNPREDICTABLE.
mov sp, ip
bl art_deliver_pending_exception
END art_quick_generic_jni_trampoline
ENTRY art_deliver_pending_exception
# This will create a new save-all frame, required by the runtime.
DELIVER_PENDING_EXCEPTION
END art_deliver_pending_exception
.extern artQuickToInterpreterBridge
ENTRY art_quick_to_interpreter_bridge
SETUP_SAVE_REFS_AND_ARGS_FRAME r1
mov r1, rSELF @ pass Thread::Current
mov r2, sp @ pass SP
blx artQuickToInterpreterBridge @ (Method* method, Thread*, SP)
ldr r2, [rSELF, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
// Tear down the callee-save frame. Skip arg registers.
add sp, #(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
.cfi_adjust_cfa_offset -(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
RESTORE_SAVE_REFS_ONLY_FRAME
REFRESH_MARKING_REGISTER
cbnz r2, 1f @ success if no exception is pending
vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
bx lr @ return on success 1:
DELIVER_PENDING_EXCEPTION
END art_quick_to_interpreter_bridge
/* Save a copy in r12 to later compute result */
mov r12, r0
/* Build pointer to start of data to compare and pre-bias */
#if (STRING_COMPRESSION_FEATURE)
lsrs r4, r4, #1
bcc .Lstring_indexof_compressed
#endif
add r0, r0, r2, lsl #1 sub r0, #2
.Lindexof_nomatch:
mov r0, #-1
pop {r4, r10-r11, pc}
.Lmatch_0: sub r0, #6 sub r0, r12
asr r0, r0, #1
pop {r4, r10-r11, pc}
.Lmatch_1: sub r0, #4 sub r0, r12
asr r0, r0, #1
pop {r4, r10-r11, pc}
.Lmatch_2: sub r0, #2 sub r0, r12
asr r0, r0, #1
pop {r4, r10-r11, pc}
.Lmatch_3: sub r0, r12
asr r0, r0, #1
pop {r4, r10-r11, pc}
#if (STRING_COMPRESSION_FEATURE)
.Lstring_indexof_compressed:
add r0, r0, r2 sub r0, #1 sub r2, r3, r2
.Lstring_indexof_compressed_loop:
subs r2, #1
blt .Lindexof_nomatch
ldrb r3, [r0, #1]!
cmp r3, r1
beq .Lstring_indexof_compressed_matched
b .Lstring_indexof_compressed_loop
.Lstring_indexof_compressed_matched: sub r0, r12
pop {r4, r10-r11, pc}
#endif
END art_quick_indexof
/* Assembly routines used to handle ABI differences. */
/* double fmod(double a, double b) */
.extern fmod
ENTRY art_quick_fmod
push {lr}
.cfi_adjust_cfa_offset 4
.cfi_rel_offset lr, 0 sub sp, #4
.cfi_adjust_cfa_offset 4
vmov r0, r1, d0
vmov r2, r3, d1
bl fmod
vmov d0, r0, r1
add sp, #4
.cfi_adjust_cfa_offset -4
pop {pc}
END art_quick_fmod
/* float fmodf(float a, float b) */
.extern fmodf
ENTRY art_quick_fmodf
push {lr}
.cfi_adjust_cfa_offset 4
.cfi_rel_offset lr, 0 sub sp, #4
.cfi_adjust_cfa_offset 4
vmov r0, r1, d0
bl fmodf
vmov s0, r0
add sp, #4
.cfi_adjust_cfa_offset -4
pop {pc}
END art_quick_fmodf
/* int64_t art_d2l(double d) */
.extern art_d2l
ENTRY art_quick_d2l
vmov r0, r1, d0
b art_d2l
END art_quick_d2l
/* int64_t art_f2l(float f) */
.extern art_f2l
ENTRY art_quick_f2l
vmov r0, s0
b art_f2l
END art_quick_f2l
.extern artStringBuilderAppend
ENTRY art_quick_string_builder_append
SETUP_SAVE_REFS_ONLY_FRAME r2 @ save callee saves in case of GC
add r1, sp, #(FRAME_SIZE_SAVE_REFS_ONLY + __SIZEOF_POINTER__) @ pass args
mov r2, rSELF @ pass Thread::Current
bl artStringBuilderAppend @ (uint32_t, const unit32_t*, Thread*)
RESTORE_SAVE_REFS_ONLY_FRAME
REFRESH_MARKING_REGISTER
RETURN_OR_DEOPT_IF_RESULT_IS_NON_NULL_OR_DELIVER
END art_quick_string_builder_append
/* *Createafunction`name`callingtheReadBarrier::Markroutine, *gettingitsargumentandreturningitsresultthroughregister *`reg`,savingandrestoringallcaller-saveregisters. * *IPisclobbered;`reg`mustnotbeIP. * *If`reg`isdifferentfrom`r0`,thegeneratedfunctionfollowsa *non-standardruntimecallingconvention: *-register`reg`(whichmaybedifferentfromR0)isusedtopassthe(sole)argument, *-register`reg`(whichmaybedifferentfromR0)isusedtoreturntheresult, *-allotherregistersarecallee-save(thevaluestheyholdarepreserved).
*/
.macro READ_BARRIER_MARK_REG name, reg
ENTRY \name
// Null check so that we can load the lock word.
SMART_CBZ \reg, .Lret_rb_\name
// Check lock word for mark bit, if marked return. Use IP for scratch since it is blocked.
ldr ip, [\reg, MIRROR_OBJECT_LOCK_WORD_OFFSET]
tst ip, #LOCK_WORD_MARK_BIT_MASK_SHIFTED
beq .Lnot_marked_rb_\name
// Already marked, return right away.
.Lret_rb_\name:
bx lr
.Lnot_marked_rb_\name:
// Test that both the forwarding state bits are 1.
#if (LOCK_WORD_STATE_SHIFT != 30) || (LOCK_WORD_STATE_FORWARDING_ADDRESS != 3)
// To use "CMP ip, #modified-immediate; BHS", we need the lock word state in
// the highest bits and the "forwarding address" state to have all bits set.
#error "Unexpected lock word state shift or forwarding address state value."
#endif
cmp ip, #(LOCK_WORD_STATE_FORWARDING_ADDRESS << LOCK_WORD_STATE_SHIFT)
bhs .Lret_forwarding_address\name
.Lslow_rb_\name:
// Save IP: The kSaveEverything entrypoint art_quick_resolve_string used to
// make a tail call here. Currently, it serves only for stack alignment but
// we may reintroduce kSaveEverything calls here in the future.
push {r0-r4, r9, ip, lr} @ save return address, core caller-save registers and ip
.cfi_adjust_cfa_offset 32
.cfi_rel_offset r0, 0
.cfi_rel_offset r1, 4
.cfi_rel_offset r2, 8
.cfi_rel_offset r3, 12
.cfi_rel_offset r4, 16
.cfi_rel_offset r9, 20
.cfi_rel_offset ip, 24
.cfi_rel_offset lr, 28
pop {r0-r4, r9, ip, lr} @ restore caller-save registers
.cfi_adjust_cfa_offset -32
.cfi_restore r0
.cfi_restore r1
.cfi_restore r2
.cfi_restore r3
.cfi_restore r4
.cfi_restore r9
.cfi_restore ip
.cfi_restore lr
bx lr
.Lret_forwarding_address\name:
// Shift left by the forwarding address shift. This clears out the state bits since they are
// in the top 2 bits of the lock word.
lsl \reg, ip, #LOCK_WORD_STATE_FORWARDING_ADDRESS_SHIFT
bx lr
END \name
.endm
.macro BRBMI_RUNTIME_CALL
// Note: This macro generates exactly 22 bytes of code. The core register
// PUSH and the MOVs are 16-bit instructions, the rest is 32-bit instructions.
.macro BRBMI_CHECK_NULL_AND_MARKED label_suffix
// If reference is null, just return it in the right register.
cmp ip, #0
beq .Lmark_introspection_return\label_suffix
// Use rMR as temp and check the mark bit of the reference.
ldr rMR, [ip, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
tst rMR, #LOCK_WORD_MARK_BIT_MASK_SHIFTED
beq .Lmark_introspection_unmarked\label_suffix
.Lmark_introspection_return\label_suffix:
.endm
.macro BRBMI_UNMARKED_FORWARDING_ADDRESS_CHECK label_suffix
.Lmark_introspection_unmarked\label_suffix:
// Check if the top two bits are one, if this is the case it is a forwarding address.
#if (LOCK_WORD_STATE_SHIFT != 30) || (LOCK_WORD_STATE_FORWARDING_ADDRESS != 3)
// To use "CMP ip, #modified-immediate; BHS", we need the lock word state in
// the highest bits and the "forwarding address" state to have all bits set.
#error "Unexpected lock word state shift or forwarding address state value."
#endif
cmp rMR, #(LOCK_WORD_STATE_FORWARDING_ADDRESS << LOCK_WORD_STATE_SHIFT)
bhs .Lmark_introspection_forwarding_address\label_suffix
.endm
.macro BRBMI_EXTRACT_FORWARDING_ADDRESS label_suffix
.Lmark_introspection_forwarding_address\label_suffix:
// Note: This macro generates exactly 22 bytes of code, the branch is near.
// Shift left by the forwarding address shift. This clears out the state bits since they are
// in the top 2 bits of the lock word.
lsl ip, rMR, #LOCK_WORD_STATE_FORWARDING_ADDRESS_SHIFT
b .Lmark_introspection_return\label_suffix
.endm
.macro BRBMI_LOAD_RETURN_REG_FROM_CODE_wide ldr_offset
// Load the half of the instruction that contains Rt. Adjust for the thumb state in LR.
ldrh rMR, [lr, #(-1 + \ldr_offset + 2)]
.endm
.macro BRBMI_LOAD_RETURN_REG_FROM_CODE_narrow ldr_offset
// Load the 16-bit instruction. Adjust for the thumb state in LR.
ldrh rMR, [lr, #(-1 + \ldr_offset)]
.endm
/* *UseintrospectiontoloadareferencefromthesameaddressastheLDR *instructioningeneratedcodewouldload(unlessloadedbythethunk, *seebelow),callReadBarrier::Mark()withthatreferenceifneeded *andreturnitinthesameregisterastheLDRinstructionwouldload. * *Theentrypointiscalledthroughathunkthatdiffersacrossloadkinds. *ForfieldandarrayloadstheLDRinstructioningeneratedcodefollows *thebranchtothethunk,i.e.theLDRis(ignoringtheheappoisoning) *at[LR,#(-4-1)](encodingT3)or[LR,#(-2-1)](encodingT1)where *the-1isanadjustmentfortheThumbmodebitinLR,andthethunk *knowstheholderandperformsthegraybitcheck,returningtotheLDR *instructioniftheobjectisnotgray,sothisentrypointnolonger *needstoknowanythingabouttheholder.ForGCrootloads,theLDR *instructioningeneratedcodeprecedesthebranchtothethunk,i.e.the *LDRisat[LR,#(-8-1)](encodingT3)or[LR,#(-6-1)](encodingT1) *wherethe-1isagaintheThumbmodebitadjustment,andthethunkdoes *notdothegraybitcheck. * *Forfieldaccessesandarrayloadswithaconstantindexthethunkloads *thereferenceintoIPusingintrospectionandcallsthemainentrypoint *("wide",for32-bitLDR)art_quick_read_barrier_mark_introspectionor *the"narrow"entrypoint(for16-bitLDR).Thelatterisataknown *offset(BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_ENTRYPOINT_OFFSET) *fromthemainentrypointandthethunkadjuststheentrypointpointer. *Withheappoisoningenabled,thepassedreferenceispoisoned. * *Forarrayaccesseswithnon-constantindex,thethunkinsertsthebits *0-5oftheLDRinstructiontotheentrypointaddress,effectively *calculatingaswitchcaselabelbasedontheindexregister(bits0-3) *andaddinganextraoffset(bits4-5holdtheshiftwhichisalways2 *forreferenceloads)todifferentiatefromthemainentrypoint,then *movesthebaseregistertoIPandjumpstotheswitchcase.Therefore *weneedtoalignthemainentrypointto512bytes,accountingfor *a256-byteoffsetfollowedby16arrayentrypointsstartingat *art_quick_read_barrier_mark_introspection_arrays,eachcontaininganLDR *(register)andabranchtothemainentrypoint. * *ForGCrootaccesseswecannotusethemainentrypointbecauseofthe *differentoffsetwheretheLDRinstructioningeneratedcodeislocated. *(Andevenwithheappoisoningenabled,GCrootsarenotpoisoned.) *Tore-usethesameentrypointpointeringeneratedcode,wemakesure *thatthegcrootentrypoint(acopyoftheentrypointwithadifferent *offsetforintrospectionloads)islocatedataknownoffset(0xc0/0xe0 *bytes,orBAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_ENTRYPOINT_OFFSET/ *BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_ENTRYPOINT_OFFSET)fromthe *mainentrypointandtheGCrootthunkadjuststheentrypointpointer, *movestherootregistertoIPandjumpstothecustomizedentrypoint, *art_quick_read_barrier_mark_introspection_gc_roots_{wide,narrow}. *Thethunkalsoperformsallthefast-pathchecks,soweneedjustthe *slowpath. * *IntrinsicCASoperations(VarHandle*CompareAnd{Set,Exchange}*and *UnsafeCASObject)usesimilarcodetotheGCrootswideloadbutusing *MOV(register,T3)insteadoftheLDR(immediate,T3),withdestination *registerinbits8-11ratherthan12-15.Thereforetheyhavetheirown *entrypoint,art_quick_read_barrier_mark_introspection_intrinsic_cas *attheoffsetBAKER_MARK_INTROSPECTION_INTRINSIC_CAS_ENTRYPOINT_OFFSET. *Thisisusedonlyforhighregisters,lowregistersreusetheGCroots *narrowloadentrypointasthelow3bitsofthedestinationregister *forMOV(register)encodingT1matchtheLDR(immediate)encodingT1. * *Thecodestructureis *art_quick_read_barrier_mark_introspection://@0x00 *Upto32bytescodeformainentrypointfast-pathcodeforfields *(andarrayelementswithconstantoffset)withLDRencodingT3; *jumpstotheswitchinthe"narrow"entrypoint. *art_quick_read_barrier_mark_introspection_narrow://@0x20 *Upto48bytescodeforfastpathcodeforfields(andarray *elementswithconstantoffset)withLDRencodingT1,endinginthe *returnswitchinstructionTBBandthetablewithswitchoffsets. *.Lmark_introspection_return_switch_case_r0://@0x50 *Exactly88bytesofcodeforthereturnswitchcases(8bytesper *case,11cases;nocodeforreservedregisters). *.Lmark_introspection_forwarding_address_narrow://@0xa8 *Exactly6bytestoextracttheforwardingaddressandjumptothe *"narrow"entrypointfastpath. *.Lmark_introspection_return_switch_case_bad://@0xae *Exactly2bytes,bkptforunexpectedreturnregister. *.Lmark_introspection_unmarked_narrow://@0xb0 *Exactly16bytesfor"narrow"entrypointslowpath. *art_quick_read_barrier_mark_introspection_gc_roots_wide://@0xc0 *GCrootentrypointcodeforLDRencodingT3(10bytes);loadsand *extractsthereturnregisterandjumpstotheruntimecall. *.Lmark_introspection_forwarding_address_wide://@0xca *Exactly6bytestoextracttheforwardingaddressandjumptothe *"wide"entrypointfastpath. *.Lmark_introspection_unmarked_wide://@0xd0 *Exactly16bytesfor"wide"entrypointslowpath. *art_quick_read_barrier_mark_introspection_gc_roots_narrow://@0xe0 *GCrootentrypointcodeforLDRencodingT1(8bytes);loadsand *extractsthereturnregisterandfallsthroughtotheruntimecall. *.Lmark_introspection_runtime_call://@0xe8 *Exactly24bytesfortheruntimecalltoMarkReg()andjumptothe *returnswitch. *art_quick_read_barrier_mark_introspection_arrays://@0x100 *Exactly128bytesforarrayloadswitchcases(16x2instructions). *art_quick_read_barrier_mark_introspection_intrinsic_cas://@0x180 *IntrinsicCASentrypointforMOV(register)encodingT3(6bytes). *Loadsthereturnregisterandjumpstotheruntimecall.
*/
#if defined(USE_READ_BARRIER) && defined(USE_BAKER_READ_BARRIER)
ENTRY_ALIGNED art_quick_read_barrier_mark_introspection, 512
// At this point, IP contains the reference, rMR is clobbered by the thunk
// and can be freely used as it will be set back to 1 before returning.
// For heap poisoning, the reference is poisoned, so unpoison it first.
UNPOISON_HEAP_REF ip
// Check for null or marked, lock word is loaded into rMR.
BRBMI_CHECK_NULL_AND_MARKED _wide
// Load and extract the return register from the instruction.
BRBMI_LOAD_AND_EXTRACT_RETURN_REG BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET, _wide
b .Lmark_introspection_return_switch
.balign 32
.thumb_func
.type art_quick_read_barrier_mark_introspection_narrow, #function
.hidden art_quick_read_barrier_mark_introspection_narrow
.global art_quick_read_barrier_mark_introspection_narrow
art_quick_read_barrier_mark_introspection_narrow:
// At this point, IP contains the reference, rMR is clobbered by the thunk
// and can be freely used as it will be set back to 1 before returning.
// For heap poisoning, the reference is poisoned, so unpoison it first.
UNPOISON_HEAP_REF ip
// Check for null or marked, lock word is loaded into rMR.
BRBMI_CHECK_NULL_AND_MARKED _narrow
// Load and extract the return register from the instruction.
BRBMI_LOAD_AND_EXTRACT_RETURN_REG BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET, _narrow
.Lmark_introspection_return_switch:
tbb [pc, rMR] // Jump to the switch case.
.Lmark_introspection_return_table:
BRBMI_FOR_REGISTERS BRBMI_RETURN_SWITCH_CASE_OFFSET, BRBMI_BAD_RETURN_SWITCH_CASE_OFFSET
BRBMI_FOR_REGISTERS BRBMI_RETURN_SWITCH_CASE, /* no code */
// 8 bytes for the loading and extracting of the return register.
BRBMI_GC_ROOT BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET, _wide
// 2 bytes for near branch to the runtime call.
b .Lmark_introspection_runtime_call
BRBMI_EXTRACT_FORWARDING_ADDRESS _wide // Not even 4-byte aligned.
// 8 bytes for the loading and extracting of the return register.
BRBMI_GC_ROOT BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET, _narrow
// And the runtime call and branch to the switch taking exactly 24 bytes
// (22 bytes for BRBMI_RUNTIME_CALL and 2 bytes for the near branch)
// shall take the rest of the 32-byte section (within a cache line).
.Lmark_introspection_runtime_call:
BRBMI_RUNTIME_CALL
b .Lmark_introspection_return_switch
.balign 8
.thumb_func
.type art_quick_read_barrier_mark_introspection_intrinsic_cas, #function
.hidden art_quick_read_barrier_mark_introspection_intrinsic_cas
.global art_quick_read_barrier_mark_introspection_intrinsic_cas
art_quick_read_barrier_mark_introspection_intrinsic_cas:
// Load the byte of the MOV instruction that contains Rd. Adjust for the thumb state in LR.
// The MOV (register, T3) is |11101010010|S|1111|(0)000|Rd|0000|Rm|, so the byte we read
// here, i.e. |(0)000|Rd|, contains only the register number, the top 4 bits are 0.
ldrb rMR, [lr, #(-1 + BAKER_MARK_INTROSPECTION_INTRINSIC_CAS_MOV_OFFSET + 3)]
b .Lmark_introspection_runtime_call
END art_quick_read_barrier_mark_introspection
#else // defined(USE_READ_BARRIER) && defined(USE_BAKER_READ_BARRIER)
ENTRY art_quick_read_barrier_mark_introspection
bkpt // Unreachable.
END art_quick_read_barrier_mark_introspection
#endif // defined(USE_READ_BARRIER) && defined(USE_BAKER_READ_BARRIER)
.extern artInvokeCustom
ENTRY art_quick_invoke_custom
SETUP_SAVE_REFS_AND_ARGS_FRAME r1
@ r0 := call_site_idx
mov r1, rSELF @ r1 := Thread::Current
mov r2, sp @ r2 := SP
bl artInvokeCustom @ artInvokeCustom(call_site_idx, Thread*, SP)
str r1, [sp, #72] @ Save r1 to context (r0:r1 = result)
RESTORE_SAVE_REFS_AND_ARGS_FRAME
REFRESH_MARKING_REGISTER
vmov d0, r0, r1 @ Put result r0:r1 into floating point return register.
RETURN_OR_DELIVER_PENDING_EXCEPTION_REG r2
END art_quick_invoke_custom
// r0 contains the class, r4 contains the inline cache. We can use ip as temporary.
ENTRY art_quick_update_inline_cache
#if (INLINE_CACHE_SIZE != 5)
#error "INLINE_CACHE_SIZE not as expected."
#endif
#if defined(USE_READ_BARRIER) && defined(USE_BAKER_READ_BARRIER)
// Don't update the cache if we are marking.
cmp rMR, #0
bne .Ldone
#endif
.Lentry1:
ldr ip, [r4, #INLINE_CACHE_CLASSES_OFFSET]
cmp ip, r0
beq .Ldone
cmp ip, #0
bne .Lentry2
ldrex ip, [r4, #INLINE_CACHE_CLASSES_OFFSET]
cmp ip, #0
bne .Lentry1
strex ip, r0, [r4, #INLINE_CACHE_CLASSES_OFFSET]
cmp ip, #0
bne .Ldone
b .Lentry1
.Lentry2:
ldr ip, [r4, #INLINE_CACHE_CLASSES_OFFSET+4]
cmp ip, r0
beq .Ldone
cmp ip, #0
bne .Lentry3
ldrex ip, [r4, #INLINE_CACHE_CLASSES_OFFSET+4]
cmp ip, #0
bne .Lentry2
strex ip, r0, [r4, #INLINE_CACHE_CLASSES_OFFSET+4]
cmp ip, #0
bne .Ldone
b .Lentry2
.Lentry3:
ldr ip, [r4, #INLINE_CACHE_CLASSES_OFFSET+8]
cmp ip, r0
beq .Ldone
cmp ip, #0
bne .Lentry4
ldrex ip, [r4, #INLINE_CACHE_CLASSES_OFFSET+8]
cmp ip, #0
bne .Lentry3
strex ip, r0, [r4, #INLINE_CACHE_CLASSES_OFFSET+8]
cmp ip, #0
bne .Ldone
b .Lentry3
.Lentry4:
ldr ip, [r4, #INLINE_CACHE_CLASSES_OFFSET+12]
cmp ip, r0
beq .Ldone
cmp ip, #0
bne .Lentry5
ldrex ip, [r4, #INLINE_CACHE_CLASSES_OFFSET+12]
cmp ip, #0
bne .Lentry4
strex ip, r0, [r4, #INLINE_CACHE_CLASSES_OFFSET+12]
cmp ip, #0
bne .Ldone
b .Lentry4
.Lentry5:
// Unconditionally store, the inline cache is megamorphic.
str r0, [r4, #INLINE_CACHE_CLASSES_OFFSET+16]
.Ldone:
blx lr
END art_quick_update_inline_cache
// On entry, method is at the bottom of the stack.
ENTRY art_quick_compile_optimized
SETUP_SAVE_EVERYTHING_FRAME r0
ldr r0, [sp, FRAME_SIZE_SAVE_EVERYTHING] @ pass ArtMethod
mov r1, rSELF @ pass Thread::Current
bl artCompileOptimized @ (ArtMethod*, Thread*)
RESTORE_SAVE_EVERYTHING_FRAME
// We don't need to restore the marking register here, as
// artCompileOptimized doesn't allow thread suspension.
blx lr
END art_quick_compile_optimized
// On entry, method is at the bottom of the stack.
ENTRY art_quick_compile_baseline
SETUP_SAVE_EVERYTHING_FRAME r0
ldr r0, [sp, FRAME_SIZE_SAVE_EVERYTHING] @ pass ArtMethod
mov r1, rSELF @ pass Thread::Current
bl artCompileBaseline @ (ArtMethod*, Thread*)
RESTORE_SAVE_EVERYTHING_FRAME
// We don't need to restore the marking register here, as
// artCompileBaseline doesn't allow thread suspension.
blx lr
END art_quick_compile_baseline
// On entry, method is at the bottom of the stack.
ENTRY art_quick_method_entry_hook
SETUP_SAVE_EVERYTHING_FRAME r0
ldr r0, [sp, FRAME_SIZE_SAVE_EVERYTHING] @ pass ArtMethod
mov r1, rSELF @ pass Thread::Current
mov r2, sp @ pass SP
bl artMethodEntryHook @ (ArtMethod*, Thread*, SP)
CFI_REMEMBER_STATE
cbnz r0, .Lentryhook_deopt
RESTORE_SAVE_EVERYTHING_FRAME
REFRESH_MARKING_REGISTER
blx lr
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.