llvm.org GIT mirror llvm / 6da385e
Drop toy GC runtime. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65801 91177308-0d34-0410-b5e6-96231b3b80d8 Gordon Henriksen 11 years ago
7 changed file(s) with 1 addition(s) and 226 deletion(s). Raw diff Collapse all Expand all
+0
-48
runtime/GC/GCInterface.h less more
None /*===-- GCInterface.h - Public interface exposed by garbage collectors ----===*\
1 |*
2 |* The LLVM Compiler Infrastructure
3 |*
4 |* This file is distributed under the University of Illinois Open Source
5 |* License. See LICENSE.TXT for details.
6 |*
7 |*===----------------------------------------------------------------------===*|
8 |*
9 |* This file defines the common public interface that must be exposed by all
10 |* LLVM garbage collectors.
11 |*
12 \*===----------------------------------------------------------------------===*/
13
14 #ifndef GCINTERFACE_H
15 #define GCINTERFACE_H
16
17 /* llvm_cg_walk_gcroots - This function is exposed by the LLVM code generator,
18 * and allows us to traverse the roots on the stack.
19 */
20 void llvm_cg_walk_gcroots(void (*FP)(void **Root, void *Meta));
21
22
23 /* llvm_gc_initialize - This function is called to initalize the garbage
24 * collector.
25 */
26 void llvm_gc_initialize(unsigned InitialHeapSize);
27
28 /* llvm_gc_allocate - This function allocates Size bytes from the heap and
29 * returns a pointer to it.
30 */
31 void *llvm_gc_allocate(unsigned Size);
32
33 /* llvm_gc_collect - This function forces a garbage collection cycle.
34 */
35 void llvm_gc_collect();
36
37 /* llvm_gc_read - This function should be implemented to include any read
38 * barrier code that is needed by the garbage collector.
39 */
40 void *llvm_gc_read(void *ObjPtr, void **FieldPtr);
41
42 /* llvm_gc_write - This function should be implemented to include any write
43 * barrier code that is needed by the garbage collector.
44 */
45 void llvm_gc_write(void *V, void *ObjPtr, void **FieldPtr);
46
47 #endif
+0
-19
runtime/GC/Makefile less more
None ##===- runtime/GC/Makefile ---------------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../..
10 PARALLEL_DIRS := SemiSpace
11 EXTRA_DIST := gc_exported_symbols.lst
12 include $(LEVEL)/Makefile.common
13
14 # Install target for libraries: Copy into $LLVMGCCDIR/bytecode-libs
15 #
16 install::
17
18 clean::
+0
-19
runtime/GC/SemiSpace/Makefile less more
None ##===- runtime/GC/SemiSpace/Makefile -----------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../..
10 BYTECODE_LIBRARY = 1
11 LIBRARYNAME = gcsemispace
12 BYTECODE_DESTINATION = $(CFERuntimeLibDir)
13 EXPORTED_SYMBOL_FILE = $(PROJ_SRC_DIR)/../gc_exported_symbols.lst
14
15 include $(LEVEL)/Makefile.common
16
17 CompileCommonOpts := $(filter-out -pedantic,$(CompileCommonOpts))
18 CompileCommonOpts := $(filter-out -Wno-long-long,$(CompileCommonOpts))
+0
-5
runtime/GC/SemiSpace/README.txt less more
None //===----------------------------------------------------------------------===//
1
2 Possible enhancement: If a collection cycle happens and the heap is not
3 compacted very much (say less than 25% of the allocated memory was freed), the
4 memory regions should be doubled in size.
+0
-127
runtime/GC/SemiSpace/semispace.c less more
None /*===-- semispace.c - Simple semi-space copying garbage collector ---------===*\
1 |*
2 |* The LLVM Compiler Infrastructure
3 |*
4 |* This file is distributed under the University of Illinois Open Source
5 |* License. See LICENSE.TXT for details.
6 |*
7 |*===----------------------------------------------------------------------===*|
8 |*
9 |* This garbage collector is an extremely simple copying collector. It splits
10 |* the managed region of memory into two pieces: the current space to allocate
11 |* from, and the copying space. When the portion being allocated from fills up,
12 |* a garbage collection cycle happens, which copies all live blocks to the other
13 |* half of the managed space.
14 |*
15 \*===----------------------------------------------------------------------===*/
16
17 #include "../GCInterface.h"
18 #include
19 #include
20 #include
21
22 /* AllocPtr - This points to the next byte that is available for allocation.
23 */
24 static char *AllocPtr;
25
26 /* AllocEnd - This points to the first byte not available for allocation. When
27 * AllocPtr passes this, we have run out of space.
28 */
29 static char *AllocEnd;
30
31 /* CurSpace/OtherSpace - These pointers point to the two regions of memory that
32 * we switch between. The unallocated portion of the CurSpace is known to be
33 * zero'd out, but the OtherSpace contains junk.
34 */
35 static void *CurSpace, *OtherSpace;
36
37 /* SpaceSize - The size of each space. */
38 static unsigned SpaceSize;
39
40 /* llvm_gc_initialize - Allocate the two spaces that we plan to switch between.
41 */
42 void llvm_gc_initialize(unsigned InitialHeapSize) {
43 SpaceSize = InitialHeapSize/2;
44 CurSpace = AllocPtr = calloc(1, SpaceSize);
45 OtherSpace = malloc(SpaceSize);
46 AllocEnd = AllocPtr + SpaceSize;
47 }
48
49 /* We always want to inline the fast path, but never want to inline the slow
50 * path.
51 */
52 void *llvm_gc_allocate(unsigned Size) __attribute__((always_inline));
53 static void* llvm_gc_alloc_slow(unsigned Size) __attribute__((noinline));
54
55 void *llvm_gc_allocate(unsigned Size) {
56 char *OldAP = AllocPtr;
57 char *NewEnd = OldAP+Size;
58 if (NewEnd > AllocEnd)
59 return llvm_gc_alloc_slow(Size);
60 AllocPtr = NewEnd;
61 return OldAP;
62 }
63
64 static void* llvm_gc_alloc_slow(unsigned Size) {
65 llvm_gc_collect();
66 if (AllocPtr+Size > AllocEnd) {
67 fprintf(stderr, "Garbage collector ran out of memory "
68 "allocating object of size: %d\n", Size);
69 exit(1);
70 }
71
72 return llvm_gc_allocate(Size);
73 }
74
75
76 static void process_pointer(void **Root, void *Meta) {
77 printf("process_root[0x%p] = 0x%p\n", (void*) Root, (void*) *Root);
78 }
79
80 void llvm_gc_collect() {
81 // Clear out the space we will be copying into.
82 // FIXME: This should do the copy, then clear out whatever space is left.
83 memset(OtherSpace, 0, SpaceSize);
84
85 printf("Garbage collecting!!\n");
86 llvm_cg_walk_gcroots(process_pointer);
87 abort();
88 }
89
90 /* We use no read/write barriers */
91 void *llvm_gc_read(void *ObjPtr, void **FieldPtr) { return *FieldPtr; }
92 void llvm_gc_write(void *V, void *ObjPtr, void **FieldPtr) { *FieldPtr = V; }
93
94
95 /*===----------------------------------------------------------------------===**
96 * FIXME: This should be in a code-generator specific library, but for now this
97 * will work for all code generators.
98 */
99 typedef struct FrameMap FrameMap;
100 struct FrameMap {
101 int32_t NumRoots; // Number of roots in stack frame.
102 int32_t NumMeta; // Number of metadata descriptors. May be < NumRoots.
103 void *Meta[]; // May be absent for roots without metadata.
104 };
105
106 typedef struct StackEntry StackEntry;
107 struct StackEntry {
108 StackEntry *Next; // Caller's stack entry.
109 const FrameMap *Map; // Pointer to constant FrameMap.
110 void *Roots[]; // Stack roots (in-place array).
111 };
112 StackEntry *llvm_gc_root_chain;
113
114 void llvm_cg_walk_gcroots(void (*FP)(void **Root, void *Meta)) {
115 StackEntry *R;
116 for (R = llvm_gc_root_chain; R; R = R->Next) {
117 unsigned i, e;
118 for (i = 0, e = R->Map->NumMeta; i != e; ++i)
119 FP(&R->Roots[i], R->Map->Meta[i]);
120 for (e = R->Map->NumRoots; i != e; ++i)
121 FP(&R->Roots[i], NULL);
122 }
123 }
124 /* END FIXME! */
125
126
+0
-7
runtime/GC/gc_exported_symbols.lst less more
None llvm_gc_initialize
1 llvm_gc_allocate
2 llvm_gc_collect
3 llvm_gc_write
4 llvm_gc_read
5
6 llvm_gc_root_chain
1010 include $(LEVEL)/Makefile.config
1111
1212 ifneq ($(wildcard $(LLVMGCC)),)
13 PARALLEL_DIRS := libprofile GC
13 PARALLEL_DIRS := libprofile
1414 else
1515 PARALLEL_DIRS :=
1616 install all ::