rt_private EIF_INTEGER private_object_id(EIF_REFERENCE object, struct stack *st, EIF_INTEGER *max_value_ptr) { register unsigned int stack_number = 0; register struct stchunk *end; register EIF_INTEGER Result; char *address; if (-1 == epush(st, object)) { /* Cannot record object */ eraise("object id", EN_MEM); /* No more memory */ return (EIF_INTEGER) 0; /* They ignored it */ } address = (char *) (st->st_top - 1); /* Was allocated here */ eif_access(address) = object; /* Record object's physical address */ /* Get the stack number */ for(end = st->st_hd; end != st->st_cur; stack_number++) end = end->sk_next; Result = (EIF_INTEGER) (stack_number*STACK_SIZE+1-(st->st_cur->sk_arena-(char **)address)); if (Result>*max_value_ptr) *max_value_ptr = Result; #ifdef DEBUG dprintf (2) ("eif_object_id %d %lx %lx\n", Result, address, object); #endif return Result; }
rt_public main(void) { /* Tests for the local variable stack */ int i; char *a1, *a2; printf("> Starting tests for local variable stack.\n"); /* Check the stack */ printf(">> Checking the stack management routines.\n"); printf(">>> Pushing one item.\n"); epush(&loc_stack, (char *) 0); stack_stats(); printf(">>> Poping the stack.\n"); epop(&loc_stack, 1); stack_stats(); /* With 10000 items */ printf(">>> Pushing 20000 items.\n"); for (i = 0; i < 20000; i++) evpush(1, &i); stack_stats(); printf(">>> Poping one item.\n"); epop(&loc_stack, 1); stack_stats(); printf(">>> Poping 9999 items.\n"); epop(&loc_stack, 9999); stack_stats(); printf(">>> Poping 10000 items (stack should be empty).\n"); epop(&loc_stack, 10000); stack_stats(); /* Test collection of local vars */ printf(">> Testing collection of local vars.\n"); printf(">>> Creating object A (remembered)\n"); a1 = emalloc(0); eremb(a1); printf(">>> Creating object B (not remembered)\n"); a2 = emalloc(0); printf(">>> Pushing A and B in local stack.\n"); evpush(2, &a1, &a2); stack_stats(); collect_stats(); printf(">>>> Address of A: 0x%lx\n", a1); printf(">>>> Address of B: 0x%lx\n", a2); printf(">>> Running a full collection.\n"); plsc(); stack_stats(); collect_stats(); printf(">>>> Address of A: 0x%lx (changed)\n", a1); printf(">>>> Address of B: 0x%lx (changed)\n", a2); printf(">>> Running a full collection again.\n"); plsc(); stack_stats(); collect_stats(); printf(">>>> Address of A: 0x%lx (same as first one)\n", a1); printf(">>>> Address of B: 0x%lx (same as first one)\n", a2); printf("> End of tests.\n"); exit(0); }
/* Push client `c' on the request chain stack `stk' without notifying SCOOP mananger. */ rt_public void eif_request_chain_push (EIF_REFERENCE c, struct stack * stk) { epush (stk, c); }