memory allocation patches for Apple's OS/X.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@23 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2001-05-03 17:13:18 +00:00
parent 18ff961273
commit f48f399540
6 changed files with 38 additions and 18 deletions

View File

@ -12,7 +12,7 @@
* Last rev: * * Last rev: *
* mods: * * mods: *
* comments: allocating space * * comments: allocating space *
* version:$Id: alloc.c,v 1.1.1.1 2001-04-09 19:53:30 vsc Exp $ * * version:$Id: alloc.c,v 1.2 2001-05-03 17:13:18 vsc Exp $ *
*************************************************************************/ *************************************************************************/
#ifdef SCCS #ifdef SCCS
static char SccsId[] = "%W% %G%"; static char SccsId[] = "%W% %G%";
@ -443,15 +443,21 @@ InitWorkSpace(Int s)
int fd; int fd;
#endif #endif
#if defined(_AIX) #if defined(_AIX) || defined(__APPLE__)
a = mmap(0, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC, a = mmap(0, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_VARIABLE, -1, 0); MAP_PRIVATE | MAP_ANONYMOUS | MAP_VARIABLE, -1, 0);
#elif __hpux #elif __hpux
a = mmap(((void *)MMAP_ADDR), (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC, a = mmap(((void *)MMAP_ADDR), (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
if (a != (MALLOC_T)MMAP_ADDR) {
Error(SYSTEM_ERROR, TermNil, "mmap could not map ANON at %p, got %p", (void *)MMAP_ADDR, a);
}
#elif defined(__APPLE__) #elif defined(__APPLE__)
a = mmap(0, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC, a = mmap(((void *)MMAP_ADDR), (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANON, -1, 0); MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
if (a != (MALLOC_T)MMAP_ADDR) {
Error(SYSTEM_ERROR, TermNil, "mmap could not map ANON at %p, got %p", (void *)MMAP_ADDR,a );
}
#else #else
fd = open("/dev/zero", O_RDWR); fd = open("/dev/zero", O_RDWR);
if (fd < 0) { if (fd < 0) {
@ -496,6 +502,9 @@ InitWorkSpace(Int s)
#if USE_FIXED #if USE_FIXED
a = mmap(((void *)MMAP_ADDR), (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC, a = mmap(((void *)MMAP_ADDR), (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_FIXED, fd, 0); MAP_PRIVATE | MAP_FIXED, fd, 0);
if (a != (MALLOC_T)MMAP_ADDR) {
Error(SYSTEM_ERROR, TermNil, "mmap could not map at %p, got %p", (void *)MMAP_ADDR, a);
}
#else #else
a = mmap(0, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC, a = mmap(0, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE, fd, 0); MAP_PRIVATE, fd, 0);
@ -536,9 +545,15 @@ ExtendWorkSpace(Int s)
a = mmap(WorkSpaceTop, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC, a = mmap(WorkSpaceTop, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (a != WorkSpaceTop) {
Error(SYSTEM_ERROR, TermNil, "mmap could not grow memory at %p, got %p", WorkSpaceTop, a );
}
#elif defined(__APPLE__) #elif defined(__APPLE__)
a = mmap(WorkSpaceTop, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC, a = mmap(WorkSpaceTop, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANON, -1, 0); MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
if (a != WorkSpaceTop) {
Error(SYSTEM_ERROR, TermNil, "mmap could not grow memory at %p, got %p", WorkSpaceTop, a );
}
#else #else
int fd; int fd;
fd = open("/dev/zero", O_RDWR); fd = open("/dev/zero", O_RDWR);
@ -581,9 +596,6 @@ ExtendWorkSpace(Int s)
return FALSE; return FALSE;
} }
} }
a = mmap(WorkSpaceTop, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_FIXED, fd, 0);
if (close(fd) == -1) { if (close(fd) == -1) {
#if HAVE_STRERROR #if HAVE_STRERROR
Error(SYSTEM_ERROR, TermNil, "mmap could not close file (%s) ]\n", strerror(errno)); Error(SYSTEM_ERROR, TermNil, "mmap could not close file (%s) ]\n", strerror(errno));
@ -593,7 +605,6 @@ ExtendWorkSpace(Int s)
return FALSE; return FALSE;
} }
#endif #endif
if (a == (MALLOC_T) - 1) { if (a == (MALLOC_T) - 1) {
#if HAVE_STRERROR #if HAVE_STRERROR
Error(SYSTEM_ERROR, TermNil, "could not allocate %d bytes (%s)", (int)s, strerror(errno)); Error(SYSTEM_ERROR, TermNil, "could not allocate %d bytes (%s)", (int)s, strerror(errno));
@ -602,6 +613,13 @@ ExtendWorkSpace(Int s)
#endif #endif
return FALSE; return FALSE;
} }
a = mmap(WorkSpaceTop, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_FIXED, fd, 0);
if (a != WorkSpaceTop) {
Error(SYSTEM_ERROR, TermNil, "mmap could not grow memory at %p, got %p", WorkSpaceTop, a );
}
WorkSpaceTop = (char *) a + s; WorkSpaceTop = (char *) a + s;
#endif /* YAPOR */ #endif /* YAPOR */
return TRUE; return TRUE;

View File

@ -655,7 +655,7 @@ init_dbtable(tr_fr_ptr trail_ptr) {
#ifdef DEBUG #ifdef DEBUG
/*#define INSTRUMENT_GC 1*/ /*#define INSTRUMENT_GC 1*/
#define CHECK_CHOICEPOINTS 1 /*#define CHECK_CHOICEPOINTS 1*/
#ifdef INSTRUMENT_GC #ifdef INSTRUMENT_GC
typedef enum { typedef enum {
@ -2546,7 +2546,7 @@ compaction_phase(tr_fr_ptr old_TR, CELL *current_env, yamop *curp, CELL *max)
YP_fprintf(YP_stderr,"[GC] Oops on iptop-H (%d) vs %d\n", iptop-(CELL_PTR *)H, total_marked); YP_fprintf(YP_stderr,"[GC] Oops on iptop-H (%d) vs %d\n", iptop-(CELL_PTR *)H, total_marked);
#endif #endif
if (iptop < (CELL_PTR *)ASP-1024 && 10*total_marked < H-H0) { if (iptop < (CELL_PTR *)ASP-1024 && 10*total_marked < H-H0) {
#ifdef DEBUG #ifdef DEBUG_IN
int effectiveness = (((H-H0)-total_marked)*100)/(H-H0); int effectiveness = (((H-H0)-total_marked)*100)/(H-H0);
fprintf(stderr,"using pointers (%d)\n", effectiveness); fprintf(stderr,"using pointers (%d)\n", effectiveness);
#endif #endif
@ -2555,7 +2555,7 @@ compaction_phase(tr_fr_ptr old_TR, CELL *current_env, yamop *curp, CELL *max)
} else } else
#endif /* HYBRID_SCHEME */ #endif /* HYBRID_SCHEME */
{ {
#ifdef DEBUG #ifdef DEBUG_IN
int effectiveness = (((H-H0)-total_marked)*100)/(H-H0); int effectiveness = (((H-H0)-total_marked)*100)/(H-H0);
fprintf(stderr,"not using pointers (%d)\n", effectiveness); fprintf(stderr,"not using pointers (%d)\n", effectiveness);
#endif #endif

View File

@ -1669,6 +1669,7 @@ SetAlias (Atom arg, int sno)
#endif /* HAVE_SETBUF */ #endif /* HAVE_SETBUF */
break; break;
default: default:
break;
} }
return; return;
} }
@ -1705,6 +1706,7 @@ PurgeAlias (int sno)
YP_stderr = 2; YP_stderr = 2;
break; break;
default: default:
break; /* just put something here */
} }
new_aliasp++; new_aliasp++;
} else { } else {

View File

@ -93,10 +93,6 @@ void STD_PROTO(YAP_InitHeap, (void *));
#if USE_MMAP #if USE_MMAP
#ifdef _APPLE__
#endif
#include <sys/types.h> #include <sys/types.h>
#include <sys/mman.h> #include <sys/mman.h>

View File

@ -6,6 +6,8 @@
<H2 ALIGN=CENTER>Yap-4.3.19:</H2> <H2 ALIGN=CENTER>Yap-4.3.19:</H2>
<UL> <UL>
<LI> FIXED: Patches for memory allocation in Apple's OS/X..
<LI> FIXED: checked whether mmap work right in alloc.c.
<LI> FIXED: ASP from Y should have space for env size. <LI> FIXED: ASP from Y should have space for env size.
<LI> NEW: new garbage collection algorithm. <LI> NEW: new garbage collection algorithm.
<LI> FIXED: don't allow importing from the module itself. <LI> FIXED: don't allow importing from the module itself.

View File

@ -10,7 +10,7 @@
* File: Yap.h.m4 * * File: Yap.h.m4 *
* mods: * * mods: *
* comments: main header file for YAP * * comments: main header file for YAP *
* version: $Id: Yap.h.m4,v 1.3 2001-04-17 21:07:41 vsc Exp $ * * version: $Id: Yap.h.m4,v 1.4 2001-05-03 17:13:18 vsc Exp $ *
*************************************************************************/ *************************************************************************/
#include "config.h" #include "config.h"
@ -223,8 +223,10 @@ extern char Option[20];
#define MMAP_ADDR 0x40000000 #define MMAP_ADDR 0x40000000
#elif mips #elif mips
#define MMAP_ADDR 0x02000000 #define MMAP_ADDR 0x02000000
#elif __APPLE__
#define MMAP_ADDR 0x01000000
#else #else
#define MMAP_ADDR 0x10010000 #define MMAP_ADDR 0x10000000
#endif #endif
#elif __svr4__ #elif __svr4__
#define MMAP_ADDR 0x02000000 #define MMAP_ADDR 0x02000000