diff --git a/mps/code/arena.c b/mps/code/arena.c index 3a41ebbb0df..05279ab6bd6 100644 --- a/mps/code/arena.c +++ b/mps/code/arena.c @@ -91,7 +91,6 @@ DEFINE_CLASS(AbstractArenaClass, class) class->free = NULL; class->chunkInit = NULL; class->chunkFinish = NULL; - class->chunkReserved = NULL; class->compact = ArenaTrivCompact; class->describe = ArenaTrivDescribe; class->pagesMarkAllocated = NULL; @@ -119,7 +118,6 @@ Bool ArenaClassCheck(ArenaClass class) CHECKL(FUNCHECK(class->free)); CHECKL(FUNCHECK(class->chunkInit)); CHECKL(FUNCHECK(class->chunkFinish)); - CHECKL(FUNCHECK(class->chunkReserved)); CHECKL(FUNCHECK(class->compact)); CHECKL(FUNCHECK(class->describe)); CHECKL(FUNCHECK(class->pagesMarkAllocated)); @@ -669,7 +667,6 @@ Res ControlDescribe(Arena arena, mps_lib_FILE *stream, Count depth) void ArenaChunkInsert(Arena arena, Chunk chunk) { Bool inserted; Tree tree, updatedTree = NULL; - Size size; AVERT(Arena, arena); AVERT(Chunk, chunk); @@ -683,8 +680,7 @@ void ArenaChunkInsert(Arena arena, Chunk chunk) { arena->chunkTree = updatedTree; RingAppend(&arena->chunkRing, &chunk->arenaRing); - size = (*arena->class->chunkReserved)(chunk); - arena->reserved += size; + arena->reserved += ChunkReserved(chunk); /* As part of the bootstrap, the first created chunk becomes the primary chunk. This step allows ArenaFreeLandInsert to allocate pages. */ @@ -708,7 +704,7 @@ void ArenaChunkRemoved(Arena arena, Chunk chunk) if (arena->primary == chunk) arena->primary = NULL; - size = (*arena->class->chunkReserved)(chunk); + size = ChunkReserved(chunk); AVER(arena->reserved >= size); arena->reserved -= size; } diff --git a/mps/code/arenacl.c b/mps/code/arenacl.c index 554dc963c72..5212faf702b 100644 --- a/mps/code/arenacl.c +++ b/mps/code/arenacl.c @@ -131,7 +131,8 @@ static Res clientChunkCreate(Chunk *chunkReturn, ClientArena clientArena, clChunk = p; chunk = ClientChunk2Chunk(clChunk); res = ChunkInit(chunk, arena, alignedBase, - AddrAlignDown(limit, ArenaGrainSize(arena)), boot); + AddrAlignDown(limit, ArenaGrainSize(arena)), + AddrOffset(base, limit), boot); if (res != ResOK) goto failChunkInit; @@ -222,17 +223,6 @@ static void ClientChunkFinish(Chunk chunk) } -/* ClientChunkReserved -- return the amount of reserved address space - * in a client chunk. - */ - -static Size ClientChunkReserved(Chunk chunk) -{ - AVERT(Chunk, chunk); - return ChunkSize(chunk); -} - - /* ClientArenaVarargs -- parse obsolete varargs */ static void ClientArenaVarargs(ArgStruct args[MPS_ARGS_MAX], va_list varargs) @@ -469,7 +459,6 @@ DEFINE_ARENA_CLASS(ClientArenaClass, this) this->free = ClientArenaFree; this->chunkInit = ClientChunkInit; this->chunkFinish = ClientChunkFinish; - this->chunkReserved = ClientChunkReserved; AVERT(ArenaClass, this); } diff --git a/mps/code/arenavm.c b/mps/code/arenavm.c index fe1f0f91e9a..b37e7125fdd 100644 --- a/mps/code/arenavm.c +++ b/mps/code/arenavm.c @@ -323,7 +323,8 @@ static Res VMChunkCreate(Chunk *chunkReturn, VMArena vmArena, Size size) /* Copy VM descriptor into its place in the chunk. */ VMCopy(VMChunkVM(vmChunk), vm); - res = ChunkInit(VMChunk2Chunk(vmChunk), arena, base, limit, boot); + res = ChunkInit(VMChunk2Chunk(vmChunk), arena, base, limit, + VMReserved(VMChunkVM(vmChunk)), boot); if (res != ResOK) goto failChunkInit; @@ -456,17 +457,6 @@ static void VMChunkFinish(Chunk chunk) } -/* VMChunkReserved -- return the amount of reserved address space in a - * VM chunk. - */ - -static Size VMChunkReserved(Chunk chunk) -{ - AVERT(Chunk, chunk); - return VMReserved(VMChunkVM(Chunk2VMChunk(chunk))); -} - - /* VMArenaVarargs -- parse obsolete varargs */ static void VMArenaVarargs(ArgStruct args[MPS_ARGS_MAX], va_list varargs) @@ -1198,7 +1188,6 @@ DEFINE_ARENA_CLASS(VMArenaClass, this) this->free = VMFree; this->chunkInit = VMChunkInit; this->chunkFinish = VMChunkFinish; - this->chunkReserved = VMChunkReserved; this->compact = VMCompact; this->describe = VMArenaDescribe; this->pagesMarkAllocated = VMPagesMarkAllocated; diff --git a/mps/code/mpmst.h b/mps/code/mpmst.h index 96e8599e424..fecd90afa54 100644 --- a/mps/code/mpmst.h +++ b/mps/code/mpmst.h @@ -536,7 +536,6 @@ typedef struct mps_arena_class_s { ArenaFreeMethod free; ArenaChunkInitMethod chunkInit; ArenaChunkFinishMethod chunkFinish; - ArenaChunkReservedMethod chunkReserved; ArenaCompactMethod compact; ArenaDescribeMethod describe; ArenaPagesMarkAllocatedMethod pagesMarkAllocated; diff --git a/mps/code/mpmtypes.h b/mps/code/mpmtypes.h index de98355342a..b0d1fe2003a 100644 --- a/mps/code/mpmtypes.h +++ b/mps/code/mpmtypes.h @@ -125,7 +125,6 @@ typedef Res (*ArenaExtendMethod)(Arena arena, Addr base, Size size); typedef Res (*ArenaGrowMethod)(Arena arena, LocusPref pref, Size size); typedef void (*ArenaFreeMethod)(Addr base, Size size, Pool pool); typedef Res (*ArenaChunkInitMethod)(Chunk chunk, BootBlock boot); -typedef Size (*ArenaChunkReservedMethod)(Chunk chunk); typedef void (*ArenaChunkFinishMethod)(Chunk chunk); typedef void (*ArenaCompactMethod)(Arena arena, Trace trace); typedef Res (*ArenaDescribeMethod)(Arena arena, mps_lib_FILE *stream, Count depth); diff --git a/mps/code/tract.c b/mps/code/tract.c index 39f6bead95e..9aa815f47ba 100644 --- a/mps/code/tract.c +++ b/mps/code/tract.c @@ -167,7 +167,8 @@ Bool ChunkCheck(Chunk chunk) /* ChunkInit -- initialize generic part of chunk */ -Res ChunkInit(Chunk chunk, Arena arena, Addr base, Addr limit, BootBlock boot) +Res ChunkInit(Chunk chunk, Arena arena, Addr base, Addr limit, Size reserved, + BootBlock boot) { Size size; Count pages; @@ -192,6 +193,7 @@ Res ChunkInit(Chunk chunk, Arena arena, Addr base, Addr limit, BootBlock boot) chunk->pageShift = pageShift = SizeLog2(chunk->pageSize); chunk->base = base; chunk->limit = limit; + chunk->reserved = reserved; size = ChunkSize(chunk); chunk->pages = pages = size >> pageShift; diff --git a/mps/code/tract.h b/mps/code/tract.h index 07906ad5756..ce7c602a176 100644 --- a/mps/code/tract.h +++ b/mps/code/tract.h @@ -148,6 +148,9 @@ typedef struct ChunkStruct { BT allocTable; /* page allocation table */ Page pageTable; /* the page table */ Count pageTablePages; /* number of pages occupied by page table */ + Size reserved; /* reserved address space for chunk (including overhead + such as losses due to alignment): must not change + (or arena reserved calculation will break) */ } ChunkStruct; @@ -159,10 +162,11 @@ typedef struct ChunkStruct { #define ChunkSizeToPages(chunk, size) ((Count)((size) >> (chunk)->pageShift)) #define ChunkPage(chunk, pi) (&(chunk)->pageTable[pi]) #define ChunkOfTree(tree) PARENT(ChunkStruct, chunkTree, tree) +#define ChunkReserved(chunk) RVALUE((chunk)->reserved) extern Bool ChunkCheck(Chunk chunk); extern Res ChunkInit(Chunk chunk, Arena arena, Addr base, Addr limit, - BootBlock boot); + Size reserved, BootBlock boot); extern void ChunkFinish(Chunk chunk); extern Compare ChunkCompare(Tree tree, TreeKey key); extern TreeKey ChunkKey(Tree tree);