Skip to content

Commit ef4efc7

Browse files
it turns out __attribute__((malloc)) made clang apply some GC-breaking optimizations - removed
1 parent 6b9e86c commit ef4efc7

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

src/runtime.h

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// ---------- RUNTIME HEADER ----------
22
#define _GNU_SOURCE
3+
4+
#ifndef __TINYC__
35
#define _FORTIFY_SOURCE 2
6+
#endif
47

58
#include <stddef.h>
69
#include <wchar.h>
@@ -49,7 +52,7 @@ typedef double NUMBER;
4952
typedef const char* restrict STRING;
5053
typedef const struct cognate_list* restrict LIST;
5154
typedef const char* restrict SYMBOL;
52-
typedef struct cognate_file* IO;
55+
typedef struct cognate_file* restrict IO;
5356
typedef const struct cognate_table* restrict TABLE;
5457

5558
typedef struct cognate_block
@@ -384,6 +387,7 @@ int main(int argc, char** argv)
384387
fn0();
385388
cleanup();
386389
}
390+
387391
static void cleanup(void)
388392
{
389393
if unlikely(stack.top != stack.start)
@@ -1086,15 +1090,7 @@ static void gc_init(void)
10861090
bitmap[1][0] = ALLOC;
10871091
}
10881092

1089-
__attribute__((hot))
1090-
static _Bool is_heap_ptr(void* ptr)
1091-
{
1092-
const uint64_t index = (uintptr_t*)ptr - space[!z];
1093-
if (index >= alloc[!z]) return 0;
1094-
return 1;
1095-
}
1096-
1097-
__attribute__((malloc, hot, assume_aligned(sizeof(uint64_t)), alloc_size(1), returns_nonnull))
1093+
__attribute__((noinline, hot, assume_aligned(sizeof(uint64_t)), returns_nonnull))
10981094
static void* gc_malloc(size_t sz)
10991095
{
11001096
static ptrdiff_t interval = 1024l*1024l*10;
@@ -1115,7 +1111,7 @@ static void* gc_malloc(size_t sz)
11151111
return buf;
11161112
}
11171113

1118-
__attribute__((malloc, hot, assume_aligned(sizeof(uint64_t)), alloc_size(1), returns_nonnull))
1114+
__attribute__((noinline, hot, assume_aligned(sizeof(uint64_t)), alloc_size(1), returns_nonnull))
11191115
static void* gc_flatmalloc(size_t sz)
11201116
{
11211117
static ptrdiff_t interval = 1024l*1024l*10;
@@ -1190,6 +1186,24 @@ static void gc_collect_root(uintptr_t* restrict addr)
11901186

11911187
static __attribute__((noinline,hot)) void gc_collect(void)
11921188
{
1189+
1190+
/*
1191+
printf("BEFORE:\n");
1192+
for (int Z = 0 ; Z < 2 ; ++Z)
1193+
{
1194+
for (int i = 0 ; i <= alloc[Z] ; ++i) switch(bitmap[Z][i])
1195+
{
1196+
case EMPTY: fputc('-', stdout); break;
1197+
case ALLOC: fputc('A', stdout); break;
1198+
case FLATALLOC: fputc('a', stdout); break;
1199+
case FORWARD: printf("%zu", (uintptr_t*)space[Z][i] - space[!Z]); break;
1200+
}
1201+
if (Z == z) printf(" (active)");
1202+
fputc('\n', stdout);
1203+
}
1204+
*/
1205+
1206+
11931207
/*
11941208
clock_t start, end;
11951209
double cpu_time_used;
@@ -1216,6 +1230,21 @@ static __attribute__((noinline,hot)) void gc_collect(void)
12161230
printf("%lf seconds for %ziMB -> %ziMB\n", (double)(end - start) / CLOCKS_PER_SEC, heapsz * 8 /1024/1024, alloc[z] * 8 / 1024/1024);
12171231
*/
12181232

1233+
/*
1234+
printf("AFTER:\n");
1235+
for (int Z = 0 ; Z < 2 ; ++Z)
1236+
{
1237+
for (int i = 0 ; i <= alloc[Z] ; ++i) switch(bitmap[Z][i])
1238+
{
1239+
case EMPTY: fputc('-', stdout); break;
1240+
case ALLOC: fputc('A', stdout); break;
1241+
case FLATALLOC: fputc('a', stdout); break;
1242+
case FORWARD: printf("%zu", (uintptr_t*)space[Z][i] - space[!Z]); break;
1243+
}
1244+
if (Z == z) printf(" (active)");
1245+
fputc('\n', stdout);
1246+
}
1247+
*/
12191248
longjmp(a, 1);
12201249
}
12211250

0 commit comments

Comments
 (0)