seg = new segment(align_page(size),true);
if(!seg) fatal_error("Out of memory in code_heap constructor",size);
- cell start = seg->start + seh_area_size;
+ cell start = seg->start + getpagesize() + seh_area_size;
allocator = new free_list_allocator<code_block>(seg->end - start,start);
- /* See os-windows-nt-x86.64.cpp for seh_area usage */
- seh_area = (char *)seg->start;
+ /* See os-windows-x86.64.cpp for seh_area usage */
+ safepoint_page = (void *)seg->start;
+ seh_area = (char *)seg->start + getpagesize();
}
code_heap::~code_heap()
factor::flush_icache(seg->start,seg->size);
}
-/* Allocate a code heap during startup */
-void factor_vm::init_code_heap(cell size)
+struct address_finder {
+ cell address;
+ code_block *found_code_block;
+
+ address_finder(cell address)
+ : address(address), found_code_block(NULL) {}
+
+ void operator()(code_block *block, cell size)
+ {
+ if ((cell)block->entry_point() <= address
+ && address - (cell)block->entry_point() < block->size())
+ {
+ assert(found_code_block == NULL);
+ found_code_block = block;
+ }
+ }
+};
+
+code_block *code_heap::code_block_for_address(cell address)
{
- code = new code_heap(size);
+ address_finder finder(address);
+ allocator->iterate(finder);
+ return finder.found_code_block;
}
-bool factor_vm::in_code_heap_p(cell ptr)
+/* Allocate a code heap during startup */
+void factor_vm::init_code_heap(cell size)
{
- return (ptr >= code->seg->start && ptr <= code->seg->end);
+ code = new code_heap(size);
}
struct word_updater {
parameters,
literals);
- word->code = compiled;
+ word->entry_point = compiled->entry_point();
}
break;
default:
critical_error("Expected a quotation or an array",data.value());
break;
}
-
- update_word_entry_point(word.untagged());
}
if(update_existing_words)
/* Note: the entry point is always a multiple of the heap
alignment (16 bytes). We cannot allocate while iterating
- through the code heap, so it is not possible to call allot_cell()
- here. It is OK, however, to add it as if it were a fixnum, and
- have library code shift it to the left by 4. */
+ through the code heap, so it is not possible to call
+ from_unsigned_cell() here. It is OK, however, to add it as
+ if it were a fixnum, and have library code shift it to the
+ left by 4. */
cell entry_point = (cell)compiled->entry_point();
assert((entry_point & (data_alignment - 1)) == 0);
assert((entry_point & TAG_MASK) == FIXNUM_TYPE);