gc-test.red 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. % GC-TEST.RED - Test of P-COMP-GC Marking primitives
  2. % M. L. Griss, 17 June 1983
  3. % MAcros extracted for file, P-COMP-GC.RED
  4. On Syslisp;
  5. internal WConst GCMarkValue = 8#777,
  6. HSkip = Forward;
  7. CompileTime <<
  8. syslsp smacro procedure Mark X; % Get GC mark bits in item X points to
  9. GCField @X;
  10. syslsp smacro procedure SetMark X; % Set GC mark bits in item X points to
  11. GCField @X := GCMarkValue;
  12. syslsp smacro procedure ClearMark X; % Clear GC mark bits in item X points to
  13. GCField @X := if NegIntP @X then -1 else 0;
  14. syslsp smacro procedure Marked X; % Is item pointed to by X marked?
  15. Mark X eq GCMarkValue;
  16. syslsp smacro procedure MarkID X;
  17. Field(SymNam X, TagStartingBit, TagBitLength) := Forward;
  18. syslsp smacro procedure MarkedID X;
  19. Tag SymNam X eq Forward;
  20. syslsp smacro procedure ClearIDMark X;
  21. Field(SymNam X, TagStartingBit, TagBitLength) := STR;
  22. % Relocation primitives
  23. syslsp smacro procedure SkipLength X; % Stored in heap header
  24. Inf @X;
  25. syslsp smacro procedure PutSkipLength(X, L); % Store in heap header
  26. Inf @X := L;
  27. put('SkipLength, 'Assign!-Op, 'PutSkipLength);
  28. >>;
  29. internal WConst BitsInSegment = 13,
  30. SegmentLength = LShift(1, BitsInSegment),
  31. SegmentMask = SegmentLength - 1;
  32. %/ External WArray GCArray;
  33. CompileTime <<
  34. syslsp smacro procedure SegmentNumber X; % Get segment part of pointer
  35. LShift(X - HeapLowerBound, -BitsInSegment);
  36. syslsp smacro procedure OffsetInSegment X; % Get offset part of pointer
  37. LAnd(X - HeapLowerBound, SegmentMask);
  38. syslsp smacro procedure MovementWithinSegment X; % Reloc field in item
  39. GCField @X;
  40. syslsp smacro procedure PutMovementWithinSegment(X, M); % Store reloc field
  41. GCField @X := M;
  42. syslsp smacro procedure ClearMovementWithinSegment X; % Clear reloc field
  43. GCField @X := if NegIntP @X then -1 else 0;
  44. put('MovementWithinSegment, 'Assign!-Op, 'PutMovementWithinSegment);
  45. syslsp smacro procedure SegmentMovement X; % Segment table
  46. GCArray[X];
  47. syslsp smacro procedure PutSegmentMovement(X, M); % Store in seg table
  48. GCArray[X] := M;
  49. put('SegmentMovement, 'Assign!-Op, 'PutSegmentMovement);
  50. syslsp smacro procedure Reloc X; % Compute pointer adjustment
  51. X - (SegmentMovement SegmentNumber X + MovementWithinSegment X);
  52. >>;
  53. syslsp procedure testmarking;
  54. begin
  55. Prin2T "---- Test GC MARK of various HEAP structures ----";
  56. Prin2T " Examine each case carefully, see MARK go on and back off";
  57. Test1Mark cons(1 , 2); % Build a fresh one
  58. Test1Mark cons(- 1 , -2); % testing sign extend
  59. Test1Mark cons('A, 'B);
  60. Test1Mark '[0 1 2 3];
  61. Test1Mark "01234";
  62. TestIdmark 'A;
  63. TestIdmark 'JUNK;
  64. TestIdmark 'NIL;
  65. Prin2T "---- Mark tests all done --- ";
  66. End;
  67. syslsp procedure Test1Mark X;
  68. Begin scalar P;
  69. Prin2 ".... Object to mark: "; Print X;
  70. P:=Inf X;
  71. Prin2 " MARK field: "; Print Mark P;
  72. Prin2 " MARKED should be NIL: "; Print Marked P;
  73. PrintBits @P;
  74. Prin2 " .. SETMARK : "; Print SetMark P;
  75. Prin2 " MARK field now: "; Print Mark P;
  76. Prin2 " MARKED should be T: "; Print Marked P;
  77. PrintBits @P;
  78. Prin2 " .. CLEARMARK: "; Print ClearMark P;
  79. Prin2 " MARK field finally: "; Print Mark P;
  80. Prin2 " MARKED should be NIL: "; Print Marked P;
  81. PrintBits @P;
  82. Prin2 " .. Object again legal: "; Print X;
  83. End;
  84. syslsp procedure TestIDMark X;
  85. Begin scalar P;
  86. Prin2 ".... ID to mark: "; Print X;
  87. P:=IDInf X;
  88. Prin2 " MARKEDID should be NIL: "; Print MARKEDID P;
  89. PrintBits SYMNAM P;
  90. Prin2 " .. MARKID : "; Print MarkId P;
  91. Prin2 " MARKEDID should be T: "; Print MARKEDID P;
  92. PrintBits SYMNAM P;
  93. Prin2 " .. CLEARIDMARK: "; Print Clearidmark P;
  94. Prin2 " MARKEDID should be NIL: "; Print MARKEDID P;
  95. PrintBits SYMNAM P;
  96. Prin2 " .. ID again legal: "; Print X;
  97. End;
  98. syslsp procedure PrintBits x;
  99. <<Prin2 " BitPattern: ";
  100. Prin2 Tag x;
  101. Prin2 ": ";
  102. Prin2 Inf x;
  103. Terpri();
  104. >>;
  105. off syslisp;
  106. procedure GCTEST;
  107. Begin scalar X,N,M;
  108. Prin2T "---- GTEST series -----";
  109. Prin2T ".... Try individual Types first ...";
  110. Prin2 " Reclaim called: "; Reclaim();
  111. Prin2 " .. Allocate a PAIR: "; Print (x:=cons(1,2));
  112. Prin2 " Reclaim called: "; Reclaim();
  113. Prin2 " .. Release the PAIR: "; Print (X:=NIL);
  114. Prin2 " Reclaim called: "; Reclaim();
  115. Prin2 " .. Allocate a VECTOR: "; Print (x:=Mkvect(4));
  116. Prin2 " Reclaim called: "; Reclaim();
  117. Prin2 " .. Release the VECTOR: "; Print (X:=NIL);
  118. Prin2 " Reclaim called: "; Reclaim();
  119. Prin2 " .. Allocate a STRING: "; Print (x:=Mkstring(5,65));
  120. Prin2 " Reclaim called: "; Reclaim();
  121. Prin2 " .. Release the STRING: "; Print (X:=NIL);
  122. Prin2 " Reclaim called: "; Reclaim();
  123. M:=2;
  124. Prin2 ".... Loop until RECLAIM automatically called :";
  125. Prin2 M; Prin2t " times";
  126. N:=GCknt!*+M;
  127. Prin2T " .. Loop on PAIRs: ";
  128. While GCKnt!* <=N do list(1,2,3,4,5,6,7,8,9,10);
  129. N:=GCknt!*+M;
  130. Prin2T " .. Loop on VECTORs: ";
  131. While GCknt!* <=N do MkVect 5;
  132. N:=GCknt!*+M;
  133. Prin2T " .. Loop on STRINGs: ";
  134. While GCKnt!* <=N do Mkstring(20,65);
  135. End;
  136. off syslisp;
  137. End;