diff options
author | Maxime Chevalier-Boisvert <[email protected]> | 2021-09-21 10:59:55 -0400 |
---|---|---|
committer | Alan Wu <[email protected]> | 2021-10-20 18:19:41 -0400 |
commit | 0385ca2e97ba29653251dba96ab8cf0f21765bb4 (patch) | |
tree | e1d1b6cc4ceabe4cbbe67d403609fe920fe19112 /yjit_iface.c | |
parent | c46bda6f191b01121ebbc8afa88b35683b6417a9 (diff) |
Try to break the code page refactoring into smaller steps
Diffstat (limited to 'yjit_iface.c')
-rw-r--r-- | yjit_iface.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/yjit_iface.c b/yjit_iface.c index 18f35f576d..8268440465 100644 --- a/yjit_iface.c +++ b/yjit_iface.c @@ -971,6 +971,10 @@ VALUE rb_yjit_code_page_alloc(void) { code_page_t* code_page = alloc_code_page(); VALUE cp_obj = TypedData_Wrap_Struct(0, &yjit_code_page_type, code_page); + + // Write a pointer to the wrapper object at the beginning of the code page + *((VALUE*)code_page->mem_block) = cp_obj; + return cp_obj; } @@ -982,6 +986,44 @@ code_page_t *rb_yjit_code_page_unwrap(VALUE cp_obj) return code_page; } +// Get the code page wrapper object for a code pointer +VALUE rb_yjit_code_page_from_ptr(uint8_t* code_ptr) +{ + VALUE* page_start = (VALUE*)((intptr_t)code_ptr & ~(CODE_PAGE_SIZE - 1)); + VALUE wrapper = *page_start; + return wrapper; +} + +// Get the inline code block corresponding to a code pointer +void rb_yjit_get_cb(codeblock_t* cb, uint8_t* code_ptr) +{ + VALUE page_wrapper = rb_yjit_code_page_from_ptr(code_ptr); + code_page_t *code_page = rb_yjit_code_page_unwrap(page_wrapper); + + // A pointer to the page wrapper object is written at the start of the code page + uint8_t* mem_block = code_page->mem_block + sizeof(VALUE); + uint32_t mem_size = (code_page->page_size/2) - sizeof(VALUE); + RUBY_ASSERT(mem_block); + + // Map the code block to this memory region + cb_init(cb, mem_block, mem_size); +} + +// Get the outlined code block corresponding to a code pointer +void rb_yjit_get_ocb(codeblock_t* cb, uint8_t* code_ptr) +{ + VALUE page_wrapper = rb_yjit_code_page_from_ptr(code_ptr); + code_page_t *code_page = rb_yjit_code_page_unwrap(page_wrapper); + + // A pointer to the page wrapper object is written at the start of the code page + uint8_t* mem_block = code_page->mem_block + (code_page->page_size/2); + uint32_t mem_size = code_page->page_size/2; + RUBY_ASSERT(mem_block); + + // Map the code block to this memory region + cb_init(cb, mem_block, mem_size); +} + bool rb_yjit_enabled_p(void) { |