]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/jit.cpp
vm: change "profiler" names to "counting_profiler"
[factor.git] / vm / jit.cpp
index 3324cfb366179a28926b8d7c0e405ea910827976..77b827bef2c290a3ceb8c3b64072f515adc744f2 100644 (file)
@@ -4,7 +4,7 @@ namespace factor
 {
 
 /* Simple code generator used by:
-- profiler (profiler.cpp),
+- counting_profiler (counting_profiler.cpp),
 - quotation compiler (quotations.cpp),
 - megamorphic caches (dispatch.cpp),
 - polymorphic inline caches (inline_cache.cpp) */
@@ -23,17 +23,17 @@ jit::jit(code_block_type type_, cell owner_, factor_vm *vm)
          parent(vm)
 {}
 
-void jit::emit_relocation(cell code_template_)
+void jit::emit_relocation(cell relocation_template_)
 {
-       data_root<array> code_template(code_template_,parent);
-       cell capacity = array_capacity(code_template.untagged());
-       for(cell i = 1; i < capacity; i += 3)
+       data_root<byte_array> relocation_template(relocation_template_,parent);
+       cell capacity = array_capacity(relocation_template.untagged())
+               / sizeof(relocation_entry);
+       relocation_entry *relocations = relocation_template->data<relocation_entry>();
+       for(cell i = 0; i < capacity; i++)
        {
-               relocation_class rel_class = (relocation_class)untag_fixnum(array_nth(code_template.untagged(),i));
-               relocation_type rel_type = (relocation_type)untag_fixnum(array_nth(code_template.untagged(),i + 1));
-               cell offset = array_nth(code_template.untagged(),i + 2);
-
-               relocation_entry new_entry(rel_type,rel_class,code.count + untag_fixnum(offset));
+               relocation_entry entry = relocations[i];
+               relocation_entry new_entry(entry.rel_type(), entry.rel_class(),
+                       entry.rel_offset() + code.count);
                relocation.append_bytes(&new_entry,sizeof(relocation_entry));
        }
 }
@@ -43,9 +43,9 @@ void jit::emit(cell code_template_)
 {
        data_root<array> code_template(code_template_,parent);
 
-       emit_relocation(code_template.value());
+       emit_relocation(array_nth(code_template.untagged(),0));
 
-       data_root<byte_array> insns(array_nth(code_template.untagged(),0),parent);
+       data_root<byte_array> insns(array_nth(code_template.untagged(),1),parent);
 
        if(computing_offset_p)
        {
@@ -116,6 +116,11 @@ void jit::compute_position(cell offset_)
 /* Allocates memory */
 code_block *jit::to_code_block()
 {
+       /* Emit dummy GC info */
+       code.grow_bytes(alignment_for(code.count + 4,data_alignment));
+       u32 dummy_gc_info = 0;
+       code.append_bytes(&dummy_gc_info,sizeof(u32));
+
        code.trim();
        relocation.trim();
        parameters.trim();