From 0cd4731bb43b3f79d33e85300407031f808763f0 Mon Sep 17 00:00:00 2001 From: Alastair Bridgewater Date: Mon, 30 Dec 2013 17:37:04 -0500 Subject: [PATCH] gencgc: Reduce conservatism for pointers to unboxed pages. * Because return addresses are unmarked, unboxed interior pointers must be allowed to pin if they point within a code object. Assuming that code objects are only allocated to CODE_PAGE_FLAG pages, preserve_pointer() will allow any code_page_p() true page to be pinned by any pointer to within its body. * But code_page_p() was broken, being an alternate version of page_allocated_p() in implementation, with no warning or comment. The net effect is extra conservatism: Any pointer to allocated space will pin whatever page it points to. * Code pages aren't always allocated to CODE_PAGE_FLAG pages, for a couple of reasons. Until we can maintain such an invariant, we can only use the weaker version (which DOES hold): code objects are always allocated to boxed pages (either BOXED_PAGE_FLAG or CODE_PAGE_FLAG, never FREE_PAGE_FLAG or UNBOXED_PAGE_FLAG). * Reduce conservatism in the GC by making code_page_p() delegate to page_boxed_p(), thus tightening up the test for pinning unboxed pages. * Also leave the "correct" logic for code_page_p() in place but disabled (and make it actually BE correct), and add a comment explaining part of what's going on. --- NEWS | 4 ++++ src/runtime/gencgc.c | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 75355ee..5977d64 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,10 @@ changes relative to sbcl-1.1.14: * enhancement: sb-ext:save-lisp-and-die on Windows now accepts :application-type argument, which can be :console or :gui. :gui allows having GUI applications without an automatically appearing console window. + * enhancement: reduced conservativism on GENCGC platforms: + conservative roots that point to unboxed pages must be tagged + pointers to the start of a valid-looking object, not merely point + to within the allocated part of the page, in order to pin the page. * bug fix: Windows applications without the console window no longer misbehave. (patch by Wilfredo Velazquez, lp#1256034). * bug fix: modular arithmetic optimizations do not stumble on dead branches diff --git a/src/runtime/gencgc.c b/src/runtime/gencgc.c index 5d218b1..77ec797 100644 --- a/src/runtime/gencgc.c +++ b/src/runtime/gencgc.c @@ -201,7 +201,18 @@ static inline boolean page_boxed_p(page_index_t page) { } static inline boolean code_page_p(page_index_t page) { - return (page_table[page].allocated & CODE_PAGE_FLAG); + /* This is used by the conservative pinning logic to determine if + * a page can contain code objects. Ideally, we'd be able to + * check the page allocation flag to see if it is CODE_PAGE_FLAG, + * but this turns out not to be reliable (in fact, badly + * unreliable) at the moment. On the upside, all code objects are + * boxed objects, so we can simply re-use the boxed_page_p() logic + * for a tighter result than merely "is this page allocated". */ +#if 0 + return (page_table[page].allocated & CODE_PAGE_FLAG) == CODE_PAGE_FLAG; +#else + return page_boxed_p(page); +#endif } static inline boolean page_boxed_no_region_p(page_index_t page) { -- 1.7.10.4