67 Commits (2855d1771478e1e368fcfeb4d56aecbb4d9429ca)

Author SHA1 Message Date
Hugo Melder e882423e5a
PowerPC {32, 64}-bit Block Trampolines (#272)
* Implement PowerPC block trampoline

* Adjust pagesize on ppc64

* Skip UnexpectedException test for PowerPC

* Move PAGE_SIZE to asmconstants.h

* Use PAGE_SIZE and PAGE_SHIFT macros for PowerPC

* Add ppc64el and powerpc qemu-crossbuild targets

* Add NO_SAFE_CACHING definition and guards

* Do not export objc_method_cache_version on ppc32

---------

Co-authored-by: David Chisnall <davidchisnall@users.noreply.github.com>
2 years ago
David Chisnall 377a81d237 Add support for fast-path alloc / init methods and direct methods.
The fast paths follow the pattern that we established for fast ARC:
Framework base classes can opt in by implementing a `+_TrivialAllocInit`
method.

This opt-in behaviour is inherited and is removed implicitly in any
subclass that implements alloc or init methods (alloc and init are
treated independently).

Compilers can emit calls to `objc_alloc(cls)` instead of `[cls alloc]`,
`objc_allocWithZone(cls)` instead of `[cls allocWithZone: NULL]`, and
`objc_alloc_init` instead of `[[cls alloc] init]`.

Direct methods don't require very much support in the runtime.  Apple
reuses their fast path for `-self` (which is supported only in the Apple
fork of clang, not the upstream version) for a fast init.  Given that
the first few fields of the runtime's class structure have been stable
for around 30 years, I'm happy moving the flags word (and the
initialised bit, in particular) into the public ABI.  This lets us do a
fast-path check for whether a class is initialised in class methods and
call `objc_send_initialize` if it isn't.  This function is now exposed
as part of the public ABI, it was there already and does the relevant
checks without invoking any of the message-sending machinery.

Fixes #165 #169
2 years ago
Earl Robsham cd50e72f81
Fix lock-ordering during init (#237)
Reorders how locking is handled in `objc_send_initialize()` to prevent a deadlock.
Previously, contention on the low level spinlocks could cause a very intermittent deadlock:
  - Thread A : `objc_send_initialize()` holds the runtime lock, then tries to acquire the object lock on the metaclass, which needs to initialize the mutex for the new metaclass inside `referenceListForObject()`, so it tries to lock the `lock_for_pointer()` / `lock_spinlock()`
  - Thread B : `referenceListForObject()` holds a spinlock for an unrelated object while running `initHiddenClassForObject()` -> `allocateHiddenClass()`, which tries to acquire the runtime lock
If the metaclass object pointer in Thread A hashes to the same spinlock as the object in thread B, the runtime lock ends up deadlocked forever.
3 years ago
David Chisnall b39a42252e Hide ARC warnings behind an off-by-default flag. 6 years ago
David Chisnall 2d87ac45a1 Fix logging macro 6 years ago
rfm 8dbee52d24 Fix fast-ARC checks.
Check for release and autorelease as well as for retain.
6 years ago
Dustin Howett f392ff1870 Fix dtable rebase and add a test for a missing case
The dtable rebasing rework in b81df02b broke the inheritance of
superclass methods from a superclass that had already been initialized.
7 years ago
David Chisnall 4a8d125b3f Fix linkage type for objc_method_cache_version.
This was accidentally common linkage, so ended up with copy relocations.
7 years ago
David Chisnall 4e9fd2ec8a Rename objc_slot and objc_slot_v1.
The objc_slot type was exposed via public interfaces and the renaming
broke things (including the GNUstep build).
8 years ago
David Chisnall 8eb06a3b15 Improve ARC test and fix bugs it uncovered.
This cleans up handling of objects that are not reference counted and
makes their interactions with ARC more consistent.  We should probably
generalise this somewhat - it currently special cases NSConstantString
and NSGlobalBlock, but it would be nice to have an API for constant
objects.
8 years ago
David Chisnall b81df02b91 Merge branch 'master' into newabi
Simplify the setSubclass dtable updating mechanism.
8 years ago
David Chisnall 11637010ad Rename method_list.h to method.h
Work around the fact that LaTeX really doesn't like file names with
underscores...
8 years ago
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
David Chisnall a8752cd842 Clean up method / slot lookup interfaces. 8 years ago
David Chisnall a9a2ed6b10 Refactor to use `objc_method` as the slot.
This change set incorporates a number of changes that all needed to
happen together:

 * The imp is now the first field of the `objc_method` structure.  This
   makes it possible to extend the structure without breaking anything
   that relies on being able to access the IMP.
 * There is no owner in the slot, so we must use other mechanisms for
   determining the owner of a method (e.g. whether the same method appears
   in the superclass)
 * Again, because there is no owner in the slot, we can't use this as a
   fast path for finding the C++ construct / destruct methods.  These are
   now cached in the class structure when they are found.
 * The version field is gone from the slot and now we provide a global
   version.  This is based on the observation that method replacements
   are relatively infrequent and the overhead of invalidating all method
   caches is cheaper than adding extra state for every (class, method)
   pair.
 * A number of the runtime functions are simplified because replacing
   the IMP in a `Method` now implicitly updates the dtable.
8 years ago
David Chisnall 314a4167ca Remove low memory profile.
This hasn't been tested for a long time and probably doesn't work.
8 years ago
Dustin Howett 82d4d3fbfd merge dtables inplace, don't hold rt lock while initializing 8 years ago
Dustin L. Howett a421d62821 teach class_setSuperclass about metaclasses, subclass lists, and dtables 8 years ago
David Chisnall 76e7d4b07f Merge branch 'master' into newabi 8 years ago
David Chisnall bdc20a8bab Add some debugging help for ARC-compilance. 8 years ago
David Chisnall 12d1ea62a4 Merge branch 'master' into newabi 9 years ago
Niels Grewe 6b285936be Avoid a deadlock
As described in gnustep/libobjc2#20
9 years ago
David Chisnall c3c81796ca Rework slot handling so that the fields that are used for dispatch are
at the start of the structure, making it easier to change the layout in
the future.

Also clean up the growth of various fields and consolidate some of the
metadata into a pointer to the `struct objc_method`.
10 years ago
David Chisnall d44bf5655b Ensure that objects that support ARC will use ARC, even if they are
created without sending a message to the class.

Also ensure that protocols are always valid objects so that ARC doesn't
become confused.
10 years ago
David Chisnall 5107130277 Move the data for sparse arrays into the tree structure.
This saves one load on the message send path for each tree depth (2
loads in the common case, 3 if you have a lot of selectors), which
should improve cache usage considerably.

Note: This is a checkpoint commit.  Currently, every objc_msgSend()
implementation except for x86-64 is broken.
10 years ago
theraven 39b6c20d5e Fix missing unlock.
Submitted by:	Nick Tuckett
12 years ago
theraven 3f94730ba8 Define ENOTSUP in the case where it actually is used if it isn't defined. 13 years ago
theraven e6d4229169 Don't forget to expand the tracing dtable... 13 years ago
theraven 68a4607f16 Define ENOTSUP if it isn't defined already. 13 years ago
theraven f50bc6cf33 Added support for tracing message sends to the runtime.
Currently x86-64 only.
13 years ago
theraven eb234ea26a Fix the case where the number of selectors grows to more than 2^16 and we need
to fall back to 3-level dtables.  

Added a test case that registers far more selectors than a sane program
contains and tries to use them.
13 years ago
theraven ca25388b37 Fix a lock-order reversal where one thread calls some dtable-manipulating
function while another is initializing.
13 years ago
theraven 85fd42dd5a Fix an infinite loop when first sending a message to a class that has a hidden class. 13 years ago
theraven 304593924f Add missing unlock.
Patch by Philippe Roussel!
14 years ago
theraven 2d835cffa6 Fix the lock order when sending +initialize, so that we don't hold a lock that
is meant to protect a runtime data structure while trying to acquire a lock
that must be held when running user code that may take an indeterminate amount
of time and may trigger deadlocks.
14 years ago
theraven 855f2601c9 Fix some corner cases where exceptions are thrown through +initialize. 14 years ago
theraven 27452f82f0 Some bug fixes. 14 years ago
theraven 26d86e101c Inherit +initialize methods. 15 years ago
theraven 8af52846b7 Small object (hidden in a pointer) support. 15 years ago
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.
15 years ago
theraven e34be81404 Fix fast-path test to work with subclasses correctly. 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 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
theraven 12385fcb1e Tidy up low memory profile to use slots directly. 15 years ago
theraven 709f238364 Sync on the metaclass, not the class, since that's what we're actually testing... 15 years ago
theraven f9d1b5f356 Clean up the low memory profile. Now passes all GNUstep-base and EtoileFoundation tests, just like the default profileand uses 5-10% less (total) RAM in GORM. Worth benchmarking to see how much performance this costs.
Updated the release announcement.
15 years ago
theraven 7b49755964 Dtable cleanup cleanups. 15 years ago
theraven bad36445e3 Improve efficiency of dtable updates from categories.
Make +initialize sending exception safe.
15 years ago
theraven 987ab88a94 Don't do hidden-class transforms for classes, just dangle the look-aside data off the class structure.
Individually lock classes so that +initialize can be sent concurrently to two different classes in two different threads.
15 years ago
theraven d51500184c More cleanups. Stop using __ identifiers for internal stuff now that it's properly marked private and we don't have to worry about conflicts. 15 years ago