mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 01:31:08 +00:00
Tidyups for garbage collection
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4952 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
775722b78e
commit
cc7cb05157
6 changed files with 57 additions and 58 deletions
|
@ -1,4 +1,4 @@
|
||||||
Tue Sep 28 9:54:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
Tue Sep 28 11:45:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
* Source/NSArray.m: ([+allocWithZone:]) tiny optimisation.
|
* Source/NSArray.m: ([+allocWithZone:]) tiny optimisation.
|
||||||
* Source/NSCountedSet.m: Some optimisation.
|
* Source/NSCountedSet.m: Some optimisation.
|
||||||
|
@ -9,6 +9,11 @@ Tue Sep 28 9:54:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
([-volatileDomainForName:]) return constant dictionary.
|
([-volatileDomainForName:]) return constant dictionary.
|
||||||
([-setPersistentDomain:forName:]) make mutable copy.
|
([-setPersistentDomain:forName:]) make mutable copy.
|
||||||
([-setVolatileDomain:forName:]) ditto
|
([-setVolatileDomain:forName:]) ditto
|
||||||
|
* Source/NSObject.m: GC tweaks
|
||||||
|
* Source/NSZone.m: added zone for atomic GC
|
||||||
|
* Headers/Foundation/NSZone.h: added zone GSAtomicMallocZone()
|
||||||
|
* Headers/Foundation/GSIArray.h: Remove special case for zero zone
|
||||||
|
* Headers/Foundation/GSIMap.h: ditto.
|
||||||
|
|
||||||
Tue Sep 28 5:54:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
Tue Sep 28 5:54:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
|
|
|
@ -428,17 +428,7 @@ GSIArrayInitWithZoneAndCapacity(GSIArray array, NSZone *zone, size_t capacity)
|
||||||
array->cap = capacity;
|
array->cap = capacity;
|
||||||
array->old = capacity/2;
|
array->old = capacity/2;
|
||||||
size = capacity*sizeof(GSIArrayItem);
|
size = capacity*sizeof(GSIArrayItem);
|
||||||
#if GS_WITH_GC
|
|
||||||
/*
|
|
||||||
* If we use a nil zone, objects we point to are subject to GC
|
|
||||||
*/
|
|
||||||
if (zone == 0)
|
|
||||||
array->ptr = (GSIArrayItem*)GC_MALLOC_ATOMIC(size);
|
|
||||||
else
|
|
||||||
array->ptr = (GSIArrayitem)GC_MALLOC(zone, size);
|
|
||||||
#else
|
|
||||||
array->ptr = (GSIArrayItem*)NSZoneMalloc(zone, size);
|
array->ptr = (GSIArrayItem*)NSZoneMalloc(zone, size);
|
||||||
#endif
|
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -364,17 +364,7 @@ GSIMapMoreNodes(GSIMapTable map)
|
||||||
chunkCount = ((map->nodeCount>>2)+1)<<1;
|
chunkCount = ((map->nodeCount>>2)+1)<<1;
|
||||||
}
|
}
|
||||||
chunkSize = chunkCount * sizeof(GSIMapNode_t);
|
chunkSize = chunkCount * sizeof(GSIMapNode_t);
|
||||||
#if GS_WITH_GC
|
|
||||||
/*
|
|
||||||
* If we use a nil zone, objects we point to are subject to GC
|
|
||||||
*/
|
|
||||||
if (map->zone == 0)
|
|
||||||
newNodes = (GSIMapNode*)GC_MALLOC_ATOMIC(chunkSize);
|
|
||||||
else
|
|
||||||
newNodes = (GSIMapNode*)GC_MALLOC(chunkSize);
|
|
||||||
#else
|
|
||||||
newNodes = (GSIMapNode)NSZoneMalloc(map->zone, chunkSize);
|
newNodes = (GSIMapNode)NSZoneMalloc(map->zone, chunkSize);
|
||||||
#endif
|
|
||||||
if (newNodes)
|
if (newNodes)
|
||||||
{
|
{
|
||||||
map->nodeChunks[map->chunkCount++] = newNodes;
|
map->nodeChunks[map->chunkCount++] = newNodes;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* Zone memory management. -*- Mode: ObjC -*-
|
/* Zone memory management. -*- Mode: ObjC -*-
|
||||||
Copyright (C) 1997 Free Software Foundation, Inc.
|
Copyright (C) 1997,1998,1999 Free Software Foundation, Inc.
|
||||||
|
|
||||||
Written by: Yoo C. Chung <wacko@laplace.snu.ac.kr>
|
Written by: Yoo C. Chung <wacko@laplace.snu.ac.kr>
|
||||||
Date: January 1997
|
Date: January 1997
|
||||||
|
@ -69,6 +69,8 @@ extern NSZone* __nszone_private_hidden_default_zone;
|
||||||
|
|
||||||
#include <gc.h>
|
#include <gc.h>
|
||||||
|
|
||||||
|
extern NSZone* __nszone_private_hidden_atomic_zone;
|
||||||
|
|
||||||
#define
|
#define
|
||||||
extern inline NSZone* NSCreateZone (size_t start, size_t gran, BOOL canFree)
|
extern inline NSZone* NSCreateZone (size_t start, size_t gran, BOOL canFree)
|
||||||
{ return __nszone_private_hidden_default_zone; }
|
{ return __nszone_private_hidden_default_zone; }
|
||||||
|
@ -76,12 +78,20 @@ extern inline NSZone* NSCreateZone (size_t start, size_t gran, BOOL canFree)
|
||||||
extern inline NSZone* NSDefaultMallocZone (void)
|
extern inline NSZone* NSDefaultMallocZone (void)
|
||||||
{ return __nszone_private_hidden_default_zone; }
|
{ return __nszone_private_hidden_default_zone; }
|
||||||
|
|
||||||
|
extern inline NSZone* GSAtomicMallocZone (void)
|
||||||
|
{ return __nszone_private_hidden_atomict_zone; }
|
||||||
|
|
||||||
extern inline NSZone* NSZoneFromPointer (void *ptr)
|
extern inline NSZone* NSZoneFromPointer (void *ptr)
|
||||||
{ return __nszone_private_hidden_default_zone; }
|
{ return __nszone_private_hidden_default_zone; }
|
||||||
|
|
||||||
extern inline void* NSZoneMalloc (NSZone *zone, size_t size)
|
extern inline void* NSZoneMalloc (NSZone *zone, size_t size)
|
||||||
{
|
{
|
||||||
void *ptr = (void*)GC_MALLOC(size);
|
void *ptr;
|
||||||
|
|
||||||
|
if (zone == GSAtomicMallocZone())
|
||||||
|
*ptr = (void*)GC_MALLOC_ATOMIC(size);
|
||||||
|
else
|
||||||
|
*ptr = (void*)GC_MALLOC(size);
|
||||||
|
|
||||||
if (ptr == 0)
|
if (ptr == 0)
|
||||||
ptr = GSOutOfMemory(size, YES);
|
ptr = GSOutOfMemory(size, YES);
|
||||||
|
@ -91,9 +101,13 @@ extern inline void* NSZoneMalloc (NSZone *zone, size_t size)
|
||||||
extern inline void* NSZoneCalloc (NSZone *zone, size_t elems, size_t bytes)
|
extern inline void* NSZoneCalloc (NSZone *zone, size_t elems, size_t bytes)
|
||||||
{
|
{
|
||||||
size_t size = elems * bytes;
|
size_t size = elems * bytes;
|
||||||
void *ptr = (void*)GC_MALLOC(size);
|
void *ptr;
|
||||||
|
|
||||||
|
if (zone == __nszone_private_hidden_atomic_zone)
|
||||||
|
*ptr = (void*)GC_MALLOC_ATOMIC(size);
|
||||||
|
else
|
||||||
|
*ptr = (void*)GC_MALLOC(size);
|
||||||
|
|
||||||
void *ptr = (void*)GC_MALLOC(size, YES);
|
|
||||||
if (ptr == 0)
|
if (ptr == 0)
|
||||||
ptr = GSOutOfMemory(size);
|
ptr = GSOutOfMemory(size);
|
||||||
memset(ptr, '\0', size);
|
memset(ptr, '\0', size);
|
||||||
|
@ -130,11 +144,7 @@ extern inline NSString* NSZoneName (NSZone *zone)
|
||||||
|
|
||||||
extern inline void* NSZoneMallocAtomic (NSZone *zone, size_t size)
|
extern inline void* NSZoneMallocAtomic (NSZone *zone, size_t size)
|
||||||
{
|
{
|
||||||
void *ptr = (void*)GC_MALLOC_ATOMIC(size);
|
return NSZoneMalloc(GSAtomicmallocZone(), size);
|
||||||
|
|
||||||
if (ptr == 0)
|
|
||||||
ptr = GSOutOfMemory(size, YES);
|
|
||||||
return ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern inline BOOL NSZoneCheck (NSZone *zone)
|
extern inline BOOL NSZoneCheck (NSZone *zone)
|
||||||
|
@ -158,6 +168,11 @@ extern inline NSZone* NSDefaultMallocZone (void)
|
||||||
return __nszone_private_hidden_default_zone;
|
return __nszone_private_hidden_default_zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern inline NSZone* GSAtomicMallocZone (void)
|
||||||
|
{
|
||||||
|
return NSDefaultMallocZone();
|
||||||
|
}
|
||||||
|
|
||||||
extern NSZone* NSZoneFromPointer (void *ptr);
|
extern NSZone* NSZoneFromPointer (void *ptr);
|
||||||
|
|
||||||
extern inline void* NSZoneMalloc (NSZone *zone, size_t size)
|
extern inline void* NSZoneMalloc (NSZone *zone, size_t size)
|
||||||
|
|
|
@ -281,42 +281,37 @@ static void
|
||||||
GSFinalize(void* object, void* data)
|
GSFinalize(void* object, void* data)
|
||||||
{
|
{
|
||||||
[(id)object gcFinalize];
|
[(id)object gcFinalize];
|
||||||
|
|
||||||
/* Set the class of anObject to FREED_OBJECT. The further messages to this
|
|
||||||
object will cause an error to occur. */
|
|
||||||
((id)object)->class_pointer = __freedObjectClass;
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
GSDebugAllocationRemove(((id)object)->class_pointer);
|
GSDebugAllocationRemove(((id)object)->class_pointer);
|
||||||
#endif
|
#endif
|
||||||
((id)object)->class_pointer = (void*) 0xdeadface;
|
((id)object)->class_pointer = (void*)0xdeadface;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline NSObject *
|
inline NSObject *
|
||||||
NSAllocateObject (Class aClass, unsigned extraBytes, NSZone *zone)
|
NSAllocateObject(Class aClass, unsigned extraBytes, NSZone *zone)
|
||||||
{
|
{
|
||||||
id new = nil;
|
id new = nil;
|
||||||
int size = aClass->instance_size + extraBytes;
|
int size = aClass->instance_size + extraBytes;
|
||||||
if (CLS_ISCLASS (aClass))
|
|
||||||
new = NSZoneMalloc (zone, size);
|
if (CLS_ISCLASS(aClass))
|
||||||
|
new = NSZoneMalloc(zone, size);
|
||||||
if (new != nil)
|
if (new != nil)
|
||||||
{
|
{
|
||||||
memset (new, 0, size);
|
memset(new, 0, size);
|
||||||
new->class_pointer = aClass;
|
new->class_pointer = aClass;
|
||||||
}
|
if (__objc_responds_to(new, @selector(gcFinalize)))
|
||||||
if ([new respondsToSelector: @selector(gcFinalize)])
|
{
|
||||||
{
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
/*
|
/*
|
||||||
* We only do allocation counting for objects that can be
|
* We only do allocation counting for objects that can be
|
||||||
* finalised - for other objects we have no way of decrementing
|
* finalised - for other objects we have no way of decrementing
|
||||||
* the count when the object is collected.
|
* the count when the object is collected.
|
||||||
*/
|
*/
|
||||||
GSDebugAllocationAdd(aClass);
|
GSDebugAllocationAdd(aClass);
|
||||||
#endif
|
#endif
|
||||||
GC_REGISTER_FINALIZER (new, GSFinalize, NULL, NULL, NULL);
|
GC_REGISTER_FINALIZER (new, GSFinalize, NULL, NULL, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1759,11 +1759,9 @@ NSZoneStats (NSZone *zone)
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Dummy zone used with garbage collection.
|
* Dummy zones used with garbage collection.
|
||||||
* In some places we make a distinction between the nul zone and the dummy
|
* The 'atomic' zone is for memory that will be assumed not to contain
|
||||||
* zone - items pointed to by memory in the nul zone can be deallocated by
|
* pointers for garbage collection purposes.
|
||||||
* the gc mechanism, while those pointed to from memory in the dummy zone
|
|
||||||
* can't.
|
|
||||||
*/
|
*/
|
||||||
static NSZone default_zone =
|
static NSZone default_zone =
|
||||||
{
|
{
|
||||||
|
@ -1771,5 +1769,11 @@ static NSZone default_zone =
|
||||||
};
|
};
|
||||||
NSZone* __nszone_private_hidden_default_zone = &default_zone;
|
NSZone* __nszone_private_hidden_default_zone = &default_zone;
|
||||||
|
|
||||||
|
static NSZone atomic_zone =
|
||||||
|
{
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, @"default", 0
|
||||||
|
};
|
||||||
|
NSZone* __nszone_private_hidden_atomic_zone = &atomic_zone;
|
||||||
|
|
||||||
#endif /* GS_WITH_GC */
|
#endif /* GS_WITH_GC */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue