[MLton-devel] mlton/runtime gc.c,1.48,1.49 my-lib.c,1.7,1.8 my-lib.h,1.4,1.5

sweeks@users.sourceforge.net sweeks@users.sourceforge.net
Wed, 01 May 2002 18:03:56 -0700


Update of /cvsroot/mlton/mlton/runtime
In directory usw-pr-cvs1:/tmp/cvs-serv25884

Modified Files:
	gc.c my-lib.c my-lib.h 
Log Message:
MAIL

Added code for swapping live data to disk when unable to allocate a large enough
toSpace.  It needs more testing.


Index: gc.c
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/gc.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -d -r1.48 -r1.49
*** gc.c	1 May 2002 19:48:57 -0000	1.48
--- gc.c	2 May 2002 01:03:54 -0000	1.49
***************
*** 219,222 ****
--- 219,230 ----
  #endif
  
+ static inline void releaseFromSpace (GC_state s) {
+ 	if (s->messages)
+ 		fprintf (stderr, "Releasing from space.\n");
+ 	release (s->base, s->fromSize);
+ 	s->base = NULL;
+ 	s->fromSize = 0;
+ }
+ 
  static inline void releaseToSpace (GC_state s) {
  	if (s->messages)
***************
*** 1698,1708 ****
  }
  
  /* If the GC didn't create enough space, then release toSpace, shrink 
   * fromSpace as much as possible, shifting it to a new location.  Then
   * try to allocate the semispace again.
   */
! static void shiftFromSpace (GC_state s, uint bytesRequested, 
! 				uint stackBytesRequested) {
! 	pointer old;
  	W32 keep, size;
  
--- 1706,1745 ----
  }
  
+ static void pageFromSpace (GC_state s, uint bytesRequested) {
+ 	FILE *stream;
+ 	char template[80] = "/tmp/FromSpaceXXXXXX";
+ 	int fd;
+ 	pointer old;
+ 
+ 	fd = smkstemp (template);
+ 	sclose (fd);
+ 	if (s->messages)
+ 		fprintf (stderr, "Paging fromSpace to %s.\n", template);
+ 	stream = sfopen (template, "wb");
+ 	old = s->base;
+ 	sfwrite (s->base, 1, s->bytesLive, stream);
+ 	sfclose (stream);
+ 	releaseFromSpace (s);
+ 	prepareToSpace (s, bytesRequested, 0);
+ 	if (s->bytesLive + bytesRequested > s->toSize) {
+ 		sunlink (template);
+ 		if (s->messages)
+ 			showMem ();
+ 		die ("Out of memory.  Unable to allocate semispace.  bytesRequested = %s.", uintToCommaString (bytesRequested));
+ 	}
+ 	swapSemis (s);
+ 	stream = sfopen (template, "rb");
+ 	sfread (s->base, 1, s->bytesLive, stream);
+ 	sfclose (stream);
+ 	sunlink (template);
+ 	GC_translateHeap (s, old, s->base, s->bytesLive);
+ }
+ 
  /* If the GC didn't create enough space, then release toSpace, shrink 
   * fromSpace as much as possible, shifting it to a new location.  Then
   * try to allocate the semispace again.
   */
! static void shiftFromSpace (GC_state s, uint bytesRequested) {
! 	pointer old, semi;
  	W32 keep, size;
  
***************
*** 1716,1741 ****
  	keep = roundPage (s, s->bytesLive);
  	s->fromSize = keep;
! 	s->base = allocateSemi (s, keep);
! 	if ((void*)-1 == s->base) {
! 		if (s->messages)
! 			showMem ();
! 		die ("Out of memory.  Unable to shift from space.");
  	}
- 	memcpy (s->base, old, keep);
- 	GC_translateHeap (s, old, s->base, s->bytesLive);
- 	release (old, size);
- 	/* Allocate a new toSpace and copy to it. */
- 	prepareToSpace (s, bytesRequested, stackBytesRequested);
- 	old = s->base;
- 	memcpy (s->toBase, s->base, keep);
- 	GC_translateHeap (s, old, s->toBase, s->bytesLive);
- 	release (s->base, keep);
- 	s->base = s->toBase;
- 	s->fromSize = s->toSize;
- 	s->toBase = NULL;
- 	s->toSize = 0;
  	GC_setStack (s);
  	s->frontier = s->base + s->bytesLive;
  	setLimit (s);
  }
  
--- 1753,1784 ----
  	keep = roundPage (s, s->bytesLive);
  	s->fromSize = keep;
! 	semi = allocateSemi (s, keep);
! 	if ((void*)-1 == semi)
! 		pageFromSpace (s, bytesRequested);
! 	else {
! 		s->base = semi;
! 		memcpy (s->base, old, keep);
! 		GC_translateHeap (s, old, s->base, s->bytesLive);
! 		release (old, size);
! 		/* Allocate a new toSpace and copy to it. */
! 		prepareToSpace (s, bytesRequested, 0);
! 		if (s->bytesLive + bytesRequested > s->toSize) {
! 			releaseToSpace (s);
! 			pageFromSpace (s, bytesRequested);
! 		} else {
! 			old = s->base;
! 			memcpy (s->toBase, s->base, keep);
! 			GC_translateHeap (s, old, s->toBase, s->bytesLive);
! 			release (s->base, keep);
! 			s->base = s->toBase;
! 			s->fromSize = s->toSize;
! 			s->toBase = NULL;
! 			s->toSize = 0;
! 		}
  	}
  	GC_setStack (s);
  	s->frontier = s->base + s->bytesLive;
  	setLimit (s);
+ 	assert (bytesRequested <= s->limit - s->frontier);
  }
  
***************
*** 1779,1788 ****
  	setLimit(s);
  	if (bytesRequested > s->limit - s->frontier) {
! 		shiftFromSpace (s, bytesRequested, stackBytesRequested);
! 		if (bytesRequested > s->limit - s->frontier) {
! 			if (s->messages)
! 				showMem ();
! 			die ("Out of memory.");
! 		}
  	} else {
  		resizeHeap (s, bytesRequested);
--- 1822,1826 ----
  	setLimit(s);
  	if (bytesRequested > s->limit - s->frontier) {
! 		shiftFromSpace (s, bytesRequested);
  	} else {
  		resizeHeap (s, bytesRequested);

Index: my-lib.c
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/my-lib.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** my-lib.c	13 Apr 2002 18:41:13 -0000	1.7
--- my-lib.c	2 May 2002 01:03:54 -0000	1.8
***************
*** 44,47 ****
--- 44,61 ----
  }
  
+ void sclose (int fd) {
+ 	unless (0 == close (fd)) 
+ 		diee ("unable to close %d", fd);
+ }
+ 
+ int smkstemp (char *template) {
+ 	int fd;
+ 
+ 	fd = mkstemp (template);
+ 	if (-1 == fd)
+ 		diee ("unable to make temporary file");
+ 	return fd;
+ }
+ 
  /* safe version of write */
  void swrite(int fd, const void *buf, size_t count) {
***************
*** 55,58 ****
--- 69,78 ----
  }
  
+ /* safe version of fclose */
+ void sfclose (FILE *file) {
+ 	unless (0 == fclose (file))
+ 		diee ("unable to close file");
+ }
+ 
  /* safe version of fopen */
  FILE *sfopen(char *fileName, char *mode) {
***************
*** 196,198 ****
--- 216,223 ----
  	if (0 != munmap(base, length))
  		diee("munmap failed");
+ }
+ 
+ void sunlink (char *path) {
+ 	unless (0 == unlink (path))
+ 		diee ("unkink (%s) failed", path);
  }

Index: my-lib.h
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/my-lib.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** my-lib.h	26 Mar 2002 17:27:30 -0000	1.4
--- my-lib.h	2 May 2002 01:03:54 -0000	1.5
***************
*** 61,69 ****
  #endif
  
! /* safe version of write */
  void swrite(int fd, const void *buf, size_t count);
  void swriteUint(int fd, uint n);
  
  /* safe versions of fopen, fread, fwrite */
  FILE *sfopen(char *fileName, char *mode);
  void sfread(void *ptr, size_t size, size_t nmemb, FILE *file);
--- 61,72 ----
  #endif
  
! /* safe version of close, mkstemp, write */
! int smkstemp (char *template);
! void sclose (int fd);
  void swrite(int fd, const void *buf, size_t count);
  void swriteUint(int fd, uint n);
  
  /* safe versions of fopen, fread, fwrite */
+ void sfclose (FILE *file);
  FILE *sfopen(char *fileName, char *mode);
  void sfread(void *ptr, size_t size, size_t nmemb, FILE *file);
***************
*** 75,78 ****
--- 78,82 ----
  void *smmap(size_t length);
  void smunmap(void *base, size_t length);
+ void sunlink (char *path);
  
  /* Return a statically allocated comma separated string */



_______________________________________________________________

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: bandwidth@sourceforge.net
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel