Author: astitcher
Date: Thu Jul 17 16:53:14 2014
New Revision: 1611404
URL: http://svn.apache.org/r1611404
Log:
PROTON-558: Reduce the memory usage for the field name tables some more.
- Used a string pool and instead of keeping addresses of strings
hold offsets into the string pool.
- This moves all the tables into rodata and only leaves the string pool
pointer as relro.
Modified:
qpid/proton/trunk/proton-c/src/codec/codec.c
qpid/proton/trunk/proton-c/src/protocol.h.py
Modified: qpid/proton/trunk/proton-c/src/codec/codec.c
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/codec/codec.c?rev=1611404&r1=1611403&r2=1611404&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/codec/codec.c (original)
+++ qpid/proton/trunk/proton-c/src/codec/codec.c Thu Jul 17 16:53:14 2014
@@ -103,8 +103,8 @@ static const pn_fields_t *pni_node_field
return NULL;
}
- if (descriptor->atom.u.as_ulong < 256) {
- const pn_fields_t *f = &FIELDS[descriptor->atom.u.as_ulong];
+ if (descriptor->atom.u.as_ulong >= FIELD_MIN && descriptor->atom.u.as_ulong
<= FIELD_MAX) {
+ const pn_fields_t *f = &FIELDS[descriptor->atom.u.as_ulong-FIELD_MIN];
return (f->name_index!=0) ? f : NULL;
} else {
return NULL;
@@ -265,7 +265,7 @@ int pni_inspect_enter(void *ctx, pn_data
return 0;
}
const char *name = (index < grandfields->field_count)
- ? FIELD_FIELDS[grandfields->first_field_index+index]
+ ? FIELD_STRINGPOOL+FIELD_FIELDS[grandfields->first_field_index+index]
: NULL;
if (name) {
err = pn_string_addf(str, "%s=", name);
@@ -285,7 +285,7 @@ int pni_inspect_enter(void *ctx, pn_data
return pn_string_addf(str, "{");
default:
if (fields && index == 0) {
- err = pn_string_addf(str, "%s", FIELD_NAME[fields->name_index]);
+ err = pn_string_addf(str, "%s",
FIELD_STRINGPOOL+FIELD_NAME[fields->name_index]);
if (err) return err;
err = pn_string_addf(str, "(");
if (err) return err;
Modified: qpid/proton/trunk/proton-c/src/protocol.h.py
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/protocol.h.py?rev=1611404&r1=1611403&r2=1611404&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/protocol.h.py (original)
+++ qpid/proton/trunk/proton-c/src/protocol.h.py Thu Jul 17 16:53:14 2014
@@ -45,49 +45,82 @@ for type in TYPES:
fields[code] = (type["@name"], [f["@name"] for f in type.query["field"]])
idx += 1
-print
+print """
+#include <stddef.h>
-print """typedef struct {
+typedef struct {
const unsigned char name_index;
const unsigned char first_field_index;
const unsigned char field_count;
} pn_fields_t;
-extern const pn_fields_t FIELDS[256];
-extern const char * const FIELD_NAME[];
-extern const char * const FIELD_FIELDS[];
+extern const pn_fields_t FIELDS[];
+extern const char * const FIELD_STRINGPOOL;
+extern const uint16_t FIELD_NAME[];
+extern const uint16_t FIELD_FIELDS[];
+extern const unsigned char FIELD_MIN;
+extern const unsigned char FIELD_MAX;
"""
print "#ifdef DEFINE_FIELDS"
-print "const char * const FIELD_NAME[] = {"
-print " NULL,"
+print 'struct FIELD_STRINGS {'
+print ' const char FIELD_STRINGS_NULL[sizeof("")];'
+strings = set()
+for name, fnames in fields.values():
+ strings.add(name)
+ strings.update(fnames)
+for str in strings:
+ istr = str.replace("-", "_");
+ print ' const char FIELD_STRINGS_%s[sizeof("%s")];' % (istr, str)
+print "};"
+print
+print 'const struct FIELD_STRINGS FIELD_STRINGS = {'
+print ' "",'
+for str in strings:
+ print ' "%s",'% str
+print "};"
+print 'const char * const FIELD_STRINGPOOL = (const char * const)
&FIELD_STRINGS;'
+print
+print "/* This is an array of offsets into FIELD_STRINGPOOL */"
+print "const uint16_t FIELD_NAME[] = {"
+print " offsetof(struct FIELD_STRINGS, FIELD_STRINGS_NULL),"
index = 1
for i in range(256):
if i in fields:
name, fnames = fields[i]
- print ' "%s", /* %d */' % (name, index)
+ iname = name.replace("-", "_");
+ print ' offsetof(struct FIELD_STRINGS, FIELD_STRINGS_%s), /* %d */' %
(iname, index)
index += 1
print "};"
-print "const char * const FIELD_FIELDS[] = {"
-print " NULL,"
+print "/* This is an array of offsets into FIELD_STRINGPOOL */"
+print "const uint16_t FIELD_FIELDS[] = {"
+print " offsetof(struct FIELD_STRINGS, FIELD_STRINGS_NULL),"
index = 1
for i in range(256):
if i in fields:
name, fnames = fields[i]
if fnames:
for f in fnames:
- print ' "%s", /* %d (%s) */' % (f, index, name)
+ ifname = f.replace("-", "_");
+ print ' offsetof(struct FIELD_STRINGS, FIELD_STRINGS_%s), /* %d (%s)
*/' % (ifname, index, name)
index += 1
print "};"
-print "const pn_fields_t FIELDS[256] = {"
+print "const pn_fields_t FIELDS[] = {"
name_count = 1
field_count = 1
+field_min = 256
+field_max = 0
for i in range(256):
if i in fields:
+ if i>field_max: field_max = i
+ if i<field_min: field_min = i
+
+for i in range(field_min, field_max+1):
+ if i in fields:
name, fnames = fields[i]
if fnames:
print ' {%d, %d, %d}, /* %d (%s) */' % (name_count, field_count,
len(fnames), i, name)
@@ -95,11 +128,16 @@ for i in range(256):
else:
print ' {%d, 0, 0}, /* %d (%s) */' % (name_count, i, name)
name_count += 1
+ if i>field_max: field_max = i
+ if i<field_min: field_min = i
else:
print ' {0, 0, 0}, /* %d */' % i
print "};"
+print
+print 'const unsigned char FIELD_MIN = %d;' % field_min
+print 'const unsigned char FIELD_MAX = %d;' % field_max
+print
print "#endif"
-
print
print "#endif /* protocol.h */"
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]