[PATCH] Optimize hooks for weakly consistent memory architectures #461

alk opened this Issue Aug 23, 2015 · 1 comment


None yet
1 participant

alk commented Aug 23, 2015

Originally reported on Google Code with ID 458

The empty list tests for newer hook API does not need an acquire barrier
since InvokeNewHookSlow will call HookList::Traverse which in its turn
will issue the needed acquire barrier.
The same case applies to old hook system where there is no subsequent
load to require an acquire barrier.
This patch optimize both cases by using a NoBarrier_Load. On Intel, which is a strong
consistent memory architecture, both call will create the same 'mov' instruction. However,
on PowerPC this avoid two unnecessary 'lwsync' in each memory allocation function.

--- a/src/malloc_hook-inl.h
+++ b/src/malloc_hook-inl.h
@@ -66,7 +66,7 @@ class AtomicPtr {
     // This prevents MSVC 2005, at least, from complaining (it has to
     // do with __wp64; AtomicWord is __wp64, but Atomic32/64 aren't).
     return reinterpret_cast<PtrT>(static_cast<AtomicWord>(
-      base::subtle::Acquire_Load(&data_)));
+      base::subtle::NoBarrier_Load(&data_)));

   // Sets the contained value to new_val and returns the old value,
@@ -124,7 +124,7 @@ struct PERFTOOLS_DLL_DECL HookList {

   // Fast inline implementation for fast path of Invoke*Hook.
   bool empty() const {
-    return base::subtle::Acquire_Load(&priv_end) == 0;
+    return base::subtle::NoBarrier_Load(&priv_end) == 0;

   // This internal data is not private so that the class is an aggregate and can

Reported by zatrazz on 2012-07-25 04:38:45

@alk alk self-assigned this Aug 23, 2015


alk commented Aug 23, 2015

Patch applied and committed to the main trunk.

r157 | chappedm@gmail.com | 2012-09-17 21:27:34 -0400 (Mon, 17 Sep 2012) | 1 line

issue-458: Optimizes malloc hooks for weakly consistent memory architectures

Reported by chappedm on 2012-09-18 01:29:40

  • Status changed: Fixed

@alk alk closed this Aug 23, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment