Add a missing reader barrier in entrypoint stub
Also refactored some comments.
Change-Id: I5c50f487bf9d71f1be5f6c8814bf039993fc1267
diff --git a/runtime/arch/x86/quick_entrypoints_x86.S b/runtime/arch/x86/quick_entrypoints_x86.S
index 1da5a2f..9b2d59d 100644
--- a/runtime/arch/x86/quick_entrypoints_x86.S
+++ b/runtime/arch/x86/quick_entrypoints_x86.S
@@ -1200,9 +1200,9 @@
READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, false
cmpl %eax, %ebx
POP eax // restore eax from the push in the beginning of READ_BARRIER macro
+ // This asymmetric push/pop saves a push of eax and maintains stack alignment.
#elif defined(USE_HEAP_POISONING)
PUSH eax // save eax
- // Cannot call READ_BARRIER macro here, because the above push messes up stack alignment.
movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
UNPOISON_HEAP_REF eax
cmpl %eax, %ebx
@@ -1225,15 +1225,22 @@
PUSH eax // save arguments
PUSH ecx
PUSH edx
+#if defined(USE_READ_BARRIER)
+ subl LITERAL(4), %esp // alignment padding
+ CFI_ADJUST_CFA_OFFSET(4)
+ READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, true
+ subl LITERAL(4), %esp // alignment padding
+ CFI_ADJUST_CFA_OFFSET(4)
+ PUSH eax // pass arg2 - type of the value to be stored
+#elif defined(USE_HEAP_POISONING)
subl LITERAL(8), %esp // alignment padding
CFI_ADJUST_CFA_OFFSET(8)
-#ifdef USE_HEAP_POISONING
- // This load does not need read barrier, since edx is unchanged and there's no GC safe point
- // from last read of MIRROR_OBJECT_CLASS_OFFSET(%edx).
- movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax // pass arg2 - type of the value to be stored
+ movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
UNPOISON_HEAP_REF eax
- PUSH eax
+ PUSH eax // pass arg2 - type of the value to be stored
#else
+ subl LITERAL(8), %esp // alignment padding
+ CFI_ADJUST_CFA_OFFSET(8)
pushl MIRROR_OBJECT_CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
CFI_ADJUST_CFA_OFFSET(4)
#endif