[M3devel] small bug report

mika at async.caltech.edu mika at async.caltech.edu
Sat Jul 26 13:20:48 CEST 2014

Hi m3devel,

So I realized that the reason my program runs slowly is not that there
are a lot of range checks, etc.

(BTW, changing M3_FRONT_FLAGS in cm3.cfg did manage to turn off these
checks as far as I can see, thanks!)

The problem is that the garbage collector involves procedure calls
whenever loading references.  This is no good if you are running a tight
inner loop that chases pointers all over the heap.

My attempt at fixing this is to change the code to use UNTRACED REF for this
particular chunk, with DISPOSE.  It's a small, simple part of the code, so this
is a good use case for the UNSAFE Modula-3 features.

I found a bug, though:


    id   : Elem;

    np : CARDINAL := 0;
    pred : UNTRACED REF ARRAY OF Node; 

    ns : CARDINAL := 0; 
    succ : UNTRACED REF ARRAY OF Node;

    when : TStamp;    (* max of all fanins observed *)
    whch : Node;      (* which fanin was critical   *)

    gen  : CARDINAL := 0; (* generation of cnt *)
    cnt  : CARDINAL;  (* how many fanins are left   *)


      nd := NEW(Node, 
                 id := el, 
                 pred := NEW(UNTRACED REF ARRAY OF Node, 1),
                 succ := NEW(UNTRACED REF ARRAY OF Node, 1),
                 sDly := NEW(UNTRACED REF ARRAY OF TStamp, 1),
                 cnt := 0);
      <*ASSERT nd.ns = 0 *>

That ASSERT fails.

The code works on PM3 (FreeBSD4), as expected.  (It works fine with
everything being traced, and I haven't changed any code at all, no DISPOSE
yet, so there "can't" be a bug in my code, at least not an unsafe one.)

Basically I think the implied initializers (from the :=... in the type definition)
aren't being run for UNTRACED ROOT OBJECTs.


More information about the M3devel mailing list