Author: thebeing
Date: Fri Oct 28 10:30:16 2016
New Revision: 40183
URL: http://svn.gna.org/viewcvs/gnustep?rev=40183&view=rev
Log:
Re-enable fast-ARC mode when possible.
Define _ARCCompliantRetainRelease on 32bit platforms and when
we have copmiler intrinsics for atomic operations that allow us
to extend the refcount field to match libobjc2.
The effective maximum reference count is still 2^24 - 1 in either
case.
Modified:
libs/base/trunk/ChangeLog
libs/base/trunk/Source/NSObject.m
Modified: libs/base/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/ChangeLog?rev=40183&r1=40182&r2=40183&view=diff
==============================================================================
--- libs/base/trunk/ChangeLog (original)
+++ libs/base/trunk/ChangeLog Fri Oct 28 10:30:16 2016
@@ -1,3 +1,11 @@
+2016-10-28 Niels Grewe <[email protected]>
+
+ * Source/NSObject.m: Re-enable fast-ARC mode when memory layout
+ and atomic operations support permit. This changes the size of the
+ field where the reference count is stored to the size of a pointer
+ in some configurations.
+ The effective maximum reference count is still 2^24 - 1.
+
2016-10-27 Wolfgang Lux <[email protected]>
* Source/NSObject.m: Comment out _ARCCompliantRetainRelease for
Modified: libs/base/trunk/Source/NSObject.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSObject.m?rev=40183&r1=40182&r2=40183&view=diff
==============================================================================
--- libs/base/trunk/Source/NSObject.m (original)
+++ libs/base/trunk/Source/NSObject.m Fri Oct 28 10:30:16 2016
@@ -187,15 +187,29 @@
#endif
+/*
+ * Traditionally, GNUstep has been using a 32bit reference count in front
+ * of the object. The automatic reference counting implementation in
+ * libobjc2 uses an intptr_t instead, so NSObject will only be compatible
+ * with ARC if either of the following apply:
+ *
+ * a) sizeof(intptr_t) == sizeof(int32_t)
+ * b) we can provide atomic operations on pointer sized values, allowing
+ * us to extend the refcount to intptr_t.
+ */
+#ifdef GS_ARC_COMPATIBLE
+#undef GS_ARC_COMPATIBLE
+#endif
#if defined(__llvm__) || (defined(USE_ATOMIC_BUILTINS) && (__GNUC__ > 4 ||
(__GNUC__ == 4 && __GNUC_MINOR__ >= 1)))
/* Use the GCC atomic operations with recent GCC versions */
-typedef int32_t volatile *gsatomic_t;
+typedef intptr_t volatile *gsatomic_t;
+typedef intptr_t gsrefcount_t;
#define GSATOMICREAD(X) (*(X))
#define GSAtomicIncrement(X) __sync_add_and_fetch(X, 1)
#define GSAtomicDecrement(X) __sync_sub_and_fetch(X, 1)
-
+#define GS_ARC_COMPATIBLE 1
#elif defined(_WIN32)
@@ -203,7 +217,7 @@
*/
typedef int32_t volatile *gsatomic_t;
-
+typedef int32_t gsrefcount_t;
#ifndef _WIN64
#undef InterlockedIncrement
#undef InterlockedDecrement
@@ -221,6 +235,7 @@
*/
typedef int32_t volatile *gsatomic_t;
+typedef int32_t gsrefcount_t;
#define GSATOMICREAD(X) (*(X))
@@ -254,6 +269,7 @@
#elif defined(__PPC__) || defined(__POWERPC__)
typedef int32_t volatile *gsatomic_t;
+typedef int32_t gsrefcount_t;
#define GSATOMICREAD(X) (*(X))
@@ -292,6 +308,7 @@
#elif defined(__m68k__)
typedef int32_t volatile *gsatomic_t;
+typedef int32_t gsrefcount_t;
#define GSATOMICREAD(X) (*(X))
@@ -316,6 +333,7 @@
#elif defined(__mips__)
typedef int32_t volatile *gsatomic_t;
+typedef int32_t gsrefcount_t;
#define GSATOMICREAD(X) (*(X))
@@ -382,6 +400,17 @@
#endif
+#ifndef GS_ARC_COMPATIBLE
+/*
+ * If we haven't previously declared that we can work in fast-ARC mode,
+ * check whether a point is 32bit (4 bytes) wide, which also enables ARC
+ * integration.
+ */
+# if __SIZEOF_POINTER__ == 4
+# define GS_ARC_COMPATIBLE 1
+# endif
+#endif
+
#if defined(__GNUC__) && __GNUC__ < 4
#define __builtin_offsetof(s, f) (uintptr_t)(&(((s*)0)->f))
#endif
@@ -438,7 +467,7 @@
if (allocationLock != 0)
{
#if defined(GSATOMICREAD)
- int32_t result;
+ gsrefcount_t result;
result = GSAtomicDecrement((gsatomic_t)&(((obj)anObject)[-1].retained));
if (result < 0)
@@ -597,6 +626,8 @@
* the start of each object.
*/
+// FIXME rewrite object allocation to use class_createInstance when we
+// are using libobjc2.
inline id
NSAllocateObject (Class aClass, NSUInteger extraBytes, NSZone *zone)
{
@@ -735,15 +766,7 @@
* </p>
*/
@implementation NSObject
-#if 0
-/* Commented out for now, since the representation of object retain
- * counts in gnustep-base and libobjc2 currently is not compatible.
- * While gnustep-base uses int32_t libobjc2 uses intptr_t, which makes
- * a difference on 64-bit architectures.
- */
-// FIXME Rewrite retain/release to use objc_retain/objc_release and
-// similarly object allocation to use class_createInstance when we
-// are using libobjc2.
+#if defined(GS_ARC_COMPATIBLE)
- (void)_ARCCompliantRetainRelease {}
#endif
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs