diff --git a/src/job.c b/src/job.c index 587b0b4..ae30d4a 100644 --- a/src/job.c +++ b/src/job.c @@ -59,7 +59,7 @@ __attribute__((noreturn)) static void run_vm(void) { static void *job_start_(const uint32_t entry_point) { term_kprint("allocate new stack..."); - static const int job_stack_size = 64 * 1024; // 64 kiB stack + static const int job_stack_size = 48 * 1024; // 48 kiB stack const uint32_t child_stack = (uint32_t)kmalloc(job_stack_size, NULL); const uint32_t new_sp = ((child_stack + 3) >> 2 << 2) + ((job_stack_size + 3) >> 2 << 2); term_kprintf("new_bp=0x%08x", child_stack); @@ -102,6 +102,8 @@ void job_resume(int job_id) { wrenResume(job_vms[job_id]); // longjmp(vm->ctxbuf, 1); } +void job_GC(int job_id) { wrenCollectGarbage(job_vms[job_id]); } + void job_free(int job_id) { // just in case something failed if (job_vms[job_id] != NULL) { diff --git a/src/job.h b/src/job.h index 35982a1..c985079 100644 --- a/src/job.h +++ b/src/job.h @@ -11,6 +11,7 @@ extern void *job_stacks[UNS_MAX_JOBS]; extern int current_job_id; int job_start(const char *name, const char *source); +void job_GC(int job_id); void job_resume(int job_id); void job_free(int job_id); diff --git a/src/main.c b/src/main.c index 0d464f1..1c1c4ec 100644 --- a/src/main.c +++ b/src/main.c @@ -124,6 +124,16 @@ int main(int isappli, int optnum) { "}\n" "System.print(\"inner end\")\n"); + job_start("test_job_3", "System.print(\"inner start\")\n" + "var i = 0\n" + "while (i < 30000) {\n" + " if ((i % 500) == 0) {\n" + " System.write(\"vm 3: i=%(i)\\n\")\n" + " }\n" + " i = i + 1\n" + "}\n" + "System.print(\"inner end\")\n"); + while (1) { // system routine @@ -165,6 +175,7 @@ int main(int isappli, int optnum) { must_yield = 0; job_resume(current_job_id); } else if (ret == 1) { + job_GC(current_job_id); // term_kprintf("job(%d) yield", current_job_id); continue; } else if (ret == 2) {