[Oberon] PO2013 - Show Heap Blocks

Tomas Kral thomas.kral at email.cz
Wed Jun 17 12:33:46 CEST 2020


Hi,

Started inspecting the heap.

My colour map ends at -128. So instead of exporting list{0..3}, I use next 4 addresses
to record values in Kernel.New(). Requires new inner core build, but
does not change the Kernel interface.

Perhaps this is all not necessary, but I was so curious about what
values lists can get.

Now I am coding this, which really borrows from Kernel.Scan().
Each run shows different values for list{0..3}, sometimes valid address, sometimes NIL(0).
That came as a surprise.

Code is not right so is my understanding so far.

Next surprise peeking 60000H heapOrg, shows first tag, peeking tag shows size 14H.
Provided tag is valid, can we really get sizes <32, <64, <128, <256 of heap byte blocks?  
 
MODULE Heap; (*TK 14.6.2020 show heap blocks*)
  IMPORT S := SYSTEM, Out;

  VAR heapOrg, MemLim, heapLim: INTEGER;
    list0, list1, list2, list3: INTEGER;

  PROCEDURE Show*;
    VAR p, q, mark, tag, size: LONGINT;
  BEGIN p := heapOrg;
    Out.String("heapOrg: "); Out.Hex(p); Out.Ln;
    S.GET(-132, list0); S.GET(-136, list1); S.GET(-140, list2); S.GET(-144, list3);
    Out.Hex(list3); Out.Hex(list2); Out.Hex(list1); Out.Hex(list0); Out.Ln;
    
    REPEAT S.GET(p+4, mark); q := p; (*mark: 0 block used, -1 block freed, >0 to be freed ????*)
      S.GET(p, tag); S.GET(tag, size); INC(p, size);
      size := p - q; (*size of [free] block*)
      IF size > 0 THEN
        IF size MOD 64 # 0 THEN
          INC(q, 32); DEC(size, 32);
          Out.String("32: "); Out.Hex(q); Out.Ln
        END ;
        IF size MOD 128 # 0 THEN
          INC(q, 64); DEC(size, 64);
          Out.String("64: "); Out.Hex(q); Out.Ln
        END ;
        IF size MOD 256 # 0 THEN
          INC(q, 128); DEC(size, 128);
          Out.String("128: "); Out.Hex(q); Out.Ln
        END ;
        IF size > 0 THEN
          INC(q, size);
          Out.String("256: "); Out.Hex(q); Out.Ln
        END
      END ;
      IF mark > 0 THEN S.GET(p, tag); S.GET(tag, size); INC(p, size)
      ELSE (*free*) S.GET(p, size); INC(p, size)
      END
    UNTIL p >= heapLim ;
  END Show;

BEGIN S.GET(12, MemLim); S.GET(24, heapOrg); heapLim := MemLim
END Heap.

Heap.Show

-- 
Tomas Kral <thomas.kral at email.cz>


More information about the Oberon mailing list