489 Commits

Author SHA1 Message Date
theraven
61bc10ad4c Remove debugging line accidentally committed. 2011-07-04 16:43:38 +00:00
theraven
73891aaecc Two small ARC fixes:
- Make objc_retain() check for stack blocks and implicitly copy them.  This fixes the case where a block pointer is stored in an object-typed variable and is assigned.
- Tweak objc_retainAutoreleaseReturnValue() so that the ARC optimiser doesn't detect that the body looks like a call to objc_retainAutoreleaseReturnValue() and replace it with an infinitely recursive call.

The second fix now means that arc.m will compile with clang without producing a function that calls itself.
2011-07-04 15:04:56 +00:00
theraven
fce7c776b6 Tweak build to only enable optimisation in non-debug builds. 2011-07-04 14:44:04 +00:00
theraven
9b9c801805 Fix off-by-one error in buffer.h 2011-07-04 14:43:32 +00:00
theraven
9d6154041c Make sure that autoreleased returned objects are destroyed when the autorelease
pool is destroyed.  They were previously being destroyed on thread termination,
this ensures that their lifespan is predictable.
2011-07-04 12:22:23 +00:00
theraven
7155f174b7 Don't enable incremental collection. It seems to cause crashing. 2011-07-04 12:21:23 +00:00
theraven
aaeb22d682 Updated README to briefly describe ARC. 2011-07-04 12:17:31 +00:00
theraven
79e29ba48f Copied ANNOUNCE to ANNOUNCE.1.5 in preparation for 1.5 release. 2011-07-04 12:11:14 +00:00
theraven
f6923d7472 Improve objc_moveWeak() implementation. 2011-07-04 11:57:13 +00:00
theraven
7b6ba21ce5 Small bug fixes:
- Don't call C++ constructors if they don't exist.
- Don't check the owner of retain / release methods if they are not implemented.
- Add arc.m as a file to ignore when checking for GC compatibility.
2011-07-04 11:28:33 +00:00
theraven
e34be81404 Fix fast-path test to work with subclasses correctly. 2011-07-03 15:29:52 +00:00
theraven
81131acfbc Fix LLVM trunk compatibility. 2011-07-03 12:52:49 +00:00
theraven
34f7baf8d7 Added a fast path for ARC. Now, if a class implements ARC-compatible retain / release / autorelease methods, we don't call them at all. Instead, we inline them in the ARC accessors. This avoids all of the overhead of the message send (lookup and call) and should make ARC quite a bit faster than manual reference counting. 2011-07-03 11:14:29 +00:00
theraven
6a37a8c3bc More ARC tweaks. 2011-06-30 14:16:52 +00:00
theraven
55191e34ae Fix the fast path. It should fall back to doing what the slow path does if the other half is not using it. 2011-06-30 12:56:59 +00:00
theraven
3e88293f74 Added mention of ARC to ANNOUNCE. 2011-06-30 09:40:24 +00:00
theraven
e3c836b090 Added fast path for objc_autoreleaseReturnValue() and objc_retainAutoreleasedReturnValue().
In a simple example:

- foo { return self; }

void someFunction(void)
{
	id a = foo;
	...
}

In ARC mode, this expands to:

- foo { return objc_retainAutoreleaseReturnValue(self); }

void someFunction(void)
{
	id a = objc_retainAutoreleasedReturnValue(foo);
	...
}

In the slow path, this is equivalent to:

- foo { return [[self retain] autorelease]; }

void someFunction(void)
{
	id a = [foo retain];
	...
	[a release];
}

The fast path skips the autorelease / retain pair.  The return value is stored
in thread-local storage temporarily and then retrieved, the retain balancing
out the autorelease.

This gives a 50% speedup on a single thread.  It also avoids some atomic
operations.
2011-06-30 09:24:14 +00:00
theraven
36d21882ec Documented objc-arc.h 2011-06-29 14:36:20 +00:00
theraven
bc87ed22e1 Implemented support for __weak with ARC.
ARC functions are all now exposed in a header, but not yet documented.  See the ARC ABI spec for now:

http://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime
2011-06-29 13:12:02 +00:00
theraven
065531b12e Remove accidentally-committed WIP ARC code. 2011-06-29 12:04:47 +00:00
theraven
b633338a7a Remove indirection from alias table. 2011-06-29 12:03:41 +00:00
theraven
9967d85d60 Fixes to be blocks runtime. Make sure that objects are not prematurely deallocated if referenced by multiple blocks. 2011-06-29 10:41:26 +00:00
theraven
9b70b22eee Use __unsafe_unretained instead of const for returning protocol arrays. Let's not break everyone's code, even if we really want to. 2011-06-29 10:12:29 +00:00
theraven
b5380d50d3 Added support for ARC.
Weak references are still not supported, but code that doesn't use them (i.e. any code that wants to be compatible with OS X 10.6) will work fine.

The current implementation is VERY inefficient and has a large number of missed optimisation opportunities: this is the 'make it right' phase, and should be almost equivalent to explicit retain / release code.
2011-06-28 16:29:42 +00:00
theraven
6412c7a4e7 And another one... 2011-06-24 14:36:54 +00:00
theraven
9ef84a982c Remove redundant include. 2011-06-24 14:32:15 +00:00
theraven
fbdfc0b9eb Allow packagers to more easily rename the library.
Patch by Sebastian Reitenbach!
2011-06-23 10:30:56 +00:00
theraven
85272c48b9 Improve some comments, minor tweaks to GC. 2011-06-23 10:30:10 +00:00
theraven
1f681c8464 Added some GC docs to the readme. 2011-05-30 15:14:20 +00:00
theraven
61a2ae0f54 Make the canary check look at the address where the canary was stored, not the word before where the canary was stored. 2011-05-30 11:19:44 +00:00
theraven
1c847cedd1 Remove GC_no_dls for now. This can be safely set if all static variables used to store pointers are id or are explicitly marked __strong, which is not (yet) the case in GNUstep. 2011-05-30 11:13:25 +00:00
theraven
851328268c Expand the coverage of canaries to object allocations, expand logging to object
allocations and all deallocations.  It's now possible to implement
malloc_history entirely parsing the dump file (or doing /dev/fd style tricks
send it straight to a monitoring process).
2011-05-29 22:13:35 +00:00
theraven
c9e54c382d Tweak auto-copy code. Now it only copies classes that are explicitly
registered to be copied on heap assignment.  By default, this is just
_NSConcreteStackBlock.  Other classes can be registered (LanguageKit should
register BlockClosure to make sure that Smalltalk works).

Fred: This makes the stuff that we discussed briefly at FOSDEM possible in GC
mode: We can allocate a GSStackEvent subclass of NSEvent on the stack.  If it
implements a -copy method that returns an NSEvent and is registered with the
runtime in this way, then any code that assigns it anywhere on the heap will
end up implicitly creating a heap copy.
2011-05-29 21:59:50 +00:00
theraven
b296b18571 Improvements to GC mode:
- Add objc_gc_collectable_address() to determine whether a pointer is managed
  by the GC

- If LIBOBJC_CANARIES is set (optionally to a random number seed) then store a
  canary value after every allocation returned by
  objc_gc_allocate_collectable() and, when it is finalised, check that the
  canary has not been modified, aborting if it has.  This catches some
  heap-buffer overflows, and currently causes GNUstep to abort.

- If LIBOBJC_LOG_ALLOCATIONS is set to a file name, log all GC-managed
  allocations to that file.  This gives something like malloc_history on OS X.

- objc_memmove_collectable() now guarantees that all copied pointers remain
  visible to the GC at all times (which was the point of the function - the
  original implementation was just a quick stub).
2011-05-29 21:28:27 +00:00
theraven
ff1e691c3b And some more... 2011-05-29 14:38:14 +00:00
theraven
4a78269815 Removed debugging line accidentally committed. 2011-05-29 14:36:05 +00:00
theraven
4ffb19230f Make sure that the statics used to store internal tables are marked as roots. 2011-05-29 14:27:41 +00:00
theraven
8f530849fd When assigning a pointer to an object that is allocated on the stack to the heap, send a -copy message. This lets you cast blocks to id and then assign them to ivars without anything breaking. Apple's 'solution' to this is to segfault, which is not particularly elegant. This code is also quite an ugly hack (it just checks whether the object is allocated within a couple of pages of the current stack frame), so I might remove it before release. 2011-05-29 13:53:15 +00:00
theraven
e7767baf50 Don't send retain / release messages in GC mode when copying object pointers into blocks. 2011-05-29 13:50:46 +00:00
theraven
d1199844cb Lock the GC mode once something has queried it. All of the GNUstep code that
does run-time detection of whether to use GC calls objc_collecting_enabled()
(sometimes indirectly, via NSGarbageCollector) to see if we're in GC mode.
After any of these calls, it is not safe to switch modes.
2011-05-28 15:10:03 +00:00
theraven
fe5d1b892a Tweak GC check, make sure GC_init() is called even when ObjC code isn't using GC (stuff internal to the runtime may be) 2011-05-28 14:38:02 +00:00
theraven
d73eb8f634 Expose another function in the header. 2011-05-28 13:24:24 +00:00
theraven
6d78040180 Initial support for running finalizers in a separate thread. 2011-05-28 13:07:11 +00:00
theraven
0c8faf1961 Sometimes people assign things like classes to __weak pointers. This confuses the GC, because it expects to be able to finalize / delete things that are the target of disappearing links. 2011-05-28 11:04:47 +00:00
thebeing
e661e203d4 Re-enable function inlining. 2011-05-27 19:12:18 +00:00
thebeing
1653751263 Use -lgc on linux platforms. 2011-05-27 18:11:53 +00:00
theraven
4136ad8413 Do an exhaustive collection before dumping stats in response to a signal. 2011-05-27 18:06:39 +00:00
thebeing
72ec07268d Work around GCC error for inline assembly. 2011-05-27 18:06:20 +00:00
theraven
0c72e2e418 Use typed allocations for the hash table entries. This makes sure that the GC won't treat the jump table bitfield as a pointer.
Store the refcount structures inside the hash table, rather than in a chained structure.  This uses less space and should be easier for the GC to scan (less cache used).
2011-05-27 17:40:58 +00:00
thebeing
32b4432ebc Add correct defines for threaded boehm-gc on linux. 2011-05-27 15:27:05 +00:00