[Oberon] PO2013 - Show Heap Blocks

Andreas Pirklbauer andreas_pirklbauer at yahoo.com
Tue Jun 16 20:52:55 CEST 2020

   > The idea is to found heap lists origin and then walk through the b-tree. Possible? 

The heap has nothing to do with a B-tree. A B-tree is used for the fiel system

   > I need to be pointed a direction, to get started.

Below is a generic heap scan routine that one may use as a starting point:

  PROCEDURE GenericScan*(typ, ptr: Handler; s: ARRAY OF CHAR; VAR resTyp, resPtr: INTEGER);
    VAR offadr, offset, p, r, mark, tag, size, pos, len, elemsize: INTEGER; continue: BOOLEAN;
  BEGIN p := heapOrg; resTyp := 0; resPtr := 0; continue := (typ # NIL) OR (ptr # NIL);
    REPEAT SYSTEM.GET(p+4, mark);
      IF mark < 0 THEN (*free*) SYSTEM.GET(p, size)
      ELSE (*allocated*) SYSTEM.GET(p, tag);
        IF mark > 0 THEN (*marked*) SYSTEM.PUT(p+4, 0);
          IF continue THEN
            IF typ # NIL THEN INC(resTyp, typ(p, tag, s, continue)) END ;
            IF continue & (ptr # NIL) THEN offadr := tag + 16; SYSTEM.GET(offadr, offset);
              WHILE continue & (offset # -1) DO (*pointers*)
                SYSTEM.GET(p+8+offset, r); INC(resPtr, ptr(p+8+offset, r, s, continue));
                INC(offadr, 4); SYSTEM.GET(offadr, offset)
      END ;
      INC(p, size)
    UNTIL p >= heapLim
  END GenericScan;

It accepts parametric handler procedures ‘typ' and 'ptr’ that are called for each encountered marked heap record as follows:

* Procedure typ is called with the address of (the type tag of) the heap object as the source, followed by the address of the referenced type descriptor as its destination.

* Procedure ptr is called for each pointer variable in the heap object with the address of the pointer variable passed as the source, followed by the address of the referenced object passed as the destination.

First, one hast to call Kernel.Mark(mod.ptr) - for example as in Oberon.GC - and then one can call the generic scan scheme with suitable procedures ‘typ’ and ‘ptr. Note that GenericScan also unmarks all marked heap records, just like the regular scan routine Kernel.Scan.

More information about the Oberon mailing list