[Vm-dev] [commit][3016] Further simplification in
platforms/unix/vm/sqUnixSpurMemory .c.
commits at squeakvm.org
commits at squeakvm.org
Tue Jun 24 18:38:46 UTC 2014
Revision: 3016
Author: eliot
Date: 2014-06-24 11:38:36 -0700 (Tue, 24 Jun 2014)
Log Message:
-----------
Further simplification in platforms/unix/vm/sqUnixSpurMemory.c. Fix snafu in
platforms/unix/vm/sqUnixMemory.c.
Modified Paths:
--------------
branches/Cog/platforms/unix/vm/sqUnixMemory.c
branches/Cog/platforms/unix/vm/sqUnixSpurMemory.c
Property Changed:
----------------
branches/Cog/platforms/Cross/vm/sqSCCSVersion.h
Property changes on: branches/Cog/platforms/Cross/vm/sqSCCSVersion.h
___________________________________________________________________
Modified: checkindate
- Tue Jun 24 10:27:03 PDT 2014
+ Tue Jun 24 11:38:03 PDT 2014
Modified: branches/Cog/platforms/unix/vm/sqUnixMemory.c
===================================================================
--- branches/Cog/platforms/unix/vm/sqUnixMemory.c 2014-06-24 17:30:28 UTC (rev 3015)
+++ branches/Cog/platforms/unix/vm/sqUnixMemory.c 2014-06-24 18:38:36 UTC (rev 3016)
@@ -39,7 +39,7 @@
#include "config.h"
#include "debug.h"
-#!if SPURVM /* Spur uses sqUnixSpurMemory.c */
+#if !SPURVM /* Spur uses sqUnixSpurMemory.c */
void *uxAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize);
/* Note:
Modified: branches/Cog/platforms/unix/vm/sqUnixSpurMemory.c
===================================================================
--- branches/Cog/platforms/unix/vm/sqUnixSpurMemory.c 2014-06-24 17:30:28 UTC (rev 3015)
+++ branches/Cog/platforms/unix/vm/sqUnixSpurMemory.c 2014-06-24 18:38:36 UTC (rev 3016)
@@ -84,13 +84,13 @@
static int min(int x, int y) { return (x < y) ? x : y; }
static int max(int x, int y) { return (x > y) ? x : y; }
-/* answer the address of minHeapSize rounded up to page size bytes of memory. */
+/* Answer the address of minHeapSize rounded up to page size bytes of memory. */
usqInt
sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize)
{
char *hint, *address, *alloc;
- long bytes, allocBytes;
+ unsigned long alignment, allocBytes;
if (pageSize) {
fprintf(stderr, "sqAllocateMemory: already called\n");
@@ -101,31 +101,18 @@
hint = sbrk(0);
- bytes = max(pageSize,1024*1024);
- address = (char *)(((usqInt)hint + bytes - 1) & ~(bytes - 1));
- allocBytes = roundUpToPage(desiredHeapSize);
+ alignment = max(pageSize,1024*1024);
+ address = (char *)(((usqInt)hint + alignment - 1) & ~(alignment - 1));
-# if TEST_MEMORY
- printf("hint at %p\n", hint);
- alloc = mmap(0, allocBytes, PROT_READ | PROT_WRITE,
- MAP_ANON | MAP_PRIVATE, -1, 0);
- printf("mmap at %p\n", alloc);
- if (alloc != MAP_FAILED)
- (void)munmap(alloc, allocBytes);
-# endif
-
- alloc = mmap(address, allocBytes, PROT_READ | PROT_WRITE,
- MAP_ANON | MAP_FIXED | MAP_PRIVATE, -1, 0);
- if (alloc != MAP_FAILED)
- return (usqInt)alloc;
- mmapErrno = errno;
- perror("sqAllocateMemory initial allocation mmap");
- exit(errno);
- return 0;
+ alloc = sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto
+ (roundUpToPage(desiredHeapSize), address, &allocBytes);
+ if (!alloc) {
+ fprintf(stderr, "sqAllocateMemory: initial alloc failed!\n");
+ exit(errno);
+ }
+ return (usqInt)alloc;
}
-static long map_flags = MAP_ANON | MAP_PRIVATE;
-
/* Allocate a region of memory of at least size bytes, at or above minAddress.
* If the attempt fails, answer null. If the attempt succeeds, answer the
* start of the region and assign its size through allocatedSizePointer.
@@ -204,11 +191,14 @@
# define MBytes *1024UL*1024UL
-int main()
+int
+main()
{
char *mem;
usqInt i, t = 16 MBytes;
+ printf("hint at %p\n", sbrk(0));
+
mem= (char *)sqAllocateMemory(t, t);
printf("memory allocated at %p\n", mem);
/* create some roadbumps */
More information about the Vm-dev
mailing list