on master help sign in
Merge pull request #241 from fmap/master
17fb34aEdwin Brady
rts/idris_gc.c+1−3
@@ -101,9 +101,7 @@ void idris_gc(VM* vm) {
101 for(root = vm->inbox_ptr; root < vm->inbox_write; ++root) {
101 for(root = vm->inbox_ptr; root < vm->inbox_write; ++root) {
102 *root = copy(vm, *root);
102 *root = copy(vm, *root);
103 }
103 }
104− for(root = vm->argv; root < vm->argv + vm->argc; ++root) {
104+
105− *root = copy(vm, *root);
106− }
107 vm->ret = copy(vm, vm->ret);
105 vm->ret = copy(vm, vm->ret);
108 vm->reg1 = copy(vm, vm->reg1);
106 vm->reg1 = copy(vm, vm->reg1);
109
107
rts/idris_rts.c+2−18
@@ -20,16 +20,10 @@ VM* init_vm(int stack_size, size_t heap_size,
20 STATS_ENTER_INIT(vm->stats)
20 STATS_ENTER_INIT(vm->stats)
21
21
22 VAL* valstack = malloc(stack_size * sizeof(VAL));
22 VAL* valstack = malloc(stack_size * sizeof(VAL));
23− int* intstack = malloc(stack_size * sizeof(int));
24− double* floatstack = malloc(stack_size*sizeof(double));
25
23
26 vm->valstack = valstack;
24 vm->valstack = valstack;
27 vm->valstack_top = valstack;
25 vm->valstack_top = valstack;
28 vm->valstack_base = valstack;
26 vm->valstack_base = valstack;
29− vm->intstack = intstack;
30− vm->intstack_ptr = intstack;
31− vm->floatstack = floatstack;
32− vm->floatstack_ptr = floatstack;
33 vm->stack_max = valstack + stack_size;
27 vm->stack_max = valstack + stack_size;
34
28
35 alloc_heap(&(vm->heap), heap_size);
29 alloc_heap(&(vm->heap), heap_size);
@@ -51,15 +45,9 @@ VM* init_vm(int stack_size, size_t heap_size,
51 vm->max_threads = max_threads;
45 vm->max_threads = max_threads;
52 vm->processes = 0;
46 vm->processes = 0;
53
47
54− int i;
48+ vm->argv = argv;
55− // Assumption: there's enough space for this in the initial heap.
56− vm->argv = malloc(argc*sizeof(VAL));
57 vm->argc = argc;
49 vm->argc = argc;
58
50
59− for(i = 0; i < argc; ++i) {
60− vm->argv[i] = MKSTR(vm, argv[i]);
61− }
62−
63 STATS_LEAVE_INIT(vm->stats)
51 STATS_LEAVE_INIT(vm->stats)
64 return vm;
52 return vm;
65}
53}
@@ -70,10 +58,7 @@ Stats terminate(VM* vm) {
70
58
71 free(vm->inbox);
59 free(vm->inbox);
72 free(vm->valstack);
60 free(vm->valstack);
73− free(vm->intstack);
74− free(vm->floatstack);
75 free_heap(&(vm->heap));
61 free_heap(&(vm->heap));
76− free(vm->argv);
77
62
78 pthread_mutex_destroy(&(vm -> inbox_lock));
63 pthread_mutex_destroy(&(vm -> inbox_lock));
79 pthread_mutex_destroy(&(vm -> inbox_block));
64 pthread_mutex_destroy(&(vm -> inbox_block));
@@ -592,11 +577,10 @@ int idris_numArgs(VM* vm) {
592}
577}
593
578
594VAL idris_getArg(VM* vm, int i) {
579VAL idris_getArg(VM* vm, int i) {
595− return vm->argv[i];
580+ return MKSTR(vm, vm->argv[i]);
596}
581}
597
582
598void stackOverflow() {
583void stackOverflow() {
599 fprintf(stderr, "Stack overflow");
584 fprintf(stderr, "Stack overflow");
600 exit(-1);
585 exit(-1);
601}
586}
602−
rts/idris_rts.h+1−5
@@ -44,12 +44,8 @@ typedef struct Closure {
44
44
45typedef struct {
45typedef struct {
46 VAL* valstack;
46 VAL* valstack;
47− int* intstack;
48− double* floatstack;
49 VAL* valstack_top;
47 VAL* valstack_top;
50 VAL* valstack_base;
48 VAL* valstack_base;
51− int* intstack_ptr;
52− double* floatstack_ptr;
53 VAL* stack_max;
49 VAL* stack_max;
54
50
55 Heap heap;
51 Heap heap;
@@ -71,7 +67,7 @@ typedef struct {
71 Stats stats;
67 Stats stats;
72
68
73 int argc;
69 int argc;
74− VAL* argv; // command line arguments
70+ char** argv; // command line arguments
75
71
76 VAL ret;
72 VAL ret;
77 VAL reg1;
73 VAL reg1;
rts/idris_stats.c+19−4
@@ -9,8 +9,23 @@ void print_stats(const Stats * stats) {
9 clock_t total = clock() - stats->start_time;
9 clock_t total = clock() - stats->start_time;
10 clock_t mut = total - stats->init_time - stats->gc_time - stats->exit_time;
10 clock_t mut = total - stats->init_time - stats->gc_time - stats->exit_time;
11 double mut_sec = (double)mut / CLOCKS_PER_SEC;
11 double mut_sec = (double)mut / CLOCKS_PER_SEC;
12+
13+ int avg_chunk = 0;
14+ if (stats->alloc_count > 0) {
12− int avg_chunk = (int)((double)stats->allocations / (double)stats->alloc_count);
15+ avg_chunk = (int)((double)stats->allocations / (double)stats->alloc_count);
16+ }
17+
18+ int alloc_rate = 0;
19+ if (mut > 0) {
13− int alloc_rate = (int)((double)(stats->allocations) / mut_sec);
20+ alloc_rate = (int)((double)(stats->allocations) / mut_sec);
21+ }
22+
23+ double gc_percent = 0.0d;
24+ double productivity = 0.0d;
25+ if (total > 0) {
26+ gc_percent = 100 * (double)stats->gc_time / (double)total;
27+ productivity = 100 * ((double)mut / (double)total);
28+ }
14
29
15 setlocale(LC_NUMERIC, "");
30 setlocale(LC_NUMERIC, "");
16 printf("\n");
31 printf("\n");
@@ -28,11 +43,11 @@ void print_stats(const Stats * stats) {
28 printf("EXIT time: %8.3fs\n", (double)stats->exit_time / CLOCKS_PER_SEC);
43 printf("EXIT time: %8.3fs\n", (double)stats->exit_time / CLOCKS_PER_SEC);
29 printf("TOTAL time: %8.3fs\n\n", (double)total / CLOCKS_PER_SEC);
44 printf("TOTAL time: %8.3fs\n\n", (double)total / CLOCKS_PER_SEC);
30
45
31− printf("%%GC time: %.2f%%\n\n", 100 * (double)stats->gc_time / (double)total);
46+ printf("%%GC time: %.2f%%\n\n", gc_percent);
32
47
33 printf("Alloc rate %'d bytes per MUT sec\n\n", alloc_rate);
48 printf("Alloc rate %'d bytes per MUT sec\n\n", alloc_rate);
34
49
35− printf("Productivity %.2f%%\n", 100 * ((double)mut / (double)total));
50+ printf("Productivity %.2f%%\n", productivity);
36}
51}
37
52
38void aggregate_stats(Stats * stats1, const Stats * stats2) {
53void aggregate_stats(Stats * stats1, const Stats * stats2) {