]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/bump_allocator.hpp
webapps.wiki: adding search bar
[factor.git] / vm / bump_allocator.hpp
index 8f4fabe9a727c634cfeeb923bda039b0a9e34ff1..28aa527fd49104f8faff3f0bcb7bccc84ab9fabd 100644 (file)
@@ -1,27 +1,38 @@
-namespace factor
-{
-
-template<typename Block> struct bump_allocator {
-       /* offset of 'here' and 'end' is hardcoded in compiler backends */
-       cell here;
-       cell start;
-       cell end;
-       cell size;
-
-       explicit bump_allocator(cell size_, cell start_) :
-               here(start_), start(start_), end(start_ + size_), size(size_) {}
-
-       inline bool contains_p(Block *block)
-       {
-               return ((cell)block - start) < size;
-       }
-
-       inline Block *allot(cell size)
-       {
-               cell h = here;
-               here = h + align(size,data_alignment);
-               return (Block *)h;
-       }
+namespace factor {
+
+struct bump_allocator {
+  // offset of 'here' and 'end' is hardcoded in compiler backends
+  cell here;
+  cell start;
+  cell end;
+  cell size;
+
+  bump_allocator(cell size, cell start)
+      : here(start), start(start), end(start + size), size(size) {}
+
+  bool contains_p(object* obj) {
+    return (cell)obj >= start && (cell)obj < end;
+  }
+
+  object* allot(cell size) {
+    cell h = here;
+    here = h + align(size, data_alignment);
+    return (object*)h;
+  }
+
+  cell occupied_space() { return here - start; }
+
+  cell free_space() { return end - here; }
+
+  void flush() {
+    here = start;
+#ifdef FACTOR_DEBUG
+    // In case of bugs, there may be bogus references pointing to the
+    // memory space after the gc has run. Filling it with a pattern
+    // makes accesses to such shadow data fail hard.
+    memset_cell((void*)start, 0xbaadbaad, size);
+#endif
+  }
 };
 
 }