43 Commits (4891eb9d5f1201ed833ec4d3dbf7fcac0f6e3cc6)

Author SHA1 Message Date
David Chisnall c4ff744620 Audit the runtime for direct access to variable-sized arrays.
Several of the structures now end with an array of structures that may
have other fields added to them that the runtime doesn't know about yet
by a compiler.  Rather than indexing into them directly, we must call an
accessor to find the correct address.

A few of the places where accesses were replaced were in functions where
it is safe because they only deal with versions of the structures that
are dynamically allocated (and will therefore have the correct size).
This was done to simplify future auditing: these fields should be
accessed directly only from the accessor functions in the header and
from the upgraders (currently in legacy.c).

Also fix a few bugs where the sizes weren't being filled in.
8 years ago
theraven 6a27408e9e Fix malloc() / free() imbalance. 15 years ago
theraven 4e7b476aa6 Change [1] to [] for variable length structure elements (C99 - silences array out of bounds errors).
Added fields to the end of the class structure for strong / weak ivar bitmaps (not yet generated by any compiler).

Fixed definition of __sync_swap() so that it works on GCC again.
15 years ago
theraven 69e53c4cdb Better test for presence of __sync_swap(). 15 years ago
theraven 7155f174b7 Don't enable incremental collection. It seems to cause crashing. 15 years ago
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. 15 years ago
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.
15 years ago
theraven 85272c48b9 Improve some comments, minor tweaks to GC. 15 years ago
theraven 61a2ae0f54 Make the canary check look at the address where the canary was stored, not the word before where the canary was stored. 15 years ago
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. 15 years ago
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).
15 years ago
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.
15 years ago
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).
15 years ago
theraven 4ffb19230f Make sure that the statics used to store internal tables are marked as roots. 15 years ago
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. 15 years ago
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.
15 years ago
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) 15 years ago
theraven 6d78040180 Initial support for running finalizers in a separate thread. 15 years ago
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. 15 years ago
theraven 4136ad8413 Do an exhaustive collection before dumping stats in response to a signal. 15 years ago
thebeing 72ec07268d Work around GCC error for inline assembly. 15 years ago
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).
15 years ago
thebeing 32b4432ebc Add correct defines for threaded boehm-gc on linux. 15 years ago
theraven 3769a48cd7 Add an ugly hack to prevent a clever optimiser from realising that it can completely optimise objc_clear_stack() away. 15 years ago
theraven 5b2c24bed3 If LIBOBJC_DUMP_GC_STATUS_ON_SIGNAL is set, dump the GC state in response to kill -$(LIBOBJC_DUMP_GC_STATUS_ON_SIGNAL) {pid}. 15 years ago
theraven cd9ac97fb8 Refine typed allocations slightly. 15 years ago
theraven 0cb2ea01bc Simplify the finalization code slightly. 15 years ago
theraven 5e60899d8e Allow tweaking GC info dump on exit from an environment variable. 15 years ago
theraven 306e10edde Tidy up some of the left-over debugging code for GC mode. 15 years ago
theraven e05c9c2ff5 More GC fixes 15 years ago
theraven 33b7ecb2f8 Don't call -finalize if it doesn't exist. 15 years ago
theraven fcc47bc7ce Fix building without GC support. Still need to make sure that some of the GC functions always work, since they are expected to be no-ops in non-GC mode. 15 years ago
theraven ae4eea1597 Some bug fixes for GC mode. 15 years ago
theraven 898707bf94 Added function for getting reference count. 15 years ago
theraven 368bf3bd1d Add reallocate function. 15 years ago
theraven 88c075893f Call ObjC++ destructors when finalising an object.
Add public APIs required to implement [NSGarbageCollector -enable] and [NSGarbageCollector -disable].
15 years ago
theraven 3385e7a724 Remove dead code. 15 years ago
theraven 9015795dde Use explicitly typed memory for instances. 15 years ago
theraven 9dcc66f7f6 Make sure that associated objects and blocks use GC-scanned memory in GC mode.
Blocks do not yet support __weak bound variables.  This needs fixing before the release.
15 years ago
theraven 2329b7a1ec Change spelling to be consistent with Apple. 15 years ago
theraven 929f8f95b4 Improved a few GC functions.
Added objc-auto.h header, providing (documented) public interfaces to this
functionality.
15 years ago
theraven ef03a4bdb0 Add objc_gc_allocate_collectible() function, which can be used to implement NSAllocateCollectible(). 15 years ago
theraven ad16172625 First pass at implementing Apple-compatible GC using Boehm. Still needs some tidying, but the following work:
- __strong pointers, preventing objects from being freed

_ __weak pointers are automatically freed when the last remaining __strong pointer goes away

- objc_gc_{retain,release}_np() functions, which can be used to implement CFRetain() and CFRelease() (adds an reference count - the object will not be collected until after its last retain is gone.
15 years ago