Author: njn
Date: 2007-10-11 08:40:10 +0100 (Thu, 11 Oct 2007)
New Revision: 6981

Log:
Changed alloc_fns from an OSet to an XArray.  Way faster because the main
operation is iteration over it, for which OSets are quite slow.  Speeds up
'heap' by 1.4x, and 'many-xpts' by almost 3x.

Modified:
   branches/MASSIF2/massif/ms_main.c
   branches/MASSIF2/massif/tests/culling1.stderr.exp
   branches/MASSIF2/massif/tests/culling2.stderr.exp
   branches/MASSIF2/massif/tests/deep-B.stderr.exp
   branches/MASSIF2/massif/tests/deep-C.stderr.exp
   branches/MASSIF2/massif/tests/realloc.stderr.exp


Modified: branches/MASSIF2/massif/ms_main.c
===================================================================
--- branches/MASSIF2/massif/ms_main.c   2007-10-11 07:28:16 UTC (rev 6980)
+++ branches/MASSIF2/massif/ms_main.c   2007-10-11 07:40:10 UTC (rev 6981)
@@ -85,7 +85,7 @@
 // 142197  nor     massif tool ignores --massif:alloc-fn parameters in .valg...
 //   - fixed in trunk
 // 142491  nor     Maximise use of alloc_fns array
-//   - addressed, it's now an OSet and thus unlimited in size
+//   - addressed, it's now an XArray and thus unlimited in size
 // 144453   (get_XCon): Assertion 'xpt->max_children != 0' failed.
 //   - relevant code now gone
 //
@@ -156,6 +156,12 @@
 //   tinycc     0.44s  ma:10.7s (24.4x, -----)
 //   many-xpts  0.11s  ma:32.8s (298.0x, -----)
 //
+// Changed alloc_fns from an OSet to an XArray:
+//   bz2        1.20s  ma: 5.4s ( 4.5x, -----)
+//   heap       0.24s  ma:19.4s (80.6x, -----)
+//   tinycc     0.49s  ma: 7.8s (16.0x, -----)
+//   many-xpts  0.12s  ma:11.2s (93.3x, -----)
+//
 //---------------------------------------------------------------------------
 
 #include "pub_tool_basics.h"
@@ -171,7 +177,6 @@
 #include "pub_tool_machine.h"
 #include "pub_tool_mallocfree.h"
 #include "pub_tool_options.h"
-#include "pub_tool_oset.h"
 #include "pub_tool_replacemalloc.h"
 #include "pub_tool_stacktrace.h"
 #include "pub_tool_tooliface.h"
@@ -288,44 +293,51 @@
 //--- Alloc fns                                            ---//
 //------------------------------------------------------------//
 
-OSet* alloc_fns;
+static XArray* alloc_fns;
 
 static void init_alloc_fns(void)
 {
-   // Create the OSet, and add the default elements.
-   alloc_fns = VG_(OSetWord_Create)(VG_(malloc), VG_(free));
-   #define DO(x)  VG_(OSetWord_Insert)(alloc_fns, (Word)x);
-   DO("malloc"           );
-   DO("calloc"           );
-   DO("realloc"          );
-   DO("memalign"         );
-   DO("__builtin_new"    );
-   DO("__builtin_vec_new");
-   // The following C++ allocators are overloadable.  It's conceivable that
-   // someone would want to not consider them as allocators, in order to see
-   // what's happening beneath them.  But if they're not in alloc_fns, then
-   // when they're not overloaded they won't be seen as alloc-fns, which
-   // will screw things up.  So we always consider them to be, and tough
-   // luck for anyone who wants to see inside them.
-   DO("operator new(unsigned)");
-   DO("operator new[](unsigned)");
-   DO("operator new(unsigned long)");
-   DO("operator new[](unsigned long)");
-   DO("operator new(unsigned, std::nothrow_t const&)");
-   DO("operator new[](unsigned, std::nothrow_t const&)");
-   DO("operator new(unsigned long, std::nothrow_t const&)");
+   // Create the list, and add the default elements.
+   alloc_fns = VG_(newXA)(VG_(malloc), VG_(free), sizeof(Char*));
+   #define DO(x)  { Char* s = x; VG_(addToXA)(alloc_fns, &s); }
+
+   // Ordered according to (presumed) frequency.
+   // Nb: The C++ "operator new*" ones are overloadable.  It's conceivable
+   // that someone would want to not consider them as allocators, in order
+   // to see what's happening beneath them.  But if they're not in
+   // alloc_fns, then when they're not overloaded they won't be seen as
+   // alloc-fns, which will screw things up.  So we always consider them to
+   // be, and tough luck for anyone who wants to see inside them.
+   // XXX: not actually necessarily true with the new (ie. old
+   // Massif1-style) alloc-fn approach.
+   DO("malloc"                                              );
+   DO("__builtin_new"                                       );
+   DO("operator new(unsigned)"                              );
+   DO("operator new(unsigned long)"                         );
+   DO("__builtin_vec_new"                                   );
+   DO("operator new[](unsigned)"                            );
+   DO("operator new[](unsigned long)"                       );
+   DO("calloc"                                              );
+   DO("realloc"                                             );
+   DO("memalign"                                            );
+   DO("operator new(unsigned, std::nothrow_t const&)"       );
+   DO("operator new[](unsigned, std::nothrow_t const&)"     );
+   DO("operator new(unsigned long, std::nothrow_t const&)"  );
    DO("operator new[](unsigned long, std::nothrow_t const&)");
 }
 
 static Bool is_alloc_fn(Char* fnname)
 {
-   Word alloc_fn_word;
-
+   Char** alloc_fn_ptr;
+   Int i;
+ 
    // Nb: It's a linear search through the list, because we're comparing
    // strings rather than pointers to strings.
-   VG_(OSetWord_ResetIter)(alloc_fns);
-   while ( VG_(OSetWord_Next)(alloc_fns, &alloc_fn_word) ) {
-      if (VG_STREQ(fnname, (Char*)alloc_fn_word))
+   // Nb: This gets called a lot.  It was an OSet, but they're quite slow to
+   // iterate through so it wasn't a good choice.
+   for (i = 0; i < VG_(sizeXA)(alloc_fns); i++) {
+      alloc_fn_ptr = VG_(indexXA)(alloc_fns, i);
+      if (VG_STREQ(fnname, *alloc_fn_ptr))
          return True;
    }
    return False;
@@ -381,7 +393,8 @@
    else if (VG_CLO_STREQ(arg, "--time-unit=B"))  clo_time_unit = TimeB;
 
    else if (VG_CLO_STREQN(11, arg, "--alloc-fn=")) {
-      VG_(OSetWord_Insert)(alloc_fns, (Word) & arg[11]);
+      Char* alloc_fn = &arg[11];
+      VG_(addToXA)(alloc_fns, &alloc_fn);
    }
 
    else
@@ -1897,7 +1910,6 @@
 static void ms_post_clo_init(void)
 {
    Int i;
-   Word alloc_fn_word;
 
    // Check options.
    if (clo_heap_admin < 0 || clo_heap_admin > 1024) {
@@ -1931,10 +1943,9 @@
    if (VG_(clo_verbosity) > 1) {
       i = 1;
       VERB(1, "alloc-fns:");
-      VG_(OSetWord_ResetIter)(alloc_fns);
-      while ( VG_(OSetWord_Next)(alloc_fns, &alloc_fn_word) ) {
-         VERB(1, "  %d: %s", i, (Char*)alloc_fn_word);
-         i++;
+      for (i = 0; i < VG_(sizeXA)(alloc_fns); i++) {
+         Char** alloc_fn_ptr = VG_(indexXA)(alloc_fns, i);
+         VERB(1, "  %d: %s", i, *alloc_fn_ptr);
       }
    }
 

Modified: branches/MASSIF2/massif/tests/culling1.stderr.exp
===================================================================
--- branches/MASSIF2/massif/tests/culling1.stderr.exp   2007-10-11 07:28:16 UTC 
(rev 6980)
+++ branches/MASSIF2/massif/tests/culling1.stderr.exp   2007-10-11 07:40:10 UTC 
(rev 6981)
@@ -1,18 +1,18 @@
 Massif: alloc-fns:
-Massif:   1: calloc
-Massif:   2: realloc
-Massif:   3: memalign
-Massif:   4: __builtin_new
-Massif:   5: __builtin_vec_new
-Massif:   6: operator new(unsigned)
-Massif:   7: operator new[](unsigned)
-Massif:   8: operator new(unsigned long)
-Massif:   9: operator new[](unsigned long)
-Massif:   10: malloc
-Massif:   11: operator new(unsigned, std::nothrow_t const&)
-Massif:   12: operator new[](unsigned, std::nothrow_t const&)
-Massif:   13: operator new(unsigned long, std::nothrow_t const&)
-Massif:   14: operator new[](unsigned long, std::nothrow_t const&)
+Massif:   0: malloc
+Massif:   1: __builtin_new
+Massif:   2: operator new(unsigned)
+Massif:   3: operator new(unsigned long)
+Massif:   4: __builtin_vec_new
+Massif:   5: operator new[](unsigned)
+Massif:   6: operator new[](unsigned long)
+Massif:   7: calloc
+Massif:   8: realloc
+Massif:   9: memalign
+Massif:   10: operator new(unsigned, std::nothrow_t const&)
+Massif:   11: operator new[](unsigned, std::nothrow_t const&)
+Massif:   12: operator new(unsigned long, std::nothrow_t const&)
+Massif:   13: operator new[](unsigned long, std::nothrow_t const&)
 Massif: startup S.  0 (t:0, hp:0, ad:0, st:0)
 Massif:   alloc S.  1 (t:18, hp:10, ad:8, st:0)
 Massif:   alloc S.  2 (t:36, hp:20, ad:16, st:0)

Modified: branches/MASSIF2/massif/tests/culling2.stderr.exp
===================================================================
--- branches/MASSIF2/massif/tests/culling2.stderr.exp   2007-10-11 07:28:16 UTC 
(rev 6980)
+++ branches/MASSIF2/massif/tests/culling2.stderr.exp   2007-10-11 07:40:10 UTC 
(rev 6981)
@@ -1,18 +1,18 @@
 Massif: alloc-fns:
-Massif:   1: calloc
-Massif:   2: realloc
-Massif:   3: memalign
-Massif:   4: __builtin_new
-Massif:   5: __builtin_vec_new
-Massif:   6: operator new(unsigned)
-Massif:   7: operator new[](unsigned)
-Massif:   8: operator new(unsigned long)
-Massif:   9: operator new[](unsigned long)
-Massif:   10: malloc
-Massif:   11: operator new(unsigned, std::nothrow_t const&)
-Massif:   12: operator new[](unsigned, std::nothrow_t const&)
-Massif:   13: operator new(unsigned long, std::nothrow_t const&)
-Massif:   14: operator new[](unsigned long, std::nothrow_t const&)
+Massif:   0: malloc
+Massif:   1: __builtin_new
+Massif:   2: operator new(unsigned)
+Massif:   3: operator new(unsigned long)
+Massif:   4: __builtin_vec_new
+Massif:   5: operator new[](unsigned)
+Massif:   6: operator new[](unsigned long)
+Massif:   7: calloc
+Massif:   8: realloc
+Massif:   9: memalign
+Massif:   10: operator new(unsigned, std::nothrow_t const&)
+Massif:   11: operator new[](unsigned, std::nothrow_t const&)
+Massif:   12: operator new(unsigned long, std::nothrow_t const&)
+Massif:   13: operator new[](unsigned long, std::nothrow_t const&)
 Massif: startup S.  0 (t:0, hp:0, ad:0, st:0)
 Massif:   alloc S.  1 (t:8, hp:0, ad:8, st:0)
 Massif:   alloc S.  2 (t:17, hp:1, ad:16, st:0)

Modified: branches/MASSIF2/massif/tests/deep-B.stderr.exp
===================================================================
--- branches/MASSIF2/massif/tests/deep-B.stderr.exp     2007-10-11 07:28:16 UTC 
(rev 6980)
+++ branches/MASSIF2/massif/tests/deep-B.stderr.exp     2007-10-11 07:40:10 UTC 
(rev 6981)
@@ -1,19 +1,19 @@
 Massif: alloc-fns:
-Massif:   1: a6
-Massif:   2: calloc
-Massif:   3: realloc
-Massif:   4: memalign
-Massif:   5: __builtin_new
-Massif:   6: __builtin_vec_new
-Massif:   7: operator new(unsigned)
-Massif:   8: operator new[](unsigned)
-Massif:   9: operator new(unsigned long)
-Massif:   10: operator new[](unsigned long)
-Massif:   11: malloc
-Massif:   12: operator new(unsigned, std::nothrow_t const&)
-Massif:   13: operator new[](unsigned, std::nothrow_t const&)
-Massif:   14: operator new(unsigned long, std::nothrow_t const&)
-Massif:   15: operator new[](unsigned long, std::nothrow_t const&)
+Massif:   0: malloc
+Massif:   1: __builtin_new
+Massif:   2: operator new(unsigned)
+Massif:   3: operator new(unsigned long)
+Massif:   4: __builtin_vec_new
+Massif:   5: operator new[](unsigned)
+Massif:   6: operator new[](unsigned long)
+Massif:   7: calloc
+Massif:   8: realloc
+Massif:   9: memalign
+Massif:   10: operator new(unsigned, std::nothrow_t const&)
+Massif:   11: operator new[](unsigned, std::nothrow_t const&)
+Massif:   12: operator new(unsigned long, std::nothrow_t const&)
+Massif:   13: operator new[](unsigned long, std::nothrow_t const&)
+Massif:   14: a6
 Massif: startup S.  0 (t:0, hp:0, ad:0, st:0)
 Massif:   alloc S.  1 (t:108, hp:100, ad:8, st:0)
 Massif:   alloc S.  2 (t:216, hp:200, ad:16, st:0)

Modified: branches/MASSIF2/massif/tests/deep-C.stderr.exp
===================================================================
--- branches/MASSIF2/massif/tests/deep-C.stderr.exp     2007-10-11 07:28:16 UTC 
(rev 6980)
+++ branches/MASSIF2/massif/tests/deep-C.stderr.exp     2007-10-11 07:40:10 UTC 
(rev 6981)
@@ -1,19 +1,19 @@
 Massif: alloc-fns:
-Massif:   1: a3
-Massif:   2: calloc
-Massif:   3: realloc
-Massif:   4: memalign
-Massif:   5: __builtin_new
-Massif:   6: __builtin_vec_new
-Massif:   7: operator new(unsigned)
-Massif:   8: operator new[](unsigned)
-Massif:   9: operator new(unsigned long)
-Massif:   10: operator new[](unsigned long)
-Massif:   11: malloc
-Massif:   12: operator new(unsigned, std::nothrow_t const&)
-Massif:   13: operator new[](unsigned, std::nothrow_t const&)
-Massif:   14: operator new(unsigned long, std::nothrow_t const&)
-Massif:   15: operator new[](unsigned long, std::nothrow_t const&)
+Massif:   0: malloc
+Massif:   1: __builtin_new
+Massif:   2: operator new(unsigned)
+Massif:   3: operator new(unsigned long)
+Massif:   4: __builtin_vec_new
+Massif:   5: operator new[](unsigned)
+Massif:   6: operator new[](unsigned long)
+Massif:   7: calloc
+Massif:   8: realloc
+Massif:   9: memalign
+Massif:   10: operator new(unsigned, std::nothrow_t const&)
+Massif:   11: operator new[](unsigned, std::nothrow_t const&)
+Massif:   12: operator new(unsigned long, std::nothrow_t const&)
+Massif:   13: operator new[](unsigned long, std::nothrow_t const&)
+Massif:   14: a3
 Massif: startup S.  0 (t:0, hp:0, ad:0, st:0)
 Massif:   alloc S.  1 (t:108, hp:100, ad:8, st:0)
 Massif:   alloc S.  2 (t:216, hp:200, ad:16, st:0)

Modified: branches/MASSIF2/massif/tests/realloc.stderr.exp
===================================================================
--- branches/MASSIF2/massif/tests/realloc.stderr.exp    2007-10-11 07:28:16 UTC 
(rev 6980)
+++ branches/MASSIF2/massif/tests/realloc.stderr.exp    2007-10-11 07:40:10 UTC 
(rev 6981)
@@ -1,18 +1,18 @@
 Massif: alloc-fns:
-Massif:   1: calloc
-Massif:   2: realloc
-Massif:   3: memalign
-Massif:   4: __builtin_new
-Massif:   5: __builtin_vec_new
-Massif:   6: operator new(unsigned)
-Massif:   7: operator new[](unsigned)
-Massif:   8: operator new(unsigned long)
-Massif:   9: operator new[](unsigned long)
-Massif:   10: malloc
-Massif:   11: operator new(unsigned, std::nothrow_t const&)
-Massif:   12: operator new[](unsigned, std::nothrow_t const&)
-Massif:   13: operator new(unsigned long, std::nothrow_t const&)
-Massif:   14: operator new[](unsigned long, std::nothrow_t const&)
+Massif:   0: malloc
+Massif:   1: __builtin_new
+Massif:   2: operator new(unsigned)
+Massif:   3: operator new(unsigned long)
+Massif:   4: __builtin_vec_new
+Massif:   5: operator new[](unsigned)
+Massif:   6: operator new[](unsigned long)
+Massif:   7: calloc
+Massif:   8: realloc
+Massif:   9: memalign
+Massif:   10: operator new(unsigned, std::nothrow_t const&)
+Massif:   11: operator new[](unsigned, std::nothrow_t const&)
+Massif:   12: operator new(unsigned long, std::nothrow_t const&)
+Massif:   13: operator new[](unsigned long, std::nothrow_t const&)
 Massif: startup S.  0 (t:0, hp:0, ad:0, st:0)
 Massif:   alloc S.  1 (t:100, hp:100, ad:0, st:0)
 Massif: realloc S.  2 (t:100, hp:100, ad:0, st:0)


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Reply via email to