Browse Source

Implement ajduk ptr compr, pool size tweaks

Also add more AjsHeap pool sizes for measurements.  The resulting pool
total size is >128kB, but only a small part of it is used.  It's good
to have pool entries with 4-byte increments in the low range so that
actual used sizes can be more easily seen.
pull/92/head
Sami Vaarala 10 years ago
parent
commit
e451c4d8fb
  1. 21
      Makefile
  2. 56
      examples/cmdline/duk_cmdline.c

21
Makefile

@ -788,6 +788,23 @@ ajtcl:
# no --depth 1 ("dumb http transport does not support --depth")
$(GIT) clone https://git.allseenalliance.org/cgit/core/ajtcl.git/
CCOPTS_AJDUK=-m32
#CCOPTS_AJDUK+='-fpack-struct=1'
CCOPTS_AJDUK+=-UDUK_CMDLINE_FANCY -DDUK_CMDLINE_AJSHEAP -D_POSIX_C_SOURCE=200809L
CCOPTS_AJDUK+=-DDUK_OPT_ASSERTIONS
CCOPTS_AJDUK+=-DDUK_OPT_LIGHTFUNC_BUILTINS
CCOPTS_AJDUK+=-DDUK_OPT_HEAPPTR16
CCOPTS_AJDUK+=-DDUK_OPT_REFCOUNT16
CCOPTS_AJDUK+=-DDUK_OPT_STRHASH16
CCOPTS_AJDUK+=-DDUK_OPT_STRLEN16
CCOPTS_AJDUK+=-DDUK_OPT_BUFLEN16
CCOPTS_AJDUK+=-DDUK_OPT_OBJSIZES16
CCOPTS_AJDUK+='-DDUK_OPT_HEAPPTR_ENC16(p)=ajsheap_enc16(p)'
CCOPTS_AJDUK+='-DDUK_OPT_HEAPPTR_DEC16(x)=ajsheap_dec16(x)'
CCOPTS_AJDUK+='-DDUK_OPT_DECLARE=extern uint8_t *ajsheap_ram; extern duk_uint16_t ajsheap_enc16(void *p); extern void *ajsheap_dec16(duk_uint16_t x);'
#CCOPTS_AJDUK+=-DDUK_OPT_DEBUG -DDUK_OPT_DPRINT
#CCOPTS_AJDUK+=-DDUK_OPT_DEBUG -DDUK_OPT_DPRINT -DDUK_OPT_DDPRINT -DDUK_OPT_DDDPRINT
ajduk: alljoyn-js ajtcl dist
# Command line with Alljoyn.js pool allocator, for low memory testing.
# The pool sizes only make sense with -m32, so force that. This forces
@ -796,9 +813,7 @@ ajduk: alljoyn-js ajtcl dist
$(CC) -o $@ \
-Ialljoyn-js/ -Iajtcl/inc/ -Iajtcl/target/linux/ \
$(CCOPTS_NONDEBUG) \
-m32 \
-UDUK_CMDLINE_FANCY -DDUK_CMDLINE_AJSHEAP -D_POSIX_C_SOURCE=200809L \
-DDUK_OPT_LIGHTFUNC_BUILTINS \
$(CCOPTS_AJDUK) \
$(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) \
alljoyn-js/ajs_heap.c ajtcl/src/aj_debug.c ajtcl/target/linux/aj_target_util.c \
-lm -lpthread

56
examples/cmdline/duk_cmdline.c

@ -409,11 +409,17 @@ static int handle_interactive(duk_context *ctx) {
static const AJS_HeapConfig ajsheap_config[] = {
{ 8, 10, AJS_POOL_BORROW, 0 },
{ 12, 10, AJS_POOL_BORROW, 0 },
{ 20, 50, AJS_POOL_BORROW, 0 },
{ 24, 100, AJS_POOL_BORROW, 0 },
{ 32, 600, AJS_POOL_BORROW, 0 },
{ 40, 200, 0, 0 },
{ 48, 400, 0, 0 },
{ 16, 200, AJS_POOL_BORROW, 0 },
{ 20, 400, AJS_POOL_BORROW, 0 },
{ 24, 400, AJS_POOL_BORROW, 0 },
{ 28, 200, AJS_POOL_BORROW, 0 },
{ 32, 200, AJS_POOL_BORROW, 0 },
{ 40, 200, AJS_POOL_BORROW, 0 },
{ 48, 50, AJS_POOL_BORROW, 0 },
{ 52, 50, AJS_POOL_BORROW, 0 },
{ 56, 50, AJS_POOL_BORROW, 0 },
{ 60, 50, AJS_POOL_BORROW, 0 },
{ 64, 50, 0, 0 },
{ 128, 80, 0, 0 },
{ 256, 16, 0, 0 },
{ 512, 16, 0, 0 },
@ -423,7 +429,45 @@ static const AJS_HeapConfig ajsheap_config[] = {
{ 8192, 1, 0, 0 }
};
static uint8_t *ajsheap_ram = NULL;
uint8_t *ajsheap_ram = NULL;
/* Pointer compression functions.
* 'base' is chosen so that no non-NULL pointer results in a zero result
* which is reserved for NULL pointers.
*/
duk_uint16_t ajsheap_enc16(void *p) {
duk_uint32_t ret;
char *base = (char *) ajsheap_ram - 4;
if (p == NULL) {
ret = 0;
} else {
ret = (duk_uint32_t) (((char *) p - base) >> 2);
}
#if 0
printf("ajsheap_enc16: %p -> %u\n", p, (unsigned int) ret);
#endif
if (ret > 0xffffUL) {
fprintf(stderr, "Failed to compress pointer\n");
fflush(stderr);
abort();
}
return (duk_uint16_t) ret;
}
void *ajsheap_dec16(duk_uint16_t x) {
void *ret;
char *base = (char *) ajsheap_ram - 4;
if (x == 0) {
ret = NULL;
} else {
ret = (void *) (base + (((duk_uint32_t) x) << 2));
}
#if 0
printf("ajsheap_dec16: %u -> %p\n", (unsigned int) x, ret);
#endif
return ret;
}
static void ajsheap_init(void) {
size_t heap_sz[1];

Loading…
Cancel
Save