]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/gc_info.hpp
io.streams.256color: faster by caching styles
[factor.git] / vm / gc_info.hpp
index d5229a19a5584414dba78a89b5de02cba555229b..79b89589b29dc04a8eeecf971a432bc02f73a853 100644 (file)
@@ -1,51 +1,54 @@
-namespace factor
-{
+namespace factor {
 
+// gc_info should be kept in sync with:
+//   basis/compiler/codegen/gc-maps/gc-maps.factor
+//   basis/vm/vm.factor
 struct gc_info {
-       u32 scrub_d_count;
-       u32 scrub_r_count;
-       u32 gc_root_count;
-       u32 return_address_count;
-
-       cell total_bitmap_size()
-       {
-               return return_address_count * (scrub_d_count + scrub_r_count + gc_root_count);
-       }
-
-       cell total_bitmap_bytes()
-       {
-               return ((total_bitmap_size() + 7) / 8);
-       }
-
-       u32 *return_addresses()
-       {
-               return (u32 *)((u8 *)this - return_address_count * sizeof(u32));
-       }
-
-       u8 *gc_info_bitmap()
-       {
-               return (u8 *)return_addresses() - total_bitmap_bytes();
-       }
-
-       cell scrub_d_base(cell index)
-       {
-               return index * scrub_d_count;
-       }
-
-       cell scrub_r_base(cell index)
-       {
-               return return_address_count * scrub_d_count +
-                       index * scrub_r_count;
-       }
-
-       cell spill_slot_base(cell index)
-       {
-               return return_address_count * scrub_d_count
-                       + return_address_count * scrub_r_count
-                       + index * gc_root_count;
-       }
-
-       int return_address_index(cell return_address);
+  uint32_t gc_root_count;
+  uint32_t derived_root_count;
+  uint32_t return_address_count;
+
+  cell callsite_bitmap_size() {
+    return gc_root_count;
+  }
+
+  cell total_bitmap_size() {
+    return return_address_count * callsite_bitmap_size();
+  }
+
+  cell total_bitmap_bytes() { return ((total_bitmap_size() + 7) / 8); }
+
+  uint32_t* return_addresses() {
+    return (uint32_t*)this - return_address_count;
+  }
+
+  uint32_t* base_pointer_map() {
+    return return_addresses() - return_address_count * derived_root_count;
+  }
+
+  uint8_t* gc_info_bitmap() {
+    return (uint8_t*)base_pointer_map() - total_bitmap_bytes();
+  }
+
+
+  cell callsite_gc_roots(cell index) {
+    return index * gc_root_count;
+  }
+
+  uint32_t lookup_base_pointer(cell index, cell derived_root) {
+    return base_pointer_map()[index * derived_root_count + derived_root];
+  }
+
+  cell return_address_index(cell return_address) {
+    uint32_t* return_address_array = return_addresses();
+
+    for (cell i = 0; i < return_address_count; i++) {
+      if (return_address == return_address_array[i])
+        return i;
+    }
+
+    return (cell)-1;
+  }
 };
 
 }