[PATCH] Remove hipe constants pool

pguyot <>
Sat Jan 29 11:00:27 CET 2011


From: Paul Guyot <>

Hipe constants used to be allocated within a single, fixed-size pool for
interaction with the garbage collector. However, the garbage collector
no longer depends on constants being allocated within a single pool, and
the fixed size of the pool both meant unnecessary allocations on most
deployments and crashes on deployments requiring more constants.

The code was simplified to directly invoke erts_alloc.
Debugging and undocumented function hipe_bifs:show_literals/0 was
removed (it returned true and output text to the console), and
debugging and undocumented function hipe_bifs:constants_size/0 was
rewritten with a global to count the size of allocated constants.
---
 erts/emulator/beam/erl_nmgc.c    |    1 -
 erts/emulator/hipe/hipe_bif0.c   |   50 +++++--------------------------------
 erts/emulator/hipe/hipe_bif0.h   |    4 ---
 erts/emulator/hipe/hipe_bif2.c   |   13 ----------
 erts/emulator/hipe/hipe_bif2.tab |    1 -
 erts/emulator/hipe/hipe_gc.c     |    1 -
 6 files changed, 7 insertions(+), 63 deletions(-)

diff --git a/erts/emulator/beam/erl_nmgc.c b/erts/emulator/beam/erl_nmgc.c
index 626d4e2..60424ba 100644
--- a/erts/emulator/beam/erl_nmgc.c
+++ b/erts/emulator/beam/erl_nmgc.c
@@ -26,7 +26,6 @@
 #include "erl_nmgc.h"
 #include "erl_debug.h"
 #if HIPE
-#include "hipe_bif0.h" /* for hipe_constants_{start,next} */
 #include "hipe_stack.h"
 #endif
 
diff --git a/erts/emulator/hipe/hipe_bif0.c b/erts/emulator/hipe/hipe_bif0.c
index 2a877d8..4205b05 100644
--- a/erts/emulator/hipe/hipe_bif0.c
+++ b/erts/emulator/hipe/hipe_bif0.c
@@ -450,52 +450,13 @@ BIF_RETTYPE hipe_bifs_alloc_data_2(BIF_ALIST_2)
 }
 
 /*
- * Memory area for constant Erlang terms.
- *
- * These constants must not be forwarded by the gc.
- * Therefore, the gc needs to be able to distinguish between
- * collectible objects and constants. Unfortunately, an Erlang
- * process' collectible objects are scattered around in two
- * heaps and a list of message buffers, so testing "is X a
- * collectible object?" can be expensive.
- *
- * Instead, constants are placed in a single contiguous area,
- * which allows for an inexpensive "is X a constant?" test.
- *
- * XXX: Allow this area to be grown.
+ * Statistics on hipe constants: size of HiPE constants, in words.
  */
-
-/* not static, needed by garbage collector */
-Eterm *hipe_constants_start = NULL;
-Eterm *hipe_constants_next = NULL;
-static unsigned constants_avail_words = 0;
-#define CONSTANTS_BYTES	(1536*1024*sizeof(Eterm))  /* 1.5 M words */
-
-static Eterm *constants_alloc(unsigned nwords)
-{
-    Eterm *next;
-
-    /* initialise at the first call */
-    if ((next = hipe_constants_next) == NULL) {
-	next = (Eterm*)erts_alloc(ERTS_ALC_T_HIPE, CONSTANTS_BYTES);
-	hipe_constants_start = next;
-	hipe_constants_next = next;
-	constants_avail_words = CONSTANTS_BYTES / sizeof(Eterm);
-    }
-    if (nwords > constants_avail_words) {
-	fprintf(stderr, "Native code constants pool depleted!\r\n");
-	/* Must terminate immediately. erl_exit() seems to
-	   continue running some code which then SIGSEGVs. */
-	exit(1);
-    }
-    constants_avail_words -= nwords;
-    hipe_constants_next = next + nwords;
-    return next;
-}
+unsigned int hipe_constants_size = 0;
 
 BIF_RETTYPE hipe_bifs_constants_size_0(BIF_ALIST_0)
 {
-    BIF_RET(make_small(hipe_constants_next - hipe_constants_start));
+    BIF_RET(make_small(hipe_constants_size));
 }
 
 /*
@@ -526,14 +487,17 @@ static void *const_term_alloc(void *tmpl)
 {
     Eterm obj;
     Uint size;
+    Uint alloc_size;
     Eterm *hp;
     struct const_term *p;
 
     obj = (Eterm)tmpl;
     ASSERT(is_not_immed(obj));
     size = size_object(obj);
+    alloc_size = size + (offsetof(struct const_term, mem)/sizeof(Eterm));
+    hipe_constants_size += alloc_size;
 
-    p = (struct const_term*)constants_alloc(size + (offsetof(struct const_term, mem)/sizeof(Eterm)));
+    p = (struct const_term*)erts_alloc(ERTS_ALC_T_HIPE, alloc_size * sizeof(Eterm));
 
     /* I have absolutely no idea if having a private 'off_heap'
        works or not. _Some_ off_heap object is required for
diff --git a/erts/emulator/hipe/hipe_bif0.h b/erts/emulator/hipe/hipe_bif0.h
index ed27d56..a283ffe 100644
--- a/erts/emulator/hipe/hipe_bif0.h
+++ b/erts/emulator/hipe/hipe_bif0.h
@@ -26,10 +26,6 @@
 
 extern Uint *hipe_bifs_find_pc_from_mfa(Eterm mfa);
 
-/* shared with ggc.c -- NOT an official API */
-extern Eterm *hipe_constants_start;
-extern Eterm *hipe_constants_next;
-
 extern void hipe_mfa_info_table_init(void);
 extern void *hipe_get_remote_na(Eterm m, Eterm f, unsigned int a);
 extern Eterm hipe_find_na_or_make_stub(Process*, Eterm, Eterm, Eterm);
diff --git a/erts/emulator/hipe/hipe_bif2.c b/erts/emulator/hipe/hipe_bif2.c
index f992b75..e5a236c 100644
--- a/erts/emulator/hipe/hipe_bif2.c
+++ b/erts/emulator/hipe/hipe_bif2.c
@@ -33,7 +33,6 @@
 #include "big.h"
 #include "hipe_debug.h"
 #include "hipe_mode_switch.h"
-#include "hipe_bif0.h" /* hipe_constants_{start,next} */
 #include "hipe_arch.h"
 #include "hipe_stack.h"
 
@@ -124,18 +123,6 @@ BIF_RETTYPE hipe_bifs_show_term_1(BIF_ALIST_1)
     BIF_RET(am_true);
 }
 
-BIF_RETTYPE hipe_bifs_show_literals_0(BIF_ALIST_0)
-{
-    Eterm *p;
-
-    p = hipe_constants_start;
-    for (; p < hipe_constants_next; ++p)
-	printf("0x%0*lx: 0x%0*lx\r\n",
-	       2*(int)sizeof(long), (unsigned long)p,
-	       2*(int)sizeof(long), *p);
-    BIF_RET(am_true);
-}
-
 BIF_RETTYPE hipe_bifs_in_native_0(BIF_ALIST_0)
 {
     BIF_RET(am_false);
diff --git a/erts/emulator/hipe/hipe_bif2.tab b/erts/emulator/hipe/hipe_bif2.tab
index d8d627e..9578b69 100644
--- a/erts/emulator/hipe/hipe_bif2.tab
+++ b/erts/emulator/hipe/hipe_bif2.tab
@@ -26,7 +26,6 @@ bif hipe_bifs:show_nstack/1
 bif hipe_bifs:nstack_used_size/0
 bif hipe_bifs:show_pcb/1
 bif hipe_bifs:show_term/1
-bif hipe_bifs:show_literals/0
 bif hipe_bifs:in_native/0
 bif hipe_bifs:modeswitch_debug_on/0
 bif hipe_bifs:modeswitch_debug_off/0
diff --git a/erts/emulator/hipe/hipe_gc.c b/erts/emulator/hipe/hipe_gc.c
index 6c9e1d9..6dd296d 100644
--- a/erts/emulator/hipe/hipe_gc.c
+++ b/erts/emulator/hipe/hipe_gc.c
@@ -28,7 +28,6 @@
 
 #include "hipe_stack.h"
 #include "hipe_gc.h"
-#include "hipe_bif0.h"		/* for hipe_constants_{start,next} */
 
 Eterm *fullsweep_nstack(Process *p, Eterm *n_htop)
 {
-- 
1.7.1.1



More information about the erlang-patches mailing list