simplify GC ... don't need to add new zone

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27783 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2009-02-04 16:45:10 +00:00
parent be86199404
commit 0e2e58bf87
18 changed files with 59 additions and 67 deletions

View file

@ -1,3 +1,24 @@
2009-02-04 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSMapTable.m:
* Source/NSHashTable.m:
* Source/NSPortCoder.m:
* Source/NSKeyedArchiver.m:
* Source/NSGarbageCollector.m:
* Source/NSZone.m:
* Source/GSDictionary.m:
* Source/GSCountedSet.m:
* Source/GSAttributedString.m:
* Source/NSNotificationCenter.m:
* Source/Additions/GSInsensitiveDictionary.m:
* Source/GSSet.m:
* Source/NSConnection.m:
* Source/NSSerializer.m:
* Source/NSArchiver.m:
* Headers/Foundation/NSZone.h:
* Headers/Additions/GNUstepBase/GSIMap.h:
Scrap GSScannedMallocZone().. not really needed.
2009-02-04 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSURLProtocol.m: Add some diagnostics and ensure that

View file

@ -207,7 +207,7 @@ extern "C" {
#define GSIMapWeakKeyAndVal ((NSZone*)3)
static BOOL _GSIMapSetup = NO;
static NSZone *_GSIMapUnscannedZone = 0;
static NSGarbageCollector *_collector = nil;
/*
* Description of the datastructure
@ -433,7 +433,7 @@ GSIMapMoreNodes(GSIMapTable map, unsigned required)
* them freed - so we must keep the array of pointers to memory chunks in
* scanned memory.
*/
if (_GSIMapUnscannedZone == 0)
if (_collector == nil)
{
newArray = (GSIMapNode*)NSZoneMalloc(map->zone, arraySize);
}
@ -471,7 +471,7 @@ GSIMapMoreNodes(GSIMapTable map, unsigned required)
chunkCount = required;
}
chunkSize = chunkCount * sizeof(GSIMapNode_t);
if (_GSIMapUnscannedZone == 0)
if (_collector == nil)
{
newNodes = (GSIMapNode)NSZoneMalloc(map->zone, chunkSize);
}
@ -637,7 +637,7 @@ GSIMapResize(GSIMapTable map, size_t new_capacity)
/*
* Make a new set of buckets for this map
*/
if (_GSIMapUnscannedZone == 0)
if (_collector == nil)
{
/* Use the zone specified for this map.
*/
@ -953,10 +953,7 @@ GSIMapSetup()
{
if (_GSIMapSetup == NO)
{
if ([NSGarbageCollector defaultCollector] != nil)
{
_GSIMapUnscannedZone = [[NSGarbageCollector defaultCollector] zone];
}
_collector = [NSGarbageCollector defaultCollector];
_GSIMapSetup = YES;
}
}
@ -965,9 +962,9 @@ static INLINE void
GSIMapInitWithZoneAndCapacity(GSIMapTable map, NSZone *zone, size_t capacity)
{
GSIMapSetup();
if (_GSIMapUnscannedZone != 0 && (uintptr_t)zone > 3)
if (_collector != nil && (uintptr_t)zone > 3)
{
if (zone == _GSIMapUnscannedZone)
if (zone == GSAtomicMallocZone())
{
map->zone = GSIMapWeakKeyAndVal; // Unscanned memory
}

View file

@ -230,13 +230,6 @@ GSOutOfMemory(size_t size, BOOL retry);
GS_EXPORT NSZone*
GSAtomicMallocZone (void);
/**
* Returns the default zone used for scanned memory allocation ... a
* garbage collectable chunk of memory which is scanned for pointers.
*/
GS_EXPORT NSZone*
GSScannedMallocZone (void);
/**
* Called during +initialize to tell the class that instances created
* in future should have the specified instance variable as a weak

View file

@ -160,7 +160,7 @@ static SEL objSel;
at: &count];
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSScannedMallocZone(), count);
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, count);
#else
GSIMapInitWithZoneAndCapacity(&map, GSObjCZone(self), count);
#endif
@ -180,7 +180,7 @@ static SEL objSel;
unsigned int i;
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSScannedMallocZone(), c);
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, c);
#else
GSIMapInitWithZoneAndCapacity(&map, GSObjCZone(self), c);
#endif
@ -223,15 +223,14 @@ static SEL objSel;
- (id) initWithDictionary: (NSDictionary*)other
copyItems: (BOOL)shouldCopy
{
NSZone *z;
NSZone *z = GSObjCZone(self);
unsigned c = [other count];
#if GS_WITH_GC
z = GSScannedMallocZone();
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, c);
#else
z = GSObjCZone(self);
#endif
GSIMapInitWithZoneAndCapacity(&map, z, c);
#endif
if (c > 0)
{
@ -384,7 +383,7 @@ static SEL objSel;
- (id) initWithCapacity: (unsigned)cap
{
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSScannedMallocZone(), cap);
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, cap);
#else
GSIMapInitWithZoneAndCapacity(&map, GSObjCZone(self), cap);
#endif

View file

@ -275,7 +275,11 @@ static void _setup(void)
NSMutableArray *a;
NSDictionary *d;
GSIMapInitWithZoneAndCapacity(&attrMap, GSScannedMallocZone(), 32);
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&attrMap, GSIMapStrongKeyAndVal, 32);
#else
GSIMapInitWithZoneAndCapacity(&attrMap, NSDefaultMallocZone(), 32);
#endif
infSel = @selector(newWithZone:value:at:);
addSel = @selector(addObject:);

View file

@ -184,7 +184,7 @@
- (id) initWithCapacity: (unsigned)cap
{
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSScannedMallocZone(), cap);
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, cap);
#else
GSIMapInitWithZoneAndCapacity(&map, [self zone], cap);
#endif
@ -204,7 +204,7 @@
(*imp)(aCoder, sel, utype, &count);
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSScannedMallocZone(), count);
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, count);
#else
GSIMapInitWithZoneAndCapacity(&map, [self zone], count);
#endif

View file

@ -157,7 +157,7 @@ static SEL objSel;
at: &count];
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSScannedMallocZone(), count);
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, count);
#else
GSIMapInitWithZoneAndCapacity(&map, GSObjCZone(self), count);
#endif
@ -177,7 +177,7 @@ static SEL objSel;
unsigned int i;
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSScannedMallocZone(), c);
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, c);
#else
GSIMapInitWithZoneAndCapacity(&map, GSObjCZone(self), c);
#endif
@ -223,7 +223,7 @@ static SEL objSel;
unsigned c = [other count];
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSScannedMallocZone(), c);
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, c);
#else
GSIMapInitWithZoneAndCapacity(&map, z, c);
#endif
@ -379,7 +379,7 @@ static SEL objSel;
- (id) initWithCapacity: (unsigned)cap
{
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSScannedMallocZone(), cap);
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, cap);
#else
GSIMapInitWithZoneAndCapacity(&map, GSObjCZone(self), cap);
#endif

View file

@ -228,7 +228,7 @@ static Class mutableSetClass;
(*imp)(aCoder, sel, @encode(unsigned), &count);
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSScannedMallocZone(), count);
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, count);
#else
GSIMapInitWithZoneAndCapacity(&map, [self zone], count);
#endif
@ -247,7 +247,7 @@ static Class mutableSetClass;
unsigned i;
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSScannedMallocZone(), c);
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, c);
#else
GSIMapInitWithZoneAndCapacity(&map, [self zone], c);
#endif
@ -585,7 +585,7 @@ static Class mutableSetClass;
- (id) initWithCapacity: (unsigned)cap
{
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSScannedMallocZone(), cap);
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, cap);
#else
GSIMapInitWithZoneAndCapacity(&map, [self zone], cap);
#endif

View file

@ -138,7 +138,7 @@ static Class NSMutableDataMallocClass;
* Set up map tables.
*/
#if GS_WITH_GC
zone = GSScannedMallocZone();
zone = GSIMapStrongKeyAndVal;
#endif
_clsMap = (GSIMapTable)NSZoneMalloc(zone, sizeof(GSIMapTable_t)*6);
_cIdMap = &_clsMap[1];

View file

@ -950,7 +950,7 @@ static NSLock *cached_proxies_gate = nil;
_requestQueue = [NSMutableArray new];
#if GS_WITH_GC
z = GSScannedMallocZone();
z = GSIMapStrongKeyAndVal;
#endif
/*
* This maps request sequence numbers to the NSPortCoder objects representing

View file

@ -87,8 +87,7 @@ static NSHashTable *uncollectable = 0;
[lock lock];
if (uncollectable == 0)
{
uncollectable = NSCreateHashTableWithZone(NSOwnedPointerHashCallBacks,
0, GSScannedMallocZone());
uncollectable = NSCreateHashTable(NSOwnedPointerHashCallBacks, 0);
}
NSHashInsertIfAbsent(uncollectable, ptr);
[lock unlock];

View file

@ -156,7 +156,7 @@ NSCopyHashTableWithZone(NSHashTable *table, NSZone *zone)
}
#if GS_WITH_GC
zone = GSScannedMallocZone();
zone = GSIMapStrongKeyAndVal;
#endif
t = (GSIMapTable)NSZoneMalloc(zone, sizeof(GSIMapTable_t));
GSIMapInitWithZoneAndCapacity(t, zone, ((GSIMapTable)table)->nodeCount);
@ -217,7 +217,7 @@ NSCreateHashTableWithZone(
GSIMapTable table;
#if GS_WITH_GC
zone = GSScannedMallocZone();
zone = GSIMapStrongKeyAndVal;
#endif
table = (GSIMapTable)NSZoneMalloc(zone, sizeof(GSIMapTable_t));
GSIMapInitWithZoneAndCapacity(table, zone, capacity);

View file

@ -810,7 +810,7 @@ static NSDictionary *makeReference(unsigned ref)
* Set up map tables.
*/
#if GS_WITH_GC
zone = GSScannedMallocZone();
zone = GSIMapStrongKeyAndVal;
#endif
_cIdMap = (GSIMapTable)NSZoneMalloc(zone, sizeof(GSIMapTable_t)*5);
_uIdMap = &_cIdMap[1];

View file

@ -208,7 +208,7 @@ NSCopyMapTableWithZone(NSMapTable *table, NSZone *zone)
}
#if GS_WITH_GC
zone = GSScannedMallocZone();
zone = GSIMapStrongKeyAndVal;
#endif
t = (GSIMapTable)NSZoneMalloc(zone, sizeof(GSIMapTable_t));
GSIMapInitWithZoneAndCapacity(t, zone, ((GSIMapTable)table)->nodeCount);
@ -274,7 +274,7 @@ NSCreateMapTableWithZone(
GSIMapTable table;
#if GS_WITH_GC
zone = GSScannedMallocZone();
zone = GSIMapStrongKeyAndVal;
#endif
table = (GSIMapTable)NSZoneMalloc(zone, sizeof(GSIMapTable_t));
GSIMapInitWithZoneAndCapacity(table, zone, capacity);

View file

@ -584,7 +584,7 @@ static NSNotificationCenter *default_center = nil;
if (self == [NSNotificationCenter class])
{
#if GS_WITH_GC
_zone = GSScannedMallocZone();
_zone = GSIMapStrongKeyAndVal;
#else
_zone = NSDefaultMallocZone();
#endif

View file

@ -1710,7 +1710,7 @@ static IMP _xRefImp; /* Serialize a crossref. */
_eValImp = [self methodForSelector: eValSel];
#if GS_WITH_GC
_zone = GSScannedMallocZone();
_zone = GSIMapStrongKeyAndVal;
#endif
/*
* Set up map tables.

View file

@ -158,7 +158,7 @@ initSerializerInfo(_NSSerializerInfo* info, NSMutableData *d, BOOL u)
if (u)
{
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&info->map, GSScannedMallocZone(), 16);
GSIMapInitWithZoneAndCapacity(&info->map, GSIMapStrongKeyAndVal, 16);
#else
GSIMapInitWithZoneAndCapacity(&info->map, NSDefaultMallocZone(), 16);
#endif

View file

@ -1770,11 +1770,6 @@ static NSZone atomic_zone =
0, 0, 0, 0, 0, 0, 0, 0, @"default", 0
};
static NSZone scanned_zone =
{
0, 0, 0, 0, 0, 0, 0, 0, @"default", 0
};
void *
NSAllocateCollectable(NSUInteger size, NSUInteger options)
{
@ -1862,12 +1857,6 @@ GSAtomicMallocZone (void)
return &atomic_zone;
}
NSZone*
GSScannedMallocZone (void)
{
return &scanned_zone;
}
NSZone*
NSZoneFromPointer (void *ptr)
{
@ -1952,10 +1941,6 @@ NSZoneCalloc (NSZone *zone, size_t elems, size_t bytes)
{
ptr = (void*)GC_MALLOC_ATOMIC(size);
}
else if (zone == &scanned_zone)
{
ptr = (void*)GC_MALLOC(size);
}
else
{
ptr = (void*)malloc(size);
@ -2012,12 +1997,6 @@ GSAtomicMallocZone (void)
return &default_zone;
}
NSZone*
GSScannedMallocZone (void)
{
return &default_zone;
}
void
GSMakeWeakPointer(Class class, const char *iVarName)
{