try to reduce memory (heap) usage

This commit is contained in:
Babz 2021-09-15 18:59:59 +02:00
parent b55464fa71
commit e64e294168
3 changed files with 15 additions and 1 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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) {