CVS: sml/src/runtime/gc build-literals.c,1.2,1.3

John Reppy <[email protected]>
Newsgroups gmane.comp.lang.sml.smlnj.commits
Message-ID <[email protected]>
Update of /cvsroot/smlnj/sml/src/runtime/gc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24903/gc

Modified Files:
	build-literals.c 
Log Message:
  Bug fix: the calculation of required space did not take sequence headers
  into account.


Index: build-literals.c
===================================================================
RCS file: /cvsroot/smlnj/sml/src/runtime/gc/build-literals.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** build-literals.c	1 Jun 2000 18:33:49 -0000	1.2
--- build-literals.c	20 May 2005 20:39:43 -0000	1.3
***************
*** 40,43 ****
--- 40,46 ----
      ((_B0(p) << 24) | (_B1(p) << 16) | (_B2(p) << 8) | _B3(p))
  
+ /* the size of a list cons cell in bytes */
+ #define CONS_SZB	(WORD_SZB*3)
+ 
  /* GetDouble:
   */
***************
*** 80,83 ****
--- 83,100 ----
      int		availSpace, spaceReq;
  
+ /* A check that the available space is sufficient for the literal object that
+  * we are about to allocate.  Note that the conce cell has already been accounted
+  * for in availSpace (but not in spaceReq).
+  */
+ #define GC_CHECK									\
+     do {										\
+ 	if ((spaceReq > availSpace) && NeedGC(msp, spaceReq+CONS_SZB)) {		\
+ 	    InvokeGCWithRoots (msp, 0, (ml_val_t *)&lits, &stk, NIL(ml_val_t *));	\
+ 	    availSpace = 0;								\
+ 	}										\
+ 	else										\
+ 	    availSpace -= spaceReq;							\
+     } while (0)
+ 
  #ifdef DEBUG_LITERALS
  SayDebug("BuildLiterals: lits = %#x, len = %d\n", lits, len);
***************
*** 96,100 ****
      while (TRUE) {
  	ASSERT(pc < len);
! 	availSpace -= 3*WORD_SZB;	/* space for stack cons cell */
  	if (availSpace < ONE_K) {
  	    if (NeedGC(msp, 64*ONE_K))
--- 113,117 ----
      while (TRUE) {
  	ASSERT(pc < len);
! 	availSpace -= CONS_SZB;	/* space for stack cons cell */
  	if (availSpace < ONE_K) {
  	    if (NeedGC(msp, 64*ONE_K))
***************
*** 126,135 ****
  	    ASSERT(n > 0);
  	    spaceReq = 4*(n+1);
! 	    if ((spaceReq > availSpace) && NeedGC(msp, spaceReq)) {
! 		InvokeGCWithRoots (msp, 0, (ml_val_t *)&lits, &stk, NIL(ml_val_t *));
! 		availSpace = 0;
! 	    }
! 	    else
! 		availSpace -= spaceReq;
  	    ML_AllocWrite (msp, 0, MAKE_DESC(n, DTAG_raw32));
  	    for (j = 1;  j <= n;  j++) {
--- 143,147 ----
  	    ASSERT(n > 0);
  	    spaceReq = 4*(n+1);
! 	    GC_CHECK;
  	    ML_AllocWrite (msp, 0, MAKE_DESC(n, DTAG_raw32));
  	    for (j = 1;  j <= n;  j++) {
***************
*** 156,165 ****
  	    ASSERT(n > 0);
  	    spaceReq = 8*(n+1);
! 	    if ((spaceReq > availSpace) && NeedGC(msp, spaceReq)) {
! 		InvokeGCWithRoots (msp, 0, (ml_val_t *)&lits, &stk, NIL(ml_val_t *));
! 		availSpace = 0;
! 	    }
! 	    else
! 		availSpace -= spaceReq;
  #ifdef ALIGN_REALDS
  	  /* Force REALD_SZB alignment (descriptor is off by one word) */
--- 168,172 ----
  	    ASSERT(n > 0);
  	    spaceReq = 8*(n+1);
! 	    GC_CHECK;
  #ifdef ALIGN_REALDS
  	  /* Force REALD_SZB alignment (descriptor is off by one word) */
***************
*** 187,197 ****
  	    }
  	    j = BYTES_TO_WORDS(n+1);  /* include space for '\0' */
! 	    spaceReq = 4*(j+1);
! 	    if ((spaceReq > availSpace) && NeedGC(msp, spaceReq)) {
! 		InvokeGCWithRoots (msp, 0, (ml_val_t *)&lits, &stk, NIL(ml_val_t *));
! 		availSpace = 0;
! 	    }
! 	    else
! 		availSpace -= spaceReq;
  	  /* allocate the data object */
  	    ML_AllocWrite(msp, 0, MAKE_DESC(j, DTAG_raw32));
--- 194,202 ----
  	    }
  	    j = BYTES_TO_WORDS(n+1);  /* include space for '\0' */
! 	  /* the space request includes space for the data-object header word and
! 	   * the sequence header object.
! 	   */
! 	    spaceReq = WORD_SZB*(j+1+3);
! 	    GC_CHECK;
  	  /* allocate the data object */
  	    ML_AllocWrite(msp, 0, MAKE_DESC(j, DTAG_raw32));
***************
*** 229,239 ****
  		break;
  	    }
! 	    spaceReq = 4*(n+1);
! 	    if ((spaceReq > availSpace) && NeedGC(msp, spaceReq)) {
! 		InvokeGCWithRoots (msp, 0, (ml_val_t *)&lits, &stk, NIL(ml_val_t *));
! 		availSpace = 0;
! 	    }
! 	    else
! 		availSpace -= spaceReq;
  	  /* allocate the data object */
  	    ML_AllocWrite(msp, 0, MAKE_DESC(n, DTAG_vec_data));
--- 234,242 ----
  		break;
  	    }
! 	  /* the space request includes space for the data-object header word and
! 	   * the sequence header object.
! 	   */
! 	    spaceReq = WORD_SZB*(n+1+3);
! 	    GC_CHECK;
  	  /* allocate the data object */
  	    ML_AllocWrite(msp, 0, MAKE_DESC(n, DTAG_vec_data));
***************
*** 265,275 ****
  	    else {
  		spaceReq = 4*(n+1);
! 		if ((spaceReq > availSpace) && NeedGC(msp, spaceReq)) {
! 		    InvokeGCWithRoots (
! 			msp, 0, (ml_val_t *)&lits, &stk, NIL(ml_val_t *));
! 		    availSpace = 0;
! 		}
! 		else
! 		    availSpace -= spaceReq;
  		ML_AllocWrite(msp, 0, MAKE_DESC(n, DTAG_record));
  	    }
--- 268,272 ----
  	    else {
  		spaceReq = 4*(n+1);
! 		GC_CHECK;
  		ML_AllocWrite(msp, 0, MAKE_DESC(n, DTAG_record));
  	    }



-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7412&alloc_id=16344&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.