[m-dev.] For review: Add implementation of reference types (global heap)
Warwick Harvey
wharvey at cs.monash.edu.au
Mon Jun 8 16:07:54 AEST 1998
Peter Schachte wrote:
> Maybe this zone should only be created on demand. Perhaps set
> global_heap_zone = NULL, and put something like
>
> if (global_heap_zone == NULL) {
> global_heap_zone = create_zone("global_heap", 1, global_heap_size,
> next_offset(), global_heap_zone_size, default_handler);
> global_hp = global_heap_zone->min;
> }
>
> in the code for making permanent copies. I guess it depends on the
> cost of allocating a big chunk of memory you'll never need vs. the
> cost of an extra test for every permanent copy.
Indeed: which is the better trade-off? I have no idea. Or is there some
better way to handle this?
> > :- pragma inline(new_nb_reference/2).
> > :- pragma c_code(new_nb_reference(X::in, Ref::out), will_not_call_mercury, "
> > incr_hp(Ref, 1);
> > save_transient_registers();
> > *(Word *)Ref = MR_make_partially_permanent(X, (Word *) TypeInfo_for_T,
> > (Word *) Ref);
> > restore_transient_registers();
> > ").
>
> Are the save_ and restore_transient_registers(); calls really
> necessary here?
YES!
It took me a while to find this bug in your code. ;-) I'm sure it worked
fine on whatever architecture you were using to develop it, but on the SPARC
I'm using, it's very definitely necessary: the heap pointer gets clobbered
whenever a C function is called.
Warwick
More information about the developers
mailing list