From da51a1f8d0d99be4ebe29996ff8cf2b696c72633 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Mon, 9 Jan 2023 02:30:45 -0500 Subject: [PATCH 1/4] Extend method root to support more than 16bit roots --- src/ircode.c | 23 ++++++++++++++++++----- src/serialize.h | 3 ++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/ircode.c b/src/ircode.c index 9f71d8e8dd28c..a0c77bddd3072 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -110,15 +110,19 @@ static void jl_encode_as_indexed_root(jl_ircode_state *s, jl_value_t *v) write_uint8(s->s, TAG_RELOC_METHODROOT); write_uint64(s->s, rr.key); } - if (id < 256) { + if (id <= UINT8_MAX) { write_uint8(s->s, TAG_METHODROOT); write_uint8(s->s, id); } - else { - assert(id <= UINT16_MAX); + else if (id <= UINT16_MAX) { write_uint8(s->s, TAG_LONG_METHODROOT); write_uint16(s->s, id); } + else { + assert(id <= UINT32_MAX); + write_uint8(s->s, TAG_32BIT_METHODROOT); + write_uint32(s->s, id); + } } static void jl_encode_value_(jl_ircode_state *s, jl_value_t *v, int as_literal) JL_GC_DISABLED @@ -645,12 +649,21 @@ static jl_value_t *jl_decode_value(jl_ircode_state *s) JL_GC_DISABLED case TAG_RELOC_METHODROOT: key = read_uint64(s->s); tag = read_uint8(s->s); - assert(tag == TAG_METHODROOT || tag == TAG_LONG_METHODROOT); - return lookup_root(s->method, key, tag == TAG_METHODROOT ? read_uint8(s->s) : read_uint16(s->s)); + assert(tag == TAG_METHODROOT || tag == TAG_LONG_METHODROOT || tag == TAG_32BIT_METHODROOT); + int index; + if (tag == TAG_METHODROOT) + return index = read_uint8(s->s); + else if (tag == TAG_LONG_METHODROOT) + return index = read_uint16(s->s); + else if (tag == TAG_32BIT_METHODROOT) + return index = read_uint32(s->s); + return lookup_root(s->method, key, index); case TAG_METHODROOT: return lookup_root(s->method, 0, read_uint8(s->s)); case TAG_LONG_METHODROOT: return lookup_root(s->method, 0, read_uint16(s->s)); + case TAG_32BIT_METHODROOT: + return lookup_root(s->method, 0, read_uint32(s->s)); case TAG_SVEC: JL_FALLTHROUGH; case TAG_LONG_SVEC: return jl_decode_value_svec(s, tag); case TAG_COMMONSYM: diff --git a/src/serialize.h b/src/serialize.h index afcdcc31d66c4..225ae76fb61a6 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -64,8 +64,9 @@ extern "C" { #define TAG_ARGUMENT 56 #define TAG_RELOC_METHODROOT 57 #define TAG_BINDING 58 +#define TAG_32BIT_METHODROOT 59 -#define LAST_TAG 58 +#define LAST_TAG 59 #define write_uint8(s, n) ios_putc((n), (s)) #define read_uint8(s) ((uint8_t)ios_getc((s))) From 6ecb40eb9bc279454cfd016e61028ff2e03e73e0 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Mon, 9 Jan 2023 02:42:19 -0500 Subject: [PATCH 2/4] fixup! Extend method root to support more than 16bit roots --- src/ircode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ircode.c b/src/ircode.c index a0c77bddd3072..0d6b1b8b5f3ff 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -650,13 +650,14 @@ static jl_value_t *jl_decode_value(jl_ircode_state *s) JL_GC_DISABLED key = read_uint64(s->s); tag = read_uint8(s->s); assert(tag == TAG_METHODROOT || tag == TAG_LONG_METHODROOT || tag == TAG_32BIT_METHODROOT); - int index; + int index = -1; if (tag == TAG_METHODROOT) return index = read_uint8(s->s); else if (tag == TAG_LONG_METHODROOT) return index = read_uint16(s->s); else if (tag == TAG_32BIT_METHODROOT) return index = read_uint32(s->s); + assert(index >= 0); return lookup_root(s->method, key, index); case TAG_METHODROOT: return lookup_root(s->method, 0, read_uint8(s->s)); From 54d8da15004a15ac9c6e23cd853d374feb3e6b98 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Mon, 9 Jan 2023 03:03:45 -0500 Subject: [PATCH 3/4] fixup! fixup! Extend method root to support more than 16bit roots --- src/ircode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ircode.c b/src/ircode.c index 0d6b1b8b5f3ff..2793ebeb50154 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -652,11 +652,11 @@ static jl_value_t *jl_decode_value(jl_ircode_state *s) JL_GC_DISABLED assert(tag == TAG_METHODROOT || tag == TAG_LONG_METHODROOT || tag == TAG_32BIT_METHODROOT); int index = -1; if (tag == TAG_METHODROOT) - return index = read_uint8(s->s); + index = read_uint8(s->s); else if (tag == TAG_LONG_METHODROOT) - return index = read_uint16(s->s); + index = read_uint16(s->s); else if (tag == TAG_32BIT_METHODROOT) - return index = read_uint32(s->s); + index = read_uint32(s->s); assert(index >= 0); return lookup_root(s->method, key, index); case TAG_METHODROOT: From 015c6924ea4e0c29609a28dcf0af80abea433e82 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Mon, 9 Jan 2023 04:53:31 -0500 Subject: [PATCH 4/4] It seems we are out of tags --- src/ircode.c | 12 ++---------- src/serialize.h | 3 +-- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/ircode.c b/src/ircode.c index 2793ebeb50154..648b954449aa2 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -114,13 +114,9 @@ static void jl_encode_as_indexed_root(jl_ircode_state *s, jl_value_t *v) write_uint8(s->s, TAG_METHODROOT); write_uint8(s->s, id); } - else if (id <= UINT16_MAX) { - write_uint8(s->s, TAG_LONG_METHODROOT); - write_uint16(s->s, id); - } else { assert(id <= UINT32_MAX); - write_uint8(s->s, TAG_32BIT_METHODROOT); + write_uint8(s->s, TAG_LONG_METHODROOT); write_uint32(s->s, id); } } @@ -649,21 +645,17 @@ static jl_value_t *jl_decode_value(jl_ircode_state *s) JL_GC_DISABLED case TAG_RELOC_METHODROOT: key = read_uint64(s->s); tag = read_uint8(s->s); - assert(tag == TAG_METHODROOT || tag == TAG_LONG_METHODROOT || tag == TAG_32BIT_METHODROOT); + assert(tag == TAG_METHODROOT || tag == TAG_LONG_METHODROOT); int index = -1; if (tag == TAG_METHODROOT) index = read_uint8(s->s); else if (tag == TAG_LONG_METHODROOT) - index = read_uint16(s->s); - else if (tag == TAG_32BIT_METHODROOT) index = read_uint32(s->s); assert(index >= 0); return lookup_root(s->method, key, index); case TAG_METHODROOT: return lookup_root(s->method, 0, read_uint8(s->s)); case TAG_LONG_METHODROOT: - return lookup_root(s->method, 0, read_uint16(s->s)); - case TAG_32BIT_METHODROOT: return lookup_root(s->method, 0, read_uint32(s->s)); case TAG_SVEC: JL_FALLTHROUGH; case TAG_LONG_SVEC: return jl_decode_value_svec(s, tag); diff --git a/src/serialize.h b/src/serialize.h index 225ae76fb61a6..afcdcc31d66c4 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -64,9 +64,8 @@ extern "C" { #define TAG_ARGUMENT 56 #define TAG_RELOC_METHODROOT 57 #define TAG_BINDING 58 -#define TAG_32BIT_METHODROOT 59 -#define LAST_TAG 59 +#define LAST_TAG 58 #define write_uint8(s, n) ios_putc((n), (s)) #define read_uint8(s) ((uint8_t)ios_getc((s)))