Commit Graph

43 Commits

Author SHA1 Message Date
Dmitri Hrybenko
2a19887dec Allow SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS to work on non-Darwin
Swift SVN r23826
2014-12-10 04:34:19 +00:00
John McCall
3b4e0d307e Intrinsic support for pinning.
Using the intrinsics is obnoxious because I needed them
to return Builtin.NativeObject?, but there's no reasonable
way to safely generate optional types from Builtins.cpp.
Ugh.

Dave and I also decided that there's no need for
swift_tryPin to allow a null object.

Swift SVN r23824
2014-12-10 00:52:48 +00:00
John McCall
3f46b30ca4 Add runtime functions to "pin" a native Swift object.
Pinning an object prevents it from being deallocated,
just like retaining it, but only one client can own the
pin at once.  Sensible "sharing" of the pin can occur
if attempts are perfectly nested.  It is efficient to
simultaneously query the pin state of an object in
conjunction with its strong reference count.

This combination of traits makes pinning suitable for
use in tracking whether a data structure backed by
an object is undergoing a non-structural modification:

- A structural change would require unique ownership
  of the object, but two non-structural changes (to
  different parts of the object) can occur at once
  without harm.  So a non-structural change can check
  for either uniqueness or a pin and then, if necessary,
  assert the pin for the duration of the change.
  Meanwhile, this act of asserting the pin prevents
  simultaneous structural changes.

- A very simple code-generation discipline leads to
  changes being perfectly nested as long as they're
  all performed by a single thread (or synchronously).
  Asynchrony can introduce imperfect nesting, but it's
  easy to write that off as a race condition and hence
  undefined behavior.

See Accessors.rst for more on both of these points.

Swift SVN r23761
2014-12-06 09:46:01 +00:00
Joe Groff
dfac9181dd Runtime: Add ObjC weak referencing support to SwiftObject.
We were missing -_tryRetain, -_isDeallocating, -allowsWeakReference and -retainWeakReference implementations on SwiftObject, so forming an ObjC weak reference to a pure Swift object always failed and produced a nil reference. Fixes rdar://problem/18637774.

This can be reapplied now that we properly call objc_destructInstance on deallocation.

Swift SVN r23070
2014-11-02 21:03:21 +00:00
Joe Groff
0885c5617e Runtime: Invoke objc_destructInstance before deallocating class instances.
This is necessary to clean up associated objects and ObjC weak references to the object. rdar://problem/18637774

Swift SVN r23068
2014-11-02 21:03:18 +00:00
Greg Parker
c6a88262cf [stdlib] Scrap bit-rotted FastEntryPoints.s. Rewrite refcounts using __atomic.
Generated code on x86_64 for swift_retain and swift_release and 
swift_allocObject are unchanged. arm64 is improved by using weaker 
memory barriers, fixing rdar://17423624.


Swift SVN r22887
2014-10-23 08:22:48 +00:00
Greg Parker
330752b749 Revert r22710 and r22711 implementing ObjC weak ref methods on SwiftObject.
This is still incomplete and needs more work. rdar://18637774.


Swift SVN r22717
2014-10-14 01:33:29 +00:00
Joe Groff
82f6260c64 Runtime: Add ObjC weak referencing support to SwiftObject.
We were missing -_tryRetain, -_isDeallocating, -allowsWeakReference and -retainWeakReference implementations on SwiftObject, so forming an ObjC weak reference to a pure Swift object always failed and produced a nil reference. Fixes rdar://problem/18637774.

Swift SVN r22710
2014-10-13 22:12:39 +00:00
Dave Abrahams
74e27aaab1 [stdlib] uniqueness checking for users
Make unique reference checking available to users, making ManagedBuffer
a complete facility for building COW value types.  Also rationalize the
way we name and organize the runtime primitives we ultimately call.

Swift SVN r22594
2014-10-08 04:48:52 +00:00
Dave Abrahams
cc9bc0c274 [stdlib] Kill _swift_isUniquelyReferenced @asmname
Swift SVN r22576
2014-10-07 21:40:48 +00:00
Dmitri Hrybenko
7a53df0d37 Remove unused includes
Swift SVN r22321
2014-09-28 01:16:14 +00:00
Joe Groff
7a08716de3 Runtime: Factor out a helper function on Metadata to say when metadata refers to a class type.
Rename the existing misleadingly-named "isClassType" to "isClassObject", and document that it refers to (swift or ObjC) class objects, the latter of which aren't always type metadata.

Swift SVN r22153
2014-09-21 00:18:16 +00:00
Michael Gottesman
e8df864581 [stdlib] Change _fixLifetime<T> to use Builtin.fixLifetime now that we lower fix_lifetime to swift_keepAlive in IRGen.
Also remove the old swift_keepAlive and rename swift_keepAlive2 => swift_fixLifetime.

rdar://16464507

Swift SVN r21723
2014-09-04 22:58:37 +00:00
Michael Gottesman
9514ba5a7d [irgen] Lower fix_lifetime => swift_keepAlive().
I introduced a function swift_keepAlive2() which has a different signature from
swift_keepAlive() until I can verify that the stdlib is using the new
infrastructure.

The difference in signature is that swift_keepAlive2 takes just a pointer while
swift_keepAlive also takes a metadata value that is not necessary for our
purposes anymore.

Swift SVN r21718
2014-09-04 21:53:18 +00:00
Dave Abrahams
0085b94509 [stdlib] AnyObject wrapper for bridging purposes
As part of the evolution toward a one-word array layout, create a type
that can be used to efficiently store Cocoa or Native class instances
and discriminate between them.

Swift SVN r21469
2014-08-27 00:04:25 +00:00
Greg Parker
fe8618a3d2 Scrap the custom allocator until we have time to fix it.
The allocator's crimes include:
* It uses OS SPI that must not be used by non-OS apps.
* It does not play well with memory debugging tools like Instruments.
* It does not return memory to the OS in response to memory pressure.
* It is less tested than we would like because many configurations 
  inadvertently turn it off (such as running from Xcode).
* Its per-thread magazine implementation does not actually work.
* Its "try alloc" flag is incompletely implemented and never used.
* Its "zero fill" flag is unimplemented and inconsistently used.



Swift SVN r20757
2014-07-30 14:11:40 +00:00
Dave Abrahams
21669b3aee [stdlib] Add "Mutable" to [Autoreleasing]UnsafePointer
UnsafePointer becomes UnsafeMutablePointer
AutoreleasingUnsafePointer becomes AutoreleasingUnsafeMutablePointer

Swift SVN r20316
2014-07-22 16:56:23 +00:00
Doug Gregor
37d69a4207 Allocator: round the size of an allocation up to the alignment on all allocation and deallocation paths.
We were rounding the size up to the alignment when allocating a new object (swift_allocObject) but not when directly allocating memory for a non-object (swift_slowAlloc). The deallocation code wasn’t rounding the size up to the alignment at all. Overall, this meant that we would get the wrong index into the allocation cache when deallocating an object whose size got rounded in a way that affects the index.

Fixes <rdar://problem/17542859>, where println(5) would fail on the 32-bit iOS simulator when building the runtime without NDEBUG (so we get extra checking) and the standard library is built without optimization (which keeps a certain 33-byte allocation on the heap). The Interpreter/SDK/objc_cast.swift test triggers this when built under those conditions.

Swift SVN r19499
2014-07-03 02:11:50 +00:00
Greg Parker
6493bee517 Remove now-unnecessary extra retain during heap object destruction.
RC_DEALLOCATING_BIT prevents re-entrance into the destructor 
due to balanced retain/release during destruction.


Swift SVN r19060
2014-06-21 00:36:44 +00:00
Michael Gottesman
e269523e48 Reintroduce discriminator bit stripping in the runtime that was reverted
when I undid the array enum change in r19026.

Swift SVN r19028
2014-06-20 02:40:57 +00:00
Michael Gottesman
8de060ff3f Revert "[stdlib] mask unused bits in uniqueness checks"
Revert "[stdlib] Use an enum for ArrayBuffer storage"

This reverts commit r18996.
This reverts commit r18954.

The optimizer is not ready yet to handle this change especially given
the time until Beta 3. After speaking with DaveA, we agreed to revert
this and take such large changes onto private branches until we are sure
that the optimizer is ready to handle them rather than risking
performance regressions due to hitting the "optimization cliff".

Swift SVN r19026
2014-06-20 01:41:04 +00:00
Dave Abrahams
2b82e8988f [stdlib] mask unused bits in uniqueness checks
Also update ArrayBuffer to take advantage of it.

This change allows us to pass a word-sized enum with a native object
reference payload directly to the runtime, without switching on the enum
to unwrap the contents.  Even though that unwrapping was semantically
equivalent to bit masking, it was causing fits in the optimizer.

Swift SVN r18996
2014-06-19 02:32:07 +00:00
John McCall
329abe543d Pass an alignment mask during heap array allocation,
not an alignment value.

Assert that various entrypoints get an alignment mask.

Get everything uniformly passing an assertion about
dealloating an object with the correct allocation
size; don't actually enable the assertion yet, though.

rdar://16989632

Swift SVN r18550
2014-05-22 01:58:05 +00:00
John McCall
5ddee671b6 Provide a hacky hook for specifying a class's instance size
and alignment for the purposes of deallocation.

If a class contains a method named __getInstanceSizeAndAlignMask,
and it takes no arguments and returns a pair of words, call
that method directly in order to get the size and alignment
mask instead of trusting the class's formal size and alignment.

This is not a replacement for a proper language solution for
custom allocation, but it'll suffice to fix some immediate
problems with HeapBufferStorage.

If we decide we like this approach, we should really raise
the deallocating destructor up to SIL.

rdar://16979846

Swift SVN r18485
2014-05-21 07:22:39 +00:00
John McCall
4fccb0607e Don't leak the allocation for objects with outstanding
weak references at deallocation time.

Also, directly call swift_slowDealloc in swift_weakRelease
instead of incorrectly recursing back into
swift_deallocObject.

Also document the correctness of the fast-path check
we do in swift_deallocObject.

rdar://16967569

Swift SVN r18475
2014-05-21 00:22:00 +00:00
Dave Zarzycki
19987bfc59 Runtime: fix zeroing weak
This bug was a result of code drift between the hand written assembly
and the generic code. Thankfully we disabled the hand written assembly a
while a go, which made this bug easier to find.

This fixes: <rdar://problem/16954674>

Swift SVN r18425
2014-05-19 18:22:32 +00:00
John McCall
059ed4cd10 Propagate alignment arguments around through the
slow allocation/deallocation APIs.

Swift SVN r18160
2014-05-16 01:40:36 +00:00
Dave Zarzycki
9dd82e3373 Heap: slowDealloc() design feedback from John
Swift SVN r18083
2014-05-14 23:04:33 +00:00
Dave Abrahams
3606513c36 [stdlib] Factor out _fixLifetime
Apparently Builtin.fixLifetime isn't yet respected
(<rdar://problem/16464507>) and calls to that and swift_keepAlive were
getting scattered around randomly.  Let's have a convenient library
function instead.

Swift SVN r17493
2014-05-05 23:21:47 +00:00
Dave Abrahams
c20f08c596 [stdlib] Don't bake refcounting details into apps
DaveZ says: In the future we're likely to store "associated objects,"
which will make inlining the introspection of the reference count
problematic.

Swift SVN r17481
2014-05-05 19:26:43 +00:00
Dave Zarzycki
1326006ed8 Runtime heap/introspection: Instruments team feedback
Swift SVN r17274
2014-05-02 21:41:16 +00:00
Dave Zarzycki
1930222f3b Runtime: Instruments support plan B
Rather than go through reentrant and problematic contortions to make Swift
work with the existing Instruments hooks, they agreed to just patch some
globals that we provide to get their logic to be activated.

Swift SVN r17144
2014-05-01 06:39:45 +00:00
Dave Zarzycki
7fedcbcffc Runtime: standards compliance feedback
Swift SVN r16828
2014-04-25 18:28:26 +00:00
Dave Zarzycki
128027dd4d Runtime: abort on resurrection
Also fix a latent bug in the logic in the disabled code to scribble over memory durring dealloc.

<rdar://problem/15855042> QoI: abort on resurrection

Swift SVN r16827
2014-04-25 18:16:59 +00:00
Dave Zarzycki
211afa943f Runtime: better crash debugging/reporting
Swift SVN r16426
2014-04-16 21:37:16 +00:00
Dave Zarzycki
d8e39d106a Runtime: finish SwiftObject
<rdar://problem/12640667> Implement SwiftObject root class

Swift SVN r15706
2014-03-31 23:10:39 +00:00
Joe Groff
3f6b616211 Runtime: 'destroyPOD' needs to at least deallocate the box.
Fixes <rdar://problem/16245165>.

Swift SVN r15328
2014-03-21 17:56:06 +00:00
Dave Zarzycki
c07ebee7b1 Runtime: make generic non-assembly entry points use atomics
Our conditional use of atomics goal will have to wait until 2.0.

Swift SVN r15305
2014-03-20 23:32:07 +00:00
Dave Zarzycki
2f4d679fd0 Runtime: Drop the "raw" label on normal memory. NFC.
DI defined away the need for zeroed memory.

Swift SVN r15293
2014-03-20 20:42:27 +00:00
Dave Abrahams
0aa818f680 [stdlib] Delete obsolete verification functions
These functions were used for runtime assertions that are now being
checked at compile-time.

Swift SVN r14983
2014-03-12 23:59:46 +00:00
Joe Groff
0c55845cc1 Replace Greg's r14771 with a slightly less outrageous hack.
Implicit conversions to and from an unsigned long long enum class give us the calling convention we want for swift_allocBox without totally destroying the API for C callers.

Swift SVN r14919
2014-03-11 16:01:13 +00:00
Greg Parker
338cb2b718 Add an outrageous hack to swift_allocBox() to fix arm (rdar://16257592).
Swift SVN r14771
2014-03-07 05:37:14 +00:00
Dave Zarzycki
a85b2a3d78 Runtime: Rename Alloc.* to HeapObject.* (NFC)
Swift SVN r14228
2014-02-21 20:12:07 +00:00