diff options
author | Chris Lattner <sabre@nondot.org> | 2004-05-23 21:25:45 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-05-23 21:25:45 +0000 |
commit | 77ac7baa6d6ae11705d0a44a691fc255d840341a (patch) | |
tree | aee6dfdf04cfdae5df33600f7c1bde98b0b220b1 /runtime | |
parent | 4cb1f3c10d6de2733099cd04a0a11b44b70c67b1 (diff) | |
download | external_llvm-77ac7baa6d6ae11705d0a44a691fc255d840341a.zip external_llvm-77ac7baa6d6ae11705d0a44a691fc255d840341a.tar.gz external_llvm-77ac7baa6d6ae11705d0a44a691fc255d840341a.tar.bz2 |
Check in an EARLY START on a simple copying collector
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13698 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/GC/SemiSpace/Makefile | 19 | ||||
-rw-r--r-- | runtime/GC/SemiSpace/semispace.c | 98 |
2 files changed, 117 insertions, 0 deletions
diff --git a/runtime/GC/SemiSpace/Makefile b/runtime/GC/SemiSpace/Makefile new file mode 100644 index 0000000..2b5af6e --- /dev/null +++ b/runtime/GC/SemiSpace/Makefile @@ -0,0 +1,19 @@ +##===- runtime/GC/SemiSpace/Makefile -----------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file was developed by the LLVM research group and is distributed under +# the University of Illinois Open Source License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../../.. +BYTECODE_LIBRARY=1 +#SHARED_LIBRARY=1 +#DONT_BUILD_RELINKED=1 +LIBRARYNAME=gcsemispace + +EXPORTED_SYMBOL_FILE = $(SourceDir)/../gc_exported_symbols.lst + +include $(LEVEL)/Makefile.common + diff --git a/runtime/GC/SemiSpace/semispace.c b/runtime/GC/SemiSpace/semispace.c new file mode 100644 index 0000000..3792f86 --- /dev/null +++ b/runtime/GC/SemiSpace/semispace.c @@ -0,0 +1,98 @@ +/*===-- semispace.c - Simple semi-space copying garbage collector ---------===*\ +|* +|* The LLVM Compiler Infrastructure +|* +|* This file was developed by the LLVM research group and is distributed under +|* the University of Illinois Open Source License. See LICENSE.TXT for details. +|* +|*===----------------------------------------------------------------------===*| +|* +|* This garbage collector is an extremely simple copying collector. It splits +|* the managed region of memory into two pieces: the current space to allocate +|* from, and the copying space. When the portion being allocated from fills up, +|* a garbage collection cycle happens, which copies all live blocks to the other +|* half of the managed space. +|* +\*===----------------------------------------------------------------------===*/ + +#include "../GCInterface.h" +#include <stdio.h> +#include <stdlib.h> + +/* FIXME: This should be in a code-generator specific library! + */ +typedef struct GCRoot { + void **RootPtr; + void *Meta; +} GCRoot; + +typedef struct GCRoots { + struct GCRoots *Next; + unsigned NumRoots; + GCRoot RootRecords[]; +} GCRoots; +GCRoots *llvm_gc_root_chain; + +static void llvm_cg_walk_gcroots(void (*FP)(void **Root, void *Meta)) { + GCRoots *R = llvm_gc_root_chain; + for (; R; R = R->Next) { + unsigned i, e; + for (i = 0, e = R->NumRoots; i != e; ++i) + FP(R->RootRecords[i].RootPtr, R->RootRecords[i].Meta); + } +} +/* END FIXME! */ + + + +/* We use no read/write barriers */ +void *llvm_gc_read(void **P) { return *P; } +void llvm_gc_write(void *V, void **P) { *P = V; } + + +/* AllocPtr - This points to the next byte that is available for allocation. + */ +static char *AllocPtr; + +/* AllocEnd - This points to the first byte not available for allocation. When + * AllocPtr passes this, we have run out of space. + */ +static char *AllocEnd; + +void llvm_gc_initialize() { + AllocPtr = calloc(1, 1000); + AllocEnd = AllocPtr + 1000; +} + +/* We always want to inline the fast path, but never want to inline the slow + * path. + */ +void *llvm_gc_allocate(unsigned Size) __attribute__((always_inline)); +static void* llvm_gc_alloc_slow(unsigned Size) __attribute__((noinline)); + +void *llvm_gc_allocate(unsigned Size) { + char *OldAP = AllocPtr; + char *NewEnd = OldAP+Size; + if (NewEnd > AllocEnd) + return llvm_gc_alloc_slow(Size); + AllocPtr = NewEnd; + return OldAP; +} + +static void* llvm_gc_alloc_slow(unsigned Size) { + llvm_gc_collect(); + return llvm_gc_allocate(Size); +} + + +static void process_root(void **Root, void *Meta) { + printf("process_root[0x%X] = 0x%X\n", Root, *Root); +} + +void llvm_gc_collect() { + printf("Garbage collecting!!\n"); + llvm_cg_walk_gcroots(process_root); + abort(); + + /* TODO: Iterate through roots. */ +} |