unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [BDW-GC] Static cell/string/symbol allocation
@ 2009-01-06  0:02 Ludovic Courtès
  2009-01-06  2:11 ` Ken Raeburn
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Ludovic Courtès @ 2009-01-06  0:02 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 860 bytes --]

Hello,

I modified <snarf.h> in the BDW-GC branch to transparently have all
`SCM_SYMBOL ()' invocations use a statically allocated stringbuf.  The
symbol itself still has to be interned then so for simplicity the
implementation statically allocates an immutable string and then uses
`string->symbol' at initialization time to create an interned symbol
(which reuses the string's stringbuf).

The idea could be applied to other types in <snarf.h>, but most of them
require an initialization phase (e.g., subrs are assigned a number at
run-time).

Alas, there's no portable way that I know of to ask the compiler to
align double cells on 8-byte boundaries so that Guile actually
recognizes them as cells.  GCC's `aligned' attribute does the job, but
is not portable.  So this can't be committed, unless someone comes up
with a bright idea.  :-)

Thanks,
Ludo'.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: The patch --]
[-- Type: text/x-patch, Size: 4990 bytes --]

diff --git a/libguile/_scm.h b/libguile/_scm.h
index 6b728be..08c58e5 100644
--- a/libguile/_scm.h
+++ b/libguile/_scm.h
@@ -58,6 +58,7 @@
 #include "libguile/variable.h"
 #include "libguile/modules.h"
 #include "libguile/inline.h"
+#include "libguile/strings.h"
 
 /* SCM_SYSCALL retries system calls that have been interrupted (EINTR).
    However this can be avoided if the operating system can restart
diff --git a/libguile/snarf.h b/libguile/snarf.h
index 5c2f187..f1fdede 100644
--- a/libguile/snarf.h
+++ b/libguile/snarf.h
@@ -3,7 +3,7 @@
 #ifndef SCM_SNARF_H
 #define SCM_SNARF_H
 
-/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2006, 2009 Free Software Foundation, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -173,13 +173,17 @@ scm_c_define_subr_with_generic (RANAME, TYPE, \
 SCM_SNARF_HERE(static const char RANAME[]=STR)\
 SCM_SNARF_INIT(scm_make_synt (RANAME, TYPE, CFN))
 
-#define SCM_SYMBOL(c_name, scheme_name) \
-SCM_SNARF_HERE(static SCM c_name) \
-SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_symbol (scheme_name)))
+#define SCM_SYMBOL(c_name, scheme_name)					\
+SCM_SNARF_HERE(								\
+  SCM_IMMUTABLE_STRING (c_name ## _string, scheme_name);		\
+  static SCM c_name)							\
+SCM_SNARF_INIT(c_name = scm_string_to_symbol (c_name ## _string))
 
-#define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
-SCM_SNARF_HERE(SCM c_name) \
-SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_symbol (scheme_name)))
+#define SCM_GLOBAL_SYMBOL(c_name, scheme_name)				\
+SCM_SNARF_HERE(								\
+  SCM_IMMUTABLE_STRING (c_name ## _string, scheme_name);		\
+  SCM c_name)								\
+SCM_SNARF_INIT(c_name = scm_string_to_symbol (c_name ## _string))
 
 #define SCM_KEYWORD(c_name, scheme_name) \
 SCM_SNARF_HERE(static SCM c_name) \
@@ -269,6 +273,35 @@ SCM_SNARF_INIT(scm_set_smob_apply((tag), (c_name), (req), (opt), (rest));)
 SCM_SNARF_HERE(SCM c_name arglist) \
 SCM_SNARF_INIT(scm_set_smob_apply((tag), (c_name), (req), (opt), (rest));)
 
+\f
+/* Low-level snarfing.  */
+
+#define SCM_IMMUTABLE_DOUBLE_CELL(c_name, car, cbr, ccr, cdr)		\
+  static SCM_UNUSED const scm_t_cell c_name ## _raw_cell [2]		\
+    __attribute__ ((__aligned__ ((8)))) =				\
+    {									\
+      { SCM_PACK (car), SCM_PACK (cbr) },				\
+      { SCM_PACK (ccr), SCM_PACK (cdr) }				\
+    };									\
+  static SCM_UNUSED SCM c_name = SCM_PACK (& c_name ## _raw_cell)
+
+#define SCM_IMMUTABLE_STRINGBUF(c_name, contents)			\
+  SCM_IMMUTABLE_DOUBLE_CELL (c_name,					\
+			     scm_tc7_stringbuf | SCM_I_STRINGBUF_F_SHARED, \
+			     (scm_t_bits) (contents),			\
+                             (scm_t_bits) sizeof (contents) - 1,	\
+			     (scm_t_bits) 0)
+
+#define SCM_IMMUTABLE_STRING(c_name, contents)				\
+  SCM_IMMUTABLE_STRINGBUF (c_name ## _stringbuf, contents);		\
+  SCM_IMMUTABLE_DOUBLE_CELL (c_name,					\
+			     scm_tc7_string + 0x200,			\
+			     (scm_t_bits) &c_name ## _stringbuf_raw_cell, \
+			     (scm_t_bits) 0,				\
+			     sizeof (contents) - 1)
+
+\f
+/* Documentation.  */
 
 #ifdef SCM_MAGIC_SNARF_DOCS
 #undef SCM_ASSERT
diff --git a/libguile/strings.c b/libguile/strings.c
index 9188a0d..f1167c6 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1998,2000,2001, 2004, 2006, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1998,2000,2001, 2004, 2006, 2008, 2009 Free Software Foundation, Inc.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -66,7 +66,7 @@
  * stringbuf.  So we have fixstrings and bigstrings...
  */
 
-#define STRINGBUF_F_SHARED      0x100
+#define STRINGBUF_F_SHARED      SCM_I_STRINGBUF_F_SHARED
 #define STRINGBUF_F_INLINE      0x200
 
 #define STRINGBUF_TAG           scm_tc7_stringbuf
diff --git a/libguile/strings.h b/libguile/strings.h
index e81ee3d..6d8bf5f 100644
--- a/libguile/strings.h
+++ b/libguile/strings.h
@@ -3,7 +3,7 @@
 #ifndef SCM_STRINGS_H
 #define SCM_STRINGS_H
 
-/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2004, 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -111,6 +111,8 @@ SCM_API SCM scm_makfromstrs (int argc, char **argv);
 
 /* internal accessor functions.  Arguments must be valid. */
 
+#define SCM_I_STRINGBUF_F_SHARED      0x100
+
 SCM_INTERNAL SCM scm_i_make_string (size_t len, char **datap);
 SCM_INTERNAL SCM scm_i_substring (SCM str, size_t start, size_t end);
 SCM_INTERNAL SCM scm_i_substring_read_only (SCM str, size_t start, size_t end);

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-01-15 23:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-06  0:02 [BDW-GC] Static cell/string/symbol allocation Ludovic Courtès
2009-01-06  2:11 ` Ken Raeburn
2009-01-13  0:04   ` Ludovic Courtès
2009-01-13 20:57     ` Ken Raeburn
2009-01-13  0:34 ` Ludovic Courtès
2009-01-15 23:20 ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).