From 4fe75dde0def4bc37c8b94918a93f150cb500c20 Mon Sep 17 00:00:00 2001 From: Douglas Katzman Date: Wed, 29 Mar 2017 22:54:39 -0400 Subject: [PATCH] Define fun_code_header in C for symmetry with Lisp --- src/runtime/gc-internal.h | 14 +------------- src/runtime/gc.h | 10 ++++++++++ src/runtime/gencgc.c | 8 +++----- src/runtime/marknsweepgc.c | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/runtime/gc-internal.h b/src/runtime/gc-internal.h index 791e5e0ce..54753cb38 100644 --- a/src/runtime/gc-internal.h +++ b/src/runtime/gc-internal.h @@ -285,9 +285,6 @@ static inline low_page_index_t find_immobile_page_index(void *addr) int immobile_obj_younger_p(lispobj,generation_index_t); void promote_immobile_obj(lispobj*,int); -// Maximum number of boxed words in a code component -#define CODE_HEADER_COUNT_MASK 0xFFFFFF - #define IMMOBILE_OBJ_VISITED_FLAG 0x10 #define IMMOBILE_OBJ_GENERATION_MASK 0x0f // mask off the VISITED flag @@ -297,20 +294,11 @@ void promote_immobile_obj(lispobj*,int); // because a simple-fun header does not contain a generation. #define __immobile_obj_generation(x) (__immobile_obj_gen_bits(x) & IMMOBILE_OBJ_GENERATION_MASK) -static inline struct code *code_obj_from_simple_fun(struct simple_fun *fun) -{ - // The upper 4 bytes of any function header will point to its layout, - // so mask those bytes off. - uword_t offset = (HeaderValue(fun->header) & CODE_HEADER_COUNT_MASK) - * N_WORD_BYTES; - return (struct code *)((uword_t)fun - offset); -} - #ifdef LISP_FEATURE_LITTLE_ENDIAN static inline int immobile_obj_gen_bits(lispobj* pointer) // native pointer { if (widetag_of(*pointer) == SIMPLE_FUN_HEADER_WIDETAG) - pointer = (lispobj*)code_obj_from_simple_fun((struct simple_fun*)pointer); + pointer = fun_code_header(pointer); return ((generation_index_t*)pointer)[3]; } // Faster way when we know that the object can't be a simple-fun, diff --git a/src/runtime/gc.h b/src/runtime/gc.h index 35a783210..884ba71e0 100644 --- a/src/runtime/gc.h +++ b/src/runtime/gc.h @@ -44,4 +44,14 @@ extern boolean maybe_gc(os_context_t *context); extern os_vm_size_t bytes_consed_between_gcs; +/// Maximum number of word backwards from a simple-fun +/// to its containing code component - corresponds to ~128MB. +/// The limit exists so that we can store the layout pointer +/// in the header of any callable object if N_WORD_BITS = 64. +/// This is not technically a restriction on the code size. +#define FUN_HEADER_NWORDS_MASK 0xFFFFFF + +#define fun_code_header(fun) \ + ((lispobj*)(fun) - (HeaderValue(*(lispobj*)(fun))&FUN_HEADER_NWORDS_MASK)) + #endif /* _GC_H_ */ diff --git a/src/runtime/gencgc.c b/src/runtime/gencgc.c index 2b9deca70..a90e9f59a 100644 --- a/src/runtime/gencgc.c +++ b/src/runtime/gencgc.c @@ -2434,15 +2434,13 @@ update_page_write_prot(page_index_t page) if (lowtag_of((lispobj)ptr) != FUN_POINTER_LOWTAG) { obj_gen = __immobile_obj_generation(native_pointer((lispobj)ptr)); } else if (widetag_of(header) == SIMPLE_FUN_HEADER_WIDETAG) { - struct code* code = - code_obj_from_simple_fun((struct simple_fun *) - ((lispobj)ptr - FUN_POINTER_LOWTAG)); + lispobj* code = fun_code_header((lispobj)ptr - FUN_POINTER_LOWTAG); // This is a heuristic, since we're not actually looking for // an object boundary. Precise scanning of 'page' would obviate // the guard conditions here. if ((lispobj)code >= IMMOBILE_VARYOBJ_SUBSPACE_START - && widetag_of(code->header) == CODE_HEADER_WIDETAG) - obj_gen = __immobile_obj_generation((lispobj*)code); + && widetag_of(*code) == CODE_HEADER_WIDETAG) + obj_gen = __immobile_obj_generation(code); } // A bogus generation number implies a not-really-pointer, // but it won't cause misbehavior. diff --git a/src/runtime/marknsweepgc.c b/src/runtime/marknsweepgc.c index 7c586b660..ba3900ac2 100644 --- a/src/runtime/marknsweepgc.c +++ b/src/runtime/marknsweepgc.c @@ -404,7 +404,7 @@ void promote_immobile_obj(lispobj *ptr, int rescan) // a native pointer { if (widetag_of(*ptr) == SIMPLE_FUN_HEADER_WIDETAG) - ptr = (lispobj*)code_obj_from_simple_fun((struct simple_fun*)ptr); + ptr = fun_code_header(ptr); gc_assert(__immobile_obj_gen_bits(ptr) == from_space); int pointerish = !unboxed_obj_widetag_p(widetag_of(*ptr)); assign_generation(ptr, (pointerish ? 0 : IMMOBILE_OBJ_VISITED_FLAG) | new_space); -- 2.11.4.GIT