From b09d6ef5866a4bfcf1f47c7494f5ff8519ddef34 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 24 Nov 2009 21:20:23 -0600 Subject: [PATCH] vm: deallocate old PIC after allocating the new one to avoid having the code heap potentially point to a free block during compaction --- vm/code_blocks.cpp | 2 -- vm/inline_cache.cpp | 19 +++++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/vm/code_blocks.cpp b/vm/code_blocks.cpp index 9d6e9a4b25..9c7349979c 100755 --- a/vm/code_blocks.cpp +++ b/vm/code_blocks.cpp @@ -79,9 +79,7 @@ void *factor_vm::get_rel_symbol(array *literals, cell index) if(sym) return sym; else - { return (void *)factor::undefined_symbol; - } } case ARRAY_TYPE: { diff --git a/vm/inline_cache.cpp b/vm/inline_cache.cpp index 469bb8bf2e..76cdda116e 100755 --- a/vm/inline_cache.cpp +++ b/vm/inline_cache.cpp @@ -183,23 +183,18 @@ void *factor_vm::inline_cache_miss(cell return_address_) check_code_pointer(return_address.value); - /* Since each PIC is only referenced from a single call site, - if the old call target was a PIC, we can deallocate it immediately, - instead of leaving dead PICs around until the next GC. */ - deallocate_inline_cache(return_address.value); - data_root cache_entries(dpop(),this); fixnum index = untag_fixnum(dpop()); data_root methods(dpop(),this); data_root generic_word(dpop(),this); data_root object(((cell *)ds)[-index],this); - void *xt; - cell pic_size = inline_cache_size(cache_entries.value()); update_pic_transitions(pic_size); + void *xt; + if(pic_size >= max_pic_size) xt = megamorphic_call_stub(generic_word.value()); else @@ -221,13 +216,17 @@ void *factor_vm::inline_cache_miss(cell return_address_) /* Install the new stub. */ if(return_address.valid) { + /* Since each PIC is only referenced from a single call site, + if the old call target was a PIC, we can deallocate it immediately, + instead of leaving dead PICs around until the next GC. */ + deallocate_inline_cache(return_address.value); set_call_target(return_address.value,xt); #ifdef PIC_DEBUG std::cout << "Updated " - << (tail_call_site_p(return_address) ? "tail" : "non-tail") - << " call site 0x" << std::hex << return_address << std::dec - << " with " << std::hex << (cell)xt << std::dec; + << (tail_call_site_p(return_address.value) ? "tail" : "non-tail") + << " call site 0x" << std::hex << return_address.value << std::dec + << " with " << std::hex << (cell)xt << std::dec << "\n"; #endif }