Skip to content

Commit f5a5091

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 344d133 + d7503bd commit f5a5091

File tree

11 files changed

+33
-30
lines changed

11 files changed

+33
-30
lines changed

cmake/RuntimeConfig.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(GC_THRESHOLD 2097152
1+
set(GC_THRESHOLD 3
22
CACHE STRING "Initial Young Generation Size")
33

44
set(NOT_YOUNG_OBJECT_BIT 0x10000000000000)

config/llvm_header.inc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,6 @@ declare void @write_configuration_to_proof_trace(ptr, ptr)
204204
205205
@gc_roots = global [256 x ptr] zeroinitializer
206206
207-
define void @set_gc_threshold(i64 %threshold) {
208-
store i64 %threshold, ptr @GC_THRESHOLD
209-
ret void
210-
}
211-
212207
define i64 @get_gc_threshold() {
213208
%threshold = load i64, ptr @GC_THRESHOLD
214209
ret i64 %threshold

include/runtime/arena.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ using memory_block_header = struct {
3535
#define MEM_BLOCK_START(ptr) \
3636
((char *)(((uintptr_t)(ptr)-1) & ~(BLOCK_SIZE - 1)))
3737

38+
extern bool time_for_collection;
39+
40+
size_t get_gc_threshold();
41+
3842
// Resets the given arena.
3943
void arena_reset(struct arena *);
4044

lib/codegen/Decision.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,12 +1003,11 @@ std::pair<std::vector<llvm::Value *>, llvm::BasicBlock *> step_function_header(
10031003
module->getContext(), "checkCollect", block->getParent());
10041004
llvm::BranchInst::Create(stuck, check_collect, is_finished, block);
10051005

1006-
auto *collection = get_or_insert_function(
1007-
module, "is_collection",
1008-
llvm::FunctionType::get(
1009-
llvm::Type::getInt1Ty(module->getContext()), {}, false));
1010-
auto *is_collection
1011-
= llvm::CallInst::Create(collection, {}, "", check_collect);
1006+
auto *collection = module->getOrInsertGlobal(
1007+
"time_for_collection", llvm::Type::getInt1Ty(module->getContext()));
1008+
auto *is_collection = new llvm::LoadInst(
1009+
llvm::Type::getInt1Ty(module->getContext()), collection, "is_collection",
1010+
check_collect);
10121011
set_debug_loc(is_collection);
10131012
auto *collect = llvm::BasicBlock::Create(
10141013
module->getContext(), "isCollect", block->getParent());

runtime/alloc/arena.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ static void *megabyte_malloc() {
7676
return result;
7777
}
7878

79+
bool time_for_collection;
80+
7981
static void fresh_block(struct arena *arena) {
8082
char *next_block = nullptr;
8183
if (arena->block_start == nullptr) {
@@ -106,8 +108,12 @@ static void fresh_block(struct arena *arena) {
106108
next_header->next_block = nullptr;
107109
next_header->semispace = arena->allocation_semispace_id;
108110
arena->num_blocks++;
111+
time_for_collection = true;
109112
}
110113
}
114+
if (!*(char **)next_block && arena->num_blocks >= get_gc_threshold()) {
115+
time_for_collection = true;
116+
}
111117
arena->block = next_block + sizeof(memory_block_header);
112118
arena->block_start = next_block;
113119
arena->block_end = next_block + BLOCK_SIZE;

runtime/collect/collect.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ static char *last_alloc_ptr;
2525
#endif
2626

2727
size_t numBytesLiveAtCollection[1 << AGE_WIDTH];
28-
void set_gc_threshold(size_t);
29-
size_t get_gc_threshold(void);
30-
bool youngspace_almost_full(size_t);
3128

3229
bool during_gc() {
3330
return is_gc;
@@ -285,6 +282,7 @@ void init_static_objects(void) {
285282

286283
void kore_collect(void **roots, uint8_t nroots, layoutitem *type_info) {
287284
is_gc = true;
285+
time_for_collection = false;
288286
collect_old = should_collect_old_gen();
289287
MEM_LOG("Starting garbage collection\n");
290288
#ifdef GC_DBG
@@ -349,16 +347,10 @@ void kore_collect(void **roots, uint8_t nroots, layoutitem *type_info) {
349347
#endif
350348
MEM_LOG("Finishing garbage collection\n");
351349
is_gc = false;
352-
set_gc_threshold(youngspace_size());
353350
}
354351

355352
void free_all_kore_mem() {
356353
kore_collect(nullptr, 0, nullptr);
357354
kore_clear();
358355
}
359-
360-
bool is_collection() {
361-
size_t threshold = get_gc_threshold();
362-
return youngspace_almost_full(threshold);
363-
}
364356
}

runtime/lto/alloc.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,7 @@ size_t youngspace_size(void) {
4545

4646
bool youngspace_almost_full(size_t threshold) {
4747
char *next_block = *(char **)youngspace.block_start;
48-
if (next_block) {
49-
// not on the last block, so short circuit and assume that we can keep
50-
// allocating for now.
51-
return false;
52-
}
53-
ptrdiff_t free_bytes = youngspace.block_end - youngspace.block;
54-
size_t total_bytes
55-
= youngspace.num_blocks * (BLOCK_SIZE - sizeof(memory_block_header));
56-
return (total_bytes - free_bytes) * 100 > threshold * 95;
48+
return !next_block;
5749
}
5850

5951
void kore_alloc_swap(bool swap_old) {

unittests/runtime-collections/lists.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ block *DUMMY1 = &D1;
6464
}
6565

6666
bool gc_enabled;
67+
size_t get_gc_threshold() {
68+
return SIZE_MAX;
69+
}
6770

6871
BOOST_AUTO_TEST_SUITE(ListTest)
6972

unittests/runtime-ffi/ffi.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ bool during_gc() {
8282
return false;
8383
}
8484

85+
size_t get_gc_threshold() {
86+
return SIZE_MAX;
87+
}
88+
8589
void print_configuration_internal(
8690
writer *file, block *subject, char const *sort, bool, void *) { }
8791
void sfprintf(writer *, char const *, ...) { }

unittests/runtime-io/io.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ bool during_gc() {
6060

6161
void add_hash64(void *, uint64_t) { }
6262

63+
size_t get_gc_threshold() {
64+
return SIZE_MAX;
65+
}
66+
6367
void flush_io_logs();
6468
string *make_string(const KCHAR *, int64_t len = -1);
6569
blockheader header_err();

unittests/runtime-strings/stringtest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ floating *move_float(floating *i) {
6868

6969
void add_hash64(void *, uint64_t) { }
7070

71+
size_t get_gc_threshold() {
72+
return SIZE_MAX;
73+
}
74+
7175
struct blockheader get_block_header_for_symbol(uint32_t tag) {
7276
return blockheader{tag};
7377
}

0 commit comments

Comments
 (0)